Skip to content

Commit 86a2ebe

Browse files
Fixed Swagger warnings for properties (#892)
Co-authored-by: Mathieu Jobin <99191+mathieujobin@users.noreply.github.com>
1 parent 352e3cd commit 86a2ebe

File tree

5 files changed

+26
-5
lines changed

5 files changed

+26
-5
lines changed

lib/apipie/generator/swagger/param_description/builder.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def for_default
7979
end
8080

8181
def required?
82-
required_from_path? || (!@in_schema && @param_description.required)
82+
required_from_path? || @param_description.required
8383
end
8484

8585
def required_from_path?

spec/lib/apipie/generator/swagger/method_description/response_schema_service_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
expect(properties).to eq(
5757
{
5858
a_number: {
59-
type: 'number'
59+
type: 'number', required: true
6060
},
6161
an_optional_number: {
6262
type: 'number'
@@ -72,7 +72,7 @@
7272
expect(properties).to eq(
7373
{
7474
a_number: {
75-
type: %w[number null]
75+
type: %w[number null], required: true
7676
},
7777
an_optional_number: {
7878
type: %w[number null]

spec/lib/apipie/generator/swagger/param_description/builder_spec.rb

+14
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@
7878

7979
it { is_expected.to be_blank }
8080

81+
context 'when is required' do
82+
let(:base_param_description_options) { { required: true } }
83+
84+
it { is_expected.to eq(true) }
85+
end
86+
8187
context 'when in_schema is false' do
8288
let(:in_schema) { false }
8389

@@ -107,6 +113,14 @@
107113
end
108114
end
109115
end
116+
117+
context 'when is required' do
118+
let(:base_param_description_options) { { required: true } }
119+
120+
it 'does not output an option without default warning' do
121+
expect { subject }.not_to output(/is optional but default value is not specified/).to_stderr
122+
end
123+
end
110124
end
111125

112126
describe '.with_type' do

spec/lib/apipie/swagger_generator_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
expect(properties).to eq(
6262
{
6363
a_number: {
64-
type: 'number'
64+
type: 'number', required: true
6565
},
6666
an_optional_number: {
6767
type: 'number'

spec/lib/swagger/openapi_2_0_schema.json

+8-1
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,14 @@
996996
"$ref": "http://json-schema.org/draft-04/schema#/definitions/positiveIntegerDefault0"
997997
},
998998
"required": {
999-
"$ref": "http://json-schema.org/draft-04/schema#/definitions/stringArray"
999+
"anyOf": [
1000+
{
1001+
"$ref": "http://json-schema.org/draft-04/schema#/definitions/stringArray"
1002+
},
1003+
{
1004+
"type": "boolean"
1005+
}
1006+
]
10001007
},
10011008
"enum": {
10021009
"$ref": "http://json-schema.org/draft-04/schema#/properties/enum"

0 commit comments

Comments
 (0)