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

How to handle nullable property references? #670

Closed
BenMorel opened this issue Apr 12, 2019 · 2 comments
Closed

How to handle nullable property references? #670

BenMorel opened this issue Apr 12, 2019 · 2 comments

Comments

@BenMorel
Copy link
Contributor

First of all sorry if I missed something obvious, but I've been struggling to find any information about how to handle this basic use case.

I have a Schema class that's not defined as nullable:

/**
 * @OA\Schema()
 */
class Deal
{
}

When I want to use it in another Schema class and make it nullable, I write:

/**
 * @OA\Schema()
 */
class Reservation
{
    /**
     * @OA\Property()
     *
     * @var Deal|null
     */
    public $deal;
}

However, |null is not taken into account like it is for scalar types, and this generates a $ref to the non-nullable Schema, like if I'd written @var Deal:

components:
  schemas:
    Reservation:
      properties:
        deal:
          $ref: '#/components/schemas/Deal'

Is this expected behaviour? I'd expect this library to generate something like:

        deal:
          nullable: true
          allOf:
            -
              $ref: '#/components/schemas/Deal'

Which is what the spec seems to suggest.

In the meantime, I tried to manually configure the @Property, with no luck so far:

    /**
     * @OA\Property(allOf={@OA\Schema(ref="#/components/schemas/Deal")}, nullable=true)
     *
     * @var Deal|null
     */
    public $deal;

This does not work as it still generates the $ref:

        deal:
          nullable: true
          allOf:
            -
              $ref: '#/components/schemas/Deal'
          $ref: '#/components/schemas/Deal'

What did I miss? Thanks in advance!

@BenMorel
Copy link
Contributor Author

After digging through the code, it looks to me like this case is just not supported at the moment.
So I went ahead and implemented it in #671.

Feedback welcome, I desperately need this feature! 👍

@bfanger
Copy link
Collaborator

bfanger commented Jul 6, 2019

Closing this as "duplicate" of #671

@bfanger bfanger closed this as completed Jul 6, 2019
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