apia-open_api 0.1.1 → 0.1.3
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/apia/open_api/objects/path.rb +22 -4
- data/lib/apia/open_api/objects/response.rb +25 -11
- data/lib/apia/open_api/objects/schema.rb +6 -1
- data/lib/apia/open_api/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a45fd172c715b417ff39eca615ecf87f12b49d68a3a0b005702be43e1cce2b7
|
4
|
+
data.tar.gz: 0bc1c81f27016b6df2085c3968ef1262a8d2630533a6e836bd786940b5c6bb7d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b0c1e241009a2cebd05ad12a654fab114634ebd3a9eb2aa29e7134cbf6c87e6b8ffae9bfa1b62e5339308475b9b610adfae3197bd56450d7bd5b1229ca119e7
|
7
|
+
data.tar.gz: 2650e1efa99461dd62ae0359baee53aa494d312655ead60df13ba4a4384b08461a99c0e8bef9a7ae6d60f6411a12229ff1c36fdb325a45ac168c269da430a397
|
@@ -99,15 +99,33 @@ module Apia
|
|
99
99
|
end
|
100
100
|
end
|
101
101
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
102
|
+
first_part = "#{@route.request_method}:"
|
103
|
+
id = "#{first_part}#{result_parts.join('_')}"
|
104
|
+
|
105
|
+
id = fallback_id(first_part) if @path_ids.include?(id)
|
106
106
|
@path_ids << id
|
107
107
|
|
108
108
|
id
|
109
109
|
end
|
110
110
|
|
111
|
+
# IDs can clash if two paths are different, but generate the same ID.
|
112
|
+
# For example:
|
113
|
+
# - /dns_zones/:dns_zone
|
114
|
+
# - /dns/zones/:dns_zone
|
115
|
+
# When there is a duplicate we fallback to using the path, but as the path
|
116
|
+
# ID is used as the prefix for any $ref IDs, we need to make sure it's not
|
117
|
+
# too long. This is because there is a 100 character filename limit imposed
|
118
|
+
# by the rubygems gem builder.
|
119
|
+
def fallback_id(first_part)
|
120
|
+
last_part = @route.path
|
121
|
+
if last_part.length >= 50
|
122
|
+
last_part = last_part.split(/[_:\/]/).map do |word|
|
123
|
+
word[0]
|
124
|
+
end.join("_")
|
125
|
+
end
|
126
|
+
"#{first_part}#{last_part}"
|
127
|
+
end
|
128
|
+
|
111
129
|
end
|
112
130
|
end
|
113
131
|
end
|
@@ -211,7 +211,7 @@ module Apia
|
|
211
211
|
end
|
212
212
|
|
213
213
|
def generate_ref(namespace, http_status_code, definitions)
|
214
|
-
id = generate_id_for_error_ref(http_status_code, definitions)
|
214
|
+
id = generate_id_for_error_ref(namespace, http_status_code, definitions)
|
215
215
|
if namespace == "responses"
|
216
216
|
add_to_responses_components(http_status_code, definitions, id)
|
217
217
|
else
|
@@ -220,25 +220,39 @@ module Apia
|
|
220
220
|
{ "$ref": "#/components/#{namespace}/#{id}" }
|
221
221
|
end
|
222
222
|
|
223
|
-
def generate_id_for_error_ref(http_status_code, definitions)
|
223
|
+
def generate_id_for_error_ref(namespace, http_status_code, definitions)
|
224
|
+
suffix = namespace == "responses" ? "Response" : "Schema"
|
224
225
|
api_authenticator_error_defs = api_authenticator_potential_errors.map(&:definition).select do |d|
|
225
226
|
d.http_status_code.to_s == http_status_code.to_s
|
226
227
|
end
|
227
228
|
if api_authenticator_error_defs.any? && api_authenticator_error_defs == definitions
|
228
|
-
"APIAuthenticator#{http_status_code}
|
229
|
+
"APIAuthenticator#{http_status_code}#{suffix}"
|
229
230
|
elsif definitions.length == 1
|
230
|
-
"#{generate_id_from_definition(definitions.first)}
|
231
|
+
"#{generate_id_from_definition(definitions.first)}#{suffix}"
|
231
232
|
else
|
232
|
-
|
233
|
-
(definitions - api_authenticator_error_defs).map do |d|
|
234
|
-
generate_id_from_definition(d)
|
235
|
-
end.join,
|
236
|
-
http_status_code,
|
237
|
-
"Response"
|
238
|
-
].flatten.join("_").camelize
|
233
|
+
generate_short_error_ref(suffix, http_status_code, definitions, api_authenticator_error_defs)
|
239
234
|
end
|
240
235
|
end
|
241
236
|
|
237
|
+
# When we have multiple errors for the same http status code, we need to generate a unique ID.
|
238
|
+
# By default we join all the error names together, with the http status code and camelize them.
|
239
|
+
# If this is too long, we use only the first and last two error names. Error names are sorted
|
240
|
+
# alphabetically, which should ensure we do not generate the same ID to represent different sets of errors.
|
241
|
+
# The length is important because the rubygems gem builder imposes a 100 character limit on filenames.
|
242
|
+
def generate_short_error_ref(suffix, http_status_code, definitions, api_authenticator_error_defs)
|
243
|
+
generated_ids = (definitions - api_authenticator_error_defs).map do |d|
|
244
|
+
generate_id_from_definition(d)
|
245
|
+
end.sort
|
246
|
+
if generated_ids.join.length > 80
|
247
|
+
sliced_ids = [generated_ids.first] + generated_ids[-2..]
|
248
|
+
end
|
249
|
+
[
|
250
|
+
(sliced_ids || generated_ids).join,
|
251
|
+
http_status_code,
|
252
|
+
suffix.first(3)
|
253
|
+
].flatten.join("_").camelize
|
254
|
+
end
|
255
|
+
|
242
256
|
def add_to_responses_components(http_status_code, definitions, id)
|
243
257
|
return unless @spec.dig(:components, :components, id).nil?
|
244
258
|
|
@@ -144,9 +144,14 @@ module Apia
|
|
144
144
|
schema[:properties][child.name.to_s] = generate_schema_ref(child)
|
145
145
|
else
|
146
146
|
child_path = @path.nil? ? nil : @path + [child]
|
147
|
+
|
148
|
+
# Nested partial fields in the response have the potential to generate
|
149
|
+
# very long IDs, so we truncate them to avoid hitting the 100 character
|
150
|
+
# filename limit imposed by the rubygems gem builder.
|
151
|
+
truncated_id = @id.match(/^(.*?)\d*?(Response|Part).*$/)[1]
|
147
152
|
schema[:properties][child.name.to_s] = generate_schema_ref(
|
148
153
|
child,
|
149
|
-
id: "#{
|
154
|
+
id: "#{truncated_id}Part_#{child.name}".camelize,
|
150
155
|
endpoint: @endpoint,
|
151
156
|
path: child_path
|
152
157
|
)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apia-open_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Sturgess
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-12-
|
11
|
+
date: 2023-12-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|