@@ -406,15 +406,15 @@ private void processNestedSchemas(Schema schema, Set<Schema> visitedSchemas) {
406
406
if (ModelUtils .isMapSchema (schema ) && ModelUtils .getAdditionalProperties (schema ) != null ) {
407
407
Schema mapValueSchema = ModelUtils .getAdditionalProperties (schema );
408
408
mapValueSchema = ModelUtils .getReferencedSchema (openAPI , mapValueSchema );
409
- if (ModelUtils .isArraySchema (mapValueSchema ) || ModelUtils .isMapSchema (mapValueSchema )) {
409
+ if (ModelUtils .isArraySchema (mapValueSchema ) || ( ModelUtils .isMapSchema (mapValueSchema ) && ! ModelUtils . isModel ( mapValueSchema ) )) {
410
410
Schema innerSchema = generateNestedSchema (mapValueSchema , visitedSchemas );
411
411
schema .setAdditionalProperties (innerSchema );
412
412
413
413
}
414
414
} else if (ModelUtils .isArraySchema (schema ) && ModelUtils .getSchemaItems (schema ) != null ) {
415
415
Schema arrayItemSchema = ModelUtils .getSchemaItems (schema );
416
416
arrayItemSchema = ModelUtils .getReferencedSchema (openAPI , arrayItemSchema );
417
- if (ModelUtils .isMapSchema (arrayItemSchema ) || ModelUtils .isArraySchema (arrayItemSchema )) {
417
+ if (( ModelUtils .isMapSchema (arrayItemSchema ) && ! ModelUtils . isModel ( arrayItemSchema ) ) || ModelUtils .isArraySchema (arrayItemSchema )) {
418
418
Schema innerSchema = generateNestedSchema (arrayItemSchema , visitedSchemas );
419
419
schema .setItems (innerSchema );
420
420
}
@@ -427,7 +427,7 @@ private void processNestedSchemas(Schema schema, Set<Schema> visitedSchemas) {
427
427
Schema innerSchema = generateNestedSchema (oneOfSchema , visitedSchemas );
428
428
innerSchema .setTitle (oneOf .getTitle ());
429
429
newOneOfs .add (innerSchema );
430
- } else if (ModelUtils .isMapSchema (oneOfSchema )) {
430
+ } else if (ModelUtils .isMapSchema (oneOfSchema ) && ! ModelUtils . isModel ( oneOfSchema ) ) {
431
431
Schema innerSchema = generateNestedSchema (oneOfSchema , visitedSchemas );
432
432
innerSchema .setTitle (oneOf .getTitle ());
433
433
newOneOfs .add (innerSchema );
@@ -1061,4 +1061,38 @@ public GeneratorLanguage generatorLanguage() {
1061
1061
return GeneratorLanguage .PROTOBUF ;
1062
1062
}
1063
1063
1064
+
1065
+ /**
1066
+ * Handles additionalProperties defined in composed schemas (e.g., allOf) by injecting into the model's properties.
1067
+ * Example:
1068
+ * components:
1069
+ * schemas:
1070
+ * Dog:
1071
+ * allOf:
1072
+ * - $ref: '#/components/schemas/DogBase'
1073
+ * - type: object
1074
+ * additionalProperties:
1075
+ * title: pet
1076
+ * $ref: '#/components/schemas/Pet'
1077
+ * In this case, the second allOf that defines a map with string keys and Pet values will be part of model's property.
1078
+ */
1079
+ @ Override
1080
+ protected void addProperties (Map <String , Schema > properties , List <String > required , Schema schema , Set <Schema > visitedSchemas ){
1081
+ super .addProperties (properties , required , schema , visitedSchemas );
1082
+ if (schema .getAdditionalProperties () != null ) {
1083
+ String addtionalPropertiesName = "default_map" ;
1084
+ if (schema .getTitle () != null ) {
1085
+ addtionalPropertiesName = schema .getTitle ();
1086
+ } else {
1087
+ Schema additionalProperties = ModelUtils .getAdditionalProperties (schema );
1088
+ if (additionalProperties .getTitle () != null ) {
1089
+ addtionalPropertiesName = additionalProperties .getTitle ();
1090
+ } else if (additionalProperties .get$ref () != null ) {
1091
+ String ref = ModelUtils .getSimpleRef (additionalProperties .get$ref ());
1092
+ addtionalPropertiesName = toVarName (toModelName (ref ));
1093
+ }
1094
+ }
1095
+ properties .put (addtionalPropertiesName , schema );
1096
+ }
1097
+ }
1064
1098
}
0 commit comments