Skip to content

Commit

Permalink
Fixed Swagger warnings for properties (#892)
Browse files Browse the repository at this point in the history
Co-authored-by: Mathieu Jobin <99191+mathieujobin@users.noreply.github.com>
  • Loading branch information
shev-vadim-net and mathieujobin authored Jul 14, 2023
1 parent 352e3cd commit 86a2ebe
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/apipie/generator/swagger/param_description/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def for_default
end

def required?
required_from_path? || (!@in_schema && @param_description.required)
required_from_path? || @param_description.required
end

def required_from_path?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
expect(properties).to eq(
{
a_number: {
type: 'number'
type: 'number', required: true
},
an_optional_number: {
type: 'number'
Expand All @@ -72,7 +72,7 @@
expect(properties).to eq(
{
a_number: {
type: %w[number null]
type: %w[number null], required: true
},
an_optional_number: {
type: %w[number null]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@

it { is_expected.to be_blank }

context 'when is required' do
let(:base_param_description_options) { { required: true } }

it { is_expected.to eq(true) }
end

context 'when in_schema is false' do
let(:in_schema) { false }

Expand Down Expand Up @@ -107,6 +113,14 @@
end
end
end

context 'when is required' do
let(:base_param_description_options) { { required: true } }

it 'does not output an option without default warning' do
expect { subject }.not_to output(/is optional but default value is not specified/).to_stderr
end
end
end

describe '.with_type' do
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/apipie/swagger_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
expect(properties).to eq(
{
a_number: {
type: 'number'
type: 'number', required: true
},
an_optional_number: {
type: 'number'
Expand Down
9 changes: 8 additions & 1 deletion spec/lib/swagger/openapi_2_0_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,14 @@
"$ref": "http://json-schema.org/draft-04/schema#/definitions/positiveIntegerDefault0"
},
"required": {
"$ref": "http://json-schema.org/draft-04/schema#/definitions/stringArray"
"anyOf": [
{
"$ref": "http://json-schema.org/draft-04/schema#/definitions/stringArray"
},
{
"type": "boolean"
}
]
},
"enum": {
"$ref": "http://json-schema.org/draft-04/schema#/properties/enum"
Expand Down

0 comments on commit 86a2ebe

Please sign in to comment.