apia-open_api 0.1.2 → 0.1.4
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/README.md +4 -8
- data/lib/apia/open_api/objects/response.rb +29 -13
- 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: f046cce05d4154ba36e9f52227306129ef092e75061db7a522b44ade60b252c0
|
4
|
+
data.tar.gz: 2c56c6cedf8281819ca4c6382159183cdcc0c550d27375410f7f39cfe4bb842a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c60e070b4a683379b689fff7c95ba8a7aa6ea9f2902e13b68474190b2aac234feec2428c73871591b467af2ba17be21c2dcb6d8b2297014a88e1ec783311472
|
7
|
+
data.tar.gz: afce3695675df681249591575c3704161caa3dd66b91a67e89bc67e58b07d45d8d6445e0080f7264c2a0fb234f1a03f87eec97aeeba22e39bf873f991b38452b
|
data/README.md
CHANGED
@@ -2,17 +2,13 @@
|
|
2
2
|
|
3
3
|
This gem can generate an [OpenAPI](https://www.openapis.org/) compatible schema from an API implemented using [Apia](https://github.com/krystal/apia).
|
4
4
|
|
5
|
-
|
5
|
+
This gem is in the early phases of development and breaking changes may be introduced whilst the gem is in the 0.1.x version range.
|
6
6
|
|
7
|
-
|
7
|
+
## Installation
|
8
8
|
|
9
9
|
Install the gem and add to the application's Gemfile by executing:
|
10
10
|
|
11
|
-
$ bundle add
|
12
|
-
|
13
|
-
If bundler is not being used to manage dependencies, install the gem by executing:
|
14
|
-
|
15
|
-
$ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
|
11
|
+
$ bundle add apia-open_api
|
16
12
|
|
17
13
|
## Usage
|
18
14
|
|
@@ -85,7 +81,7 @@ You can also run `bin/console` for an interactive prompt that will allow you to
|
|
85
81
|
|
86
82
|
## Releasing a new version
|
87
83
|
|
88
|
-
|
84
|
+
[Release Please](https://github.com/googleapis/release-please) is configured. The [convential commits](https://www.conventionalcommits.org/en/v1.0.0/) format should be used and upon merging to main, Release Please will open a new PR following semver rules. When that Release Please PR is merged, a new version will be published to RubyGems.
|
89
85
|
|
90
86
|
## Contributing
|
91
87
|
|
@@ -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,16 +220,17 @@ 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
|
-
generate_short_error_ref(http_status_code, definitions, api_authenticator_error_defs)
|
233
|
+
generate_short_error_ref(suffix, http_status_code, definitions, api_authenticator_error_defs)
|
233
234
|
end
|
234
235
|
end
|
235
236
|
|
@@ -238,7 +239,7 @@ module Apia
|
|
238
239
|
# If this is too long, we use only the first and last two error names. Error names are sorted
|
239
240
|
# alphabetically, which should ensure we do not generate the same ID to represent different sets of errors.
|
240
241
|
# 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
|
+
def generate_short_error_ref(suffix, http_status_code, definitions, api_authenticator_error_defs)
|
242
243
|
generated_ids = (definitions - api_authenticator_error_defs).map do |d|
|
243
244
|
generate_id_from_definition(d)
|
244
245
|
end.sort
|
@@ -248,7 +249,7 @@ module Apia
|
|
248
249
|
[
|
249
250
|
(sliced_ids || generated_ids).join,
|
250
251
|
http_status_code,
|
251
|
-
|
252
|
+
suffix.first(3)
|
252
253
|
].flatten.join("_").camelize
|
253
254
|
end
|
254
255
|
|
@@ -282,16 +283,31 @@ module Apia
|
|
282
283
|
component_schema
|
283
284
|
end
|
284
285
|
|
286
|
+
# We want to declare the code in the error response as an enum, with only
|
287
|
+
# one possible value, as this makes it explicit to the client what the
|
288
|
+
# value will be.
|
289
|
+
#
|
290
|
+
# However, the code field is not defined as an Enum scalar within Apia,
|
291
|
+
# so we generate an Enum definition "on the fly" here.
|
292
|
+
#
|
293
|
+
# This means we can add a schema for the enum and a related $ref, which
|
294
|
+
# helps prompt client generators to generate an explicit enum type for the code.
|
295
|
+
# Otherwise if we generate the enum 'inline' in the response, some client generators
|
296
|
+
# will not generate an enum type for the code.
|
285
297
|
def generate_schema_properties_for_definition(definition)
|
286
|
-
|
298
|
+
id = generate_id_from_definition(definition)
|
299
|
+
detail_ref = generate_schema_ref(definition, id: id)
|
300
|
+
|
301
|
+
code_enum_id = "#{id}Enum"
|
302
|
+
code_enum_field_definition = Definitions::Field.new(:enum, id: code_enum_id)
|
303
|
+
code_enum_field_definition.type = Class.new(Apia::Enum) { value(definition.code) }
|
304
|
+
code_ref = generate_schema_ref(code_enum_field_definition, id: code_enum_id)
|
305
|
+
|
287
306
|
{
|
288
307
|
properties: {
|
289
|
-
code:
|
290
|
-
type: "string",
|
291
|
-
enum: [definition.code]
|
292
|
-
},
|
308
|
+
code: code_ref,
|
293
309
|
description: { type: "string" },
|
294
|
-
detail:
|
310
|
+
detail: detail_ref
|
295
311
|
}
|
296
312
|
}
|
297
313
|
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.
|
4
|
+
version: 0.1.4
|
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-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|