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

Different state of real class properties and schema properties: nullable #1318

Open
dmitrach opened this issue Sep 29, 2022 · 1 comment
Open
Labels
type handling Type handling / mapping

Comments

@dmitrach
Copy link

Hello. Thank you for your package, it has saved some my time due to existent documentation in classes.

But I found a feature or a bug) when the real properties of a class are different with schema properties.

Steps to reproduce

I have the next code.

    /**
     * Some description.
     *
     * @OA\Property(nullable=false, format="number", example="0.00")
     */
    public ?string $value = null;

It describes the value that has the default value null, but this value is never returned in responses and there is always non-null values, like 0.00.

I expected the follow description in yaml. There is nullable: false or without nullable due to I redefine this property.

      properties:
        annual:
          description: 'Some description.'
          type: string
          nullable: false # here
          format: number
          example: '0.00'

or

      properties:
        annual:
          description: 'Some description.'
          type: string # there isn't nullable here
          format: number
          example: '0.00'

But I got the follow result.

      properties:
        annual:
          description: 'Some description.'
          type: string
          nullable: true # here
          format: number
          example: '0.00'

To fix it I've redefined the value type: type="string".

    /**
     * Some description.
     *
     * @OA\Property(type="string", format="number", example="0.00")
     */
    public ?string $value = null;

Now I got this result.

      properties:
        annual:
          description: 'Some description.'
          type: string # there isn't nullable here, because I defined another type.
          format: number
          example: '0.00'

I would like to know, it is a bug or a feature? Perhabs the tool should override the detected state of the property.

Thank you!

@DerManoMann
Copy link
Collaborator

A bit of both, probably.

Type handling is not very consistent and the introduction of attributes added to that too.

There are no clear rules about priority, but I agree the annotation should be the authority in this case.
Hopefully this will be fixed as part of #1310

@DerManoMann DerManoMann added the type handling Type handling / mapping label Oct 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type handling Type handling / mapping
Projects
None yet
Development

No branches or pull requests

2 participants