verquest 0.11.0 → 0.12.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7419f824e6f2966c2301b9f9c2ea9a3df48c6dd7559e7adbbd3ab297476726df
4
- data.tar.gz: ece88f624641894745c5b6d0a5a3dc818839ceb79deef5548657a8e9bf7553c2
3
+ metadata.gz: 3e0fcd7f6d608af2e076189ca2484861a076d2e24e19fb61a76795924a53b22c
4
+ data.tar.gz: 59fd91a6e47c36499a212bffca49bd71fa3375bf333b91d0b162a5e54a9564d7
5
5
  SHA512:
6
- metadata.gz: d541f01f0945d3003d21edf031eb1dca54256d5ed702b7bae7d08ab99a32407873822a787f509d0512edc93cf8cd09e4220cf7cf2b83bdf2d84c407459902524
7
- data.tar.gz: 43cbf7621f6a84d7f396835bf75358d842b835f92209abc3748bdd83e3287723a0a3895abb452a092e1ded7c9ac9470a6d6987424cfe8201fc13a4f237cceb0c
6
+ metadata.gz: d81a27ce31546a76107dac399cbc7baf57e02dad44eef25b00482c9b9023440ce88921e830d74ce9b991ea78d566e31a75258d1f5def238ae71a8151b34fc4e9
7
+ data.tar.gz: bd463d27e048cd7d513106c6b22352bad04f5c0ef333398a38cbf26c748826a7c64778096e238f10f4b1840fbb60ccd3330e39534e6c91a439fe6abab49e5a02
data/.rubocop.yml CHANGED
@@ -10,5 +10,5 @@ plugins:
10
10
  - rubocop-rake
11
11
 
12
12
  AllCops:
13
- TargetRubyVersion: 3.1
13
+ TargetRubyVersion: 3.3
14
14
  NewCops: enable # Enables new cops from plugins, as the main cops are managed by standard (the inherit_gem above)
data/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.12.0] - 2026-11-17
4
+
5
+ ### Added
6
+ - A named `one_of` takes schema options: annotations (`description`, `title`, `examples`, `example`, `deprecated`, `readOnly`, `writeOnly`, `externalDocs`, `$comment`), `default` and `x-` extensions. They go on the property schema next to `oneOf`, or next to the outer `anyOf` of a nullable `one_of`. The validation schema takes only `default`, so a nullable `one_of` can default to null. A default that doesn't match the `one_of`, like null on one that isn't nullable, raises `Verquest::DefinitionError`, as does a default on a `one_of` with `required: [:other]`, which would make every request without the `one_of` need `other`. Other options raise `Verquest::DefinitionError`, as do schema options on an unnamed `one_of`.
7
+
8
+ ### Changed
9
+ - A named `one_of` inside `with_options` takes that block's annotation defaults (`description`, `title`, `deprecated`, `readOnly`, `writeOnly`, `externalDocs`), which changes the generated schemas. Other defaults, like `example`, `additional_properties` or `discriminator`, still don't apply to it. Its variants and their properties no longer take the annotations it takes, so they don't repeat the `one_of`'s description; they still take `examples`, `example` and `$comment`.
10
+ - Under `json_schema_version = :openapi30`, documents write `examples` as `example` (its first item, unless the schema has an `example`) and `$comment` as the `x-comment` extension, as OpenAPI 3.0 has neither. A schema with both a keyword and the extension it becomes, like `$comment` and `x-comment`, raises `Verquest::DefinitionError`.
11
+ - Verquest needs Ruby 3.3 or later. Ruby 3.2 reached its end of life on 2026-04-01.
12
+
13
+ ### Fixed
14
+ - An inserted default is a deep copy, so changing its nested Hashes, Arrays or Strings in the processed params no longer changes the default for later requests.
15
+ - A root `one_of` schema takes its version's `description` and the annotations and `x-` extensions of its `schema_options`, which it used to drop. Other schema options on its version, except `additional_properties`, raise `Verquest::DefinitionError`.
16
+ - Schema option keys of `x-` extensions and `$` keywords keep their names, so `"x-my_ext":` is no longer written as `x-myExt`.
17
+
3
18
  ## [0.11.0] - 2026-11-10
4
19
 
5
20
  ### Added
data/README.md CHANGED
@@ -358,7 +358,7 @@ OpenAPI 3.0 has no `null` type, so with `json_schema_version = :openapi30` docum
358
358
  - merged into a nullable constant (with `null` in its `enum`) or a `one_of` without a discriminator;
359
359
  - next to an `allOf` around a nullable reference (`{"allOf" => [{"$ref" => "..."}], "nullable" => true}`) or a nullable `one_of` with a discriminator, which keeps null outside the discriminated `oneOf`, as versponse does.
360
360
 
361
- OpenAPI 3.0 also has no `dependentRequired` (from `required: [:other]`), so documents write it as the `x-dependentRequired` extension. Validation still enforces it.
361
+ OpenAPI 3.0 also has no `dependentRequired` (from `required: [:other]`), so documents write it as the `x-dependentRequired` extension. Validation still enforces it. Nor does it have `examples` or `$comment`: documents write the first example as `example`, unless the schema has one, and `$comment` as the `x-comment` extension. A schema with both `$comment` and `x-comment`, or `dependentRequired` and `x-dependentRequired`, raises `Verquest::DefinitionError`.
362
362
 
363
363
  Mixed types become an `anyOf` of single types, each nullable when the property is. Strict OpenAPI 3.0.3 tools honour `nullable` only next to `type`, so they may still treat a nullable reference or `one_of` as not nullable. Validation schemas keep the forms above, which validators honour.
364
364
 
@@ -560,9 +560,10 @@ OrderRequest.process({"order_id" => "o1", "payment" => {"method" => "card", "car
560
560
  "discriminator" => {"propertyName" => "method", "mapping" => {"card" => "#/components/schemas/CardPaymentComponent", "bank" => "#/components/schemas/BankPaymentComponent"}}}
561
561
  ```
562
562
 
563
- - Without `name:`, the whole request is one of the variants (`one_of discriminator: :type do ... end` as the only property of a version).
563
+ - Without `name:`, the whole request is one of the variants (`one_of discriminator: :type do ... end` as the only property of a version). Its schema takes the version's `description` and the annotations and `x-` extensions of its `schema_options`; other schema options, except `additional_properties`, raise `Verquest::DefinitionError`.
564
564
  - Without `discriminator:`, the value must match exactly one variant's schema. Validation rejects it otherwise; with validation off, mapping raises `Verquest::MappingError`.
565
565
  - `one_of` works inside objects, collections and other variants, and with `nullable: true` and `map:`.
566
+ - A named `one_of` takes schema options: annotations (`description:`, `title:`, `examples:`, `example:`, `deprecated:`, `read_only:`, `write_only:`, `external_docs:`, `"$comment":`), `default:` and `x-` extensions (`"x-internal": true`). They go on the property schema next to `oneOf`, or next to the outer `anyOf` of a nullable `one_of`; the validation schema takes only `default:`, which must match the `one_of` (null only when it is `nullable: true`) and can't go with `required: [:other]`. From `with_options`, it takes only `description`, `title`, `deprecated`, `read_only`, `write_only` and `external_docs`, and its variants take none of those, only the block's `examples`, `example` and `$comment`. Other options, like `additional_properties:`, `min_properties:` or `parameter_examples:`, raise `Verquest::DefinitionError`. So do schema options on an unnamed `one_of`; describe its version or the enclosing property instead.
566
567
 
567
568
  #### oneOf discriminators in validation
568
569
 
@@ -14,12 +14,13 @@ module Verquest
14
14
  #
15
15
  # Transforms all keys in the given hash from snake_case (e.g., "max_length")
16
16
  # to camelCase (e.g., "maxLength") format, which is commonly used in JSON Schema.
17
+ # Keys of x- extensions and $ keywords are kept as they are, as their names are exact.
17
18
  # The transformation happens in place, modifying the original hash.
18
19
  #
19
20
  # @param hash [Hash] The hash containing snake_case keys
20
21
  # @return [Hash] The same hash with keys transformed to camelCase
21
22
  def camelize(hash)
22
- hash.transform_keys! { |key| snake_to_camel(key.to_s).to_sym }
23
+ hash.transform_keys! { |key| key.to_s.start_with?("x-", "$") ? key.to_sym : snake_to_camel(key.to_s).to_sym }
23
24
  end
24
25
 
25
26
  # Converts a snake_case string to camelCase
@@ -462,23 +462,57 @@ module Verquest
462
462
  # @param required [Boolean, Array<Symbol>, nil] Whether this property is required
463
463
  # @param nullable [Boolean] Whether this property can be null
464
464
  # @param map [String, nil] An optional mapping to another property
465
+ # @param schema_options [Hash] Additional schema options for a named oneOf property: annotations, like a description,
466
+ # a default and x- extensions. Only annotations without examples come from the with_options defaults
467
+ # (see Verquest::Properties::OneOf::DEFAULT_ANNOTATION_KEYWORDS), and the variants of a named oneOf
468
+ # don't take the with_options annotations
465
469
  # @yield Block defining the schema options using reference declarations
466
470
  # @return [void]
467
- def one_of(name: nil, discriminator: nil, required: nil, nullable: nil, map: nil, &block)
471
+ # @raise [Verquest::DefinitionError] If schema options are given without a name, or aren't annotations,
472
+ # a default or x- extensions (see Verquest::Properties::OneOf.schema_option?)
473
+ def one_of(name: nil, discriminator: nil, required: nil, nullable: nil, map: nil, **schema_options, &block)
474
+ previous_scope = current_scope
475
+ previous_options = default_options
476
+ camelize(schema_options)
468
477
  required = default_options.fetch(:required, false) if required.nil?
469
478
  nullable = default_options.fetch(:nullable, false) if nullable.nil?
479
+ schema_options = one_of_schema_options(name, schema_options)
470
480
 
471
- one_of = Properties::OneOf.new(name:, discriminator:, required:, nullable:, map:)
481
+ one_of = Properties::OneOf.new(name:, discriminator:, required:, nullable:, map:, **schema_options)
472
482
  current_scope.add(one_of)
473
483
 
474
484
  if block_given?
475
- previous_scope = current_scope
476
485
  @current_scope = one_of
486
+ # A named oneOf holds the with_options annotations it takes, so its variants don't repeat them
487
+ @default_options = default_options.except(*Properties::OneOf::DEFAULT_ANNOTATION_OPTIONS) if name
477
488
 
478
489
  instance_exec(&block)
479
490
  end
480
491
  ensure
481
- @current_scope = previous_scope if block_given?
492
+ if block_given?
493
+ @current_scope = previous_scope
494
+ @default_options = previous_options
495
+ end
496
+ end
497
+
498
+ # Schema options of a oneOf, with the annotation defaults of with_options for a named one
499
+ #
500
+ # A named oneOf takes only annotations without examples from the with_options
501
+ # defaults, and Verquest::Properties::OneOf checks the options it's given.
502
+ # An unnamed oneOf stands for its scope and has no property schema to hold
503
+ # options, so it ignores the defaults and rejects its own options.
504
+ #
505
+ # @param name [Symbol, nil] The oneOf property name
506
+ # @param schema_options [Hash] The camelized schema options given to the oneOf
507
+ # @return [Hash] The schema options for the oneOf property
508
+ # @raise [Verquest::DefinitionError] If schema options are given without a name
509
+ def one_of_schema_options(name, schema_options)
510
+ return default_options.slice(*Properties::OneOf::DEFAULT_ANNOTATION_OPTIONS).merge(schema_options) if name
511
+ return schema_options if schema_options.empty?
512
+
513
+ alternative = current_scope.is_a?(Version) ? "describe the version" : "put the options on the enclosing property"
514
+ raise DefinitionError, "An unnamed one_of in version '#{@defining_version&.name}' can't take schema options " \
515
+ "(#{schema_options.keys.join(", ")}), give it a name: or #{alternative}"
482
516
  end
483
517
 
484
518
  # Errors for root keys that only another version declares
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Verquest
4
- GEM_VERSION = "0.11.0"
4
+ GEM_VERSION = "0.12.0"
5
5
  end
@@ -10,7 +10,9 @@ module Verquest
10
10
  # - an `anyOf` with a single null alternative becomes `nullable: true`, with an `allOf` around a `$ref`
11
11
  # (OpenAPI 3.0 ignores keywords next to `$ref`) or a discriminated `oneOf` (which would reject null),
12
12
  # and `null` added to an `enum`
13
- # - `dependentRequired` becomes the `x-dependentRequired` extension
13
+ # - `dependentRequired` becomes the `x-dependentRequired` extension, and `$comment` the `x-comment` extension
14
+ # (a schema with both a keyword and its extension raises Verquest::DefinitionError)
15
+ # - `examples` becomes `example`, its first item, unless the schema has an `example`
14
16
  #
15
17
  # Only schema positions are visited, so a property named "type" is never read as the keyword.
16
18
  #
@@ -34,7 +36,7 @@ module Verquest
34
36
  ].freeze
35
37
 
36
38
  # Keywords OpenAPI 3.0 lacks, written as extensions
37
- RENAMED = {"dependentRequired" => "x-dependentRequired"}.freeze
39
+ RENAMED = {"dependentRequired" => "x-dependentRequired", "$comment" => "x-comment"}.freeze
38
40
 
39
41
  module_function
40
42
 
@@ -44,7 +46,34 @@ module Verquest
44
46
  return schema unless schema.is_a?(::Hash)
45
47
 
46
48
  # The null alternative goes first, so a merged alternative's type array meets nullable in type_union
47
- type_union(nullable_any_of(schema).to_h { |keyword, value| [RENAMED.fetch(keyword, keyword), child(keyword, value)] })
49
+ schema = single_example(nullable_any_of(schema))
50
+ check_renamed(schema)
51
+ type_union(schema.to_h { |keyword, value| [RENAMED.fetch(keyword, keyword), child(keyword, value)] })
52
+ end
53
+
54
+ # Raises when a schema has a keyword and the extension it's written as, so one would overwrite the other
55
+ #
56
+ # @param schema [Hash] A schema
57
+ # @return [void]
58
+ # @raise [Verquest::DefinitionError] If the schema has both
59
+ def check_renamed(schema)
60
+ RENAMED.each do |keyword, extension|
61
+ next unless schema.key?(keyword) && schema.key?(extension)
62
+
63
+ raise DefinitionError, "A schema has both #{keyword} and #{extension}, which OpenAPI 3.0 documents write #{keyword} as"
64
+ end
65
+ end
66
+
67
+ # OpenAPI 3.0 has a single `example` and no `examples`
68
+ #
69
+ # @param schema [Hash] A schema
70
+ # @return [Hash] The schema without examples, with the first one as its example unless it has one
71
+ def single_example(schema)
72
+ examples = schema["examples"]
73
+ return schema unless examples.is_a?(::Array)
74
+ return schema.except("examples") if schema.key?("example") || examples.empty?
75
+
76
+ schema.except("examples").merge("example" => examples.first)
48
77
  end
49
78
 
50
79
  # @param keyword [String] The schema keyword
@@ -123,6 +152,6 @@ module Verquest
123
152
  schema.key?("enum") ? schema.merge("enum" => schema["enum"] | [nil]) : schema
124
153
  end
125
154
 
126
- private_class_method :child, :type_union, :any_of, :nullable_any_of, :nullable_alternative, :nullable_enum
155
+ private_class_method :check_renamed, :single_example, :child, :type_union, :any_of, :nullable_any_of, :nullable_alternative, :nullable_enum
127
156
  end
128
157
  end
@@ -34,6 +34,32 @@ module Verquest
34
34
  # With a discriminator, the validation schema keeps the discriminator (see DiscriminatedSchema),
35
35
  # so OpenAPI 3.0 and 3.1 validators validate only the variant the discriminator selects.
36
36
  class OneOf < Base
37
+ # Annotation keywords a named oneOf takes, which go only into the documentation schema
38
+ ANNOTATION_KEYWORDS = %w[description title examples example deprecated readOnly writeOnly externalDocs $comment].freeze
39
+
40
+ # Annotation keywords a named oneOf takes from the with_options defaults. Examples and
41
+ # $comment are left out, as they're written for the sibling properties and may not fit
42
+ # the oneOf, so they go to its variants instead.
43
+ DEFAULT_ANNOTATION_KEYWORDS = (ANNOTATION_KEYWORDS - %w[examples example $comment]).freeze
44
+
45
+ # DEFAULT_ANNOTATION_KEYWORDS as the with_options keys the DSL slices
46
+ DEFAULT_ANNOTATION_OPTIONS = DEFAULT_ANNOTATION_KEYWORDS.map(&:to_sym).freeze
47
+
48
+ # Keywords a named oneOf takes besides annotations, which also go into the validation schema
49
+ VALIDATION_KEYWORDS = %w[default].freeze
50
+
51
+ # Whether a named oneOf takes the schema option
52
+ #
53
+ # A named oneOf takes annotations, a default and x- extensions. Any other keyword
54
+ # would constrain the value next to the variants, or isn't a schema keyword.
55
+ #
56
+ # @param key [String, Symbol] The camelized schema option key
57
+ # @return [Boolean] true if the oneOf takes the option
58
+ def self.schema_option?(key)
59
+ key = key.to_s
60
+ ANNOTATION_KEYWORDS.include?(key) || VALIDATION_KEYWORDS.include?(key) || key.start_with?("x-")
61
+ end
62
+
37
63
  # @return [String, nil] The discriminator property name for schema selection
38
64
  attr_reader :discriminator
39
65
 
@@ -45,13 +71,21 @@ module Verquest
45
71
  # @param required [Boolean, Array<Symbol>] Whether this property is required, or array of dependency names
46
72
  # @param nullable [Boolean] Whether this property can be null
47
73
  # @param map [String, nil] The mapping path for this property
48
- def initialize(name: nil, discriminator: nil, required: false, nullable: false, map: nil)
74
+ # @param schema_options [Hash] Additional JSON schema options for a named oneOf property, like a description
75
+ # (see .schema_option?)
76
+ # @raise [Verquest::DefinitionError] If a schema option isn't an annotation, a default or an x- extension,
77
+ # or the oneOf has a default and requires other properties
78
+ def initialize(name: nil, discriminator: nil, required: false, nullable: false, map: nil, **schema_options)
49
79
  @name = name&.to_s
50
80
  @required = required
51
81
  @nullable = nullable
52
82
  @map = map
53
83
  @discriminator = discriminator&.to_s
54
84
  @schemas = {}
85
+ @schema_options = schema_options.transform_keys(&:to_s)
86
+ @checked_default_schemas = {}
87
+ check_schema_options
88
+ check_default_dependencies
55
89
  end
56
90
 
57
91
  # Add a schema option to this oneOf
@@ -78,19 +112,24 @@ module Verquest
78
112
  # @return [Hash] The schema definition with oneOf array and optional discriminator
79
113
  def to_schema
80
114
  freeze_schemas
81
- wrap_schema(nullable_schema(build_schema_with_refs))
115
+ wrap_schema(nullable_schema(build_schema_with_refs).merge(schema_options))
82
116
  end
83
117
 
84
118
  # Generate validation schema for this oneOf property
85
119
  #
86
120
  # Unlike to_schema which uses $ref, the validation schema includes
87
- # the full inline schema definitions for each option.
121
+ # the full inline schema definitions for each option. Of the schema
122
+ # options, it keeps only the default, as annotations and extensions
123
+ # don't take part in validation.
88
124
  #
89
125
  # @param version [String, nil] The version to generate validation schema for
90
126
  # @return [Hash] The validation schema with inline schema definitions
127
+ # @raise [Verquest::DefinitionError] If the default doesn't match the schema
91
128
  def to_validation_schema(version: nil)
92
129
  freeze_schemas
93
- wrap_schema(nullable_schema(build_validation_schema(version: version)))
130
+ schema = nullable_schema(build_validation_schema(version: version))
131
+ check_default(schema)
132
+ wrap_schema(schema.merge(schema_options.slice(*VALIDATION_KEYWORDS)))
94
133
  end
95
134
 
96
135
  # Create mapping for this oneOf property
@@ -163,7 +202,48 @@ module Verquest
163
202
 
164
203
  private
165
204
 
166
- attr_reader :schemas
205
+ attr_reader :schemas, :schema_options
206
+
207
+ # Raises for schema options a oneOf doesn't take (see .schema_option?)
208
+ #
209
+ # @return [void]
210
+ # @raise [Verquest::DefinitionError] If a schema option isn't an annotation, a default or an x- extension
211
+ def check_schema_options
212
+ rejected = schema_options.keys.reject { |key| self.class.schema_option?(key) }
213
+ return if rejected.empty?
214
+
215
+ raise DefinitionError, "one_of '#{name}' can't take #{rejected.join(", ")}, " \
216
+ "it takes only #{(ANNOTATION_KEYWORDS + VALIDATION_KEYWORDS).join(", ")} and x- extensions"
217
+ end
218
+
219
+ # Raises when the oneOf has a default and requires other properties, as inserting
220
+ # the default would make every request without the oneOf need them
221
+ #
222
+ # @return [void]
223
+ # @raise [Verquest::DefinitionError] If the oneOf has a default and requires other properties
224
+ def check_default_dependencies
225
+ return unless schema_options.key?("default") && required.is_a?(::Array)
226
+
227
+ raise DefinitionError, "one_of '#{name}' has a default and requires #{required.join(", ")}, " \
228
+ "so every request without #{name} would need #{required.join(", ")}"
229
+ end
230
+
231
+ # Raises when the default doesn't match the oneOf, so inserting it wouldn't fail the request
232
+ #
233
+ # Each schema is checked once, as versions that inherit the oneOf share it.
234
+ #
235
+ # @param schema [Hash] The validation schema without the default
236
+ # @return [void]
237
+ # @raise [Verquest::DefinitionError] If the default doesn't match the schema
238
+ def check_default(schema)
239
+ return unless schema_options.key?("default")
240
+
241
+ default = schema_options["default"]
242
+ key = [schema, Verquest.configuration.json_schema_uri]
243
+ return if @checked_default_schemas[key] ||= JSONSchemer.schema(schema, meta_schema: key[1]).valid?(default)
244
+
245
+ raise DefinitionError, "one_of '#{name}' has a default, #{default.inspect}, that doesn't match its schema"
246
+ end
167
247
 
168
248
  # Freezes the schemas hash to prevent further modifications
169
249
  # This is called on first read access to ensure immutability after setup
@@ -398,7 +398,39 @@ module Verquest
398
398
  key = [Verquest.configuration.json_schema_uri, insert_property_defaults_setting]
399
399
 
400
400
  @validation_schemers_lock.synchronize do
401
- @validation_schemers[key] ||= JSONSchemer.schema(validation_schema, meta_schema: key[0], insert_property_defaults: key[1])
401
+ @validation_schemers[key] ||= JSONSchemer.schema(
402
+ validation_schema, meta_schema: key[0], insert_property_defaults: key[1], property_default_resolver: property_default_resolver(key[1])
403
+ )
404
+ end
405
+ end
406
+
407
+ # Returns a resolver that inserts a deep copy of the default
408
+ #
409
+ # json_schemer inserts a shallow copy, so the params would share nested Hashes and Arrays
410
+ # with the schema, and changing them would change the default for later requests.
411
+ #
412
+ # @param setting [Boolean, Symbol] The insert_property_defaults value to compile with
413
+ # @return [Proc, nil] The resolver, or nil when defaults aren't inserted
414
+ def property_default_resolver(setting)
415
+ return unless setting
416
+
417
+ symbol = setting == :symbol
418
+ resolver = symbol ? JSONSchemer::Schema::SYMBOL_PROPERTY_DEFAULT_RESOLVER : JSONSchemer::Schema::DEFAULT_PROPERTY_DEFAULT_RESOLVER
419
+ proc do |instance, property, results|
420
+ resolver.call(instance, property, results).tap do |inserted|
421
+ key = symbol ? property.to_sym : property
422
+ instance[key] = copy_default(instance[key]) if inserted
423
+ end
424
+ end
425
+ end
426
+
427
+ # @param value [Object] An inserted default
428
+ # @return [Object] A copy of the value with copies of its Hashes, Arrays and Strings
429
+ def copy_default(value)
430
+ case value
431
+ when Hash then value.transform_values { |item| copy_default(item) }
432
+ when Array then value.map { |item| copy_default(item) }
433
+ else value.dup
402
434
  end
403
435
  end
404
436
 
@@ -432,14 +464,30 @@ module Verquest
432
464
  # Generates the JSON schema for combination schemas (oneOf at root level)
433
465
  #
434
466
  # For combination schemas, the schema is delegated directly to the oneOf
435
- # property since it represents the entire request structure.
467
+ # property since it represents the entire request structure. It takes the
468
+ # version's description and the annotations and x- extensions of its schema
469
+ # options. additionalProperties is left out, as the variants set their own.
436
470
  #
437
471
  # @return [Hash] The schema from the oneOf property
438
472
  # @raise [ArgumentError] If the version also has conditions
473
+ # @raise [Verquest::DefinitionError] If the version has other schema options
439
474
  def prepare_combination_schema
440
475
  raise ArgumentError, "Conditions can not be declared next to a root-level one_of" if conditions.any?
441
476
 
442
- @schema = document_schema(properties.values.first.to_schema)
477
+ annotations = combination_annotations
478
+ annotations["description"] = description if description
479
+ @schema = document_schema(properties.values.first.to_schema.merge(annotations))
480
+ end
481
+
482
+ # @return [Hash] The annotations and x- extensions of the schema options
483
+ # @raise [Verquest::DefinitionError] If the version has other schema options
484
+ def combination_annotations
485
+ options = schema_options.except("additionalProperties")
486
+ rejected = options.keys.reject { |key| key != "default" && Properties::OneOf.schema_option?(key) }
487
+ return options if rejected.empty?
488
+
489
+ raise DefinitionError, "The root one_of of version '#{name}' can't take schema options (#{rejected.join(", ")}), " \
490
+ "it takes only annotations and x- extensions"
443
491
  end
444
492
 
445
493
  # @return [Hash] The schema the meta-schema checks: the document under OpenAPI 3.0, the validation schema otherwise
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: verquest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Petr Hlavicka
@@ -132,7 +132,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
132
132
  requirements:
133
133
  - - ">="
134
134
  - !ruby/object:Gem::Version
135
- version: '3.2'
135
+ version: '3.3'
136
136
  required_rubygems_version: !ruby/object:Gem::Requirement
137
137
  requirements:
138
138
  - - ">="