Merge pull request #123 from Swagger2Markup/features/polymorphism

fixed #22 : Add discriminator field to the output
This commit is contained in:
Robert Winkler
2016-04-04 20:04:20 +02:00
31 changed files with 734 additions and 124 deletions

View File

@@ -20,7 +20,7 @@ import io.github.swagger2markup.Swagger2MarkupConverter;
import io.github.swagger2markup.Swagger2MarkupExtensionRegistry; import io.github.swagger2markup.Swagger2MarkupExtensionRegistry;
import io.github.swagger2markup.internal.document.MarkupDocument; import io.github.swagger2markup.internal.document.MarkupDocument;
import io.github.swagger2markup.internal.type.ObjectType; import io.github.swagger2markup.internal.type.ObjectType;
import io.github.swagger2markup.internal.type.RefType; import io.github.swagger2markup.internal.type.ObjectTypePolymorphism;
import io.github.swagger2markup.internal.type.Type; import io.github.swagger2markup.internal.type.Type;
import io.github.swagger2markup.internal.utils.ModelUtils; import io.github.swagger2markup.internal.utils.ModelUtils;
import io.github.swagger2markup.markup.builder.MarkupDocBuilder; import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
@@ -30,6 +30,7 @@ import io.swagger.models.properties.Property;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils; import org.apache.commons.collections4.MapUtils;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate; import org.apache.commons.lang3.Validate;
import java.io.File; import java.io.File;
@@ -52,8 +53,14 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank;
*/ */
public class DefinitionsDocumentBuilder extends MarkupDocumentBuilder { public class DefinitionsDocumentBuilder extends MarkupDocumentBuilder {
/* Discriminator is only displayed for inheriting definitions */
private static final boolean ALWAYS_DISPLAY_DISCRIMINATOR = false;
private static final String DEFINITIONS_ANCHOR = "definitions"; private static final String DEFINITIONS_ANCHOR = "definitions";
private final String DEFINITIONS; private final String DEFINITIONS;
private final String DISCRIMINATOR_COLUMN;
private final String POLYMORPHISM_COLUMN;
private final Map<ObjectTypePolymorphism.Nature, String> POLYMORPHISM_NATURE;
private final String TYPE_COLUMN; private final String TYPE_COLUMN;
private static final List<String> IGNORED_DEFINITIONS = Collections.singletonList("Void"); private static final List<String> IGNORED_DEFINITIONS = Collections.singletonList("Void");
private static final String DESCRIPTION_FILE_NAME = "description"; private static final String DESCRIPTION_FILE_NAME = "description";
@@ -63,6 +70,12 @@ public class DefinitionsDocumentBuilder extends MarkupDocumentBuilder {
ResourceBundle labels = ResourceBundle.getBundle("io/github/swagger2markup/lang/labels", config.getOutputLanguage().toLocale()); ResourceBundle labels = ResourceBundle.getBundle("io/github/swagger2markup/lang/labels", config.getOutputLanguage().toLocale());
DEFINITIONS = labels.getString("definitions"); DEFINITIONS = labels.getString("definitions");
POLYMORPHISM_COLUMN = labels.getString("polymorphism.column");
DISCRIMINATOR_COLUMN = labels.getString("polymorphism.discriminator");
POLYMORPHISM_NATURE = new HashMap<ObjectTypePolymorphism.Nature, String>() {{
put(ObjectTypePolymorphism.Nature.COMPOSITION, labels.getString("polymorphism.nature.COMPOSITION"));
put(ObjectTypePolymorphism.Nature.INHERITANCE, labels.getString("polymorphism.nature.INHERITANCE"));
}};
TYPE_COLUMN = labels.getString("type_column"); TYPE_COLUMN = labels.getString("type_column");
if (config.isDefinitionDescriptionsEnabled()) { if (config.isDefinitionDescriptionsEnabled()) {
@@ -255,13 +268,36 @@ public class DefinitionsDocumentBuilder extends MarkupDocumentBuilder {
*/ */
private List<ObjectType> typeSection(String definitionName, Model model, MarkupDocBuilder docBuilder) { private List<ObjectType> typeSection(String definitionName, Model model, MarkupDocBuilder docBuilder) {
List<ObjectType> localDefinitions = new ArrayList<>(); List<ObjectType> localDefinitions = new ArrayList<>();
Type modelType = ModelUtils.getType(model, globalContext.getSwagger().getDefinitions(), new DefinitionDocumentResolverFromDefinition()); Type modelType = ModelUtils.resolveRefType(ModelUtils.getType(model, globalContext.getSwagger().getDefinitions(), new DefinitionDocumentResolverFromDefinition()));
if (modelType instanceof ObjectType) {
ObjectType objectType = (ObjectType) modelType;
MarkupDocBuilder typeInfos = docBuilder.copy(false);
switch (objectType.getPolymorphism().getNature()) {
case COMPOSITION:
typeInfos.italicText(POLYMORPHISM_COLUMN).textLine(" : " + POLYMORPHISM_NATURE.get(objectType.getPolymorphism().getNature()));
break;
case INHERITANCE:
typeInfos.italicText(POLYMORPHISM_COLUMN).textLine(" : " + POLYMORPHISM_NATURE.get(objectType.getPolymorphism().getNature()));
typeInfos.italicText(DISCRIMINATOR_COLUMN).textLine(" : " + objectType.getPolymorphism().getDiscriminator());
break;
case NONE:
if (ALWAYS_DISPLAY_DISCRIMINATOR) {
if (StringUtils.isNotBlank(objectType.getPolymorphism().getDiscriminator()))
typeInfos.italicText(DISCRIMINATOR_COLUMN).textLine(" : " + objectType.getPolymorphism().getDiscriminator());
}
if (modelType instanceof ObjectType || modelType instanceof RefType) { default: break;
localDefinitions.addAll(buildPropertiesTable(ModelUtils.getTypeProperties(modelType), definitionName, 1, new PropertyDescriptor(modelType), new DefinitionDocumentResolverFromDefinition(), docBuilder)); }
String typeInfosString = typeInfos.toString();
if (StringUtils.isNotBlank(typeInfosString))
docBuilder.paragraph(typeInfosString, true);
localDefinitions.addAll(buildPropertiesTable(((ObjectType) modelType).getProperties(), definitionName, 1, new PropertyDescriptor(modelType), new DefinitionDocumentResolverFromDefinition(), docBuilder));
} else if (modelType != null) { } else if (modelType != null) {
MarkupDocBuilder typeInfos = docBuilder.copy(false); MarkupDocBuilder typeInfos = docBuilder.copy(false);
typeInfos.italicText(TYPE_COLUMN).textLine(": " + modelType.displaySchema(docBuilder)); typeInfos.italicText(TYPE_COLUMN).textLine(" : " + modelType.displaySchema(docBuilder));
docBuilder.paragraph(typeInfos.toString()); docBuilder.paragraph(typeInfos.toString());
} }

View File

@@ -106,7 +106,7 @@ public class OverviewDocumentBuilder extends MarkupDocumentBuilder {
private void buildVersionInfoSection(String version) { private void buildVersionInfoSection(String version) {
if(isNotBlank(version)){ if(isNotBlank(version)){
this.markupDocBuilder.sectionTitleLevel2(CURRENT_VERSION); this.markupDocBuilder.sectionTitleLevel2(CURRENT_VERSION);
this.markupDocBuilder.textLine(VERSION + COLON + version); this.markupDocBuilder.textLine(VERSION + COLON + version, true);
} }
} }
@@ -114,10 +114,10 @@ public class OverviewDocumentBuilder extends MarkupDocumentBuilder {
if(contact != null){ if(contact != null){
this.markupDocBuilder.sectionTitleLevel2(CONTACT_INFORMATION); this.markupDocBuilder.sectionTitleLevel2(CONTACT_INFORMATION);
if(isNotBlank(contact.getName())){ if(isNotBlank(contact.getName())){
this.markupDocBuilder.textLine(CONTACT_NAME + COLON + contact.getName()); this.markupDocBuilder.textLine(CONTACT_NAME + COLON + contact.getName(), true);
} }
if(isNotBlank(contact.getEmail())){ if(isNotBlank(contact.getEmail())){
this.markupDocBuilder.textLine(CONTACT_EMAIL + COLON + contact.getEmail()); this.markupDocBuilder.textLine(CONTACT_EMAIL + COLON + contact.getEmail(), true);
} }
} }
} }
@@ -126,14 +126,14 @@ public class OverviewDocumentBuilder extends MarkupDocumentBuilder {
if(license != null && (isNotBlank(license.getName()) || isNotBlank(license.getUrl()))) { if(license != null && (isNotBlank(license.getName()) || isNotBlank(license.getUrl()))) {
this.markupDocBuilder.sectionTitleLevel2(LICENSE_INFORMATION); this.markupDocBuilder.sectionTitleLevel2(LICENSE_INFORMATION);
if (isNotBlank(license.getName())) { if (isNotBlank(license.getName())) {
this.markupDocBuilder.textLine(LICENSE + COLON + license.getName()); this.markupDocBuilder.textLine(LICENSE + COLON + license.getName(), true);
} }
if (isNotBlank(license.getUrl())) { if (isNotBlank(license.getUrl())) {
this.markupDocBuilder.textLine(LICENSE_URL + COLON + license.getUrl()); this.markupDocBuilder.textLine(LICENSE_URL + COLON + license.getUrl(), true);
} }
} }
if(isNotBlank(termOfService)){ if(isNotBlank(termOfService)){
this.markupDocBuilder.textLine(TERMS_OF_SERVICE + COLON + termOfService); this.markupDocBuilder.textLine(TERMS_OF_SERVICE + COLON + termOfService, true);
} }
} }
@@ -141,17 +141,17 @@ public class OverviewDocumentBuilder extends MarkupDocumentBuilder {
if(isNotBlank(swagger.getHost()) || isNotBlank(swagger.getBasePath()) || isNotEmpty(swagger.getSchemes())) { if(isNotBlank(swagger.getHost()) || isNotBlank(swagger.getBasePath()) || isNotEmpty(swagger.getSchemes())) {
this.markupDocBuilder.sectionTitleLevel2(URI_SCHEME); this.markupDocBuilder.sectionTitleLevel2(URI_SCHEME);
if (isNotBlank(swagger.getHost())) { if (isNotBlank(swagger.getHost())) {
this.markupDocBuilder.textLine(HOST + COLON + swagger.getHost()); this.markupDocBuilder.textLine(HOST + COLON + swagger.getHost(), true);
} }
if (isNotBlank(swagger.getBasePath())) { if (isNotBlank(swagger.getBasePath())) {
this.markupDocBuilder.textLine(BASE_PATH + COLON + swagger.getBasePath()); this.markupDocBuilder.textLine(BASE_PATH + COLON + swagger.getBasePath(), true);
} }
if (isNotEmpty(swagger.getSchemes())) { if (isNotEmpty(swagger.getSchemes())) {
List<String> schemes = new ArrayList<>(); List<String> schemes = new ArrayList<>();
for (Scheme scheme : swagger.getSchemes()) { for (Scheme scheme : swagger.getSchemes()) {
schemes.add(scheme.toString()); schemes.add(scheme.toString());
} }
this.markupDocBuilder.textLine(SCHEMES + COLON + join(schemes, ", ")); this.markupDocBuilder.textLine(SCHEMES + COLON + join(schemes, ", "), true);
} }
} }
} }

View File

@@ -524,15 +524,15 @@ public class PathsDocumentBuilder extends MarkupDocumentBuilder {
} }
MarkupDocBuilder typeInfos = docBuilder.copy(false); MarkupDocBuilder typeInfos = docBuilder.copy(false);
typeInfos.italicText(REQUIRED_COLUMN).textLine(": " + parameter.getRequired()); typeInfos.italicText(REQUIRED_COLUMN).textLine(" : " + parameter.getRequired());
typeInfos.italicText(NAME_COLUMN).textLine(": " + parameter.getName()); typeInfos.italicText(NAME_COLUMN).textLine(" : " + parameter.getName());
if (!(type instanceof ObjectType)) { if (!(type instanceof ObjectType)) {
typeInfos.italicText(TYPE_COLUMN).textLine(": " + type.displaySchema(docBuilder)); typeInfos.italicText(TYPE_COLUMN).textLine(" : " + type.displaySchema(docBuilder));
}
docBuilder.paragraph(typeInfos.toString()); docBuilder.paragraph(typeInfos.toString(), true);
} else {
docBuilder.paragraph(typeInfos.toString());
if (type instanceof ObjectType) {
localDefinitions.addAll(buildPropertiesTable(((ObjectType) type).getProperties(), operation.getId(), config.getInlineSchemaDepthLevel(), new PropertyDescriptor(type), new DefinitionDocumentResolverFromOperation(), docBuilder)); localDefinitions.addAll(buildPropertiesTable(((ObjectType) type).getProperties(), operation.getId(), config.getInlineSchemaDepthLevel(), new PropertyDescriptor(type), new DefinitionDocumentResolverFromOperation(), docBuilder));
} }
} }

View File

@@ -25,12 +25,18 @@ import java.util.Map;
* Complex object abstraction * Complex object abstraction
*/ */
public class ObjectType extends Type { public class ObjectType extends Type {
protected Map<String, Property> properties; protected Map<String, Property> properties;
protected ObjectTypePolymorphism polymorphism;
public ObjectType(String name, ObjectTypePolymorphism polymorphism, Map<String, Property> properties) {
super(name == null ? "object" : name);
this.polymorphism = polymorphism;
this.properties = properties;
}
public ObjectType(String name, Map<String, Property> properties) { public ObjectType(String name, Map<String, Property> properties) {
super(name == null ? "object" : name); this(name, new ObjectTypePolymorphism(ObjectTypePolymorphism.Nature.NONE, null), properties);
this.properties = properties;
} }
@Override @Override
@@ -38,6 +44,14 @@ public class ObjectType extends Type {
return "object"; return "object";
} }
public ObjectTypePolymorphism getPolymorphism() {
return polymorphism;
}
public void setPolymorphism(ObjectTypePolymorphism polymorphism) {
this.polymorphism = polymorphism;
}
public Map<String, Property> getProperties() { public Map<String, Property> getProperties() {
return properties; return properties;
} }

View File

@@ -0,0 +1,51 @@
/*
* Copyright 2016 Robert Winkler
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.github.swagger2markup.internal.type;
public class ObjectTypePolymorphism {
public enum Nature {
NONE,
COMPOSITION,
INHERITANCE
}
public Nature nature = Nature.NONE;
public String discriminator;
public ObjectTypePolymorphism(Nature nature, String discriminator) {
this.nature = nature;
this.discriminator = discriminator;
}
public Nature getNature() {
return nature;
}
public void setNature(Nature nature) {
this.nature = nature;
}
public String getDiscriminator() {
return discriminator;
}
public void setDiscriminator(String discriminator) {
this.discriminator = discriminator;
}
}

View File

@@ -29,23 +29,18 @@ import java.util.Map;
public final class ModelUtils { public final class ModelUtils {
/** /**
* Retrieves the specified {@code type} properties if any, and recursively follows RefType * Recursively resolve referenced type if {@code type} is of type RefType
* @param type retrieve properties from type * @param type type to resolve
* @return dereferenced type properties, or null if type has no properties * @return referenced type
*/ */
public static Map<String, Property> getTypeProperties(Type type) { public static Type resolveRefType(Type type) {
Map<String, Property> properties = null; if (type == null)
if (type instanceof ObjectType) {
properties = ((ObjectType) type).getProperties();
} else if (type instanceof RefType) {
properties = getTypeProperties(((RefType) type).getRefType());
}
if (properties != null && !org.apache.commons.collections4.MapUtils.isEmpty(properties))
return ImmutableMap.copyOf(properties);
else
return null; return null;
if (type instanceof RefType)
return resolveRefType(((RefType) type).getRefType());
else
return type;
} }
/** /**
@@ -64,31 +59,49 @@ public final class ModelUtils {
return new MapType(null, PropertyUtils.getType(modelImpl.getAdditionalProperties(), definitionDocumentResolver)); return new MapType(null, PropertyUtils.getType(modelImpl.getAdditionalProperties(), definitionDocumentResolver));
else if (modelImpl.getEnum() != null) else if (modelImpl.getEnum() != null)
return new EnumType(null, modelImpl.getEnum()); return new EnumType(null, modelImpl.getEnum());
else if (modelImpl.getProperties() != null) else if (modelImpl.getProperties() != null) {
return new ObjectType(null, model.getProperties()); ObjectType objectType = new ObjectType(null, model.getProperties());
else
objectType.getPolymorphism().setDiscriminator(modelImpl.getDiscriminator());
return objectType;
} else
return new BasicType(((ModelImpl) model).getType()); return new BasicType(((ModelImpl) model).getType());
} else if (model instanceof ComposedModel) { } else if (model instanceof ComposedModel) {
ComposedModel composedModel = (ComposedModel) model; ComposedModel composedModel = (ComposedModel) model;
Map<String, Property> allProperties = new HashMap<>(); Map<String, Property> allProperties = new HashMap<>();
if (composedModel.getAllOf() != null) { ObjectTypePolymorphism polymorphism = new ObjectTypePolymorphism(ObjectTypePolymorphism.Nature.NONE, null);
for (Model innerModel : composedModel.getAllOf()) {
Type innerModelType = getType(innerModel, definitions, definitionDocumentResolver);
Map<String, Property> innerModelProperties = getTypeProperties(innerModelType);
if (innerModelProperties != null) if (composedModel.getAllOf() != null) {
allProperties.putAll(innerModelProperties); polymorphism.setNature(ObjectTypePolymorphism.Nature.COMPOSITION);
for (Model innerModel : composedModel.getAllOf()) {
Type innerModelType = resolveRefType(getType(innerModel, definitions, definitionDocumentResolver));
if (innerModelType instanceof ObjectType) {
String innerModelDiscriminator = ((ObjectType) innerModelType).getPolymorphism().getDiscriminator();
if (innerModelDiscriminator != null) {
polymorphism.setNature(ObjectTypePolymorphism.Nature.INHERITANCE);
polymorphism.setDiscriminator(innerModelDiscriminator);
}
Map<String, Property> innerModelProperties = ((ObjectType) innerModelType).getProperties();
if (innerModelProperties != null)
allProperties.putAll(ImmutableMap.copyOf(innerModelProperties));
}
} }
} }
return new ObjectType(null, allProperties);
return new ObjectType(null, polymorphism, allProperties);
} else if (model instanceof RefModel) { } else if (model instanceof RefModel) {
RefModel refModel = (RefModel) model; RefModel refModel = (RefModel) model;
String refName = refModel.getRefFormat().equals(RefFormat.INTERNAL) ? refModel.getSimpleRef() : refModel.getReference(); String refName = refModel.getRefFormat().equals(RefFormat.INTERNAL) ? refModel.getSimpleRef() : refModel.getReference();
Type refType = new ObjectType(refName, null); Type refType = new ObjectType(refName, null);
if (definitions.containsKey(refName)) if (definitions.containsKey(refName))
refType = getType(definitions.get(refName), definitions, definitionDocumentResolver); refType = getType(definitions.get(refName), definitions, definitionDocumentResolver);
return new RefType(definitionDocumentResolver.apply(refName), refName, refName, refType); return new RefType(definitionDocumentResolver.apply(refName), refName, refName, refType);
} else if (model instanceof ArrayModel) { } else if (model instanceof ArrayModel) {
ArrayModel arrayModel = ((ArrayModel) model); ArrayModel arrayModel = ((ArrayModel) model);

View File

@@ -10,7 +10,7 @@ scopes_column=Scopes
produces=Erzeugt produces=Erzeugt
consumes=Verarbeitet consumes=Verarbeitet
tags=Tags tags=Tags
overview=<EFBFBD>bersicht overview=<EFBFBD>bersicht
current_version=Aktuelle Version current_version=Aktuelle Version
version=Version version=Version
contact_information=Kontaktinformationen contact_information=Kontaktinformationen
@@ -45,4 +45,8 @@ http_code_column=HTTP Code
parameter=Parameter parameter=Parameter
unknown=Unbekannt unknown=Unbekannt
no_content=Kein Inhalt no_content=Kein Inhalt
operation.deprecated=Diese Operation ist veraltet. operation.deprecated=Diese Operation ist veraltet.
polymorphism.column=Polymorphism
polymorphism.discriminator=Discriminator
polymorphism.nature.INHERITANCE=Inheritance
polymorphism.nature.COMPOSITION=Composition

View File

@@ -49,4 +49,8 @@ parameter=Parameter
unknown=Unknown unknown=Unknown
no_content=No Content no_content=No Content
operation.deprecated=This operation is deprecated. operation.deprecated=This operation is deprecated.
polymorphism.column=Polymorphism
polymorphism.discriminator=Discriminator
polymorphism.nature.INHERITANCE=Inheritance
polymorphism.nature.COMPOSITION=Composition

View File

@@ -49,4 +49,8 @@ parameter=Param\u00E8tre
unknown=Unknown unknown=Unknown
no_content=Pas de contenu no_content=Pas de contenu
operation.deprecated=Cette op\u00E9ration est obsol\u00E8te. operation.deprecated=Cette op\u00E9ration est obsol\u00E8te.
polymorphism.column=Polymorphisme
polymorphism.discriminator=Discriminateur
polymorphism.nature.INHERITANCE=H\u00E9ritage
polymorphism.nature.COMPOSITION=Composition

View File

@@ -1,6 +1,4 @@
definitions=\u041E\u043F\u0440\u0435\u0434\u0435\u043B\u0435\u043D\u0438\u044F definitions=\u041E\u043F\u0440\u0435\u0434\u0435\u043B\u0435\u043D\u0438\u044F
json_schema=JSON \u0441\u0445\u0435\u043C\u0430
xml_schema=XML \u0441\u0445\u0435\u043C\u0430
default_column=\u041F\u043E \u0443\u043C\u043E\u043B\u0447\u0430\u043D\u0438\u044E default_column=\u041F\u043E \u0443\u043C\u043E\u043B\u0447\u0430\u043D\u0438\u044E
required_column=\u041E\u0431\u044F\u0437\u0430\u0442\u0435\u043B\u044C\u043D\u043E required_column=\u041E\u0431\u044F\u0437\u0430\u0442\u0435\u043B\u044C\u043D\u043E
@@ -51,4 +49,8 @@ parameter=\u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440
unknown=Unknown unknown=Unknown
no_content=\u0411\u0435\u0437 \u0441\u043E\u0434\u0435\u0440\u0436\u0438\u043C\u043E\u0433\u043E no_content=\u0411\u0435\u0437 \u0441\u043E\u0434\u0435\u0440\u0436\u0438\u043C\u043E\u0433\u043E
operation.deprecated=\u042D\u0442\u0430 \u043E\u043F\u0435\u0440\u0430\u0446\u0438\u044F \u0443\u0441\u0442\u0430\u0440\u0435\u043B\u0430. operation.deprecated=\u042D\u0442\u0430 \u043E\u043F\u0435\u0440\u0430\u0446\u0438\u044F \u0443\u0441\u0442\u0430\u0440\u0435\u043B\u0430.
polymorphism.column=Polymorphism
polymorphism.discriminator=Discriminator
polymorphism.nature.INHERITANCE=Inheritance
polymorphism.nature.COMPOSITION=Composition

View File

@@ -407,4 +407,27 @@ public class AsciidocConverterTest {
Path expectedFilesDirectory = Paths.get(AsciidocConverterTest.class.getResource("/expected/asciidoc/enums").toURI()); Path expectedFilesDirectory = Paths.get(AsciidocConverterTest.class.getResource("/expected/asciidoc/enums").toURI());
DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testSwagger2AsciiDocConversionWithEnums.html"); DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testSwagger2AsciiDocConversionWithEnums.html");
} }
@Test
public void testSwagger2AsciiDocConversionWithPolymorphism() throws IOException, URISyntaxException {
//Given
Path file = Paths.get(AsciidocConverterTest.class.getResource("/json/swagger_polymorphism.json").toURI());
Path outputDirectory = Paths.get("build/test/asciidoc/polymorphism");
FileUtils.deleteQuietly(outputDirectory.toFile());
//When
Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
.build();
Swagger2MarkupConverter.from(file)
.withConfig(config)
.build()
.toFolder(outputDirectory);
//Then
String[] files = outputDirectory.toFile().list();
assertThat(files).hasSize(4).containsAll(expectedFiles);
Path expectedFilesDirectory = Paths.get(AsciidocConverterTest.class.getResource("/expected/asciidoc/polymorphism").toURI());
DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testSwagger2AsciiDocConversionWithPolymorphism.html");
}
} }

View File

@@ -11,20 +11,20 @@ For this sample, you can use the api key `special-key` to test the authorization
=== Version information === Version information
Version : 1.0.0 Version : 1.0.0 +
=== Contact information === Contact information
Contact : apiteam@swagger.io Contact : apiteam@swagger.io +
=== License information === License information
License : Apache 2.0 License : Apache 2.0 +
License URL : http://www.apache.org/licenses/LICENSE-2.0.html License URL : http://www.apache.org/licenses/LICENSE-2.0.html +
Terms of service : http://helloreverb.com/terms/ Terms of service : http://helloreverb.com/terms/ +
=== URI scheme === URI scheme
Host : petstore.swagger.io Host : petstore.swagger.io +
BasePath : /v2 BasePath : /v2 +
Schemes : HTTP Schemes : HTTP +
=== Tags === Tags

View File

@@ -6,14 +6,14 @@
=== EnumString === EnumString
Enum string Enum string
_Type_: enum (ADDED, REMOVED, CHANGED) _Type_ : enum (ADDED, REMOVED, CHANGED)
[[_simplestring]] [[_simplestring]]
=== SimpleString === SimpleString
Simple string Simple string
_Type_: string _Type_ : string

View File

@@ -7,9 +7,9 @@ Description
=== Version information === Version information
Version : Developer build Version : Developer build +
=== URI scheme === URI scheme
Host : localhost:8080 Host : localhost:8080 +

View File

@@ -70,6 +70,9 @@ Test description
[[_user]] [[_user]]
=== User === User
[%hardbreaks]
_Polymorphism_ : Composition
[options="header", cols=".^1h,.^6,.^1,.^1,.^1,.^1"] [options="header", cols=".^1h,.^6,.^1,.^1,.^1,.^1"]
|=== |===

View File

@@ -11,20 +11,20 @@ For this sample, you can use the api key `special-key` to test the authorization
=== Version information === Version information
Version : 1.0.0 Version : 1.0.0 +
=== Contact information === Contact information
Contact : apiteam@wordnik.com Contact : apiteam@wordnik.com +
=== License information === License information
License : Apache 2.0 License : Apache 2.0 +
License URL : http://www.apache.org/licenses/LICENSE-2.0.html License URL : http://www.apache.org/licenses/LICENSE-2.0.html +
Terms of service : http://helloreverb.com/terms/ Terms of service : http://helloreverb.com/terms/ +
=== URI scheme === URI scheme
Host : petstore.swagger.wordnik.com Host : petstore.swagger.wordnik.com +
BasePath : /v2 BasePath : /v2 +
Schemes : HTTP Schemes : HTTP +
=== Tags === Tags

View File

@@ -11,20 +11,20 @@ For this sample, you can use the api key `special-key` to test the authorization
=== Version information === Version information
Version : 1.0.0 Version : 1.0.0 +
=== Contact information === Contact information
Contact : apiteam@swagger.io Contact : apiteam@swagger.io +
=== License information === License information
License : Apache 2.0 License : Apache 2.0 +
License URL : http://www.apache.org/licenses/LICENSE-2.0.html License URL : http://www.apache.org/licenses/LICENSE-2.0.html +
Terms of service : http://helloreverb.com/terms/ Terms of service : http://helloreverb.com/terms/ +
=== URI scheme === URI scheme
Host : petstore.swagger.io Host : petstore.swagger.io +
BasePath : /v2 BasePath : /v2 +
Schemes : HTTP Schemes : HTTP +
=== Tags === Tags

View File

@@ -72,6 +72,9 @@ Test description
[[_user]] [[_user]]
=== User === User
[%hardbreaks]
_Polymorphism_ : Composition
[options="header", cols=".^1h,.^6,.^1,.^1,.^1,.^1"] [options="header", cols=".^1h,.^6,.^1,.^1,.^1,.^1"]
|=== |===

View File

@@ -11,20 +11,20 @@ For this sample, you can use the api key `special-key` to test the authorization
=== Version information === Version information
Version : 1.0.0 Version : 1.0.0 +
=== Contact information === Contact information
Contact : apiteam@wordnik.com Contact : apiteam@wordnik.com +
=== License information === License information
License : Apache 2.0 License : Apache 2.0 +
License URL : http://www.apache.org/licenses/LICENSE-2.0.html License URL : http://www.apache.org/licenses/LICENSE-2.0.html +
Terms of service : http://helloreverb.com/terms/ Terms of service : http://helloreverb.com/terms/ +
=== URI scheme === URI scheme
Host : petstore.swagger.wordnik.com Host : petstore.swagger.wordnik.com +
BasePath : /v2 BasePath : /v2 +
Schemes : HTTP Schemes : HTTP +
=== Tags === Tags

View File

@@ -11,20 +11,20 @@ For this sample, you can use the api key `special-key` to test the authorization
=== Version information === Version information
Version : 1.0.0 Version : 1.0.0 +
=== Contact information === Contact information
Contact : apiteam@swagger.io Contact : apiteam@swagger.io +
=== License information === License information
License : Apache 2.0 License : Apache 2.0 +
License URL : http://www.apache.org/licenses/LICENSE-2.0.html License URL : http://www.apache.org/licenses/LICENSE-2.0.html +
Terms of service : http://helloreverb.com/terms/ Terms of service : http://helloreverb.com/terms/ +
=== URI scheme === URI scheme
Host : petstore.swagger.io Host : petstore.swagger.io +
BasePath : /v2 BasePath : /v2 +
Schemes : HTTP Schemes : HTTP +
=== Tags === Tags

View File

@@ -7,11 +7,11 @@ Service API
=== Version information === Version information
Version : 2.18 Version : 2.18 +
=== URI scheme === URI scheme
Host : service.host.com Host : service.host.com +
Schemes : HTTPS Schemes : HTTPS +
=== Consumes === Consumes

View File

@@ -7,14 +7,14 @@ Description
=== Version information === Version information
Version : Developer build Version : Developer build +
=== Contact information === Contact information
Contact : (Contact name) Contact : (Contact name) +
=== URI scheme === URI scheme
Host : localhost:8080 Host : localhost:8080 +
BasePath : /engine BasePath : /engine +
=== Tags === Tags

View File

@@ -2,6 +2,52 @@
[[_paths]] [[_paths]]
== Paths == Paths
[[_createintegermetrics]]
=== Create integer Metrics
----
POST /integerMetrics
----
==== Description
Returns integer metrics information for the application.
==== Parameters
[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"]
|===
|Type|Name|Description|Required|Schema|Default
|Body|body|String metrics|false|<string,integer(int32)> map|
|===
==== Responses
===== HTTP Code 200
[options="header", cols=".^1h,.^3,.^1"]
|===
|HTTP Code|Description|Schema
|200|OK|<string,string> map
|===
==== Consumes
* application/json
==== Produces
* */*
==== Tags
* Spring Boot Actuator
[[_createmappings]] [[_createmappings]]
=== Create Path Mappings === Create Path Mappings
---- ----

View File

@@ -0,0 +1,100 @@
[[_definitions]]
== Definitions
[[_array]]
=== Array
An array
[%hardbreaks]
_Polymorphism_ : Inheritance
_Discriminator_ : collType
[options="header", cols=".^1h,.^6,.^1,.^1,.^1,.^1"]
|===
|Name|Description|Required|Schema|Default|Example
|collType|collection type discriminator|true|string||
|name||false|string||
|===
[[_cat]]
=== Cat
A representation of a cat
[%hardbreaks]
_Polymorphism_ : Inheritance
_Discriminator_ : petType
[options="header", cols=".^1h,.^6,.^1,.^1,.^1,.^1"]
|===
|Name|Description|Required|Schema|Default|Example
|huntingSkill|The measured skill for hunting|true|enum (clueless, lazy, adventurous, aggressive)|lazy|
|name||true|string||
|petType||true|string||
|===
[[_collection]]
=== Collection
Collection parent type without discriminator
[options="header", cols=".^1h,.^6,.^1,.^1,.^1,.^1"]
|===
|Name|Description|Required|Schema|Default|Example
|name||false|string||
|===
[[_dog]]
=== Dog
A representation of a dog with a conflicting discriminator
[%hardbreaks]
_Polymorphism_ : Inheritance
_Discriminator_ : dogType
[options="header", cols=".^1h,.^6,.^1,.^1,.^1,.^1"]
|===
|Name|Description|Required|Schema|Default|Example
|dogType||true|string||
|name||true|string||
|packSize|the size of the pack the dog is from|true|integer(int32)|0|
|petType||true|string||
|===
[[_map]]
=== Map
A map without discriminator
[%hardbreaks]
_Polymorphism_ : Composition
[options="header", cols=".^1h,.^6,.^1,.^1,.^1,.^1"]
|===
|Name|Description|Required|Schema|Default|Example
|collType|collection type discriminator|true|string||
|name||false|string||
|===
[[_pet]]
=== Pet
Pet parent type with discriminator
[options="header", cols=".^1h,.^6,.^1,.^1,.^1,.^1"]
|===
|Name|Description|Required|Schema|Default|Example
|name||true|string||
|petType||true|string||
|===

View File

@@ -0,0 +1,15 @@
= Title
[[_overview]]
== Overview
Description
=== Version information
Version : Developer build +
=== URI scheme
Host : localhost:8080 +

View File

@@ -0,0 +1,69 @@
[[_paths]]
== Paths
[[_getcolls]]
=== Get collections
----
GET /collections
----
==== Description
Get collections
==== Responses
===== HTTP Code 200
[options="header", cols=".^1h,.^3,.^1"]
|===
|HTTP Code|Description|Schema
|200|OK|<<_collection,Collection>>
|===
==== Consumes
* application/json
==== Produces
* */*
[[_getpets]]
=== Get Pets
----
GET /pets
----
==== Description
Get pets
==== Responses
===== HTTP Code 200
[options="header", cols=".^1h,.^3,.^1"]
|===
|HTTP Code|Description|Schema
|200|OK|<<_pet,Pet>>
|===
==== Consumes
* application/json
==== Produces
* */*

View File

@@ -0,0 +1,2 @@

View File

@@ -11,20 +11,20 @@ For this sample, you can use the api key `special-key` to test the authorization
=== Version information === Version information
Version : 1.0.0 Version : 1.0.0 +
=== Contact information === Contact information
Contact : apiteam@swagger.io Contact : apiteam@swagger.io +
=== License information === License information
License : Apache 2.0 License : Apache 2.0 +
License URL : http://www.apache.org/licenses/LICENSE-2.0.html License URL : http://www.apache.org/licenses/LICENSE-2.0.html +
Terms of service : http://helloreverb.com/terms/ Terms of service : http://helloreverb.com/terms/ +
=== URI scheme === URI scheme
Host : petstore.swagger.io Host : petstore.swagger.io +
BasePath : /v2 BasePath : /v2 +
Schemes : HTTP Schemes : HTTP +
=== Tags === Tags

View File

@@ -11,20 +11,20 @@ For this sample, you can use the api key `special-key` to test the authorization
### Version information ### Version information
Version : 1.0.0 Version : 1.0.0
### Contact information ### Contact information
Contact : apiteam@swagger.io Contact : apiteam@swagger.io
### License information ### License information
License : Apache 2.0 License : Apache 2.0
License URL : http://www.apache.org/licenses/LICENSE-2.0.html License URL : http://www.apache.org/licenses/LICENSE-2.0.html
Terms of service : http://helloreverb.com/terms/ Terms of service : http://helloreverb.com/terms/
### URI scheme ### URI scheme
Host : petstore.swagger.io Host : petstore.swagger.io
BasePath : /v2 BasePath : /v2
Schemes : HTTP Schemes : HTTP
### Tags ### Tags

View File

@@ -152,6 +152,48 @@
} }
} }
} }
},
"/integerMetrics": {
"post": {
"tags": [
"Spring Boot Actuator"
],
"summary": "Create integer Metrics",
"description": "Returns integer metrics information for the application.",
"operationId": "createIntegerMetrics",
"consumes": [
"application/json"
],
"produces": [
"*/*"
],
"parameters": [
{
"in": "body",
"name": "body",
"description": "String metrics",
"required": false,
"schema": {
"type": "object",
"additionalProperties": {
"type": "integer",
"format": "int32"
}
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
}
}
}
} }
}, },
"definitions": { "definitions": {

View File

@@ -0,0 +1,179 @@
{
"swagger": "2.0",
"info": {
"description": "Description",
"version": "Developer build",
"title": "Title"
},
"host": "localhost:8080",
"paths": {
"/pets": {
"get": {
"summary": "Get Pets",
"description": "Get pets",
"operationId": "getPets",
"consumes": [
"application/json"
],
"produces": [
"*/*"
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "array",
"$ref": "#/definitions/Pet"
}
}
}
}
},
"/collections": {
"get": {
"summary": "Get collections",
"description": "Get collections",
"operationId": "getColls",
"consumes": [
"application/json"
],
"produces": [
"*/*"
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "array",
"$ref": "#/definitions/Collection"
}
}
}
}
}
},
"definitions": {
"Pet": {
"description": "Pet parent type with discriminator",
"type": "object",
"discriminator": "petType",
"properties": {
"name": {
"type": "string"
},
"petType": {
"type": "string"
}
},
"required": [
"name",
"petType"
]
},
"Cat": {
"description": "A representation of a cat",
"allOf": [
{
"$ref": "#/definitions/Pet"
},
{
"type": "object",
"properties": {
"huntingSkill": {
"type": "string",
"description": "The measured skill for hunting",
"default": "lazy",
"enum": [
"clueless",
"lazy",
"adventurous",
"aggressive"
]
}
},
"required": [
"huntingSkill"
]
}
]
},
"Dog": {
"description": "A representation of a dog with a conflicting discriminator",
"allOf": [
{
"$ref": "#/definitions/Pet"
},
{
"type": "object",
"discriminator": "dogType",
"properties": {
"dogType": {
"type": "string"
},
"packSize": {
"type": "integer",
"format": "int32",
"description": "the size of the pack the dog is from",
"default": 0,
"minimum": 0
}
},
"required": [
"dogType",
"packSize"
]
}
]
},
"Collection": {
"description": "Collection parent type without discriminator",
"type": "object",
"properties": {
"name": {
"type": "string"
}
}
},
"Array": {
"description": "An array",
"allOf": [
{
"$ref": "#/definitions/Collection"
},
{
"type": "object",
"discriminator": "collType",
"properties": {
"collType": {
"type": "string",
"description": "collection type discriminator"
}
},
"required": [
"collType"
]
}
]
},
"Map": {
"description": "A map without discriminator",
"allOf": [
{
"$ref": "#/definitions/Collection"
},
{
"type": "object",
"properties": {
"collType": {
"type": "string",
"description": "collection type discriminator"
}
},
"required": [
"collType"
]
}
]
}
}
}