Remove all commented code. Add "nullable"

This commit is contained in:
Greg Myers
2020-04-04 23:37:38 +01:00
parent b158f1e164
commit d644a91da5
11 changed files with 26 additions and 353 deletions

View File

@@ -75,46 +75,6 @@ module Rswag
metadata[:response][:examples] = example
end
## OA3
# # checks the examples in the parameters should be able to add $ref and externalValue examples.
# # This syntax would look something like this in the integration _spec.rb file
# #
# # request_body_json schema: { '$ref' => '#/components/schemas/blog' },
# # examples: [:blog, {name: :external_blog,
# # externalValue: 'http://api.sample.org/myjson_example'},
# # {name: :another_example,
# # '$ref' => '#/components/examples/flexible_blog_example'}]
# # The first value :blog, points to a let param of the same name, and is used to make the request in the
# # integration test (it is used to build the request payload)
# #
# # The second item in the array shows how to add an externalValue for the examples in the requestBody section
# # The third item shows how to add a $ref item that points to the components/examples section of the swagger spec.
# #
# # NOTE: that the externalValue will produce valid example syntax in the swagger output, but swagger-ui
# # will not show it yet
# def merge_other_examples!(example_metadata)
# # example.metadata[:operation][:requestBody][:content]['application/json'][:examples]
# content_node = example_metadata[:operation][:requestBody][:content]['application/json']
# return unless content_node
# external_example = example_metadata[:operation]&.dig(:parameters)&.detect { |p| p[:in] == :body && p[:name].is_a?(Hash) && p[:name][:externalValue] } || {}
# ref_example = example_metadata[:operation]&.dig(:parameters)&.detect { |p| p[:in] == :body && p[:name].is_a?(Hash) && p[:name]['$ref'] } || {}
# examples_node = content_node[:examples] ||= {}
# nodes_to_add = []
# nodes_to_add << external_example unless external_example.empty?
# nodes_to_add << ref_example unless ref_example.empty?
# nodes_to_add.each do |node|
# json_request_examples = examples_node ||= {}
# other_name = node[:name][:name]
# other_key = node[:name][:externalValue] ? :externalValue : '$ref'
# if other_name
# json_request_examples.merge!(other_name => {other_key => node[:param_value]})
# end
# end
# end
def run_test!(&block)
# NOTE: rspec 2.x support
if RSPEC_VERSION < 3
@@ -135,30 +95,6 @@ module Rswag
assert_response_matches_metadata(example.metadata, &block)
example.instance_exec(response, &block) if block_given?
end
## OA3
# after do |example|
# body_parameter = example.metadata[:operation]&.dig(:parameters)&.detect { |p| p[:in] == :body && p[:required] }
# if body_parameter && respond_to?(body_parameter[:name]) && example.metadata[:operation][:requestBody][:content]['application/json']
# # save response examples by default
# if example.metadata[:response][:examples].nil? || example.metadata[:response][:examples].empty?
# example.metadata[:response][:examples] = { 'application/json' => JSON.parse(response.body, symbolize_names: true) } unless response.body.to_s.empty?
# end
# # save request examples using the let(:param_name) { REQUEST_BODY_HASH } syntax in the test
# if response.code.to_s =~ /^2\d{2}$/
# example.metadata[:operation][:requestBody][:content]['application/json'] = { examples: {} } unless example.metadata[:operation][:requestBody][:content]['application/json'][:examples]
# json_request_examples = example.metadata[:operation][:requestBody][:content]['application/json'][:examples]
# json_request_examples[body_parameter[:name]] = { value: send(body_parameter[:name]) }
# example.metadata[:operation][:requestBody][:content]['application/json'][:examples] = json_request_examples
# end
# end
# self.class.merge_other_examples!(example.metadata) if example.metadata[:operation][:requestBody]
# end
end
end
end

View File

@@ -15,9 +15,7 @@ module Rswag
class ExtendedTypeAttribute < JSON::Schema::TypeV4Attribute
def self.validate(current_schema, data, fragments, processor, validator, options = {})
## OA3
# return if data.nil? && (current_schema.schema['nullable'] == true || current_schema.schema['x-nullable'] == true)
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

View File

@@ -196,15 +196,6 @@ module Rswag
body_param = parameters.select { |p| p[:in] == :body }.first
body_param ? example.send(body_param[:name]).to_json : nil
end
## OA3
# def build_json_payload(parameters, example)
# body_param = parameters.select { |p| p[:in] == :body && p[:name].is_a?(Symbol) }.first
# return nil unless body_param
# source_body_param = example.send(body_param[:name]) if body_param[:name] && example.respond_to?(body_param[:name])
# source_body_param ||= body_param[:param_value]
# source_body_param ? source_body_param.to_json : nil
# end
def doc_version(doc)
doc[:openapi] || doc[:swagger] || '3'

View File

@@ -102,17 +102,6 @@ module Rswag
def metadata_to_swagger(metadata)
response_code = metadata[:response][:code]
response = metadata[:response].reject { |k, _v| k == :code }
## OA3
# content_type = metadata[:response][:content].present? ? metadata[:response][:content].keys.first : 'application/json'
# # need to merge in to response
# if response[:examples]&.dig(content_type)
# example = response[:examples].dig(content_type).dup
# schema = response.dig(:content, content_type, :schema)
# new_hash = {example: example}
# new_hash[:schema] = schema if schema
# response.merge!(content: { content_type => new_hash })
# response.delete(:examples)
# end
verb = metadata[:operation][:verb]
operation = metadata[:operation]