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

Fix bug where oneOf within anyOf would not be rendered in request schemas #944

Merged

Conversation

robbieaverill
Copy link
Contributor

@robbieaverill robbieaverill commented Sep 5, 2024

Description

  • Add support for oneOf within anyOf when generating a schema

Motivation and Context

My schema looks like this:

MySchema:
  properties:
    some_property:
      anyOf:
        - oneOf:
            - $ref: '#/components/schemas/SchemaPartA'
            - $ref: '#/components/schemas/SchemaPartB'
          title: Either of SchemaPartA or SchemaPartB
        - type: 'null'

Currently, when I generate MySchema, the SchemaTabs component has no children which causes the page to crash. I added a workaround for that to SchemaTabs, i.e. if (!children?.length) return null.

This PR aims to add support for nested oneOf constructs within anyOf in a schema.

I realise that the same could be expressed as below, but the schema is generated from FastAPI and I have less control over changing that. As far as I can tell, the schema snippet above is valid.

      anyOf:
        - $ref: '#/components/schemas/SchemaPartA'
        - $ref: '#/components/schemas/SchemaPartB'
        - type: 'null'

Keen to hear if there is a better way to do this, or if this is simply not the right approach! Thanks in advance.

Screenshot

image

How Has This Been Tested?

  • Added a test
  • Updated snapshots
  • Added example to docs demo site

Types of changes

  • New feature (non-breaking change which adds functionality)

Checklist

  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes if appropriate.
  • All new and existing tests passed.

Copy link

github-actions bot commented Sep 5, 2024

Visit the preview URL for this PR (updated for commit cd2ef3b):

https://docusaurus-openapi-36b86--pr944-1so5qwh2.web.app

(expires Sat, 05 Oct 2024 13:54:03 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

@sserrata sserrata merged commit bdc4028 into PaloAltoNetworks:main Sep 5, 2024
15 checks passed
@robbieaverill robbieaverill deleted the fix-oneof-within-anyof branch September 5, 2024 19:48
@sserrata sserrata added v4.0.0 v4.0.0 bug Something isn't working labels Sep 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working v4.0.0 v4.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants