diff --git a/src/main/java/io/github/swagger2markup/internal/adapter/PropertyAdapter.java b/src/main/java/io/github/swagger2markup/internal/adapter/PropertyAdapter.java index 4467f217..b81d675b 100644 --- a/src/main/java/io/github/swagger2markup/internal/adapter/PropertyAdapter.java +++ b/src/main/java/io/github/swagger2markup/internal/adapter/PropertyAdapter.java @@ -65,11 +65,32 @@ public final class PropertyAdapter { } else { if (logger.isDebugEnabled()) logger.debug("generateExample for ref not RefProperty"); } + case "array": + if (property instanceof ArrayProperty) { + return generateArrayExample((ArrayProperty) property, markupDocBuilder); + } default: return property.getType(); } } + /** + * Generate example for an ArrayProperty + * + * @param property ArrayProperty to generate example for + * @param markupDocBuilder MarkupDocBuilder containing all associated settings + * @return String example + */ + private static Object generateArrayExample(ArrayProperty property, MarkupDocBuilder markupDocBuilder) { + // TODO: Fix example generation for arrays. See Issue #180 + Property itemProperty = property.getItems(); + List exampleArray = new ArrayList<>(); + + exampleArray.add(generateExample(itemProperty, markupDocBuilder)); +// ExamplesUtil.generateExampleForRefModel(true, itemProperty.getName(), /* TODO */, /* TODO */, markupDocBuilder, /* TODO */); + return exampleArray; + } + /** * Convert a string {@code value} to specified {@code type}. * diff --git a/src/main/java/io/github/swagger2markup/internal/component/PathOperationComponent.java b/src/main/java/io/github/swagger2markup/internal/component/PathOperationComponent.java index f1e62a53..1d37354f 100644 --- a/src/main/java/io/github/swagger2markup/internal/component/PathOperationComponent.java +++ b/src/main/java/io/github/swagger2markup/internal/component/PathOperationComponent.java @@ -372,11 +372,13 @@ public class PathOperationComponent extends MarkupComponent> fieldsIterator = rootNode.fields(); + + if (!fieldsIterator.hasNext()) { // workaround for "array" example //TODO: print $ref'd examples correctly instead of just "array" - String example = stripExampleQuotes(Json.pretty(entry.getValue())); - example = Json.pretty(example); + String example = stripExampleQuotes(Json.pretty(rootNode)); +// example = Json.pretty(example); markupDocBuilder.listingBlock(example, "json"); } while (fieldsIterator.hasNext()) { diff --git a/src/main/java/io/github/swagger2markup/internal/utils/ExamplesUtil.java b/src/main/java/io/github/swagger2markup/internal/utils/ExamplesUtil.java index 8e995e63..5c3561b5 100644 --- a/src/main/java/io/github/swagger2markup/internal/utils/ExamplesUtil.java +++ b/src/main/java/io/github/swagger2markup/internal/utils/ExamplesUtil.java @@ -63,6 +63,9 @@ public class ExamplesUtil { String simpleRef = ((RefProperty) schema).getSimpleRef(); example = generateExampleForRefModel(generateMissingExamples, simpleRef, definitions, definitionDocumentResolver, markupDocBuilder, new HashMap<>()); } + if (example == null && schema instanceof ArrayProperty && generateMissingExamples) { + example = generateExampleForArrayProperty((ArrayProperty) schema, definitions, definitionDocumentResolver, markupDocBuilder, new HashMap<>()); + } if (example == null && generateMissingExamples) { example = PropertyAdapter.generateExample(schema, markupDocBuilder); } diff --git a/src/test/resources/expected/asciidoc/issue180/paths.adoc b/src/test/resources/expected/asciidoc/issue180/paths.adoc index 8aab48cb..0a9c8b81 100644 --- a/src/test/resources/expected/asciidoc/issue180/paths.adoc +++ b/src/test/resources/expected/asciidoc/issue180/paths.adoc @@ -41,7 +41,6 @@ Returns the navigation as a tree ===== Response 123 [source,json] ---- -{ [ { "id" : 0.0, "childs" : [ { @@ -49,7 +48,6 @@ Returns the navigation as a tree "childs" : [ "..." ] } ] } ] -} ----