-
Notifications
You must be signed in to change notification settings - Fork 299
Option + nullable = false + default expands to a degenerate oneOf #1380
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
base: master
Are you sure you want to change the base?
Conversation
42faa80
to
8d9dfa6
Compare
Ah... 😅🫠 |
As 2f2dbd3 demonstrates, the problem comes from Option<_> + nullable = false + default. I'll update the issue/title accordingly. |
Probable source of the problem: utoipa/utoipa-gen/src/component.rs Lines 1361 to 1371 in ac71b23
|
And yet, I think in OAS 3.1, $ref + default is valid. |
OAS 3.0: https://swagger.io/docs/specification/v3_0/using-ref/
OAS 3.1: https://spec.openapis.org/oas/v3.1.0#schema-object
https://json-schema.org/draft/2020-12/json-schema-core#section-8.2.3.1
And this StackOverflow answer: https://stackoverflow.com/a/41752575
Thus, I think |
f85b3a9
to
96a6cdf
Compare
@juhaku ready for review! Feedback welcome 🙏. |
Actually I think my tests are incomplete. Please wait before merging. |
There is still an issue with the utoipa/utoipa-gen/src/component.rs Lines 1290 to 1305 in ac71b23
|
…= false + default
96a6cdf
to
14d036e
Compare
I have tested the following: let schema = if nullable {
quote_spanned! {type_path.span()=>
utoipa::openapi::schema::OneOfBuilder::new()
#nullable_item
.item(#items_tokens)
#title_tokens
#default_tokens
#description_stream
}
} else {
items_tokens
}; But then, Here is an example of generated code with object = object
.property(
"orthographic",
utoipa::openapi::schema::OneOfBuilder::new()
.item(
utoipa::openapi::schema::ObjectBuilder::new()
.schema_type(utoipa::openapi::schema::Type::Null),
)
.item(
<OrthographicCamera as utoipa::PartialSchema>::schema(),
)
.description(
Some(
"An orthographic camera containing properties to create an orthographic\nprojection matrix. This property **MUST NOT** be defined when `perspective`\nis defined.",
),
),
); And with object = object
.property(
"orthographic",
<OrthographicCamera as utoipa::PartialSchema>::schema(),
); But |
When there is a title, a description or a default, the best option is probably to use a ✔️ I have tested with Swagger UI, and it does merge the title, a description and default with the object. ✔️ I have successfully validated the OpenAPI schema. ✔️ OpenAPIGenerator also generates the expected code. |
dd3133d
to
03744c5
Compare
03744c5
to
fe595a2
Compare
@juhaku I have asked ChatGPT (o4-mini-high) to generate the following summary for your review: 🐛 The Problem (Issue #1378)When you have an
the generator was emitting a “degenerate” 🔧 Key Changes
👀 What to Look For
✅ Outcome
Let me know if anything looks off or needs further tweaking! |
FYI this fix has interesting side effects with the fresh 7.13.0 release of OpenAPI Generator that includes this PR: OpenAPITools/openapi-generator#21043 One might argue that this fix might not be needed since
|
@juhaku anything I can do to help moving this forward? |
Implements #1378
Some of the code in this MR was generated with Claude Code and the generated code reviewed by me:
To Do