Skip to content

Commit

Permalink
Use Generator::UNDEFINED as default for untyped args default/example (#…
Browse files Browse the repository at this point in the history
…1189)

This allows those two to accept `null` as actual value.
  • Loading branch information
DerManoMann committed Apr 6, 2022
1 parent 2515905 commit 04c7861
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 28 deletions.
1 change: 1 addition & 0 deletions src/Annotations/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
8 changes: 4 additions & 4 deletions src/Attributes/Items.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions src/Attributes/JsonContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/Attributes/MediaType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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),
Expand Down
10 changes: 4 additions & 6 deletions src/Attributes/Property.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions src/Attributes/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions src/Attributes/XmlContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/Apis/Attributes/basic.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/Apis/DocBlocks/basic.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/Apis/Mixed/basic.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
6 changes: 5 additions & 1 deletion tests/Fixtures/Apis/basic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@ components:
quantity:
type: integer
brand:
type: string
type:
- string
- 'null'
default: null
example: null
colour:
$ref: '#/components/schemas/Colour'
id:
Expand Down

0 comments on commit 04c7861

Please sign in to comment.