swagger-dsl 1.5.1 → 2.0.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: 786aa5eea8ae2c2ce700f8c9bf9777da355f5647788d0fd7a1756316017bc182
4
- data.tar.gz: 879edc53b7549aa2d194428cdc66f94080adc7c1e306c9aa6d67612606d4639c
3
+ metadata.gz: 0705c9ed69ca2d85b649a9303ffedf6994945ceb125223d83d2a69b41f25b6c4
4
+ data.tar.gz: 8c36b3e9c7a2cfa3d259ab601ace110a204305306e9456950a1589dd6ee04da3
5
5
  SHA512:
6
- metadata.gz: f3462fb293dfb7f055d80ec3d027a2b33c9d5a973c84a0aaa2b84c566e7587bbfaa456a0e17e24321e1d525e22356314e9aa203d58f5c33ffac6d47d90d0f0e3
7
- data.tar.gz: eb112da3508f85283177a6bdfb375f487880b5f32a2c18f301d21f4f221981fe7cf3e42c84f868e933032254fa944d790618be327ceba1648d1b183be79d2df0
6
+ metadata.gz: cb8144de2b171a95c8a8ed1bd0ad49c0ada18ef8e4c997824b3c829fe68202ee8c5163686aae8a2b3c1d24f0d518e0edc84207d021517107eaca70d39c34bc56
7
+ data.tar.gz: e66d3beadaada0b4623d7506a05a6ba8843fdf0f8f5229c0ea7e4eee81d7d3242cba700a77d2caa1e620ce0987294d1742a51718606c3668706dad990bcb6c1d
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 2.0.2
4
+
5
+ - fix: unique operation id
6
+
7
+ ## 2.0.1
8
+
9
+ - fix(brake): nested class naming
10
+
11
+ ## 2.0.0
12
+
13
+ - fix(brake): adjust to OAS3 spec
14
+
3
15
  ## 1.4.0
4
16
 
5
17
  - add: lazy_define_paths for Rails eager_load
@@ -18,7 +18,7 @@ module Swagger
18
18
  private
19
19
 
20
20
  def serializer_name(name)
21
- name.to_s.sub(/(?:Serializer)?$/, "Serializer")
21
+ name.to_s.gsub(/-/, '::').sub(/(?:Serializer)?$/, "Serializer")
22
22
  end
23
23
  end
24
24
  end
@@ -13,7 +13,7 @@ module Swagger
13
13
  )
14
14
  @inject_key = inject_key
15
15
  @default_dsl = default_dsl
16
- @dsl_options ||= { reference_name: ->(name) { name.sub(/Serializer$/, "") } }
16
+ @dsl_options ||= { reference_name: ->(name) { name.sub(/Serializer$/, "").gsub(/::/, '-') } }
17
17
  @eager = eager
18
18
  @default_required = default_required
19
19
  @lazy_define_paths = lazy_define_paths
@@ -5,7 +5,7 @@ module Jimmy
5
5
  class SchemaCreation
6
6
  module Referencing
7
7
  def component(id)
8
- name = "#/components/#{id}"
8
+ name = "#/components/schemas/#{id}"
9
9
  reference_name = Swagger::DSL.current.config.dsl_options[:reference_name]
10
10
  reference_name ? reference_name.call(name) : name
11
11
  end
@@ -16,7 +16,6 @@ module Swagger
16
16
 
17
17
  def initialize(operation_id, format: :json, &block)
18
18
  self["operationId"] = operation_id
19
- self["requestBody"] = { "content" => {}, "required" => true }
20
19
  self["responses"] = {}
21
20
  self["parameters"] = []
22
21
  self["tags"] = []
@@ -42,20 +41,24 @@ module Swagger
42
41
 
43
42
  def body(format: @format, dsl: nil, &block)
44
43
  formats(format).each do |f|
44
+ self["requestBody"] ||= { "required" => true }
45
+ self["requestBody"]["content"] ||= {}
45
46
  self["requestBody"]["content"][f] = { "schema" => Swagger::DSL::JsonSchema.by(dsl).dsl(&block) }
46
47
  end
47
48
  end
48
49
 
49
50
  def body_description(body_description = nil)
51
+ self["requestBody"] ||= { "required" => true }
50
52
  self["requestBody"]["description"] = body_description
51
53
  end
52
54
 
53
55
  def body_optional(optional = true)
56
+ self["requestBody"] ||= {}
54
57
  self["requestBody"]["required"] = optional
55
58
  end
56
59
 
57
60
  def render(code = 200, format: @format, dsl: nil, &block)
58
- self["responses"][code] ||= { "content" => {} }
61
+ self["responses"][code] ||= { "content" => {}, "description" => "#{code}" }
59
62
  formats(format).each do |f|
60
63
  self["responses"][code]["content"][f] = { "schema" => Swagger::DSL::JsonSchema.by(dsl).dsl(&block) }
61
64
  end
@@ -17,8 +17,6 @@ module Swagger
17
17
  end
18
18
 
19
19
  def swagger_define_path(action, format = :json, path: nil, method: nil, &block)
20
- operation_id = "#{name}##{action}"
21
-
22
20
  defaults = { action: action.to_s, controller: name.underscore.sub(/_controller$/, "") }
23
21
  route = Rails.application.routes.routes.routes.find { |r| r.required_defaults == defaults }
24
22
  unless route
@@ -32,6 +30,7 @@ module Swagger
32
30
  method = %w[put patch] if %w[put patch].include?(method)
33
31
  path ||= route.path.spec.to_s.sub("(.:format)", "").gsub(/:(\w+)/, "{\\1}")
34
32
 
33
+ operation_id = "#{name}##{action}.#{method}"
35
34
  operation = Swagger::DSL::Operation.new(operation_id, format: format, &block)
36
35
  Swagger::DSL.current["paths"][path] ||= {}
37
36
  Array(method).each { |single_method| Swagger::DSL.current["paths"][path][single_method] = operation }
@@ -5,8 +5,8 @@ module Swagger
5
5
  class DSL < Hash
6
6
  module Serializer
7
7
  def swagger(dsl: nil, &block)
8
- name = self.name.sub(/Serializer$/, "")
9
- Swagger::DSL.current["components"][name] =
8
+ name = self.name.sub(/Serializer$/, "").gsub(/::/, '-')
9
+ Swagger::DSL.current["components"]["schemas"][name] =
10
10
  Swagger::DSL::JsonSchema.by(dsl).dsl(&block).merge(Swagger::DSL.current.config.inject_key => name)
11
11
  end
12
12
 
@@ -1,5 +1,5 @@
1
1
  module Swagger
2
2
  class DSL < Hash
3
- VERSION = "1.5.1".freeze
3
+ VERSION = "2.0.2".freeze
4
4
  end
5
5
  end
data/lib/swagger/dsl.rb CHANGED
@@ -20,9 +20,10 @@ module Swagger
20
20
  def initialize(schema = nil, config: Config.new)
21
21
  merge!(schema || {})
22
22
  self["openapi"] ||= "3.0.0"
23
- self["info"] ||= {}
23
+ self["info"] ||= { "title" => "OpenAPI schema", "version" => "0.0.0" }
24
24
  self["paths"] ||= {}
25
- self["components"] = Components[self["components"] || {}]
25
+ self["components"] ||= {}
26
+ self["components"]["schemas"] = Components[self["components"]["schemas"] || {}]
26
27
  @config = config
27
28
  @define_paths_procs = []
28
29
  end
data/swagger-dsl.gemspec CHANGED
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
28
28
  spec.require_paths = %w[lib]
29
29
 
30
30
  spec.add_dependency "jimmy", "~> 0.5"
31
- spec.add_dependency "json-schema-subset-dsl", "~> 1.2"
31
+ spec.add_dependency "json-schema-subset-dsl", "~> 2.0"
32
32
  spec.add_dependency "hana", "~> 1.3"
33
33
  spec.add_dependency "json_refs", "~> 0.1"
34
34
  spec.add_dependency "activesupport", ">= 4.0.2"
@@ -42,4 +42,6 @@ Gem::Specification.new do |spec|
42
42
  spec.add_development_dependency "rubocop-config-prettier", "~> 0.1"
43
43
  spec.add_development_dependency "yard", "~> 0.9"
44
44
  spec.add_development_dependency "pry-byebug", "~> 3.7"
45
+ spec.add_development_dependency "json_spec", "~> 1"
46
+ spec.add_development_dependency "openapi3_parser", "~> 0.9.1"
45
47
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swagger-dsl
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Narazaka
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-19 00:00:00.000000000 Z
11
+ date: 2022-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jimmy
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.2'
33
+ version: '2.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.2'
40
+ version: '2.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: hana
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -220,7 +220,35 @@ dependencies:
220
220
  - - "~>"
221
221
  - !ruby/object:Gem::Version
222
222
  version: '3.7'
223
- description:
223
+ - !ruby/object:Gem::Dependency
224
+ name: json_spec
225
+ requirement: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - "~>"
228
+ - !ruby/object:Gem::Version
229
+ version: '1'
230
+ type: :development
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - "~>"
235
+ - !ruby/object:Gem::Version
236
+ version: '1'
237
+ - !ruby/object:Gem::Dependency
238
+ name: openapi3_parser
239
+ requirement: !ruby/object:Gem::Requirement
240
+ requirements:
241
+ - - "~>"
242
+ - !ruby/object:Gem::Version
243
+ version: 0.9.1
244
+ type: :development
245
+ prerelease: false
246
+ version_requirements: !ruby/object:Gem::Requirement
247
+ requirements:
248
+ - - "~>"
249
+ - !ruby/object:Gem::Version
250
+ version: 0.9.1
251
+ description:
224
252
  email:
225
253
  - info@narazaka.net
226
254
  executables: []
@@ -264,8 +292,8 @@ metadata:
264
292
  homepage_uri: https://github.com/Narazaka/swagger-dsl
265
293
  source_code_uri: https://github.com/Narazaka/swagger-dsl.git
266
294
  changelog_uri: https://github.com/Narazaka/swagger-dsl/blob/master/CHANGELOG.md
267
- documentation_uri: https://www.rubydoc.info/gems/swagger-dsl/1.5.1
268
- post_install_message:
295
+ documentation_uri: https://www.rubydoc.info/gems/swagger-dsl/2.0.2
296
+ post_install_message:
269
297
  rdoc_options: []
270
298
  require_paths:
271
299
  - lib
@@ -281,7 +309,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
281
309
  version: '0'
282
310
  requirements: []
283
311
  rubygems_version: 3.1.4
284
- signing_key:
312
+ signing_key:
285
313
  specification_version: 4
286
314
  summary: Swagger (OpenAPI 3) DSL
287
315
  test_files: []