Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1085,13 +1085,13 @@ private String toExampleValueRecursive(String modelName, Schema schema, Object o
}
return fullPrefix + example + closeChars;
} else if (ModelUtils.isArraySchema(schema)) {
if (objExample instanceof Iterable) {
// If the example is already a list, return it directly instead of wrongly wrap it in another list
return fullPrefix + objExample.toString();
}
ArraySchema arrayschema = (ArraySchema) schema;
Schema itemSchema = arrayschema.getItems();
String itemModelName = getModelName(itemSchema);
if (objExample instanceof Iterable && itemModelName == null) {
// If the example is already a list, return it directly instead of wrongly wrap it in another list
return fullPrefix + objExample.toString() + closeChars;
}
seenSchemas.add(schema);
example = fullPrefix + "[" + "\n" + toExampleValueRecursive(itemModelName, itemSchema, objExample, indentationLevel + 1, "", exampleLine + 1, seenSchemas) + ",\n" + closingIndentation + "]" + closeChars;
return example;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@
import java.math.BigDecimal;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.openapitools.codegen.*;
import org.openapitools.codegen.languages.PythonClientCodegen;
Expand Down Expand Up @@ -290,8 +292,9 @@ public void complexMapPropertyTest() {
// should not start with 'null'. need help from the community to investigate further
@Test(description = "convert an array model")
public void arrayModelTest() {
final DefaultCodegen codegen = new PythonClientCodegen();
final PythonClientCodegen codegen = new PythonClientCodegen();
OpenAPI openAPI = TestUtils.createOpenAPI();

final Schema model = new ArraySchema()
.items(new Schema().$ref("#/components/schemas/Children"))
.description("an array model");
Expand All @@ -312,6 +315,12 @@ public void arrayModelTest() {
Assert.assertEquals(cm.parent, "list");
Assert.assertEquals(cm.imports.size(), 1);
Assert.assertEquals(Sets.intersection(cm.imports, Sets.newHashSet("Children")).size(), 1);

final Map<String, Integer> childExample = new HashMap<>();
childExample.put("number", 3);
final List<Map<String, Integer>> example = Arrays.asList(childExample);
String exampleValue = codegen.toExampleValue(model, example);
Assert.assertEquals("[Children(number=1,),]", exampleValue.replaceAll("\\s+",""));
}

// should not start with 'null'. need help from the community to investigate further
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,15 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/AnimalFarm'
examples:
simple-list:
summary: Simple list example
description: Should not get into code examples
value:
- className: foo
color: yellow
- className: bar
color: green
required: false
responses:
'200':
Expand Down