Skip to content

Commit 634c4c0

Browse files
authored
Fix generation of map model examples (#8063)
When generation examples of objects with additional properties, we use the map syntax inside a model instantiation, which is incorrect. This fixes it by checking for model at the right place.
1 parent 64ade2c commit 634c4c0

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1072,7 +1072,10 @@ private String toExampleValueRecursive(String modelName, Schema schema, Object o
10721072
key = addPropsSchema.getEnum().get(0).toString();
10731073
}
10741074
addPropsExample = exampleFromStringOrArraySchema(addPropsSchema, addPropsExample, key);
1075-
String addPropPrefix = ensureQuotes(key) + ": ";
1075+
String addPropPrefix = key + "=";
1076+
if (modelName == null) {
1077+
addPropPrefix = ensureQuotes(key) + ": ";
1078+
}
10761079
String addPropsModelName = getModelName(addPropsSchema);
10771080
example = fullPrefix + "\n" + toExampleValueRecursive(addPropsModelName, addPropsSchema, addPropsExample, indentationLevel + 1, addPropPrefix, exampleLine + 1) + ",\n" + closingIndentation + closeChars;
10781081
} else {

samples/openapi3/client/petstore/python/docs/FakeApi.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ with petstore_api.ApiClient() as api_client:
5151
# Create an instance of the API class
5252
api_instance = fake_api.FakeApi(api_client)
5353
additional_properties_with_array_of_enums = AdditionalPropertiesWithArrayOfEnums(
54-
"key": [
54+
key=[
5555
EnumClass("-efg"),
5656
],
5757
) # AdditionalPropertiesWithArrayOfEnums | Input enum (optional)

0 commit comments

Comments
 (0)