swagger-dsl 1.1.0 → 1.2.0

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: df246a1f449c1cb5be1e6d1353bd3a5f04863471ebc6e742d1474bb8f320729d
4
- data.tar.gz: e7b9841234c25d9c0c44171cadfcdc2768cae499c1969e74569d7b8f25fd5369
3
+ metadata.gz: b131abdb9e40b72e5958ab7c2a7e34b42cf21e162ef01726feab2585b1e6e450
4
+ data.tar.gz: dec48a00848fc65cf08fa11ebb4369cfa9793491ea10884bc472eb848ddeee06
5
5
  SHA512:
6
- metadata.gz: 33920f490f0899e4ec4a2fd1b5d25a53ead73b1e20712b7cbaf3ed9998d2af84abb9c77fa89f669ae858a0b9487a0c8335bdd81556f6edabb7f9b113704a9b01
7
- data.tar.gz: 71319ffb954af6404a9eac5618f89a81d3d00c5d7b7c45959891bfa3560aa7d0b8d505fcdf96937d19f9cf10c0eeeb186b1c6cd908a359e69d8ce8cf877c6f15
6
+ metadata.gz: 5ab34c7b9ca4de4d1dd3eb8bcabfdfb06a6090d6c3cace125abe1d67511bc00c876303bce1f2825a70e5573b737477f8c849e8d4539478c3bcfe5187e0f34a10
7
+ data.tar.gz: da64cb44e3c4bee8ee6f4249be6393c86b181729fc2cf48e245279f94c883df775a9234f90ede60c35862e3051296b86ffdf8d376084aab398c68a8e85156f23
@@ -1,9 +1,13 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.2.0
4
+
5
+ - mod(brake): params default required
6
+
3
7
  ## 1.1.0
4
8
 
5
- - add: multiple format accept in params
6
- - add: form shortcut in params format
9
+ - add: multiple format accept
10
+ - add: form shortcut in format
7
11
 
8
12
  ## 1.0.0
9
13
 
@@ -1,13 +1,14 @@
1
1
  module Swagger
2
2
  class DSL
3
3
  class Config
4
- attr_accessor :inject_key, :default_dsl, :dsl_options, :eager
4
+ attr_accessor :inject_key, :default_dsl, :dsl_options, :eager, :default_required
5
5
 
6
- def initialize(inject_key: "title", default_dsl: nil, dsl_options: nil, eager: false)
6
+ def initialize(inject_key: "title", default_dsl: nil, dsl_options: nil, eager: false, default_required: true)
7
7
  @inject_key = inject_key
8
8
  @default_dsl = default_dsl
9
9
  @dsl_options ||= { reference_name: ->(name) { name.sub(/Serializer$/, "") } }
10
10
  @eager = eager
11
+ @default_required = default_required
11
12
  end
12
13
  end
13
14
  end
@@ -1,5 +1,6 @@
1
1
  require_relative "./json_schema"
2
2
  require_relative "./parameters"
3
+ require_relative "../dsl"
3
4
 
4
5
  module Swagger
5
6
  class DSL
@@ -22,8 +23,8 @@ module Swagger
22
23
  instance_eval(&block)
23
24
  end
24
25
 
25
- def params(&block)
26
- self["parameters"] = Parameters.new(&block)
26
+ def params(default_required: Swagger::DSL.current.config.default_required, &block)
27
+ self["parameters"] = Parameters.new(default_required: default_required, &block)
27
28
  end
28
29
 
29
30
  def body(format: @format, dsl: nil, &block)
@@ -3,11 +3,14 @@ require_relative "./json_schema"
3
3
  module Swagger
4
4
  class DSL
5
5
  class Parameter < Hash
6
- def initialize(*args, &block)
6
+ def initialize(options, *args, &block)
7
+ @default_required = options[:default_required]
8
+ self["required"] = true if @default_required
7
9
  unless args.empty?
8
10
  self["name"] = args.first
9
11
  args[1..-1].each { |arg| merge!(arg.map { |k, v| [k.to_s, v] }.to_h) }
10
12
  canonical_schema!
13
+ delete("required") unless self["required"]
11
14
  end
12
15
  instance_eval(&block) if block_given?
13
16
  end
@@ -17,10 +20,18 @@ module Swagger
17
20
  canonical_schema!
18
21
  end
19
22
 
20
- %w[description required deprecated allowEmptyValue style explode allowReserved example examples].each do |name|
23
+ %w[description deprecated allowEmptyValue style explode allowReserved example examples].each do |name|
21
24
  define_method(name) { |value| self[name] = value }
22
25
  end
23
26
 
27
+ def required(value)
28
+ if value
29
+ self["required"] = true
30
+ else
31
+ delete("required")
32
+ end
33
+ end
34
+
24
35
  private
25
36
 
26
37
  def canonical_schema!
@@ -3,14 +3,14 @@ require_relative "./parameters_in_type"
3
3
  module Swagger
4
4
  class DSL
5
5
  class Parameters < Array
6
- def initialize(format: :json, &block)
7
- @format = format
6
+ def initialize(default_required:, &block)
7
+ @default_required = default_required
8
8
  instance_eval(&block)
9
9
  end
10
10
 
11
11
  %i[path query header cookie].each do |in_type|
12
12
  define_method(in_type) do |*args, &block|
13
- args.empty? ? ParametersInType.new(self, in_type, &block) : self << Parameter.new(*args, in: in_type, &block)
13
+ args.empty? ? ParametersInType.new(self, in_type, { default_required: @default_required }, &block) : self << Parameter.new({ default_required: @default_required }, *args, in: in_type, &block)
14
14
  end
15
15
  end
16
16
  end
@@ -3,9 +3,10 @@ require_relative "./parameter"
3
3
  module Swagger
4
4
  class DSL < Hash
5
5
  class ParametersInType
6
- def initialize(parent, type, &block)
6
+ def initialize(parent, type, parameter_options, &block)
7
7
  @parent = parent
8
8
  @type = type
9
+ @parameter_options = parameter_options
9
10
  instance_eval(&block)
10
11
  end
11
12
 
@@ -14,7 +15,7 @@ module Swagger
14
15
  end
15
16
 
16
17
  def method_missing(name, *args, &block)
17
- @parent << Parameter.new(name, *args, in: @type, &block)
18
+ @parent << Parameter.new(@parameter_options, name, *args, in: @type, &block)
18
19
  end
19
20
  end
20
21
  end
@@ -1,5 +1,5 @@
1
1
  module Swagger
2
2
  class DSL < Hash
3
- VERSION = "1.1.0".freeze
3
+ VERSION = "1.2.0".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swagger-dsl
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Narazaka
@@ -264,7 +264,7 @@ metadata:
264
264
  homepage_uri: https://github.com/Narazaka/swagger-dsl
265
265
  source_code_uri: https://github.com/Narazaka/swagger-dsl.git
266
266
  changelog_uri: https://github.com/Narazaka/swagger-dsl/blob/master/CHANGELOG.md
267
- documentation_uri: https://www.rubydoc.info/gems/swagger-dsl/1.1.0
267
+ documentation_uri: https://www.rubydoc.info/gems/swagger-dsl/1.2.0
268
268
  post_install_message:
269
269
  rdoc_options: []
270
270
  require_paths: