Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(#2222): Fix properties with default values getting marked as requ…
…ired (#2248) * fix(#2222): Fix default value properties getting marked as required * Implement PR review feedback * Fix tests for PHP 7.4 * Fix code style * refactor promoted properties tests * remove readonly * remove testEntityWithPromotedPropertiesWithDefaults * add license header --------- Co-authored-by: DjordyKoert <djordy.koert@yoursurprise.com>
- Loading branch information
1 parent
196ef00
commit 7f46161
Showing
10 changed files
with
318 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
tests/Functional/Configs/AlternativeNamesPHP80Entities.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Removes the `80` suffix from the entity names used in annotation entities. | ||
nelmio_api_doc: | ||
models: | ||
names: | ||
- alias: EntityWithPromotedPropertiesWithDefaults | ||
type: Nelmio\ApiDocBundle\Tests\Functional\Entity\EntityWithPromotedPropertiesWithDefaults80 | ||
- alias: EntityWithAlternateType | ||
type: Nelmio\ApiDocBundle\Tests\Functional\Entity\EntityWithAlternateType80 | ||
|
||
# Clean unused components from the OpenAPI schema. | ||
services: | ||
OpenApi\Processors\CleanUnusedComponents: | ||
tags: | ||
- { name: 'nelmio_api_doc.swagger.processor', priority: -100 } |
14 changes: 14 additions & 0 deletions
14
tests/Functional/Configs/AlternativeNamesPHP81Entities.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Removes the `81` suffix from the entity names used in attribute entities. | ||
nelmio_api_doc: | ||
models: | ||
names: | ||
- alias: EntityWithPromotedPropertiesWithDefaults | ||
type: Nelmio\ApiDocBundle\Tests\Functional\Entity\EntityWithPromotedPropertiesWithDefaults81 | ||
- alias: EntityWithAlternateType | ||
type: Nelmio\ApiDocBundle\Tests\Functional\Entity\EntityWithAlternateType81 | ||
|
||
# Clean unused components from the OpenAPI schema. | ||
services: | ||
OpenApi\Processors\CleanUnusedComponents: | ||
tags: | ||
- { name: 'nelmio_api_doc.swagger.processor', priority: -100 } |
42 changes: 42 additions & 0 deletions
42
tests/Functional/Controller/PromotedPropertiesController80.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the NelmioApiDocBundle package. | ||
* | ||
* (c) Nelmio | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Nelmio\ApiDocBundle\Tests\Functional\Controller; | ||
|
||
use Nelmio\ApiDocBundle\Annotation\Model; | ||
use Nelmio\ApiDocBundle\Tests\Functional\Entity\EntityWithPromotedPropertiesWithDefaults80; | ||
use OpenApi\Annotations as OA; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
|
||
class PromotedPropertiesController80 | ||
{ | ||
/** | ||
* @Route("/entity-with-promoted-properties-with-defaults", methods={"GET"}) | ||
* | ||
* @OA\Get( | ||
* operationId="getEntityWithPromotedPropertiesWithDefaults", | ||
* ) | ||
* | ||
* @OA\Response( | ||
* response="204", | ||
* description="Operation automatically detected", | ||
* ), | ||
* | ||
* @OA\RequestBody( | ||
* | ||
* @Model(type=EntityWithPromotedPropertiesWithDefaults80::class)) | ||
* )*/ | ||
public function entityWithPromotedPropertiesWithDefaults() | ||
{ | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
tests/Functional/Controller/PromotedPropertiesController81.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the NelmioApiDocBundle package. | ||
* | ||
* (c) Nelmio | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Nelmio\ApiDocBundle\Tests\Functional\Controller; | ||
|
||
use Nelmio\ApiDocBundle\Annotation\Model; | ||
use Nelmio\ApiDocBundle\Tests\Functional\Entity\EntityWithPromotedPropertiesWithDefaults81; | ||
use OpenApi\Attributes as OA; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
|
||
class PromotedPropertiesController81 | ||
{ | ||
#[Route('/entity-with-promoted-properties-with-defaults', methods: ['GET'])] | ||
#[OA\Get( | ||
operationId: 'getEntityWithPromotedPropertiesWithDefaults', | ||
)] | ||
#[OA\Response( | ||
response: 204, | ||
description: 'Operation automatically detected', | ||
)] | ||
#[OA\RequestBody( | ||
content: new Model(type: EntityWithPromotedPropertiesWithDefaults81::class), | ||
)] | ||
public function entityWithPromotedPropertiesWithDefaults() | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
tests/Functional/Entity/EntityWithPromotedPropertiesWithDefaults80.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the NelmioApiDocBundle package. | ||
* | ||
* (c) Nelmio | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Nelmio\ApiDocBundle\Tests\Functional\Entity; | ||
|
||
use Symfony\Component\Validator\Constraints as Assert; | ||
|
||
class EntityWithPromotedPropertiesWithDefaults80 | ||
{ | ||
/** | ||
* @Assert\NotBlank() | ||
*/ | ||
public string $nonNullableNonPromotedPropertyWithDefault; | ||
|
||
public function __construct( | ||
int $nonNullableNonPromotedProperty, | ||
?string $nullableNonPromotedProperty, | ||
|
||
string $nonNullableNonPromotedPropertyWithDefault = 'nonNullableNonPromotedPropertyWithDefault', | ||
?int $nullableNonPromotedPropertyWithDefault = null, | ||
|
||
public int $nonNullablePromotedPropertyWithDefault = 4711, | ||
public ?string $nullablePromotedPropertyWithDefault = null, | ||
) { | ||
$this->nonNullableNonPromotedPropertyWithDefault = $nonNullableNonPromotedPropertyWithDefault; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
tests/Functional/Entity/EntityWithPromotedPropertiesWithDefaults81.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the NelmioApiDocBundle package. | ||
* | ||
* (c) Nelmio | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Nelmio\ApiDocBundle\Tests\Functional\Entity; | ||
|
||
use Symfony\Component\Validator\Constraints as Assert; | ||
|
||
class EntityWithPromotedPropertiesWithDefaults81 | ||
{ | ||
#[Assert\NotBlank] | ||
public readonly string $nonNullableNonPromotedPropertyWithDefault; | ||
|
||
public function __construct( | ||
int $nonNullableNonPromotedProperty, | ||
?string $nullableNonPromotedProperty, | ||
|
||
string $nonNullableNonPromotedPropertyWithDefault = 'nonNullableNonPromotedPropertyWithDefault', | ||
?int $nullableNonPromotedPropertyWithDefault = null, | ||
|
||
public readonly int $nonNullablePromotedPropertyWithDefault = 4711, | ||
public readonly ?string $nullablePromotedPropertyWithDefault = null, | ||
) { | ||
$this->nonNullableNonPromotedPropertyWithDefault = $nonNullableNonPromotedPropertyWithDefault; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
{ | ||
"openapi": "3.0.0", | ||
"info": { | ||
"title": "", | ||
"version": "0.0.0" | ||
}, | ||
"paths": { | ||
"/entity-with-promoted-properties-with-defaults": { | ||
"get": { | ||
"operationId": "getEntityWithPromotedPropertiesWithDefaults", | ||
"requestBody": { | ||
"content": { | ||
"application/json": { | ||
"schema": { | ||
"$ref": "#/components/schemas/EntityWithPromotedPropertiesWithDefaults" | ||
} | ||
} | ||
} | ||
}, | ||
"responses": { | ||
"204": { | ||
"description": "Operation automatically detected" | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"components": { | ||
"schemas": { | ||
"EntityWithPromotedPropertiesWithDefaults": { | ||
"properties": { | ||
"nonNullableNonPromotedPropertyWithDefault": { | ||
"type": "string", | ||
"default": "nonNullableNonPromotedPropertyWithDefault" | ||
}, | ||
"nonNullablePromotedPropertyWithDefault": { | ||
"type": "integer", | ||
"default": 4711 | ||
}, | ||
"nullablePromotedPropertyWithDefault": { | ||
"type": "string", | ||
"default": null, | ||
"nullable": true | ||
} | ||
}, | ||
"type": "object" | ||
} | ||
} | ||
} | ||
} |