Skip to content

Commit 96a6cdf

Browse files
author
Jean-Marc Le Roux
committed
fix(utoipa-gen): degenerate oneOf when using Option<_> + nullable = false + default
1 parent 975dece commit 96a6cdf

3 files changed

Lines changed: 4 additions & 12 deletions

File tree

utoipa-gen/src/component.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1358,7 +1358,7 @@ impl ComponentSchema {
13581358
// TODO: refs support `summary` field but currently there is no such field
13591359
// on schemas more over there is no way to distinct the `summary` from
13601360
// `description` of the ref. Should we consider supporting the summary?
1361-
let schema = if default.is_some() || nullable || title.is_some() {
1361+
let schema = if nullable {
13621362
composed_or_ref(quote_spanned! {type_path.span()=>
13631363
utoipa::openapi::schema::OneOfBuilder::new()
13641364
#nullable_item

utoipa-gen/tests/snapshots/schema_derive_test__derive_schema_unnamed_title-2.snap

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ expression: enum_value
44
snapshot_kind: text
55
---
66
{
7-
"oneOf": [
8-
{
9-
"$ref": "#/components/schemas/UnnamedEnum"
10-
}
11-
],
7+
"$ref": "#/components/schemas/UnnamedEnum",
128
"title": "This is enum ref title"
139
}

utoipa-gen/tests/snapshots/schema_derive_test__derive_struct_with_default_attr_field.snap

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,10 @@ snapshot_kind: text
3030
"type": "array"
3131
},
3232
"favorite_book": {
33+
"$ref": "#/components/schemas/Book",
3334
"default": {
3435
"name": "Dune"
35-
},
36-
"oneOf": [
37-
{
38-
"$ref": "#/components/schemas/Book"
39-
}
40-
]
36+
}
4137
},
4238
"leases": {
4339
"additionalProperties": {

0 commit comments

Comments
 (0)