apiculture 0.2.0 → 0.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d78cc86595f72f0ec4ea08adaa5b545798eb54653aafedb47d3e6923351b3b76
4
- data.tar.gz: 532aa3794d65dfd962d4d5984a29678e026b5da43efd1f5ad5dbaea4d4ee6ff1
3
+ metadata.gz: bd3d6da6eca1e6a1c63d824bfbed2d43d2a74032f966dc6f17df09c6458548c8
4
+ data.tar.gz: 53581729f4b81574b5bc400786509cfa6f9364fde56486611ae8eab8c3370f8e
5
5
  SHA512:
6
- metadata.gz: b351b52e4a10c1c7ee2b7d4f7b5c8f63d4ed8b28f65348ebf63ec0f064ccb55b9bfd6cad6f21d49c34867436dfc50036e67f4d8fdb206f3525581346ee7db3a8
7
- data.tar.gz: 9a0d97711023461335d4237f44e077daf2b1669c9509bb53dcd79571fb8a157188fb06b9d93db28ab9df69f170d152c50746ce8c27f73eb2af7781963d8e26bf
6
+ metadata.gz: c2f325148ce9a454206d278f665b583fbd896b442d5f07eecfef481a43143299001c3097eceaf37e2d61866f8f06e5523677ffcad031a9a5811419ce7f84ee9e
7
+ data.tar.gz: 97159d92a46fef3e7c093c87ce4b80e783a4610c073857f80c74205ddfcabc7d6b019d3d29b1b2a66d5fd2a6fff92a2fef9f2d3c910dc62478613d42e692dabe
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
1
  ## 0.2.0
2
2
  * Add ruby 3 support
3
3
  * Bump `mustermann` dependency to '~> 3'
4
+
5
+
6
+ ## 0.2.1
7
+ * Add support for nested fields
@@ -8,9 +8,9 @@ module OpenApiDocumentation
8
8
  @paths = chunks.select { |chunk| chunk.respond_to?(:http_verb) }
9
9
  @data = {
10
10
  openapi: '3.0.0',
11
- info: {
12
- title: @app.to_s,
13
- version: '0.0.1',
11
+ info: {
12
+ title: @app.to_s,
13
+ version: '0.0.1',
14
14
  description: @app.to_s + " " + chunks.select { |chunk| chunk.respond_to?(:to_markdown) }.map(&:to_markdown).join("\n")
15
15
  },
16
16
  tags: []
@@ -27,7 +27,7 @@ module OpenApiDocumentation
27
27
  end
28
28
 
29
29
  def spec
30
- @data
30
+ @data
31
31
  end
32
32
 
33
33
  private
@@ -137,7 +137,7 @@ module OpenApiDocumentation
137
137
 
138
138
  def build_request_body
139
139
  return nil if VERBS_WITHOUT_BODY.include?(@path.http_verb)
140
-
140
+
141
141
  body_params = Hash[ @path.parameters.collect do |parameter|
142
142
  [parameter.name, {
143
143
  type: Util.map_type(parameter.matchable),
@@ -171,7 +171,7 @@ module OpenApiDocumentation
171
171
  unless response.jsonable_object_example.nil? || response.jsonable_object_example.empty?
172
172
  _response[:content] = {
173
173
  'application/json': {
174
- schema:
174
+ schema:
175
175
  { type: 'object',
176
176
  properties: Util.response_to_schema(response.jsonable_object_example) }
177
177
  }
@@ -198,15 +198,27 @@ module OpenApiDocumentation
198
198
  }.freeze
199
199
 
200
200
  def self.response_to_schema(response)
201
- schema = {}
202
- return nil if response.nil? || response.empty? || response.class == String
203
- response.each do |key, value|
204
- schema[key] = {
205
- type: 'string',
206
- example: value.to_s
207
- }
201
+ case response
202
+ when NilClass
203
+ when String
204
+ { type: 'string', example: response }
205
+ when Integer
206
+ { type: 'integer', example: response }
207
+ when Float
208
+ { type: 'float', example: response }
209
+ when Array
210
+ if response.empty?
211
+ { type: 'array', items: {} }
212
+ else
213
+ { type: 'array', items: response.map { |elem| response_to_schema(elem) } }
214
+ end
215
+ when Hash
216
+ response.each_with_object({}) do |(key, val), schema_hash|
217
+ schema_hash[key] = response_to_schema(val)
218
+ end
219
+ else
220
+ { type: response.class.name.downcase, example: response.to_s }
208
221
  end
209
- schema
210
222
  end
211
223
 
212
224
  def self.map_type(type)
@@ -1,3 +1,3 @@
1
1
  module Apiculture
2
- VERSION = '0.2.0'.freeze
2
+ VERSION = '0.2.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apiculture
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julik Tarkhanov
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-02-08 00:00:00.000000000 Z
12
+ date: 2023-11-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: builder
@@ -216,7 +216,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
216
216
  - !ruby/object:Gem::Version
217
217
  version: '0'
218
218
  requirements: []
219
- rubygems_version: 3.2.33
219
+ rubygems_version: 3.4.6
220
220
  signing_key:
221
221
  specification_version: 4
222
222
  summary: Sweet API sauce on top of Rack