mirror of
https://github.com/ditkrg/rswag.git
synced 2026-01-22 22:06:43 +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?
|
||||
|
||||
# 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
|
||||
# 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
|
||||
|
||||
@ -40,7 +40,8 @@ module Rswag
|
||||
def derive_security_params(metadata, swagger_doc)
|
||||
requirements = metadata[:operation][:security] || swagger_doc[:security] || []
|
||||
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|
|
||||
param = scheme[:type] == :apiKey ? scheme.slice(:name, :in) : { name: 'Authorization', in: :header }
|
||||
|
||||
@ -42,7 +42,8 @@ module Rswag
|
||||
response_schema = metadata[:response][:schema]
|
||||
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
|
||||
.merge('$schema' => 'http://tempuri.org/rswag/specs/extended_schema')
|
||||
|
||||
@ -16,11 +16,13 @@ module Rswag
|
||||
let(:config) { double('config') }
|
||||
let(:swagger_doc) do
|
||||
{
|
||||
securityDefinitions: {
|
||||
api_key: {
|
||||
type: :apiKey,
|
||||
name: 'api_key',
|
||||
in: :query
|
||||
components: {
|
||||
securitySchemes: {
|
||||
api_key: {
|
||||
type: :apiKey,
|
||||
name: 'api_key',
|
||||
in: :query
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -204,7 +204,10 @@ module Rswag
|
||||
|
||||
context 'basic auth' do
|
||||
before do
|
||||
swagger_doc[:securityDefinitions] = { basic: { type: :basic } }
|
||||
swagger_doc[:components] = { securitySchemes: {
|
||||
basic: { type: :basic }
|
||||
}
|
||||
}
|
||||
metadata[:operation][:security] = [basic: []]
|
||||
allow(example).to receive(:Authorization).and_return('Basic foobar')
|
||||
end
|
||||
@ -216,7 +219,10 @@ module Rswag
|
||||
|
||||
context 'apiKey' 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: []]
|
||||
allow(example).to receive(:api_key).and_return('foobar')
|
||||
end
|
||||
@ -257,7 +263,10 @@ module Rswag
|
||||
|
||||
context 'oauth2' 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']]
|
||||
allow(example).to receive(:Authorization).and_return('Bearer foobar')
|
||||
end
|
||||
@ -269,9 +278,10 @@ module Rswag
|
||||
|
||||
context 'paired security requirements' do
|
||||
before do
|
||||
swagger_doc[:securityDefinitions] = {
|
||||
basic: { type: :basic },
|
||||
api_key: { type: :apiKey, name: 'api_key', in: :query }
|
||||
swagger_doc[:components] = { securitySchemes: {
|
||||
basic: { type: :basic },
|
||||
api_key: { type: :apiKey, name: 'api_key', in: :query }
|
||||
}
|
||||
}
|
||||
metadata[:operation][:security] = [{ basic: [], api_key: [] }]
|
||||
allow(example).to receive(:Authorization).and_return('Basic foobar')
|
||||
@ -327,7 +337,7 @@ module Rswag
|
||||
|
||||
context 'global security requirements' 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: []]
|
||||
allow(example).to receive(:api_key).and_return('foobar')
|
||||
end
|
||||
|
||||
@ -11,7 +11,7 @@ module Rswag
|
||||
allow(config).to receive(:get_swagger_doc).and_return(swagger_doc)
|
||||
end
|
||||
let(:config) { double('config') }
|
||||
let(:swagger_doc) { {:components => {}} }
|
||||
let(:swagger_doc) {{}}
|
||||
let(:example) { double('example') }
|
||||
let(:metadata) do
|
||||
{
|
||||
@ -58,13 +58,7 @@ module Rswag
|
||||
|
||||
context 'referenced schemas' do
|
||||
before do
|
||||
# swagger_doc[:definitions] = {
|
||||
# 'blog' => {
|
||||
# type: :object,
|
||||
# properties: { foo: { type: :string } },
|
||||
# required: ['foo']
|
||||
# }
|
||||
# }
|
||||
swagger_doc[:components] = {}
|
||||
swagger_doc[:components][:schemas] = {
|
||||
'blog' => {
|
||||
type: :object,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user