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

Better discriminator support? #85

Open
danp opened this issue Oct 12, 2023 · 1 comment
Open

Better discriminator support? #85

danp opened this issue Oct 12, 2023 · 1 comment

Comments

@danp
Copy link

danp commented Oct 12, 2023

Hi there, thanks for this family of modules.

I'm using this module to generate schema near existing HTTP handler code (like a minimal version of swaggest/rest). Trying to use oneOf in a request body which works fine using JSONSchemaOneOf. But I can't seem to crack an easy or straightforward way to set discriminator as described here.

I see that Schema has Discriminator on it but I'm not quite sure how to get there from something like this.

I tried implementing jsonschema.Preparer and Exposer but don't think I can influence discriminator that way.

Assuming I'm not missing something (apologies if I am!), would some better support for this be good? I could see discriminator tag support somewhere to set propertyName. But it would probably also be good to support mapping as well.

Happy to try putting a PR together if there's a direction you'd like to go.

Thanks again!

@danp
Copy link
Author

danp commented Oct 12, 2023

If I dig into the spec after AddOperation I can do it in a roundabout way, eg:

c := ref.Spec.Components.Schemas.MapOfSchemaOrRefValues["SomethingUsingOneOf"]
c.Schema.WithDiscriminator(openapi3.Discriminator{PropertyName: "kind"})

But I have to know what name the component will end up with. And it would be nicer to do it closer to my handler and related types.

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

1 participant