open_api_import 0.10.4 → 0.10.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/open_api_import.rb +14 -13
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 49208568b77f0a0a4a4577918618d82ed6d685617d69cb5e2ea548c1abce0d36
4
- data.tar.gz: 10d64714deb8b8229102ba47116f69abd36b0732a534caf0aefd5e8c01a2c272
3
+ metadata.gz: bf4a735fd2ca50a6f7d5070a96fef58896e1783834f586548deb943cee3aac49
4
+ data.tar.gz: 148fca2cc536cd64fbe1b70d21f902810659d67579922ae04cfaeda621400f17
5
5
  SHA512:
6
- metadata.gz: a6d6a075fb6c4156b8983b41f2904c95aadb7d364745a97085d9caf1552ecb8e84a059f6a39c8517cc6695ec53401b0ebdd67bda9e65675e88071bb3e871c194
7
- data.tar.gz: ae9083df4898a3d262e7ba32d789dba2c7a818bab646a47237455327b8362876cb27b5ec700f1a0d78c85fd3bf10d008a734a71f84387b50a1b8e620d4009374
6
+ metadata.gz: d31884dda9909b9e6bba2eec6fbfb83967a8d3d4b35e5e0826027e066a2f42c7a496d021257ec905f1b54a47da3e05177dab7bd3d7a8d0ba9ea3547edbd52166
7
+ data.tar.gz: 0c35baa4265c34312f2c2b6866a7197ecb3403a230dccdba20b03f04282674e3e97b6c1f80fd4142862788a351b759802a172a880b967de1e95a357a17cc9471
@@ -388,15 +388,17 @@ class OpenApiImport
388
388
  end
389
389
  end
390
390
 
391
- if dpv.key?(:type) and dpv[:type].downcase == "string"
392
- valv = '"' + valv + '"'
391
+ #todo: consider check default and insert it
392
+ if dpv.key?(:type)
393
+ params_data << get_examples({dpk => dpv}, :only_value, true).join
394
+ params_data[-1].chop!.chop! if params_data[-1].to_s[-2..-1]==', '
395
+ params_data.pop if params_data[-1].match?(/^\s*$/im)
393
396
  else
394
- #todo: consider check default and insert it
395
397
  if valv.to_s == ""
396
398
  valv = '"' + valv + '"'
397
399
  end
400
+ params_data << "#{dpk}: #{valv}"
398
401
  end
399
- params_data << "#{dpk}: #{valv}"
400
402
  }
401
403
 
402
404
  if params_data.size > 0
@@ -730,14 +732,14 @@ class OpenApiImport
730
732
  else
731
733
  #todo: differ between response examples and data examples
732
734
  if type == :only_value
733
- example << get_response_examples({schema: val}).join("\n")
735
+ example << get_response_examples({schema: val}, remove_readonly).join("\n")
734
736
  else
735
- example << " #{prop.to_sym}: " + get_response_examples({schema: val}).join("\n") + ", "
737
+ example << " #{prop.to_sym}: " + get_response_examples({schema: val}, remove_readonly).join("\n") + ", "
736
738
  end
737
739
  end
738
740
  when "object"
739
741
  #todo: differ between response examples and data examples
740
- res_ex = get_response_examples({schema: val})
742
+ res_ex = get_response_examples({schema: val}, remove_readonly)
741
743
  if res_ex.size == 0
742
744
  res_ex = "{ }"
743
745
  else
@@ -755,7 +757,7 @@ class OpenApiImport
755
757
  end
756
758
 
757
759
  # Retrieve the response examples from the hash
758
- private def get_response_examples(v)
760
+ private def get_response_examples(v, remove_readonly = false)
759
761
  # TODO: take in consideration the case allOf, oneOf... schema.items.allOf[0].properties schema.items.allOf[1].properties
760
762
  # example on https://github.com/OAI/OpenAPI-Specification/blob/master/examples/v2.0/yaml/petstore-expanded.yaml
761
763
  v=v.dup
@@ -765,7 +767,6 @@ class OpenApiImport
765
767
  v[:content][:'application/json'].key?(:schema)
766
768
  v=v[:content][:'application/json'].dup
767
769
  end
768
-
769
770
  if v.key?(:examples) && v[:examples].is_a?(Hash) && v[:examples].key?(:'application/json')
770
771
  if v[:examples][:'application/json'].is_a?(String)
771
772
  response_example << v[:examples][:'application/json']
@@ -817,9 +818,9 @@ class OpenApiImport
817
818
  end
818
819
  elsif v.key?(:schema) && v[:schema].is_a?(Hash) &&
819
820
  (v[:schema].key?(:properties) ||
820
- (v[:schema].key?(:items) && v[:schema][:items].key?(:properties)) ||
821
- (v[:schema].key?(:items) && v[:schema][:items].key?(:allOf)) ||
822
- v[:schema].key?(:allOf))
821
+ (v[:schema].key?(:items) && v[:schema][:items].key?(:properties)) ||
822
+ (v[:schema].key?(:items) && v[:schema][:items].key?(:allOf)) ||
823
+ v[:schema].key?(:allOf))
823
824
  properties = {}
824
825
  if v[:schema].key?(:properties)
825
826
  properties = v[:schema][:properties]
@@ -837,7 +838,7 @@ class OpenApiImport
837
838
  response_example << "["
838
839
  end
839
840
 
840
- response_example += get_examples(properties) unless properties.empty?
841
+ response_example += get_examples(properties, :key_value, remove_readonly) unless properties.empty?
841
842
 
842
843
  unless response_example.empty?
843
844
  if v[:schema].key?(:properties) || v[:schema].key?(:allOf)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: open_api_import
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.4
4
+ version: 0.10.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mario Ruiz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-08 00:00:00.000000000 Z
11
+ date: 2020-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oas_parser