Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Open api3 rebased #928

Draft
wants to merge 55 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
4604e1a
wip: openapi 3.0
Oct 13, 2018
f29e14c
move files to respective version folders
Oct 14, 2018
ac90d9f
begin to parse params
Oct 20, 2018
6bac652
fix failing tests
Nov 1, 2018
af9b11d
Initial support for openapi3 requestBody
Nov 10, 2018
c266c5b
OpenAPI3 parameters and request bodies are actually OpenAPI3 compliant
Nov 12, 2018
c7170da
Fix array parameter type (not custom types for now)
Nov 16, 2018
94a3fee
add tests
Nov 17, 2018
3189dfa
Initial support for openapi3 components/schemas
Nov 17, 2018
d3120f8
Fix tests
Nov 17, 2018
7f846a6
Add test
Nov 18, 2018
54de96d
Add test
Nov 25, 2018
aeb40a7
Fix edge cases with ranges, floats and strings
Nov 25, 2018
1c85b58
Add test
Nov 25, 2018
ce8c852
Add test
Nov 25, 2018
a7872ca
Add test
Nov 25, 2018
f0f2816
Add test
Nov 25, 2018
48932a5
Add test
Nov 25, 2018
ac5ad64
Better implementation of request body
Nov 30, 2018
a41d712
Fix test
Nov 30, 2018
c2e6a5a
Add test
Nov 30, 2018
47ec64e
Add test
Nov 30, 2018
5d3b522
Add test
Nov 30, 2018
d305600
fix array test
Dec 2, 2018
dcdcc38
Fix test
Dec 6, 2018
1518be3
Add test
Dec 6, 2018
8998cbf
Add test
Dec 6, 2018
e1d09c1
Add test
Dec 6, 2018
3eb21a2
Add test
Dec 6, 2018
12e7a4f
Add test
Dec 6, 2018
d65d13e
Add test
Dec 6, 2018
bbf21b9
Add test
Dec 6, 2018
5ff4d39
Add test
Dec 6, 2018
4c470fb
Add test
Dec 6, 2018
f50a24a
Fix tests
Dec 6, 2018
7a3fb37
Add test
Dec 7, 2018
a89c16f
Add test
Dec 7, 2018
c0d9ee9
Add test
Dec 7, 2018
7199caf
Add test
Dec 7, 2018
1ebeb33
Fix file response body
Dec 11, 2018
b3eaa88
Add examples spec
Dec 17, 2018
b4c95fe
Fix host test
Dec 27, 2018
230efaf
Add specs
Dec 27, 2018
5d6bb3a
Fix guarded endpoint spec, after a rebase
Dec 28, 2018
9713a2b
Fix spec
Dec 28, 2018
1f9c449
Add spec
Dec 30, 2018
9b6cb2a
Add spec
Jan 20, 2019
2cbb17b
Fix: Prevent class name collisions in specs with ApiClassDefinitionCl…
numbata Jul 13, 2024
fd14ca9
Fix ParamsParser call from OpenAPI3 module
numbata Jul 13, 2024
f55b906
Skip anonymous API class definition deletion in specs
numbata Jul 13, 2024
510457f
Cleanup a bit
numbata Jul 14, 2024
752525a
Set the right $ref object for the request body
numbata Jul 14, 2024
dcecc68
Specs fix
numbata Jul 14, 2024
00ed99e
Add schema validation against OpenAPI3 specification
numbata Jul 14, 2024
5288b69
Getting rid of the debug noise a little bit
numbata Jul 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add tests
  • Loading branch information
blake authored and numbata committed Jul 12, 2024
commit 94a3fee7f62454f6559a727cc6d09d24d97df243
2 changes: 1 addition & 1 deletion lib/grape-swagger/openapi_3/endpoint.rb
Original file line number Diff line number Diff line change
@@ -208,7 +208,7 @@ def response_body_object(_, _, parameters)
properties = v.map { |value| [value[:name], value.except(:name, :in, :required, :schema).merge(value[:schema])] }.to_h
required_values = v.select { |param| param[:required] }.map { |required| required[:name] }
result = { 'schema' => { 'type' => 'object', 'properties' => properties } }
result['required'] = required_values unless required_values.empty?
result['schema']['required'] = required_values unless required_values.empty?
['application/x-www-form-urlencoded', result]
end.to_h
}
20 changes: 16 additions & 4 deletions spec/openapi_3/api_openapi_3_response_spec.rb
Original file line number Diff line number Diff line change
@@ -114,12 +114,24 @@ def app
end

specify do
fail("TODO: Fix")
expect(subject['paths']['/params_given']['post']).to eql(
'description' => 'This returns something',
'parameters' => [
{ 'in' => 'formData', 'name' => 'description', 'type' => 'string', 'required' => false },
{ 'in' => 'formData', 'name' => '$responses', 'type' => 'array', 'items' => { 'type' => 'string' }, 'required' => false }
],
'requestBody' => {
'content' => {
'application/x-www-form-urlencoded' => {
'schema' => {
'properties' => {
'$responses' => {
'items' => { 'type' => 'string' }, 'type' => 'array'
},
'description' => { 'type' => 'string' }
},
'type' => 'object'
}
}
}
},
'responses' => {
'201' => {
'description' => 'This returns something'
94 changes: 94 additions & 0 deletions spec/openapi_3/param_type_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# frozen_string_literal: true

require 'spec_helper'

describe 'Params Types' do
def app
Class.new(Grape::API) do
format :json

params do
requires :input, type: String
end
post :action do
end

params do
requires :input, type: String, default: '14', documentation: { type: 'email', default: '42' }
end
post :action_with_doc do
end

add_swagger_documentation openapi_version: '3.0'
end
end
context 'with no documentation hash' do
subject do
get '/swagger_doc/action'
expect(last_response.status).to eq 200
body = JSON.parse last_response.body
body['paths']['/action']['post']
end

it 'reads param type correctly' do
expect(subject['requestBody']).to eq 'content' => {
'application/x-www-form-urlencoded' => {
'schema' => {
'properties' => {
'input' => { 'type' => 'string' }
},
'required' => ['input'],
'type' => 'object'
}
}
}
end

describe 'header params' do
def app
Class.new(Grape::API) do
format :json

desc 'Some API', headers: { 'My-Header' => { required: true, description: 'Set this!' } }
params do
requires :input, type: String
end
post :action do
end

add_swagger_documentation openapi_version: '3.0'
end
end

it 'has consistent types' do
parameter_type = subject['parameters'].map { |param| param['schema']['type'] }
expect(parameter_type).to eq(%w[string])

header_type = subject['requestBody']['content']['application/x-www-form-urlencoded']['schema']['properties'].values.map { |param| param['type'] }
expect(header_type).to eq(%w[string])
end
end
end

context 'with documentation hash' do
subject do
get '/swagger_doc/action_with_doc'
expect(last_response.status).to eq 200
body = JSON.parse last_response.body
body['paths']['/action_with_doc']['post']['requestBody']
end

it 'reads param type correctly' do
expect(subject).to eq 'content' => {
'application/x-www-form-urlencoded' => {
'schema' => {
'properties' => {
'input' => { 'default' => '42', 'format' => 'email', 'type' => 'string' }
},
'required' => ['input'], 'type' => 'object'
}
}
}
end
end
end