schemable 1.0.1 → 1.0.2
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 +1 -0
- data/lib/schemable/definition.rb +12 -0
- data/lib/schemable/relationship_schema_generator.rb +37 -30
- data/lib/schemable/version.rb +1 -1
- data/sig/schemable/definition.rbs +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d63ce1b1c91d8f6344b5800d9e793bb33a3b9694f91f646546a0e59f470a675
|
4
|
+
data.tar.gz: 04c750e85b0095266a86b5e74ccf64212af0c7669476b23229b3d0874af4a287
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 182e79396d00e3eb16d2344467cde65f9a8a0841b152f38c9fccafe4f3dfbaf47febdeb1a00063206090eb1fed37942f00788ee7530a936bda983a9c67944d34
|
7
|
+
data.tar.gz: 188035d9d158f7f28b2b79b98c1b9dea08df8482344c287eebac12116fddd5758637871917b8c79194537ad8af80ea72676f17f0e8cb5df2d811f5605240909e
|
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.2 (2024-01-30)
|
5
|
+
|
6
|
+
* 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.
|
7
|
+
|
4
8
|
## Schemable 1.0.1 (2024-01-29)
|
5
9
|
|
6
10
|
* Added configuration for changing the default value of enums. By default first key is used, or alternatively default can be set manually by the method `default_value_for_enum_attributes` from the definition.
|
data/README.md
CHANGED
@@ -86,6 +86,7 @@ The following is a list of the methods that can be overridden. (See the example
|
|
86
86
|
| `optional_create_request_attributes` | Returns the attributes that are not required in the create request. |
|
87
87
|
| `optional_update_request_attributes` | Returns the attributes that are not required in the update request. |
|
88
88
|
| `nullable_attributes` | Returns the attributes that are nullable in the request/response body. |
|
89
|
+
| `nullable_relationships` | Returns the relationships that are nullable in the response body. |
|
89
90
|
| `additional_create_request_attributes` | Returns the additional create request attributes that are not automatically generated. |
|
90
91
|
| `additional_update_request_attributes` | Returns the additional update request attributes that are not automatically generated. |
|
91
92
|
| `additional_response_attributes` | Returns the additional response attributes that are not automatically generated. |
|
data/lib/schemable/definition.rb
CHANGED
@@ -125,6 +125,18 @@ module Schemable
|
|
125
125
|
%i[]
|
126
126
|
end
|
127
127
|
|
128
|
+
# Returns the relationships that are nullable in the response body.
|
129
|
+
# This means that they can be present in the response body but they can be null.
|
130
|
+
# They are not required to be present in the request body.
|
131
|
+
#
|
132
|
+
# @example
|
133
|
+
# ['users', 'applicant']
|
134
|
+
#
|
135
|
+
# @return [Array<String>] The attributes that are nullable in the response body.
|
136
|
+
def nullable_relationships
|
137
|
+
%w[]
|
138
|
+
end
|
139
|
+
|
128
140
|
# Returns the additional create request attributes that are not automatically generated.
|
129
141
|
# These attributes are appended to the create request schema.
|
130
142
|
#
|
@@ -84,36 +84,43 @@ module Schemable
|
|
84
84
|
#
|
85
85
|
# @return [Hash] The generated schema for the relationship.
|
86
86
|
def generate_schema(type_name, collection: false)
|
87
|
-
if collection
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
87
|
+
schema = if collection
|
88
|
+
{
|
89
|
+
type: :object,
|
90
|
+
properties: {
|
91
|
+
data: {
|
92
|
+
type: :array,
|
93
|
+
items: {
|
94
|
+
type: :object,
|
95
|
+
properties: {
|
96
|
+
id: { type: :string },
|
97
|
+
type: { type: :string, default: type_name }
|
98
|
+
}
|
99
|
+
}
|
100
|
+
}
|
101
|
+
}
|
102
|
+
}
|
103
|
+
else
|
104
|
+
{
|
105
|
+
type: :object,
|
106
|
+
properties: {
|
107
|
+
data: {
|
108
|
+
type: :object,
|
109
|
+
properties: {
|
110
|
+
id: { type: :string },
|
111
|
+
type: { type: :string, default: type_name }
|
112
|
+
}
|
113
|
+
}
|
114
|
+
}
|
115
|
+
}
|
116
|
+
end
|
117
|
+
|
118
|
+
# Modify the schema to nullable if the relationship is in nullable
|
119
|
+
is_relation_nullable = @model_definition.nullable_relationships.include?(type_name)
|
120
|
+
|
121
|
+
return schema unless is_relation_nullable
|
122
|
+
|
123
|
+
@schema_modifier.add_properties(schema, { nullable: true }, 'properties.data')
|
117
124
|
end
|
118
125
|
end
|
119
126
|
end
|
data/lib/schemable/version.rb
CHANGED
@@ -13,6 +13,7 @@ module Schemable
|
|
13
13
|
def array_types: -> Hash[Symbol, any]
|
14
14
|
def relationships: -> Hash[Symbol, any]
|
15
15
|
def nullable_attributes: -> Array[Symbol]
|
16
|
+
def nullable_relationships: -> Array[String]
|
16
17
|
def serialized_instance: -> Hash[Symbol, any]
|
17
18
|
def self.generate: -> Array[Hash[Symbol, any]]
|
18
19
|
def excluded_response_included: -> Array[Symbol]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schemable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Muhammad Nawzad
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-01-
|
11
|
+
date: 2024-01-30 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: The schemable gem is an opinionated Gem for Rails applications to auto
|
14
14
|
generate schema for models in JSONAPI format. It is designed to work with rswag's
|