@@ -438,7 +438,7 @@ impl SchemaRenderer<JsonSchema> for JsonSchemaRenderer {
438438 ) -> RenderResult < JsonSchema > {
439439 let mut properties = BTreeMap :: new ( ) ;
440440 let mut required = BTreeSet :: from_iter ( structure. required . clone ( ) . unwrap_or_default ( ) ) ;
441- let mut additional_properties = JsonSchema :: Bool ( false ) ;
441+ let mut additional_properties = Some ( Box :: new ( JsonSchema :: Bool ( false ) ) ) ;
442442 let exclude_aliases = self . options . exclude_aliases ;
443443
444444 for ( name, field) in & structure. fields {
@@ -447,7 +447,19 @@ impl SchemaRenderer<JsonSchema> for JsonSchemaRenderer {
447447 }
448448
449449 if field. flatten {
450- additional_properties = self . render_schema_without_reference ( & field. schema ) ?;
450+ if let Some ( schema) = field. schema . get_nonnull_schema ( ) {
451+ let flattened = self . render_schema_without_reference ( schema) ?;
452+
453+ if matches ! ( schema. ty, SchemaType :: Object ( _) )
454+ && let JsonSchema :: Object ( inner) = flattened. clone ( )
455+ && let Some ( object) = inner. object
456+ {
457+ additional_properties = object. additional_properties ;
458+ } else {
459+ additional_properties = Some ( Box :: new ( flattened) ) ;
460+ }
461+ }
462+
451463 continue ;
452464 }
453465
@@ -471,7 +483,7 @@ impl SchemaRenderer<JsonSchema> for JsonSchemaRenderer {
471483 metadata : Some ( Box :: new ( self . create_metadata_from_schema ( schema) ) ) ,
472484 instance_type : Some ( SingleOrVec :: Single ( Box :: new ( InstanceType :: Object ) ) ) ,
473485 object : Some ( Box :: new ( ObjectValidation {
474- additional_properties : Some ( Box :: new ( additional_properties ) ) ,
486+ additional_properties,
475487 required,
476488 properties,
477489 ..Default :: default ( )
0 commit comments