Skip to content

Commit

Permalink
Specs fix
Browse files Browse the repository at this point in the history
  • Loading branch information
numbata committed Jul 14, 2024
1 parent 752525a commit dcecc68
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 47 deletions.
33 changes: 18 additions & 15 deletions spec/openapi_3/form_params_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
36 changes: 7 additions & 29 deletions spec/openapi_3/openapi_3_param_type_body_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -207,19 +189,15 @@ def app
let(:request_parameters_definition) do
{
'schema' => {
'properties' => {
'WithEntityParam' => { '$ref' => '#/components/schemas/postWithEntityParam' }
},
'required' => ['WithEntityParam'],
'type' => 'object'
'$ref' => '#/components/schemas/postWithEntityParam'
}
}
end

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
Expand All @@ -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
Expand Down
10 changes: 8 additions & 2 deletions spec/openapi_3/param_values_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand Down Expand Up @@ -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'
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/openapi_3/params_array_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand Down

0 comments on commit dcecc68

Please sign in to comment.