open_api_import 0.7.5 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/open_api_import.rb +56 -10
  3. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 54be1f4446f39e542561f15f1e0f650c65f6a1a91a6cad9392e09fa6703b40c9
4
- data.tar.gz: 10f01866d9c18b487fb900b32790f8f0876540ca8959f2a634a7dafec6a2de09
3
+ metadata.gz: 349414f04ac95d62ddc790ed6eb8c78adad89c2eaa3b4f4d406c34c678143680
4
+ data.tar.gz: 5f443ca0d9f463455937d4a3f3fcb2a230a344d740be6ebeb4031bb09774c0a2
5
5
  SHA512:
6
- metadata.gz: fba22a339648c4bf383d459149f7554bb52309811232be5887a2e634a6666794163f73fccb76ca62d820aabd0a754b90523e9671bc3ce20e2a295acb88cca386
7
- data.tar.gz: 3c370e6567c8eb3efa75c6e45509bd273dd5399ceec382c1cd26337e8115346ff4076aa703aeb4e24622e5d5aaf758a0278b4da26a2fecf97598ce60fed10328
6
+ metadata.gz: a75dc6469b177d39a3e7682ccd7b51ebe61d95ae038f3f0e61e0e99bc7c2444a3002636794f9888d3ef8714b354cc3b7f4360bc8a9bca0d2c66c3a155a1dbb4d
7
+ data.tar.gz: 944f57ff3070edc0c17c49af937288861f695ff632dfb9e3b08a85edee5e0e1987c6365bbb7c6b3e430935f5212f156f9af5d7a77584c8295d33de7371e2f208
@@ -217,11 +217,10 @@ class OpenApiImport
217
217
  if include_responses && cont.key?(:responses) && cont[:responses].is_a?(Hash)
218
218
  cont[:responses].each do |k, v|
219
219
  response_example = []
220
-
221
220
  response_example = get_response_examples(v)
221
+ data_pattern += get_patterns(k, v[:schema]) if v.key?(:schema)
222
222
  v[:description] = v[:description].to_s.gsub("'", %q(\\\'))
223
223
 
224
-
225
224
  if !response_example.empty?
226
225
  responses << "'#{k}': { "
227
226
  responses << "message: '#{v[:description]}', "
@@ -325,14 +324,9 @@ class OpenApiImport
325
324
  if dpv.keys.include?(:description)
326
325
  description_parameters << "# #{dpk}: (#{dpv[:type]}) #{dpv[:description]}"
327
326
  end
328
- if dpv.keys.include?(:pattern)
329
- #todo: control better the cases with back slashes
330
- if dpv[:pattern].include?('\\/')
331
- data_pattern << "#{dpk}: //"
332
- else
333
- data_pattern << "#{dpk}: /#{dpv[:pattern].to_s.gsub("\\/", "\/")}/"
334
- end
335
- end
327
+
328
+ data_pattern += get_patterns(dpk,dpv)
329
+
336
330
  if dpv.keys.include?(:readOnly) and dpv[:readOnly] == true
337
331
  data_read_only << dpk
338
332
  end
@@ -795,6 +789,58 @@ class OpenApiImport
795
789
  return data_required
796
790
  end
797
791
 
792
+ # Get patterns
793
+ private def get_patterns(dpk, dpv)
794
+ data_pattern = []
795
+
796
+ if dpv.keys.include?(:pattern)
797
+ #todo: control better the cases with back slashes
798
+ if dpv[:pattern].include?('\\/')
799
+ data_pattern << "#{dpk}: //"
800
+ else
801
+ data_pattern << "#{dpk}: /#{dpv[:pattern].to_s.gsub("\\/", "\/")}/"
802
+ end
803
+ elsif dpv.key?(:minLength) and dpv.key?(:maxLength)
804
+ data_pattern << "#{dpk}: :'#{dpv[:minLength]}-#{dpv[:maxLength]}:TN'"
805
+ elsif dpv.key?(:minLength) and !dpv.key?(:maxLength)
806
+ data_pattern << "#{dpk}: :'#{dpv[:minLength]}:TN'"
807
+ elsif !dpv.key?(:minLength) and dpv.key?(:maxLength)
808
+ data_pattern << "#{dpk}: :'0-#{dpv[:maxLength]}:TN'"
809
+ elsif dpv.key?(:minimum) and dpv.key?(:maximum) and dpv[:type]=='string'
810
+ data_pattern << "#{dpk}: :'#{dpv[:minimum]}-#{dpv[:maximum]}:TN'"
811
+ elsif dpv.key?(:minimum) and dpv.key?(:maximum)
812
+ data_pattern << "#{dpk}: #{dpv[:minimum]}..#{dpv[:maximum]}"
813
+ elsif dpv.key?(:minimum) and !dpv.key?(:maximum)
814
+ if RUBY_VERSION >= '2.6.0'
815
+ data_pattern << "#{dpk}: #{dpv[:minimum]}.."
816
+ else
817
+ data_pattern << "##{dpk}: #{dpv[:minimum]}.. # INFINITE only working on ruby>=2.6.0"
818
+ end
819
+ elsif !dpv.key?(:minimum) and dpv.key?(:maximum)
820
+ data_pattern << "#{dpk}: 0..#{dpv[:maximum]}"
821
+ elsif dpv.key?(:enum)
822
+ data_pattern << "#{dpk}: :'#{dpv[:enum].join('|')}'"
823
+ elsif dpv[:format] == 'date-time'
824
+ data_pattern << "#{dpk}: DateTime"
825
+ elsif dpv[:type] == 'boolean'
826
+ data_pattern << "#{dpk}: Boolean"
827
+ elsif dpv[:type] == 'array' and dpv.key?(:items) and dpv[:items].is_a?(Hash) and dpv[:items].key?(:enum) and dpv[:items][:enum].is_a?(Array)
828
+ #{:title=>"Balala", :type=>"array", :items=>{:type=>"string", :enum=>["uno","dos"], :example=>"uno"}}
829
+ data_pattern << "#{dpk}: [:'#{dpv[:items][:enum].join('|')}']"
830
+ elsif dpv[:type] == 'array' and dpv.key?(:items) and dpv[:items].is_a?(Hash) and !dpv[:items].key?(:enum) and dpv[:items].key?(:properties)
831
+ #{:title=>"Balala", :type=>"array", :items=>{title: 'xxxx, properties: {server: {enum:['ibm','msa','pytan']}}}
832
+ dpv[:items][:properties].each do |dpkk,dpvv|
833
+ data_pattern += get_patterns(dpkk,dpvv)
834
+ end
835
+ elsif dpv[:type] == 'object' and dpv.key?(:properties)
836
+ dpv[:properties].each do |dpkk,dpvv|
837
+ data_pattern += get_patterns(dpkk,dpvv)
838
+ end
839
+ end
840
+ return data_pattern
841
+
842
+ end
843
+
798
844
  #filter hash
799
845
  private def filter(hash, keys)
800
846
  result = {}
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.7.5
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mario Ruiz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-18 00:00:00.000000000 Z
11
+ date: 2019-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oas_parser
@@ -59,7 +59,7 @@ dependencies:
59
59
  version: '1.12'
60
60
  - - ">="
61
61
  - !ruby/object:Gem::Version
62
- version: 1.12.8
62
+ version: 1.12.12
63
63
  type: :runtime
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
@@ -69,7 +69,7 @@ dependencies:
69
69
  version: '1.12'
70
70
  - - ">="
71
71
  - !ruby/object:Gem::Version
72
- version: 1.12.8
72
+ version: 1.12.12
73
73
  - !ruby/object:Gem::Dependency
74
74
  name: rspec
75
75
  requirement: !ruby/object:Gem::Requirement