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

discriminator: simpler OpenAPI schema #1551

Closed
mdesousa opened this issue Jan 29, 2023 · 3 comments · Fixed by #1572
Closed

discriminator: simpler OpenAPI schema #1551

mdesousa opened this issue Jan 29, 2023 · 3 comments · Fixed by #1572

Comments

@mdesousa
Copy link
Contributor

It looks like ajv now supports the OpenAPI discriminator keyword, which seems to have better support and is a bit simpler than if-then-else.

{
  type: "object",
  discriminator: {propertyName: "foo"},
  required: ["foo"],
  oneOf: [
    {
      properties: {
        foo: {const: "x"},
        a: {type: "string"},
      },
      required: ["a"],
    },
    {
      properties: {
        foo: {enum: ["y", "z"]},
        b: {type: "string"},
      },
      required: ["b"],
    },
  ],
}

@daanboer @domoritz @mvanniekerkSQ i know you have been contributing to this feature (thanks for that by the way!)
how do you feel about switching to this approach?

@domoritz
Copy link
Member

I think we need to wait for others like vscode to catch up and support it before we can use it. This also doesn't seem like an official json schema property, right? I'd be okay with adding it as an additional hint but not to replace existing logic at this point.

@mdesousa
Copy link
Contributor Author

you are right... even though ajv is supporting it, it's not json schema yet... it's in the OpenAPI spec. the additional hint sounds like a good option 👍

@github-actions
Copy link

🚀 Issue was released in v1.3.0-next.0 🚀

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

Successfully merging a pull request may close this issue.

2 participants