Skip to content

Commit

Permalink
bugfix on data examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Mario.RuizSanchez committed Feb 5, 2019
1 parent feedae7 commit c64e534
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 11 deletions.
12 changes: 9 additions & 3 deletions lib/open_api_import.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,15 @@ def self.from(swagger_file, create_method_name: :operation_id, include_responses
module_requests = ""

definition.paths.each do |path|

raw = path.raw.deep_symbolize_keys

if raw.key?(:parameters)
raw.each do |met, cont|
if met != :parameters
if raw[met].key?(:parameters)
raw[met][:parameters] = raw[met][:parameters] & raw[:parameters]
#todo: check if in some cases the parameters on the method can be added to the ones in the path
#raw[met][:parameters] = raw[met][:parameters] & raw[:parameters]
else
raw[met][:parameters] = raw[:parameters]
end
Expand All @@ -109,6 +111,7 @@ def self.from(swagger_file, create_method_name: :operation_id, include_responses
end

raw.each do |met, cont|

if %w[get post put delete patch].include?(met.to_s.downcase)
params = []
params_path = []
Expand Down Expand Up @@ -186,7 +189,6 @@ def self.from(swagger_file, create_method_name: :operation_id, include_responses

response_example = get_response_examples(v)


if !response_example.empty?
responses << "'#{k}': { "
responses << "message: '#{v[:description]}', "
Expand Down Expand Up @@ -257,7 +259,11 @@ def self.from(swagger_file, create_method_name: :operation_id, include_responses
if dpv.keys.include?(:example)
valv = dpv[:example]
else
valv = ""
if dpv.type == "object"
valv = "{}"
else
valv = ""
end
end
if dpv.keys.include?(:description)
description_parameters << "# #{dpk}: (#{dpv[:type]}) #{dpv[:description]}"
Expand Down
2 changes: 1 addition & 1 deletion open_api_import.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = 'open_api_import'
s.version = '0.2.2'
s.version = '0.2.3'
s.summary = "OpenApiImport -- Import a Swagger or Open API file and create a Ruby Request Hash file including all requests and responses with all the examples. The file can be in JSON or YAML"
s.description = "OpenApiImport -- Import a Swagger or Open API file and create a Ruby Request Hash file including all requests and responses with all the examples. The file can be in JSON or YAML"
s.authors = ["Mario Ruiz"]
Expand Down
10 changes: 4 additions & 6 deletions spec/fixtures/v3.0/petstore-expanded.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,10 @@ paths:
responses:
'200':
description: pet response
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Pet'
schema:
type: array
items:
$ref: 'responses/Pet.yaml'
default:
description: unexpected error
content:
Expand Down
12 changes: 12 additions & 0 deletions spec/fixtures/v3.0/responses/Pet.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
allOf:
- required:
- id
- name
properties:
id:
type: integer
format: int64
name:
type: string
tag:
type: string
1 change: 0 additions & 1 deletion spec/open_api_import/open_api_import_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
RSpec.describe OpenApiImport do

describe '#from' do

it 'creates a log file if swagger_file is a valid string for a file name' do
file_name = 'example.yaml'
File.delete("#{file_name}_open_api_import.log") if File.exist?("#{file_name}_open_api_import.log")
Expand Down

0 comments on commit c64e534

Please sign in to comment.