Skip to content

Commit

Permalink
Feat: Change nullable & type for OpenApi v3.1.0 (#1502)
Browse files Browse the repository at this point in the history
  • Loading branch information
DjordyKoert authored Nov 30, 2023
1 parent 5d16fec commit 21366a8
Show file tree
Hide file tree
Showing 17 changed files with 161 additions and 40 deletions.
13 changes: 9 additions & 4 deletions docs/reference/annotations.md
Original file line number Diff line number Diff line change
Expand Up @@ -956,10 +956,12 @@ An object instance is valid against this property if its number of properties is
<dt><strong>required</strong> : <span style="font-family: monospace;">string[]</span></dt>
<dd><p>An object instance is valid against this property if its property set contains all elements in this property's<br />
array value.</p></dd>
<dt><strong>type</strong> : <span style="font-family: monospace;">string</span></dt>
<dt><strong>type</strong> : <span style="font-family: monospace;">string|non-empty-array&lt;string&gt;</span></dt>
<dd><p>The type of the schema/property.<br />
<br />
The value MUST be one of "string", "number", "integer", "boolean", "array" or "object".</p></dd>
OpenApi v3.0: The value MUST be one of "string", "number", "integer", "boolean", "array" or "object".<br />
<br />
Since OpenApi v3.1 an array of types may be used.</p></dd>
<dt><strong>format</strong> : <span style="font-family: monospace;">string</span></dt>
<dd><p>The extending format for the previously mentioned type. See Data Type Formats for further details.</p></dd>
<dt><strong>collectionFormat</strong> : <span style="font-family: monospace;">string</span></dt>
Expand Down Expand Up @@ -1040,7 +1042,10 @@ To represent examples that cannot naturally be represented in JSON or YAML, a st
contain the example with escaping where necessary.</p></dd>
<dt><strong>nullable</strong> : <span style="font-family: monospace;">bool</span></dt>
<dd><p>Allows sending a null value for the defined schema.<br />
Default value is false.</p></dd>
Default value is false.<br />
<br />
This must not be used when using OpenApi version 3.1,<br />
instead make the "type" property an array and add "null" as a possible type.</p></dd>
<dt><strong>deprecated</strong> : <span style="font-family: monospace;">bool</span></dt>
<dd><p>Specifies that a schema is deprecated and should be transitioned out of usage.<br />
Default value is false.</p></dd>
Expand Down Expand Up @@ -1093,7 +1098,7 @@ defined by this property's value.</p></dd>
<dd><p>The relative or absolute path to a security scheme.</p><p><i>See</i>: <a href="https://swagger.io/docs/specification/using-ref/">Using refs</a></p></dd>
<dt><strong>securityScheme</strong> : <span style="font-family: monospace;">string</span></dt>
<dd><p>The key into OpenApi->security array.</p></dd>
<dt><strong>type</strong> : <span style="font-family: monospace;">string</span></dt>
<dt><strong>type</strong> : <span style="font-family: monospace;">string|non-empty-array&lt;string&gt;</span></dt>
<dd><p>The type of the security scheme.</p></dd>
<dt><strong>description</strong> : <span style="font-family: monospace;">string</span></dt>
<dd><p>A short description for security scheme.</p></dd>
Expand Down
68 changes: 49 additions & 19 deletions docs/reference/attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ array value.</p></dd>
<dd><p>A collection of properties to define for an object.<br />
<br />
Each property is represented as an instance of the <a href="#property">Property</a> class.</p></dd>
<dt><strong>type</strong> : <span style="font-family: monospace;">string|null</span></dt>
<dt><strong>type</strong> : <span style="font-family: monospace;">string|non-empty-array&lt;string&gt;|null</span></dt>
<dd><p>The type of the schema/property.<br />
<br />
The value MUST be one of "string", "number", "integer", "boolean", "array" or "object".</p></dd>
OpenApi v3.0: The value MUST be one of "string", "number", "integer", "boolean", "array" or "object".<br />
<br />
Since OpenApi v3.1 an array of types may be used.</p></dd>
<dt><strong>format</strong> : <span style="font-family: monospace;">string|null</span></dt>
<dd><p>The extending format for the previously mentioned type. See Data Type Formats for further details.</p></dd>
<dt><strong>items</strong> : <span style="font-family: monospace;">OpenApi\Attributes\Items|null</span></dt>
Expand Down Expand Up @@ -139,7 +141,10 @@ To represent examples that cannot naturally be represented in JSON or YAML, a st
contain the example with escaping where necessary.</p></dd>
<dt><strong>nullable</strong> : <span style="font-family: monospace;">bool|null</span></dt>
<dd><p>Allows sending a null value for the defined schema.<br />
Default value is false.</p></dd>
Default value is false.<br />
<br />
This must not be used when using OpenApi version 3.1,<br />
instead make the "type" property an array and add "null" as a possible type.</p></dd>
<dt><strong>deprecated</strong> : <span style="font-family: monospace;">bool|null</span></dt>
<dd><p>Specifies that a schema is deprecated and should be transitioned out of usage.<br />
Default value is false.</p></dd>
Expand Down Expand Up @@ -1002,10 +1007,12 @@ array value.</p></dd>
<dd><p>A collection of properties to define for an object.<br />
<br />
Each property is represented as an instance of the <a href="#property">Property</a> class.</p></dd>
<dt><strong>type</strong> : <span style="font-family: monospace;">string|null</span></dt>
<dt><strong>type</strong> : <span style="font-family: monospace;">string|non-empty-array&lt;string&gt;|null</span></dt>
<dd><p>The type of the schema/property.<br />
<br />
The value MUST be one of "string", "number", "integer", "boolean", "array" or "object".</p></dd>
OpenApi v3.0: The value MUST be one of "string", "number", "integer", "boolean", "array" or "object".<br />
<br />
Since OpenApi v3.1 an array of types may be used.</p></dd>
<dt><strong>format</strong> : <span style="font-family: monospace;">string|null</span></dt>
<dd><p>The extending format for the previously mentioned type. See Data Type Formats for further details.</p></dd>
<dt><strong>items</strong> : <span style="font-family: monospace;">OpenApi\Attributes\Items|null</span></dt>
Expand Down Expand Up @@ -1097,7 +1104,10 @@ To represent examples that cannot naturally be represented in JSON or YAML, a st
contain the example with escaping where necessary.</p></dd>
<dt><strong>nullable</strong> : <span style="font-family: monospace;">bool|null</span></dt>
<dd><p>Allows sending a null value for the defined schema.<br />
Default value is false.</p></dd>
Default value is false.<br />
<br />
This must not be used when using OpenApi version 3.1,<br />
instead make the "type" property an array and add "null" as a possible type.</p></dd>
<dt><strong>deprecated</strong> : <span style="font-family: monospace;">bool|null</span></dt>
<dd><p>Specifies that a schema is deprecated and should be transitioned out of usage.<br />
Default value is false.</p></dd>
Expand Down Expand Up @@ -1160,10 +1170,12 @@ array value.</p></dd>
<dd><p>A collection of properties to define for an object.<br />
<br />
Each property is represented as an instance of the <a href="#property">Property</a> class.</p></dd>
<dt><strong>type</strong> : <span style="font-family: monospace;">string|null</span></dt>
<dt><strong>type</strong> : <span style="font-family: monospace;">string|non-empty-array&lt;string&gt;|null</span></dt>
<dd><p>The type of the schema/property.<br />
<br />
The value MUST be one of "string", "number", "integer", "boolean", "array" or "object".</p></dd>
OpenApi v3.0: The value MUST be one of "string", "number", "integer", "boolean", "array" or "object".<br />
<br />
Since OpenApi v3.1 an array of types may be used.</p></dd>
<dt><strong>format</strong> : <span style="font-family: monospace;">string|null</span></dt>
<dd><p>The extending format for the previously mentioned type. See Data Type Formats for further details.</p></dd>
<dt><strong>items</strong> : <span style="font-family: monospace;">OpenApi\Attributes\Items|null</span></dt>
Expand Down Expand Up @@ -1255,7 +1267,10 @@ To represent examples that cannot naturally be represented in JSON or YAML, a st
contain the example with escaping where necessary.</p></dd>
<dt><strong>nullable</strong> : <span style="font-family: monospace;">bool|null</span></dt>
<dd><p>Allows sending a null value for the defined schema.<br />
Default value is false.</p></dd>
Default value is false.<br />
<br />
This must not be used when using OpenApi version 3.1,<br />
instead make the "type" property an array and add "null" as a possible type.</p></dd>
<dt><strong>deprecated</strong> : <span style="font-family: monospace;">bool|null</span></dt>
<dd><p>Specifies that a schema is deprecated and should be transitioned out of usage.<br />
Default value is false.</p></dd>
Expand Down Expand Up @@ -2024,10 +2039,12 @@ array value.</p></dd>
<dd><p>A collection of properties to define for an object.<br />
<br />
Each property is represented as an instance of the <a href="#property">Property</a> class.</p></dd>
<dt><strong>type</strong> : <span style="font-family: monospace;">string|null</span></dt>
<dt><strong>type</strong> : <span style="font-family: monospace;">string|non-empty-array&lt;string&gt;|null</span></dt>
<dd><p>The type of the schema/property.<br />
<br />
The value MUST be one of "string", "number", "integer", "boolean", "array" or "object".</p></dd>
OpenApi v3.0: The value MUST be one of "string", "number", "integer", "boolean", "array" or "object".<br />
<br />
Since OpenApi v3.1 an array of types may be used.</p></dd>
<dt><strong>format</strong> : <span style="font-family: monospace;">string|null</span></dt>
<dd><p>The extending format for the previously mentioned type. See Data Type Formats for further details.</p></dd>
<dt><strong>items</strong> : <span style="font-family: monospace;">OpenApi\Attributes\Items|null</span></dt>
Expand Down Expand Up @@ -2119,7 +2136,10 @@ To represent examples that cannot naturally be represented in JSON or YAML, a st
contain the example with escaping where necessary.</p></dd>
<dt><strong>nullable</strong> : <span style="font-family: monospace;">bool|null</span></dt>
<dd><p>Allows sending a null value for the defined schema.<br />
Default value is false.</p></dd>
Default value is false.<br />
<br />
This must not be used when using OpenApi version 3.1,<br />
instead make the "type" property an array and add "null" as a possible type.</p></dd>
<dt><strong>deprecated</strong> : <span style="font-family: monospace;">bool|null</span></dt>
<dd><p>Specifies that a schema is deprecated and should be transitioned out of usage.<br />
Default value is false.</p></dd>
Expand Down Expand Up @@ -2470,10 +2490,12 @@ array value.</p></dd>
<dd><p>A collection of properties to define for an object.<br />
<br />
Each property is represented as an instance of the <a href="#property">Property</a> class.</p></dd>
<dt><strong>type</strong> : <span style="font-family: monospace;">string|null</span></dt>
<dt><strong>type</strong> : <span style="font-family: monospace;">string|non-empty-array&lt;string&gt;|null</span></dt>
<dd><p>The type of the schema/property.<br />
<br />
The value MUST be one of "string", "number", "integer", "boolean", "array" or "object".</p></dd>
OpenApi v3.0: The value MUST be one of "string", "number", "integer", "boolean", "array" or "object".<br />
<br />
Since OpenApi v3.1 an array of types may be used.</p></dd>
<dt><strong>format</strong> : <span style="font-family: monospace;">string|null</span></dt>
<dd><p>The extending format for the previously mentioned type. See Data Type Formats for further details.</p></dd>
<dt><strong>items</strong> : <span style="font-family: monospace;">OpenApi\Attributes\Items|null</span></dt>
Expand Down Expand Up @@ -2565,7 +2587,10 @@ To represent examples that cannot naturally be represented in JSON or YAML, a st
contain the example with escaping where necessary.</p></dd>
<dt><strong>nullable</strong> : <span style="font-family: monospace;">bool|null</span></dt>
<dd><p>Allows sending a null value for the defined schema.<br />
Default value is false.</p></dd>
Default value is false.<br />
<br />
This must not be used when using OpenApi version 3.1,<br />
instead make the "type" property an array and add "null" as a possible type.</p></dd>
<dt><strong>deprecated</strong> : <span style="font-family: monospace;">bool|null</span></dt>
<dd><p>Specifies that a schema is deprecated and should be transitioned out of usage.<br />
Default value is false.</p></dd>
Expand Down Expand Up @@ -2610,7 +2635,7 @@ These will be ignored but can be used for custom processing.</p></dd>
<dd><p>The relative or absolute path to a security scheme.</p><p><i>See</i>: <a href="https://swagger.io/docs/specification/using-ref/">Using refs</a></p></dd>
<dt><strong>securityScheme</strong> : <span style="font-family: monospace;">string|null</span></dt>
<dd><p>The key into OpenApi->security array.</p></dd>
<dt><strong>type</strong> : <span style="font-family: monospace;">string|null</span></dt>
<dt><strong>type</strong> : <span style="font-family: monospace;">string|non-empty-array&lt;string&gt;|null</span></dt>
<dd><p>The type of the security scheme.</p></dd>
<dt><strong>description</strong> : <span style="font-family: monospace;">string|null</span></dt>
<dd><p>A short description for security scheme.</p></dd>
Expand Down Expand Up @@ -2918,10 +2943,12 @@ array value.</p></dd>
<dd><p>A collection of properties to define for an object.<br />
<br />
Each property is represented as an instance of the <a href="#property">Property</a> class.</p></dd>
<dt><strong>type</strong> : <span style="font-family: monospace;">string|null</span></dt>
<dt><strong>type</strong> : <span style="font-family: monospace;">string|non-empty-array&lt;string&gt;|null</span></dt>
<dd><p>The type of the schema/property.<br />
<br />
The value MUST be one of "string", "number", "integer", "boolean", "array" or "object".</p></dd>
OpenApi v3.0: The value MUST be one of "string", "number", "integer", "boolean", "array" or "object".<br />
<br />
Since OpenApi v3.1 an array of types may be used.</p></dd>
<dt><strong>format</strong> : <span style="font-family: monospace;">string|null</span></dt>
<dd><p>The extending format for the previously mentioned type. See Data Type Formats for further details.</p></dd>
<dt><strong>items</strong> : <span style="font-family: monospace;">OpenApi\Attributes\Items|null</span></dt>
Expand Down Expand Up @@ -3013,7 +3040,10 @@ To represent examples that cannot naturally be represented in JSON or YAML, a st
contain the example with escaping where necessary.</p></dd>
<dt><strong>nullable</strong> : <span style="font-family: monospace;">bool|null</span></dt>
<dd><p>Allows sending a null value for the defined schema.<br />
Default value is false.</p></dd>
Default value is false.<br />
<br />
This must not be used when using OpenApi version 3.1,<br />
instead make the "type" property an array and add "null" as a possible type.</p></dd>
<dt><strong>deprecated</strong> : <span style="font-family: monospace;">bool|null</span></dt>
<dd><p>Specifies that a schema is deprecated and should be transitioned out of usage.<br />
Default value is false.</p></dd>
Expand Down
11 changes: 9 additions & 2 deletions src/Annotations/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,11 @@ class Schema extends AbstractAnnotation
/**
* The type of the schema/property.
*
* The value MUST be one of "string", "number", "integer", "boolean", "array" or "object".
* OpenApi v3.0: The value MUST be one of "string", "number", "integer", "boolean", "array" or "object".
*
* @var string
* Since OpenApi v3.1 an array of types may be used.
*
* @var string|non-empty-array<string>
*/
public $type = Generator::UNDEFINED;

Expand Down Expand Up @@ -325,7 +327,12 @@ class Schema extends AbstractAnnotation
* Allows sending a null value for the defined schema.
* Default value is false.
*
* This must not be used when using OpenApi version 3.1,
* instead make the "type" property an array and add "null" as a possible type.
*
* @var bool
*
* @see https://www.openapis.org/blog/2021/02/16/migrating-from-openapi-3-0-to-3-1-0
*/
public $nullable = Generator::UNDEFINED;

Expand Down
2 changes: 1 addition & 1 deletion src/Annotations/SecurityScheme.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class SecurityScheme extends AbstractAnnotation
/**
* The type of the security scheme.
*
* @var string
* @var string|non-empty-array<string>
*/
public $type = Generator::UNDEFINED;

Expand Down
3 changes: 2 additions & 1 deletion src/Attributes/AdditionalProperties.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
class AdditionalProperties extends \OpenApi\Annotations\AdditionalProperties
{
/**
* @param string|non-empty-array<string>|null $type
* @param string|class-string|object|null $ref
* @param string[] $required
* @param Property[] $properties
Expand All @@ -34,7 +35,7 @@ public function __construct(
?int $minProperties = null,
?array $required = null,
?array $properties = null,
?string $type = null,
string|array|null $type = null,
?string $format = null,
?Items $items = null,
?string $collectionFormat = null,
Expand Down
3 changes: 2 additions & 1 deletion src/Attributes/Items.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
class Items extends \OpenApi\Annotations\Items
{
/**
* @param string|non-empty-array<string>|null $type
* @param string|class-string|object|null $ref
* @param string[] $required
* @param Property[] $properties
Expand All @@ -34,7 +35,7 @@ public function __construct(
?int $minProperties = null,
?array $required = null,
?array $properties = null,
?string $type = null,
string|array|null $type = null,
?string $format = null,
?Items $items = null,
?string $collectionFormat = null,
Expand Down
3 changes: 2 additions & 1 deletion src/Attributes/JsonContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
class JsonContent extends \OpenApi\Annotations\JsonContent
{
/**
* @param string|non-empty-array<string>|null $type
* @param string|class-string|object|null $ref
* @param array<string,Examples> $examples
* @param string[] $required
Expand All @@ -36,7 +37,7 @@ public function __construct(
?int $minProperties = null,
?array $required = null,
?array $properties = null,
?string $type = null,
string|array|null $type = null,
?string $format = null,
?Items $items = null,
?string $collectionFormat = null,
Expand Down
3 changes: 2 additions & 1 deletion src/Attributes/Property.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
class Property extends \OpenApi\Annotations\Property
{
/**
* @param string|non-empty-array<string>|null $type
* @param string|class-string|object|null $ref
* @param string[] $required
* @param Property[] $properties
Expand All @@ -35,7 +36,7 @@ public function __construct(
?int $minProperties = null,
?array $required = null,
?array $properties = null,
?string $type = null,
string|array|null $type = null,
?string $format = null,
?Items $items = null,
?string $collectionFormat = null,
Expand Down
3 changes: 2 additions & 1 deletion src/Attributes/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
class Schema extends \OpenApi\Annotations\Schema
{
/**
* @param string|non-empty-array<string>|null $type
* @param string|class-string|object|null $ref
* @param string[] $required
* @param Property[] $properties
Expand All @@ -35,7 +36,7 @@ public function __construct(
?int $minProperties = null,
?array $required = null,
?array $properties = null,
?string $type = null,
string|array|null $type = null,
?string $format = null,
?Items $items = null,
?string $collectionFormat = null,
Expand Down
Loading

0 comments on commit 21366a8

Please sign in to comment.