From a1224896b9977e0112eea9829b5fb6b13e3bd515 Mon Sep 17 00:00:00 2001
From: DjordyKoert
Date: Thu, 23 Nov 2023 15:54:50 +0100
Subject: [PATCH 1/4] Convert exclusiveMinimum/Maximum for openapi 3.1
---
src/Annotations/AbstractAnnotation.php | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/src/Annotations/AbstractAnnotation.php b/src/Annotations/AbstractAnnotation.php
index 1c8bac50..63d2a236 100644
--- a/src/Annotations/AbstractAnnotation.php
+++ b/src/Annotations/AbstractAnnotation.php
@@ -399,6 +399,24 @@ public function jsonSerialize()
}
unset($data->nullable);
}
+
+ if (isset($data->minimum) && isset($data->exclusiveMinimum)) {
+ if (true === $data->exclusiveMinimum) {
+ $data->exclusiveMinimum = $data->minimum;
+ unset($data->minimum);
+ } elseif (false === $data->exclusiveMinimum) {
+ unset($data->exclusiveMinimum);
+ }
+ }
+
+ if (isset($data->maximum) && isset($data->exclusiveMaximum)) {
+ if (true === $data->exclusiveMaximum) {
+ $data->exclusiveMaximum = $data->maximum;
+ unset($data->maximum);
+ } elseif (false === $data->exclusiveMaximum) {
+ unset($data->exclusiveMaximum);
+ }
+ }
}
return $data;
From 419682b901122b496275968ed0f58e0ef75b5496 Mon Sep 17 00:00:00 2001
From: DjordyKoert
Date: Thu, 23 Nov 2023 15:56:03 +0100
Subject: [PATCH 2/4] Add correct OpenApi 3.1 types for
exclusiveMinimum/Maximum
---
docs/reference/annotations.md | 8 +++---
docs/reference/attributes.md | 38 ++++++++++++-------------
src/Annotations/Schema.php | 4 +--
src/Attributes/AdditionalProperties.php | 4 +--
src/Attributes/Items.php | 4 +--
src/Attributes/JsonContent.php | 4 +--
src/Attributes/Property.php | 4 +--
src/Attributes/Schema.php | 4 +--
src/Attributes/XmlContent.php | 4 +--
9 files changed, 37 insertions(+), 37 deletions(-)
diff --git a/docs/reference/annotations.md b/docs/reference/annotations.md
index 2208ec7a..fc0d71d6 100644
--- a/docs/reference/annotations.md
+++ b/docs/reference/annotations.md
@@ -977,13 +977,13 @@ Default value is csv.
- serverVariable : string
The key into Server->variables array.
- - enum : string[]|int[]|float[]|\UnitEnum[]|class-string
+ - enum : string[]|int[]|float[]|bool[]|\UnitEnum[]|class-string
An enumeration of values to be used if the substitution options are from a limited set.
- default : string
The default value to use for substitution, and to send, if an alternate value is not supplied.
diff --git a/docs/reference/attributes.md b/docs/reference/attributes.md
index 292679b0..c724b65e 100644
--- a/docs/reference/attributes.md
+++ b/docs/reference/attributes.md
@@ -67,13 +67,13 @@ Default value is csv.
Sets a default value to the parameter. The type of the value depends on the defined type.
See: JSON schema validation
- maximum : int|float
The maximum value allowed for a numeric property. This value must be a number.
See: JSON schema validation
- - exclusiveMaximum : bool|null
+ - exclusiveMaximum : int|float|bool|null
A boolean indicating whether the maximum value is excluded from the set of valid values.
When set to true, the maximum value is excluded, and when false or not specified, it is included.
See: JSON schema validation
- minimum : int|float
The minimum value allowed for a numeric property. This value must be a number.
See: JSON schema validation
- - exclusiveMinimum : bool|null
+ - exclusiveMinimum : int|float|bool|null
A boolean indicating whether the minimum value is excluded from the set of valid values.
When set to true, the minimum value is excluded, and when false or not specified, it is included.
See: JSON schema validation
@@ -99,7 +99,7 @@ An array instance is valid against this property if its number of items is great
If this attribute is set to true, then all items in the array must be unique.See: JSON schema validation
- pattern : string|null
A string instance is considered valid if the regular expression matches the instance successfully.
- - enum : string[]|int[]|float[]|\UnitEnum[]|class-string
+ - enum : string[]|int[]|float[]|bool[]|\UnitEnum[]|class-string
A collection of allowable values for a property.
A property instance is valid against this attribute if its value is one of the values specified in this collection.
See: JSON schema validation
@@ -1025,13 +1025,13 @@ Default value is csv.
Sets a default value to the parameter. The type of the value depends on the defined type.
See: JSON schema validation
- maximum : int|float
The maximum value allowed for a numeric property. This value must be a number.
See: JSON schema validation
- - exclusiveMaximum : bool|null
+ - exclusiveMaximum : int|float|bool|null
A boolean indicating whether the maximum value is excluded from the set of valid values.
When set to true, the maximum value is excluded, and when false or not specified, it is included.
See: JSON schema validation
- minimum : int|float
The minimum value allowed for a numeric property. This value must be a number.
See: JSON schema validation
- - exclusiveMinimum : bool|null
+ - exclusiveMinimum : int|float|bool|null
A boolean indicating whether the minimum value is excluded from the set of valid values.
When set to true, the minimum value is excluded, and when false or not specified, it is included.
See: JSON schema validation
@@ -1057,7 +1057,7 @@ An array instance is valid against this property if its number of items is great
If this attribute is set to true, then all items in the array must be unique.See: JSON schema validation
- pattern : string|null
A string instance is considered valid if the regular expression matches the instance successfully.
- - enum : string[]|int[]|float[]|\UnitEnum[]|class-string
+ - enum : string[]|int[]|float[]|bool[]|\UnitEnum[]|class-string
A collection of allowable values for a property.
A property instance is valid against this attribute if its value is one of the values specified in this collection.
See: JSON schema validation
@@ -1183,13 +1183,13 @@ Default value is csv.
Sets a default value to the parameter. The type of the value depends on the defined type.
See: JSON schema validation
- maximum : int|float
The maximum value allowed for a numeric property. This value must be a number.
See: JSON schema validation
- - exclusiveMaximum : bool|null
+ - exclusiveMaximum : int|float|bool|null
A boolean indicating whether the maximum value is excluded from the set of valid values.
When set to true, the maximum value is excluded, and when false or not specified, it is included.
See: JSON schema validation
- minimum : int|float
The minimum value allowed for a numeric property. This value must be a number.
See: JSON schema validation
- - exclusiveMinimum : bool|null
+ - exclusiveMinimum : int|float|bool|null
A boolean indicating whether the minimum value is excluded from the set of valid values.
When set to true, the minimum value is excluded, and when false or not specified, it is included.
See: JSON schema validation
@@ -1215,7 +1215,7 @@ An array instance is valid against this property if its number of items is great
If this attribute is set to true, then all items in the array must be unique.See: JSON schema validation
- pattern : string|null
A string instance is considered valid if the regular expression matches the instance successfully.
- - enum : string[]|int[]|float[]|\UnitEnum[]|class-string
+ - enum : string[]|int[]|float[]|bool[]|\UnitEnum[]|class-string
A collection of allowable values for a property.
A property instance is valid against this attribute if its value is one of the values specified in this collection.
See: JSON schema validation
@@ -2047,13 +2047,13 @@ Default value is csv.
Sets a default value to the parameter. The type of the value depends on the defined type.
See: JSON schema validation
- maximum : int|float
The maximum value allowed for a numeric property. This value must be a number.
See: JSON schema validation
- - exclusiveMaximum : bool|null
+ - exclusiveMaximum : int|float|bool|null
A boolean indicating whether the maximum value is excluded from the set of valid values.
When set to true, the maximum value is excluded, and when false or not specified, it is included.
See: JSON schema validation
- minimum : int|float
The minimum value allowed for a numeric property. This value must be a number.
See: JSON schema validation
- - exclusiveMinimum : bool|null
+ - exclusiveMinimum : int|float|bool|null
A boolean indicating whether the minimum value is excluded from the set of valid values.
When set to true, the minimum value is excluded, and when false or not specified, it is included.
See: JSON schema validation
@@ -2079,7 +2079,7 @@ An array instance is valid against this property if its number of items is great
If this attribute is set to true, then all items in the array must be unique.See: JSON schema validation
- pattern : string|null
A string instance is considered valid if the regular expression matches the instance successfully.
- - enum : string[]|int[]|float[]|\UnitEnum[]|class-string
+ - enum : string[]|int[]|float[]|bool[]|\UnitEnum[]|class-string
A collection of allowable values for a property.
A property instance is valid against this attribute if its value is one of the values specified in this collection.
See: JSON schema validation
@@ -2493,13 +2493,13 @@ Default value is csv.
Sets a default value to the parameter. The type of the value depends on the defined type.
See: JSON schema validation
- maximum : int|float
The maximum value allowed for a numeric property. This value must be a number.
See: JSON schema validation
- - exclusiveMaximum : bool|null
+ - exclusiveMaximum : int|float|bool|null
A boolean indicating whether the maximum value is excluded from the set of valid values.
When set to true, the maximum value is excluded, and when false or not specified, it is included.
See: JSON schema validation
- minimum : int|float
The minimum value allowed for a numeric property. This value must be a number.
See: JSON schema validation
- - exclusiveMinimum : bool|null
+ - exclusiveMinimum : int|float|bool|null
A boolean indicating whether the minimum value is excluded from the set of valid values.
When set to true, the minimum value is excluded, and when false or not specified, it is included.
See: JSON schema validation
@@ -2525,7 +2525,7 @@ An array instance is valid against this property if its number of items is great
If this attribute is set to true, then all items in the array must be unique.See: JSON schema validation
- pattern : string|null
A string instance is considered valid if the regular expression matches the instance successfully.
- - enum : string[]|int[]|float[]|\UnitEnum[]|class-string
+ - enum : string[]|int[]|float[]|bool[]|\UnitEnum[]|class-string
A collection of allowable values for a property.
A property instance is valid against this attribute if its value is one of the values specified in this collection.
See: JSON schema validation
@@ -2700,7 +2700,7 @@ CommonMark syntax MAY be used for rich text representation.
The default value to use for substitution, and to send, if an alternate value is not supplied.
Unlike the Schema Object's default, this value must be provided by the consumer.
- - enum : string[]|int[]|float[]|\UnitEnum[]|class-string|null
+ - enum : string[]|int[]|float[]|bool[]|\UnitEnum[]|class-string|null
An enumeration of values to be used if the substitution options are from a limited set.
- variables : array|null
A map between a variable name and its value.
@@ -2941,13 +2941,13 @@ Default value is csv.
Sets a default value to the parameter. The type of the value depends on the defined type.
See: JSON schema validation
- maximum : int|float
The maximum value allowed for a numeric property. This value must be a number.
See: JSON schema validation
- - exclusiveMaximum : bool|null
+ - exclusiveMaximum : int|float|bool|null
A boolean indicating whether the maximum value is excluded from the set of valid values.
When set to true, the maximum value is excluded, and when false or not specified, it is included.
See: JSON schema validation
- minimum : int|float
The minimum value allowed for a numeric property. This value must be a number.
See: JSON schema validation
- - exclusiveMinimum : bool|null
+ - exclusiveMinimum : int|float|bool|null
A boolean indicating whether the minimum value is excluded from the set of valid values.
When set to true, the minimum value is excluded, and when false or not specified, it is included.
See: JSON schema validation
@@ -2973,7 +2973,7 @@ An array instance is valid against this property if its number of items is great
If this attribute is set to true, then all items in the array must be unique.See: JSON schema validation
- pattern : string|null
A string instance is considered valid if the regular expression matches the instance successfully.
- - enum : string[]|int[]|float[]|\UnitEnum[]|class-string
+ - enum : string[]|int[]|float[]|bool[]|\UnitEnum[]|class-string
A collection of allowable values for a property.
A property instance is valid against this attribute if its value is one of the values specified in this collection.
See: JSON schema validation
diff --git a/src/Annotations/Schema.php b/src/Annotations/Schema.php
index 77c81853..4395ab25 100644
--- a/src/Annotations/Schema.php
+++ b/src/Annotations/Schema.php
@@ -152,7 +152,7 @@ class Schema extends AbstractAnnotation
*
* @see [JSON schema validation](http://json-schema.org/latest/json-schema-validation.html#anchor17)
*
- * @var bool
+ * @var bool|int|float
*/
public $exclusiveMaximum = Generator::UNDEFINED;
@@ -172,7 +172,7 @@ class Schema extends AbstractAnnotation
*
* @see [JSON schema validation](http://json-schema.org/latest/json-schema-validation.html#anchor21)
*
- * @var bool
+ * @var bool|int|float
*/
public $exclusiveMinimum = Generator::UNDEFINED;
diff --git a/src/Attributes/AdditionalProperties.php b/src/Attributes/AdditionalProperties.php
index ca0ab3f8..ae9ff944 100644
--- a/src/Attributes/AdditionalProperties.php
+++ b/src/Attributes/AdditionalProperties.php
@@ -40,9 +40,9 @@ public function __construct(
?string $collectionFormat = null,
mixed $default = Generator::UNDEFINED,
$maximum = null,
- ?bool $exclusiveMaximum = null,
+ bool|int|float|null $exclusiveMaximum = null,
$minimum = null,
- ?bool $exclusiveMinimum = null,
+ bool|int|float|null $exclusiveMinimum = null,
?int $maxLength = null,
?int $minLength = null,
?int $maxItems = null,
diff --git a/src/Attributes/Items.php b/src/Attributes/Items.php
index ad8f3606..8ab82d96 100644
--- a/src/Attributes/Items.php
+++ b/src/Attributes/Items.php
@@ -40,9 +40,9 @@ public function __construct(
?string $collectionFormat = null,
mixed $default = Generator::UNDEFINED,
$maximum = null,
- ?bool $exclusiveMaximum = null,
+ bool|int|float|null $exclusiveMaximum = null,
$minimum = null,
- ?bool $exclusiveMinimum = null,
+ bool|int|float|null $exclusiveMinimum = null,
?int $maxLength = null,
?int $minLength = null,
?int $maxItems = null,
diff --git a/src/Attributes/JsonContent.php b/src/Attributes/JsonContent.php
index e10c605d..2b35183d 100644
--- a/src/Attributes/JsonContent.php
+++ b/src/Attributes/JsonContent.php
@@ -42,9 +42,9 @@ public function __construct(
?string $collectionFormat = null,
mixed $default = Generator::UNDEFINED,
$maximum = null,
- ?bool $exclusiveMaximum = null,
+ bool|int|float|null $exclusiveMaximum = null,
$minimum = null,
- ?bool $exclusiveMinimum = null,
+ bool|int|float|null $exclusiveMinimum = null,
?int $maxLength = null,
?int $minLength = null,
?int $maxItems = null,
diff --git a/src/Attributes/Property.php b/src/Attributes/Property.php
index a3e2916c..d30af6b4 100644
--- a/src/Attributes/Property.php
+++ b/src/Attributes/Property.php
@@ -41,9 +41,9 @@ public function __construct(
?string $collectionFormat = null,
mixed $default = Generator::UNDEFINED,
$maximum = null,
- ?bool $exclusiveMaximum = null,
+ bool|int|float|null $exclusiveMaximum = null,
$minimum = null,
- ?bool $exclusiveMinimum = null,
+ bool|int|float|null $exclusiveMinimum = null,
?int $maxLength = null,
?int $minLength = null,
?int $maxItems = null,
diff --git a/src/Attributes/Schema.php b/src/Attributes/Schema.php
index 3437bbc5..1998f274 100644
--- a/src/Attributes/Schema.php
+++ b/src/Attributes/Schema.php
@@ -41,9 +41,9 @@ public function __construct(
?string $collectionFormat = null,
mixed $default = Generator::UNDEFINED,
$maximum = null,
- ?bool $exclusiveMaximum = null,
+ bool|int|float|null $exclusiveMaximum = null,
$minimum = null,
- ?bool $exclusiveMinimum = null,
+ bool|int|float|null $exclusiveMinimum = null,
?int $maxLength = null,
?int $minLength = null,
?int $maxItems = null,
diff --git a/src/Attributes/XmlContent.php b/src/Attributes/XmlContent.php
index b4035994..f7a41647 100644
--- a/src/Attributes/XmlContent.php
+++ b/src/Attributes/XmlContent.php
@@ -42,9 +42,9 @@ public function __construct(
?string $collectionFormat = null,
mixed $default = Generator::UNDEFINED,
$maximum = null,
- ?bool $exclusiveMaximum = null,
+ bool|int|float|null $exclusiveMaximum = null,
$minimum = null,
- ?bool $exclusiveMinimum = null,
+ bool|int|float|null $exclusiveMinimum = null,
?int $maxLength = null,
?int $minLength = null,
?int $maxItems = null,
From 772a58523cd5633c2be8e7d3a5051e5449d0d47e Mon Sep 17 00:00:00 2001
From: DjordyKoert
Date: Fri, 24 Nov 2023 09:34:32 +0100
Subject: [PATCH 3/4] Add exclusiveMinMax test for openapi 3.1
---
tests/Fixtures/Scratch/ExclusiveMinMax31.php | 43 +++++++++++++++++++
tests/Fixtures/Scratch/ExclusiveMinMax31.yaml | 37 ++++++++++++++++
2 files changed, 80 insertions(+)
create mode 100644 tests/Fixtures/Scratch/ExclusiveMinMax31.php
create mode 100644 tests/Fixtures/Scratch/ExclusiveMinMax31.yaml
diff --git a/tests/Fixtures/Scratch/ExclusiveMinMax31.php b/tests/Fixtures/Scratch/ExclusiveMinMax31.php
new file mode 100644
index 00000000..b79eb414
--- /dev/null
+++ b/tests/Fixtures/Scratch/ExclusiveMinMax31.php
@@ -0,0 +1,43 @@
+
Date: Fri, 24 Nov 2023 09:40:57 +0100
Subject: [PATCH 4/4] Add type validation support for union types
---
src/Annotations/AbstractAnnotation.php | 11 +++++++++++
src/Annotations/Schema.php | 4 ++--
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/src/Annotations/AbstractAnnotation.php b/src/Annotations/AbstractAnnotation.php
index 63d2a236..3aeb46eb 100644
--- a/src/Annotations/AbstractAnnotation.php
+++ b/src/Annotations/AbstractAnnotation.php
@@ -704,6 +704,17 @@ private function validateType(string $type, $value): bool
*/
private function validateDefaultTypes(string $type, $value): bool
{
+ if (str_contains($type, '|')) {
+ $types = explode('|', $type);
+ foreach ($types as $type) {
+ if ($this->validateDefaultTypes($type, $value)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
switch ($type) {
case 'string':
return is_string($value);
diff --git a/src/Annotations/Schema.php b/src/Annotations/Schema.php
index 4395ab25..afcf9fdd 100644
--- a/src/Annotations/Schema.php
+++ b/src/Annotations/Schema.php
@@ -415,9 +415,9 @@ class Schema extends AbstractAnnotation
'format' => 'string',
'collectionFormat' => ['csv', 'ssv', 'tsv', 'pipes', 'multi'],
'maximum' => 'number',
- 'exclusiveMaximum' => 'boolean',
+ 'exclusiveMaximum' => 'boolean|integer|number',
'minimum' => 'number',
- 'exclusiveMinimum' => 'boolean',
+ 'exclusiveMinimum' => 'boolean|integer|number',
'maxLength' => 'integer',
'minLength' => 'integer',
'pattern' => 'string',