open_api_import 0.10.3 → 0.10.8
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.
- checksums.yaml +4 -4
- data/lib/open_api_import.rb +45 -20
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8cfae7bbbbe63a987babdbbc219b357dd9352cb8a24944045512f45cc43be396
|
4
|
+
data.tar.gz: 9fd701d2e6031121bf36bb16870a1ce27b912b08392a535b64df1758e9b71c70
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f851adec79aa6e12aeb3c7cb51736735249b80299142b0f32f4e790ae18be3452e3e55a248c5e8c5a81544df34a99c7cf4fb486a1df03c119f035fca8aefbc83
|
7
|
+
data.tar.gz: 7b8006104b05632049383690c0114fd5594cdbe89ef8172e2bbe4063dc2ebd47f77a81d2d36bdace45af58f0cd82afe5aba909883725b6a041ca2dc504c5fbe2
|
data/lib/open_api_import.rb
CHANGED
@@ -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
|
@@ -361,11 +369,22 @@ class OpenApiImport
|
|
361
369
|
end
|
362
370
|
end
|
363
371
|
if dpv.keys.include?(:description)
|
364
|
-
description_parameters << "# #{dpk}: (#{dpv[:type]}) #{dpv[:description]}"
|
372
|
+
description_parameters << "# #{dpk}: (#{dpv[:type]}) #{dpv[:description].split("\n").join("\n#\t\t\t")}"
|
365
373
|
end
|
366
374
|
|
367
375
|
data_pattern += get_patterns(dpk,dpv)
|
368
376
|
data_pattern.uniq!
|
377
|
+
dpkeys = []
|
378
|
+
data_pattern.reject! do |dp|
|
379
|
+
dpkey = dp.scan(/^'[\w\.]+'/)
|
380
|
+
|
381
|
+
if dpkeys.include?(dpkey)
|
382
|
+
true
|
383
|
+
else
|
384
|
+
dpkeys << dpkey
|
385
|
+
false
|
386
|
+
end
|
387
|
+
end
|
369
388
|
|
370
389
|
if dpv.keys.include?(:readOnly) and dpv[:readOnly] == true
|
371
390
|
data_read_only << dpk
|
@@ -380,17 +399,19 @@ class OpenApiImport
|
|
380
399
|
end
|
381
400
|
end
|
382
401
|
|
383
|
-
|
384
|
-
|
402
|
+
#todo: consider check default and insert it
|
403
|
+
#todo: remove array from here and add the option to get_examples for the case thisisthekey: ['xxxx']
|
404
|
+
if dpv.key?(:type) and dpv[:type]!='array'
|
405
|
+
params_data << get_examples({dpk => dpv}, :only_value, true).join
|
406
|
+
params_data[-1].chop!.chop! if params_data[-1].to_s[-2..-1]==', '
|
407
|
+
params_data.pop if params_data[-1].match?(/^\s*$/im)
|
385
408
|
else
|
386
|
-
#todo: consider check default and insert it
|
387
409
|
if valv.to_s == ""
|
388
410
|
valv = '"' + valv + '"'
|
389
411
|
end
|
412
|
+
params_data << "#{dpk}: #{valv}"
|
390
413
|
end
|
391
|
-
params_data << "#{dpk}: #{valv}"
|
392
414
|
}
|
393
|
-
|
394
415
|
if params_data.size > 0
|
395
416
|
if data_examples_all_of == true and data_examples.size > 0
|
396
417
|
data_examples[0]+=params_data
|
@@ -706,30 +727,32 @@ class OpenApiImport
|
|
706
727
|
end
|
707
728
|
|
708
729
|
if val.key?(:items) and val[:items].key?(:enum)
|
730
|
+
#before we were getting in all these cases a random value from the enum, now we are getting the first position by default
|
731
|
+
#the reason is to avoid confusion later in case we want to compare two swaggers and verify the changes
|
709
732
|
if type==:only_value
|
710
733
|
if val[:items][:enum][0].is_a?(String)
|
711
|
-
example << " [\"" + val[:items][:enum]
|
734
|
+
example << " [\"" + val[:items][:enum][0] + "\"] "
|
712
735
|
else
|
713
|
-
example << " [" + val[:items][:enum]
|
736
|
+
example << " [" + val[:items][:enum][0] + "] "
|
714
737
|
end
|
715
738
|
else
|
716
739
|
if val[:items][:enum][0].is_a?(String)
|
717
|
-
example << " #{prop.to_sym}: [\"" + val[:items][:enum]
|
740
|
+
example << " #{prop.to_sym}: [\"" + val[:items][:enum][0] + "\"], "
|
718
741
|
else
|
719
|
-
example << " #{prop.to_sym}: [" + val[:items][:enum]
|
742
|
+
example << " #{prop.to_sym}: [" + val[:items][:enum][0] + "], "
|
720
743
|
end
|
721
744
|
end
|
722
745
|
else
|
723
746
|
#todo: differ between response examples and data examples
|
724
747
|
if type == :only_value
|
725
|
-
example << get_response_examples({schema: val}).join("\n")
|
748
|
+
example << get_response_examples({schema: val}, remove_readonly).join("\n")
|
726
749
|
else
|
727
|
-
example << " #{prop.to_sym}: " + get_response_examples({schema: val}).join("\n") + ", "
|
750
|
+
example << " #{prop.to_sym}: " + get_response_examples({schema: val}, remove_readonly).join("\n") + ", "
|
728
751
|
end
|
729
752
|
end
|
730
753
|
when "object"
|
731
754
|
#todo: differ between response examples and data examples
|
732
|
-
res_ex = get_response_examples({schema: val})
|
755
|
+
res_ex = get_response_examples({schema: val}, remove_readonly)
|
733
756
|
if res_ex.size == 0
|
734
757
|
res_ex = "{ }"
|
735
758
|
else
|
@@ -747,7 +770,7 @@ class OpenApiImport
|
|
747
770
|
end
|
748
771
|
|
749
772
|
# Retrieve the response examples from the hash
|
750
|
-
private def get_response_examples(v)
|
773
|
+
private def get_response_examples(v, remove_readonly = false)
|
751
774
|
# TODO: take in consideration the case allOf, oneOf... schema.items.allOf[0].properties schema.items.allOf[1].properties
|
752
775
|
# example on https://github.com/OAI/OpenAPI-Specification/blob/master/examples/v2.0/yaml/petstore-expanded.yaml
|
753
776
|
v=v.dup
|
@@ -757,7 +780,6 @@ class OpenApiImport
|
|
757
780
|
v[:content][:'application/json'].key?(:schema)
|
758
781
|
v=v[:content][:'application/json'].dup
|
759
782
|
end
|
760
|
-
|
761
783
|
if v.key?(:examples) && v[:examples].is_a?(Hash) && v[:examples].key?(:'application/json')
|
762
784
|
if v[:examples][:'application/json'].is_a?(String)
|
763
785
|
response_example << v[:examples][:'application/json']
|
@@ -809,9 +831,9 @@ class OpenApiImport
|
|
809
831
|
end
|
810
832
|
elsif v.key?(:schema) && v[:schema].is_a?(Hash) &&
|
811
833
|
(v[:schema].key?(:properties) ||
|
812
|
-
|
813
|
-
|
814
|
-
|
834
|
+
(v[:schema].key?(:items) && v[:schema][:items].key?(:properties)) ||
|
835
|
+
(v[:schema].key?(:items) && v[:schema][:items].key?(:allOf)) ||
|
836
|
+
v[:schema].key?(:allOf))
|
815
837
|
properties = {}
|
816
838
|
if v[:schema].key?(:properties)
|
817
839
|
properties = v[:schema][:properties]
|
@@ -829,7 +851,7 @@ class OpenApiImport
|
|
829
851
|
response_example << "["
|
830
852
|
end
|
831
853
|
|
832
|
-
response_example += get_examples(properties) unless properties.empty?
|
854
|
+
response_example += get_examples(properties, :key_value, remove_readonly) unless properties.empty?
|
833
855
|
|
834
856
|
unless response_example.empty?
|
835
857
|
if v[:schema].key?(:properties) || v[:schema].key?(:allOf)
|
@@ -898,7 +920,6 @@ class OpenApiImport
|
|
898
920
|
# Get patterns
|
899
921
|
private def get_patterns(dpk, dpv)
|
900
922
|
data_pattern = []
|
901
|
-
|
902
923
|
if dpv.keys.include?(:pattern)
|
903
924
|
#todo: control better the cases with back slashes
|
904
925
|
if dpv[:pattern].include?('\\\\/')
|
@@ -943,6 +964,10 @@ class OpenApiImport
|
|
943
964
|
data_pattern += get_patterns("#{dpk}.#{dpkk}",dpvv)
|
944
965
|
end
|
945
966
|
end
|
967
|
+
elsif dpv[:type] == 'array' and dpv.key?(:items) and dpv[:items].is_a?(Hash) and
|
968
|
+
!dpv[:items].key?(:enum) and !dpv[:items].key?(:properties) and dpv[:items].key?(:type)
|
969
|
+
#{:title=>"labels", :description=>"Labels specified for the file system", :type=>"array", :items=>{:type=>"string", :enum=>["string"]}}
|
970
|
+
data_pattern << "'#{dpk}': [ #{get_patterns('', dpv[:items]).join[4..-1]} ]"
|
946
971
|
elsif dpv[:type] == 'object' and dpv.key?(:properties)
|
947
972
|
dpv[:properties].each do |dpkk,dpvv|
|
948
973
|
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.
|
4
|
+
version: 0.10.8
|
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-
|
11
|
+
date: 2020-11-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oas_parser
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0.
|
19
|
+
version: '0.25'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0.
|
26
|
+
version: '0.25'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rufo
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '1.
|
47
|
+
version: '1.17'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '1.
|
54
|
+
version: '1.17'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|