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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 955300fe20fc1f9dfe45283d0f4608886592feceb45db0cb7765e7eac1bda439
4
- data.tar.gz: bcac14db5aae2164a71ec642cea311aeba135c3f7f43d3a173aea92579cedbcb
3
+ metadata.gz: 05d45b3316abff7109efe2f2438be8cb720300c67040c72a6c93245354b5129c
4
+ data.tar.gz: f51d879560afec23a90423ba83b162cb3c799748a4447e1b56e62a41a601dc9a
5
5
  SHA512:
6
- metadata.gz: 6be97c3ea397aafdc76b6f51f9222cc6bf2cfd0b8ef76982ce7cc73a79687f095110f99902cb8be787c3b1603bc9bdc47eb7ae14a2fab7fbfe24fd4fb71db4ad
7
- data.tar.gz: e2b44b0e135fefd0c1af80a86c76dd2cfbc7cc69d9c74de0821808cf75ce4945cdf5e18ca4c1a55e95a096ab404255a0e4c6213e0227b5aac2be0a9777e9745c
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, input: false # excluded from UserInput
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, input: false # excluded from UserInput (response only)
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, input: false # excluído do UserInput
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, input: false # excluído do UserInput (response only)
430
+ association :posts, type: :array, read_only: true # excluído do UserInput (response only)
431
431
  ```
432
432
 
433
433
  ---
@@ -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, input: true)
17
+ def association(name, type: nil, read_only: false)
18
18
  @_associations ||= []
19
- @_associations << { name: name, type: type, input: input }
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
- input = assoc.fetch(:input, true)
67
- ref = { "$ref" => "#/components/schemas/#{name.to_s.classify}" }
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 unless input
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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OpenapiBlocks
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openapi_blocks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Caio Santos