Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nullability and requiredness of a property gets ignored when using an attribute derived from \OpenApi\Attributes\Property #2128

Open
egonolieux opened this issue Aug 16, 2023 · 3 comments

Comments

@egonolieux
Copy link

egonolieux commented Aug 16, 2023

If a class has a nullable property:

final readonly class SomeObject
{
    public function __construct(
        public ?int $number,
    ) {}
}

The OpenAPI spec is generated correctly with nullable set to true:

"number": {
    "type": "integer",
    "nullable": true
}

However, when the number property has an attribute that is derived from the OpenAPI OpenApi\Attributes\Property class (where CustomOpenApiProperty is defined as final class CustomOpenApiProperty extends \OpenApi\Attributes\Property):

final readonly class SomeObject
{
    public function __construct(
        #[CustomOpenApiProperty()]
        public ?int $number,
    ) {}
}

The OpenAPI spec is generated without nullable:

"number": {
    "type": "integer",
    "x": [
        "someCustomData": "someCustomValue"
    ]
}

As I'm unfamiliar with the internals of this bundle, this might be a more general issue not specific to nullable.


Update: this issue also applies to the the property being required since #2111 was fixed.

@egonolieux egonolieux changed the title Nullability of a property gets ignored when using the App\OpenApi\Attribute\Property attribute Nullability of a property gets ignored when using an attribute derived from App\OpenApi\Attribute\Property Aug 16, 2023
@egonolieux egonolieux changed the title Nullability of a property gets ignored when using an attribute derived from App\OpenApi\Attribute\Property Nullability of a property gets ignored when using an attribute derived from \OpenApi\Attributes\Property Aug 16, 2023
@DerManoMann
Copy link
Contributor

This might be more likely an issue in the underlying swagger-php library.

@egonolieux
Copy link
Author

This might be more likely an issue in the underlying swagger-php library.

I think not, because using the OpenApi\Attributes\Property directly does not reproduce the issue. I suspect this might be caused by the merging logic of the describers somehow.

@DerManoMann
Copy link
Contributor

Turns out you are right ;) - zircote/swagger-php#1466

Historically there have been cases in the library where code was checking for specific class types, but I think those should be all gone by now.

@egonolieux egonolieux changed the title Nullability of a property gets ignored when using an attribute derived from \OpenApi\Attributes\Property Nullability and requiredness of a property gets ignored when using an attribute derived from \OpenApi\Attributes\Property Jan 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants