swagalicious 0.4.2 → 0.4.3

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: fc2174d33212b6196c1cfa15e022cd1e3c9d6f2633b6f6ad6c56cc4506895b82
4
- data.tar.gz: 3a67216c81d671a023969138a24fdf5f0a3dfc20ec468a07abf1ce4b4dbb3892
3
+ metadata.gz: 07172e8767c218c6fa083315bd673c0a44e2b58e1a6895498494dc94c254dbd6
4
+ data.tar.gz: 89f1919937bcbd9bf1d19c8908d3627740436628ff12445bc9749ec547a44c3c
5
5
  SHA512:
6
- metadata.gz: 51bc671599f979b41ef407a3b4d2936a3ec133efe6df7c2b6a51b1ad92a5c98850d5226908ed66cbac0ef183bbddbc542e1505f1777ed02c9153b4d7a90324fe
7
- data.tar.gz: d3db035d1bc8e6d37fd934be9ed7cbd93809c469a761fa1133080b2ad4faf7be3016655f8f88453c5bbd7e34989bd29003901e5ee8aa5b09f8928e24ac194d5a
6
+ metadata.gz: fc08b4023572d0da49587efdcadd66ca490df1474adfb6e522f07f326c9214f2d26d3ae751774a1335c7a21349efe178c8fe5ba989b8ae440a3b8c012179c7d4
7
+ data.tar.gz: 6399f42ccf024d8add0ef4b181eba92f4bd520b634c194a22cc5337216989e35cb1dca1cafa166e3c192a15a0059de86f015045d6537d40219b5f284f27c0690
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- swagalicious (0.4.2)
4
+ swagalicious (0.4.3)
5
5
  faraday (~> 1.3.0)
6
6
  json-schema (~> 2.8.1)
7
7
  oj (~> 3.11.0)
@@ -36,7 +36,7 @@ GEM
36
36
  method_source (1.0.0)
37
37
  minitest (5.14.3)
38
38
  multipart-post (2.1.1)
39
- oj (3.11.0)
39
+ oj (3.11.3)
40
40
  pry (0.13.1)
41
41
  coderay (~> 1.1)
42
42
  method_source (~> 1.0)
@@ -78,4 +78,4 @@ DEPENDENCIES
78
78
  swagalicious!
79
79
 
80
80
  BUNDLED WITH
81
- 2.2.6
81
+ 2.2.16
@@ -52,16 +52,22 @@ class Swagalicious
52
52
  metadata[:paths] ||= []
53
53
  metadata[:paths] << request[:path]
54
54
 
55
- if request[:payload]
56
- metadata[:response][:request] = Oj.load(request[:payload])
57
- end
58
-
59
- metadata[:response][:examples] ||= {}
55
+ metadata[:response][:requestBody] ||= {}
56
+ metadata[:response][:examples] ||= {}
60
57
 
61
58
  mime_types = metadata[:response][:produces] || ["application/json"]
62
59
  full_title = metadata[:swagger_example_name] || "#{metadata[:operation][:summary]}: #{metadata[:description]}"
63
60
 
64
61
  mime_types.each do |mime_type|
62
+ if request[:payload]
63
+ metadata[:response][:requestBody][:content] ||= {}
64
+ metadata[:response][:requestBody][:content][mime_type] ||= {}
65
+ metadata[:response][:requestBody][:content][mime_type][:examples] ||= {}
66
+ metadata[:response][:requestBody][:content][mime_type][:examples][full_title] ||= {}
67
+
68
+ metadata[:response][:requestBody][:content][mime_type][:examples][full_title][:value] = Oj.load(request[:payload]).dup
69
+ end
70
+
65
71
  metadata[:response][:examples][mime_type] ||= {}
66
72
  metadata[:response][:examples][mime_type][full_title] = @body
67
73
  end
@@ -31,27 +31,6 @@ class Swagalicious
31
31
  upgrade_response_produces!(doc, metadata)
32
32
  upgrade_request_type!(metadata)
33
33
 
34
- unless doc_version(doc).start_with?("2")
35
- doc[:paths]&.each_pair do |_k, v|
36
- v.each_pair do |_verb, value|
37
- is_hash = value.is_a?(Hash)
38
- if is_hash && value.dig(:parameters)
39
- schema_param = value.dig(:parameters)&.find { |p| (p[:in] == :body || p[:in] == :formData) && p[:schema] }
40
- mime_list = value.dig(:consumes)
41
- if value && schema_param && mime_list
42
- value[:requestBody] = { content: {} } unless value.dig(:requestBody, :content)
43
- mime_list.each do |mime|
44
- value[:requestBody][:content][mime] = { schema: schema_param[:schema] }
45
- end
46
- end
47
-
48
- value[:parameters].reject! { |p| p[:in] == :body || p[:in] == :formData }
49
- end
50
- remove_invalid_operation_keys!(value)
51
- end
52
- end
53
- end
54
-
55
34
  doc.deep_merge!(metadata_to_swagger(metadata))
56
35
  end
57
36
 
@@ -93,6 +72,7 @@ class Swagalicious
93
72
  response_code = metadata[:response][:code]
94
73
  response = metadata[:response].reject { |k, _v| k == :code }
95
74
  examples = response.delete(:examples) || []
75
+ body = response.delete(:requestBody) || {}
96
76
 
97
77
  examples.each do |mime_type, titles|
98
78
  titles.each do |title, example|
@@ -111,6 +91,20 @@ class Swagalicious
111
91
  .reject { |k, _v| k == :verb }
112
92
  .merge(responses: { response_code => response })
113
93
 
94
+ is_hash = operation.is_a?(Hash)
95
+ if is_hash && operation.dig(:parameters)
96
+ schema_param = operation.dig(:parameters)&.find { |p| (p[:in] == :body || p[:in] == :formData) && p[:schema] }
97
+ mime_list = operation.dig(:consumes)
98
+ if operation && schema_param && mime_list
99
+ operation[:requestBody] = { content: {} }
100
+ mime_list.each do |mime|
101
+ operation[:requestBody][:content][mime] = { schema: schema_param[:schema] }.merge((body.dig(:content, mime) || {}))
102
+ end
103
+ end
104
+
105
+ operation[:parameters].reject! { |p| p[:in] == :body || p[:in] == :formData }
106
+ end
107
+
114
108
  path_template = metadata[:path_item][:template]
115
109
  path_item = metadata[:path_item]
116
110
  .reject { |k, _v| k == :template }
@@ -1,3 +1,3 @@
1
1
  class Swagalicious
2
- VERSION = "0.4.2"
2
+ VERSION = "0.4.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swagalicious
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eugene Howe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-25 00:00:00.000000000 Z
11
+ date: 2021-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday