diff --git a/src/main/java/io/github/robwin/swagger2markup/builder/document/PathsDocument.java b/src/main/java/io/github/robwin/swagger2markup/builder/document/PathsDocument.java index 82e3a152..78a05fe9 100644 --- a/src/main/java/io/github/robwin/swagger2markup/builder/document/PathsDocument.java +++ b/src/main/java/io/github/robwin/swagger2markup/builder/document/PathsDocument.java @@ -102,7 +102,7 @@ public class PathsDocument extends MarkupDocument { DEPRECATED_OPERATION = labels.getString("operation.deprecated"); UNKNOWN = labels.getString("unknown"); - if (config.isExamplesEnabled()) { + if (config.isGeneratedExamplesEnabled()) { if (logger.isDebugEnabled()) { logger.debug("Include examples is enabled."); } @@ -593,26 +593,19 @@ public class PathsDocument extends MarkupDocument { */ private void examplesSection(PathOperation operation, MarkupDocBuilder docBuilder) { - if (globalContext.config.isExamplesEnabled()) { - Optional> generatedRequestExampleMap; - Optional> generatedResponseExampleMap; + Map generatedRequestExampleMap = ExamplesUtil.generateRequestExampleMap(globalContext.config.isGeneratedExamplesEnabled(), operation, globalContext.swagger.getDefinitions(), markupDocBuilder); + Map generatedResponseExampleMap = ExamplesUtil.generateResponseExampleMap(globalContext.config.isGeneratedExamplesEnabled(), operation.getOperation(), globalContext.swagger.getDefinitions(), markupDocBuilder); - generatedRequestExampleMap = ExamplesUtil.generateRequestExampleMap(operation, globalContext.swagger.getDefinitions(), markupDocBuilder); - generatedResponseExampleMap = ExamplesUtil.generateResponseExampleMap(operation.getOperation(), globalContext.swagger.getDefinitions(), markupDocBuilder); - - exampleMap(generatedRequestExampleMap, EXAMPLE_REQUEST, REQUEST, docBuilder); - exampleMap(generatedResponseExampleMap, EXAMPLE_RESPONSE, RESPONSE, docBuilder); - } + exampleMap(generatedRequestExampleMap, EXAMPLE_REQUEST, REQUEST, docBuilder); + exampleMap(generatedResponseExampleMap, EXAMPLE_RESPONSE, RESPONSE, docBuilder); } - private void exampleMap(Optional> exampleMap, String operationSectionTitle, String sectionTile, MarkupDocBuilder docBuilder){ - if (exampleMap.isPresent()) { + private void exampleMap(Map exampleMap, String operationSectionTitle, String sectionTile, MarkupDocBuilder docBuilder) { + if (exampleMap.size() > 0) { addOperationSectionTitle(operationSectionTitle, docBuilder); - if (exampleMap.get().size() > 0) { - for (Map.Entry entry : exampleMap.get().entrySet()) { - docBuilder.sectionTitleLevel4(sectionTile + " " + entry.getKey() + " :"); - docBuilder.listing(Json.pretty(entry.getValue())); - } + for (Map.Entry entry : exampleMap.entrySet()) { + addOperationSectionTitle(sectionTile + " " + entry.getKey(), docBuilder); + docBuilder.listing(Json.pretty(entry.getValue())); } } } diff --git a/src/main/java/io/github/robwin/swagger2markup/config/Swagger2MarkupConfig.java b/src/main/java/io/github/robwin/swagger2markup/config/Swagger2MarkupConfig.java index 342347a0..36f15edf 100644 --- a/src/main/java/io/github/robwin/swagger2markup/config/Swagger2MarkupConfig.java +++ b/src/main/java/io/github/robwin/swagger2markup/config/Swagger2MarkupConfig.java @@ -41,7 +41,7 @@ public class Swagger2MarkupConfig { private static final Logger logger = LoggerFactory.getLogger(Swagger2MarkupConfig.class); private MarkupLanguage markupLanguage; - private boolean examplesEnabled; + private boolean generatedExamplesEnabled; private boolean schemasEnabled; private URI schemasUri; private boolean operationDescriptionsEnabled; @@ -142,8 +142,8 @@ public class Swagger2MarkupConfig { return markupLanguage; } - public boolean isExamplesEnabled() { - return examplesEnabled; + public boolean isGeneratedExamplesEnabled() { + return generatedExamplesEnabled; } public boolean isSchemasEnabled() { @@ -327,7 +327,7 @@ public class Swagger2MarkupConfig { safeProperties.putAll(properties); config.markupLanguage = MarkupLanguage.valueOf(safeProperties.getProperty(PROPERTIES_PREFIX + "markupLanguage")); - config.examplesEnabled = Boolean.valueOf(safeProperties.getProperty(PROPERTIES_PREFIX + "examplesEnabled")); + config.generatedExamplesEnabled = Boolean.valueOf(safeProperties.getProperty(PROPERTIES_PREFIX + "generatedExamplesEnabled")); config.schemasEnabled = Boolean.valueOf(safeProperties.getProperty(PROPERTIES_PREFIX + "schemasEnabled")); if (safeProperties.containsKey(PROPERTIES_PREFIX + "schemasUri")) config.schemasUri = URI.create(safeProperties.getProperty(PROPERTIES_PREFIX + "schemasUri")); @@ -408,12 +408,12 @@ public class Swagger2MarkupConfig { } /** - * Include examples into the Paths document + * Include generated examples into the Paths document * * @return this builder */ - public Builder withExamples() { - config.examplesEnabled = true; + public Builder withGeneratedExamples() { + config.generatedExamplesEnabled = true; return this; } diff --git a/src/main/java/io/github/robwin/swagger2markup/utils/ExamplesUtil.java b/src/main/java/io/github/robwin/swagger2markup/utils/ExamplesUtil.java index 4e2edf61..b05cf741 100644 --- a/src/main/java/io/github/robwin/swagger2markup/utils/ExamplesUtil.java +++ b/src/main/java/io/github/robwin/swagger2markup/utils/ExamplesUtil.java @@ -1,6 +1,5 @@ package io.github.robwin.swagger2markup.utils; -import com.google.common.base.Optional; import io.github.robwin.markup.builder.MarkupDocBuilder; import io.github.robwin.swagger2markup.PathOperation; import io.swagger.models.*; @@ -27,32 +26,33 @@ public class ExamplesUtil { * @param operation the Swagger Operation * @return map containing response examples. */ - public static Optional> generateResponseExampleMap(Operation operation, Map definitions, MarkupDocBuilder markupDocBuilder) { + public static Map generateResponseExampleMap(boolean generateMissingExamples, Operation operation, Map definitions, MarkupDocBuilder markupDocBuilder) { Map examples = new HashMap<>(); Map responses = operation.getResponses(); for (Map.Entry responseEntry : responses.entrySet()) { Response response = responseEntry.getValue(); Object example = response.getExamples(); - if (example != null) { - examples.put(responseEntry.getKey(), example); - } else { + if (example == null) { Property schema = response.getSchema(); - example = schema != null ? schema.getExample() : null; - if (example == null && schema instanceof RefProperty) { - String simpleRef = ((RefProperty) schema).getSimpleRef(); - example = generateExampleForRefModel(simpleRef, definitions, markupDocBuilder); - } - if (example == null && schema != null) { - examples.put(responseEntry.getKey(), PropertyUtils.exampleFromType(schema.getType(), schema, markupDocBuilder)); - } else if (example != null) { - examples.put(responseEntry.getKey(), example); + if (schema != null) { + example = schema.getExample(); + + if (example == null && schema instanceof RefProperty) { + String simpleRef = ((RefProperty) schema).getSimpleRef(); + example = generateExampleForRefModel(generateMissingExamples, simpleRef, definitions, markupDocBuilder); + } + if (example == null && generateMissingExamples) { + example = PropertyUtils.exampleFromType(schema.getType(), schema, markupDocBuilder); + } } } + + if (example != null) + examples.put(responseEntry.getKey(), example); + } - if (examples.size() == 0) { - return Optional.absent(); - } - return Optional.of(examples); + + return examples; } /** @@ -61,13 +61,14 @@ public class ExamplesUtil { * @param pathOperation the Swagger Operation * @return an Optional with the example content */ - public static Optional> generateRequestExampleMap(PathOperation pathOperation, Map definitions, MarkupDocBuilder markupDocBuilder) { + public static Map generateRequestExampleMap(boolean generateMissingExamples, PathOperation pathOperation, Map definitions, MarkupDocBuilder markupDocBuilder) { Operation operation = pathOperation.getOperation(); List parameters = operation.getParameters(); Map examples = new HashMap<>(); - //Path example should always be included: - examples.put("path", pathOperation.getPath()); + // Path example should always be included (if generateMissingExamples): + if (generateMissingExamples) + examples.put("path", pathOperation.getPath()); for (Parameter parameter : parameters) { Object example = null; if (parameter instanceof BodyParameter) { @@ -76,62 +77,64 @@ public class ExamplesUtil { Model schema = ((BodyParameter) parameter).getSchema(); if (schema instanceof RefModel) { String simpleRef = ((RefModel) schema).getSimpleRef(); - example = generateExampleForRefModel(simpleRef, definitions, markupDocBuilder); - } else if (schema instanceof ComposedModel) { - example = exampleMapForProperties(getPropertiesForComposedModel( - (ComposedModel) schema, definitions), definitions, markupDocBuilder); - } else if (schema instanceof ArrayModel) { - example = generateExampleForArrayModel((ArrayModel) schema, definitions, markupDocBuilder); - } else { - example = schema.getExample(); - if (example == null) { - example = exampleMapForProperties(schema.getProperties(), definitions, markupDocBuilder); + example = generateExampleForRefModel(generateMissingExamples, simpleRef, definitions, markupDocBuilder); + } else if (generateMissingExamples) { + if (schema instanceof ComposedModel) { + example = exampleMapForProperties(getPropertiesForComposedModel( + (ComposedModel) schema, definitions), definitions, markupDocBuilder); + } else if (schema instanceof ArrayModel) { + example = generateExampleForArrayModel((ArrayModel) schema, definitions, markupDocBuilder); + } else { + example = schema.getExample(); + if (example == null) { + example = exampleMapForProperties(schema.getProperties(), definitions, markupDocBuilder); + } } } } } else if (parameter instanceof AbstractSerializableParameter) { - Object abstractSerializableParameterExample; - abstractSerializableParameterExample = ((AbstractSerializableParameter) parameter).getExample(); - if (abstractSerializableParameterExample == null) { - Property item = ((AbstractSerializableParameter) parameter).getItems(); - if (item != null) { - abstractSerializableParameterExample = convertStringToType((String) item.getExample(), item.getType()); + if (generateMissingExamples) { + Object abstractSerializableParameterExample; + abstractSerializableParameterExample = ((AbstractSerializableParameter) parameter).getExample(); + if (abstractSerializableParameterExample == null) { + Property item = ((AbstractSerializableParameter) parameter).getItems(); + if (item != null) { + abstractSerializableParameterExample = convertStringToType(item.getExample(), item.getType()); + if (abstractSerializableParameterExample == null) { + abstractSerializableParameterExample = PropertyUtils.exampleFromType(item.getType(), item, markupDocBuilder); + } + } if (abstractSerializableParameterExample == null) { - abstractSerializableParameterExample = PropertyUtils.exampleFromType(item.getType(), item, markupDocBuilder); + abstractSerializableParameterExample = PropertyUtils.exampleFromType(((AbstractSerializableParameter) parameter).getType(), null, markupDocBuilder); } } - if (abstractSerializableParameterExample == null) { - abstractSerializableParameterExample = PropertyUtils.exampleFromType(((AbstractSerializableParameter) parameter).getType(), null, markupDocBuilder); + if (parameter instanceof PathParameter) { + String pathExample = (String) examples.get("path"); + pathExample = pathExample.replace('{' + parameter.getName() + '}', String.valueOf(abstractSerializableParameterExample)); + example = pathExample; + } else { + example = abstractSerializableParameterExample; } - } - if (parameter instanceof PathParameter) { - String pathExample = (String) examples.get("path"); - MarkupDocBuilder italicString = markupDocBuilder.copy().italicText(String.valueOf(abstractSerializableParameterExample)); - pathExample = pathExample.replace('{' + parameter.getName() + '}', '*' + italicString.toString() + "*"); - example = pathExample; - } else { - example = abstractSerializableParameterExample; - } - if (parameter instanceof QueryParameter) { - //noinspection unchecked - Map queryExampleMap = (Map) examples.get("query"); - if (queryExampleMap == null) { - queryExampleMap = new HashMap<>(); + if (parameter instanceof QueryParameter) { + //noinspection unchecked + Map queryExampleMap = (Map) examples.get("query"); + if (queryExampleMap == null) { + queryExampleMap = new HashMap<>(); + } + queryExampleMap.put(parameter.getName(), abstractSerializableParameterExample); + example = queryExampleMap; } - queryExampleMap.put(parameter.getName(), abstractSerializableParameterExample); - example = queryExampleMap; } } else if (parameter instanceof RefParameter) { String simpleRef = ((RefParameter) parameter).getSimpleRef(); - example = generateExampleForRefModel(simpleRef, definitions, markupDocBuilder); + example = generateExampleForRefModel(generateMissingExamples, simpleRef, definitions, markupDocBuilder); } - examples.put(parameter.getIn(), example); + + if (example != null) + examples.put(parameter.getIn(), example); } - if (examples.size() == 0) { - return Optional.absent(); - } - return Optional.of(examples); + return examples; } /** @@ -140,12 +143,12 @@ public class ExamplesUtil { * @param simpleRef the simple reference string * @return returns an Object or Map of examples */ - public static Object generateExampleForRefModel(String simpleRef, Map definitions, MarkupDocBuilder markupDocBuilder) { + public static Object generateExampleForRefModel(boolean generateMissingExamples, String simpleRef, Map definitions, MarkupDocBuilder markupDocBuilder) { Model model = definitions.get(simpleRef); Object example = null; if (model != null) { example = model.getExample(); - if (example == null) { + if (example == null && generateMissingExamples) { if (model instanceof ComposedModel) { example = exampleMapForProperties(getPropertiesForComposedModel((ComposedModel) model, definitions), definitions, markupDocBuilder); } else { @@ -190,11 +193,11 @@ public class ExamplesUtil { */ public static Map exampleMapForProperties(Map properties, Map definitions, MarkupDocBuilder markupDocBuilder) { Map exampleMap = new HashMap<>(); - for (Map.Entry property : properties.entrySet()) { + for (Map.Entry property : properties.entrySet()) { Object exampleObject = convertStringToType(property.getValue().getExample(), property.getValue().getType()); if (exampleObject == null) { if (property.getValue() instanceof RefProperty) { - exampleObject = generateExampleForRefModel(((RefProperty) property.getValue()).getSimpleRef(), definitions, markupDocBuilder); + exampleObject = generateExampleForRefModel(true, ((RefProperty) property.getValue()).getSimpleRef(), definitions, markupDocBuilder); } else if (property.getValue() instanceof ArrayProperty) { exampleObject = generateExampleForArrayProperty((ArrayProperty) property.getValue(), definitions, markupDocBuilder); } else if (property.getValue() instanceof MapProperty) { @@ -227,17 +230,17 @@ public class ExamplesUtil { if (model.getExample() != null) { return model.getExample(); } else if (model.getProperties() != null) { - return new Object[] {exampleMapForProperties(model.getProperties(), definitions, markupDocBuilder)}; + return new Object[]{exampleMapForProperties(model.getProperties(), definitions, markupDocBuilder)}; } else { Property itemProperty = model.getItems(); if (itemProperty.getExample() != null) { - return new Object[] { convertStringToType(itemProperty.getExample(), itemProperty.getType()) }; + return new Object[]{convertStringToType(itemProperty.getExample(), itemProperty.getType())}; } else if (itemProperty instanceof ArrayProperty) { - return new Object[] { generateExampleForArrayProperty((ArrayProperty) itemProperty, definitions, markupDocBuilder) }; + return new Object[]{generateExampleForArrayProperty((ArrayProperty) itemProperty, definitions, markupDocBuilder)}; } else if (itemProperty instanceof RefProperty) { - return new Object[] { generateExampleForRefModel(((RefProperty) itemProperty).getSimpleRef(), definitions, markupDocBuilder) }; + return new Object[]{generateExampleForRefModel(true, ((RefProperty) itemProperty).getSimpleRef(), definitions, markupDocBuilder)}; } else { - return new Object[] { PropertyUtils.exampleFromType(itemProperty.getType(), itemProperty, markupDocBuilder) }; + return new Object[]{PropertyUtils.exampleFromType(itemProperty.getType(), itemProperty, markupDocBuilder)}; } } } @@ -251,13 +254,13 @@ public class ExamplesUtil { public static Object[] generateExampleForArrayProperty(ArrayProperty value, Map definitions, MarkupDocBuilder markupDocBuilder) { Property property = value.getItems(); if (property.getExample() != null) { - return new Object[] {convertStringToType(property.getExample(), property.getType())}; + return new Object[]{convertStringToType(property.getExample(), property.getType())}; } else if (property instanceof ArrayProperty) { - return new Object[] {generateExampleForArrayProperty((ArrayProperty) property, definitions, markupDocBuilder)}; + return new Object[]{generateExampleForArrayProperty((ArrayProperty) property, definitions, markupDocBuilder)}; } else if (property instanceof RefProperty) { - return new Object[] {generateExampleForRefModel(((RefProperty) property).getSimpleRef(), definitions, markupDocBuilder)}; + return new Object[]{generateExampleForRefModel(true, ((RefProperty) property).getSimpleRef(), definitions, markupDocBuilder)}; } else { - return new Object[] {PropertyUtils.exampleFromType(property.getType(), property, markupDocBuilder)}; + return new Object[]{PropertyUtils.exampleFromType(property.getType(), property, markupDocBuilder)}; } } @@ -274,7 +277,7 @@ public class ExamplesUtil { case "boolean": return new Boolean(value); case "string": - return value; + return value; default: return value; } diff --git a/src/main/java/io/github/robwin/swagger2markup/utils/PropertyUtils.java b/src/main/java/io/github/robwin/swagger2markup/utils/PropertyUtils.java index 8025ecb2..bc1b4d6c 100644 --- a/src/main/java/io/github/robwin/swagger2markup/utils/PropertyUtils.java +++ b/src/main/java/io/github/robwin/swagger2markup/utils/PropertyUtils.java @@ -27,10 +27,7 @@ import io.swagger.util.Json; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.Validate; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; +import java.util.*; import static org.apache.commons.lang3.StringUtils.isNotBlank; @@ -43,7 +40,7 @@ public final class PropertyUtils { * @return the type of the property */ public static Type getType(Property property, Function definitionDocumentResolver) { - Validate.notNull(property, "property must not be null!"); + Validate.notNull(property, "property must not be null"); Type type; if (property instanceof RefProperty) { RefProperty refProperty = (RefProperty) property; @@ -82,7 +79,7 @@ public final class PropertyUtils { * @return the default value of the property, or otherwise an empty String */ public static String getDefaultValue(Property property) { - Validate.notNull(property, "property must not be null!"); + Validate.notNull(property, "property must not be null"); String defaultValue = ""; if (property instanceof BooleanProperty) { BooleanProperty booleanProperty = (BooleanProperty) property; @@ -109,8 +106,15 @@ public final class PropertyUtils { return defaultValue; } + /** + * Return example display string for the given {@code property}. + * + * @param property property + * @param markupDocBuilder doc builder + * @return property example display string + */ public static String getExample(Property property, MarkupDocBuilder markupDocBuilder) { - Validate.notNull(property, "parameter must not be null!"); + Validate.notNull(property, "property must not be null"); Object examplesValue; if (property.getExample() != null) { examplesValue = property.getExample(); @@ -124,10 +128,12 @@ public final class PropertyUtils { examplesValue = Json.pretty(exampleMap); } } else if (property instanceof ArrayProperty) { + List exampleArray = new ArrayList<>(); Property itemProperty = ((ArrayProperty) property).getItems(); - examplesValue = "[ " + exampleFromType(itemProperty.getType(), itemProperty, markupDocBuilder) + " ]"; + exampleArray.add(exampleFromType(itemProperty.getType(), itemProperty, markupDocBuilder)); + examplesValue = Json.pretty(exampleArray); } else { - examplesValue = exampleFromType(property.getType(), property, markupDocBuilder); + examplesValue = Json.pretty(exampleFromType(property.getType(), property, markupDocBuilder)); } return String.valueOf(examplesValue); } diff --git a/src/main/resources/io/github/robwin/swagger2markup/config/default.properties b/src/main/resources/io/github/robwin/swagger2markup/config/default.properties index 159d8b3e..cc0a9b16 100644 --- a/src/main/resources/io/github/robwin/swagger2markup/config/default.properties +++ b/src/main/resources/io/github/robwin/swagger2markup/config/default.properties @@ -1,5 +1,5 @@ swagger2markup.markupLanguage=ASCIIDOC -swagger2markup.examplesEnabled=false +swagger2markup.generatedExamplesEnabled=false swagger2markup.schemasEnabled=false swagger2markup.operationDescriptionsEnabled=false swagger2markup.definitionDescriptionsEnabled=false diff --git a/src/test/java/io/github/robwin/swagger2markup/Swagger2MarkupConverterTest.java b/src/test/java/io/github/robwin/swagger2markup/Swagger2MarkupConverterTest.java index 14755d88..7a989479 100644 --- a/src/test/java/io/github/robwin/swagger2markup/Swagger2MarkupConverterTest.java +++ b/src/test/java/io/github/robwin/swagger2markup/Swagger2MarkupConverterTest.java @@ -110,7 +110,6 @@ public class Swagger2MarkupConverterTest { //When Swagger2MarkupConfig config = Swagger2MarkupConfig.ofDefaults() - .withExamples() .build(); Swagger2MarkupConverter.from(swaggerJsonString) @@ -120,12 +119,142 @@ public class Swagger2MarkupConverterTest { //Then String[] directories = outputDirectory.toFile().list(); - assertThat(new String(Files.readAllBytes(outputDirectory.resolve("paths.adoc")))) - .contains("==== Example HTTP response"); - assertThat(new String(Files.readAllBytes(outputDirectory.resolve("definitions.adoc")))) - .contains("|name||true|string||doggie"); + String orderExample = "----\n" + + "{\n" + + " \"id\" : 99,\n" + + " \"petId\" : 122,\n" + + " \"quantity\" : 2,\n" + + " \"shipDate\" : \"2016-02-22T23:02:05Z\",\n" + + " \"status\" : \"PENDING\",\n" + + " \"complete\" : true\n" + + "}\n" + + "----\n"; + String petResponseExample = "----\n" + + "{\n" + + " \"application/json\" : {\n" + + " \"name\" : \"Puma\",\n" + + " \"type\" : 22,\n" + + " \"color\" : \"Black\",\n" + + " \"gender\" : \"Female\",\n" + + " \"breed\" : \"Mixed\"\n" + + " }\n" + + "}\n" + + "----\n"; + + String pathsDocument = new String(Files.readAllBytes(outputDirectory.resolve("paths.adoc"))); + assertThat(pathsDocument) + .contains("==== Response 405\n" + petResponseExample); + assertThat(pathsDocument) + .contains("==== Request body\n" + orderExample); + assertThat(pathsDocument) + .contains("==== Response 200\n" + orderExample); + + String definitionsDocument = new String(Files.readAllBytes(outputDirectory.resolve("definitions.adoc"))); + assertThat(definitionsDocument) + .contains("|id||false|integer(int64)||77"); + assertThat(definitionsDocument).contains("|pictures||false|string(byte) array||[ \"string\" ]"); + assertThat(definitionsDocument).contains("|shipDate||false|string(date-time)||\"string\""); + assertThat(definitionsDocument) + .doesNotContain("99"); } + @Test + public void testSwagger2AsciiDocConversionWithGeneratedExamples() throws IOException { + //Given + String swaggerJsonString = IOUtils.toString(getClass().getResourceAsStream("/json/swagger_examples.json")); + Path outputDirectory = Paths.get("build/docs/asciidoc/generated"); + FileUtils.deleteQuietly(outputDirectory.toFile()); + + //When + Swagger2MarkupConfig config = Swagger2MarkupConfig.ofDefaults() + .withGeneratedExamples() + .build(); + + Swagger2MarkupConverter.from(swaggerJsonString) + .withConfig(config) + .build() + .intoFolder(outputDirectory); + + //Then + String[] directories = outputDirectory.toFile().list(); + String petGeneratedExample = "----\n" + + "{\n" + + " \"tags\" : [ {\n" + + " \"id\" : 0,\n" + + " \"name\" : \"string\"\n" + + " } ],\n" + + " \"id\" : 0,\n" + + " \"nicknames\" : {\n" + + " \"string\" : \"string\"\n" + + " },\n" + + " \"category\" : {\n" + + " \"id\" : 123,\n" + + " \"name\" : \"Canines\"\n" + + " },\n" + + " \"weight\" : 0.0,\n" + + " \"status\" : \"string\",\n" + + " \"name\" : \"doggie\",\n" + + " \"photoUrls\" : [ \"string\" ]\n" + + "}\n" + + "----\n"; + String petResponseExample = "----\n" + + "{\n" + + " \"application/json\" : {\n" + + " \"name\" : \"Puma\",\n" + + " \"type\" : 22,\n" + + " \"color\" : \"Black\",\n" + + " \"gender\" : \"Female\",\n" + + " \"breed\" : \"Mixed\"\n" + + " }\n" + + "}\n" + + "----\n"; + String pathsDocument = new String(Files.readAllBytes(outputDirectory.resolve("paths.adoc"))); + assertThat(pathsDocument) + .contains("==== Request body\n" + petGeneratedExample); + assertThat(pathsDocument) + .contains("== Request path\n" + "----\n" + + "\"/pets\"\n" + + "----"); + assertThat(pathsDocument) + .contains("==== Request query\n" + + "----\n" + + "{\n" + + " \"status\" : \"string\"\n" + + "}\n" + + "----\n"); + assertThat(pathsDocument) + .contains("==== Response 405\n" + petResponseExample); + assertThat(pathsDocument) + .contains("==== Response 200\n" + + "----\n" + + "\"array\"\n" + + "----"); + assertThat(pathsDocument) + .contains("==== Request path\n" + + "----\n" + + "\"/pets/0\"\n" + + "----"); + + String definitionsDocument = new String(Files.readAllBytes(outputDirectory.resolve("definitions.adoc"))); + assertThat(definitionsDocument) + .contains("|id||false|integer(int64)||77"); + assertThat(definitionsDocument) + .contains("|name||true|string||doggie"); + assertThat(definitionsDocument) + .contains("|nicknames||false|object||{\n" + + " \"string\" : \"string\"\n" + + "}"); + assertThat(definitionsDocument) + .contains("[options=\"header\", cols=\".^1h,.^6,.^1,.^1,.^1,.^1\"]\n" + + "|===\n" + + "|Name|Description|Required|Schema|Default|Example\n" + + "|id||false|integer(int64)||0\n" + + "|===\n"); + + + } + + @Test public void testSwagger2AsciiDocConversionAsString() throws IOException, URISyntaxException { //Given diff --git a/src/test/java/io/github/robwin/swagger2markup/config/Swagger2MarkupConfigTest.java b/src/test/java/io/github/robwin/swagger2markup/config/Swagger2MarkupConfigTest.java index f3d63754..a65b4275 100644 --- a/src/test/java/io/github/robwin/swagger2markup/config/Swagger2MarkupConfigTest.java +++ b/src/test/java/io/github/robwin/swagger2markup/config/Swagger2MarkupConfigTest.java @@ -45,7 +45,7 @@ public class Swagger2MarkupConfigTest { assertThat(config.getOperationDescriptionsUri()).isNull(); assertThat(config.isDefinitionDescriptionsEnabled()).isFalse(); assertThat(config.getDefinitionDescriptionsUri()).isNull(); - assertThat(config.isExamplesEnabled()).isFalse(); + assertThat(config.isGeneratedExamplesEnabled()).isFalse(); assertThat(config.getInlineSchemaDepthLevel()).isEqualTo(0); assertThat(config.getInterDocumentCrossReferencesPrefix()).isNull(); assertThat(config.getMarkupLanguage()).isEqualTo(MarkupLanguage.ASCIIDOC); @@ -91,7 +91,7 @@ public class Swagger2MarkupConfigTest { assertThat(config.getOperationDescriptionsUri()).isEqualTo(URI.create("operationDescriptions")); assertThat(config.isDefinitionDescriptionsEnabled()).isTrue(); assertThat(config.getDefinitionDescriptionsUri()).isEqualTo(URI.create("definitionDescriptions")); - assertThat(config.isExamplesEnabled()).isTrue(); + assertThat(config.isGeneratedExamplesEnabled()).isTrue(); assertThat(config.getInlineSchemaDepthLevel()).isEqualTo(2); assertThat(config.getInterDocumentCrossReferencesPrefix()).isEqualTo("xrefPrefix"); assertThat(config.getMarkupLanguage()).isEqualTo(MarkupLanguage.MARKDOWN); diff --git a/src/test/resources/config/config.properties b/src/test/resources/config/config.properties index 6270ec37..ddf1a86e 100644 --- a/src/test/resources/config/config.properties +++ b/src/test/resources/config/config.properties @@ -1,5 +1,5 @@ swagger2markup.markupLanguage=MARKDOWN -swagger2markup.examplesEnabled=true +swagger2markup.generatedExamplesEnabled=true swagger2markup.schemasUri=schemas swagger2markup.schemasEnabled=true swagger2markup.operationDescriptionsEnabled=true diff --git a/src/test/resources/json/swagger_examples.json b/src/test/resources/json/swagger_examples.json index 8f19b9f9..1bb99da5 100644 --- a/src/test/resources/json/swagger_examples.json +++ b/src/test/resources/json/swagger_examples.json @@ -1,907 +1,918 @@ { - "swagger": "2.0", - "info": { - "description": "This is a sample server Petstore server.\n\n[Learn about Swagger](http://swagger.wordnik.com) or join the IRC channel `#swagger` on irc.freenode.net.\n\nFor this sample, you can use the api key `special-key` to test the authorization filters\n", - "version": "1.0.0", - "title": "Swagger Petstore API", - "termsOfService": "http://helloreverb.com/terms/", - "contact": { - "name": "apiteam@wordnik.com" - }, - "license": { - "name": "Apache 2.0", - "url": "http://www.apache.org/licenses/LICENSE-2.0.html" - } + "swagger": "2.0", + "info": { + "description": "This is a sample server Petstore server.\n\n[Learn about Swagger](http://swagger.wordnik.com) or join the IRC channel `#swagger` on irc.freenode.net.\n\nFor this sample, you can use the api key `special-key` to test the authorization filters\n", + "version": "1.0.0", + "title": "Swagger Petstore API", + "termsOfService": "http://helloreverb.com/terms/", + "contact": { + "name": "apiteam@wordnik.com" }, - "host": "petstore.swagger.wordnik.com", - "basePath": "/v2", - "schemes": [ - "http" - ], - "tags": [ - { - "name": "pet", - "description": "Pet resource" - }, - { - "name": "store", - "description": "Store resource" - }, - { - "name": "user", - "description": "User resource" - } - ], - "paths": { - "/pets": { - "post": { - "tags": [ - "pet" - ], - "summary": "Add a new pet to the store", - "description": "", - "operationId": "addPet", - "consumes": [ - "application/json", - "application/xml" - ], - "produces": [ - "application/json", - "application/xml" - ], - "parameters": [ - { - "in": "body", - "name": "body", - "description": "Pet object that needs to be added to the store", - "required": false, - "schema": { - "$ref": "#/definitions/Pet" - } - } - ], - "responses": { - "405": { - "description": "Invalid input", - "examples": { - "application/json": { - "name": "Puma", - "type": 22, - "color": "Black", - "gender": "Female", - "breed": "Mixed" - } - } - } - }, - "security": [ - { - "petstore_auth": [ - "write_pets", - "read_pets" - ] - } - ] - }, - "put": { - "tags": [ - "pet" - ], - "summary": "Update an existing pet", - "description": "", - "operationId": "updatePet", - "consumes": [ - "application/json", - "application/xml" - ], - "produces": [ - "application/json", - "application/xml" - ], - "parameters": [ - { - "in": "body", - "name": "body", - "description": "Pet object that needs to be added to the store", - "required": false, - "schema": { - "$ref": "#/definitions/Pet" - } - } - ], - "responses": { - "400": { - "description": "Invalid ID supplied" - }, - "404": { - "description": "Pet not found" - }, - "405": { - "description": "Validation exception" - } - }, - "security": [ - { - "petstore_auth": [ - "write_pets", - "read_pets" - ] - } - ] - } - }, - "/pets/findByStatus": { - "get": { - "tags": [ - "pet" - ], - "summary": "Finds Pets by status", - "description": "Multiple status values can be provided with comma seperated strings", - "operationId": "findPetsByStatus", - "produces": [ - "application/json", - "application/xml" - ], - "parameters": [ - { - "in": "query", - "name": "status", - "description": "Status values that need to be considered for filter", - "required": false, - "type": "array", - "items": { - "type": "string" - }, - "collectionFormat": "multi" - } - ], - "responses": { - "200": { - "$ref": "#/responses/FoundPets" - }, - "400": { - "description": "Invalid status value" - } - }, - "security": [ - { - "petstore_auth": [ - "write_pets", - "read_pets" - ] - } - ] - } - }, - "/pets/findByTags": { - "get": { - "tags": [ - "pet" - ], - "summary": "Finds Pets by tags", - "description": "Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.", - "operationId": "findPetsByTags", - "produces": [ - "application/json", - "application/xml" - ], - "parameters": [ - { - "in": "query", - "name": "tags", - "description": "Tags to filter by", - "required": false, - "type": "array", - "items": { - "type": "string" - }, - "collectionFormat": "multi" - } - ], - "responses": { - "200": { - "$ref": "#/responses/FoundPets" - }, - "400": { - "description": "Invalid tag value" - } - }, - "security": [ - { - "petstore_auth": [ - "write_pets", - "read_pets" - ] - } - ] - } - }, - "/pets/{petId}": { - "get": { - "tags": [ - "pet" - ], - "summary": "Find pet by ID", - "description": "Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions", - "operationId": "getPetById", - "produces": [ - "application/json", - "application/xml" - ], - "parameters": [ - { - "$ref": "#/parameters/petId" - } - ], - "responses": { - "200": { - "description": "successful operation", - "schema": { - "$ref": "#/definitions/Pet" - } - }, - "400": { - "description": "Invalid ID supplied" - }, - "404": { - "description": "Pet not found" - } - }, - "security": [ - { - "api_key": [] - }, - { - "petstore_auth": [ - "write_pets", - "read_pets" - ] - } - ] - }, - "post": { - "tags": [ - "pet" - ], - "summary": "Updates a pet in the store with form data", - "description": "", - "operationId": "updatePetWithForm", - "consumes": [ - "application/x-www-form-urlencoded" - ], - "produces": [ - "application/json", - "application/xml" - ], - "parameters": [ - { - "in": "path", - "name": "petId", - "description": "ID of pet that needs to be updated", - "required": true, - "type": "string" - }, - { - "in": "formData", - "name": "name", - "description": "Updated name of the pet", - "required": true, - "type": "string" - }, - { - "in": "formData", - "name": "status", - "description": "Updated status of the pet", - "required": true, - "type": "string" - } - ], - "responses": { - "405": { - "description": "Invalid input" - } - }, - "security": [ - { - "petstore_auth": [ - "write_pets", - "read_pets" - ] - } - ] - }, - "delete": { - "tags": [ - "pet" - ], - "summary": "Deletes a pet", - "description": "", - "operationId": "deletePet", - "produces": [ - "application/json", - "application/xml" - ], - "parameters": [ - { - "in": "header", - "name": "api_key", - "description": "", - "required": true, - "type": "string" - }, - { - "in": "path", - "name": "petId", - "description": "Pet id to delete", - "required": true, - "type": "integer", - "format": "int64" - } - ], - "responses": { - "400": { - "description": "Invalid pet value" - } - }, - "security": [ - { - "petstore_auth": [ - "write_pets", - "read_pets" - ] - } - ] - } - }, - "/stores/order": { - "post": { - "tags": [ - "store" - ], - "summary": "Place an order for a pet", - "description": "", - "operationId": "placeOrder", - "produces": [ - "application/json", - "application/xml" - ], - "parameters": [ - { - "in": "body", - "name": "body", - "description": "order placed for purchasing the pet", - "required": false, - "schema": { - "$ref": "#/definitions/Order" - } - } - ], - "responses": { - "200": { - "description": "successful operation", - "schema": { - "$ref": "#/definitions/Order" - } - }, - "400": { - "description": "Invalid Order" - } - } - } - }, - "/stores/order/{orderId}": { - "get": { - "tags": [ - "store" - ], - "summary": "Find purchase order by ID", - "description": "For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions", - "operationId": "getOrderById", - "produces": [ - "application/json", - "application/xml" - ], - "parameters": [ - { - "in": "path", - "name": "orderId", - "description": "ID of pet that needs to be fetched", - "required": true, - "type": "string" - } - ], - "responses": { - "200": { - "description": "successful operation", - "schema": { - "$ref": "#/definitions/Order" - } - }, - "400": { - "description": "Invalid ID supplied" - }, - "404": { - "description": "Order not found" - } - } - }, - "delete": { - "tags": [ - "store" - ], - "summary": "Delete purchase order by ID", - "description": "For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors", - "operationId": "deleteOrder", - "produces": [ - "application/json", - "application/xml" - ], - "parameters": [ - { - "in": "path", - "name": "orderId", - "description": "ID of the order that needs to be deleted", - "required": true, - "type": "string" - } - ], - "responses": { - "400": { - "description": "Invalid ID supplied" - }, - "404": { - "description": "Order not found" - } - } - } - }, - "/users": { - "post": { - "tags": [ - "user" - ], - "summary": "Create user", - "description": "This can only be done by the logged in user.", - "operationId": "createUser", - "produces": [ - "application/json", - "application/xml" - ], - "parameters": [ - { - "in": "body", - "name": "body", - "description": "Created user object", - "required": false, - "schema": { - "$ref": "#/definitions/User" - } - } - ], - "responses": { - "default": { - "description": "successful operation" - } - } - } - }, - "/users/createWithArray": { - "post": { - "tags": [ - "user" - ], - "summary": "Creates list of users with given input array", - "description": "", - "operationId": "createUsersWithArrayInput", - "produces": [ - "application/json", - "application/xml" - ], - "parameters": [ - { - "in": "body", - "name": "body", - "description": "List of user object", - "required": false, - "schema": { - "type": "array", - "items": { - "$ref": "#/definitions/User" - } - } - } - ], - "responses": { - "default": { - "description": "successful operation" - } - } - } - }, - "/users/createWithList": { - "post": { - "tags": [ - "user" - ], - "summary": "Creates list of users with given input array", - "description": "", - "operationId": "createUsersWithListInput", - "produces": [ - "application/json", - "application/xml" - ], - "parameters": [ - { - "in": "body", - "name": "body", - "description": "List of user object", - "required": false, - "schema": { - "type": "array", - "items": { - "$ref": "#/definitions/User" - } - } - } - ], - "responses": { - "default": { - "description": "successful operation" - } - } - } - }, - "/users/login": { - "get": { - "tags": [ - "user" - ], - "summary": "Logs user into the system", - "description": "", - "operationId": "loginUser", - "produces": [ - "application/json", - "application/xml" - ], - "parameters": [ - { - "in": "query", - "name": "username", - "description": "The user name for login", - "required": false, - "type": "string", - "default": "testUser" - }, - { - "in": "query", - "name": "password", - "description": "The password for login in clear text", - "required": false, - "type": "string", - "default": "testPassword" - } - ], - "responses": { - "200": { - "description": "successful operation", - "schema": { - "type": "string" - } - }, - "400": { - "description": "Invalid username/password supplied" - } - } - } - }, - "/users/logout": { - "get": { - "tags": [ - "user" - ], - "summary": "Logs out current logged in user session", - "description": "", - "operationId": "logoutUser", - "produces": [ - "application/json", - "application/xml" - ], - "responses": { - "default": { - "description": "successful operation" - } - } - } - }, - "/users/{username}": { - "get": { - "tags": [ - "user" - ], - "summary": "Get user by user name", - "description": "", - "operationId": "getUserByName", - "produces": [ - "application/json", - "application/xml" - ], - "parameters": [ - { - "in": "path", - "name": "username", - "description": "The name that needs to be fetched. Use user1 for testing.", - "required": true, - "type": "string", - "default": "testUser" - } - ], - "responses": { - "200": { - "description": "successful operation", - "schema": { - "$ref": "#/definitions/User" - } - }, - "400": { - "description": "Invalid username supplied" - }, - "404": { - "description": "User not found" - } - } - }, - "put": { - "tags": [ - "user" - ], - "summary": "Updated user", - "description": "This can only be done by the logged in user.", - "operationId": "updateUser", - "produces": [ - "application/json", - "application/xml" - ], - "parameters": [ - { - "in": "path", - "name": "username", - "description": "name that need to be deleted", - "required": true, - "type": "string" - }, - { - "in": "body", - "name": "body", - "description": "Updated user object", - "required": false, - "schema": { - "$ref": "#/definitions/User" - } - } - ], - "responses": { - "400": { - "description": "Invalid user supplied" - }, - "404": { - "description": "User not found" - } - } - }, - "delete": { - "tags": [ - "user" - ], - "summary": "Delete user", - "description": "This can only be done by the logged in user.", - "operationId": "deleteUser", - "produces": [ - "application/json", - "application/xml" - ], - "parameters": [ - { - "in": "path", - "name": "username", - "description": "The name that needs to be deleted", - "required": true, - "type": "string" - } - ], - "responses": { - "400": { - "description": "Invalid username supplied" - }, - "404": { - "description": "User not found" - } - } - } - } + "license": { + "name": "Apache 2.0", + "url": "http://www.apache.org/licenses/LICENSE-2.0.html" + } + }, + "host": "petstore.swagger.wordnik.com", + "basePath": "/v2", + "schemes": [ + "http" + ], + "tags": [ + { + "name": "pet", + "description": "Pet resource" }, - "securityDefinitions": { - "api_key": { - "type": "apiKey", - "name": "api_key", - "in": "header" - }, - "petstore_auth": { - "type": "oauth2", - "authorizationUrl": "http://petstore.swagger.wordnik.com/api/oauth/dialog", - "flow": "implicit", - "scopes": { - "write_pets": "modify pets in your account", - "read_pets": "read your pets" - } - } + { + "name": "store", + "description": "Store resource" }, - "responses":{ - "FoundPets": { + { + "name": "user", + "description": "User resource" + } + ], + "paths": { + "/pets": { + "post": { + "tags": [ + "pet" + ], + "summary": "Add a new pet to the store", + "description": "", + "operationId": "addPet", + "consumes": [ + "application/json", + "application/xml" + ], + "produces": [ + "application/json", + "application/xml" + ], + "parameters": [ + { + "in": "body", + "name": "body", + "description": "Pet object that needs to be added to the store", + "required": false, + "schema": { + "$ref": "#/definitions/Pet" + } + } + ], + "responses": { + "405": { + "description": "Invalid input", + "examples": { + "application/json": { + "name": "Puma", + "type": 22, + "color": "Black", + "gender": "Female", + "breed": "Mixed" + } + } + } + }, + "security": [ + { + "petstore_auth": [ + "write_pets", + "read_pets" + ] + } + ] + }, + "put": { + "tags": [ + "pet" + ], + "summary": "Update an existing pet", + "description": "", + "operationId": "updatePet", + "consumes": [ + "application/json", + "application/xml" + ], + "produces": [ + "application/json", + "application/xml" + ], + "parameters": [ + { + "in": "body", + "name": "body", + "description": "Pet object that needs to be added to the store", + "required": false, + "schema": { + "$ref": "#/definitions/Pet" + } + } + ], + "responses": { + "400": { + "description": "Invalid ID supplied" + }, + "404": { + "description": "Pet not found" + }, + "405": { + "description": "Validation exception" + } + }, + "security": [ + { + "petstore_auth": [ + "write_pets", + "read_pets" + ] + } + ] + } + }, + "/pets/findByStatus": { + "get": { + "tags": [ + "pet" + ], + "summary": "Finds Pets by status", + "description": "Multiple status values can be provided with comma seperated strings", + "operationId": "findPetsByStatus", + "produces": [ + "application/json", + "application/xml" + ], + "parameters": [ + { + "in": "query", + "name": "status", + "description": "Status values that need to be considered for filter", + "required": false, + "type": "array", + "items": { + "type": "string" + }, + "collectionFormat": "multi" + } + ], + "responses": { + "200": { + "$ref": "#/responses/FoundPets" + }, + "400": { + "description": "Invalid status value" + } + }, + "security": [ + { + "petstore_auth": [ + "write_pets", + "read_pets" + ] + } + ] + } + }, + "/pets/findByTags": { + "get": { + "tags": [ + "pet" + ], + "summary": "Finds Pets by tags", + "description": "Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.", + "operationId": "findPetsByTags", + "produces": [ + "application/json", + "application/xml" + ], + "parameters": [ + { + "in": "query", + "name": "tags", + "description": "Tags to filter by", + "required": false, + "type": "array", + "items": { + "type": "string" + }, + "collectionFormat": "multi" + } + ], + "responses": { + "200": { + "$ref": "#/responses/FoundPets" + }, + "400": { + "description": "Invalid tag value" + } + }, + "security": [ + { + "petstore_auth": [ + "write_pets", + "read_pets" + ] + } + ] + } + }, + "/pets/{petId}": { + "get": { + "tags": [ + "pet" + ], + "summary": "Find pet by ID", + "description": "Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions", + "operationId": "getPetById", + "produces": [ + "application/json", + "application/xml" + ], + "parameters": [ + { + "$ref": "#/parameters/petId" + } + ], + "responses": { + "200": { "description": "successful operation", "schema": { - "type": "array", - "items": { - "$ref": "#/definitions/Pet" - } + "$ref": "#/definitions/Pet" } - } - }, - "parameters":{ - "petId": { + }, + "400": { + "description": "Invalid ID supplied" + }, + "404": { + "description": "Pet not found" + } + }, + "security": [ + { + "api_key": [] + }, + { + "petstore_auth": [ + "write_pets", + "read_pets" + ] + } + ] + }, + "post": { + "tags": [ + "pet" + ], + "summary": "Updates a pet in the store with form data", + "description": "", + "operationId": "updatePetWithForm", + "consumes": [ + "application/x-www-form-urlencoded" + ], + "produces": [ + "application/json", + "application/xml" + ], + "parameters": [ + { "in": "path", "name": "petId", - "description": "ID of the pet", + "description": "ID of pet that needs to be updated", + "required": true, + "type": "string" + }, + { + "in": "formData", + "name": "name", + "description": "Updated name of the pet", + "required": true, + "type": "string" + }, + { + "in": "formData", + "name": "status", + "description": "Updated status of the pet", + "required": true, + "type": "string" + } + ], + "responses": { + "405": { + "description": "Invalid input" + } + }, + "security": [ + { + "petstore_auth": [ + "write_pets", + "read_pets" + ] + } + ] + }, + "delete": { + "tags": [ + "pet" + ], + "summary": "Deletes a pet", + "description": "", + "operationId": "deletePet", + "produces": [ + "application/json", + "application/xml" + ], + "parameters": [ + { + "in": "header", + "name": "api_key", + "description": "", + "required": true, + "type": "string" + }, + { + "in": "path", + "name": "petId", + "description": "Pet id to delete", "required": true, "type": "integer", "format": "int64" - } - }, - "definitions": { - "Identified": { - "properties": { - "id": { - "type": "integer", - "format": "int64" - } - } + } + ], + "responses": { + "400": { + "description": "Invalid pet value" + } }, - "User": { - "allOf": [ - { - "$ref": "#/definitions/Identified" - }, - { - "properties": { - "username": { - "type": "string" - }, - "firstName": { - "type": "string" - }, - "lastName": { - "type": "string" - }, - "email": { - "type": "string" - }, - "password": { - "type": "string" - }, - "phone": { - "type": "string" - }, - "userStatus": { - "type": "integer", - "format": "int32", - "description": "User Status" - }, - "pictures": { - "type": "array", - "items": { - "type": "string", - "format": "byte" - } - } - } - } + "security": [ + { + "petstore_auth": [ + "write_pets", + "read_pets" ] - }, - "Category": { - "properties": { - "id": { - "type": "integer", - "format": "int64", - "example": "123" - }, - "name": { - "type": "string", - "example": "Canines" - } + } + ] + } + }, + "/stores/order": { + "post": { + "tags": [ + "store" + ], + "summary": "Place an order for a pet", + "description": "", + "operationId": "placeOrder", + "produces": [ + "application/json", + "application/xml" + ], + "parameters": [ + { + "in": "body", + "name": "body", + "description": "order placed for purchasing the pet", + "required": false, + "schema": { + "$ref": "#/definitions/Order" } - }, - "Pet": { - "description" : "Test description", - "required": [ - "name", - "photoUrls" - ], - "properties": { - "id": { - "type": "integer", - "format": "int64" - }, - "category": { - "$ref": "#/definitions/Category" - }, - "name": { - "type": "string", - "example": "doggie" - }, - "nicknames": { - "type": "object", - "additionalProperties": { - "type": "string" - } - }, - "photoUrls": { - "type": "array", - "items": { - "type": "string" - } - }, - "tags": { - "type": "array", - "items": { - "$ref": "#/definitions/Tag" - } - }, - "status": { - "type": "string", - "description": "pet status in the store" - }, - "weight": { - "type": "number", - "description": "the weight of the pet" - } - } - }, - "Tag": { - "properties": { - "id": { - "type": "integer", - "format": "int64" - }, - "name": { - "type": "string" - } - } - }, - "Order": { - "properties": { - "id": { - "type": "integer", - "format": "int64" - }, - "petId": { - "type": "integer", - "format": "int64" - }, - "quantity": { - "type": "integer", - "format": "int32" - }, - "shipDate": { - "type": "string", - "format": "date-time" - }, - "status": { - "type": "string", - "description": "Order Status" - }, - "complete": { - "type": "boolean" - } + } + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "$ref": "#/definitions/Order" } + }, + "400": { + "description": "Invalid Order" + } } + } + }, + "/stores/order/{orderId}": { + "get": { + "tags": [ + "store" + ], + "summary": "Find purchase order by ID", + "description": "For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions", + "operationId": "getOrderById", + "produces": [ + "application/json", + "application/xml" + ], + "parameters": [ + { + "in": "path", + "name": "orderId", + "description": "ID of pet that needs to be fetched", + "required": true, + "type": "string" + } + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "$ref": "#/definitions/Order" + } + }, + "400": { + "description": "Invalid ID supplied" + }, + "404": { + "description": "Order not found" + } + } + }, + "delete": { + "tags": [ + "store" + ], + "summary": "Delete purchase order by ID", + "description": "For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors", + "operationId": "deleteOrder", + "produces": [ + "application/json", + "application/xml" + ], + "parameters": [ + { + "in": "path", + "name": "orderId", + "description": "ID of the order that needs to be deleted", + "required": true, + "type": "string" + } + ], + "responses": { + "400": { + "description": "Invalid ID supplied" + }, + "404": { + "description": "Order not found" + } + } + } + }, + "/users": { + "post": { + "tags": [ + "user" + ], + "summary": "Create user", + "description": "This can only be done by the logged in user.", + "operationId": "createUser", + "produces": [ + "application/json", + "application/xml" + ], + "parameters": [ + { + "in": "body", + "name": "body", + "description": "Created user object", + "required": false, + "schema": { + "$ref": "#/definitions/User" + } + } + ], + "responses": { + "default": { + "description": "successful operation" + } + } + } + }, + "/users/createWithArray": { + "post": { + "tags": [ + "user" + ], + "summary": "Creates list of users with given input array", + "description": "", + "operationId": "createUsersWithArrayInput", + "produces": [ + "application/json", + "application/xml" + ], + "parameters": [ + { + "in": "body", + "name": "body", + "description": "List of user object", + "required": false, + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/User" + } + } + } + ], + "responses": { + "default": { + "description": "successful operation" + } + } + } + }, + "/users/createWithList": { + "post": { + "tags": [ + "user" + ], + "summary": "Creates list of users with given input array", + "description": "", + "operationId": "createUsersWithListInput", + "produces": [ + "application/json", + "application/xml" + ], + "parameters": [ + { + "in": "body", + "name": "body", + "description": "List of user object", + "required": false, + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/User" + } + } + } + ], + "responses": { + "default": { + "description": "successful operation" + } + } + } + }, + "/users/login": { + "get": { + "tags": [ + "user" + ], + "summary": "Logs user into the system", + "description": "", + "operationId": "loginUser", + "produces": [ + "application/json", + "application/xml" + ], + "parameters": [ + { + "in": "query", + "name": "username", + "description": "The user name for login", + "required": false, + "type": "string", + "default": "testUser" + }, + { + "in": "query", + "name": "password", + "description": "The password for login in clear text", + "required": false, + "type": "string", + "default": "testPassword" + } + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "type": "string" + } + }, + "400": { + "description": "Invalid username/password supplied" + } + } + } + }, + "/users/logout": { + "get": { + "tags": [ + "user" + ], + "summary": "Logs out current logged in user session", + "description": "", + "operationId": "logoutUser", + "produces": [ + "application/json", + "application/xml" + ], + "responses": { + "default": { + "description": "successful operation" + } + } + } + }, + "/users/{username}": { + "get": { + "tags": [ + "user" + ], + "summary": "Get user by user name", + "description": "", + "operationId": "getUserByName", + "produces": [ + "application/json", + "application/xml" + ], + "parameters": [ + { + "in": "path", + "name": "username", + "description": "The name that needs to be fetched. Use user1 for testing.", + "required": true, + "type": "string", + "default": "testUser" + } + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "$ref": "#/definitions/User" + } + }, + "400": { + "description": "Invalid username supplied" + }, + "404": { + "description": "User not found" + } + } + }, + "put": { + "tags": [ + "user" + ], + "summary": "Updated user", + "description": "This can only be done by the logged in user.", + "operationId": "updateUser", + "produces": [ + "application/json", + "application/xml" + ], + "parameters": [ + { + "in": "path", + "name": "username", + "description": "name that need to be deleted", + "required": true, + "type": "string" + }, + { + "in": "body", + "name": "body", + "description": "Updated user object", + "required": false, + "schema": { + "$ref": "#/definitions/User" + } + } + ], + "responses": { + "400": { + "description": "Invalid user supplied" + }, + "404": { + "description": "User not found" + } + } + }, + "delete": { + "tags": [ + "user" + ], + "summary": "Delete user", + "description": "This can only be done by the logged in user.", + "operationId": "deleteUser", + "produces": [ + "application/json", + "application/xml" + ], + "parameters": [ + { + "in": "path", + "name": "username", + "description": "The name that needs to be deleted", + "required": true, + "type": "string" + } + ], + "responses": { + "400": { + "description": "Invalid username supplied" + }, + "404": { + "description": "User not found" + } + } + } } + }, + "securityDefinitions": { + "api_key": { + "type": "apiKey", + "name": "api_key", + "in": "header" + }, + "petstore_auth": { + "type": "oauth2", + "authorizationUrl": "http://petstore.swagger.wordnik.com/api/oauth/dialog", + "flow": "implicit", + "scopes": { + "write_pets": "modify pets in your account", + "read_pets": "read your pets" + } + } + }, + "responses": { + "FoundPets": { + "description": "successful operation", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/Pet" + } + } + } + }, + "parameters": { + "petId": { + "in": "path", + "name": "petId", + "description": "ID of the pet", + "required": true, + "type": "integer", + "format": "int64" + } + }, + "definitions": { + "Identified": { + "properties": { + "id": { + "type": "integer", + "format": "int64" + } + } + }, + "User": { + "allOf": [ + { + "$ref": "#/definitions/Identified" + }, + { + "properties": { + "username": { + "type": "string" + }, + "firstName": { + "type": "string" + }, + "lastName": { + "type": "string" + }, + "email": { + "type": "string" + }, + "password": { + "type": "string" + }, + "phone": { + "type": "string" + }, + "userStatus": { + "type": "integer", + "format": "int32", + "description": "User Status" + }, + "pictures": { + "type": "array", + "items": { + "type": "string", + "format": "byte" + } + } + } + } + ] + }, + "Category": { + "properties": { + "id": { + "type": "integer", + "format": "int64", + "example": "123" + }, + "name": { + "type": "string", + "example": "Canines" + } + } + }, + "Pet": { + "description": "Test description", + "required": [ + "name", + "photoUrls" + ], + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "category": { + "$ref": "#/definitions/Category" + }, + "name": { + "type": "string", + "example": "doggie" + }, + "nicknames": { + "type": "object", + "additionalProperties": { + "type": "string" + } + }, + "photoUrls": { + "type": "array", + "items": { + "type": "string" + } + }, + "tags": { + "type": "array", + "items": { + "$ref": "#/definitions/Tag" + } + }, + "status": { + "type": "string", + "description": "pet status in the store" + }, + "weight": { + "type": "number", + "description": "the weight of the pet" + } + } + }, + "Tag": { + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "name": { + "type": "string" + } + } + }, + "Order": { + "properties": { + "id": { + "type": "integer", + "format": "int64", + "example": 77 + + }, + "petId": { + "type": "integer", + "format": "int64" + }, + "quantity": { + "type": "integer", + "format": "int32" + }, + "shipDate": { + "type": "string", + "format": "date-time" + }, + "status": { + "type": "string", + "description": "Order Status", + "example": "DONE" + }, + "complete": { + "type": "boolean" + } + }, + "example": { + "id": 99, + "petId": 122, + "quantity": 2, + "shipDate": "2016-02-22T23:02:05Z", + "status": "PENDING", + "complete": true + } + } + } } \ No newline at end of file