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

Implement nullable refs #671

Closed
wants to merge 1 commit into from
Closed

Conversation

BenMorel
Copy link
Contributor

This is a follow-up to #670.

The idea is to transform a nullable property:

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

Into this:

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

The implementation is simple:

  • if the property types contain 'null': set nullable and allOf with ref
  • else: set ref as usual

✅ No BC breaks
✅ Covered by tests

@BenMorel
Copy link
Contributor Author

Any feedback here?

@BenMorel
Copy link
Contributor Author

Bump.

@bfanger
Copy link
Collaborator

bfanger commented Jul 6, 2019

I noticed the allOf (which is correct btw) but I'd like to see oneOf and general support for the | operator, not just for null, for example:

/**
 * @var Deal|Scam
 */

Would generate:

       deal:
          oneOf:
            -
              $ref: '#/components/schemas/Deal'
            -
              $ref: '#/components/schemas/Scam'

Do you agree? and would you like to implement that feature?

@BenMorel
Copy link
Contributor Author

BenMorel commented Jul 6, 2019

I agree this would be nice, but I think that it is a separate issue that can be handled after the current PR is merged! I can work on it if you wish.

@bfanger
Copy link
Collaborator

bfanger commented Jul 7, 2019

Merged as 615941e
(I've changed allOf to oneOf, with only one entry it has the same meaning, but makes the aforementioned feature easier to implement)

Looking forward to your PR

@bfanger bfanger closed this Jul 7, 2019
@BenMorel
Copy link
Contributor Author

BenMorel commented Jul 8, 2019

Cool, thanks! I'll try to find some time this week to work on the generic union types.

@bfanger bfanger mentioned this pull request Aug 19, 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

Successfully merging this pull request may close these issues.

2 participants