Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions utoipa-gen/tests/schema_derive_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3226,6 +3226,24 @@ fn derive_map_with_property_names() {
assert_json_snapshot!(value);
}

#[test]
fn derive_map_with_optional_ref_value() {
#![allow(unused)]

#[derive(ToSchema)]
struct NewString(String);

let value = api_doc! {
struct Map {
map: std::collections::BTreeMap<String, Option<NewString>>,
#[schema(inline)]
inline_map: std::collections::BTreeMap<String, Option<NewString>>,
}
};

assert_json_snapshot!(value);
}

#[test]
fn derive_schema_with_ignored_field() {
#![allow(unused)]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
source: utoipa-gen/tests/schema_derive_test.rs
expression: value
---
{
"properties": {
"inline_map": {
"additionalProperties": {
"oneOf": [
{
"type": "string"
},
{
"type": "null"
}
]
},
"propertyNames": {
"type": "string"
},
"type": "object"
},
"map": {
"additionalProperties": {
"oneOf": [
{
"$ref": "#/components/schemas/NewString"
},
{
"type": "null"
}
]
},
"propertyNames": {
"type": "string"
},
"type": "object"
}
},
"required": [
"map",
"inline_map"
],
"type": "object"
}
12 changes: 12 additions & 0 deletions utoipa/src/openapi/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1669,6 +1669,18 @@ impl From<AllOfBuilder> for AdditionalProperties<Schema> {
}
}

impl From<OneOfBuilder> for AdditionalProperties<Schema> {
fn from(value: OneOfBuilder) -> Self {
Self::RefOr(RefOr::T(Schema::OneOf(value.build())))
}
}

impl From<AnyOfBuilder> for AdditionalProperties<Schema> {
fn from(value: AnyOfBuilder) -> Self {
Self::RefOr(RefOr::T(Schema::AnyOf(value.build())))
}
}

builder! {
RefBuilder;

Expand Down