open_api_import 0.10.0 → 0.10.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 34a7117aedab4cd987fe9af035ebb047c04439068aba13fdea8431fc872354f4
4
- data.tar.gz: 3e6517fb5517a848b757e7105306d82a4a5e624771a3a9bfe5835266d42aa336
3
+ metadata.gz: bf4a735fd2ca50a6f7d5070a96fef58896e1783834f586548deb943cee3aac49
4
+ data.tar.gz: 148fca2cc536cd64fbe1b70d21f902810659d67579922ae04cfaeda621400f17
5
5
  SHA512:
6
- metadata.gz: c9c355b6f63e6e9b877aea3e58cc3f48d6c6f472fa7e09bd1d3c4044d8bbb4a0275e8d52044f1d8532a8fe7330651709cdb9ad31e89292b2c5e897c41512211d
7
- data.tar.gz: dfed0eccfe012f5eeaf728f01cacb933c5352368e8811116d7b2d881d781eb3a61fea9035c5354a23cc466b2a299322d30e2dacbd07ef54e7d227173988799f4
6
+ metadata.gz: d31884dda9909b9e6bba2eec6fbfb83967a8d3d4b35e5e0826027e066a2f42c7a496d021257ec905f1b54a47da3e05177dab7bd3d7a8d0ba9ea3547edbd52166
7
+ data.tar.gz: 0c35baa4265c34312f2c2b6866a7197ecb3403a230dccdba20b03f04282674e3e97b6c1f80fd4142862788a351b759802a172a880b967de1e95a357a17cc9471
@@ -69,5 +69,5 @@ if filename.to_s==''
69
69
  puts optparse
70
70
  puts "** Need to specify at least a file to import."
71
71
  else
72
- OpenApiImport.from filename, options
72
+ OpenApiImport.from filename, **options
73
73
  end
@@ -150,6 +150,10 @@ class OpenApiImport
150
150
  elsif create_method_name == :operation_id
151
151
  if (name_for_module == :tags or name_for_module == :tags_file) and cont.key?(:tags) and cont[:tags].is_a?(Array) and cont[:tags].size>0
152
152
  metnametmp = cont[:operationId].gsub(/^#{cont[:tags].join}[\s_]*/, '')
153
+ cont[:tags].join.split(' ').each do |tag|
154
+ metnametmp.gsub!(/^#{tag}[\s_]*/i, '')
155
+ end
156
+ metnametmp = met if metnametmp == ''
153
157
  else
154
158
  metnametmp = cont[:operationId]
155
159
  end
@@ -157,6 +161,10 @@ class OpenApiImport
157
161
  else
158
162
  if (name_for_module == :tags or name_for_module == :tags_file) and cont.key?(:tags) and cont[:tags].is_a?(Array) and cont[:tags].size>0
159
163
  method_name = cont[:operationId].gsub(/^#{cont[:tags].join}[\s_]*/, '')
164
+ cont[:tags].join.split(' ').each do |tag|
165
+ method_name.gsub!(/^#{tag}[\s_]*/i, '')
166
+ end
167
+ method_name = met if method_name == ''
160
168
  else
161
169
  method_name = cont[:operationId]
162
170
  end
@@ -337,7 +345,11 @@ class OpenApiImport
337
345
 
338
346
  body[:properties].each { |dpk, dpv|
339
347
  if dpv.keys.include?(:example)
340
- valv = dpv[:example].to_s
348
+ if dpv[:example].is_a?(Array) and dpv.type != 'array'
349
+ valv = dpv[:example][0]
350
+ else
351
+ valv = dpv[:example].to_s
352
+ end
341
353
  else
342
354
  if dpv.type == "object"
343
355
  if dpv.key?(:properties)
@@ -367,23 +379,28 @@ class OpenApiImport
367
379
  data_read_only << dpk
368
380
  end
369
381
  if dpv.keys.include?(:default)
370
- if dpv.type != "string"
382
+ if dpv[:default].nil?
383
+ data_default << "#{dpk}: nil"
384
+ elsif dpv.type != "string"
371
385
  data_default << "#{dpk}: #{dpv[:default]}"
372
386
  else
373
387
  data_default << "#{dpk}: '#{dpv[:default]}'"
374
388
  end
375
389
  end
376
390
 
377
- if dpv.key?(:type) and dpv[:type].downcase == "string"
378
- 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)
379
396
  else
380
- #todo: consider check default and insert it
381
397
  if valv.to_s == ""
382
398
  valv = '"' + valv + '"'
383
399
  end
400
+ params_data << "#{dpk}: #{valv}"
384
401
  end
385
- params_data << "#{dpk}: #{valv}"
386
402
  }
403
+
387
404
  if params_data.size > 0
388
405
  if data_examples_all_of == true and data_examples.size > 0
389
406
  data_examples[0]+=params_data
@@ -467,7 +484,7 @@ class OpenApiImport
467
484
  paramst.concat params
468
485
  params = paramst
469
486
  end
470
-
487
+ params.uniq!
471
488
  output << "def self.#{method_name} (#{params.join(", ")})"
472
489
 
473
490
  output << "{"
@@ -674,10 +691,14 @@ class OpenApiImport
674
691
  val[:type]='array'
675
692
  end
676
693
  if val.key?(:example)
677
- example << if val[:example].is_a?(String) or val[:example].is_a?(Time)
678
- " #{prop.to_sym}: \"#{val[:example]}\", "
694
+ if val[:example].is_a?(Array) and val.key?(:type) and val[:type]=='string'
695
+ example << " #{prop.to_sym}: \"#{val[:example][0]}\", " # only the first example
679
696
  else
680
- " #{prop.to_sym}: #{val[:example]}, "
697
+ example << if val[:example].is_a?(String) or val[:example].is_a?(Time)
698
+ " #{prop.to_sym}: \"#{val[:example]}\", "
699
+ else
700
+ " #{prop.to_sym}: #{val[:example]}, "
701
+ end
681
702
  end
682
703
  elsif val.key?(:type)
683
704
  format = val[:format]
@@ -711,14 +732,14 @@ class OpenApiImport
711
732
  else
712
733
  #todo: differ between response examples and data examples
713
734
  if type == :only_value
714
- example << get_response_examples({schema: val}).join("\n")
735
+ example << get_response_examples({schema: val}, remove_readonly).join("\n")
715
736
  else
716
- 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") + ", "
717
738
  end
718
739
  end
719
740
  when "object"
720
741
  #todo: differ between response examples and data examples
721
- res_ex = get_response_examples({schema: val})
742
+ res_ex = get_response_examples({schema: val}, remove_readonly)
722
743
  if res_ex.size == 0
723
744
  res_ex = "{ }"
724
745
  else
@@ -736,7 +757,7 @@ class OpenApiImport
736
757
  end
737
758
 
738
759
  # Retrieve the response examples from the hash
739
- private def get_response_examples(v)
760
+ private def get_response_examples(v, remove_readonly = false)
740
761
  # TODO: take in consideration the case allOf, oneOf... schema.items.allOf[0].properties schema.items.allOf[1].properties
741
762
  # example on https://github.com/OAI/OpenAPI-Specification/blob/master/examples/v2.0/yaml/petstore-expanded.yaml
742
763
  v=v.dup
@@ -746,7 +767,6 @@ class OpenApiImport
746
767
  v[:content][:'application/json'].key?(:schema)
747
768
  v=v[:content][:'application/json'].dup
748
769
  end
749
-
750
770
  if v.key?(:examples) && v[:examples].is_a?(Hash) && v[:examples].key?(:'application/json')
751
771
  if v[:examples][:'application/json'].is_a?(String)
752
772
  response_example << v[:examples][:'application/json']
@@ -776,6 +796,7 @@ class OpenApiImport
776
796
  else
777
797
  tresp = ""
778
798
  end
799
+
779
800
  if tresp.is_a?(String)
780
801
  response_example << tresp
781
802
  elsif tresp.is_a?(Hash)
@@ -797,9 +818,9 @@ class OpenApiImport
797
818
  end
798
819
  elsif v.key?(:schema) && v[:schema].is_a?(Hash) &&
799
820
  (v[:schema].key?(:properties) ||
800
- (v[:schema].key?(:items) && v[:schema][:items].key?(:properties)) ||
801
- (v[:schema].key?(:items) && v[:schema][:items].key?(:allOf)) ||
802
- 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))
803
824
  properties = {}
804
825
  if v[:schema].key?(:properties)
805
826
  properties = v[:schema][:properties]
@@ -817,7 +838,7 @@ class OpenApiImport
817
838
  response_example << "["
818
839
  end
819
840
 
820
- response_example += get_examples(properties) unless properties.empty?
841
+ response_example += get_examples(properties, :key_value, remove_readonly) unless properties.empty?
821
842
 
822
843
  unless response_example.empty?
823
844
  if v[:schema].key?(:properties) || v[:schema].key?(:allOf)
@@ -837,7 +858,6 @@ class OpenApiImport
837
858
  rs.gsub!(/@(\w+):/,'\'@\1\':')
838
859
  end
839
860
  end
840
-
841
861
  return response_example
842
862
  end
843
863
 
@@ -887,7 +907,6 @@ class OpenApiImport
887
907
  # Get patterns
888
908
  private def get_patterns(dpk, dpv)
889
909
  data_pattern = []
890
-
891
910
  if dpv.keys.include?(:pattern)
892
911
  #todo: control better the cases with back slashes
893
912
  if dpv[:pattern].include?('\\\\/')
@@ -932,6 +951,10 @@ class OpenApiImport
932
951
  data_pattern += get_patterns("#{dpk}.#{dpkk}",dpvv)
933
952
  end
934
953
  end
954
+ elsif dpv[:type] == 'array' and dpv.key?(:items) and dpv[:items].is_a?(Hash) and
955
+ !dpv[:items].key?(:enum) and !dpv[:items].key?(:properties) and dpv[:items].key?(:type)
956
+ #{:title=>"labels", :description=>"Labels specified for the file system", :type=>"array", :items=>{:type=>"string", :enum=>["string"]}}
957
+ data_pattern << "'#{dpk}': [ #{get_patterns('', dpv[:items]).join[4..-1]} ]"
935
958
  elsif dpv[:type] == 'object' and dpv.key?(:properties)
936
959
  dpv[:properties].each do |dpkk,dpvv|
937
960
  if dpk == ''
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.0
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-03-04 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
@@ -16,60 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.22'
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 0.22.2
19
+ version: '0.25'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
24
  - - "~>"
28
25
  - !ruby/object:Gem::Version
29
- version: '0.22'
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: 0.22.2
26
+ version: '0.25'
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: rufo
35
29
  requirement: !ruby/object:Gem::Requirement
36
30
  requirements:
37
- - - ">="
38
- - !ruby/object:Gem::Version
39
- version: 0.11.0
40
31
  - - "~>"
41
32
  - !ruby/object:Gem::Version
42
- version: '0.11'
33
+ version: '0.12'
43
34
  type: :runtime
44
35
  prerelease: false
45
36
  version_requirements: !ruby/object:Gem::Requirement
46
37
  requirements:
47
- - - ">="
48
- - !ruby/object:Gem::Version
49
- version: 0.11.0
50
38
  - - "~>"
51
39
  - !ruby/object:Gem::Version
52
- version: '0.11'
40
+ version: '0.12'
53
41
  - !ruby/object:Gem::Dependency
54
42
  name: nice_hash
55
43
  requirement: !ruby/object:Gem::Requirement
56
44
  requirements:
57
45
  - - "~>"
58
46
  - !ruby/object:Gem::Version
59
- version: '1.15'
60
- - - ">="
61
- - !ruby/object:Gem::Version
62
- version: 1.15.4
47
+ version: '1.16'
63
48
  type: :runtime
64
49
  prerelease: false
65
50
  version_requirements: !ruby/object:Gem::Requirement
66
51
  requirements:
67
52
  - - "~>"
68
53
  - !ruby/object:Gem::Version
69
- version: '1.15'
70
- - - ">="
71
- - !ruby/object:Gem::Version
72
- version: 1.15.4
54
+ version: '1.16'
73
55
  - !ruby/object:Gem::Dependency
74
56
  name: rspec
75
57
  requirement: !ruby/object:Gem::Requirement