mirror of
https://github.com/ditkrg/rswag.git
synced 2026-01-25 07:16:40 +00:00
Updates specs to add 3.0 compliant structure and tests around the new schema/structure
This commit is contained in:
parent
04564d933f
commit
4baf5efd11
@ -43,7 +43,9 @@ module Rswag
|
|||||||
# TODO: setup travis CI?
|
# TODO: setup travis CI?
|
||||||
|
|
||||||
# MUST HAVES
|
# MUST HAVES
|
||||||
# TODO: look at integrating and documenting the rest of the responses in the blog_spec and get a clean 3.0 output
|
# TODO: fix the specs in the rswag-specs gem
|
||||||
|
# TODO: look at handling different ways schemas can be defined in 3.0 for requestBody and response
|
||||||
|
# can we handle all of them?
|
||||||
# Then can look at handling different request_body things like $ref, etc
|
# Then can look at handling different request_body things like $ref, etc
|
||||||
# TODO: look at adding request_body method to handle diffs in Open API 2.0 to 3.0
|
# TODO: look at adding request_body method to handle diffs in Open API 2.0 to 3.0
|
||||||
# TODO: look at adding examples in content request_body
|
# TODO: look at adding examples in content request_body
|
||||||
|
|||||||
@ -40,7 +40,8 @@ module Rswag
|
|||||||
def derive_security_params(metadata, swagger_doc)
|
def derive_security_params(metadata, swagger_doc)
|
||||||
requirements = metadata[:operation][:security] || swagger_doc[:security] || []
|
requirements = metadata[:operation][:security] || swagger_doc[:security] || []
|
||||||
scheme_names = requirements.flat_map(&:keys)
|
scheme_names = requirements.flat_map(&:keys)
|
||||||
schemes = (swagger_doc[:components][:securitySchemes] || {}).slice(*scheme_names).values
|
components = swagger_doc[:components] || {}
|
||||||
|
schemes = (components[:securitySchemes] || {}).slice(*scheme_names).values
|
||||||
|
|
||||||
schemes.map do |scheme|
|
schemes.map do |scheme|
|
||||||
param = scheme[:type] == :apiKey ? scheme.slice(:name, :in) : { name: 'Authorization', in: :header }
|
param = scheme[:type] == :apiKey ? scheme.slice(:name, :in) : { name: 'Authorization', in: :header }
|
||||||
|
|||||||
@ -42,7 +42,8 @@ module Rswag
|
|||||||
response_schema = metadata[:response][:schema]
|
response_schema = metadata[:response][:schema]
|
||||||
return if response_schema.nil?
|
return if response_schema.nil?
|
||||||
|
|
||||||
components_schemas = { components: { schemas: swagger_doc[:components][:schemas] } }
|
components = swagger_doc[:components] || {}
|
||||||
|
components_schemas = { components: { schemas: components[:schemas] } }
|
||||||
|
|
||||||
validation_schema = response_schema
|
validation_schema = response_schema
|
||||||
.merge('$schema' => 'http://tempuri.org/rswag/specs/extended_schema')
|
.merge('$schema' => 'http://tempuri.org/rswag/specs/extended_schema')
|
||||||
|
|||||||
@ -16,11 +16,13 @@ module Rswag
|
|||||||
let(:config) { double('config') }
|
let(:config) { double('config') }
|
||||||
let(:swagger_doc) do
|
let(:swagger_doc) do
|
||||||
{
|
{
|
||||||
securityDefinitions: {
|
components: {
|
||||||
api_key: {
|
securitySchemes: {
|
||||||
type: :apiKey,
|
api_key: {
|
||||||
name: 'api_key',
|
type: :apiKey,
|
||||||
in: :query
|
name: 'api_key',
|
||||||
|
in: :query
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -204,7 +204,10 @@ module Rswag
|
|||||||
|
|
||||||
context 'basic auth' do
|
context 'basic auth' do
|
||||||
before do
|
before do
|
||||||
swagger_doc[:securityDefinitions] = { basic: { type: :basic } }
|
swagger_doc[:components] = { securitySchemes: {
|
||||||
|
basic: { type: :basic }
|
||||||
|
}
|
||||||
|
}
|
||||||
metadata[:operation][:security] = [basic: []]
|
metadata[:operation][:security] = [basic: []]
|
||||||
allow(example).to receive(:Authorization).and_return('Basic foobar')
|
allow(example).to receive(:Authorization).and_return('Basic foobar')
|
||||||
end
|
end
|
||||||
@ -216,7 +219,10 @@ module Rswag
|
|||||||
|
|
||||||
context 'apiKey' do
|
context 'apiKey' do
|
||||||
before do
|
before do
|
||||||
swagger_doc[:securityDefinitions] = { apiKey: { type: :apiKey, name: 'api_key', in: key_location } }
|
swagger_doc[:components] = { securitySchemes: {
|
||||||
|
apiKey: { type: :apiKey, name: 'api_key', in: key_location }
|
||||||
|
}
|
||||||
|
}
|
||||||
metadata[:operation][:security] = [apiKey: []]
|
metadata[:operation][:security] = [apiKey: []]
|
||||||
allow(example).to receive(:api_key).and_return('foobar')
|
allow(example).to receive(:api_key).and_return('foobar')
|
||||||
end
|
end
|
||||||
@ -257,7 +263,10 @@ module Rswag
|
|||||||
|
|
||||||
context 'oauth2' do
|
context 'oauth2' do
|
||||||
before do
|
before do
|
||||||
swagger_doc[:securityDefinitions] = { oauth2: { type: :oauth2, scopes: ['read:blogs'] } }
|
swagger_doc[:components] = { securitySchemes: {
|
||||||
|
oauth2: { type: :oauth2, scopes: ['read:blogs'] }
|
||||||
|
}
|
||||||
|
}
|
||||||
metadata[:operation][:security] = [oauth2: ['read:blogs']]
|
metadata[:operation][:security] = [oauth2: ['read:blogs']]
|
||||||
allow(example).to receive(:Authorization).and_return('Bearer foobar')
|
allow(example).to receive(:Authorization).and_return('Bearer foobar')
|
||||||
end
|
end
|
||||||
@ -269,9 +278,10 @@ module Rswag
|
|||||||
|
|
||||||
context 'paired security requirements' do
|
context 'paired security requirements' do
|
||||||
before do
|
before do
|
||||||
swagger_doc[:securityDefinitions] = {
|
swagger_doc[:components] = { securitySchemes: {
|
||||||
basic: { type: :basic },
|
basic: { type: :basic },
|
||||||
api_key: { type: :apiKey, name: 'api_key', in: :query }
|
api_key: { type: :apiKey, name: 'api_key', in: :query }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
metadata[:operation][:security] = [{ basic: [], api_key: [] }]
|
metadata[:operation][:security] = [{ basic: [], api_key: [] }]
|
||||||
allow(example).to receive(:Authorization).and_return('Basic foobar')
|
allow(example).to receive(:Authorization).and_return('Basic foobar')
|
||||||
@ -327,7 +337,7 @@ module Rswag
|
|||||||
|
|
||||||
context 'global security requirements' do
|
context 'global security requirements' do
|
||||||
before do
|
before do
|
||||||
swagger_doc[:securityDefinitions] = { apiKey: { type: :apiKey, name: 'api_key', in: :query } }
|
swagger_doc[:components] = {securitySchemes: { apiKey: { type: :apiKey, name: 'api_key', in: :query } }}
|
||||||
swagger_doc[:security] = [apiKey: []]
|
swagger_doc[:security] = [apiKey: []]
|
||||||
allow(example).to receive(:api_key).and_return('foobar')
|
allow(example).to receive(:api_key).and_return('foobar')
|
||||||
end
|
end
|
||||||
|
|||||||
@ -11,7 +11,7 @@ module Rswag
|
|||||||
allow(config).to receive(:get_swagger_doc).and_return(swagger_doc)
|
allow(config).to receive(:get_swagger_doc).and_return(swagger_doc)
|
||||||
end
|
end
|
||||||
let(:config) { double('config') }
|
let(:config) { double('config') }
|
||||||
let(:swagger_doc) { {:components => {}} }
|
let(:swagger_doc) {{}}
|
||||||
let(:example) { double('example') }
|
let(:example) { double('example') }
|
||||||
let(:metadata) do
|
let(:metadata) do
|
||||||
{
|
{
|
||||||
@ -58,13 +58,7 @@ module Rswag
|
|||||||
|
|
||||||
context 'referenced schemas' do
|
context 'referenced schemas' do
|
||||||
before do
|
before do
|
||||||
# swagger_doc[:definitions] = {
|
swagger_doc[:components] = {}
|
||||||
# 'blog' => {
|
|
||||||
# type: :object,
|
|
||||||
# properties: { foo: { type: :string } },
|
|
||||||
# required: ['foo']
|
|
||||||
# }
|
|
||||||
# }
|
|
||||||
swagger_doc[:components][:schemas] = {
|
swagger_doc[:components][:schemas] = {
|
||||||
'blog' => {
|
'blog' => {
|
||||||
type: :object,
|
type: :object,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user