Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#### Fixes

* Your contribution here.
* [#87](https://github.com/ruby-grape/grape-swagger-entity/pull/87): remove hidden attributes from required [@bogdan](https://github.com/bogdan)

### 0.7.0 (2025/08/02)

Expand Down
7 changes: 5 additions & 2 deletions lib/grape-swagger/entity/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,11 @@ def parse_nested(entity_name, entity_options, parent_model = nil)

def required_params(params)
params.each_with_object(Set.new) do |(key, options), accum|
required = if options.fetch(:documentation, {}).key?(:required)
options.dig(:documentation, :required)
documentation = options.fetch(:documentation, {})
next if documentation[:hidden]

required = if documentation.key?(:required)
documentation[:required]
else
!options.key?(:if) && !options.key?(:unless) && options[:expose_nil] != false
end
Expand Down
3 changes: 1 addition & 2 deletions spec/grape-swagger/entities/response_model_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ def app
'code' => { 'type' => 'string', 'description' => 'Error code' },
'message' => { 'type' => 'string', 'description' => 'Error message' },
'attr' => { 'type' => 'string', 'description' => 'Attribute' } },
'required' => %w[text colors hidden_attr created_at kind kind2 kind3 tags relation
attr code message]
'required' => %w[text colors created_at kind kind2 kind3 tags relation attr code message]
)

expect(subject['definitions'].keys).to include 'ThisApi_Entities_Kind'
Expand Down
4 changes: 4 additions & 0 deletions spec/grape-swagger/entity/parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
expect(properties[:kind3]['$ref']).to eq('#/definitions/Kind')
end

it 'does not mark hidden attributes as required' do
expect(required).not_to include(:hidden_attr)
end

it 'merges attributes that have merge: true defined' do
expect(properties[:merged_attribute]).to be_nil
expect(properties[:code][:type]).to eq('string')
Expand Down
Loading