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

Support for allOf & discriminator #29

Closed
joeydebreuk opened this issue Sep 1, 2022 · 3 comments
Closed

Support for allOf & discriminator #29

joeydebreuk opened this issue Sep 1, 2022 · 3 comments

Comments

@joeydebreuk
Copy link

Is there support for allOf & discriminator? If so, can you provide an example?

EG I want to achieve spec:

Animal:
  discriminator:
    propertyName: type
  type: object
  properties:
    name:
      type: string
    type:
      type: string
      enum:
        - dog
        - cat
Dog:
  discriminator:
    propertyName: type
  allOf:
    - $ref: '#/components/schemas/Animal'
    - type: object
      properties:
        type:
          type: string
          const: dog
      required:
        - type
@AGalabov
Copy link
Collaborator

AGalabov commented Sep 2, 2022

@joeydebreuk thank you for using zod-to-openapi.

Saddly there is no such support right now. Basically with extended schemas we took the approach of just generating the full object (i.e duplicating their schemas). There is no problem when validating because if you already have zod you can use it to validate your data. And in that case there would be no need for the discriminator in the documentation since you can use union/discriminatedUnion.

Having said that I will take a more in depth look at your request when I find the time to research the generated zod schema from an extended object (if we have some metadata that we can use) and write back to you.

AGalabov added a commit that referenced this issue Sep 3, 2022
AGalabov added a commit that referenced this issue Sep 15, 2022
…xtended-schemas

Task/#29 add support for extended schemas
@AGalabov
Copy link
Collaborator

AGalabov commented Sep 15, 2022

Hello again @joeydebreuk,

We added support for extended schemas in the PR linked to your issue. The discriminator part is OpenApi specific and can be added using the .openapi method. A unit test with your exact example can be seen here.

Please feel free to test it out by upgrading to version 1.4.0.

Thany for using @asteasolutions/zod-to-openapi and reporting this.

@joeydebreuk
Copy link
Author

Thanks @AGalabov !

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