mirror of
https://github.com/ditkrg/rswag.git
synced 2026-01-25 07:16:40 +00:00
Initial commit for trying to produce and consume v3 swagger
This commit is contained in:
@@ -35,6 +35,14 @@ module Rswag
|
||||
end
|
||||
end
|
||||
|
||||
#TODO: look at adding request_body method to handle diffs in Open API 2.0 to 3.0
|
||||
# https://swagger.io/docs/specification/describing-request-body/
|
||||
# need to make sure we output requestBody in the swagger generator .json
|
||||
# also need to make sure that it can handle content: , required: true/false, schema: ref
|
||||
|
||||
|
||||
|
||||
|
||||
def parameter(attributes)
|
||||
if attributes[:in] && attributes[:in].to_sym == :path
|
||||
attributes[:required] = true
|
||||
|
||||
@@ -15,7 +15,7 @@ module Rswag
|
||||
class ExtendedTypeAttribute < JSON::Schema::TypeV4Attribute
|
||||
|
||||
def self.validate(current_schema, data, fragments, processor, validator, options={})
|
||||
return if data.nil? && current_schema.schema['x-nullable'] == true
|
||||
return if data.nil? && (current_schema.schema['nullable'] == true || current_schema.schema['x-nullable'] == true)
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
@@ -39,7 +39,7 @@ module Rswag
|
||||
def derive_security_params(metadata, swagger_doc)
|
||||
requirements = metadata[:operation][:security] || swagger_doc[:security] || []
|
||||
scheme_names = requirements.flat_map { |r| r.keys }
|
||||
schemes = (swagger_doc[:securityDefinitions] || {}).slice(*scheme_names).values
|
||||
schemes = (swagger_doc[:components][:securitySchemes] || {}).slice(*scheme_names).values
|
||||
|
||||
schemes.map do |scheme|
|
||||
param = (scheme[:type] == :apiKey) ? scheme.slice(:name, :in) : { name: 'Authorization', in: :header }
|
||||
|
||||
@@ -41,9 +41,12 @@ module Rswag
|
||||
response_schema = metadata[:response][:schema]
|
||||
return if response_schema.nil?
|
||||
|
||||
components_schemas = {components: {schemas: swagger_doc[:components][:schemas]}}
|
||||
|
||||
validation_schema = response_schema
|
||||
.merge('$schema' => 'http://tempuri.org/rswag/specs/extended_schema')
|
||||
.merge(swagger_doc.slice(:definitions))
|
||||
.merge(components_schemas)
|
||||
|
||||
errors = JSON::Validator.fully_validate(validation_schema, body)
|
||||
raise UnexpectedResponse, "Expected response body to match schema: #{errors[0]}" if errors.any?
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user