diff --git a/lib/apipie/generator/swagger/param_description/builder.rb b/lib/apipie/generator/swagger/param_description/builder.rb index 03978f8b..4e3bb7e6 100644 --- a/lib/apipie/generator/swagger/param_description/builder.rb +++ b/lib/apipie/generator/swagger/param_description/builder.rb @@ -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? diff --git a/spec/lib/apipie/generator/swagger/method_description/response_schema_service_spec.rb b/spec/lib/apipie/generator/swagger/method_description/response_schema_service_spec.rb index 9d5c35c6..d6c86174 100644 --- a/spec/lib/apipie/generator/swagger/method_description/response_schema_service_spec.rb +++ b/spec/lib/apipie/generator/swagger/method_description/response_schema_service_spec.rb @@ -56,7 +56,7 @@ expect(properties).to eq( { a_number: { - type: 'number' + type: 'number', required: true }, an_optional_number: { type: 'number' @@ -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] diff --git a/spec/lib/apipie/generator/swagger/param_description/builder_spec.rb b/spec/lib/apipie/generator/swagger/param_description/builder_spec.rb index 9a97b9ab..24efae60 100644 --- a/spec/lib/apipie/generator/swagger/param_description/builder_spec.rb +++ b/spec/lib/apipie/generator/swagger/param_description/builder_spec.rb @@ -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 } @@ -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 diff --git a/spec/lib/apipie/swagger_generator_spec.rb b/spec/lib/apipie/swagger_generator_spec.rb index 2df36a06..f0adb9b9 100644 --- a/spec/lib/apipie/swagger_generator_spec.rb +++ b/spec/lib/apipie/swagger_generator_spec.rb @@ -61,7 +61,7 @@ expect(properties).to eq( { a_number: { - type: 'number' + type: 'number', required: true }, an_optional_number: { type: 'number' diff --git a/spec/lib/swagger/openapi_2_0_schema.json b/spec/lib/swagger/openapi_2_0_schema.json index ebe10ed3..3d989473 100644 --- a/spec/lib/swagger/openapi_2_0_schema.json +++ b/spec/lib/swagger/openapi_2_0_schema.json @@ -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"