Skip to content

Commit

Permalink
added data example removing read_only data
Browse files Browse the repository at this point in the history
  • Loading branch information
Mario.RuizSanchez committed Mar 21, 2019
1 parent e3c836b commit 9c329ea
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
26 changes: 23 additions & 3 deletions lib/open_api_import.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ def self.from(swagger_file, create_method_name: :operation_id, include_responses
method_name = cont[:operationId]
end
end

path_txt = path.path.dup.to_s
if [:path, :path_file, :tags, :tags_file].include?(name_for_module)
old_module_requests = module_requests
Expand Down Expand Up @@ -457,6 +456,27 @@ def self.from(swagger_file, create_method_name: :operation_id, include_responses
output << "},"
end
end
unless data_read_only.empty? or !data_required.empty?
reqdata = []
#remove read only fields from :data
data_examples[0].each do |edata|
read_only = false
data_read_only.each do |rdata|
if edata.scan(/^#{rdata}:/).size>0
read_only = true
break
elsif edata.scan(/:/).size==0
break
end
end
reqdata << edata unless read_only
end
unless reqdata.empty?
output << "data: {"
output << reqdata.join(", \n")
output << "},"
end
end
output << "data_examples: ["
data_examples.each do |data|
Expand Down Expand Up @@ -558,12 +578,12 @@ def self.from(swagger_file, create_method_name: :operation_id, include_responses
class << self
# Retrieve the examples from the properties hash
private def get_examples(properties, type=:key_value, remove_read_only=false)
private def get_examples(properties, type=:key_value, remove_readonly=false)
#todo: consider using this method also to get data examples
example = []
example << "{" unless properties.empty? or type==:only_value
properties.each do |prop, val|
unless remove_read_only and val.key?(:readOnly) and val[:readOnly]==true
unless remove_readonly and val.key?(:readOnly) and val[:readOnly]==true
if val.key?(:properties) and !val.key?(:example) and !val.key?(:type)
val[:type]='object'
end
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.7.1'
s.version = '0.7.2'
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

0 comments on commit 9c329ea

Please sign in to comment.