apia-open_api 0.1.1 → 0.1.2

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: 34c08e44efe16ad5c8c47e58621d9d416433e8aa16d65c9d250a9b7154ce4d93
4
- data.tar.gz: cf33503d1e4ee2c028c9b62902d718eee5fc7ca4c80e936a1bf8dbed032c1335
3
+ metadata.gz: e088b172e1ebbabca8a2520ecb0958e3663bc36231a84f06191057500fb9ca60
4
+ data.tar.gz: ea8b66ea6a4bcd2fe9a8fb94c632034ae6166c49e9a22c75469fe5a8d93d9a2f
5
5
  SHA512:
6
- metadata.gz: 207a6efc59f1c89c5505e21e75a2fd456e5b1603eb4eafafb4d93052fc61f28dca62e1c9daa6edabe36cc8db75f3728db61213a214dc4dd31d332048c34e3c33
7
- data.tar.gz: 33455542c2d48abd6a0b7c1e3fd9881ba3fe03780f76d68cdc2ea248ef25040035023b43d50378e92ac543e491a6a2c481d3333b722367f0e164e4d4e4b6e658
6
+ metadata.gz: 16d96e51f64037afe00b2b8dcddedfb0f1aa9f98d4bbb9effab44094b3db1d82aa4351cbab692002f36a60ee2727a16ebf7557f5a5e906bd4f6ae25590bc113d
7
+ data.tar.gz: 7e18b018812c02900b10b1948e27c9b631cd8099beab1c1f1880557b0c4b7d1173d6204a77c55a355f5bb9c1de20ff6925980e4c0ec8c1f2c649c38acfa3dfb9
@@ -99,15 +99,33 @@ module Apia
99
99
  end
100
100
  end
101
101
 
102
- id = "#{@route.request_method}:#{result_parts.join('_')}"
103
- if @path_ids.include?(id)
104
- id = "#{@route.request_method}:#{@route.path}"
105
- end
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
@@ -229,16 +229,29 @@ module Apia
229
229
  elsif definitions.length == 1
230
230
  "#{generate_id_from_definition(definitions.first)}Response"
231
231
  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
232
+ generate_short_error_ref(http_status_code, definitions, api_authenticator_error_defs)
239
233
  end
240
234
  end
241
235
 
236
+ # When we have multiple errors for the same http status code, we need to generate a unique ID.
237
+ # By default we join all the error names together, with the http status code and camelize them.
238
+ # If this is too long, we use only the first and last two error names. Error names are sorted
239
+ # alphabetically, which should ensure we do not generate the same ID to represent different sets of errors.
240
+ # The length is important because the rubygems gem builder imposes a 100 character limit on filenames.
241
+ def generate_short_error_ref(http_status_code, definitions, api_authenticator_error_defs)
242
+ generated_ids = (definitions - api_authenticator_error_defs).map do |d|
243
+ generate_id_from_definition(d)
244
+ end.sort
245
+ if generated_ids.join.length > 80
246
+ sliced_ids = [generated_ids.first] + generated_ids[-2..]
247
+ end
248
+ [
249
+ (sliced_ids || generated_ids).join,
250
+ http_status_code,
251
+ "Error"
252
+ ].flatten.join("_").camelize
253
+ end
254
+
242
255
  def add_to_responses_components(http_status_code, definitions, id)
243
256
  return unless @spec.dig(:components, :components, id).nil?
244
257
 
@@ -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: "#{@id}_#{child.name}".camelize,
154
+ id: "#{truncated_id}Part_#{child.name}".camelize,
150
155
  endpoint: @endpoint,
151
156
  path: child_path
152
157
  )
@@ -3,7 +3,7 @@
3
3
  module Apia
4
4
  module OpenApi
5
5
 
6
- VERSION = "0.1.1"
6
+ VERSION = "0.1.2"
7
7
 
8
8
  end
9
9
  end
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.1
4
+ version: 0.1.2
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-06 00:00:00.000000000 Z
11
+ date: 2023-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport