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

[Bug]: @OA\Property excludes property from model's required array #2271

Open
v-noskov opened this issue Apr 18, 2024 · 2 comments
Open

[Bug]: @OA\Property excludes property from model's required array #2271

v-noskov opened this issue Apr 18, 2024 · 2 comments
Labels

Comments

@v-noskov
Copy link

Version

4.24.1

Description

Model properties without OA\Property annotation or attribute are included in the model's 'required' array if they aren't nullable and don't have a default value. For instance, model:

class FooBarModel
{
    public int $foo;

    public string $bar;
}

is described as:

"FooBarModel": {
    "required": [
        "foo",
        "bar"
    ],
    "properties": {
        "foo": {
            "type": "integer"
        },
        "bar": {
            "type": "string"
        }
    },
    "type": "object"
}

But if you add OA\Property annotation or attribute:

class FooBarModel
{
    #[OA\Property(example: 12345)]
    public int $foo;

    public string $bar;
}

the corresponding property won't be added to the 'required' array:

"FooBarModel": {
    "required": [
        "bar"
    ],
    "properties": {
        "foo": {
            "type": "integer",
            "example": 12345
        },
        "bar": {
            "type": "string"
        }
    },
    "type": "object"
}

Additional context

No response

@v-noskov v-noskov added the bug label Apr 18, 2024
@DominicLuidold
Copy link
Contributor

I tried to reproduce this bug using your description and the sample code you provided, but it worked as expected with both version 4.24.1 and the latest version 4.25.3.

Could you provide more of your code or at best a minimal, self-contained and reproducible test case?

@v-noskov
Copy link
Author

v-noskov commented Apr 20, 2024

#2277 is a quick reproduction of this bug. When I dropped #[\OpenApi\Attributes\Property(type: 'string')] and @OA\Property(type = "string") from the User::location property, this property was included in 'required' array.
It's just a demo. If this bug will be fixed, User::location must be in 'required' array even with OA\Property attribute/annotation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants