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

Can we add SchemaType.Intersection for SProducts? #3767

Open
oyvindberg opened this issue May 15, 2024 · 1 comment
Open

Can we add SchemaType.Intersection for SProducts? #3767

oyvindberg opened this issue May 15, 2024 · 1 comment

Comments

@oyvindberg
Copy link

So let me describe a use case I'm fairly sure is familiar.

I have bunch of data types. Some product types appear both in a sum type and alone. I prefer to use discriminators in sum types.

The way this typically works out is that you get two unrelated types in JSON Schema, where one has a 1 suffix, one of the two have the discriminator field, and they share the entire structure otherwise.

I'd like for this to be rendered as two types in JSON Schema:

  • Foo (without discriminator)
  • FooDisc (with discriminator)

Where FooDisc would be expressed using allOf in JSON Schema. This way the relationship would be clear, there would be less duplication.

I can try a PR myself, just wanted to check if it looks worthwhile first

@adamw
Copy link
Member

adamw commented May 16, 2024

Interesting - definitely better than Foo and Foo1 schemas. I don't think we can add a new SchemaType implementation, though, as that would break binary compatibility I think? But maybe that's not needed - and it would be enough to add this logic at the tapir schema -> openapi schema translation stage? (in the TapirSchemaToJsonSchema class)

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