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.
This commit is contained in:
Thomas Hervé
2020-12-02 04:04:23 +01:00
committed by GitHub
parent 64ade2ce8f
commit 634c4c09e4
2 changed files with 5 additions and 2 deletions

View File

@@ -1072,7 +1072,10 @@ public class PythonClientCodegen extends PythonLegacyClientCodegen {
key = addPropsSchema.getEnum().get(0).toString(); key = addPropsSchema.getEnum().get(0).toString();
} }
addPropsExample = exampleFromStringOrArraySchema(addPropsSchema, addPropsExample, key); addPropsExample = exampleFromStringOrArraySchema(addPropsSchema, addPropsExample, key);
String addPropPrefix = ensureQuotes(key) + ": "; String addPropPrefix = key + "=";
if (modelName == null) {
addPropPrefix = ensureQuotes(key) + ": ";
}
String addPropsModelName = getModelName(addPropsSchema); String addPropsModelName = getModelName(addPropsSchema);
example = fullPrefix + "\n" + toExampleValueRecursive(addPropsModelName, addPropsSchema, addPropsExample, indentationLevel + 1, addPropPrefix, exampleLine + 1) + ",\n" + closingIndentation + closeChars; example = fullPrefix + "\n" + toExampleValueRecursive(addPropsModelName, addPropsSchema, addPropsExample, indentationLevel + 1, addPropPrefix, exampleLine + 1) + ",\n" + closingIndentation + closeChars;
} else { } else {

View File

@@ -51,7 +51,7 @@ with petstore_api.ApiClient() as api_client:
# Create an instance of the API class # Create an instance of the API class
api_instance = fake_api.FakeApi(api_client) api_instance = fake_api.FakeApi(api_client)
additional_properties_with_array_of_enums = AdditionalPropertiesWithArrayOfEnums( additional_properties_with_array_of_enums = AdditionalPropertiesWithArrayOfEnums(
"key": [ key=[
EnumClass("-efg"), EnumClass("-efg"),
], ],
) # AdditionalPropertiesWithArrayOfEnums | Input enum (optional) ) # AdditionalPropertiesWithArrayOfEnums | Input enum (optional)