json-schema-subset-dsl 1.1.0 → 2.0.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: 2fc0fdb0a235748e53ecfc032c9d1d97a7b541681e48899c05d045e6cf0a4565
4
+ data.tar.gz: f1fc46f4d894fa0d4019539ed51d9ec3abfa920178e15654be3b310f289633c8
5
5
  SHA512:
6
- metadata.gz: c7b08bca28d96506afba2998ffc0ff009d6e14ba7d0c145b7df7795236c92f39baa976f89261f24998da9fad85e6b2815b58474d8c09031f9e33437accedeb2c
7
- data.tar.gz: 524736dea681839b8ff6da0a38b0229b5b5cecf235d34e50912fa91cc4d050683bc869ab9fbce6ee0d70ebc44619b266fab70113bc9f5b706c1dee7ba84081d9
6
+ metadata.gz: b2a9f4ba528fb0be6c908e72f2479f2c0794fe5d046e04c7c5bf2eb546efe7b515079c0cbdc51e8f74fa98c4992052c3a8d116601bd0522d887e26e50662af57
7
+ data.tar.gz: 504fa8751266b830425ba9fc34858f240b8d7beef7e279930b888ed3a94254ddbef0a89ca3bd42b6b24540314549a4255db66ea4f5496ffe8300434f85e0761c
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 2.0.0
4
+
5
+ - fix: cref!(id) == "#/components/schemas/#{id}"
6
+
7
+ ## 1.3.0
8
+
9
+ - add: additionalPropeties support
10
+
11
+ ## 1.2.0
12
+
13
+ - add: reference_name option
14
+
3
15
  ## 1.1.0
4
16
 
5
17
  - 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
@@ -39,10 +43,10 @@ dsl = Json::Schema::Subset::DSL.new do
39
43
  meta :object do
40
44
  description :string
41
45
  params :array do
42
- ref! "#/components/Param"
46
+ ref! "#/components/schemas/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
@@ -59,8 +63,8 @@ dsl.compile! == {
59
63
  "type" => "object",
60
64
  "properties" => {
61
65
  "description" => { "type" => "string" },
62
- "params" => { "items" => { "$ref" => "#/components/Param" }, "type" => "array" },
63
- "opt_params" => { "items" => { "$ref" => "#/components/OptParam" }, "type" => "array" },
66
+ "params" => { "items" => { "$ref" => "#/components/schemas/Param" }, "type" => "array" },
67
+ "opt_params" => { "items" => { "$ref" => "#/components/schemas/OptParam" }, "type" => "array" },
64
68
  "uuid" => { "$ref" => "#/UUID" },
65
69
  },
66
70
  "required" => %w[description params opt_params],
@@ -29,7 +29,7 @@ Gem::Specification.new do |spec|
29
29
  spec.require_paths = %w[lib]
30
30
 
31
31
  spec.add_development_dependency "bundler", "~> 2"
32
- spec.add_development_dependency "rake", "~> 10.5"
32
+ spec.add_development_dependency "rake", "~> 13.0"
33
33
  spec.add_development_dependency "rspec", "~> 3.9"
34
34
  spec.add_development_dependency "rspec-power_assert", "~> 1.1"
35
35
  spec.add_development_dependency "rubocop", "~> 0.76"
@@ -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 = "2.0.0".freeze
6
6
  end
7
7
  end
8
8
  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/schemas/#{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)
@@ -76,7 +77,11 @@ module Json
76
77
 
77
78
  def method_missing(name, *args, &block)
78
79
  if name.to_s.end_with?("!")
79
- @params[name[0...-1]] = args[0]
80
+ if block_given?
81
+ @params[name[0...-1]] = DSL.new(options: @options, &block).compile!
82
+ else
83
+ @params[name[0...-1]] = args[0]
84
+ end
80
85
  return
81
86
  end
82
87
 
@@ -88,17 +93,20 @@ module Json
88
93
  type = type.is_a?(Array) ? type.map(&:to_s) : type.to_s
89
94
  case
90
95
  when type == "ref"
91
- @schema[name.to_s] = DSL.new(ref: args[1], &block)
96
+ @schema[name.to_s] = DSL.new(ref: args[1], options: @options, &block)
92
97
  when type == "cref"
93
- @schema[name.to_s] = DSL.new(ref: components!(args[1]), &block)
98
+ @schema[name.to_s] = DSL.new(ref: components!(args[1]), options: @options, &block)
94
99
  when type == "dref"
95
- @schema[name.to_s] = DSL.new(ref: definitions!(args[1]), &block)
100
+ @schema[name.to_s] = DSL.new(ref: definitions!(args[1]), options: @options, &block)
96
101
  when Array(type).include?("array")
97
- @schema[name.to_s] = DSL.new(type: type, params: opts, schema: { "items" => DSL.new(&block) })
102
+ @schema[name.to_s] =
103
+ DSL.new(
104
+ type: type, params: opts, schema: { "items" => DSL.new(options: @options, &block) }, options: @options,
105
+ )
98
106
  when Array(type).include?("object")
99
- @schema[name.to_s] = DSL.new(type: type, params: opts, &block)
107
+ @schema[name.to_s] = DSL.new(type: type, params: opts, options: @options, &block)
100
108
  else
101
- @schema[name.to_s] = DSL.new(type: type, schema: opts, &block)
109
+ @schema[name.to_s] = DSL.new(type: type, schema: opts, options: @options, &block)
102
110
  end
103
111
  end
104
112
 
@@ -114,6 +122,10 @@ module Json
114
122
  @type = Array(@type) + [type]
115
123
  end
116
124
  end
125
+
126
+ def canon_name!(name)
127
+ @options[:reference_name] ? @options[:reference_name].call(name.to_s) : name.to_s
128
+ end
117
129
  end
118
130
  end
119
131
  end
metadata CHANGED
@@ -1,14 +1,14 @@
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: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Narazaka
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-30 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: bundler
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.5'
33
+ version: '13.0'
34
34
  type: :development
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: '10.5'
40
+ version: '13.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -182,8 +182,8 @@ 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
186
- post_install_message:
185
+ documentation_uri: https://www.rubydoc.info/gems/json-schema-subset-dsl/2.0.0
186
+ post_install_message:
187
187
  rdoc_options: []
188
188
  require_paths:
189
189
  - lib
@@ -198,8 +198,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
198
198
  - !ruby/object:Gem::Version
199
199
  version: '0'
200
200
  requirements: []
201
- rubygems_version: 3.0.3
202
- signing_key:
201
+ rubygems_version: 3.1.4
202
+ signing_key:
203
203
  specification_version: 4
204
204
  summary: Yet another JSON Schema subset DSL
205
205
  test_files: []