json-schema-subset-dsl 1.1.0 → 1.2.0
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 +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +6 -2
- data/lib/json/schema/subset/dsl.rb +18 -10
- data/lib/json/schema/subset/dsl/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5aab5735b6f1fc77fb82cf833b565b7394f064177e0d2608e492de7a66be9bcb
|
4
|
+
data.tar.gz: 95ba200fe739435cae6cbc89c1a7a4f663c80ac9c0701c593acfdffc7fa6f6c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b248c05fcc4eb39f9a06550fd11952cc801ba49552c50611b4c77432740528bd7bfd1f23cc9e361e4e4197a63467d08a01b81c40b8a00847c44fc36e3a96f67
|
7
|
+
data.tar.gz: 3706692a8b802c78d7666be4042e2b9f0ea2ec62f7901c31da62a26ea34b8fe4f92079cb0af32770da2afa12cd09fd527bdf0e7890b4ee81ce640589e5a8942c
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -26,7 +26,11 @@ Or install it yourself as:
|
|
26
26
|
## Usage
|
27
27
|
|
28
28
|
```ruby
|
29
|
-
|
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! "
|
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] =
|
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
|
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.
|
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.
|
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:
|