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 dropdown for discriminator #10224

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

YousefHaggy
Copy link

@YousefHaggy YousefHaggy commented Nov 25, 2024

Fixes #2438 and adds a dropdown to select between schemas that extend a base schema via allOf with discriminator

dropdown

Sample spec:
spec.json

Description

  • When parsing the spec, build a map of parent to child schemas
  • In ModelWrapper, if the current schema has child schemas, render a drop down to select from those schemas
  • Supports both explicit and implicit mappings

Motivation and Context

OpenAPI spec supports inheritance via allOf and discriminator, but currently in Swagger UI when you reference a schema that is extended with allOf, there's no indication of this inheritance and valid child schemas a user can input. Provides a poor user experience for specs that rely on this kind of structure

This works in other tools like Redoc: https://github.com/Rebilly/ReDoc/blob/master/docs/images/discriminator-demo.gif

Fixes #2438. Solves a very common allOf usecase, some examples in the OAS 3.1.1 official spec

How Has This Been Tested?

I've manually tested this change using the attached sample spec. I tested for both 3.0 and 3.1. I tested a spec with no explicit mappings, all explicit mappings, and a mix

spec.json

Ran all existing unit tests successfully. Tried to run npm run e2e as the README.md says, but no script e2e exists

Screenshots (if appropriate):

Checklist

My PR contains...

  • No code changes (src/ is unmodified: changes to documentation, CI, metadata, etc.)
  • Dependency changes (any modification to dependencies in package.json)
  • Bug fixes (non-breaking change which fixes an issue)
  • Improvements (misc. changes to existing features)
  • Features (non-breaking change which adds functionality)

My changes...

  • are breaking changes to a public API (config options, System API, major UI change, etc).
  • are breaking changes to a private API (Redux, component props, utility functions, etc.).
  • are breaking changes to a developer API (npm script behavior changes, new dev system dependencies, etc).
  • are not breaking changes.

Documentation

  • My changes do not require a change to the project documentation.
  • My changes require a change to the project documentation.
  • If yes to above: I have updated the documentation accordingly.

Automated tests

  • My changes can not or do not need to be tested.
  • My changes can and should be tested by unit and/or integration tests.
  • If yes to above: I have added tests to cover my changes.
  • If yes to above: I have taken care to cover edge cases in my tests.
  • All new and existing tests passed.

@@ -357,6 +357,7 @@ export default class ParameterRow extends Component {
getConfigs={ getConfigs }
isExecute={ isExecute }
specSelectors={ specSelectors }
specActions={ specActions }
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a better way to get specAction down to model-wrapper.jsx than plumbing it down everywhere like this? I couldn't find a context provider with specActions in the hierarchy

@@ -2,7 +2,8 @@
{
font-size: 12px;
font-weight: 300;

display: block;
Copy link
Author

@YousefHaggy YousefHaggy Nov 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for OAS 3.0.X, the model is inline with the dropdown if we don't specify this

@YousefHaggy
Copy link
Author

@char0n Could I get you or another maintainers review on this? Thanks!

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.

Discriminator does not switch schema
1 participant