schemable 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +2 -1
- data/lib/schemable/configuration.rb +2 -0
- data/lib/schemable/response_schema_generator.rb +7 -3
- data/lib/schemable/version.rb +1 -1
- data/lib/templates/schemable.rb +5 -0
- data/sig/schemable/configuration.rbs +1 -0
- data/sig/schemable/response_schema_generator.rbs +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 76b5ccf66c28d0bcfc644321e370e1c4404518ee1a4ba056fe20bb72a22cc415
|
4
|
+
data.tar.gz: cd7ad60e43634159a2b845c15ef557a3a60b02cb5c465e63e5f90ff47807afe5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 835b1048ab2efd7419b45e77d4733e769d9c657a5cd08e67a26584f3cf6f3ca23588d7875eb21353d9a283f422b50bb50bfc8a5ef0dd2edcad3dcf0c76cfda16
|
7
|
+
data.tar.gz: accc7a59d075dfc07437f7d2c6bfa8367336b3aafd8d04aca652c38a98cebdf3e7f80c614c1e90524091df6f32e7306ac4f2d183ab79157863f4014376a3b14a
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
# Changelog
|
2
2
|
This file is used to list changes made in each version of the Schemable gem.
|
3
3
|
|
4
|
+
## Schemable 1.0.3 (2024-01-30)
|
5
|
+
|
6
|
+
* Added configuration for preventing expansion for nested relationships. This can be done by setting the `expand_nested` to `true` when invoking `ResponseSchemaGenerator`'s `generate` instance method (e.g. `ResponseSchemaGenerator.new(instance).generate(expand: true, expand_nested: true)`. Additionally, you could globally set the value of `expand_nested` to the same value as `expand` by setting the configuration `infer_expand_nested_from_expand` to `true` in the `/config/initializers/schemable.rb`.
|
7
|
+
|
4
8
|
## Schemable 1.0.2 (2024-01-30)
|
5
9
|
|
6
10
|
* Added configuration for making certain associations nullable in the response's relationship. This can be done by adding the name of the relation in the `nullable_relationships` method's array of strings.
|
data/README.md
CHANGED
@@ -61,6 +61,7 @@ Please note that the configurations options below are defined in the `Schemable`
|
|
61
61
|
| `enum_prefix_for_simple_enum` | The prefix to be used for the enum values when `mongoid` is used. | `nil` |
|
62
62
|
| `enum_suffix_for_simple_enum` | The suffix to be used for the enum values when `mongoid` is used. | `nil` |
|
63
63
|
| `infer_attributes_from_custom_method` | The name of the custom method that is used to get the attributes to be generated in the schema. See [Annex 1.3 - Infer attributes from custom method](#annex-13---infer-attributes-from-custom-method) for more information. | `nil` |
|
64
|
+
| `infer_expand_nested_from_expand` | Configures `ResponseSchemaGenerator`'s `generate` method to prevent expansion for nested relationships. It globally set the value of `expand_nested` to the same value as `expand` by setting the configuration to `true` | `flase` |
|
64
65
|
| `infer_attributes_from_jsonapi_serializable` | Whether or not to infer the attributes from the `JSONAPI::Serializable::Resource` class. See the previous example [Annex 1.1 - Use serialized instance](#annex-11---use-serialized-instance) for more information. | `false` |
|
65
66
|
| `custom_meta_response_schema` | A hash of custom meta response schema that can be used to override the default meta response schema. See [Annex 1.4 - Custom meta response schema](#annex-14---custom-meta-response-schema) for more information. | `nil` |
|
66
67
|
| `pagination_enabled` | Enable pagination schema generation in the `meta` section of the response schema. | `true` |
|
@@ -400,7 +401,7 @@ module Swagger
|
|
400
401
|
"#{schema_instance.model}CreateRequest": schema_instance.camelize_keys(Schemable::RequestSchemaGenerator.new(schema_instance).generate_for_create),
|
401
402
|
"#{schema_instance.model}UpdateRequest": schema_instance.camelize_keys(Schemable::RequestSchemaGenerator.new(schema_instance).generate_for_update),
|
402
403
|
"#{schema_instance.model}Response": schema_instance.camelize_keys(Schemable::ResponseSchemaGenerator.new(schema_instance).generate(expand: true, collection: true, relationships_to_exclude_from_expansion: %w[addresses stores attachments])),
|
403
|
-
"#{schema_instance.model}ResponseExpanded": schema_instance.camelize_keys(Schemable::ResponseSchemaGenerator.new(schema_instance).generate(expand: true))
|
404
|
+
"#{schema_instance.model}ResponseExpanded": schema_instance.camelize_keys(Schemable::ResponseSchemaGenerator.new(schema_instance).generate(expand: true, expand_nested: true))
|
404
405
|
]
|
405
406
|
end
|
406
407
|
end
|
@@ -16,6 +16,7 @@ module Schemable
|
|
16
16
|
:enum_prefix_for_simple_enum,
|
17
17
|
:enum_suffix_for_simple_enum,
|
18
18
|
:custom_meta_response_schema,
|
19
|
+
:infer_expand_nested_from_expand,
|
19
20
|
:infer_attributes_from_custom_method,
|
20
21
|
:infer_attributes_from_jsonapi_serializable
|
21
22
|
)
|
@@ -32,6 +33,7 @@ module Schemable
|
|
32
33
|
@custom_meta_response_schema = nil
|
33
34
|
@enum_prefix_for_simple_enum = nil
|
34
35
|
@enum_suffix_for_simple_enum = nil
|
36
|
+
@infer_expand_nested_from_expand = false
|
35
37
|
@infer_attributes_from_custom_method = nil
|
36
38
|
@infer_attributes_from_jsonapi_serializable = false
|
37
39
|
end
|
@@ -27,12 +27,16 @@ module Schemable
|
|
27
27
|
# @param expand [Boolean] Whether to include the included resources in the schema.
|
28
28
|
# @param relationships_to_exclude_from_expansion [Array] The relationships to exclude from expansion in the schema.
|
29
29
|
# @param collection [Boolean] Whether the response is for a collection of resources.
|
30
|
+
# @param expand_nested [Boolean] Whether to include the nested relationships in the schema.
|
30
31
|
#
|
31
32
|
# @example
|
32
|
-
# schema = generator.generate(expand: true, relationships_to_exclude_from_expansion: ['some_relationship'], collection: true)
|
33
|
+
# schema = generator.generate(expand: true, relationships_to_exclude_from_expansion: ['some_relationship'], collection: true, expand_nested: true)
|
33
34
|
#
|
34
35
|
# @return [Hash] The generated schema.
|
35
|
-
def generate(expand: false, relationships_to_exclude_from_expansion: [], collection: false)
|
36
|
+
def generate(expand: false, relationships_to_exclude_from_expansion: [], collection: false, expand_nested: false)
|
37
|
+
# Override expand_nested if infer_expand_nested_from_expand is true
|
38
|
+
expand_nested = expand if @configuration.infer_expand_nested_from_expand
|
39
|
+
|
36
40
|
data = {
|
37
41
|
type: :object,
|
38
42
|
properties: {
|
@@ -51,7 +55,7 @@ module Schemable
|
|
51
55
|
schema = collection ? { data: { type: :array, items: data } } : { data: }
|
52
56
|
|
53
57
|
if expand
|
54
|
-
included_schema = IncludedSchemaGenerator.new(@model_definition).generate(expand
|
58
|
+
included_schema = IncludedSchemaGenerator.new(@model_definition).generate(expand: expand_nested, relationships_to_exclude_from_expansion:)
|
55
59
|
@schema_modifier.add_properties(schema, included_schema, '.')
|
56
60
|
end
|
57
61
|
|
data/lib/schemable/version.rb
CHANGED
data/lib/templates/schemable.rb
CHANGED
@@ -41,6 +41,11 @@ Schemable.configure do |config|
|
|
41
41
|
#
|
42
42
|
# config.infer_attributes_from_custom_method = nil
|
43
43
|
|
44
|
+
# If you want to recursively expand the relationships in the response schema
|
45
|
+
# then set this option to true, otherwise set it to false (default).
|
46
|
+
#
|
47
|
+
# config.infer_expand_nested_from_expand = true
|
48
|
+
|
44
49
|
# If you want to get the list of attributes from the jsonapi-rails gem's
|
45
50
|
# JSONAPI::Serializable::Resource class, set this option to true.
|
46
51
|
# It uses the attribute_blocks method to get the list of attributes.
|
@@ -8,6 +8,7 @@ module Schemable
|
|
8
8
|
attr_accessor custom_defined_enum_method: Symbol?
|
9
9
|
attr_accessor enum_prefix_for_simple_enum: String?
|
10
10
|
attr_accessor enum_suffix_for_simple_enum: String?
|
11
|
+
attr_accessor infer_expand_nested_from_expand: bool
|
11
12
|
attr_accessor custom_type_mappers: Hash[Symbol, any]
|
12
13
|
attr_accessor infer_attributes_from_custom_method: Symbol?
|
13
14
|
attr_accessor custom_meta_response_schema: Hash[Symbol, any]?
|
@@ -8,6 +8,6 @@ module Schemable
|
|
8
8
|
def initialize: (Definition) -> void
|
9
9
|
def meta: -> Hash[Symbol, any]
|
10
10
|
def jsonapi: -> Hash[Symbol, any]
|
11
|
-
def generate: (expand: bool, relationships_to_exclude_from_expansion: Array[Symbol], collection: bool) -> Hash[Symbol, any]
|
11
|
+
def generate: (expand: bool, relationships_to_exclude_from_expansion: Array[Symbol], collection: bool, expand_nested: bool) -> Hash[Symbol, any]
|
12
12
|
end
|
13
13
|
end
|