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 multiple oneOf calls that are not nested #528

Closed
viralanomaly opened this issue Jun 5, 2018 · 7 comments
Closed

Support multiple oneOf calls that are not nested #528

viralanomaly opened this issue Jun 5, 2018 · 7 comments

Comments

@viralanomaly
Copy link
Contributor

viralanomaly commented Jun 5, 2018

Right now, the only way to have my request show a second, unrelated oneOf selection is to do this:

MyObject:
  allOf:
    - oneOf:
        - allOf:
           - $ref: 'RefToChoice1Option1'
           - oneOf:
              - $ref: 'RefToChoice2Option1'
              - $ref: 'RefToChoice2Option2'
        - allOf:
           - $ref: 'RefToChoice1Option2'
           - oneOf:
              - $ref: 'RefToChoice2Option1'
              - $ref: 'RefToChoice2Option2'

I would prefer to be able to do this:

MyObject:
  allOf:
    - oneOf:
       - $ref: 'RefToChoice1Option1'
       - $ref: 'RefToChoice1Option2'
    - oneOf:
       - $ref: 'RefToChoice2Option1'
       - $ref: 'RefToChoice2Option2'
@RomanHotsiy
Copy link
Member

Could you please provide more details about your use case so I better understand what you are going to achieve.
Thanks

@viralanomaly
Copy link
Contributor Author

Sure. I have an absolutely wretched API to document. The request has a lot of options. I'm needing to support this sort of thing:
Provide username or email
Provide bank account details object or credit card details object
(This is very much simplified from the 5 or 6 levels of choices I actually have, but it still shows the problem)

These two choices are completely independent of each other, but the only way I can get it to render correctly in redoc is with the first style of code:


MyObject:
  allOf:
    - oneOf:
        - allOf:
           - $ref: '#/components/schemas/Username'
           - oneOf:
              - $ref: '#/components/schemas/BankAccountDetails'
              - $ref: '#/components/schemas/CreditCardDetails'
        - allOf:
           - $ref: '#/components/schemas/Email'
           - oneOf:
              - $ref: '#/components/schemas/BankAccountDetails'
              - $ref: '#/components/schemas/CreditCardDetails'
    - My other properties here that aren't a choice

I expected to be able to represent this like this when I started:


MyObject:
  allOf:
    - oneOf:
        - $ref: '#/components/schemas/Username'
        - $ref: '#/components/schemas/Email'
    - oneOf:
         - $ref: '#/components/schemas/BankAccountDetails'
         - $ref: '#/components/schemas/CreditCardDetails'
    - My other properties here that aren't a choice

@RomanHotsiy
Copy link
Member

@viralanomaly got it! Thanks for the detailed explanation.

This is rare use case and it's not so easy to fix so PR's are welcome.
Hint: I could be handled in OpenAPIParser.mergeAllOf

@viralanomaly
Copy link
Contributor Author

I'll see if I can find time to take a look. :)

@viralanomaly
Copy link
Contributor Author

@RomanGotsiy, I fear this may have broken some of the oneOf logic for displaying choices (or at least it's broken on the alpha 29 you referenced, even if it wasn't that change specifically). My spec renders correctly in swagger-editor and swagger-ui, so I'm optimistic that I have the syntax correct. Do you want me to write a new issue for it?

@RomanHotsiy
Copy link
Member

RomanHotsiy commented Jul 18, 2018

@viralanomaly Yes, please!

@viralanomaly
Copy link
Contributor Author

Here you go!

#569

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

No branches or pull requests

2 participants