diff --git a/utoipa-gen/tests/schema_derive_test.rs b/utoipa-gen/tests/schema_derive_test.rs index d3adc26c..94ce81d7 100644 --- a/utoipa-gen/tests/schema_derive_test.rs +++ b/utoipa-gen/tests/schema_derive_test.rs @@ -4387,3 +4387,35 @@ fn derive_unit_type_untagged_enum() { }) ) } + +#[test] +fn derive_schema_with_unit_hashmap() { + let value = api_doc! { + struct Container { + volumes: HashMap> + } + }; + + assert_json_eq!( + value, + json!({ + "properties": { + "volumes": { + "additionalProperties": { + "additionalProperties": { + "type": "object", + "default": null, + "nullable": true, + }, + "type": "object" + }, + "type": "object" + }, + }, + "required": [ + "volumes" + ], + "type": "object" + }) + ) +} diff --git a/utoipa/src/openapi/schema.rs b/utoipa/src/openapi/schema.rs index 1f2c7bae..340fc6ff 100644 --- a/utoipa/src/openapi/schema.rs +++ b/utoipa/src/openapi/schema.rs @@ -895,6 +895,12 @@ impl From for AdditionalProperties { } } +impl From for AdditionalProperties { + fn from(value: Schema) -> Self { + Self::RefOr(RefOr::T(value)) + } +} + /// Implements [OpenAPI Reference Object][reference] that can be used to reference /// reusable components such as [`Schema`]s or [`Response`]s. ///