json-schema-subset-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: b477b7c6a66763298840118e09dbeee4c9324bc832eff1e07a790b1307f9309e
4
- data.tar.gz: 4719a5ab55b54b7eeaf73368c91687a0c6c13f3000c8cab7e08b5103bf4f7e2d
3
+ metadata.gz: 5aab5735b6f1fc77fb82cf833b565b7394f064177e0d2608e492de7a66be9bcb
4
+ data.tar.gz: 95ba200fe739435cae6cbc89c1a7a4f663c80ac9c0701c593acfdffc7fa6f6c8
5
5
  SHA512:
6
- metadata.gz: c7b08bca28d96506afba2998ffc0ff009d6e14ba7d0c145b7df7795236c92f39baa976f89261f24998da9fad85e6b2815b58474d8c09031f9e33437accedeb2c
7
- data.tar.gz: 524736dea681839b8ff6da0a38b0229b5b5cecf235d34e50912fa91cc4d050683bc869ab9fbce6ee0d70ebc44619b266fab70113bc9f5b706c1dee7ba84081d9
6
+ metadata.gz: 4b248c05fcc4eb39f9a06550fd11952cc801ba49552c50611b4c77432740528bd7bfd1f23cc9e361e4e4197a63467d08a01b81c40b8a00847c44fc36e3a96f67
7
+ data.tar.gz: 3706692a8b802c78d7666be4042e2b9f0ea2ec62f7901c31da62a26ea34b8fe4f92079cb0af32770da2afa12cd09fd527bdf0e7890b4ee81ce640589e5a8942c
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.2.0
4
+
5
+ - add: reference_name option
6
+
3
7
  ## 1.1.0
4
8
 
5
9
  - scalar value block allowed
data/README.md CHANGED
@@ -26,7 +26,11 @@ Or install it yourself as:
26
26
  ## Usage
27
27
 
28
28
  ```ruby
29
- dsl = Json::Schema::Subset::DSL.new do
29
+ options = {
30
+ reference_name: ->(name) { name.sub(/Serializer$/, ""),
31
+ }
32
+
33
+ dsl = Json::Schema::Subset::DSL.new(options) do
30
34
  title! "Example"
31
35
  id :integer
32
36
  name :string, minLength: 1, optional: true
@@ -42,7 +46,7 @@ dsl = Json::Schema::Subset::DSL.new do
42
46
  ref! "#/components/Param"
43
47
  end
44
48
  opt_params :array do
45
- cref! "OptParam"
49
+ cref! "OptParamSerializer"
46
50
  end
47
51
  uuid :ref, "#/UUID", optional: true
48
52
  end
@@ -4,11 +4,12 @@ module Json
4
4
  module Schema
5
5
  module Subset
6
6
  class DSL
7
- def initialize(type: "object", schema: {}, params: {}, ref: nil, &block)
7
+ def initialize(type: "object", schema: {}, params: {}, ref: nil, options: nil, &block)
8
8
  @type = type
9
9
  @schema = schema
10
10
  @params = params
11
11
  @ref = ref
12
+ @options = options || {}
12
13
  @optionals = []
13
14
  set!(&block) if block_given?
14
15
  end
@@ -58,16 +59,16 @@ module Json
58
59
  end
59
60
 
60
61
  def components!(name)
61
- "#/components/#{name}"
62
+ "#/components/#{canon_name!(name)}"
62
63
  end
63
64
 
64
65
  def definitions!(name)
65
- "#/definitions/#{name}"
66
+ "#/definitions/#{canon_name!(name)}"
66
67
  end
67
68
 
68
69
  def array!(&block)
69
70
  change_type!("array")
70
- @schema["items"] = DSL.new(&block)
71
+ @schema["items"] = DSL.new(options: @options, &block)
71
72
  end
72
73
 
73
74
  def respond_to_missing?(name, include_private)
@@ -88,17 +89,20 @@ module Json
88
89
  type = type.is_a?(Array) ? type.map(&:to_s) : type.to_s
89
90
  case
90
91
  when type == "ref"
91
- @schema[name.to_s] = DSL.new(ref: args[1], &block)
92
+ @schema[name.to_s] = DSL.new(ref: args[1], options: @options, &block)
92
93
  when type == "cref"
93
- @schema[name.to_s] = DSL.new(ref: components!(args[1]), &block)
94
+ @schema[name.to_s] = DSL.new(ref: components!(args[1]), options: @options, &block)
94
95
  when type == "dref"
95
- @schema[name.to_s] = DSL.new(ref: definitions!(args[1]), &block)
96
+ @schema[name.to_s] = DSL.new(ref: definitions!(args[1]), options: @options, &block)
96
97
  when Array(type).include?("array")
97
- @schema[name.to_s] = DSL.new(type: type, params: opts, schema: { "items" => DSL.new(&block) })
98
+ @schema[name.to_s] =
99
+ DSL.new(
100
+ type: type, params: opts, schema: { "items" => DSL.new(options: @options, &block) }, options: @options,
101
+ )
98
102
  when Array(type).include?("object")
99
- @schema[name.to_s] = DSL.new(type: type, params: opts, &block)
103
+ @schema[name.to_s] = DSL.new(type: type, params: opts, options: @options, &block)
100
104
  else
101
- @schema[name.to_s] = DSL.new(type: type, schema: opts, &block)
105
+ @schema[name.to_s] = DSL.new(type: type, schema: opts, options: @options, &block)
102
106
  end
103
107
  end
104
108
 
@@ -114,6 +118,10 @@ module Json
114
118
  @type = Array(@type) + [type]
115
119
  end
116
120
  end
121
+
122
+ def canon_name!(name)
123
+ @options[:reference_name] ? @options[:reference_name].call(name.to_s) : name.to_s
124
+ end
117
125
  end
118
126
  end
119
127
  end
@@ -2,7 +2,7 @@ module Json
2
2
  module Schema
3
3
  module Subset
4
4
  class DSL
5
- VERSION = "1.1.0".freeze
5
+ VERSION = "1.2.0".freeze
6
6
  end
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json-schema-subset-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
@@ -182,7 +182,7 @@ metadata:
182
182
  homepage_uri: https://github.com/Narazaka/json-schema-subset-dsl
183
183
  source_code_uri: https://github.com/Narazaka/json-schema-subset-dsl.git
184
184
  changelog_uri: https://github.com/Narazaka/json-schema-subset-dsl/blob/master/CHANGELOG.md
185
- documentation_uri: https://www.rubydoc.info/gems/json-schema-subset-dsl/1.1.0
185
+ documentation_uri: https://www.rubydoc.info/gems/json-schema-subset-dsl/1.2.0
186
186
  post_install_message:
187
187
  rdoc_options: []
188
188
  require_paths: