diff --git a/spec/openapi_3/form_params_spec.rb b/spec/openapi_3/form_params_spec.rb index b43551ca..0a0e83e7 100644 --- a/spec/openapi_3/form_params_spec.rb +++ b/spec/openapi_3/form_params_spec.rb @@ -67,24 +67,27 @@ def app }] expect(subject['paths']['/items/{id}']['post']['requestBody']).to eq 'content' => { - 'application/json' => { 'schema' => { 'properties' => {}, 'type' => 'object' } }, - 'application/x-www-form-urlencoded' => { + 'application/json' => { 'schema' => { - 'properties' => { - 'conditions' => { - 'description' => 'conditions of item', - 'enum' => %w[one two], - 'type' => 'string' - }, - 'name' => { - 'description' => 'name of item', - 'type' => 'string' - } - }, - 'required' => ['name'], - 'type' => 'object' + '$ref' => '#/components/schemas/postItems' } } } + + expect(subject['components']['schemas']['postItems']).to match( + 'properties' => { + 'conditions' => { + 'description' => 'conditions of item', + 'enum' => %w[one two], + 'type' => 'string' + }, + 'name' => { + 'description' => 'name of item', + 'type' => 'string' + } + }, + 'required' => ['name'], + 'type' => 'object' + ) end end diff --git a/spec/openapi_3/openapi_3_param_type_body_spec.rb b/spec/openapi_3/openapi_3_param_type_body_spec.rb index 02833963..dbfa89c2 100644 --- a/spec/openapi_3/openapi_3_param_type_body_spec.rb +++ b/spec/openapi_3/openapi_3_param_type_body_spec.rb @@ -85,11 +85,7 @@ def app specify do expect(subject['paths']['/wo_entities/in_body']['post']['requestBody']['content']['application/json']).to eql( 'schema' => { - 'properties' => { - 'WoEntitiesInBody' => { '$ref' => '#/components/schemas/postWoEntitiesInBody' } - }, - 'required' => ['WoEntitiesInBody'], - 'type' => 'object' + '$ref' => '#/components/schemas/postWoEntitiesInBody' } ) end @@ -116,11 +112,7 @@ def app expect(subject['paths']['/wo_entities/in_body/{key}']['put']['requestBody']['content']['application/json']).to eql( 'schema' => { - 'properties' => { - 'WoEntitiesInBody' => { '$ref' => '#/components/schemas/putWoEntitiesInBody' } - }, - 'required' => ['WoEntitiesInBody'], - 'type' => 'object' + '$ref' => '#/components/schemas/putWoEntitiesInBody' } ) end @@ -147,13 +139,7 @@ def app specify do expect(subject['paths']['/with_entities/in_body']['post']['requestBody']['content']['application/json']).to eql( 'schema' => { - 'properties' => { - 'WithEntitiesInBody' => { - '$ref' => '#/components/schemas/postWithEntitiesInBody' - } - }, - 'required' => ['WithEntitiesInBody'], - 'type' => 'object' + '$ref' => '#/components/schemas/postWithEntitiesInBody' } ) end @@ -183,11 +169,7 @@ def app expect(subject['paths']['/with_entities/in_body/{id}']['put']['requestBody']['content']['application/json']).to eql( 'schema' => { - 'properties' => { - 'WithEntitiesInBody' => { '$ref' => '#/components/schemas/putWithEntitiesInBody' } - }, - 'required' => ['WithEntitiesInBody'], - 'type' => 'object' + '$ref' => '#/components/schemas/putWithEntitiesInBody' } ) end @@ -207,11 +189,7 @@ def app let(:request_parameters_definition) do { 'schema' => { - 'properties' => { - 'WithEntityParam' => { '$ref' => '#/components/schemas/postWithEntityParam' } - }, - 'required' => ['WithEntityParam'], - 'type' => 'object' + '$ref' => '#/components/schemas/postWithEntityParam' } } end @@ -219,7 +197,7 @@ def app let(:request_body_parameters_definition) do { 'description' => 'put in body with entity parameter', - 'properties' => { 'data' => { '$ref' => '#/components/schemas/ApiResponse', 'description' => 'request data' } }, + 'properties' => { 'data' => { '$ref' => '#/components/schemas/NestedModule_ApiResponse', 'description' => 'request data' } }, 'type' => 'object' } end @@ -234,7 +212,7 @@ def app end specify do - expect(subject['components']['schemas']['ApiResponse']).not_to be_nil + expect(subject['components']['schemas']['NestedModule_ApiResponse']).not_to be_nil end specify do diff --git a/spec/openapi_3/param_values_spec.rb b/spec/openapi_3/param_values_spec.rb index e034f3fe..7228ae5a 100644 --- a/spec/openapi_3/param_values_spec.rb +++ b/spec/openapi_3/param_values_spec.rb @@ -12,24 +12,28 @@ def app requires :letter, type: String, values: %w[a b c] end post :plain_array do + 'ok' end params do requires :letter, type: String, values: proc { %w[d e f] } end post :array_in_proc do + 'ok' end params do requires :letter, type: String, values: 'a'..'z' end post :range_letter do + 'ok' end params do requires :integer, type: Integer, values: -5..5 end post :range_integer do + 'ok' end add_swagger_documentation openapi_version: '3.0' @@ -40,7 +44,7 @@ def first_parameter_info(request) get "/swagger_doc/#{request}" expect(last_response.status).to eq 200 body = JSON.parse last_response.body - body['paths']["/#{request}"]['post']['requestBody']['content']['application/x-www-form-urlencoded']['schema'] + body['components']['schemas']["post#{request.camelize}"] end context 'Plain array values' do @@ -116,12 +120,14 @@ def app requires :letter, type: String, values: proc { 'string' } end post :non_array_in_proc do + 'ok' end params do requires :float, type: Float, values: -5.0..5.0 end post :range_float do + 'ok' end add_swagger_documentation openapi_version: '3.0' @@ -132,7 +138,7 @@ def first_parameter_info(request) get "/swagger_doc/#{request}" expect(last_response.status).to eq 200 body = JSON.parse last_response.body - body['paths']["/#{request}"]['post']['requestBody']['content']['application/x-www-form-urlencoded']['schema'] + body['components']['schemas']["post#{request.camelize}"] end context 'Non array in proc values' do diff --git a/spec/openapi_3/params_array_spec.rb b/spec/openapi_3/params_array_spec.rb index 55beccb4..7cf1c5fc 100644 --- a/spec/openapi_3/params_array_spec.rb +++ b/spec/openapi_3/params_array_spec.rb @@ -84,7 +84,7 @@ end specify do - expect(subject['paths']['/groups']['post']['requestBody']['content']['application/x-www-form-urlencoded']).to eql( + expect(subject['paths']['/groups']['post']['requestBody']['content']['application/json']).to eql( 'schema' => { 'properties' => { "required_group#{braces}[required_param_1]" => { 'items' => { 'type' => 'string' }, 'type' => 'array' },