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

Invalid inline schema defined in oneOf according to spec #346

Closed
affanshahid opened this issue Nov 11, 2022 · 4 comments · Fixed by #1059
Closed

Invalid inline schema defined in oneOf according to spec #346

affanshahid opened this issue Nov 11, 2022 · 4 comments · Fixed by #1059
Labels
Discriminator Openapi Discriminator

Comments

@affanshahid
Copy link

affanshahid commented Nov 11, 2022

Trying to use OpenAPI Generator CLI for my API which has some enums with type tag. I'm getting the following error:

WARN  o.o.codegen.DefaultCodegen - Invalid inline schema defined in oneOf/anyOf in 'CreateQuestionData'. Per the OpenApi spec, for this case when a composed schema defines a discriminator, the oneOf/anyOf schemas must use $ref. Change this inline definition to a $ref definition

This leads to invalid type generation for enums. I am assuming this is because utoipa generates an inline schema for enums whereas according to the spec it should use $refs?

Any workarounds?

@juhaku
Copy link
Owner

juhaku commented Dec 10, 2022

Not sure about this. Probably depending on generation library itself. According to spec enums are allowed to have inlined schemas as well or references. Way I have validated the spec is basically checked it with editor.swagger.io to see whether it gives any lint errors.

Since the rust types are so flexible it also depends on how you have defined your enum. For tagged enums with serde(tag = ...) The enums are most likely necessary to be inlined in order to create the schema serde json would output. Other way would be to start restricting what kind of types users can actually define. But I would not like to choose restricting unless it is absolutely necessary.

But more context to this would be appreciated, like what kind of enum you have defined, and what is the code generation library you have used here? Perhaps I will find time to investigate this in future, but I cannot promise anything.

@juhaku
Copy link
Owner

juhaku commented Sep 16, 2024

Related to #617

@juhaku
Copy link
Owner

juhaku commented Sep 18, 2024

@affanshahid I commented on another issue related to this discriminator thing. I'd like some ideas of regarding how to solve this, see #621 (comment)

@juhaku juhaku added the Discriminator Openapi Discriminator label Sep 18, 2024
@juhaku
Copy link
Owner

juhaku commented Sep 21, 2024

Going to be fixed in #1059 as explained here #617 (comment)

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

Successfully merging a pull request may close this issue.

2 participants