diff --git a/src/Annotations/Schema.php b/src/Annotations/Schema.php index b52a47128..1fff1a02c 100644 --- a/src/Annotations/Schema.php +++ b/src/Annotations/Schema.php @@ -266,6 +266,7 @@ class Schema extends AbstractAnnotation /** * A free-form property to include an example of an instance for this schema. + * * To represent examples that cannot be naturally represented in JSON or YAML, a string value can be used to * contain the example with escaping where necessary. */ diff --git a/src/Attributes/Items.php b/src/Attributes/Items.php index fd40055c8..92775a332 100644 --- a/src/Attributes/Items.php +++ b/src/Attributes/Items.php @@ -29,7 +29,7 @@ public function __construct( ?string $format = null, ?Items $items = null, ?string $collectionFormat = null, - $default = null, + $default = Generator::UNDEFINED, $maximum = null, ?bool $exclusiveMaximum = null, $minimum = null, @@ -46,7 +46,7 @@ public function __construct( ?bool $writeOnly = null, ?Xml $xml = null, ?ExternalDocumentation $externalDocs = null, - $example = null, + $example = Generator::UNDEFINED, ?bool $nullable = null, ?bool $deprecated = null, ?array $allOf = null, @@ -68,7 +68,7 @@ public function __construct( 'type' => $type ?? Generator::UNDEFINED, 'format' => $format ?? Generator::UNDEFINED, 'collectionFormat' => $collectionFormat ?? Generator::UNDEFINED, - 'default' => $default ?? Generator::UNDEFINED, + 'default' => $default, 'maximum' => $maximum ?? Generator::UNDEFINED, 'exclusiveMaximum' => $exclusiveMaximum ?? Generator::UNDEFINED, 'minimum' => $minimum ?? Generator::UNDEFINED, @@ -83,7 +83,7 @@ public function __construct( 'readOnly' => $readOnly ?? Generator::UNDEFINED, 'writeOnly' => $writeOnly ?? Generator::UNDEFINED, 'xml' => $xml ?? Generator::UNDEFINED, - 'example' => $example ?? Generator::UNDEFINED, + 'example' => $example, 'nullable' => $nullable ?? Generator::UNDEFINED, 'deprecated' => $deprecated ?? Generator::UNDEFINED, 'allOf' => $allOf ?? Generator::UNDEFINED, diff --git a/src/Attributes/JsonContent.php b/src/Attributes/JsonContent.php index 2d4961943..54be25c5e 100644 --- a/src/Attributes/JsonContent.php +++ b/src/Attributes/JsonContent.php @@ -31,7 +31,7 @@ public function __construct( ?string $format = null, ?Items $items = null, ?string $collectionFormat = null, - $default = null, + $default = Generator::UNDEFINED, $maximum = null, ?bool $exclusiveMaximum = null, $minimum = null, @@ -48,7 +48,7 @@ public function __construct( ?bool $writeOnly = null, ?Xml $xml = null, ?ExternalDocumentation $externalDocs = null, - $example = null, + $example = Generator::UNDEFINED, ?bool $nullable = null, ?bool $deprecated = null, ?array $allOf = null, @@ -71,7 +71,7 @@ public function __construct( 'type' => $type ?? Generator::UNDEFINED, 'format' => $format ?? Generator::UNDEFINED, 'collectionFormat' => $collectionFormat ?? Generator::UNDEFINED, - 'default' => $default ?? Generator::UNDEFINED, + 'default' => $default, 'maximum' => $maximum ?? Generator::UNDEFINED, 'exclusiveMaximum' => $exclusiveMaximum ?? Generator::UNDEFINED, 'minimum' => $minimum ?? Generator::UNDEFINED, @@ -86,7 +86,7 @@ public function __construct( 'readOnly' => $readOnly ?? Generator::UNDEFINED, 'writeOnly' => $writeOnly ?? Generator::UNDEFINED, 'xml' => $xml ?? Generator::UNDEFINED, - 'example' => $example ?? Generator::UNDEFINED, + 'example' => $example, 'nullable' => $nullable ?? Generator::UNDEFINED, 'deprecated' => $deprecated ?? Generator::UNDEFINED, 'allOf' => $allOf ?? Generator::UNDEFINED, diff --git a/src/Attributes/MediaType.php b/src/Attributes/MediaType.php index 0f2e0b20e..31668a2df 100644 --- a/src/Attributes/MediaType.php +++ b/src/Attributes/MediaType.php @@ -19,7 +19,7 @@ class MediaType extends \OpenApi\Annotations\MediaType public function __construct( ?string $mediaType = null, ?Schema $schema = null, - $example = null, + $example = Generator::UNDEFINED, ?array $examples = null, ?string $encoding = null, // annotation @@ -28,7 +28,7 @@ public function __construct( ) { parent::__construct([ 'mediaType' => $mediaType ?? Generator::UNDEFINED, - 'example' => $example ?? Generator::UNDEFINED, + 'example' => $example, 'encoding' => $encoding ?? Generator::UNDEFINED, 'x' => $x ?? Generator::UNDEFINED, 'value' => $this->combine($schema, $examples, $attachables), diff --git a/src/Attributes/Property.php b/src/Attributes/Property.php index 595b2bcc3..9aa91a9d5 100644 --- a/src/Attributes/Property.php +++ b/src/Attributes/Property.php @@ -30,7 +30,7 @@ public function __construct( ?string $format = null, ?Items $items = null, ?string $collectionFormat = null, - $default = null, + $default = Generator::UNDEFINED, $maximum = null, ?bool $exclusiveMaximum = null, $minimum = null, @@ -47,7 +47,7 @@ public function __construct( ?bool $writeOnly = null, ?Xml $xml = null, ?ExternalDocumentation $externalDocs = null, - $example = null, + $example = Generator::UNDEFINED, ?bool $nullable = null, ?bool $deprecated = null, ?array $allOf = null, @@ -70,8 +70,7 @@ public function __construct( 'type' => $type ?? Generator::UNDEFINED, 'format' => $format ?? Generator::UNDEFINED, 'collectionFormat' => $collectionFormat ?? Generator::UNDEFINED, - - 'default' => $default ?? Generator::UNDEFINED, + 'default' => $default, 'maximum' => $maximum ?? Generator::UNDEFINED, 'exclusiveMaximum' => $exclusiveMaximum ?? Generator::UNDEFINED, 'minimum' => $minimum ?? Generator::UNDEFINED, @@ -81,13 +80,12 @@ public function __construct( 'maxItems' => $maxItems ?? Generator::UNDEFINED, 'minItems' => $minItems ?? Generator::UNDEFINED, 'uniqueItems' => $uniqueItems ?? Generator::UNDEFINED, - 'pattern' => $pattern ?? Generator::UNDEFINED, 'enum' => $enum ?? Generator::UNDEFINED, 'readOnly' => $readOnly ?? Generator::UNDEFINED, 'writeOnly' => $writeOnly ?? Generator::UNDEFINED, 'xml' => $xml ?? Generator::UNDEFINED, - 'example' => $example ?? Generator::UNDEFINED, + 'example' => $example, 'nullable' => $nullable ?? Generator::UNDEFINED, 'deprecated' => $deprecated ?? Generator::UNDEFINED, 'allOf' => $allOf ?? Generator::UNDEFINED, diff --git a/src/Attributes/Schema.php b/src/Attributes/Schema.php index 14c07f01d..9c217de74 100644 --- a/src/Attributes/Schema.php +++ b/src/Attributes/Schema.php @@ -29,7 +29,7 @@ public function __construct( ?string $format = null, ?Items $items = null, ?string $collectionFormat = null, - $default = null, + $default = Generator::UNDEFINED, $maximum = null, ?bool $exclusiveMaximum = null, $minimum = null, @@ -46,7 +46,7 @@ public function __construct( ?bool $writeOnly = null, ?Xml $xml = null, ?ExternalDocumentation $externalDocs = null, - $example = null, + $example = Generator::UNDEFINED, ?bool $nullable = null, ?bool $deprecated = null, ?array $allOf = null, @@ -67,7 +67,7 @@ public function __construct( 'type' => $type ?? Generator::UNDEFINED, 'format' => $format ?? Generator::UNDEFINED, 'collectionFormat' => $collectionFormat ?? Generator::UNDEFINED, - 'default' => $default ?? Generator::UNDEFINED, + 'default' => $default, 'maximum' => $maximum ?? Generator::UNDEFINED, 'exclusiveMaximum' => $exclusiveMaximum ?? Generator::UNDEFINED, 'minimum' => $minimum ?? Generator::UNDEFINED, @@ -82,7 +82,7 @@ public function __construct( 'readOnly' => $readOnly ?? Generator::UNDEFINED, 'writeOnly' => $writeOnly ?? Generator::UNDEFINED, 'xml' => $xml ?? Generator::UNDEFINED, - 'example' => $example ?? Generator::UNDEFINED, + 'example' => $example, 'nullable' => $nullable ?? Generator::UNDEFINED, 'deprecated' => $deprecated ?? Generator::UNDEFINED, 'allOf' => $allOf ?? Generator::UNDEFINED, diff --git a/src/Attributes/XmlContent.php b/src/Attributes/XmlContent.php index 94dec7818..b73de7750 100644 --- a/src/Attributes/XmlContent.php +++ b/src/Attributes/XmlContent.php @@ -31,7 +31,7 @@ public function __construct( ?string $format = null, ?Items $items = null, ?string $collectionFormat = null, - $default = null, + $default = Generator::UNDEFINED, $maximum = null, ?bool $exclusiveMaximum = null, $minimum = null, @@ -48,7 +48,7 @@ public function __construct( ?bool $writeOnly = null, ?Xml $xml = null, ?ExternalDocumentation $externalDocs = null, - $example = null, + $example = Generator::UNDEFINED, ?bool $nullable = null, ?bool $deprecated = null, ?array $allOf = null, @@ -71,7 +71,7 @@ public function __construct( 'type' => $type ?? Generator::UNDEFINED, 'format' => $format ?? Generator::UNDEFINED, 'collectionFormat' => $collectionFormat ?? Generator::UNDEFINED, - 'default' => $default ?? Generator::UNDEFINED, + 'default' => $default, 'maximum' => $maximum ?? Generator::UNDEFINED, 'exclusiveMaximum' => $exclusiveMaximum ?? Generator::UNDEFINED, 'minimum' => $minimum ?? Generator::UNDEFINED, @@ -86,7 +86,7 @@ public function __construct( 'readOnly' => $readOnly ?? Generator::UNDEFINED, 'writeOnly' => $writeOnly ?? Generator::UNDEFINED, 'xml' => $xml ?? Generator::UNDEFINED, - 'example' => $example ?? Generator::UNDEFINED, + 'example' => $example, 'nullable' => $nullable ?? Generator::UNDEFINED, 'deprecated' => $deprecated ?? Generator::UNDEFINED, 'allOf' => $allOf ?? Generator::UNDEFINED, diff --git a/tests/Fixtures/Apis/Attributes/basic.php b/tests/Fixtures/Apis/Attributes/basic.php index ee3d666db..59dee3aaf 100644 --- a/tests/Fixtures/Apis/Attributes/basic.php +++ b/tests/Fixtures/Apis/Attributes/basic.php @@ -64,7 +64,7 @@ class Product implements ProductInterface public function __construct( #[OAT\Property()] public int $quantity, - #[OAT\Property()] public string $brand, + #[OAT\Property(nullable: true, default: null, example: null)] public string $brand, #[OAT\Property()] public Colour $colour, #[OAT\Property(type: 'string')] public \DateTimeInterface $releasedAt, ) { diff --git a/tests/Fixtures/Apis/DocBlocks/basic.php b/tests/Fixtures/Apis/DocBlocks/basic.php index 79ef3037c..922d4ac20 100644 --- a/tests/Fixtures/Apis/DocBlocks/basic.php +++ b/tests/Fixtures/Apis/DocBlocks/basic.php @@ -85,7 +85,7 @@ class Product implements ProductInterface /** @OA\Property */ public int $quantity; - /** @OA\Property */ + /** @OA\Property(nullable=true, default=null, example=null) */ public string $brand; /** @OA\Property */ diff --git a/tests/Fixtures/Apis/Mixed/basic.php b/tests/Fixtures/Apis/Mixed/basic.php index 90e9b7763..85bef7b48 100644 --- a/tests/Fixtures/Apis/Mixed/basic.php +++ b/tests/Fixtures/Apis/Mixed/basic.php @@ -78,7 +78,7 @@ class Product implements ProductInterface #[OAT\Property()] public int $quantity; - #[OAT\Property()] + #[OAT\Property(nullable: true, default: null, example: null)] public string $brand; /** @OA\Property */ diff --git a/tests/Fixtures/Apis/basic.yaml b/tests/Fixtures/Apis/basic.yaml index d579b1264..a0402c036 100644 --- a/tests/Fixtures/Apis/basic.yaml +++ b/tests/Fixtures/Apis/basic.yaml @@ -108,7 +108,11 @@ components: quantity: type: integer brand: - type: string + type: + - string + - 'null' + default: null + example: null colour: $ref: '#/components/schemas/Colour' id: