apia-open_api 0.1.3 → 0.1.5

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: 3a45fd172c715b417ff39eca615ecf87f12b49d68a3a0b005702be43e1cce2b7
4
- data.tar.gz: 0bc1c81f27016b6df2085c3968ef1262a8d2630533a6e836bd786940b5c6bb7d
3
+ metadata.gz: d7c3d54619c699cf9edca73ebc76e68819c2656f0259adbd6d5e411d4e415ca6
4
+ data.tar.gz: f31e758e511dd57af96896cd9ca956e6455c29747fc8389d5bda59a6c5938f3d
5
5
  SHA512:
6
- metadata.gz: 0b0c1e241009a2cebd05ad12a654fab114634ebd3a9eb2aa29e7134cbf6c87e6b8ffae9bfa1b62e5339308475b9b610adfae3197bd56450d7bd5b1229ca119e7
7
- data.tar.gz: 2650e1efa99461dd62ae0359baee53aa494d312655ead60df13ba4a4384b08461a99c0e8bef9a7ae6d60f6411a12229ff1c36fdb325a45ac168c269da430a397
6
+ metadata.gz: 1f96b6eca24cc4d97d4e248892adf62bce141c4d4cce4697c8141cd1b844465d7ce9ef33036daddee81bf908dd41b4cc1bcad2b4436bc2cd1aef431e8fba8602
7
+ data.tar.gz: 1754bd390af23a0c88658c9a58b7c367f1743df4021a2f47c186720b3b3ff8235be743adaf62d0a3613502ae22267264f6aea71ae44ab716ba5ca8b86257345d
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
- ## Installation
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
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
7
+ ## Installation
8
8
 
9
9
  Install the gem and add to the application's Gemfile by executing:
10
10
 
11
- $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
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
- TODO: Write instructions for releasing a new version of the gem.
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
 
@@ -283,16 +283,31 @@ module Apia
283
283
  component_schema
284
284
  end
285
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.
286
297
  def generate_schema_properties_for_definition(definition)
287
- detail = generate_schema_ref(definition, id: generate_id_from_definition(definition))
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
+
288
306
  {
289
307
  properties: {
290
- code: {
291
- type: "string",
292
- enum: [definition.code]
293
- },
308
+ code: code_ref,
294
309
  description: { type: "string" },
295
- detail: detail
310
+ detail: detail_ref
296
311
  }
297
312
  }
298
313
  end
@@ -40,7 +40,7 @@ module Apia
40
40
  @definition = definition
41
41
  @schema = schema
42
42
  @id = id
43
- @endpoint = endpoint
43
+ @endpoint = endpoint # endpoint gets specified when we are dealing with a partial response
44
44
  @path = path
45
45
  @children = []
46
46
  end
@@ -130,6 +130,10 @@ module Apia
130
130
  schema[:properties][child.name.to_s] = generate_scalar_schema(child)
131
131
  end
132
132
 
133
+ if child.try(:null?)
134
+ schema[:properties][child.name.to_s][:nullable] = true
135
+ end
136
+
133
137
  if child.try(:required?)
134
138
  schema[:required] ||= []
135
139
  schema[:required] << child.name.to_s
@@ -141,7 +145,7 @@ module Apia
141
145
  schema[:type] = "object"
142
146
  schema[:properties] ||= {}
143
147
  if all_properties_included
144
- schema[:properties][child.name.to_s] = generate_schema_ref(child)
148
+ ref = generate_schema_ref(child)
145
149
  else
146
150
  child_path = @path.nil? ? nil : @path + [child]
147
151
 
@@ -149,13 +153,16 @@ module Apia
149
153
  # very long IDs, so we truncate them to avoid hitting the 100 character
150
154
  # filename limit imposed by the rubygems gem builder.
151
155
  truncated_id = @id.match(/^(.*?)\d*?(Response|Part).*$/)[1]
152
- schema[:properties][child.name.to_s] = generate_schema_ref(
156
+ ref = generate_schema_ref(
153
157
  child,
154
158
  id: "#{truncated_id}Part_#{child.name}".camelize,
155
159
  endpoint: @endpoint,
156
160
  path: child_path
157
161
  )
158
162
  end
163
+
164
+ # Using allOf is a workaround to allow us to set a ref as `nullable` in OpenAPI 3.0
165
+ schema[:properties][child.name.to_s] = { allOf: [ref] }
159
166
  end
160
167
 
161
168
  end
@@ -3,7 +3,7 @@
3
3
  module Apia
4
4
  module OpenApi
5
5
 
6
- VERSION = "0.1.3"
6
+ VERSION = "0.1.5"
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.3
4
+ version: 0.1.5
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-13 00:00:00.000000000 Z
11
+ date: 2024-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -70,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
70
70
  - !ruby/object:Gem::Version
71
71
  version: '0'
72
72
  requirements: []
73
- rubygems_version: 3.4.10
73
+ rubygems_version: 3.4.19
74
74
  signing_key:
75
75
  specification_version: 4
76
76
  summary: Apia OpenAPI spec generator