openapi_blocks 0.2.0 → 0.2.1
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 +5 -0
- data/README.md +2 -2
- data/README.pt-BR.md +2 -2
- data/lib/openapi_blocks/base.rb +2 -2
- data/lib/openapi_blocks/schema/extractor.rb +3 -3
- data/lib/openapi_blocks/spec/components.rb +7 -2
- data/lib/openapi_blocks/version.rb +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: 05d45b3316abff7109efe2f2438be8cb720300c67040c72a6c93245354b5129c
|
|
4
|
+
data.tar.gz: f51d879560afec23a90423ba83b162cb3c799748a4447e1b56e62a41a601dc9a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c8c0ddcfde5053794e761fde4ecec89f5cbdcc021b37bd5dde751f76fdc6a0d05749802c9504bc05104c0c9fb242c533f3b94251f29961bf9c077fc4788850fd
|
|
7
|
+
data.tar.gz: 21a332227d4653fe2c233d666213087bc0e5ba91ef7210577f864d68a56987236d2023f2f7f9f5285dd5a9ea40b2eba97d1c1bf6d546ca7b0116fb897239f6c9
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.2.1] - 2026-06-01
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
- `association` DSL now uses `read_only: true` instead of `input: false` for consistency with `attribute` DSL
|
|
14
|
+
|
|
10
15
|
## [0.2.0] - 2026-06-01
|
|
11
16
|
|
|
12
17
|
### Added
|
data/README.md
CHANGED
|
@@ -120,7 +120,7 @@ class UserOpenapi < OpenapiBlocks::Base
|
|
|
120
120
|
|
|
121
121
|
# opt-in associations
|
|
122
122
|
association :company
|
|
123
|
-
association :posts, type: :array,
|
|
123
|
+
association :posts, type: :array, read_only: true # excluded from UserInput
|
|
124
124
|
|
|
125
125
|
# virtual attributes (not in the database)
|
|
126
126
|
# read_only: true -> exposed in response (User), excluded from request body (UserInput)
|
|
@@ -237,7 +237,7 @@ end
|
|
|
237
237
|
```ruby
|
|
238
238
|
association :company # belongs_to — $ref to Company schema
|
|
239
239
|
association :posts, type: :array # has_many — array of $ref to Post schema
|
|
240
|
-
association :posts, type: :array,
|
|
240
|
+
association :posts, type: :array, read_only: true # excluded from UserInput (response only)
|
|
241
241
|
```
|
|
242
242
|
|
|
243
243
|
---
|
data/README.pt-BR.md
CHANGED
|
@@ -310,7 +310,7 @@ class UserOpenapi < OpenapiBlocks::Base
|
|
|
310
310
|
|
|
311
311
|
# associações opt-in
|
|
312
312
|
association :company
|
|
313
|
-
association :posts, type: :array,
|
|
313
|
+
association :posts, type: :array, read_only: true # excluído do UserInput
|
|
314
314
|
|
|
315
315
|
# atributos virtuais (não existem no banco de dados)
|
|
316
316
|
# read_only: true -> exposto apenas na resposta (User)
|
|
@@ -427,7 +427,7 @@ class UserOpenapi < OpenapiBlocks::Base
|
|
|
427
427
|
```ruby
|
|
428
428
|
association :company # belongs_to — $ref para Company schema
|
|
429
429
|
association :posts, type: :array # has_many — array de $ref para Post schema
|
|
430
|
-
association :posts, type: :array,
|
|
430
|
+
association :posts, type: :array, read_only: true # excluído do UserInput (response only)
|
|
431
431
|
```
|
|
432
432
|
|
|
433
433
|
---
|
data/lib/openapi_blocks/base.rb
CHANGED
|
@@ -14,9 +14,9 @@ module OpenapiBlocks
|
|
|
14
14
|
@_ignored.concat(attributes.map(&:to_s))
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
-
def association(name, type: nil,
|
|
17
|
+
def association(name, type: nil, read_only: false)
|
|
18
18
|
@_associations ||= []
|
|
19
|
-
@_associations << { name: name, type: type,
|
|
19
|
+
@_associations << { name: name, type: type, read_only: read_only }
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
def attribute(name, **)
|
|
@@ -63,11 +63,11 @@ module OpenapiBlocks
|
|
|
63
63
|
Array(@openapi_class._associations).each_with_object({}) do |assoc, hash|
|
|
64
64
|
name = assoc[:name]
|
|
65
65
|
type = assoc[:type]
|
|
66
|
-
|
|
67
|
-
ref
|
|
66
|
+
read_only = assoc.fetch(:read_only, false)
|
|
67
|
+
ref = { "$ref" => "#/components/schemas/#{name.to_s.classify}" }
|
|
68
68
|
|
|
69
69
|
schema = type == :array ? { type: "array", items: ref } : ref
|
|
70
|
-
schema[:readOnly] = true
|
|
70
|
+
schema[:readOnly] = true if read_only
|
|
71
71
|
|
|
72
72
|
hash[name.to_s] = schema
|
|
73
73
|
end
|
|
@@ -30,14 +30,19 @@ module OpenapiBlocks
|
|
|
30
30
|
|
|
31
31
|
private
|
|
32
32
|
|
|
33
|
-
def build_input(schema, openapi_class) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
|
|
33
|
+
def build_input(schema, openapi_class) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
|
|
34
34
|
read_only_virtuals = Array(openapi_class._virtual_attributes)
|
|
35
35
|
.select { |attr| attr[:read_only] == true }
|
|
36
36
|
.map { |attr| attr[:name].to_s }
|
|
37
37
|
|
|
38
|
+
read_only_associations = Array(openapi_class._associations)
|
|
39
|
+
.select { |assoc| assoc[:read_only] == true }
|
|
40
|
+
.map { |assoc| assoc[:name].to_s }
|
|
41
|
+
|
|
38
42
|
input_properties = schema[:properties].reject do |name, property|
|
|
39
43
|
INPUT_IGNORED_PROPERTIES.include?(name.to_s) ||
|
|
40
|
-
read_only_virtuals.include?(name.to_s)
|
|
44
|
+
read_only_virtuals.include?(name.to_s) ||
|
|
45
|
+
read_only_associations.include?(name.to_s) ||
|
|
41
46
|
property[:readOnly] == true
|
|
42
47
|
end
|
|
43
48
|
|