diff --git a/build.gradle b/build.gradle index 6e2a8dab..bb706576 100644 --- a/build.gradle +++ b/build.gradle @@ -54,6 +54,9 @@ configure(project.coreProjects) { options.encoding = 'UTF-8' options.compilerArgs += ["-Xlint:unchecked", "-parameters"] } + tasks.withType(Javadoc){ + options.encoding = 'UTF-8' + } jmh { duplicateClassesStrategy = 'warn' } diff --git a/libraries.gradle b/libraries.gradle index c5b2f650..41f04255 100644 --- a/libraries.gradle +++ b/libraries.gradle @@ -6,6 +6,7 @@ ext { dependencyOverrides = [:] } implLibraries = [ + asciiDocJApi : "org.asciidoctor:asciidoctorj-api:2.2.0", commonsBeanUtils : "commons-beanutils:commons-beanutils:1.9.4", commonsCodec : "commons-codec:commons-codec:1.13", commonsCollections4: "org.apache.commons:commons-collections4:4.4", @@ -13,16 +14,20 @@ implLibraries = [ commonsLang3 : "org.apache.commons:commons-lang3:3.9", commonsIO : "commons-io:commons-io:2.6", commonsText : "org.apache.commons:commons-text:1.8", + guava : 'com.google.guava:guava:27.0.1-android', + jacksonDatabind : 'com.fasterxml.jackson.core:jackson-databind:2.9.10', mark2Ascii : "nl.jworks.markdown_to_asciidoc:markdown_to_asciidoc:1.1", paleo : "ch.netzwerg:paleo-core:0.14.0", pegdown : "org.pegdown:pegdown:1.6.0", slf4j : "org.slf4j:slf4j-api:1.7.28", - swaggerConverterV2 : "io.swagger.parser.v3:swagger-parser-v2-converter:2.0.15", + swaggerV2 : "io.swagger:swagger-parser:1.0.47", + swaggerV2Converter : "io.swagger.parser.v3:swagger-parser-v2-converter:2.0.15", + swaggerV3 : "io.swagger.parser.v3:swagger-parser:2.0.15", vavr : "io.vavr:vavr:0.10.2" ] testLibraries = [ - asciiDocJ : "org.asciidoctor:asciidoctorj:2.1.0", + asciiDocJ : "org.asciidoctor:asciidoctorj:2.2.0", assertj : "org.assertj:assertj-core:3.13.2", assertjDiff: "io.github.robwin:assertj-diff:0.1.1", junit : "junit:junit:4.12", @@ -36,9 +41,9 @@ dependencyOverrides = [ commonsIO : implLibraries.commonsIO, commonsLang3 : implLibraries.commonsLang3, findBugs : 'com.google.code.findbugs:jsr305:3.0.2', - guava : 'com.google.guava:guava:27.0.1-android', + guava : implLibraries.guava, jaksonCore : 'com.github.fge:jackson-coreutils:1.8', - jacksonDatabind: 'com.fasterxml.jackson.core:jackson-databind:2.9.10', + jacksonDatabind: implLibraries.jacksonDatabind, jnrConstants : 'com.github.jnr:jnr-constants:0.9.12', jnrEnxio : 'com.github.jnr:jnr-enxio:0.19', jnrPosix : 'com.github.jnr:jnr-posix:3.0.49', diff --git a/openapi2markup/build.gradle b/openapi2markup/build.gradle new file mode 100644 index 00000000..a167e3d0 --- /dev/null +++ b/openapi2markup/build.gradle @@ -0,0 +1,34 @@ +ext.moduleName="io.github.swagger2markup.openapi2markup" + +dependencies { + configurations.all { + resolutionStrategy.force dependencyOverrides.commonsCodec + resolutionStrategy.force dependencyOverrides.commonsIO + resolutionStrategy.force dependencyOverrides.commonsLang3 + resolutionStrategy.force dependencyOverrides.jnrConstants + resolutionStrategy.force dependencyOverrides.jnrEnxio + resolutionStrategy.force dependencyOverrides.jnrPosix + resolutionStrategy.force dependencyOverrides.jodaTime + resolutionStrategy.force dependencyOverrides.slf4j + resolutionStrategy.force dependencyOverrides.jacksonDatabind + resolutionStrategy.force dependencyOverrides.guava + resolutionStrategy.force dependencyOverrides.findBugs + resolutionStrategy.force dependencyOverrides.jaksonCore + resolutionStrategy.force dependencyOverrides.assertj + } +// implementation implLibraries.swaggerV2Converter + compile project(':swagger2markup-asciidoc') + compile project(':swagger2markup-core') + implementation implLibraries.asciiDocJApi + implementation implLibraries.commonsText + implementation implLibraries.commonsBeanUtils + implementation implLibraries.slf4j + implementation implLibraries.swaggerV3 + implementation implLibraries.commonsCollections4 + implementation implLibraries.commonsConf2 + implementation implLibraries.vavr + testImplementation testLibraries.assertj + testImplementation testLibraries.assertjDiff + testImplementation testLibraries.junit + testImplementation testLibraries.logback +} diff --git a/openapi2markup/src/main/java/io/github/swagger2markup/OpenAPI2MarkupConverter.java b/openapi2markup/src/main/java/io/github/swagger2markup/OpenAPI2MarkupConverter.java new file mode 100644 index 00000000..ba039f68 --- /dev/null +++ b/openapi2markup/src/main/java/io/github/swagger2markup/OpenAPI2MarkupConverter.java @@ -0,0 +1,380 @@ +/* + * Copyright 2017 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; + +import io.github.swagger2markup.adoc.ast.impl.DocumentImpl; +import io.github.swagger2markup.config.Labels; +import io.github.swagger2markup.config.MarkupLanguage; +import io.github.swagger2markup.config.OpenAPILabels; +import io.github.swagger2markup.config.builder.OpenAPI2MarkupConfigBuilder; +import io.github.swagger2markup.extension.OpenAPI2MarkupExtensionRegistry; +import io.github.swagger2markup.extension.builder.OpenAPI2MarkupExtensionRegistryBuilder; +import io.github.swagger2markup.internal.document.ComponentsDocument; +import io.github.swagger2markup.internal.document.OverviewDocument; +import io.github.swagger2markup.internal.document.PathsDocument; +import io.github.swagger2markup.internal.document.SecurityDocument; +import io.github.swagger2markup.utils.URIUtils; +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.parser.OpenAPIV3Parser; +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.Validate; +import org.asciidoctor.ast.Document; + +import java.io.BufferedWriter; +import java.io.IOException; +import java.io.Reader; +import java.io.StringReader; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +public class OpenAPI2MarkupConverter extends AbstractSchema2MarkupConverter { + private final OverviewDocument overviewDocument; + private final PathsDocument pathsDocument; + private final ComponentsDocument componentsDocument; + private final SecurityDocument securityDocument; + private final OpenAPIContext openAPIContext; + + + public OpenAPI2MarkupConverter(OpenAPIContext context) { + super(context); + this.openAPIContext = context; + this.overviewDocument = new OverviewDocument(context); + this.pathsDocument = new PathsDocument(context); + this.componentsDocument = new ComponentsDocument(context); + this.securityDocument = new SecurityDocument(context); + } + + + /** + * Creates a OpenAPI2MarkupConverter.Builder from a URI. + * + * @param swaggerUri the URI + * @return a OpenAPI2MarkupConverter + */ + public static Builder from(URI swaggerUri) { + Validate.notNull(swaggerUri, "swaggerUri must not be null"); + String scheme = swaggerUri.getScheme(); + if (scheme != null && swaggerUri.getScheme().startsWith("http")) { + try { + return from(swaggerUri.toURL()); + } catch (MalformedURLException e) { + throw new RuntimeException("Failed to convert URI to URL", e); + } + } else if (scheme != null && swaggerUri.getScheme().startsWith("file")) { + return from(Paths.get(swaggerUri)); + } else { + return from(URIUtils.convertUriWithoutSchemeToFileScheme(swaggerUri)); + } + } + + /** + * Creates a OpenAPI2MarkupConverter.Builder using a remote URL. + * + * @param swaggerURL the remote URL + * @return a OpenAPI2MarkupConverter + */ + public static Builder from(URL swaggerURL) { + Validate.notNull(swaggerURL, "swaggerURL must not be null"); + return new Builder(swaggerURL); + } + + /** + * Creates a OpenAPI2MarkupConverter.Builder using a local Path. + * + * @param swaggerPath the local Path + * @return a OpenAPI2MarkupConverter + */ + public static Builder from(Path swaggerPath) { + Validate.notNull(swaggerPath, "swaggerPath must not be null"); + if (Files.notExists(swaggerPath)) { + throw new IllegalArgumentException(String.format("swaggerPath does not exist: %s", swaggerPath)); + } + try { + if (Files.isHidden(swaggerPath)) { + throw new IllegalArgumentException("swaggerPath must not be a hidden file"); + } + } catch (IOException e) { + throw new RuntimeException("Failed to check if swaggerPath is a hidden file", e); + } + return new Builder(swaggerPath); + } + + /** + * Creates a OpenAPI2MarkupConverter.Builder from a given Swagger model. + * + * @param openAPI the Swagger source. + * @return a OpenAPI2MarkupConverter + */ + public static Builder from(OpenAPI openAPI) { + Validate.notNull(openAPI, "schema must not be null"); + return new Builder(openAPI); + } + + /** + * Creates a OpenAPI2MarkupConverter.Builder from a given Swagger YAML or JSON String. + * + * @param swaggerString the Swagger YAML or JSON String. + * @return a OpenAPI2MarkupConverter + */ + public static Builder from(String swaggerString) { + Validate.notEmpty(swaggerString, "swaggerString must not be null"); + return from(new StringReader(swaggerString)); + } + + /** + * Creates a OpenAPI2MarkupConverter.Builder from a given Swagger YAML or JSON reader. + * + * @param schemaReader the schema YAML or JSON reader. + * @return a OpenAPI2MarkupConverter + */ + public static Builder from(Reader schemaReader) { + Validate.notNull(schemaReader, "swaggerReader must not be null"); + OpenAPI openAPI; + try { + //TODO + openAPI = new OpenAPIV3Parser().read(IOUtils.toString(schemaReader)); + } catch (IOException e) { + throw new RuntimeException("Swagger source can not be parsed", e); + } + if (openAPI == null) + throw new IllegalArgumentException("Swagger source is in a wrong format"); + + return new Builder(openAPI); + } + + + @Override + public void toFolder(Path outputDirectory) { + Validate.notNull(outputDirectory, "outputDirectory must not be null"); + openAPIContext.setOutputPath(outputDirectory); + writeToFile(applyOverviewDocument(), outputDirectory.resolve(openAPIContext.config.getOverviewDocument())); + writeToFile(applyPathsDocument(), outputDirectory.resolve(openAPIContext.config.getPathsDocument())); + writeToFile(applyComponentsDocument(), outputDirectory.resolve(openAPIContext.config.getDefinitionsDocument())); + writeToFile(applySecurityDocument(), outputDirectory.resolve(openAPIContext.config.getSecurityDocument())); + } + + @Override + public void toFile(Path outputFile) { + Validate.notNull(outputFile, "outputFile must not be null"); + + writeToFile(applyOverviewDocument(), outputFile); + writeToFile(applyPathsDocument(), outputFile); + writeToFile(applyComponentsDocument(), outputFile); + writeToFile(applySecurityDocument(), outputFile); + } + + @Override + public void toFileWithoutExtension(Path outputFile) { + Validate.notNull(outputFile, "outputFile must not be null"); + + writeToFileWithoutExtension(applyOverviewDocument(), outputFile); + writeToFileWithoutExtension(applyPathsDocument(), outputFile); + writeToFileWithoutExtension(applyComponentsDocument(), outputFile); + writeToFileWithoutExtension(applySecurityDocument(), outputFile); + } + + @Override + public String toString() { + return applyOverviewDocument().convert() + + applyPathsDocument().convert() + + applyComponentsDocument().convert() + + applySecurityDocument().convert(); + } + + private Document applyOverviewDocument() { + return overviewDocument.apply( + openAPIContext.createDocument(), + OverviewDocument.parameters(openAPIContext.getSchema())); + } + + private Document applyPathsDocument() { + return pathsDocument.apply( + openAPIContext.createDocument(), + PathsDocument.parameters(openAPIContext.getSchema())); + } + + private Document applyComponentsDocument() { + return componentsDocument.apply( + openAPIContext.createDocument(), + ComponentsDocument.parameters(openAPIContext.getSchema().getComponents())); + } + + private Document applySecurityDocument() { + return securityDocument.apply( + openAPIContext.createDocument(), + SecurityDocument.parameters(openAPIContext.getSchema())); + } + + private void writeToFile(Document document, Path path) { + MarkupLanguage markupLanguage = openAPIContext.config.getMarkupLanguage(); + if (isMarkupLanguageSupported(markupLanguage)) { + String fileExtension = markupLanguage.getFileNameExtensions().get(0); + writeToFileWithoutExtension(document, path.resolveSibling(path.getFileName().toString() + fileExtension)); + } else { + throw new RuntimeException("Given Markup language '"+markupLanguage+"' is not supported by "+getClass().getName()); + } + } + + private boolean isMarkupLanguageSupported(MarkupLanguage markupLanguage) { + return markupLanguage == MarkupLanguage.ASCIIDOC; + } + + private void writeToFileWithoutExtension(Document document, Path file) { + if (file.getParent() != null) { + try { + Files.createDirectories(file.getParent()); + } catch (IOException e) { + throw new RuntimeException("Failed create directory", e); + } + } + try (BufferedWriter writer = Files.newBufferedWriter(file, StandardCharsets.UTF_8)) { + writer.write(document.convert()); + } catch (IOException e) { + throw new RuntimeException("Failed to write file", e); + } + if (logger.isInfoEnabled()) { + logger.info("Markup document written to: {}", file); + } + } + + public static class OpenAPIContext extends Context { + private OpenAPI2MarkupConfigBuilder.OpenSchema2MarkupConfig config; + private OpenAPI2MarkupExtensionRegistry extensionRegistry; + + public OpenAPIContext(OpenAPI2MarkupConfigBuilder.OpenSchema2MarkupConfig config, + OpenAPI2MarkupExtensionRegistry extensionRegistry, + OpenAPI schema, URI swaggerLocation, Labels labels) { + super(config, extensionRegistry, schema, swaggerLocation, labels); + this.config = config; + this.extensionRegistry = extensionRegistry; + } + + @Override + public OpenAPI2MarkupConfigBuilder.OpenSchema2MarkupConfig getConfig() { + return config; + } + + @Override + public OpenAPI2MarkupExtensionRegistry getExtensionRegistry() { + return extensionRegistry; + } + + public Document createDocument() { + return new DocumentImpl(); + } + } + + public static class Builder { + private final OpenAPI openAPI; + private final URI schemaLocation; + private OpenAPI2MarkupConfigBuilder.OpenSchema2MarkupConfig config; + private OpenAPI2MarkupExtensionRegistry extensionRegistry; + + /** + * Creates a Builder from a remote URL. + * + * @param schemaUrl the remote URL + */ + Builder(URL schemaUrl) { + try { + this.schemaLocation = schemaUrl.toURI(); + } catch (URISyntaxException e) { + throw new IllegalArgumentException("swaggerURL is in a wrong format", e); + } + this.openAPI = readSchema(schemaUrl.toString()); + } + + /** + * Creates a Builder from a local Path. + * + * @param swaggerPath the local Path + */ + Builder(Path swaggerPath) { + this.schemaLocation = swaggerPath.toAbsolutePath().toUri(); + this.openAPI = readSchema(swaggerPath.toString()); + } + + /** + * Creates a Builder using a given Swagger model. + * + * @param openAPI the Swagger source. + */ + Builder(OpenAPI openAPI) { + this.openAPI = openAPI; + this.schemaLocation = null; + } + + /** + * Uses the SwaggerParser to read the Swagger source. + * + * @param schemaLocation the location of the Swagger source + * @return the Swagger model + */ + private OpenAPI readSchema(String schemaLocation) { + OpenAPI openAPI = new OpenAPIV3Parser().read(schemaLocation); + if (openAPI == null) { + throw new IllegalArgumentException("Failed to read the schema"); + } + return openAPI; + } + + public Builder withConfig(OpenAPI2MarkupConfigBuilder.OpenSchema2MarkupConfig config) { + Validate.notNull(config, "config must not be null"); + this.config = config; + return this; + } + + public Builder withExtensionRegistry(OpenAPI2MarkupExtensionRegistry registry) { + Validate.notNull(registry, "registry must not be null"); + this.extensionRegistry = registry; + return this; + } + + public OpenAPI2MarkupConverter build() { + if (config == null) + config = new OpenAPI2MarkupConfigBuilder().build(); + + if (extensionRegistry == null) + extensionRegistry = new OpenAPI2MarkupExtensionRegistryBuilder().build(); + OpenAPILabels openApiLabels = new OpenAPILabels(config); + OpenAPIContext context = new OpenAPIContext(config, extensionRegistry, openAPI, schemaLocation, openApiLabels); + + initExtensions(context); + + applySwaggerExtensions(context); + + return new OpenAPI2MarkupConverter(context); + } + + private void initExtensions(OpenAPIContext context) { + extensionRegistry.getSwaggerModelExtensions().forEach(extension -> extension.setGlobalContext(context)); + extensionRegistry.getOverviewDocumentExtensions().forEach(extension -> extension.setGlobalContext(context)); + extensionRegistry.getDefinitionsDocumentExtensions().forEach(extension -> extension.setGlobalContext(context)); + extensionRegistry.getPathsDocumentExtensions().forEach(extension -> extension.setGlobalContext(context)); + extensionRegistry.getSecurityDocumentExtensions().forEach(extension -> extension.setGlobalContext(context)); + } + + private void applySwaggerExtensions(OpenAPIContext context) { + extensionRegistry.getSwaggerModelExtensions().forEach(extension -> extension.apply(context.getSchema())); + } + } +} diff --git a/openapi2markup/src/main/java/io/github/swagger2markup/OpenAPI2MarkupProperties.java b/openapi2markup/src/main/java/io/github/swagger2markup/OpenAPI2MarkupProperties.java new file mode 100644 index 00000000..8c54ac7d --- /dev/null +++ b/openapi2markup/src/main/java/io/github/swagger2markup/OpenAPI2MarkupProperties.java @@ -0,0 +1,36 @@ +/* + * Copyright 2017 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; + +import org.apache.commons.configuration2.Configuration; + +import java.util.Map; +import java.util.Properties; + +public class OpenAPI2MarkupProperties extends Schema2MarkupProperties { + + public OpenAPI2MarkupProperties(Properties properties) { + super(properties); + } + + public OpenAPI2MarkupProperties(Map map) { + super(map); + } + + public OpenAPI2MarkupProperties(Configuration configuration) { + super(configuration); + } +} diff --git a/openapi2markup/src/main/java/io/github/swagger2markup/config/OpenAPILabels.java b/openapi2markup/src/main/java/io/github/swagger2markup/config/OpenAPILabels.java new file mode 100644 index 00000000..304b1d56 --- /dev/null +++ b/openapi2markup/src/main/java/io/github/swagger2markup/config/OpenAPILabels.java @@ -0,0 +1,71 @@ +package io.github.swagger2markup.config; + +import io.github.swagger2markup.config.builder.OpenAPI2MarkupConfigBuilder; + +import java.util.ResourceBundle; + +public class OpenAPILabels extends Labels { + + public static final String LABEL_CONTENT = "label_content"; + public static final String LABEL_DEFAULT = "label_default"; + public static final String LABEL_DEPRECATED = "label_deprecated"; + public static final String LABEL_EXAMPLE = "label_example"; + public static final String LABEL_EXAMPLES = "label_examples"; + public static final String LABEL_EXCLUSIVE_MAXIMUM = "label_exclusive_maximum"; + public static final String LABEL_EXCLUSIVE_MINIMUM = "label_exclusive_minimum"; + public static final String LABEL_EXTERNAL_VALUE = "label_external_value"; + public static final String LABEL_FORMAT = "label_format"; + public static final String LABEL_MAXIMUM = "label_maximum"; + public static final String LABEL_MAX_ITEMS = "label_max_items"; + public static final String LABEL_MAX_LENGTH = "label_max_length"; + public static final String LABEL_MAX_PROPERTIES = "label_max_properties"; + public static final String LABEL_MINIMUM = "label_minimum"; + public static final String LABEL_MIN_ITEMS = "label_min_items"; + public static final String LABEL_MIN_LENGTH = "label_min_length"; + public static final String LABEL_MIN_PROPERTIES = "label_min_properties"; + public static final String LABEL_MULTIPLE_OF = "label_multiple_of"; + public static final String LABEL_NO_LINKS = "label_no_links"; + public static final String LABEL_NULLABLE = "label_nullable"; + public static final String LABEL_OPERATION = "label_operation"; + public static final String LABEL_OPTIONAL = "label_optional"; + public static final String LABEL_PARAMETERS = "label_parameters"; + public static final String LABEL_READ_ONLY = "label_read_only"; + public static final String LABEL_REQUIRED = "label_required"; + public static final String LABEL_SERVER = "label_server"; + public static final String LABEL_TERMS_OF_SERVICE = "label_terms_of_service"; + public static final String LABEL_TITLE = "label_title"; + public static final String LABEL_TYPE = "label_type"; + public static final String LABEL_UNIQUE_ITEMS = "label_unique_items"; + public static final String LABEL_WRITE_ONLY = "label_write_only"; + public static final String SECTION_TITLE_COMPONENTS = "section_title_components"; + public static final String SECTION_TITLE_PARAMETERS = "section_title_parameters"; + public static final String SECTION_TITLE_PATHS = "section_title_paths"; + public static final String SECTION_TITLE_SCHEMAS = "section_title_schemas"; + public static final String SECTION_TITLE_SECURITY = "section_title_security"; + public static final String SECTION_TITLE_SERVERS = "section_title_servers"; + public static final String SECTION_TITLE_OVERVIEW = "section_title_overview"; + public static final String SECTION_TITLE_TAGS = "section_title_tags"; + public static final String SECTION_TITLE_RESPONSES = "section_title_responses"; + public static final String SECTION_TITLE_HEADERS = "section_title_headers"; + public static final String SECTION_TITLE_LINKS = "section_title_links"; + public static final String TABLE_HEADER_DEFAULT = "table_header_default"; + public static final String TABLE_HEADER_DESCRIPTION = "table_header_description"; + public static final String TABLE_HEADER_HTTP_CODE = "table_header_http_code"; + public static final String TABLE_HEADER_LINKS = "table_header_links"; + public static final String TABLE_HEADER_NAME = "table_header_name"; + public static final String TABLE_HEADER_POSSIBLE_VALUES = "table_header_possible_values"; + public static final String TABLE_HEADER_SCHEMA = "table_header_schema"; + public static final String TABLE_HEADER_SCOPES = "table_header_scopes"; + public static final String TABLE_HEADER_TYPE = "table_header_type"; + public static final String TABLE_HEADER_VARIABLE = "table_header_variable"; + public static final String TABLE_TITLE_HEADERS = "table_title_headers"; + public static final String TABLE_TITLE_PARAMETERS = "table_title_parameters"; + public static final String TABLE_TITLE_PROPERTIES = "table_title_properties"; + public static final String TABLE_TITLE_RESPONSES = "table_title_responses"; + public static final String TABLE_TITLE_SECURITY = "table_title_security"; + public static final String TABLE_TITLE_SERVER_VARIABLES = "table_title_server_variables"; + + public OpenAPILabels(OpenAPI2MarkupConfigBuilder.OpenSchema2MarkupConfig config) { + super(ResourceBundle.getBundle("io/github/swagger2markup/lang/labels", config.getLanguage().toLocale())); + } +} diff --git a/openapi2markup/src/main/java/io/github/swagger2markup/config/builder/OpenAPI2MarkupConfigBuilder.java b/openapi2markup/src/main/java/io/github/swagger2markup/config/builder/OpenAPI2MarkupConfigBuilder.java new file mode 100644 index 00000000..7d099caf --- /dev/null +++ b/openapi2markup/src/main/java/io/github/swagger2markup/config/builder/OpenAPI2MarkupConfigBuilder.java @@ -0,0 +1,48 @@ +package io.github.swagger2markup.config.builder; + +import io.github.swagger2markup.OpenAPI2MarkupProperties; +import org.apache.commons.configuration2.Configuration; +import org.apache.commons.configuration2.ConfigurationConverter; +import org.apache.commons.configuration2.MapConfiguration; +import org.apache.commons.configuration2.PropertiesConfiguration; + +import java.util.Map; +import java.util.Properties; + +public class OpenAPI2MarkupConfigBuilder extends Schema2MarkupConfigBuilder { + private OpenSchema2MarkupConfig openApi2MarkupConfig; + + public OpenAPI2MarkupConfigBuilder() { + this(new PropertiesConfiguration()); + } + + public OpenAPI2MarkupConfigBuilder(Properties properties) { + this(ConfigurationConverter.getConfiguration(properties)); + } + + public OpenAPI2MarkupConfigBuilder(Map map) { + this(new MapConfiguration(map)); + } + + private OpenAPI2MarkupConfigBuilder(Configuration configuration) { + super(new OpenAPI2MarkupProperties(getCompositeConfiguration(configuration)), configuration); + } + + @Override + public DefaultSchema2MarkupConfig createConfigInstance() { + if(openApi2MarkupConfig == null) { + openApi2MarkupConfig = new OpenSchema2MarkupConfig(); + } + return openApi2MarkupConfig; + } + + @Override + public OpenSchema2MarkupConfig build() { + buildNaturalOrdering(); + return openApi2MarkupConfig; + } + + public static class OpenSchema2MarkupConfig extends DefaultSchema2MarkupConfig { + + } +} diff --git a/openapi2markup/src/main/java/io/github/swagger2markup/extension/AbstractExtension.java b/openapi2markup/src/main/java/io/github/swagger2markup/extension/AbstractExtension.java new file mode 100644 index 00000000..e4c546ba --- /dev/null +++ b/openapi2markup/src/main/java/io/github/swagger2markup/extension/AbstractExtension.java @@ -0,0 +1,36 @@ +/* + * Copyright 2017 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.extension; + +import io.github.swagger2markup.OpenAPI2MarkupConverter.OpenAPIContext; + +/** + * An abstract OpenAPI extension which must be extended by an other OpenAPI extensions + */ +abstract class AbstractExtension implements Extension { + + protected OpenAPIContext globalContext; + + /** + * Global context lazy initialization + * + * @param globalContext Global context + */ + public void setGlobalContext(OpenAPIContext globalContext) { + this.globalContext = globalContext; + } +} diff --git a/openapi2markup/src/main/java/io/github/swagger2markup/extension/ContentContext.java b/openapi2markup/src/main/java/io/github/swagger2markup/extension/ContentContext.java new file mode 100644 index 00000000..1ae8a2aa --- /dev/null +++ b/openapi2markup/src/main/java/io/github/swagger2markup/extension/ContentContext.java @@ -0,0 +1,15 @@ +package io.github.swagger2markup.extension; + +import org.asciidoctor.ast.Document; + +public class ContentContext { + private Document document; + + public ContentContext(Document document) { + this.document = document; + } + + public Document getDocument() { + return document; + } +} diff --git a/openapi2markup/src/main/java/io/github/swagger2markup/extension/DefinitionsDocumentExtension.java b/openapi2markup/src/main/java/io/github/swagger2markup/extension/DefinitionsDocumentExtension.java new file mode 100644 index 00000000..ecf4affe --- /dev/null +++ b/openapi2markup/src/main/java/io/github/swagger2markup/extension/DefinitionsDocumentExtension.java @@ -0,0 +1,92 @@ +/* + * Copyright 2017 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.extension; + +import io.swagger.models.Model; +import org.apache.commons.lang3.Validate; +import org.asciidoctor.ast.Document; + +import java.util.Optional; + +/** + * DefinitionsDocumentExtension extension point can be used to extend the definitions document content. + */ +public abstract class DefinitionsDocumentExtension extends AbstractExtension { + + + public abstract void apply(Context context); + + public enum Position { + DOCUMENT_BEFORE, + DOCUMENT_BEGIN, + DOCUMENT_END, + DOCUMENT_AFTER, + DEFINITION_BEFORE, + DEFINITION_BEGIN, + DEFINITION_END, + DEFINITION_AFTER + } + + public static class Context extends ContentContext { + private Position position; + /** + * null if position == DOCUMENT_* + */ + private String definitionName; + + /** + * null if position == DOCUMENT_* + */ + private Model model; + + /** + * @param position the current position + */ + public Context(Position position, Document document) { + super(document); + Validate.inclusiveBetween(Position.DOCUMENT_BEFORE, Position.DOCUMENT_AFTER, position); + this.position = position; + } + + /** + * @param position the current position + * @param definitionName the name of the current definition + * @param model the current Model of the definition + */ + public Context(Position position, Document document, String definitionName, Model model) { + super(document); + Validate.inclusiveBetween(Position.DEFINITION_BEFORE, Position.DEFINITION_AFTER, position); + Validate.notNull(definitionName); + Validate.notNull(model); + this.position = position; + this.definitionName = definitionName; + this.model = model; + } + + public Position getPosition() { + return position; + } + + public Optional getDefinitionName() { + return Optional.ofNullable(definitionName); + } + + public Optional getModel() { + return Optional.ofNullable(model); + } + } +} diff --git a/openapi2markup/src/main/java/io/github/swagger2markup/extension/Extension.java b/openapi2markup/src/main/java/io/github/swagger2markup/extension/Extension.java new file mode 100644 index 00000000..c5f3ffca --- /dev/null +++ b/openapi2markup/src/main/java/io/github/swagger2markup/extension/Extension.java @@ -0,0 +1,33 @@ +/* + * Copyright 2017 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.extension; + +import static io.github.swagger2markup.OpenAPI2MarkupConverter.OpenAPIContext; + +/** + * Extension interface which must be implemented by an OpenAPI extension + */ +interface Extension { + + /** + * Global context lazy initialization + * + * @param globalContext Global context + */ + void setGlobalContext(OpenAPIContext globalContext); + +} diff --git a/openapi2markup/src/main/java/io/github/swagger2markup/extension/MarkupComponent.java b/openapi2markup/src/main/java/io/github/swagger2markup/extension/MarkupComponent.java new file mode 100644 index 00000000..05d4a672 --- /dev/null +++ b/openapi2markup/src/main/java/io/github/swagger2markup/extension/MarkupComponent.java @@ -0,0 +1,41 @@ +/* + * Copyright 2017 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.extension; + +import io.github.swagger2markup.config.builder.OpenAPI2MarkupConfigBuilder; +import io.github.swagger2markup.OpenAPI2MarkupConverter; +import io.github.swagger2markup.config.Labels; +import io.swagger.v3.oas.models.OpenAPI; +import io.vavr.Function2; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public abstract class MarkupComponent implements Function2 { + + protected Logger logger = LoggerFactory.getLogger(getClass()); + protected OpenAPI2MarkupConverter.Context context; + protected Labels labels; + protected OpenAPI2MarkupConfigBuilder.OpenSchema2MarkupConfig config; + protected OpenAPI2MarkupExtensionRegistry extensionRegistry; + + public MarkupComponent(OpenAPI2MarkupConverter.OpenAPIContext context) { + this.context = context; + this.config = context.getConfig(); + this.extensionRegistry = context.getExtensionRegistry(); + this.labels = context.getLabels(); + } +} diff --git a/openapi2markup/src/main/java/io/github/swagger2markup/extension/OpenAPI2MarkupExtensionRegistry.java b/openapi2markup/src/main/java/io/github/swagger2markup/extension/OpenAPI2MarkupExtensionRegistry.java new file mode 100644 index 00000000..4eec03b1 --- /dev/null +++ b/openapi2markup/src/main/java/io/github/swagger2markup/extension/OpenAPI2MarkupExtensionRegistry.java @@ -0,0 +1,58 @@ +/* + * Copyright 2017 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.extension; + +import java.util.List; + +/** + * Extension points registry interface. + */ +public interface OpenAPI2MarkupExtensionRegistry extends Schema2MarkupExtensionRegistry { + /** + * OpenAPIModelExtension extension point can be used to preprocess the Swagger model. + * + * @return registered extensions extending OpenAPIModelExtension extension point + */ + List getSwaggerModelExtensions(); + + /** + * OverviewDocumentExtension extension point can be used to extend the overview document content. + * + * @return registered extensions extending OverviewDocumentExtension extension point + */ + List getOverviewDocumentExtensions(); + + /** + * DefinitionsDocumentExtension extension point can be used to extend the definitions document content. + * + * @return registered extensions extending DefinitionsDocumentExtension extension point + */ + List getDefinitionsDocumentExtensions(); + + /** + * SecurityContentExtension extension point can be used to extend the security document content. + * + * @return registered extensions extending SecurityContentExtension extension point + */ + List getSecurityDocumentExtensions(); + + /** + * PathsDocumentExtension extension point can be used to extend the paths document content. + * + * @return registered extensions extending PathsDocumentExtension extension point + */ + List getPathsDocumentExtensions(); +} diff --git a/openapi2markup/src/main/java/io/github/swagger2markup/extension/OpenAPIModelExtension.java b/openapi2markup/src/main/java/io/github/swagger2markup/extension/OpenAPIModelExtension.java new file mode 100644 index 00000000..e8ab8dd2 --- /dev/null +++ b/openapi2markup/src/main/java/io/github/swagger2markup/extension/OpenAPIModelExtension.java @@ -0,0 +1,28 @@ +/* + * Copyright 2017 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.extension; + +import io.swagger.v3.oas.models.OpenAPI; + +/** + * OpenAPIModelExtension extension point can be used to preprocess the Swagger model. + */ +public abstract class OpenAPIModelExtension extends AbstractExtension { + + public abstract void apply(OpenAPI openAPI); + +} diff --git a/openapi2markup/src/main/java/io/github/swagger2markup/extension/OverviewDocumentExtension.java b/openapi2markup/src/main/java/io/github/swagger2markup/extension/OverviewDocumentExtension.java new file mode 100644 index 00000000..79fd6229 --- /dev/null +++ b/openapi2markup/src/main/java/io/github/swagger2markup/extension/OverviewDocumentExtension.java @@ -0,0 +1,51 @@ +/* + * Copyright 2017 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.extension; + +import org.asciidoctor.ast.Document; + +/** + * OverviewDocumentExtension extension point can be used to extend the overview document content. + */ +public abstract class OverviewDocumentExtension extends AbstractExtension { + + public abstract void apply(Context context); + + public enum Position { + DOCUMENT_BEFORE, + DOCUMENT_AFTER, + DOCUMENT_BEGIN, + DOCUMENT_END + } + + public static class Context extends ContentContext { + private Position position; + + /** + * @param position the current position + */ + public Context(Position position, Document document) { + super(document); + this.position = position; + } + + public Position getPosition() { + return position; + } + } + +} diff --git a/openapi2markup/src/main/java/io/github/swagger2markup/extension/PathsDocumentExtension.java b/openapi2markup/src/main/java/io/github/swagger2markup/extension/PathsDocumentExtension.java new file mode 100644 index 00000000..e148ae5e --- /dev/null +++ b/openapi2markup/src/main/java/io/github/swagger2markup/extension/PathsDocumentExtension.java @@ -0,0 +1,101 @@ +/* + * Copyright 2017 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.extension; + +import io.github.swagger2markup.model.PathOperation; +import org.apache.commons.lang3.Validate; +import org.asciidoctor.ast.Document; + +import java.util.Optional; + +/** + * PathsDocumentExtension extension point can be used to extend the paths document content. + */ +public abstract class PathsDocumentExtension extends AbstractExtension { + + public abstract void apply(Context context); + + public enum Position { + DOCUMENT_BEFORE, + DOCUMENT_BEGIN, + DOCUMENT_END, + DOCUMENT_AFTER, + OPERATION_BEFORE, + OPERATION_BEGIN, + OPERATION_END, + OPERATION_AFTER, + OPERATION_DESCRIPTION_BEFORE, + OPERATION_DESCRIPTION_BEGIN, + OPERATION_DESCRIPTION_END, + OPERATION_DESCRIPTION_AFTER, + OPERATION_PARAMETERS_BEFORE, + OPERATION_PARAMETERS_BEGIN, + OPERATION_PARAMETERS_END, + OPERATION_PARAMETERS_AFTER, + OPERATION_RESPONSES_BEFORE, + OPERATION_RESPONSES_BEGIN, + OPERATION_RESPONSES_END, + OPERATION_RESPONSES_AFTER, + OPERATION_SECURITY_BEFORE, + OPERATION_SECURITY_BEGIN, + OPERATION_SECURITY_END, + OPERATION_SECURITY_AFTER + } + + public static class Context extends ContentContext { + private Position position; + /** + * null if position == DOCUMENT_* + */ + private PathOperation operation; + + /** + * Context for positions DOCUMENT_* + * + * @param position the current position + * @param document document object + */ + public Context(Position position, Document document) { + super(document); + Validate.inclusiveBetween(Position.DOCUMENT_BEFORE, Position.DOCUMENT_AFTER, position); + this.position = position; + } + + /** + * Context for all other positions + * + * @param position the current position + * @param document document object + * @param operation the current path operation + */ + public Context(Position position, Document document, PathOperation operation) { + super(document); + Validate.inclusiveBetween(Position.OPERATION_BEFORE, Position.OPERATION_SECURITY_AFTER, position); + Validate.notNull(operation); + this.position = position; + this.operation = operation; + } + + public Position getPosition() { + return position; + } + + public Optional getOperation() { + return Optional.ofNullable(operation); + } + } +} diff --git a/openapi2markup/src/main/java/io/github/swagger2markup/extension/SecurityDocumentExtension.java b/openapi2markup/src/main/java/io/github/swagger2markup/extension/SecurityDocumentExtension.java new file mode 100644 index 00000000..9d4e64c8 --- /dev/null +++ b/openapi2markup/src/main/java/io/github/swagger2markup/extension/SecurityDocumentExtension.java @@ -0,0 +1,94 @@ +/* + * Copyright 2017 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.extension; + +import io.swagger.models.auth.SecuritySchemeDefinition; +import org.apache.commons.lang3.Validate; +import org.asciidoctor.ast.Document; + +import java.util.Optional; + +/** + * SecurityContentExtension extension point can be used to extend the security document content. + */ +public abstract class SecurityDocumentExtension extends AbstractExtension { + + + public abstract void apply(Context context); + + public enum Position { + DOCUMENT_BEFORE, + DOCUMENT_BEGIN, + DOCUMENT_END, + DOCUMENT_AFTER, + SECURITY_SCHEME_BEFORE, + SECURITY_SCHEME_BEGIN, + SECURITY_SCHEME_END, + SECURITY_SCHEME_AFTER + } + + public static class Context extends ContentContext { + private Position position; + /** + * null if position == DOCUMENT_* + */ + private String securitySchemeName; + /** + * null if position == DOCUMENT_* + */ + private SecuritySchemeDefinition securityScheme; + + /** + * @param position the current position + * @param document the MarkupDocBuilder + */ + public Context(Position position, Document document) { + super(document); + Validate.inclusiveBetween(Position.DOCUMENT_BEFORE, Position.DOCUMENT_AFTER, position); + this.position = position; + } + + /** + * @param position the current position + * @param document the MarkupDocBuilder + * @param securitySchemeName the name of the current securityScheme + * @param securityScheme the current security scheme securityScheme + */ + public Context(Position position, Document document, String securitySchemeName, SecuritySchemeDefinition securityScheme) { + super(document); + Validate.inclusiveBetween(Position.SECURITY_SCHEME_BEFORE, Position.SECURITY_SCHEME_AFTER, position); + Validate.notNull(securitySchemeName); + Validate.notNull(securityScheme); + this.position = position; + this.securitySchemeName = securitySchemeName; + this.securityScheme = securityScheme; + } + + public Position getPosition() { + return position; + } + + public Optional getSecuritySchemeName() { + return Optional.ofNullable(securitySchemeName); + } + + public Optional getSecurityScheme() { + return Optional.ofNullable(securityScheme); + } + } + +} diff --git a/openapi2markup/src/main/java/io/github/swagger2markup/extension/builder/OpenAPI2MarkupExtensionRegistryBuilder.java b/openapi2markup/src/main/java/io/github/swagger2markup/extension/builder/OpenAPI2MarkupExtensionRegistryBuilder.java new file mode 100644 index 00000000..7a326774 --- /dev/null +++ b/openapi2markup/src/main/java/io/github/swagger2markup/extension/builder/OpenAPI2MarkupExtensionRegistryBuilder.java @@ -0,0 +1,127 @@ +/* + * Copyright 2017 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.extension.builder; + +import io.github.swagger2markup.extension.*; + +import java.util.List; + +import static java.util.ServiceLoader.load; +import static org.apache.commons.collections4.IteratorUtils.toList; + +public class OpenAPI2MarkupExtensionRegistryBuilder { + + private final Context context; + + public OpenAPI2MarkupExtensionRegistryBuilder() { + List openAPIModelExtensions = toList(load(OpenAPIModelExtension.class).iterator()); + List overviewDocumentExtensions = toList(load(OverviewDocumentExtension.class).iterator()); + List definitionsDocumentExtensions = toList(load(DefinitionsDocumentExtension.class).iterator()); + List pathsDocumentExtensions = toList(load(PathsDocumentExtension.class).iterator()); + List securityDocumentExtensions = toList(load(SecurityDocumentExtension.class).iterator()); + context = new Context( + openAPIModelExtensions, + overviewDocumentExtensions, + definitionsDocumentExtensions, + pathsDocumentExtensions, + securityDocumentExtensions); + } + + public OpenAPI2MarkupExtensionRegistry build() { + return new DefaultOpenAPI2MarkupExtensionRegistry(context); + } + + public OpenAPI2MarkupExtensionRegistryBuilder withSwaggerModelExtension(OpenAPIModelExtension extension) { + context.openAPIModelExtensions.add(extension); + return this; + } + + public OpenAPI2MarkupExtensionRegistryBuilder withOverviewDocumentExtension(OverviewDocumentExtension extension) { + context.overviewDocumentExtensions.add(extension); + return this; + } + + public OpenAPI2MarkupExtensionRegistryBuilder withDefinitionsDocumentExtension(DefinitionsDocumentExtension extension) { + context.definitionsDocumentExtensions.add(extension); + return this; + } + + public OpenAPI2MarkupExtensionRegistryBuilder withPathsDocumentExtension(PathsDocumentExtension extension) { + context.pathsDocumentExtensions.add(extension); + return this; + } + + public OpenAPI2MarkupExtensionRegistryBuilder withSecurityDocumentExtension(SecurityDocumentExtension extension) { + context.securityDocumentExtensions.add(extension); + return this; + } + + static class DefaultOpenAPI2MarkupExtensionRegistry implements OpenAPI2MarkupExtensionRegistry { + + private Context context; + + DefaultOpenAPI2MarkupExtensionRegistry(Context context) { + this.context = context; + } + + @Override + public List getSwaggerModelExtensions() { + return context.openAPIModelExtensions; + } + + @Override + public List getOverviewDocumentExtensions() { + return context.overviewDocumentExtensions; + } + + @Override + public List getDefinitionsDocumentExtensions() { + return context.definitionsDocumentExtensions; + } + + @Override + public List getSecurityDocumentExtensions() { + return context.securityDocumentExtensions; + } + + @Override + public List getPathsDocumentExtensions() { + return context.pathsDocumentExtensions; + } + + } + + private static class Context { + final List openAPIModelExtensions; + final List overviewDocumentExtensions; + final List definitionsDocumentExtensions; + final List pathsDocumentExtensions; + final List securityDocumentExtensions; + + Context(List openAPIModelExtensions, + List overviewDocumentExtensions, + List definitionsDocumentExtensions, + List pathsDocumentExtensions, + List securityDocumentExtensions) { + this.openAPIModelExtensions = openAPIModelExtensions; + this.overviewDocumentExtensions = overviewDocumentExtensions; + this.definitionsDocumentExtensions = definitionsDocumentExtensions; + this.pathsDocumentExtensions = pathsDocumentExtensions; + this.securityDocumentExtensions = securityDocumentExtensions; + } + } +} diff --git a/openapi2markup/src/main/java/io/github/swagger2markup/internal/component/EncodingComponent.java b/openapi2markup/src/main/java/io/github/swagger2markup/internal/component/EncodingComponent.java new file mode 100644 index 00000000..080446c2 --- /dev/null +++ b/openapi2markup/src/main/java/io/github/swagger2markup/internal/component/EncodingComponent.java @@ -0,0 +1,101 @@ +/* + * Copyright 2017 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.component; + +import io.github.swagger2markup.OpenAPI2MarkupConverter; +import io.github.swagger2markup.adoc.ast.impl.DescriptionListEntryImpl; +import io.github.swagger2markup.adoc.ast.impl.DescriptionListImpl; +import io.github.swagger2markup.adoc.ast.impl.ListItemImpl; +import io.github.swagger2markup.adoc.ast.impl.ParagraphBlockImpl; +import io.github.swagger2markup.extension.MarkupComponent; +import io.swagger.v3.oas.models.media.Encoding; +import org.apache.commons.lang3.StringUtils; +import org.asciidoctor.ast.StructuralNode; + +import java.util.Collections; +import java.util.Map; + +import static io.github.swagger2markup.adoc.converter.internal.Delimiters.LINE_SEPARATOR; +import static io.github.swagger2markup.config.OpenAPILabels.LABEL_EXAMPLES; +import static io.github.swagger2markup.internal.helper.OpenApiHelpers.italicUnconstrained; + +public class EncodingComponent extends MarkupComponent { + + private final HeadersComponent headersComponent; + + public EncodingComponent(OpenAPI2MarkupConverter.OpenAPIContext context) { + super(context); + this.headersComponent = new HeadersComponent(context); + } + + public static EncodingComponent.Parameters parameters(Map encodings) { + return new EncodingComponent.Parameters(encodings); + } + + public StructuralNode apply(StructuralNode node, Map encodings) { + return apply(node, parameters(encodings)); + } + + @Override + public StructuralNode apply(StructuralNode node, EncodingComponent.Parameters parameters) { + Map encodings = parameters.encodings; + if (encodings == null || encodings.isEmpty()) return node; + + DescriptionListImpl encodingList = new DescriptionListImpl(node); + encodingList.setTitle(labels.getLabel(LABEL_EXAMPLES)); + + encodings.forEach((name, encoding) -> { + DescriptionListEntryImpl encodingEntry = new DescriptionListEntryImpl(encodingList, Collections.singletonList(new ListItemImpl(encodingList, name))); + ListItemImpl tagDesc = new ListItemImpl(encodingEntry, ""); + ParagraphBlockImpl encodingBlock = new ParagraphBlockImpl(tagDesc); + + StringBuilder sb = new StringBuilder(); + String contentType = encoding.getContentType(); + if(StringUtils.isNotBlank(contentType)){ + sb.append("Content-Type:").append(contentType).append(LINE_SEPARATOR); + } + if(encoding.getAllowReserved()){ + sb.append(italicUnconstrained("Allow Reserved").toLowerCase()).append(LINE_SEPARATOR); + } + if(encoding.getExplode()){ + sb.append(italicUnconstrained("Explode").toLowerCase()).append(LINE_SEPARATOR); + } + Encoding.StyleEnum style = encoding.getStyle(); + if(style != null){ + sb.append("style").append(style).append(LINE_SEPARATOR); + } + encodingBlock.setSource(sb.toString()); + tagDesc.append(encodingBlock); + headersComponent.apply(tagDesc, encoding.getHeaders()); + + encodingEntry.setDescription(tagDesc); + + encodingList.addEntry(encodingEntry); + }); + node.append(encodingList); + + return node; + } + + public static class Parameters { + + private final Map encodings; + + public Parameters(Map encodings) { + this.encodings = encodings; + } + } +} diff --git a/openapi2markup/src/main/java/io/github/swagger2markup/internal/component/ExamplesComponent.java b/openapi2markup/src/main/java/io/github/swagger2markup/internal/component/ExamplesComponent.java new file mode 100644 index 00000000..4f73a07d --- /dev/null +++ b/openapi2markup/src/main/java/io/github/swagger2markup/internal/component/ExamplesComponent.java @@ -0,0 +1,108 @@ +/* + * Copyright 2017 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.component; + +import io.github.swagger2markup.OpenAPI2MarkupConverter; +import io.github.swagger2markup.adoc.ast.impl.DescriptionListEntryImpl; +import io.github.swagger2markup.adoc.ast.impl.DescriptionListImpl; +import io.github.swagger2markup.adoc.ast.impl.ListItemImpl; +import io.github.swagger2markup.adoc.ast.impl.ParagraphBlockImpl; +import io.github.swagger2markup.extension.MarkupComponent; +import io.swagger.v3.oas.models.examples.Example; +import org.apache.commons.lang3.StringUtils; +import org.asciidoctor.ast.StructuralNode; + +import java.util.Collections; +import java.util.Map; + +import static io.github.swagger2markup.adoc.converter.internal.Delimiters.LINE_SEPARATOR; +import static io.github.swagger2markup.config.OpenAPILabels.LABEL_EXAMPLES; +import static io.github.swagger2markup.config.OpenAPILabels.LABEL_EXTERNAL_VALUE; +import static io.github.swagger2markup.internal.helper.OpenApiHelpers.appendDescription; + +public class ExamplesComponent extends MarkupComponent { + + private final MediaTypeExampleComponent mediaTypeExampleComponent; + + public ExamplesComponent(OpenAPI2MarkupConverter.OpenAPIContext context) { + super(context); + this.mediaTypeExampleComponent = new MediaTypeExampleComponent(context); + } + + public static ExamplesComponent.Parameters parameters(Map examples) { + return new ExamplesComponent.Parameters(examples); + } + + public StructuralNode apply(StructuralNode node, Map examples) { + return apply(node, parameters(examples)); + } + + @Override + public StructuralNode apply(StructuralNode node, ExamplesComponent.Parameters parameters) { + Map examples = parameters.examples; + if (examples == null || examples.isEmpty()) return node; + + DescriptionListImpl examplesList = new DescriptionListImpl(node); + examplesList.setTitle(labels.getLabel(LABEL_EXAMPLES)); + + examples.forEach((name, example) -> { + DescriptionListEntryImpl exampleEntry = new DescriptionListEntryImpl(examplesList, Collections.singletonList(new ListItemImpl(examplesList, name))); + ListItemImpl tagDesc = new ListItemImpl(exampleEntry, ""); + + ParagraphBlockImpl exampleBlock = new ParagraphBlockImpl(tagDesc); + + appendDescription(exampleBlock, example.getSummary()); + appendDescription(exampleBlock, example.getDescription()); + mediaTypeExampleComponent.apply(tagDesc, example.getValue()); + + ParagraphBlockImpl paragraphBlock = new ParagraphBlockImpl(tagDesc); + String source = ""; + generateRefLink(source, example.getExternalValue(), labels.getLabel(LABEL_EXTERNAL_VALUE)); + generateRefLink(source, example.get$ref(), ""); + if(StringUtils.isNotBlank(source)){ + paragraphBlock.setSource(source); + tagDesc.append(paragraphBlock); + } + + exampleEntry.setDescription(tagDesc); + + examplesList.addEntry(exampleEntry); + }); + node.append(examplesList); + + return node; + } + + private String generateRefLink(String source, String ref, String alt) { + if (StringUtils.isNotBlank(ref)) { + if (StringUtils.isBlank(alt)) { + alt = ref.substring(ref.lastIndexOf('/') + 1); + } + String anchor = ref.replaceFirst("#", "").replaceAll("/", "_"); + source += "<<" + anchor + "," + alt + ">>" + LINE_SEPARATOR; + } + return source; + } + + public static class Parameters { + + private final Map examples; + + public Parameters(Map examples) { + this.examples = examples; + } + } +} diff --git a/openapi2markup/src/main/java/io/github/swagger2markup/internal/component/ExternalDocumentationComponent.java b/openapi2markup/src/main/java/io/github/swagger2markup/internal/component/ExternalDocumentationComponent.java new file mode 100644 index 00000000..e3c81652 --- /dev/null +++ b/openapi2markup/src/main/java/io/github/swagger2markup/internal/component/ExternalDocumentationComponent.java @@ -0,0 +1,64 @@ +/* + * Copyright 2017 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.component; + +import io.github.swagger2markup.OpenAPI2MarkupConverter; +import io.github.swagger2markup.extension.MarkupComponent; +import io.github.swagger2markup.adoc.ast.impl.ParagraphBlockImpl; +import io.swagger.v3.oas.models.ExternalDocumentation; +import org.apache.commons.lang3.StringUtils; +import org.asciidoctor.ast.Block; +import org.asciidoctor.ast.StructuralNode; + + +public class ExternalDocumentationComponent extends MarkupComponent { + + public ExternalDocumentationComponent(OpenAPI2MarkupConverter.OpenAPIContext context) { + super(context); + } + + public static Parameters parameters(ExternalDocumentation externalDocs) { + return new Parameters(externalDocs); + } + + public StructuralNode apply(StructuralNode node, ExternalDocumentation externalDocs) { + return apply(node, parameters(externalDocs)); + } + + @Override + public StructuralNode apply(StructuralNode node, Parameters params) { + ExternalDocumentation externalDocs = params.externalDocs; + if (externalDocs == null) return node; + + String url = externalDocs.getUrl(); + if (StringUtils.isNotBlank(url)) { + Block paragraph = new ParagraphBlockImpl(node); + String desc = externalDocs.getDescription(); + paragraph.setSource(url + (StringUtils.isNotBlank(desc) ? "[" + desc + "]" : "")); + node.append(paragraph); + } + + return node; + } + + public static class Parameters { + private final ExternalDocumentation externalDocs; + + public Parameters(ExternalDocumentation externalDocs) { + this.externalDocs = externalDocs; + } + } +} diff --git a/openapi2markup/src/main/java/io/github/swagger2markup/internal/component/HeadersComponent.java b/openapi2markup/src/main/java/io/github/swagger2markup/internal/component/HeadersComponent.java new file mode 100644 index 00000000..caca6001 --- /dev/null +++ b/openapi2markup/src/main/java/io/github/swagger2markup/internal/component/HeadersComponent.java @@ -0,0 +1,79 @@ +/* + * Copyright 2017 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.component; + +import io.github.swagger2markup.OpenAPI2MarkupConverter; +import io.github.swagger2markup.adoc.ast.impl.TableImpl; +import io.github.swagger2markup.extension.MarkupComponent; +import io.swagger.v3.oas.models.headers.Header; +import org.asciidoctor.ast.StructuralNode; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; + +import static io.github.swagger2markup.config.OpenAPILabels.*; +import static io.github.swagger2markup.internal.helper.OpenApiHelpers.generateInnerDoc; +import static io.github.swagger2markup.internal.helper.OpenApiHelpers.getSchemaTypeAsString; + +public class HeadersComponent extends MarkupComponent { + + private final SchemaComponent schemaComponent; + + public HeadersComponent(OpenAPI2MarkupConverter.OpenAPIContext context) { + super(context); + this.schemaComponent = new SchemaComponent(context); + } + + public static HeadersComponent.Parameters parameters(Map headers) { + return new HeadersComponent.Parameters(headers); + } + + public StructuralNode apply(StructuralNode node, Map headers) { + return apply(node, parameters(headers)); + } + + @Override + public StructuralNode apply(StructuralNode node, HeadersComponent.Parameters parameters) { + Map headers = parameters.headers; + if (null == headers || headers.isEmpty()) return node; + + TableImpl responseHeadersTable = new TableImpl(node, new HashMap<>(), new ArrayList<>()); + responseHeadersTable.setOption("header"); + responseHeadersTable.setAttribute("caption", "", true); + responseHeadersTable.setAttribute("cols", ".^2a,.^14a,.^4a", true); + responseHeadersTable.setTitle(labels.getLabel(TABLE_TITLE_HEADERS)); + responseHeadersTable.setHeaderRow(labels.getLabel(TABLE_HEADER_NAME), labels.getLabel(TABLE_HEADER_DESCRIPTION), labels.getLabel(TABLE_HEADER_SCHEMA)); + headers.forEach((name, header) -> + responseHeadersTable.addRow( + generateInnerDoc(responseHeadersTable, name), + generateInnerDoc(responseHeadersTable, Optional.ofNullable(header.getDescription()).orElse("")), + generateInnerDoc(responseHeadersTable, getSchemaTypeAsString(header.getSchema())) + )); + node.append(responseHeadersTable); + return node; + } + + public static class Parameters { + + private final Map headers; + + public Parameters(Map headers) { + this.headers = headers; + } + } +} diff --git a/openapi2markup/src/main/java/io/github/swagger2markup/internal/component/LinkComponent.java b/openapi2markup/src/main/java/io/github/swagger2markup/internal/component/LinkComponent.java new file mode 100644 index 00000000..ee11af09 --- /dev/null +++ b/openapi2markup/src/main/java/io/github/swagger2markup/internal/component/LinkComponent.java @@ -0,0 +1,82 @@ +/* + * Copyright 2017 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.component; + +import io.github.swagger2markup.OpenAPI2MarkupConverter; +import io.github.swagger2markup.adoc.ast.impl.DocumentImpl; +import io.github.swagger2markup.adoc.ast.impl.ParagraphBlockImpl; +import io.github.swagger2markup.extension.MarkupComponent; +import io.swagger.v3.oas.models.links.Link; +import org.asciidoctor.ast.Document; +import org.asciidoctor.ast.StructuralNode; + +import java.util.Map; + +import static io.github.swagger2markup.adoc.converter.internal.Delimiters.LINE_SEPARATOR; +import static io.github.swagger2markup.config.OpenAPILabels.*; +import static io.github.swagger2markup.internal.helper.OpenApiHelpers.italicUnconstrained; + +public class LinkComponent extends MarkupComponent { + + public LinkComponent(OpenAPI2MarkupConverter.OpenAPIContext context) { + super(context); + } + + public static LinkComponent.Parameters parameters(Map links) { + return new LinkComponent.Parameters(links); + } + + public Document apply(StructuralNode parent, Map links) { + return apply(parent, parameters(links)); + } + + @Override + public Document apply(StructuralNode parent, LinkComponent.Parameters parameters) { + DocumentImpl linksDocument = new DocumentImpl(parent); + ParagraphBlockImpl linkParagraph = new ParagraphBlockImpl(linksDocument); + + Map links = parameters.links; + if (null == links || links.isEmpty()) { + linkParagraph.setSource(labels.getLabel(LABEL_NO_LINKS)); + } else { + StringBuilder sb = new StringBuilder(); + links.forEach((name, link) -> { + sb.append(name).append(" +").append(LINE_SEPARATOR); + sb.append(italicUnconstrained(labels.getLabel(LABEL_OPERATION))).append(' ') + .append(italicUnconstrained(link.getOperationId())).append(" +").append(LINE_SEPARATOR); + Map linkParameters = link.getParameters(); + if (null != linkParameters && !linkParameters.isEmpty()) { + sb.append(italicUnconstrained(labels.getLabel(LABEL_PARAMETERS))).append(" {").append(" +").append(LINE_SEPARATOR); + linkParameters.forEach((param, value) -> + sb.append('"').append(param).append("\": \"").append(value).append('"').append(" +").append(LINE_SEPARATOR) + ); + sb.append('}').append(" +").append(LINE_SEPARATOR); + } + }); + linkParagraph.setSource(sb.toString()); + } + linksDocument.append(linkParagraph); + return linksDocument; + } + + public static class Parameters { + private final Map links; + + public Parameters(Map links) { + this.links = links; + } + } +} diff --git a/openapi2markup/src/main/java/io/github/swagger2markup/internal/component/MediaContentComponent.java b/openapi2markup/src/main/java/io/github/swagger2markup/internal/component/MediaContentComponent.java new file mode 100644 index 00000000..9c249917 --- /dev/null +++ b/openapi2markup/src/main/java/io/github/swagger2markup/internal/component/MediaContentComponent.java @@ -0,0 +1,87 @@ +/* + * Copyright 2017 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.component; + +import io.github.swagger2markup.OpenAPI2MarkupConverter; +import io.github.swagger2markup.adoc.ast.impl.DescriptionListEntryImpl; +import io.github.swagger2markup.adoc.ast.impl.DescriptionListImpl; +import io.github.swagger2markup.adoc.ast.impl.ListItemImpl; +import io.github.swagger2markup.extension.MarkupComponent; +import io.swagger.v3.oas.models.media.Content; +import org.asciidoctor.ast.Document; +import org.asciidoctor.ast.StructuralNode; + +import java.util.Collections; + +import static io.github.swagger2markup.config.OpenAPILabels.LABEL_CONTENT; + +public class MediaContentComponent extends MarkupComponent { + + private final MediaTypeExampleComponent mediaTypeExampleComponent; + private final ExamplesComponent examplesComponent; + private final SchemaComponent schemaComponent; + private final EncodingComponent encodingComponent; + + public MediaContentComponent(OpenAPI2MarkupConverter.OpenAPIContext context) { + super(context); + this.mediaTypeExampleComponent = new MediaTypeExampleComponent(context); + this.examplesComponent = new ExamplesComponent(context); + this.schemaComponent = new SchemaComponent(context); + this.encodingComponent = new EncodingComponent(context); + } + + public static MediaContentComponent.Parameters parameters(Content content) { + return new MediaContentComponent.Parameters(content); + } + + public StructuralNode apply(StructuralNode node, Content content) { + return apply(node, parameters(content)); + } + + @Override + public StructuralNode apply(StructuralNode node, MediaContentComponent.Parameters parameters) { + Content content = parameters.content; + if (content == null || content.isEmpty()) return node; + + DescriptionListImpl mediaContentList = new DescriptionListImpl(node); + mediaContentList.setTitle(labels.getLabel(LABEL_CONTENT)); + + content.forEach((type, mediaType) -> { + DescriptionListEntryImpl tagEntry = new DescriptionListEntryImpl(mediaContentList, Collections.singletonList(new ListItemImpl(mediaContentList, type))); + ListItemImpl tagDesc = new ListItemImpl(tagEntry, ""); + + Document tagDescDocument = schemaComponent.apply(mediaContentList, mediaType.getSchema()); + mediaTypeExampleComponent.apply(tagDescDocument, mediaType.getExample()); + examplesComponent.apply(tagDescDocument, mediaType.getExamples()); + encodingComponent.apply(tagDescDocument, mediaType.getEncoding()); + tagDesc.append(tagDescDocument); + + tagEntry.setDescription(tagDesc); + mediaContentList.addEntry(tagEntry); + }); + node.append(mediaContentList); + return node; + } + + public static class Parameters { + + private final Content content; + + public Parameters(Content content) { + this.content = content; + } + } +} diff --git a/openapi2markup/src/main/java/io/github/swagger2markup/internal/component/MediaTypeExampleComponent.java b/openapi2markup/src/main/java/io/github/swagger2markup/internal/component/MediaTypeExampleComponent.java new file mode 100644 index 00000000..9ee59652 --- /dev/null +++ b/openapi2markup/src/main/java/io/github/swagger2markup/internal/component/MediaTypeExampleComponent.java @@ -0,0 +1,64 @@ +/* + * Copyright 2017 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.component; + +import io.github.swagger2markup.OpenAPI2MarkupConverter; +import io.github.swagger2markup.adoc.ast.impl.ParagraphBlockImpl; +import io.github.swagger2markup.extension.MarkupComponent; +import org.apache.commons.lang3.StringUtils; +import org.asciidoctor.ast.StructuralNode; + +import static io.github.swagger2markup.adoc.converter.internal.Delimiters.DELIMITER_BLOCK; +import static io.github.swagger2markup.adoc.converter.internal.Delimiters.LINE_SEPARATOR; +import static io.github.swagger2markup.config.OpenAPILabels.LABEL_EXAMPLE; + +public class MediaTypeExampleComponent extends MarkupComponent { + + public MediaTypeExampleComponent(OpenAPI2MarkupConverter.OpenAPIContext context) { + super(context); + } + + public static MediaTypeExampleComponent.Parameters parameters(Object example) { + return new MediaTypeExampleComponent.Parameters(example); + } + + public StructuralNode apply(StructuralNode node, Object example) { + return apply(node, parameters(example)); + } + + @Override + public StructuralNode apply(StructuralNode node, MediaTypeExampleComponent.Parameters parameters) { + Object example = parameters.example; + if (example == null || StringUtils.isBlank(example.toString())) return node; + + ParagraphBlockImpl sourceBlock = new ParagraphBlockImpl(node); + sourceBlock.setTitle(labels.getLabel(LABEL_EXAMPLE)); + sourceBlock.setAttribute("style", "source", true); + sourceBlock.setSource(DELIMITER_BLOCK + LINE_SEPARATOR + example + LINE_SEPARATOR + DELIMITER_BLOCK); + node.append(sourceBlock); + + return node; + } + + public static class Parameters { + + private final Object example; + + public Parameters(Object example) { + this.example = example; + } + } +} diff --git a/openapi2markup/src/main/java/io/github/swagger2markup/internal/component/ParametersComponent.java b/openapi2markup/src/main/java/io/github/swagger2markup/internal/component/ParametersComponent.java new file mode 100644 index 00000000..c4e58b4d --- /dev/null +++ b/openapi2markup/src/main/java/io/github/swagger2markup/internal/component/ParametersComponent.java @@ -0,0 +1,103 @@ +/* + * Copyright 2017 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.component; + +import io.github.swagger2markup.OpenAPI2MarkupConverter; +import io.github.swagger2markup.adoc.ast.impl.TableImpl; +import io.github.swagger2markup.extension.MarkupComponent; +import io.swagger.v3.oas.models.parameters.Parameter; +import org.asciidoctor.ast.Document; +import org.asciidoctor.ast.StructuralNode; +import org.asciidoctor.ast.Table; + +import java.util.*; +import java.util.stream.Collectors; + +import static io.github.swagger2markup.adoc.converter.internal.Delimiters.LINE_SEPARATOR; +import static io.github.swagger2markup.config.OpenAPILabels.*; +import static io.github.swagger2markup.internal.helper.OpenApiHelpers.*; + +public class ParametersComponent extends MarkupComponent { + + private final SchemaComponent schemaComponent; + + public ParametersComponent(OpenAPI2MarkupConverter.OpenAPIContext context) { + super(context); + this.schemaComponent = new SchemaComponent(context); + } + + public static ParametersComponent.Parameters parameters(Map parameters) { + return new ParametersComponent.Parameters(parameters); + } + + public static ParametersComponent.Parameters parameters(List parameters) { + if(null == parameters) { + return new ParametersComponent.Parameters(new HashMap<>()); + } + return new ParametersComponent.Parameters(parameters.stream().collect(Collectors.toMap(Parameter::getName, parameter -> parameter))); + } + + public StructuralNode apply(StructuralNode parent, List params) { + return apply(parent, parameters(params)); + } + + public StructuralNode apply(StructuralNode parent, Map params) { + return apply(parent, parameters(params)); + } + + @Override + public StructuralNode apply(StructuralNode parent, ParametersComponent.Parameters componentParameters) { + Map parameters = componentParameters.parameters; + if (null == parameters || parameters.isEmpty()) return parent; + + TableImpl pathParametersTable = new TableImpl(parent, new HashMap<>(), new ArrayList<>()); + pathParametersTable.setOption("header"); + pathParametersTable.setAttribute("caption", "", true); + pathParametersTable.setAttribute("cols", ".^2a,.^3a,.^10a,.^5a", true); + pathParametersTable.setTitle(labels.getLabel(TABLE_TITLE_PARAMETERS)); + pathParametersTable.setHeaderRow( + labels.getLabel(TABLE_HEADER_TYPE), + labels.getLabel(TABLE_HEADER_NAME), + labels.getLabel(TABLE_HEADER_DESCRIPTION), + labels.getLabel(TABLE_HEADER_SCHEMA)); + + parameters.forEach((alt, parameter) -> + pathParametersTable.addRow( + generateInnerDoc(pathParametersTable, boldUnconstrained(parameter.getIn()), alt), + getParameterNameDocument(pathParametersTable, parameter), + generateInnerDoc(pathParametersTable, Optional.ofNullable(parameter.getDescription()).orElse("")), + generateInnerDoc(pathParametersTable, getSchemaTypeAsString(parameter.getSchema())) + )); + parent.append(pathParametersTable); + + return parent; + } + + private Document getParameterNameDocument(Table table, Parameter parameter) { + String documentContent = boldUnconstrained(parameter.getName()) + " +" + LINE_SEPARATOR + requiredIndicator(parameter.getRequired(), + labels.getLabel(LABEL_REQUIRED), labels.getLabel(LABEL_OPTIONAL)); + return generateInnerDoc(table, documentContent); + } + + public static class Parameters { + + private final Map parameters; + + public Parameters(Map parameters) { + this.parameters = parameters; + } + } +} diff --git a/openapi2markup/src/main/java/io/github/swagger2markup/internal/component/PropertiesTableComponent.java b/openapi2markup/src/main/java/io/github/swagger2markup/internal/component/PropertiesTableComponent.java new file mode 100755 index 00000000..b8a5797c --- /dev/null +++ b/openapi2markup/src/main/java/io/github/swagger2markup/internal/component/PropertiesTableComponent.java @@ -0,0 +1,89 @@ +/* + * Copyright 2017 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.component; + +import io.github.swagger2markup.OpenAPI2MarkupConverter; +import io.github.swagger2markup.adoc.ast.impl.TableImpl; +import io.github.swagger2markup.extension.MarkupComponent; +import io.swagger.v3.oas.models.media.Schema; +import org.asciidoctor.ast.StructuralNode; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static io.github.swagger2markup.adoc.converter.internal.Delimiters.LINE_SEPARATOR; +import static io.github.swagger2markup.config.OpenAPILabels.*; +import static io.github.swagger2markup.internal.helper.OpenApiHelpers.*; + +public class PropertiesTableComponent extends MarkupComponent { + + private final SchemaComponent schemaComponent; + + PropertiesTableComponent(OpenAPI2MarkupConverter.OpenAPIContext context) { + super(context); + this.schemaComponent = new SchemaComponent(context); + } + + public static Parameters parameters(@SuppressWarnings("rawtypes") Map properties, List schemaRequired) { + return new Parameters(properties, schemaRequired); + } + + public StructuralNode apply(StructuralNode parent, @SuppressWarnings("rawtypes") Map properties, List schemaRequired) { + return apply(parent, parameters(properties, schemaRequired)); + } + + public StructuralNode apply(StructuralNode parent, Parameters params) { + @SuppressWarnings("rawtypes") Map properties = params.properties; + List schemaRequired = params.schemaRequired; + + if (null == properties || properties.isEmpty()) return parent; + + List finalSchemaRequired = (null == schemaRequired) ? new ArrayList<>() : schemaRequired; + + TableImpl propertiesTable = new TableImpl(parent, new HashMap<>(), new ArrayList<>()); + propertiesTable.setOption("header"); + propertiesTable.setAttribute("caption", "", true); + propertiesTable.setAttribute("cols", ".^4a,.^16a,.^4a", true); + propertiesTable.setTitle(labels.getLabel(TABLE_TITLE_PROPERTIES)); + propertiesTable.setHeaderRow( + labels.getLabel(TABLE_HEADER_NAME), + labels.getLabel(TABLE_HEADER_DESCRIPTION), + labels.getLabel(TABLE_HEADER_SCHEMA)); + + properties.forEach((name, schema) -> propertiesTable.addRow( + generateInnerDoc(propertiesTable, name + LINE_SEPARATOR + requiredIndicator(finalSchemaRequired.contains(name), + labels.getLabel(LABEL_REQUIRED), labels.getLabel(LABEL_OPTIONAL))), + schemaComponent.apply(propertiesTable, schema), + generateInnerDoc(propertiesTable, getSchemaTypeAsString(schema)) + )); + parent.append(propertiesTable); + return parent; + } + + @SuppressWarnings("rawtypes") + public static class Parameters { + private final Map properties; + private final List schemaRequired; + + public Parameters(Map properties, List schemaRequired) { + + this.properties = properties; + this.schemaRequired = schemaRequired; + } + } +} diff --git a/openapi2markup/src/main/java/io/github/swagger2markup/internal/component/ResponseComponent.java b/openapi2markup/src/main/java/io/github/swagger2markup/internal/component/ResponseComponent.java new file mode 100644 index 00000000..e493b6c8 --- /dev/null +++ b/openapi2markup/src/main/java/io/github/swagger2markup/internal/component/ResponseComponent.java @@ -0,0 +1,96 @@ +/* + * Copyright 2017 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.component; + +import io.github.swagger2markup.OpenAPI2MarkupConverter; +import io.github.swagger2markup.adoc.ast.impl.TableImpl; +import io.github.swagger2markup.extension.MarkupComponent; +import io.swagger.v3.oas.models.responses.ApiResponse; +import org.asciidoctor.ast.Document; +import org.asciidoctor.ast.StructuralNode; +import org.asciidoctor.ast.Table; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; + +import static io.github.swagger2markup.config.OpenAPILabels.*; +import static io.github.swagger2markup.internal.helper.OpenApiHelpers.generateInnerDoc; + +public class ResponseComponent extends MarkupComponent { + + private final HeadersComponent headersComponent; + private final LinkComponent linkComponent; + private final MediaContentComponent mediaContentComponent; + + public ResponseComponent(OpenAPI2MarkupConverter.OpenAPIContext context) { + super(context); + this.headersComponent = new HeadersComponent(context); + this.linkComponent = new LinkComponent(context); + this.mediaContentComponent = new MediaContentComponent(context); + } + + public static Parameters parameters(Map apiResponses) { + return new Parameters(apiResponses); + } + + public StructuralNode apply(StructuralNode serverSection, Map apiResponses) { + return apply(serverSection, parameters(apiResponses)); + } + + @Override + public StructuralNode apply(StructuralNode serverSection, Parameters params) { + Map apiResponses = params.apiResponses; + + if (null == apiResponses || apiResponses.isEmpty()) return serverSection; + + TableImpl pathResponsesTable = new TableImpl(serverSection, new HashMap<>(), new ArrayList<>()); + pathResponsesTable.setOption("header"); + pathResponsesTable.setAttribute("caption", "", true); + pathResponsesTable.setAttribute("cols", ".^2a,.^14a,.^4a", true); + pathResponsesTable.setTitle(labels.getLabel(TABLE_TITLE_RESPONSES)); + pathResponsesTable.setHeaderRow( + labels.getLabel(TABLE_HEADER_HTTP_CODE), + labels.getLabel(TABLE_HEADER_DESCRIPTION), + labels.getLabel(TABLE_HEADER_LINKS)); + + apiResponses.forEach((httpCode, apiResponse) -> + pathResponsesTable.addRow( + generateInnerDoc(pathResponsesTable, httpCode), + getResponseDescriptionColumnDocument(pathResponsesTable, apiResponse), + linkComponent.apply(pathResponsesTable, apiResponse.getLinks()) + )); + serverSection.append(pathResponsesTable); + return serverSection; + } + + private Document getResponseDescriptionColumnDocument(Table table, ApiResponse apiResponse) { + Document document = generateInnerDoc(table, Optional.ofNullable(apiResponse.getDescription()).orElse("")); + headersComponent.apply(document, apiResponse.getHeaders()); + mediaContentComponent.apply(document, apiResponse.getContent()); + return document; + } + + public static class Parameters { + private final Map apiResponses; + + public Parameters(Map apiResponses) { + + this.apiResponses = apiResponses; + } + } +} diff --git a/openapi2markup/src/main/java/io/github/swagger2markup/internal/component/SchemaComponent.java b/openapi2markup/src/main/java/io/github/swagger2markup/internal/component/SchemaComponent.java new file mode 100644 index 00000000..36bc2562 --- /dev/null +++ b/openapi2markup/src/main/java/io/github/swagger2markup/internal/component/SchemaComponent.java @@ -0,0 +1,118 @@ +/* + * Copyright 2017 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.component; + +import io.github.swagger2markup.OpenAPI2MarkupConverter; +import io.github.swagger2markup.adoc.ast.impl.DocumentImpl; +import io.github.swagger2markup.adoc.ast.impl.ParagraphBlockImpl; +import io.github.swagger2markup.extension.MarkupComponent; +import io.github.swagger2markup.internal.helper.OpenApiHelpers; +import io.swagger.v3.oas.models.media.Schema; +import org.apache.commons.lang3.StringUtils; +import org.asciidoctor.ast.Document; +import org.asciidoctor.ast.StructuralNode; + +import java.util.HashMap; +import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static io.github.swagger2markup.adoc.converter.internal.Delimiters.LINE_SEPARATOR; +import static io.github.swagger2markup.config.OpenAPILabels.*; +import static io.github.swagger2markup.internal.helper.OpenApiHelpers.boldUnconstrained; + +public class SchemaComponent extends MarkupComponent { + + private final OpenAPI2MarkupConverter.OpenAPIContext context; + + public SchemaComponent(OpenAPI2MarkupConverter.OpenAPIContext context) { + super(context); + this.context = context; + } + + public static SchemaComponent.Parameters parameters(@SuppressWarnings("rawtypes") Schema schema) { + return new SchemaComponent.Parameters(schema); + } + + public Document apply(StructuralNode parent, @SuppressWarnings("rawtypes") Schema schema) { + return apply(parent, parameters(schema)); + } + + @SuppressWarnings({"unchecked", "rawtypes"}) + @Override + public Document apply(StructuralNode parent, SchemaComponent.Parameters parameters) { + Document schemaDocument = new DocumentImpl(parent); + Schema schema = parameters.schema; + if (null == schema) return schemaDocument; + + OpenApiHelpers.appendDescription(schemaDocument, schema.getDescription()); + + Map schemasBooleanProperties = new HashMap() {{ + put(labels.getLabel(LABEL_DEPRECATED), schema.getDeprecated()); + put(labels.getLabel(LABEL_NULLABLE), schema.getNullable()); + put(labels.getLabel(LABEL_READ_ONLY), schema.getReadOnly()); + put(labels.getLabel(LABEL_WRITE_ONLY), schema.getWriteOnly()); + put(labels.getLabel(LABEL_UNIQUE_ITEMS), schema.getUniqueItems()); + put(labels.getLabel(LABEL_EXCLUSIVE_MAXIMUM), schema.getExclusiveMaximum()); + put(labels.getLabel(LABEL_EXCLUSIVE_MINIMUM), schema.getExclusiveMinimum()); + }}; + + Map schemasValueProperties = new HashMap() {{ + put(labels.getLabel(LABEL_TITLE), schema.getTitle()); + put(labels.getLabel(LABEL_DEFAULT), schema.getDefault()); + put(labels.getLabel(LABEL_MAXIMUM), schema.getMaximum()); + put(labels.getLabel(LABEL_MINIMUM), schema.getMinimum()); + put(labels.getLabel(LABEL_MAX_LENGTH), schema.getMaxLength()); + put(labels.getLabel(LABEL_MIN_LENGTH), schema.getMinLength()); + put(labels.getLabel(LABEL_MAX_ITEMS), schema.getMaxItems()); + put(labels.getLabel(LABEL_MIN_ITEMS), schema.getMinItems()); + put(labels.getLabel(LABEL_MAX_PROPERTIES), schema.getMaxProperties()); + put(labels.getLabel(LABEL_MIN_PROPERTIES), schema.getMinProperties()); + put(labels.getLabel(LABEL_MULTIPLE_OF), schema.getMultipleOf()); + }}; + + Stream schemaBooleanStream = schemasBooleanProperties.entrySet().stream() + .filter(e -> null != e.getValue() && e.getValue()) + .map(e -> OpenApiHelpers.italicUnconstrained(e.getKey().toLowerCase())); + Stream schemaValueStream = schemasValueProperties.entrySet().stream() + .filter(e -> null != e.getValue() && StringUtils.isNotBlank(e.getValue().toString())) + .map(e -> boldUnconstrained(e.getKey()) + ": " + e.getValue()); + + ParagraphBlockImpl paragraphBlock = new ParagraphBlockImpl(schemaDocument); + String source = Stream.concat(schemaBooleanStream, schemaValueStream).collect(Collectors.joining(" +" + LINE_SEPARATOR)); + paragraphBlock.setSource(source); + + schemaDocument.append(paragraphBlock); + + Map properties = schema.getProperties(); + if (null != properties && !properties.isEmpty()) { + PropertiesTableComponent propertiesTableComponent = new PropertiesTableComponent(context); + propertiesTableComponent.apply(schemaDocument, properties, schema.getRequired()); + } + + return schemaDocument; + } + + @SuppressWarnings("rawtypes") + public static class Parameters { + + private final Schema schema; + + public Parameters(Schema schema) { + this.schema = schema; + } + } +} diff --git a/openapi2markup/src/main/java/io/github/swagger2markup/internal/component/SecurityRequirementTableComponent.java b/openapi2markup/src/main/java/io/github/swagger2markup/internal/component/SecurityRequirementTableComponent.java new file mode 100644 index 00000000..6a3872c0 --- /dev/null +++ b/openapi2markup/src/main/java/io/github/swagger2markup/internal/component/SecurityRequirementTableComponent.java @@ -0,0 +1,86 @@ +/* + * Copyright 2017 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.component; + +import io.github.swagger2markup.OpenAPI2MarkupConverter; +import io.github.swagger2markup.adoc.ast.impl.TableImpl; +import io.github.swagger2markup.extension.MarkupComponent; +import io.swagger.v3.oas.models.security.SecurityRequirement; +import org.asciidoctor.ast.StructuralNode; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import static io.github.swagger2markup.config.OpenAPILabels.*; +import static io.github.swagger2markup.internal.helper.OpenApiHelpers.*; + +public class SecurityRequirementTableComponent extends MarkupComponent { + + public SecurityRequirementTableComponent(OpenAPI2MarkupConverter.OpenAPIContext context) { + super(context); + } + + public static SecurityRequirementTableComponent.Parameters parameters(List securityRequirements, boolean addTitle) { + return new SecurityRequirementTableComponent.Parameters(securityRequirements, addTitle); + } + + public StructuralNode apply(StructuralNode document, List securityRequirements, boolean addTitle) { + return apply(document, parameters(securityRequirements, addTitle)); + } + + @Override + public StructuralNode apply(StructuralNode node, SecurityRequirementTableComponent.Parameters parameters) { + List securityRequirements = parameters.securityRequirements; + + if (securityRequirements == null || securityRequirements.isEmpty()) return node; + + TableImpl securityRequirementsTable = new TableImpl(node, new HashMap<>(), new ArrayList<>()); + securityRequirementsTable.setOption("header"); + securityRequirementsTable.setAttribute("caption", "", true); + securityRequirementsTable.setAttribute("cols", ".^3a,.^4a,.^13a", true); + if (parameters.addTitle) { + securityRequirementsTable.setTitle(labels.getLabel(TABLE_TITLE_SECURITY)); + } + securityRequirementsTable.setHeaderRow( + labels.getLabel(TABLE_HEADER_TYPE), + labels.getLabel(TABLE_HEADER_NAME), + labels.getLabel(TABLE_HEADER_SCOPES)); + + securityRequirements.forEach(securityRequirement -> + securityRequirement.forEach((name, scopes) -> + securityRequirementsTable.addRow( + generateInnerDoc(securityRequirementsTable, boldUnconstrained(scopes.isEmpty() ? "apiKey" : "oauth2")), + generateInnerDoc(securityRequirementsTable, name), + generateInnerDoc(securityRequirementsTable, String.join(", ", scopes)) + ) + ) + ); + node.append(securityRequirementsTable); + return node; + } + + public static class Parameters { + + private final List securityRequirements; + private final boolean addTitle; + + public Parameters(List securityRequirements, boolean addTitle) { + this.securityRequirements = securityRequirements; + this.addTitle = addTitle; + } + } +} diff --git a/openapi2markup/src/main/java/io/github/swagger2markup/internal/component/TagsComponent.java b/openapi2markup/src/main/java/io/github/swagger2markup/internal/component/TagsComponent.java new file mode 100644 index 00000000..109c1541 --- /dev/null +++ b/openapi2markup/src/main/java/io/github/swagger2markup/internal/component/TagsComponent.java @@ -0,0 +1,86 @@ +/* + * Copyright 2017 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.component; + +import io.github.swagger2markup.OpenAPI2MarkupConverter; +import io.github.swagger2markup.adoc.ast.impl.DescriptionListEntryImpl; +import io.github.swagger2markup.adoc.ast.impl.DescriptionListImpl; +import io.github.swagger2markup.adoc.ast.impl.ListItemImpl; +import io.github.swagger2markup.adoc.ast.impl.SectionImpl; +import io.github.swagger2markup.extension.MarkupComponent; +import io.swagger.v3.oas.models.tags.Tag; +import org.apache.commons.lang3.StringUtils; +import org.asciidoctor.ast.Document; +import org.asciidoctor.ast.Section; + +import java.util.Collections; +import java.util.List; + +import static io.github.swagger2markup.config.OpenAPILabels.SECTION_TITLE_TAGS; + + +public class TagsComponent extends MarkupComponent { + + private final ExternalDocumentationComponent externalDocumentationComponent; + + public TagsComponent(OpenAPI2MarkupConverter.OpenAPIContext context) { + super(context); + this.externalDocumentationComponent = new ExternalDocumentationComponent(context); + } + + public static TagsComponent.Parameters parameters(List tags) { + return new TagsComponent.Parameters(tags); + } + + public Document apply(Document document, List tags) { + return apply(document, parameters(tags)); + } + + @Override + public Document apply(Document document, TagsComponent.Parameters parameters) { + List openAPITags = parameters.tags; + if (null == openAPITags || openAPITags.isEmpty()) return document; + + Section tagsSection = new SectionImpl(document); + tagsSection.setTitle(labels.getLabel(SECTION_TITLE_TAGS)); + + DescriptionListImpl tagsList = new DescriptionListImpl(tagsSection); + openAPITags.forEach(tag -> { + DescriptionListEntryImpl tagEntry = new DescriptionListEntryImpl(tagsList, Collections.singletonList(new ListItemImpl(tagsList, tag.getName()))); + String description = tag.getDescription(); + if(StringUtils.isNotBlank(description)){ + ListItemImpl tagDesc = new ListItemImpl(tagEntry, ""); + tagDesc.setSource(description); + externalDocumentationComponent.apply(tagDesc, tag.getExternalDocs()); + tagEntry.setDescription(tagDesc); + } + tagsList.addEntry(tagEntry); + }); + + tagsSection.append(tagsList); + document.append(tagsSection); + return document; + } + + public static class Parameters { + + private final List tags; + + public Parameters(List tags) { + this.tags = tags; + } + } +} diff --git a/openapi2markup/src/main/java/io/github/swagger2markup/internal/document/ComponentsDocument.java b/openapi2markup/src/main/java/io/github/swagger2markup/internal/document/ComponentsDocument.java new file mode 100644 index 00000000..c5a288d6 --- /dev/null +++ b/openapi2markup/src/main/java/io/github/swagger2markup/internal/document/ComponentsDocument.java @@ -0,0 +1,122 @@ +package io.github.swagger2markup.internal.document; + +import io.github.swagger2markup.OpenAPI2MarkupConverter; +import io.github.swagger2markup.adoc.ast.impl.SectionImpl; +import io.github.swagger2markup.extension.MarkupComponent; +import io.github.swagger2markup.internal.component.*; +import io.swagger.v3.oas.models.Components; +import io.swagger.v3.oas.models.headers.Header; +import io.swagger.v3.oas.models.links.Link; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.parameters.Parameter; +import io.swagger.v3.oas.models.responses.ApiResponse; +import org.apache.commons.lang3.Validate; +import org.asciidoctor.ast.Document; +import org.asciidoctor.ast.Section; +import org.asciidoctor.ast.StructuralNode; + +import java.util.Map; + +import static io.github.swagger2markup.config.OpenAPILabels.*; + +public class ComponentsDocument extends MarkupComponent { + + private final ParametersComponent parametersComponent; + private final ResponseComponent responseComponent; + private final HeadersComponent headersComponent; + private final SchemaComponent schemaComponent; + private final LinkComponent linkComponent; + + public ComponentsDocument(OpenAPI2MarkupConverter.OpenAPIContext context) { + super(context); + this.parametersComponent = new ParametersComponent(context); + this.responseComponent = new ResponseComponent(context); + this.headersComponent = new HeadersComponent(context); + this.schemaComponent = new SchemaComponent(context); + this.linkComponent = new LinkComponent(context); + } + + public static Parameters parameters(Components components) { + return new Parameters(components); + } + + @Override + public Document apply(Document document, ComponentsDocument.Parameters parameters) { + + appendComponentsSection(document, parameters.components); + + return document; + } + + public static class Parameters { + private final Components components; + + public Parameters(Components components) { + this.components = Validate.notNull(components, "Schema must not be null"); + } + } + + private void appendComponentsSection(Document document, Components components) { + if (null == components) return; + + Section componentsSection = new SectionImpl(document); + componentsSection.setTitle(labels.getLabel(SECTION_TITLE_COMPONENTS)); + String componentSectionId = "_components"; + componentsSection.setId(componentSectionId); + + appendComponentsSchemasSection(componentsSection, componentSectionId, components.getSchemas()); + Map parameters = components.getParameters(); + if (null != parameters && !parameters.isEmpty()) { + appendSubSection(componentsSection, componentSectionId, parametersComponent, SECTION_TITLE_PARAMETERS, + new ParametersComponent.Parameters(parameters)); + } + Map responses = components.getResponses(); + if (null != responses && !responses.isEmpty()) { + appendSubSection(componentsSection, componentSectionId, responseComponent, SECTION_TITLE_RESPONSES, + new ResponseComponent.Parameters(responses)); + } + Map headers = components.getHeaders(); + if (null != headers && !headers.isEmpty()) { + appendSubSection(componentsSection, componentSectionId, headersComponent, SECTION_TITLE_HEADERS, + new HeadersComponent.Parameters(headers)); + } + Map links = components.getLinks(); + if (null != links && !links.isEmpty()) { + appendSubSection(componentsSection, componentSectionId, linkComponent, SECTION_TITLE_LINKS, + new LinkComponent.Parameters(links)); + } + document.append(componentsSection); + } + + private void appendComponentsSchemasSection( + Section componentsSection, String componentSectionId, + @SuppressWarnings("rawtypes") Map schemas) { + if (null == schemas || schemas.isEmpty()) return; + + SectionImpl schemasSection = new SectionImpl(componentsSection); + String schemasSectionId = componentSectionId + "_schemas"; + schemasSection.setTitle(labels.getLabel(SECTION_TITLE_SCHEMAS)); + schemasSection.setId(schemasSectionId); + schemas.forEach((name, schema) -> { + String schemaDocumentId = schemasSectionId + "_" + name; + Document schemaDocument = schemaComponent.apply(schemasSection, schema); + schemaDocument.setTitle(name); + schemaDocument.setId(schemaDocumentId); + schemasSection.append(schemaDocument); + }); + componentsSection.append(schemasSection); + } + + private void appendSubSection(Section componentsSection, String componentSectionId, + MarkupComponent markupComponent, + String sectionLabel, T parameters) { + SectionImpl parametersSection = new SectionImpl(componentsSection); + String parametersSectionId = componentSectionId + "_parameters"; + parametersSection.setTitle(labels.getLabel(sectionLabel)); + parametersSection.setId(parametersSectionId); + markupComponent.apply(parametersSection, parameters); + componentsSection.append(parametersSection); + } +} + + diff --git a/openapi2markup/src/main/java/io/github/swagger2markup/internal/document/OverviewDocument.java b/openapi2markup/src/main/java/io/github/swagger2markup/internal/document/OverviewDocument.java new file mode 100644 index 00000000..dda3c509 --- /dev/null +++ b/openapi2markup/src/main/java/io/github/swagger2markup/internal/document/OverviewDocument.java @@ -0,0 +1,138 @@ +package io.github.swagger2markup.internal.document; + +import io.github.swagger2markup.OpenAPI2MarkupConverter; +import io.github.swagger2markup.adoc.ast.impl.BlockImpl; +import io.github.swagger2markup.adoc.ast.impl.DocumentImpl; +import io.github.swagger2markup.adoc.ast.impl.ParagraphBlockImpl; +import io.github.swagger2markup.adoc.ast.impl.SectionImpl; +import io.github.swagger2markup.extension.MarkupComponent; +import io.github.swagger2markup.extension.OverviewDocumentExtension; +import io.github.swagger2markup.internal.component.ExternalDocumentationComponent; +import io.github.swagger2markup.internal.component.TagsComponent; +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.info.Contact; +import io.swagger.v3.oas.models.info.Info; +import io.swagger.v3.oas.models.info.License; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.Validate; +import org.asciidoctor.ast.Block; +import org.asciidoctor.ast.Document; +import org.asciidoctor.ast.Section; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Optional; + +import static io.github.swagger2markup.config.OpenAPILabels.LABEL_TERMS_OF_SERVICE; +import static io.github.swagger2markup.config.OpenAPILabels.SECTION_TITLE_OVERVIEW; +import static io.github.swagger2markup.extension.OverviewDocumentExtension.Context; +import static io.github.swagger2markup.internal.helper.OpenApiHelpers.appendDescription; + +public class OverviewDocument extends MarkupComponent { + private final TagsComponent tagsComponent; + private final ExternalDocumentationComponent externalDocumentationComponent; + + public OverviewDocument(OpenAPI2MarkupConverter.OpenAPIContext context) { + super(context); + tagsComponent = new TagsComponent(context); + this.externalDocumentationComponent = new ExternalDocumentationComponent(context); + } + + public static OverviewDocument.Parameters parameters(OpenAPI schema) { + return new OverviewDocument.Parameters(schema); + } + + @Override + public Document apply(Document document, Parameters parameters) { + Info apiInfo = parameters.openAPI.getInfo(); + document.setAttribute("openapi", parameters.openAPI.getOpenapi(), true); + addDocumentTitle(document, apiInfo); + addAuthorInfo(document, apiInfo); + addVersionInfo(document, apiInfo); + + applyOverviewDocumentExtension(new Context(OverviewDocumentExtension.Position.DOCUMENT_BEFORE, document)); + Document subDocument = new DocumentImpl(document); + Section overviewDoc = new SectionImpl(subDocument, "section", new HashMap<>(), new ArrayList<>(), + null, new ArrayList<>(), 1, "", new ArrayList<>(), + null, null, "", "", false, false); + applyOverviewDocumentExtension(new Context(OverviewDocumentExtension.Position.DOCUMENT_BEGIN, subDocument)); + overviewDoc.setTitle(labels.getLabel(SECTION_TITLE_OVERVIEW)); + + appendDescription(overviewDoc, apiInfo.getDescription()); + appendTermsOfServiceInfo(overviewDoc, apiInfo); + appendLicenseInfo(overviewDoc, apiInfo); + subDocument.append(overviewDoc); + applyOverviewDocumentExtension(new Context(OverviewDocumentExtension.Position.DOCUMENT_END, subDocument)); + document.append(subDocument); + + externalDocumentationComponent.apply(document, parameters.openAPI.getExternalDocs()); + tagsComponent.apply(document, parameters.openAPI.getTags()); + applyOverviewDocumentExtension(new Context(OverviewDocumentExtension.Position.DOCUMENT_AFTER, document)); + return document; + } + + private void applyOverviewDocumentExtension(Context context) { + extensionRegistry.getOverviewDocumentExtensions().forEach(extension -> extension.apply(context)); + } + + private void addDocumentTitle(Document rootDocument, Info apiInfo) { + String title = apiInfo.getTitle(); + if (StringUtils.isNotBlank(title)) { + rootDocument.setTitle(title); + } + } + + private void addVersionInfo(Document rootDocument, Info info) { + String version = info.getVersion(); + if (StringUtils.isNotBlank(version)) { + rootDocument.setAttribute("revnumber", version, true); + } + } + + private void addAuthorInfo(Document rootDocument, Info info) { + Contact contact = info.getContact(); + if (null != contact) { + String author = Optional.ofNullable(contact.getName()).orElse(""); + String email = contact.getEmail(); + if (StringUtils.isNotBlank(email)) { + rootDocument.setAttribute("email", email, true); + } + rootDocument.setAttribute("author", author, true); + rootDocument.setAttribute("authorcount", 1L, true); + } + } + + private void appendLicenseInfo(Section overviewDoc, Info info) { + License license = info.getLicense(); + if (null != license) { + StringBuilder sb = new StringBuilder(); + if (StringUtils.isNotBlank(license.getUrl())) { + sb.append(license.getUrl()).append("["); + } + sb.append(license.getName()); + if (StringUtils.isNotBlank(license.getUrl())) { + sb.append("]"); + } + BlockImpl paragraph = new ParagraphBlockImpl(overviewDoc); + paragraph.setSource(sb.toString()); + overviewDoc.append(paragraph); + } + } + + private void appendTermsOfServiceInfo(Section overviewDoc, Info info) { + String termsOfService = info.getTermsOfService(); + if (StringUtils.isNotBlank(termsOfService)) { + Block paragraph = new ParagraphBlockImpl(overviewDoc); + paragraph.setSource(termsOfService + "[" + labels.getLabel(LABEL_TERMS_OF_SERVICE) + "]"); + overviewDoc.append(paragraph); + } + } + + public static class Parameters { + private final OpenAPI openAPI; + + public Parameters(OpenAPI openAPI) { + this.openAPI = Validate.notNull(openAPI, "Schema must not be null"); + } + } +} diff --git a/openapi2markup/src/main/java/io/github/swagger2markup/internal/document/PathsDocument.java b/openapi2markup/src/main/java/io/github/swagger2markup/internal/document/PathsDocument.java new file mode 100644 index 00000000..2eacd373 --- /dev/null +++ b/openapi2markup/src/main/java/io/github/swagger2markup/internal/document/PathsDocument.java @@ -0,0 +1,116 @@ +package io.github.swagger2markup.internal.document; + +import io.github.swagger2markup.OpenAPI2MarkupConverter; +import io.github.swagger2markup.adoc.ast.impl.SectionImpl; +import io.github.swagger2markup.adoc.ast.impl.TableImpl; +import io.github.swagger2markup.extension.MarkupComponent; +import io.github.swagger2markup.internal.component.ExternalDocumentationComponent; +import io.github.swagger2markup.internal.component.ParametersComponent; +import io.github.swagger2markup.internal.component.ResponseComponent; +import io.github.swagger2markup.internal.component.SecurityRequirementTableComponent; +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.Paths; +import io.swagger.v3.oas.models.servers.Server; +import io.swagger.v3.oas.models.servers.ServerVariables; +import org.apache.commons.lang3.Validate; +import org.asciidoctor.ast.Document; +import org.asciidoctor.ast.Section; +import org.asciidoctor.ast.StructuralNode; + +import java.util.*; + +import static io.github.swagger2markup.config.OpenAPILabels.*; +import static io.github.swagger2markup.internal.helper.OpenApiHelpers.*; + +public class PathsDocument extends MarkupComponent { + private final ParametersComponent parametersComponent; + private final ExternalDocumentationComponent externalDocumentationComponent; + private final ResponseComponent responseComponent; + private final SecurityRequirementTableComponent securityRequirementTableComponent; + + public PathsDocument(OpenAPI2MarkupConverter.OpenAPIContext context) { + super(context); + this.parametersComponent = new ParametersComponent(context); + this.externalDocumentationComponent = new ExternalDocumentationComponent(context); + this.responseComponent = new ResponseComponent(context); + this.securityRequirementTableComponent = new SecurityRequirementTableComponent(context); + } + + public static Parameters parameters(OpenAPI schema) { + return new Parameters(schema); + } + + @Override + public Document apply(Document document, Parameters parameters) { + Paths apiPaths = parameters.schema.getPaths(); + + if (null == apiPaths || apiPaths.isEmpty()) return document; + + SectionImpl allPathsSection = new SectionImpl(document); + allPathsSection.setTitle(labels.getLabel(SECTION_TITLE_PATHS)); + + apiPaths.forEach((name, pathItem) -> + pathItem.readOperationsMap().forEach(((httpMethod, operation) -> { + SectionImpl operationSection = new SectionImpl(allPathsSection); + String summary = Optional.ofNullable(operation.getSummary()).orElse(""); + operationSection.setTitle((italicUnconstrained(httpMethod.name().toUpperCase()) + " " + monospaced(name) + " " + summary).trim()); + appendDescription(operationSection, operation.getDescription()); + externalDocumentationComponent.apply(operationSection, operation.getExternalDocs()); + parametersComponent.apply(operationSection, operation.getParameters()); + responseComponent.apply(operationSection, operation.getResponses()); + appendServersSection(operationSection, operation.getServers()); + securityRequirementTableComponent.apply(operationSection, operation.getSecurity(), false); + allPathsSection.append(operationSection); + }))); + + document.append(allPathsSection); + return document; + } + + private void appendServersSection(StructuralNode node, List servers) { + if (null == servers || servers.isEmpty()) return; + + Section serversSection = new SectionImpl(node); + serversSection.setTitle(labels.getLabel(SECTION_TITLE_SERVERS)); + + servers.forEach(server -> { + Section serverSection = new SectionImpl(serversSection); + serverSection.setTitle(italicUnconstrained(labels.getLabel(LABEL_SERVER)) + ": " + server.getUrl()); + + appendDescription(serverSection, server.getDescription()); + ServerVariables variables = server.getVariables(); + appendVariables(serverSection, variables); + serversSection.append(serverSection); + }); + node.append(serversSection); + } + + private void appendVariables(Section serverSection, ServerVariables variables) { + if (null == variables || variables.isEmpty()) return; + + TableImpl serverVariables = new TableImpl(serverSection, new HashMap() {{ + put("header-option", ""); + put("cols", ".^2a,.^9a,.^3a,.^4a"); + }}, new ArrayList<>()); + serverVariables.setTitle(labels.getLabel(TABLE_TITLE_SERVER_VARIABLES)); + + serverVariables.setHeaderRow(labels.getLabel(TABLE_HEADER_VARIABLE), labels.getLabel(TABLE_HEADER_DESCRIPTION), + labels.getLabel(TABLE_HEADER_POSSIBLE_VALUES), labels.getLabel(TABLE_HEADER_DEFAULT) + ); + + variables.forEach((name, variable) -> { + String possibleValues = String.join(", ", Optional.ofNullable(variable.getEnum()).orElse(Collections.singletonList("Any"))); + serverVariables.addRow(name, Optional.ofNullable(variable.getDescription()).orElse(""), possibleValues, variable.getDefault()); + + }); + serverSection.append(serverVariables); + } + + public static class Parameters { + private final OpenAPI schema; + + public Parameters(OpenAPI schema) { + this.schema = Validate.notNull(schema, "Schema must not be null"); + } + } +} diff --git a/openapi2markup/src/main/java/io/github/swagger2markup/internal/document/SecurityDocument.java b/openapi2markup/src/main/java/io/github/swagger2markup/internal/document/SecurityDocument.java new file mode 100644 index 00000000..f22882a5 --- /dev/null +++ b/openapi2markup/src/main/java/io/github/swagger2markup/internal/document/SecurityDocument.java @@ -0,0 +1,49 @@ +package io.github.swagger2markup.internal.document; + +import io.github.swagger2markup.OpenAPI2MarkupConverter; +import io.github.swagger2markup.adoc.ast.impl.SectionImpl; +import io.github.swagger2markup.extension.MarkupComponent; +import io.github.swagger2markup.internal.component.SecurityRequirementTableComponent; +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.security.SecurityRequirement; +import org.apache.commons.lang3.Validate; +import org.asciidoctor.ast.Document; +import org.asciidoctor.ast.Section; + +import java.util.List; + +import static io.github.swagger2markup.config.OpenAPILabels.SECTION_TITLE_SECURITY; + +public class SecurityDocument extends MarkupComponent { + private final SecurityRequirementTableComponent securityRequirementTableComponent; + + public SecurityDocument(OpenAPI2MarkupConverter.OpenAPIContext context) { + super(context); + this.securityRequirementTableComponent = new SecurityRequirementTableComponent(context); + } + + public static Parameters parameters(OpenAPI schema) { + return new Parameters(schema); + } + + @Override + public Document apply(Document document, SecurityDocument.Parameters parameters) { + List securityRequirements = parameters.schema.getSecurity(); + if (null == securityRequirements || securityRequirements.isEmpty()) return document; + + Section securityRequirementsSection = new SectionImpl(document); + securityRequirementsSection.setTitle(labels.getLabel(SECTION_TITLE_SECURITY)); + securityRequirementTableComponent.apply(securityRequirementsSection, securityRequirements, false); + document.append(securityRequirementsSection); + + return document; + } + + public static class Parameters { + private final OpenAPI schema; + + public Parameters(OpenAPI schema) { + this.schema = Validate.notNull(schema, "Schema must not be null"); + } + } +} diff --git a/openapi2markup/src/main/java/io/github/swagger2markup/internal/helper/OpenApiHelpers.java b/openapi2markup/src/main/java/io/github/swagger2markup/internal/helper/OpenApiHelpers.java new file mode 100644 index 00000000..5740fe6a --- /dev/null +++ b/openapi2markup/src/main/java/io/github/swagger2markup/internal/helper/OpenApiHelpers.java @@ -0,0 +1,115 @@ +package io.github.swagger2markup.internal.helper; + +import io.github.swagger2markup.adoc.ast.impl.DocumentImpl; +import io.github.swagger2markup.adoc.ast.impl.ParagraphBlockImpl; +import io.swagger.v3.oas.models.media.ArraySchema; +import io.swagger.v3.oas.models.media.Schema; +import org.apache.commons.lang3.StringUtils; +import org.asciidoctor.ast.Block; +import org.asciidoctor.ast.Document; +import org.asciidoctor.ast.StructuralNode; +import org.asciidoctor.ast.Table; + +import java.util.List; + +import static io.github.swagger2markup.adoc.converter.internal.Delimiters.LINE_SEPARATOR; + +public class OpenApiHelpers { + + public static void appendDescription(StructuralNode node, String description) { + if (StringUtils.isNotBlank(description)) { + Block paragraph = new ParagraphBlockImpl(node); + paragraph.setSource(description); + node.append(paragraph); + } + } + + public static Document generateInnerDoc(Table table, String documentContent) { + return generateInnerDoc(table, documentContent, ""); + } + + public static Document generateInnerDoc(Table table, String documentContent, String id) { + Document innerDoc = new DocumentImpl(table); + if (StringUtils.isNotBlank(id)) { + innerDoc.setId(id); + } + + Block paragraph = new ParagraphBlockImpl(innerDoc); + paragraph.setSource(documentContent); + innerDoc.append(paragraph); + return innerDoc; + } + + public static String requiredIndicator(boolean isRequired, String labelRequired, String labelOptional) { + return italicUnconstrained(isRequired ? labelRequired : labelOptional).toLowerCase(); + } + + public static String superScript(String str) { + return "^" + str + "^"; + } + + public static String subScript(String str) { + return "~" + str + "~"; + } + + public static String italicUnconstrained(String str) { + return "__" + str + "__"; + } + + public static String boldUnconstrained(String str) { + return "**" + str + "**"; + } + + public static String monospaced(String str) { + return "`" + str + "`"; + } + + public static String getSchemaTypeAsString(Schema schema) { + StringBuilder stringBuilder = new StringBuilder(); + if (schema instanceof ArraySchema) { + stringBuilder.append("< "); + Schema items = ((ArraySchema) schema).getItems(); + stringBuilder.append(getSchemaType(items)); + stringBuilder.append(" > "); + stringBuilder.append(schema.getType()); + } else { + List enumList = schema.getEnum(); + if (enumList != null) { + stringBuilder.append("enum ("); + for (Object value : enumList) { + stringBuilder.append(value.toString()); + stringBuilder.append(","); + } + stringBuilder.deleteCharAt(stringBuilder.length() - 1); + stringBuilder.append(')'); + } else { + stringBuilder.append(getSchemaType(schema)); + String format = schema.getFormat(); + if (format != null) { + stringBuilder.append(' '); + stringBuilder.append('('); + stringBuilder.append(format); + stringBuilder.append(')'); + } + } + } + return stringBuilder.toString(); + } + + private static String getSchemaType(Schema schema) { + String type = schema.getType(); + if (StringUtils.isNotEmpty(type)) { + return type; + } else { + return generateRefLink(schema.get$ref()); + } + } + + private static String generateRefLink(String ref) { + if (StringUtils.isNotBlank(ref)) { + String anchor = ref.toLowerCase().replaceFirst("#", "").replaceAll("/", "_"); + return "<<" + anchor + ">>" + LINE_SEPARATOR; + } + return ""; + } +} diff --git a/openapi2markup/src/main/resources/io/github/swagger2markup/config/default.properties b/openapi2markup/src/main/resources/io/github/swagger2markup/config/default.properties new file mode 100644 index 00000000..25cbecea --- /dev/null +++ b/openapi2markup/src/main/resources/io/github/swagger2markup/config/default.properties @@ -0,0 +1,30 @@ +swagger2markup.markupLanguage=ASCIIDOC +swagger2markup.swaggerMarkupLanguage=ASCIIDOC +swagger2markup.generatedExamplesEnabled=false +swagger2markup.hostnameEnabled=false +swagger2markup.basePathPrefixEnabled=false +swagger2markup.operationExtensionsEnabled=false +swagger2markup.definitionExtensionsEnabled=false +swagger2markup.separatedDefinitionsEnabled=false +swagger2markup.separatedOperationsEnabled=false +swagger2markup.pathsGroupedBy=AS_IS +swagger2markup.outputLanguage=EN +swagger2markup.inlineSchemaEnabled=true +swagger2markup.interDocumentCrossReferencesEnabled=false +swagger2markup.flatBodyEnabled=false +swagger2markup.pathSecuritySectionEnabled=true +swagger2markup.overviewDocument=overview +swagger2markup.pathsDocument=paths +swagger2markup.definitionsDocument=definitions +swagger2markup.securityDocument=security +swagger2markup.separatedOperationsFolder=operations +swagger2markup.separatedDefinitionsFolder=definitions +swagger2markup.tagOrderBy=NATURAL +swagger2markup.operationOrderBy=NATURAL +swagger2markup.definitionOrderBy=NATURAL +swagger2markup.parameterOrderBy=NATURAL +swagger2markup.propertyOrderBy=NATURAL +swagger2markup.responseOrderBy=NATURAL +swagger2markup.listDelimiterEnabled=false +swagger2markup.listDelimiter=, +swagger2markup.asciidoc.pegdown.timeoutMillis=2000 diff --git a/openapi2markup/src/main/resources/io/github/swagger2markup/lang/labels_en.properties b/openapi2markup/src/main/resources/io/github/swagger2markup/lang/labels_en.properties new file mode 100644 index 00000000..8689004f --- /dev/null +++ b/openapi2markup/src/main/resources/io/github/swagger2markup/lang/labels_en.properties @@ -0,0 +1,58 @@ +label_content=Content +label_default=Default +label_deprecated=Deprecated +label_example=Example +label_examples=Examples +label_exclusive_maximum=Exclusive Maximum +label_exclusive_minimum=Exclusive Minimum +label_external_value=External Value +label_format=Format +label_maximum=Maximum +label_max_items=Maximum Items +label_max_length=Maximum Length +label_max_properties=Maximum Properties +label_minimum=Minimum +label_min_items=Minimum Items +label_min_length=Minimum Length +label_min_properties=Minimum Properties +label_multiple_of=Multiple Of +label_no_links=No Links +label_nullable=Nullable +label_operation=Operation +label_optional=Optional +label_parameters=Parameters +label_read_only=Read Only +label_required=Required +label_server=Server +label_terms_of_service=Terms Of Service +label_title=Title +label_type=Type +label_unique_items=Unique Items +label_write_only=Write Only +section_title_components=Components +section_title_parameters=Parameters +section_title_paths=Paths +section_title_schemas=Schemas +section_title_security=Security +section_title_servers=Servers +section_title_overview=Overview +section_title_tags=Tags +section_title_responses=Responses +section_title_headers=Headers +section_title_links=Links +table_header_default=Default +table_header_description=Description +table_header_http_code=Code +table_header_links=Links +table_header_name=Name +table_header_possible_values=Possible Values +table_header_schema=Schema +table_header_scopes=Scopes +table_header_type=Type +table_header_variable=Variable +table_title_headers=Headers +table_title_parameters=Parameters +table_title_properties=Properties +table_title_responses=Responses +table_title_security=Security +table_title_server_variables=Server Variables diff --git a/openapi2markup/src/test/java/io/github/swagger2markup/AsciidocConverterTest.java b/openapi2markup/src/test/java/io/github/swagger2markup/AsciidocConverterTest.java new file mode 100644 index 00000000..11f18208 --- /dev/null +++ b/openapi2markup/src/test/java/io/github/swagger2markup/AsciidocConverterTest.java @@ -0,0 +1,74 @@ +/* + * Copyright 2017 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; + +import io.github.swagger2markup.assertions.DiffUtils; +import org.apache.commons.io.FileUtils; +import org.assertj.core.api.Assertions; +import org.junit.Before; +import org.junit.Test; + +import java.net.URISyntaxException; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; + +import static java.util.Arrays.asList; +import static org.assertj.core.api.Assertions.assertThat; + +public class AsciidocConverterTest { + + private static final String[] EXPECTED_FILES = new String[]{"definitions.adoc", "overview.adoc", "paths.adoc", "security.adoc"}; + private List expectedFiles; + + @Before + public void setUp() { + expectedFiles = new ArrayList<>(asList(EXPECTED_FILES)); + } + + @Test + public void testToString() throws URISyntaxException { + //Given + Path file = Paths.get(AsciidocConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI()); + + //When + String asciiDocAsString = OpenAPI2MarkupConverter.from(file).build() + .toString(); + //Then + Assertions.assertThat(asciiDocAsString).isNotEmpty(); + System.out.println(asciiDocAsString); + } + + @Test + public void testToFolder() throws URISyntaxException { + //Given + Path file = Paths.get(AsciidocConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI()); + Path outputDirectory = Paths.get("build/test/asciidoc/to_folder"); + FileUtils.deleteQuietly(outputDirectory.toFile()); + + //When + OpenAPI2MarkupConverter.from(file).build() + .toFolder(outputDirectory); + + //Then + String[] files = outputDirectory.toFile().list(); + assertThat(files).hasSize(4).containsAll(expectedFiles); + + Path expectedFilesDirectory = Paths.get(AsciidocConverterTest.class.getResource("/expected/asciidoc/to_folder").toURI()); + DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testToFolder.html"); + } +} diff --git a/openapi2markup/src/test/java/io/github/swagger2markup/OpenApi2AsciiDocTest.java b/openapi2markup/src/test/java/io/github/swagger2markup/OpenApi2AsciiDocTest.java new file mode 100644 index 00000000..87dde351 --- /dev/null +++ b/openapi2markup/src/test/java/io/github/swagger2markup/OpenApi2AsciiDocTest.java @@ -0,0 +1,49 @@ +package io.github.swagger2markup; + +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.parser.OpenAPIV3Parser; +import io.swagger.v3.parser.core.models.ParseOptions; +import io.swagger.v3.parser.core.models.SwaggerParseResult; +import org.apache.commons.io.IOUtils; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Paths; +import java.util.Arrays; + +import static org.junit.Assert.assertNotNull; + +@RunWith(Parameterized.class) +public class OpenApi2AsciiDocTest { + + final private String openApiFile; + final private String expectedAsciiDoc; + + public OpenApi2AsciiDocTest(String openApiFile, String expectedAsciiDoc) throws IOException { + this.openApiFile = "./src/test/resources/open_api/" + openApiFile; + this.expectedAsciiDoc = IOUtils.toString(getClass().getResourceAsStream("/asciidoc/" + expectedAsciiDoc), StandardCharsets.UTF_8); + } + + @Parameterized.Parameters(name = "Run {index}: open api={0}, asciidoc={1}") + public static Iterable data() { + return Arrays.asList(new Object[][]{ + {"simple.yaml", "simple.adoc"}, + {"petstore.yaml", "petstore.adoc"} + }); + } + + @Test + public void converts_open_api_v3_to_asciidoc() { + ParseOptions options = new ParseOptions(); + options.setResolve(true); + SwaggerParseResult result = new OpenAPIV3Parser().readLocation(openApiFile, null, options); + OpenAPI swagger = result.getOpenAPI(); + assertNotNull(swagger); + + OpenAPI2MarkupConverter converter = OpenAPI2MarkupConverter.from(swagger).build(); + converter.toFolder(Paths.get("build/test/asciidoc")); + } +} diff --git a/swagger2markup-core/src/test/java/io/github/swagger2markup/assertions/DiffUtils.java b/openapi2markup/src/test/java/io/github/swagger2markup/assertions/DiffUtils.java similarity index 100% rename from swagger2markup-core/src/test/java/io/github/swagger2markup/assertions/DiffUtils.java rename to openapi2markup/src/test/java/io/github/swagger2markup/assertions/DiffUtils.java diff --git a/openapi2markup/src/test/resources/asciidoc/petstore.adoc b/openapi2markup/src/test/resources/asciidoc/petstore.adoc new file mode 100644 index 00000000..32df5d97 --- /dev/null +++ b/openapi2markup/src/test/resources/asciidoc/petstore.adoc @@ -0,0 +1,1898 @@ += Swagger Petstore +apiteam@swagger.io +v1.0.0 +:revnumber: 1.0.0 +:openapi: 3.0.0 +:author: apiteam@swagger.io +:authorcount: 1 + +== Overview +This is a sample server Petstore server. You can find out more about Swagger at http://swagger.io or on irc.freenode.net, #swagger. For this sample, you can use the api key "special-key" to test the authorization filters + +http://swagger.io/terms/[Terms Of Service] + +http://www.apache.org/licenses/LICENSE-2.0.html[Apache 2.0] + +https://swagger.io[Find more info here] + +== Tags +pet:: +Pet Operations ++ +http://swagger.io + +user:: +All about the Users + +== Servers +=== __Server__: http://localhost:8000/v2/api + +== Paths +=== __POST__ `/pet/add` Add a new pet to the store +.Responses +[%header,caption=,cols=".^2a,.^14a,.^4a"] +|=== +<.<|Code + + +<.<|Description + + +<.<|Links + + + +<.<|200 + + +<.<|This is a sample + +.Content +text/plain:: ++ + +type: string + +.Example +[source] +---- +whoa! +---- + + +<.<|No Links + + + +<.<|405 + + +<.<|Invalid input + + +<.<|No Links + + + +|=== +.Security +[%header,caption=,cols=".^3a,.^4a,.^13a"] +|=== +<.<|Type + + +<.<|Name + + +<.<|Scopes + + + +<.<|**oauth2** + + +<.<|petstore_auth + + +<.<|write:pets, read:pets + + + +|=== + +=== __PUT__ `/pet` Update an existing pet +.Responses +[%header,caption=,cols=".^2a,.^14a,.^4a"] +|=== +<.<|Code + + +<.<|Description + + +<.<|Links + + + +<.<|400 + + +<.<|Invalid ID supplied + + +<.<|No Links + + + +<.<|404 + + +<.<|Pet not found + + +<.<|No Links + + + +<.<|405 + + +<.<|Validation exception + + +<.<|No Links + + + +|=== +.Security +[%header,caption=,cols=".^3a,.^4a,.^13a"] +|=== +<.<|Type + + +<.<|Name + + +<.<|Scopes + + + +<.<|**oauth2** + + +<.<|petstore_auth + + +<.<|write:pets, read:pets + + + +|=== + +=== __POST__ `/pet` Add a new pet to the store +.Responses +[%header,caption=,cols=".^2a,.^14a,.^4a"] +|=== +<.<|Code + + +<.<|Description + + +<.<|Links + + + +<.<|405 + + +<.<|Invalid input + + +<.<|No Links + + + +|=== +.Security +[%header,caption=,cols=".^3a,.^4a,.^13a"] +|=== +<.<|Type + + +<.<|Name + + +<.<|Scopes + + + +<.<|**oauth2** + + +<.<|petstore_auth + + +<.<|write:pets, read:pets + + + +|=== + +=== __GET__ `/pet/findByStatus` Finds Pets by status +Multiple status values can be provided with comma seperated strings + +.Parameters +[%header,caption=,cols=".^2a,.^3a,.^10a,.^5a"] +|=== +<.<|Type + + +<.<|Name + + +<.<|Description + + +<.<|Schema + + + +<.<|**query** + + +<.<|**status** + +__optional__ + + +<.<|Status values that need to be considered for filter + + +<.<|type: array + + + +|=== +.Responses +[%header,caption=,cols=".^2a,.^14a,.^4a"] +|=== +<.<|Code + + +<.<|Description + + +<.<|Links + + + +<.<|200 + + +<.<|successful operation + +.Content +application/json:: ++ + +<<_components_schemas_PetArray,PetArray>> + +application/xml:: ++ + +<<_components_schemas_PetArray,PetArray>> + + +<.<|No Links + + + +<.<|400 + + +<.<|Invalid status value + + +<.<|No Links + + + +|=== +.Security +[%header,caption=,cols=".^3a,.^4a,.^13a"] +|=== +<.<|Type + + +<.<|Name + + +<.<|Scopes + + + +<.<|**oauth2** + + +<.<|petstore_auth + + +<.<|write:pets, read:pets + + + +|=== + +=== __GET__ `/pet/findByTags` Finds Pets by tags +Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. + +.Parameters +[%header,caption=,cols=".^2a,.^3a,.^10a,.^5a"] +|=== +<.<|Type + + +<.<|Name + + +<.<|Description + + +<.<|Schema + + + +<.<|**query** + + +<.<|**tags** + +__optional__ + + +<.<|Tags to filter by + + +<.<|type: array + + + +|=== +.Responses +[%header,caption=,cols=".^2a,.^14a,.^4a"] +|=== +<.<|Code + + +<.<|Description + + +<.<|Links + + + +<.<|200 + + +<.<|successful operation + +.Content +application/json:: ++ + +type: array + +application/xml:: ++ + +type: array + + +<.<|No Links + + + +<.<|400 + + +<.<|Invalid tag value + + +<.<|No Links + + + +|=== +.Security +[%header,caption=,cols=".^3a,.^4a,.^13a"] +|=== +<.<|Type + + +<.<|Name + + +<.<|Scopes + + + +<.<|**oauth2** + + +<.<|petstore_auth + + +<.<|write:pets, read:pets + + + +|=== + +=== __GET__ `/pet/{petId}` Find pet by ID +Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions + +.Parameters +[%header,caption=,cols=".^2a,.^3a,.^10a,.^5a"] +|=== +<.<|Type + + +<.<|Name + + +<.<|Description + + +<.<|Schema + + + +<.<|**path** + + +<.<|**petId** + +__required__ + + +<.<|ID of pet that needs to be fetched + + +<.<|type: integer + +format: int64 + + + +|=== +.Responses +[%header,caption=,cols=".^2a,.^14a,.^4a"] +|=== +<.<|Code + + +<.<|Description + + +<.<|Links + + + +<.<|200 + + +<.<|successful operation + +.Content +application/json:: ++ + +<<_components_schemas_Pet,Pet>> + +application/xml:: ++ + +<<_components_schemas_Pet,Pet>> + + +<.<|No Links + + + +<.<|400 + + +<.<|Invalid ID supplied + + +<.<|No Links + + + +<.<|404 + + +<.<|Pet not found + + +<.<|No Links + + + +|=== +.Security +[%header,caption=,cols=".^3a,.^4a,.^13a"] +|=== +<.<|Type + + +<.<|Name + + +<.<|Scopes + + + +<.<|**apiKey** + + +<.<|api_key + + +<.<| + +<.<|**oauth2** + + +<.<|petstore_auth + + +<.<|write:pets, read:pets + + + +|=== + +=== __POST__ `/pet/{petId}` Updates a pet in the store with form data +.Parameters +[%header,caption=,cols=".^2a,.^3a,.^10a,.^5a"] +|=== +<.<|Type + + +<.<|Name + + +<.<|Description + + +<.<|Schema + + + +<.<|**path** + + +<.<|**petId** + +__required__ + + +<.<|ID of pet that needs to be updated + + +<.<|type: string + + + +|=== +.Responses +[%header,caption=,cols=".^2a,.^14a,.^4a"] +|=== +<.<|Code + + +<.<|Description + + +<.<|Links + + + +<.<|405 + + +<.<|Invalid input + + +<.<|No Links + + + +|=== +.Security +[%header,caption=,cols=".^3a,.^4a,.^13a"] +|=== +<.<|Type + + +<.<|Name + + +<.<|Scopes + + + +<.<|**oauth2** + + +<.<|petstore_auth + + +<.<|write:pets, read:pets + + + +|=== + +=== __DELETE__ `/pet/{petId}` Deletes a pet +.Parameters +[%header,caption=,cols=".^2a,.^3a,.^10a,.^5a"] +|=== +<.<|Type + + +<.<|Name + + +<.<|Description + + +<.<|Schema + + + +<.<|**path** + + +<.<|**petId** + +__required__ + + +<.<|Pet id to delete + + +<.<|type: integer + +format: int64 + + + +<.<|**header** + + +<.<|**api_key** + +__optional__ + + +<.<| +<.<|type: string + + + +|=== +.Responses +[%header,caption=,cols=".^2a,.^14a,.^4a"] +|=== +<.<|Code + + +<.<|Description + + +<.<|Links + + + +<.<|400 + + +<.<|Invalid pet value + + +<.<|No Links + + + +|=== +.Security +[%header,caption=,cols=".^3a,.^4a,.^13a"] +|=== +<.<|Type + + +<.<|Name + + +<.<|Scopes + + + +<.<|**oauth2** + + +<.<|petstore_auth + + +<.<|write:pets, read:pets + + + +|=== + +=== __POST__ `/pet/{petId}/uploadImage` uploads an image +.Parameters +[%header,caption=,cols=".^2a,.^3a,.^10a,.^5a"] +|=== +<.<|Type + + +<.<|Name + + +<.<|Description + + +<.<|Schema + + + +<.<|**path** + + +<.<|**petId** + +__required__ + + +<.<|ID of pet to update + + +<.<|type: integer + +format: int64 + + + +|=== +.Responses +[%header,caption=,cols=".^2a,.^14a,.^4a"] +|=== +<.<|Code + + +<.<|Description + + +<.<|Links + + + +<.<|200 + + +<.<|successful operation + +.Content +application/json:: ++ + +<<_components_schemas_ApiResponse,ApiResponse>> + + +<.<|No Links + + + +|=== +.Security +[%header,caption=,cols=".^3a,.^4a,.^13a"] +|=== +<.<|Type + + +<.<|Name + + +<.<|Scopes + + + +<.<|**oauth2** + + +<.<|petstore_auth + + +<.<|write:pets, read:pets + + + +|=== + +=== __GET__ `/store/inventory` Returns pet inventories by status +Returns a map of status codes to quantities + +.Responses +[%header,caption=,cols=".^2a,.^14a,.^4a"] +|=== +<.<|Code + + +<.<|Description + + +<.<|Links + + + +<.<|200 + + +<.<|successful operation + +.Content +application/json:: ++ + +type: object + +application/xml:: ++ + +type: object + + +<.<|No Links + + + +|=== +.Security +[%header,caption=,cols=".^3a,.^4a,.^13a"] +|=== +<.<|Type + + +<.<|Name + + +<.<|Scopes + + + +<.<|**apiKey** + + +<.<|api_key + + +<.<| + +|=== + +=== __POST__ `/store/order` Place an order for a pet +.Responses +[%header,caption=,cols=".^2a,.^14a,.^4a"] +|=== +<.<|Code + + +<.<|Description + + +<.<|Links + + + +<.<|200 + + +<.<|successful operation + +.Content +application/json:: ++ + +<<_components_schemas_Order,Order>> + +application/xml:: ++ + +<<_components_schemas_Order,Order>> + + +<.<|No Links + + + +<.<|400 + + +<.<|Invalid Order + + +<.<|No Links + + + +|=== + +=== __GET__ `/store/order/{orderId}` Find purchase order by ID +For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions + +.Parameters +[%header,caption=,cols=".^2a,.^3a,.^10a,.^5a"] +|=== +<.<|Type + + +<.<|Name + + +<.<|Description + + +<.<|Schema + + + +<.<|**path** + + +<.<|**orderId** + +__required__ + + +<.<|ID of pet that needs to be fetched + + +<.<|type: string + + + +|=== +.Responses +[%header,caption=,cols=".^2a,.^14a,.^4a"] +|=== +<.<|Code + + +<.<|Description + + +<.<|Links + + + +<.<|200 + + +<.<|successful operation + +.Content +application/json:: ++ + +<<_components_schemas_Order,Order>> + +application/xml:: ++ + +<<_components_schemas_Order,Order>> + + +<.<|No Links + + + +<.<|400 + + +<.<|Invalid ID supplied + + +<.<|No Links + + + +<.<|404 + + +<.<|Order not found + + +<.<|No Links + + + +|=== + +=== __DELETE__ `/store/order/{orderId}` Delete purchase order by ID +For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + +.Parameters +[%header,caption=,cols=".^2a,.^3a,.^10a,.^5a"] +|=== +<.<|Type + + +<.<|Name + + +<.<|Description + + +<.<|Schema + + + +<.<|**path** + + +<.<|**orderId** + +__required__ + + +<.<|ID of the order that needs to be deleted + + +<.<|type: string + + + +|=== +.Responses +[%header,caption=,cols=".^2a,.^14a,.^4a"] +|=== +<.<|Code + + +<.<|Description + + +<.<|Links + + + +<.<|400 + + +<.<|Invalid ID supplied + + +<.<|No Links + + + +<.<|404 + + +<.<|Order not found + + +<.<|No Links + + + +|=== + +=== __POST__ `/user` Create user +This can only be done by the logged in user. + +.Responses +[%header,caption=,cols=".^2a,.^14a,.^4a"] +|=== +<.<|Code + + +<.<|Description + + +<.<|Links + + + +<.<|200 + + +<.<|.Content +application/json:: ++ + +type: object + +.Properties +[%header,caption=,cols=".^4a,.^16a"] +!=== +<.> + +application/xml:: ++ + +<<_components_schemas_User,User>> + + +<.<|No Links + + + +<.<|400 + + +<.<|Invalid username supplied + + +<.<|No Links + + + +<.<|404 + + +<.<|User not found + + +<.<|No Links + + + +|=== + +=== __PUT__ `/user/{username}` Updated user +This can only be done by the logged in user. + +.Parameters +[%header,caption=,cols=".^2a,.^3a,.^10a,.^5a"] +|=== +<.<|Type + + +<.<|Name + + +<.<|Description + + +<.<|Schema + + + +<.<|**path** + + +<.<|**username** + +__required__ + + +<.<|name that need to be deleted + + +<.<|type: string + + + +|=== +.Responses +[%header,caption=,cols=".^2a,.^14a,.^4a"] +|=== +<.<|Code + + +<.<|Description + + +<.<|Links + + + +<.<|400 + + +<.<|Invalid user supplied + + +<.<|No Links + + + +<.<|404 + + +<.<|User not found + + +<.<|No Links + + + +|=== + +=== __DELETE__ `/user/{username}` Delete user +This can only be done by the logged in user. + +.Parameters +[%header,caption=,cols=".^2a,.^3a,.^10a,.^5a"] +|=== +<.<|Type + + +<.<|Name + + +<.<|Description + + +<.<|Schema + + + +<.<|**path** + + +<.<|**username** + +__required__ + + +<.<|The name that needs to be deleted + + +<.<|type: string + + + +|=== +.Responses +[%header,caption=,cols=".^2a,.^14a,.^4a"] +|=== +<.<|Code + + +<.<|Description + + +<.<|Links + + + +<.<|400 + + +<.<|Invalid username supplied + + +<.<|No Links + + + +<.<|404 + + +<.<|User not found + + +<.<|No Links + + + +|=== + +[[_components]] +== Components +[[_components_schemas]] +=== Schemas +[[_components_schemas_user]] +==== User + +.Properties +[%header,caption=,cols=".^4a,.^16a"] +|=== +<.<|Name + + +<.<|Schema + + + +<.<|id +__optional__ + + +<.<|type: integer + +format: int64 + + + +<.<|username +__optional__ + + +<.<|type: string + + + +<.<|firstName +__optional__ + + +<.<|type: string + + + +<.<|lastName +__optional__ + + +<.<|type: string + + + +<.<|email +__optional__ + + +<.<|type: string + + + +<.<|password +__optional__ + + +<.<|type: string + + + +<.<|phone +__optional__ + + +<.<|type: string + + + +<.<|userStatus +__optional__ + + +<.<|User Status + +type: integer + +format: int32 + + + +|=== +[[_components_schemas_category]] +==== Category + +.Properties +[%header,caption=,cols=".^4a,.^16a"] +|=== +<.<|Name + + +<.<|Schema + + + +<.<|id +__optional__ + + +<.<|type: integer + +format: int64 + + + +<.<|name +__optional__ + + +<.<|type: string + + + +|=== +[[_components_schemas_pet]] +==== Pet + +.Properties +[%header,caption=,cols=".^4a,.^16a"] +|=== +<.<|Name + + +<.<|Schema + + + +<.<|id +__optional__ + + +<.<|type: integer + +format: int64 + + + +<.<|category +__optional__ + + +<.<|<<_components_schemas_Category,Category>> + + + +<.<|name +__required__ + + +<.<|type: string + + + +<.<|photoUrls +__required__ + + +<.<|type: array + + + +<.<|tags +__optional__ + + +<.<|type: array + + + +<.<|status +__optional__ + + +<.<|pet status in the store + +type: string + + + +|=== +[[_components_schemas_tag]] +==== Tag + +.Properties +[%header,caption=,cols=".^4a,.^16a"] +|=== +<.<|Name + + +<.<|Schema + + + +<.<|id +__optional__ + + +<.<|type: integer + +format: int64 + + + +<.<|name +__optional__ + + +<.<|type: string + + + +|=== +[[_components_schemas_order]] +==== Order + +.Properties +[%header,caption=,cols=".^4a,.^16a"] +|=== +<.<|Name + + +<.<|Schema + + + +<.<|id +__optional__ + + +<.<|type: integer + +format: int64 + + + +<.<|petId +__optional__ + + +<.<|type: integer + +format: int64 + + + +<.<|quantity +__optional__ + + +<.<|type: integer + +format: int32 + + + +<.<|shipDate +__optional__ + + +<.<|type: string + +format: date-time + + + +<.<|status +__optional__ + + +<.<|Order Status + +type: string + + + +<.<|complete +__optional__ + + +<.<|type: boolean + + + +|=== +[[_components_schemas_petarray]] +==== PetArray + +type: array + +.Responses +[%header,caption=,cols=".^2a,.^14a,.^4a"] +|=== +<.<|Code + + +<.<|Description + + +<.<|Links + + + +<.<|veryBad + + +<.<|failed + + +<.<|No Links + + + +|=== + +== Security +[%header,caption=,cols=".^3a,.^4a,.^13a"] +|=== +<.<|Type + + +<.<|Name + + +<.<|Scopes + + + +<.<|**oauth2** + + +<.<|foo + + +<.<|bar, baz + + + +<.<|**oauth2** + + +<.<|a + + +<.<|b, c + + + +|=== + diff --git a/openapi2markup/src/test/resources/asciidoc/simple.adoc b/openapi2markup/src/test/resources/asciidoc/simple.adoc new file mode 100644 index 00000000..ad0b255b --- /dev/null +++ b/openapi2markup/src/test/resources/asciidoc/simple.adoc @@ -0,0 +1,276 @@ += Simple Inventory API + +v1.0.0 +:revnumber: 1.0.0 +:openapi: 3.0.0 +:authorcount: 1 +:email: you@your-company.com + +== Overview +This is a simple API + +http://www.apache.org/licenses/LICENSE-2.0.html[Apache 2.0] + +== Tags +admins:: +Secured Admin-only calls +developers:: +Operations available to regular developers + +== Servers +=== __Server__: / + +== Paths +=== __GET__ `/inventory` searches inventory +By passing in the appropriate options, you can search for +available inventory in the system + +.Parameters +[%header,caption=,cols=".^2a,.^3a,.^10a,.^5a"] +|=== +<.<|Type + + +<.<|Name + + +<.<|Description + + +<.<|Schema + + + +<.<|**query** + + +<.<|**searchString** + +__optional__ + + +<.<|pass an optional search string for looking up inventory + + +<.<|type: string + + + +<.<|**query** + + +<.<|**limit** + +__optional__ + + +<.<|maximum number of records to return + + +<.<|minimum: 0 + +type: integer + +maximum: 50 + +format: int32 + + + +<.<|**query** + + +<.<|**skip** + +__optional__ + + +<.<|number of records to skip for pagination + + +<.<|minimum: 0 + +type: integer + +format: int32 + + + +|=== +.Responses +[%header,caption=,cols=".^2a,.^14a,.^4a"] +|=== +<.<|Code + + +<.<|Description + + +<.<|Links + + + +<.<|200 + + +<.<|search results matching criteria + +.Content +application/json:: ++ + +type: array + + +<.<|No Links + + + +<.<|400 + + +<.<|bad input parameter + + +<.<|No Links + + + +|=== + +=== __POST__ `/inventory` adds an inventory item +Adds an item to the system + +.Responses +[%header,caption=,cols=".^2a,.^14a,.^4a"] +|=== +<.<|Code + + +<.<|Description + + +<.<|Links + + + +<.<|201 + + +<.<|item created + + +<.<|No Links + + + +<.<|400 + + +<.<|invalid input, object invalid + + +<.<|No Links + + + +<.<|409 + + +<.<|an existing item already exists + + +<.<|No Links + + + +|=== + +[[_components]] +== Components +[[_components_schemas]] +=== Schemas +[[_components_schemas_inventoryitem]] +==== InventoryItem + +type: object + +.Properties +[%header,caption=,cols=".^4a,.^16a"] +|=== +<.<|Name + + +<.<|Schema + + + +<.<|id +__required__ + + +<.<|type: string + +format: uuid + + + +<.<|name +__required__ + + +<.<|type: string + + + +<.<|releaseDate +__required__ + + +<.<|type: string + +format: date-time + + + +<.<|manufacturer +__required__ + + +<.<|<<_components_schemas_Manufacturer,Manufacturer>> + + + +|=== +[[_components_schemas_manufacturer]] +==== Manufacturer + +type: object + +.Properties +[%header,caption=,cols=".^4a,.^16a"] +|=== +<.<|Name + + +<.<|Schema + + + +<.<|name +__required__ + + +<.<|type: string + + + +<.<|homePage +__optional__ + + +<.<|type: string + +format: url + + + +<.<|phone +__optional__ + + +<.<|type: string + + + +|=== + diff --git a/openapi2markup/src/test/resources/expected/asciidoc/to_folder/definitions.adoc b/openapi2markup/src/test/resources/expected/asciidoc/to_folder/definitions.adoc new file mode 100644 index 00000000..9315f9db --- /dev/null +++ b/openapi2markup/src/test/resources/expected/asciidoc/to_folder/definitions.adoc @@ -0,0 +1,351 @@ + +[[_components]] +== Components +[[_components_schemas]] +=== Schemas +[[_components_schemas_user]] +==== User + +.Properties +[%header,caption=,cols=".^4a,.^16a,.^4a"] +|=== +<.<|Name + + +<.<|Description + + +<.<|Schema + + + +<.<|id +__optional__ + + +<.<| +<.<|integer (int64) + + + +<.<|username +__optional__ + + +<.<| +<.<|string + + + +<.<|firstName +__optional__ + + +<.<| +<.<|string + + + +<.<|lastName +__optional__ + + +<.<| +<.<|string + + + +<.<|email +__optional__ + + +<.<| +<.<|string + + + +<.<|password +__optional__ + + +<.<| +<.<|string + + + +<.<|phone +__optional__ + + +<.<| +<.<|string + + + +<.<|userStatus +__optional__ + + +<.<|User Status + + +<.<|integer (int32) + + + +|=== +[[_components_schemas_category]] +==== Category + +.Properties +[%header,caption=,cols=".^4a,.^16a,.^4a"] +|=== +<.<|Name + + +<.<|Description + + +<.<|Schema + + + +<.<|id +__optional__ + + +<.<| +<.<|integer (int64) + + + +<.<|name +__optional__ + + +<.<|The name of the category + +**Maximum Length**: 255 + +**Minimum Length**: 0 + +**Default**: DefaultCategory + + +<.<|string + + + +|=== +[[_components_schemas_pet]] +==== Pet + +.Properties +[%header,caption=,cols=".^4a,.^16a,.^4a"] +|=== +<.<|Name + + +<.<|Description + + +<.<|Schema + + + +<.<|id +__optional__ + + +<.<| +<.<|integer (int64) + + + +<.<|category +__optional__ + + +<.<| +<.<|<<_components_schemas_category>> + + + +<.<|name +__required__ + + +<.<| +<.<|string + + + +<.<|photoUrls +__required__ + + +<.<| +<.<|< string > array + + + +<.<|tags +__optional__ + + +<.<| +<.<|< <<_components_schemas_tag>> + > array + + + +<.<|status +__optional__ + + +<.<|pet status in the store, + + +<.<|enum (Dead,Alive) + + + +|=== +[[_components_schemas_tag]] +==== Tag + +.Properties +[%header,caption=,cols=".^4a,.^16a,.^4a"] +|=== +<.<|Name + + +<.<|Description + + +<.<|Schema + + + +<.<|id +__optional__ + + +<.<| +<.<|integer (int64) + + + +<.<|name +__optional__ + + +<.<| +<.<|string + + + +|=== +[[_components_schemas_order]] +==== Order + +.Properties +[%header,caption=,cols=".^4a,.^16a,.^4a"] +|=== +<.<|Name + + +<.<|Description + + +<.<|Schema + + + +<.<|id +__optional__ + + +<.<| +<.<|integer (int64) + + + +<.<|petId +__optional__ + + +<.<| +<.<|integer (int64) + + + +<.<|quantity +__optional__ + + +<.<|**Maximum**: 10000 + +**Minimum**: 0 + +**Default**: 0 + + +<.<|integer (int32) + + + +<.<|shipDate +__optional__ + + +<.<| +<.<|string (date-time) + + + +<.<|status +__optional__ + + +<.<|Order Status + + +<.<|enum (Ordered,Cancelled) + + + +<.<|complete +__optional__ + + +<.<| +<.<|boolean + + + +|=== + +[[_components_parameters]] +=== Responses +.Responses +[%header,caption=,cols=".^2a,.^14a,.^4a"] +|=== +<.<|Code + + +<.<|Description + + +<.<|Links + + + +<.<|InvalidId + + +<.<|Invalid ID supplied + + +<.<|No Links + + + +|=== + diff --git a/openapi2markup/src/test/resources/expected/asciidoc/to_folder/overview.adoc b/openapi2markup/src/test/resources/expected/asciidoc/to_folder/overview.adoc new file mode 100644 index 00000000..9ff8d78f --- /dev/null +++ b/openapi2markup/src/test/resources/expected/asciidoc/to_folder/overview.adoc @@ -0,0 +1,30 @@ += Swagger Petstore +apiteam@swagger.io +v1.0.0 +:revnumber: 1.0.0 +:openapi: 3.0.0 +:author: apiteam@swagger.io +:authorcount: 1 + + +== Overview +This is a sample server Petstore server. + +[Learn about Swagger](http://swagger.io) or join the IRC channel `#swagger` on irc.freenode.net. + +For this sample, you can use the api key `special-key` to test the authorization filters + +http://helloreverb.com/terms/[Terms Of Service] + +http://www.apache.org/licenses/LICENSE-2.0.html[Apache 2.0] + +http://swagger.io[Find out more about Swagger] + +== Tags +pet:: +Pet resource +store:: +Store resource +user:: +User resource + diff --git a/openapi2markup/src/test/resources/expected/asciidoc/to_folder/paths.adoc b/openapi2markup/src/test/resources/expected/asciidoc/to_folder/paths.adoc new file mode 100644 index 00000000..7e402bec --- /dev/null +++ b/openapi2markup/src/test/resources/expected/asciidoc/to_folder/paths.adoc @@ -0,0 +1,1396 @@ + +== Paths +=== __PUT__ `/pets` Update an existing pet +.Responses +[%header,caption=,cols=".^2a,.^14a,.^4a"] +|=== +<.<|Code + + +<.<|Description + + +<.<|Links + + + +<.<|400 + + +<.<|Invalid ID supplied + + +<.<|No Links + + + +<.<|404 + + +<.<|Pet not found + + +<.<|No Links + + + +<.<|405 + + +<.<|Validation exception + + +<.<|No Links + + + +|=== +[%header,caption=,cols=".^3a,.^4a,.^13a"] +|=== +<.<|Type + + +<.<|Name + + +<.<|Scopes + + + +<.<|**oauth2** + + +<.<|petstore_auth + + +<.<|write_pets, read_pets + + + +|=== + +=== __POST__ `/pets` Add a new pet to the store +.Responses +[%header,caption=,cols=".^2a,.^14a,.^4a"] +|=== +<.<|Code + + +<.<|Description + + +<.<|Links + + + +<.<|405 + + +<.<|Invalid input + + +<.<|No Links + + + +|=== +[%header,caption=,cols=".^3a,.^4a,.^13a"] +|=== +<.<|Type + + +<.<|Name + + +<.<|Scopes + + + +<.<|**oauth2** + + +<.<|petstore_auth + + +<.<|write_pets, read_pets + + + +|=== + +=== __GET__ `/pets/findByStatus` Finds Pets by status +Multiple status values can be provided with comma seperated strings + +.Parameters +[%header,caption=,cols=".^2a,.^3a,.^10a,.^5a"] +|=== +<.<|Type + + +<.<|Name + + +<.<|Description + + +<.<|Schema + + + +<.<|**query** + + +<.<|**status** + +__optional__ + + +<.<|Status values that need to be considered for filter + + +<.<|< string > array + + + +|=== +.Responses +[%header,caption=,cols=".^2a,.^14a,.^4a"] +|=== +<.<|Code + + +<.<|Description + + +<.<|Links + + + +<.<|200 + + +<.<|successful operation + +.Headers +[%header,caption=,cols=".^2a,.^14a,.^4a"] +!=== +<. array + + + +|=== +.Responses +[%header,caption=,cols=".^2a,.^14a,.^4a"] +|=== +<.<|Code + + +<.<|Description + + +<.<|Links + + + +<.<|200 + + +<.<|successful operation + +.Headers +[%header,caption=,cols=".^2a,.^14a,.^4a"] +!=== +<. 10 or nonintegers will simulate API error conditions + +.Parameters +[%header,caption=,cols=".^2a,.^3a,.^10a,.^5a"] +|=== +<.<|Type + + +<.<|Name + + +<.<|Description + + +<.<|Schema + + + +<.<|**path** + + +<.<|**petId** + +__required__ + + +<.<|ID of pet that needs to be fetched + + +<.<|integer (int64) + + + +|=== +.Responses +[%header,caption=,cols=".^2a,.^14a,.^4a"] +|=== +<.<|Code + + +<.<|Description + + +<.<|Links + + + +<.<|200 + + +<.<|successful operation + +.Headers +[%header,caption=,cols=".^2a,.^14a,.^4a"] +!=== +<. 10. Other values will generated exceptions + +.Parameters +[%header,caption=,cols=".^2a,.^3a,.^10a,.^5a"] +|=== +<.<|Type + + +<.<|Name + + +<.<|Description + + +<.<|Schema + + + +<.<|**path** + + +<.<|**orderId** + +__required__ + + +<.<|ID of pet that needs to be fetched + + +<.<|string + + + +|=== +.Responses +[%header,caption=,cols=".^2a,.^14a,.^4a"] +|=== +<.<|Code + + +<.<|Description + + +<.<|Links + + + +<.<|200 + + +<.<|successful operation + +.Headers +[%header,caption=,cols=".^2a,.^14a,.^4a"] +!=== +<. + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + + diff --git a/openapi2markup/src/test/resources/open_api/petstore.yaml b/openapi2markup/src/test/resources/open_api/petstore.yaml new file mode 100644 index 00000000..c0fe3019 --- /dev/null +++ b/openapi2markup/src/test/resources/open_api/petstore.yaml @@ -0,0 +1,732 @@ +openapi: 3.0.0 +servers: + - url: 'http://localhost:8000/v2/api' +info: + description: >- + This is a sample server Petstore server. You can find out more about + Swagger at http://swagger.io or on + irc.freenode.net, #swagger. For this sample, you can use the api key + "special-key" to test the authorization filters + version: 1.0.0 + title: Swagger Petstore + termsOfService: 'http://swagger.io/terms/' + contact: + name: apiteam@swagger.io + license: + name: Apache 2.0 + url: 'http://www.apache.org/licenses/LICENSE-2.0.html' +externalDocs: + description: Find more info here + url: 'https://swagger.io' +tags: + - name: pet + description: Pet Operations + externalDocs: + url: 'http://swagger.io' + - name: user + description: All about the Users +paths: + /pet/add: + post: + tags: + - pet + summary: Add a new pet to the store + description: '' + operationId: createPet + responses: + '200': + description: This is a sample + content: + text/plain: + schema: + type: string + example: 'whoa!' + '405': + description: Invalid input + security: + - petstore_auth: + - 'write:pets' + - 'read:pets' + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/Pet' + description: Pet object that needs to be added to the store + /pet: + post: + tags: + - pet + summary: Add a new pet to the store + description: '' + operationId: addPet + responses: + '405': + description: Invalid input + security: + - petstore_auth: + - 'write:pets' + - 'read:pets' + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/Pet' + application/xml: + schema: + $ref: '#/components/schemas/Pet' + description: Pet object that needs to be added to the store + put: + tags: + - pet + summary: Update an existing pet + description: '' + operationId: updatePet + responses: + '400': + description: Invalid ID supplied + '404': + description: Pet not found + '405': + description: Validation exception + security: + - petstore_auth: + - 'write:pets' + - 'read:pets' + requestBody: + $ref: '#/components/requestBodies/Pet' + /pet/findByStatus: + get: + tags: + - pet + summary: Finds Pets by status + description: Multiple status values can be provided with comma seperated strings + operationId: findPetsByStatus + parameters: + - name: status + in: query + description: Status values that need to be considered for filter + required: false + style: pipeDelimited + schema: + type: array + items: + type: string + default: available + responses: + '200': + description: successful operation + content: + application/json: + schema: + $ref: '#/components/schemas/PetArray' + application/xml: + schema: + $ref: '#/components/schemas/PetArray' + '400': + description: Invalid status value + security: + - petstore_auth: + - 'write:pets' + - 'read:pets' + /pet/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 + parameters: + - name: tags + in: query + description: Tags to filter by + required: false + explode: true + schema: + type: array + items: + type: string + responses: + '200': + description: successful operation + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/Pet' + application/xml: + schema: + type: array + items: + $ref: '#/components/schemas/Pet' + '400': + description: Invalid tag value + security: + - petstore_auth: + - 'write:pets' + - 'read:pets' + '/pet/{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 + parameters: + - name: petId + in: path + description: ID of pet that needs to be fetched + required: true + schema: + type: integer + format: int64 + responses: + '200': + description: successful operation + content: + application/json: + schema: + $ref: '#/components/schemas/Pet' + application/xml: + schema: + $ref: '#/components/schemas/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 + parameters: + - name: petId + in: path + description: ID of pet that needs to be updated + required: true + schema: + type: string + responses: + '405': + description: Invalid input + security: + - petstore_auth: + - 'write:pets' + - 'read:pets' + requestBody: + content: + application/x-www-form-urlencoded: + schema: + type: object + properties: + name: + description: Updated name of the pet + type: string + status: + description: Updated status of the pet + type: string + delete: + tags: + - pet + summary: Deletes a pet + description: '' + operationId: deletePet + parameters: + - name: api_key + in: header + description: '' + required: false + schema: + type: string + - name: petId + in: path + description: Pet id to delete + required: true + schema: + type: integer + format: int64 + responses: + '400': + description: Invalid pet value + security: + - petstore_auth: + - 'write:pets' + - 'read:pets' + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/Pet' + description: Pet extra params that needs to be deleted + '/pet/{petId}/uploadImage': + post: + tags: + - pet + summary: uploads an image + description: '' + operationId: uploadFile + parameters: + - name: petId + in: path + description: ID of pet to update + required: true + schema: + type: integer + format: int64 + responses: + '200': + description: successful operation + content: + application/json: + schema: + $ref: "#/components/schemas/ApiResponse" + security: + - petstore_auth: + - 'write:pets' + - 'read:pets' + requestBody: + content: + multipart/form-data: + schema: + type: object + properties: + additionalMetadata: + description: Additional data to pass to server + type: string + file: + description: file to upload + type: string + format: binary + /store/inventory: + get: + tags: + - store + summary: Returns pet inventories by status + description: Returns a map of status codes to quantities + operationId: get inventory+1 + responses: + '200': + description: successful operation + content: + application/json: + schema: + type: object + additionalProperties: + type: integer + format: int32 + application/xml: + schema: + type: object + additionalProperties: + type: integer + format: int32 + security: + - api_key: [] + /store/order: + post: + tags: + - store + summary: Place an order for a pet + description: '' + operationId: placeOrder + responses: + '200': + description: successful operation + content: + application/json: + schema: + $ref: '#/components/schemas/Order' + application/xml: + schema: + $ref: '#/components/schemas/Order' + '400': + description: Invalid Order + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/Order' + description: order placed for purchasing the pet + '/store/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 + parameters: + - name: orderId + in: path + description: ID of pet that needs to be fetched + required: true + schema: + type: string + responses: + '200': + description: successful operation + content: + application/json: + schema: + $ref: '#/components/schemas/Order' + application/xml: + schema: + $ref: '#/components/schemas/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 + parameters: + - name: orderId + in: path + description: ID of the order that needs to be deleted + required: true + schema: + type: string + responses: + '400': + description: Invalid ID supplied + '404': + description: Order not found + /user: + post: + tags: + - user + summary: Create user + description: This can only be done by the logged in user. + operationId: createUser + responses: + 200: + content: + 'application/json': + schema: + type: object + properties: + id: + # default is text/plain + type: string + format: text + examples: + foo: + value: {"foo": "bar"} + bar: + summary: A bar example + value: {"bar": "baz"} + default: + description: successful operation + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/User' + description: Created user object + /user/createWithArray: + post: + tags: + - user + summary: Creates list of users with given input array + description: '' + operationId: createUsersWithArrayInput + responses: + default: + description: successful operation + requestBody: + $ref: '#/components/requestBodies/UserArray' + /user/createWithList: + post: + tags: + - user + summary: Creates list of users with given input array + description: '' + operationId: createUsersWithListInput + responses: + default: + description: successful operation + requestBody: + $ref: '#/components/requestBodies/UserArray' + /user/login: + get: + tags: + - user + security: + - https + summary: Logs user into the system + description: '' + operationId: loginUser + parameters: + - name: username + in: query + description: The user name for login + required: false + schema: + type: string + - name: password + in: query + description: The password for login in clear text + required: false + schema: + type: string + responses: + '200': + description: successful operation + content: + application/json: + schema: + type: string + application/xml: + schema: + type: string + '400': + description: Invalid username/password supplied + /user/logout: + get: + tags: + - user + security: + - https + summary: Logs out current logged in user session + description: '' + operationId: logoutUser + responses: + default: + description: successful operation + '/user/{username}': + get: + tags: + - user + summary: Get user by user name + description: '' + operationId: getUserByName + parameters: + - name: username + in: path + description: 'The name that needs to be fetched. Use user1 for testing.' + required: true + schema: + type: string + responses: + '200': + description: successful operation + content: + application/json: + schema: + $ref: '#/components/schemas/User' + application/xml: + schema: + $ref: '#/components/schemas/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 + parameters: + - name: username + in: path + description: name that need to be deleted + required: true + schema: + type: string + responses: + '400': + description: Invalid user supplied + '404': + description: User not found + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/User' + description: Updated user object + delete: + tags: + - user + summary: Delete user + description: This can only be done by the logged in user. + operationId: deleteUser + parameters: + - name: username + in: path + description: The name that needs to be deleted + required: true + schema: + type: string + responses: + '400': + description: Invalid username supplied + '404': + description: User not found +security: + - foo: + - bar + - baz + a: + - b + - c +components: + parameters: + sharedSkip: + name: skip + in: query + description: Results to skip + required: false + schema: + type: integer + format: int32 + responses: + veryBad: + description: failed + requestBodies: + UserArray: + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/User' + description: List of user object + Pet: + content: + application/json: + schema: + $ref: '#/components/schemas/Pet' + application/xml: + schema: + $ref: '#/components/schemas/Pet' + description: Pet object that needs to be added to the store + securitySchemes: + api_key: + type: apiKey + name: api_key + in: header + petstore_auth: + type: oauth2 + flows: + implicit: + authorizationUrl: 'http://petstore.swagger.io/api/oauth/dialog' + scopes: + 'write:pets': modify pets in your account + 'read:pets': read your pets + schemas: + User: + properties: + id: + type: integer + format: int64 + 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 + xml: + name: User + Category: + properties: + id: + type: integer + format: int64 + name: + type: string + xml: + name: Category + Pet: + required: + - name + - photoUrls + properties: + id: + type: integer + format: int64 + category: + $ref: '#/components/schemas/Category' + name: + type: string + example: doggie + photoUrls: + type: array + xml: + name: photoUrl + wrapped: true + items: + type: string + tags: + type: array + xml: + name: tag + wrapped: true + items: + $ref: '#/components/schemas/Tag' + status: + type: string + description: pet status in the store + xml: + name: Pet + Tag: + properties: + id: + type: integer + format: int64 + name: + type: string + xml: + name: Tag + 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 + xml: + name: Order + PetArray: + type: array + items: + $ref: '#/components/schemas/Pet' diff --git a/openapi2markup/src/test/resources/open_api/simple.yaml b/openapi2markup/src/test/resources/open_api/simple.yaml new file mode 100644 index 00000000..6ec4a0f8 --- /dev/null +++ b/openapi2markup/src/test/resources/open_api/simple.yaml @@ -0,0 +1,115 @@ +openapi: 3.0.0 +info: + description: This is a simple API + version: "1.0.0" + title: Simple Inventory API + contact: + email: you@your-company.com + license: + name: Apache 2.0 + url: 'http://www.apache.org/licenses/LICENSE-2.0.html' +tags: + - name: admins + description: Secured Admin-only calls + - name: developers + description: Operations available to regular developers +paths: + /inventory: + get: + tags: + - developers + summary: searches inventory + operationId: searchInventory + description: | + By passing in the appropriate options, you can search for + available inventory in the system + parameters: + - in: query + name: searchString + description: pass an optional search string for looking up inventory + required: false + schema: + type: string + - in: query + name: skip + description: number of records to skip for pagination + schema: + type: integer + format: int32 + minimum: 0 + - in: query + name: limit + description: maximum number of records to return + schema: + type: integer + format: int32 + minimum: 0 + maximum: 50 + responses: + '200': + description: search results matching criteria + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/InventoryItem' + '400': + description: bad input parameter + post: + tags: + - admins + summary: adds an inventory item + operationId: addInventory + description: Adds an item to the system + responses: + '201': + description: item created + '400': + description: 'invalid input, object invalid' + '409': + description: an existing item already exists + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/InventoryItem' + description: Inventory item to add +components: + schemas: + InventoryItem: + type: object + required: + - id + - name + - manufacturer + - releaseDate + properties: + id: + type: string + format: uuid + example: d290f1ee-6c54-4b01-90e6-d701748f0851 + name: + type: string + example: Widget Adapter + releaseDate: + type: string + format: date-time + example: '2016-08-29T09:12:33.001Z' + manufacturer: + $ref: '#/components/schemas/Manufacturer' + Manufacturer: + required: + - name + properties: + name: + type: string + example: ACME Corporation + homePage: + type: string + format: url + example: 'https://www.acme-corp.com' + phone: + type: string + example: 408-867-5309 + type: object diff --git a/openapi2markup/src/test/resources/yaml/swagger_petstore.yaml b/openapi2markup/src/test/resources/yaml/swagger_petstore.yaml new file mode 100644 index 00000000..25251e7d --- /dev/null +++ b/openapi2markup/src/test/resources/yaml/swagger_petstore.yaml @@ -0,0 +1,693 @@ +openapi: 3.0.0 +info: + description: > + This is a sample server Petstore server. + + + [Learn about Swagger](http://swagger.io) or join the IRC channel `#swagger` on irc.freenode.net. + + + For this sample, you can use the api key `special-key` to test the authorization filters + version: 1.0.0 + title: Swagger Petstore + termsOfService: http://helloreverb.com/terms/ + contact: + name: apiteam@swagger.io + license: + name: Apache 2.0 + url: http://www.apache.org/licenses/LICENSE-2.0.html +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 + requestBody: + $ref: "#/components/requestBodies/Pet" + responses: + "405": + description: Invalid input + security: + - petstore_auth: + - write_pets + - read_pets + put: + tags: + - pet + summary: Update an existing pet + description: "" + operationId: updatePet + requestBody: + $ref: "#/components/requestBodies/Pet" + responses: + "400": + $ref: "#/components/responses/InvalidId" + "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 + parameters: + - in: query + name: status + description: Status values that need to be considered for filter + required: false + explode: true + schema: + type: array + items: + type: string + responses: + "200": + description: successful operation + headers: + X-Rate-Limit-Limit: + description: The number of allowed requests in the current period + schema: + type: integer + X-Rate-Limit-Remaining: + description: The number of remaining requests in the current period + schema: + type: integer + X-Rate-Limit-Reset: + description: The number of seconds left in the current period + schema: + type: integer + content: + application/json: + schema: + type: array + items: + $ref: "#/components/schemas/Pet" + application/xml: + schema: + type: array + items: + $ref: "#/components/schemas/Pet" + "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 + parameters: + - in: query + name: tags + description: Tags to filter by + required: false + example: adorable + explode: true + schema: + type: array + items: + type: string + responses: + "200": + description: successful operation + headers: + X-Rate-Limit-Limit: + description: The number of allowed requests in the current period + schema: + type: integer + X-Rate-Limit-Remaining: + description: The number of remaining requests in the current period + schema: + type: integer + X-Rate-Limit-Reset: + description: The number of seconds left in the current period + schema: + type: integer + content: + application/json: + schema: + type: array + items: + $ref: "#/components/schemas/Pet" + application/xml: + schema: + type: array + items: + $ref: "#/components/schemas/Pet" + "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 + parameters: + - in: path + name: petId + description: ID of pet that needs to be fetched + required: true + example: 30 + schema: + type: integer + format: int64 + responses: + "200": + description: successful operation + headers: + X-Rate-Limit-Limit: + description: The number of allowed requests in the current period + schema: + type: integer + X-Rate-Limit-Remaining: + description: The number of remaining requests in the current period + schema: + type: integer + X-Rate-Limit-Reset: + description: The number of seconds left in the current period + schema: + type: integer + content: + application/json: + schema: + $ref: "#/components/schemas/Pet" + application/xml: + schema: + $ref: "#/components/schemas/Pet" + "400": + $ref: "#/components/responses/InvalidId" + "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 + parameters: + - in: path + name: petId + description: ID of pet that needs to be updated + required: true + schema: + type: string + requestBody: + content: + application/x-www-form-urlencoded: + schema: + type: object + properties: + name: + description: Updated name of the pet + type: string + status: + description: Updated status of the pet + type: string + required: + - name + - status + responses: + "405": + description: Invalid input + security: + - petstore_auth: + - write_pets + - read_pets + delete: + tags: + - pet + summary: Deletes a pet + description: "" + operationId: deletePet + parameters: + - in: header + name: api_key + description: "" + required: true + schema: + type: string + - in: path + name: petId + description: Pet id to delete + required: true + schema: + 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 + requestBody: + content: + application/json: + schema: + $ref: "#/components/schemas/Order" + description: order placed for purchasing the pet + responses: + "200": + description: successful operation + headers: + X-Rate-Limit-Limit: + description: The number of allowed requests in the current period + schema: + type: integer + X-Rate-Limit-Remaining: + description: The number of remaining requests in the current period + schema: + type: integer + X-Rate-Limit-Reset: + description: The number of seconds left in the current period + schema: + type: integer + content: + application/json: + schema: + $ref: "#/components/schemas/Order" + application/xml: + schema: + $ref: "#/components/schemas/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 + parameters: + - in: path + name: orderId + description: ID of pet that needs to be fetched + required: true + schema: + type: string + responses: + "200": + description: successful operation + headers: + X-Rate-Limit-Limit: + description: The number of allowed requests in the current period + schema: + type: integer + X-Rate-Limit-Remaining: + description: The number of remaining requests in the current period + schema: + type: integer + X-Rate-Limit-Reset: + description: The number of seconds left in the current period + schema: + type: integer + content: + application/json: + schema: + $ref: "#/components/schemas/Order" + application/xml: + schema: + $ref: "#/components/schemas/Order" + "400": + $ref: "#/components/responses/InvalidId" + "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 + parameters: + - in: path + name: orderId + description: ID of the order that needs to be deleted + required: true + schema: + type: string + responses: + "400": + $ref: "#/components/responses/InvalidId" + "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 + requestBody: + content: + application/json: + schema: + $ref: "#/components/schemas/User" + description: Created user object + responses: + default: + description: successful operation + /users/createWithArray: + post: + tags: + - user + summary: Creates list of users with given input array + description: "" + operationId: createUsersWithArrayInput + requestBody: + $ref: "#/components/requestBodies/UserArray" + responses: + default: + description: successful operation + /users/createWithList: + post: + tags: + - user + summary: Creates list of users with given input array + description: "" + operationId: createUsersWithListInput + requestBody: + $ref: "#/components/requestBodies/UserArray" + responses: + default: + description: successful operation + /users/login: + get: + tags: + - user + summary: Logs user into the system + description: "" + operationId: loginUser + parameters: + - in: query + name: username + description: The user name for login + required: false + schema: + type: string + - in: query + name: password + description: The password for login in clear text + required: false + schema: + type: string + responses: + "200": + description: successful operation + headers: + X-Rate-Limit-Limit: + description: The number of allowed requests in the current period + schema: + type: integer + X-Rate-Limit-Remaining: + description: The number of remaining requests in the current period + schema: + type: integer + X-Rate-Limit-Reset: + description: The number of seconds left in the current period + schema: + type: integer + content: + application/json: + schema: + type: string + application/xml: + 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 + responses: + default: + description: successful operation + "/users/{username}": + get: + tags: + - user + summary: Get user by user name + description: "" + operationId: getUserByName + parameters: + - in: path + name: username + description: The name that needs to be fetched. Use user1 for testing. + required: true + schema: + type: string + responses: + "200": + description: successful operation + headers: + X-Rate-Limit-Limit: + description: The number of allowed requests in the current period + schema: + type: integer + X-Rate-Limit-Remaining: + description: The number of remaining requests in the current period + schema: + type: integer + X-Rate-Limit-Reset: + description: The number of seconds left in the current period + schema: + type: integer + content: + application/json: + schema: + $ref: "#/components/schemas/User" + application/xml: + schema: + $ref: "#/components/schemas/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 + parameters: + - in: path + name: username + description: name that need to be deleted + required: true + schema: + type: string + requestBody: + content: + application/json: + schema: + $ref: "#/components/schemas/User" + description: Updated user object + 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 + parameters: + - in: path + name: username + description: The name that needs to be deleted + required: true + schema: + type: string + responses: + "400": + description: Invalid username supplied + "404": + description: User not found +externalDocs: + description: Find out more about Swagger + url: http://swagger.io +servers: + - url: http://petstore.swagger.io/v2 +components: + responses: + InvalidId: + description: Invalid ID supplied + requestBodies: + UserArray: + content: + application/json: + schema: + type: array + items: + $ref: "#/components/schemas/User" + description: List of user object + Pet: + content: + application/json: + schema: + $ref: "#/components/schemas/Pet" + application/xml: + schema: + $ref: "#/components/schemas/Pet" + description: Pet object that needs to be added to the store + securitySchemes: + api_key: + type: apiKey + name: api_key + in: header + description: This is another description + petstore_auth: + type: oauth2 + description: This is a standard oauth flow + flows: + implicit: + authorizationUrl: http://petstore.swagger.io/api/oauth/dialog + scopes: + write_pets: modify pets in your account + read_pets: read your pets + schemas: + User: + type: object + properties: + id: + type: integer + format: int64 + 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 + Category: + type: object + properties: + id: + type: integer + format: int64 + name: + type: string + description: The name of the category + minLength: 0 + maxLength: 255 + pattern: "[A-Za-zäöüÄÖÜß]{0,255}" + default: DefaultCategory + example: FoobarCategory + Pet: + type: object + required: + - name + - photoUrls + properties: + id: + type: integer + format: int64 + category: + $ref: "#/components/schemas/Category" + name: + type: string + example: doggie + photoUrls: + type: array + items: + type: string + tags: + type: array + items: + $ref: "#/components/schemas/Tag" + status: + type: string + description: pet status in the store, + enum: + - Dead + - Alive + Tag: + type: object + properties: + id: + type: integer + format: int64 + name: + type: string + Order: + type: object + properties: + id: + type: integer + format: int64 + petId: + type: integer + format: int64 + quantity: + type: integer + format: int32 + minimum: 0 + maximum: 10000 + default: 0 + example: 10 + shipDate: + type: string + format: date-time + status: + type: string + description: Order Status + enum: + - Ordered + - Cancelled + complete: + type: boolean \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 97408e0e..7efc0173 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,6 +1,10 @@ rootProject.name = 'swagger2markup' +include 'swagger2markup-asciidoc' include 'swagger2markup-bom' include 'swagger2markup-builder' -include 'swagger2markup-core' include 'swagger2markup-documentation' +include 'swagger2markup' +include 'swagger2markup-core' +include 'openapi2markup' + diff --git a/swagger2markup-asciidoc/build.gradle b/swagger2markup-asciidoc/build.gradle new file mode 100644 index 00000000..b69f0d0c --- /dev/null +++ b/swagger2markup-asciidoc/build.gradle @@ -0,0 +1,25 @@ +ext.moduleName="io.github.swagger2markup.asciidoc" + +dependencies { + configurations.all { +// resolutionStrategy.force dependencyOverrides.commonsCodec +// resolutionStrategy.force dependencyOverrides.commonsIO +// resolutionStrategy.force dependencyOverrides.commonsLang3 + resolutionStrategy.force dependencyOverrides.jnrConstants + resolutionStrategy.force dependencyOverrides.jnrEnxio + resolutionStrategy.force dependencyOverrides.jnrPosix +// resolutionStrategy.force dependencyOverrides.jodaTime + resolutionStrategy.force dependencyOverrides.slf4j +// resolutionStrategy.force dependencyOverrides.jacksonDatabind +// resolutionStrategy.force dependencyOverrides.guava +// resolutionStrategy.force dependencyOverrides.findBugs +// resolutionStrategy.force dependencyOverrides.jaksonCore + } + implementation implLibraries.asciiDocJApi + implementation implLibraries.commonsText + implementation implLibraries.slf4j + testImplementation implLibraries.commonsIO + testImplementation testLibraries.asciiDocJ + testImplementation testLibraries.junit + testImplementation testLibraries.logback +} diff --git a/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/AsciidocConverter.java b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/AsciidocConverter.java new file mode 100644 index 00000000..f78e25ee --- /dev/null +++ b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/AsciidocConverter.java @@ -0,0 +1,887 @@ +package io.github.swagger2markup.adoc; + +import io.github.swagger2markup.adoc.converter.internal.*; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.text.StringEscapeUtils; +import org.asciidoctor.ast.List; +import org.asciidoctor.ast.*; +import org.asciidoctor.converter.ConverterFor; +import org.asciidoctor.converter.StringConverter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; +import java.util.stream.LongStream; +import java.util.stream.Stream; + +import static io.github.swagger2markup.adoc.converter.internal.Delimiters.*; + +@ConverterFor(AsciidocConverter.NAME) +public class AsciidocConverter extends StringConverter { + + private Logger logger = LoggerFactory.getLogger(getClass()); + + public static final String NAME = "adoc"; + + private final Pattern emptyLineOrStartWith = Pattern.compile("(?m)^\\s*(?:\\r?\\n)|(?m)^\\s+"); + private final Pattern coListItemIdPattern = Pattern.compile(".*-(\\d+)"); + private final Pattern tableColumnsStylePattern = Pattern.compile("((\\d+)\\*)?([<^>])?(\\.[<^>])?(\\d+)?([adehlmsv])?"); + + private static final java.util.List attributeToExclude = Arrays.asList( + "localtime", + "filetype", + "asciidoctor-version", + "doctime", + "localyear", + "docdate", + "localdate", + "localdatetime", + "docdatetime", + "backend", + "basebackend", + "doctitle", + "docyear" + ); + + private static final String[] supportedUrlSchemes = new String[]{ + "http", + "https", + "ftp", + "irc", + "mailto" + }; + + public AsciidocConverter(String backend, Map opts) { + super(backend, opts); + } + + /** + * Converts an {@link ContentNode} using the specified transform along + * with additional options. If a transform is not specified, implementations + * typically derive one from the {@link ContentNode#getNodeName()} property. + * + *

Implementations are free to decide how to carry out the conversion. In + * the case of the built-in converters, the tranform value is used to + * dispatch to a handler method. The TemplateConverter uses the value of + * the transform to select a template to render. + * + * @param node The concrete instance of FlowNode to convert + * @param transform An optional String transform that hints at which transformation + * should be applied to this node. If a transform is not specified, + * the transform is typically derived from the value of the + * node's node_name property. (optional, default: null) + * @param opts An optional map of options that provide additional hints about + * how to convert the node. (optional, default: empty map) + * @return the converted result + */ + @Override + public String convert(ContentNode node, String transform, Map opts) { + if (null == transform) { + transform = node.getNodeName(); + } + switch (transform) { + case "inline_quoted": + return convertInlineQuoted((PhraseNode) node); + case "paragraph": + return convertParagraph((StructuralNode) node); + case "inline_anchor": + return convertInlineAnchor((PhraseNode) node); + case "section": + return convertSection((Section) node); + case "listing": + return convertListing((Block) node); + case "literal": + return convertLiteral((StructuralNode) node); + case "ulist": + return convertUList((List) node); + case "olist": + return convertOList((List) node); + case "dlist": + return convertDescriptionList((DescriptionList) node); + case "admonition": + return convertAdmonition((Block) node); + case "colist": + return convertCoList((List) node); + case "embedded": + case "document": + return convertEmbedded((Document) node); + case "example": + return convertExample((Block) node); + case "floating_title": + return convertFloatingTitle((StructuralNode) node); + case "image": + return convertImage((StructuralNode) node); + case "inline_break": + return convertInlineBreak(node); + case "inline_button": + return convertInlineButton(node); + case "inline_callout": + return convertInlineCallout(node); + case "inline_footnote": + return convertInlineFootnote(node); + case "inline_image": + return convertInlineImage((PhraseNode) node); + case "inline_indexterm": + return convertInlineIndexTerm(node); + case "inline_kbd": + return convertInlineKbd(node); + case "inline_menu": + return convertInlineMenu(node); + case "open": + return convertOpen((StructuralNode) node); + case "page_break": + return convertPageBreak(node); + case "preamble": + return convertPreamble((StructuralNode) node); + case "quote": + return convertQuote((StructuralNode) node); + case "sidebar": + return convertSidebar((StructuralNode) node); + case "stem": + return convertStem(node); + case "table": + return convertTable((Table) node); + case "thematic_break": + return convertThematicBreak(node); + case "verse": + return convertVerse((StructuralNode) node); + case "video": + return convertVideo(node); + case "toc": + return convertToc(node); + case "pass": + return convertPass(node); + case "audio": + return convertAudio(node); + // didn't exist on html converter + case "list": + return convertList((List) node); + case "list_item": + return convertListItem((ListItem) node); + default: + logger.debug("Don't know how to convert transform: [" + transform + "] Node: " + node); + return null; + } + } + + String convertEmbedded(Document node) { + logger.debug("convertEmbedded"); + StringBuilder sb = new StringBuilder(); + appendId(node, sb); + if (StringUtils.isNotBlank(node.getDoctitle())) { + sb.append(repeat(node.getLevel() + 1,DOCUMENT_TITLE)).append(' ').append(StringEscapeUtils.unescapeHtml4(node.getDoctitle())).append(LINE_SEPARATOR); + } + Map attributes = node.getAttributes(); + appendAuthors(sb, attributes); + appendRevisionDetails(sb, attributes); + appendDocumentAttributes(sb, attributes); + appendTrailingNewLine(sb); + appendChildBlocks(node, sb); + return sb.toString(); + } + + private void appendAuthors(StringBuilder sb, Map attributes) { + Long authorCount = (Long) attributes.getOrDefault("authorcount", 0L); + if (authorCount == 1) { + String author = getAuthorDetail(attributes, "author", "email"); + if (StringUtils.isNotBlank(author)) { + sb.append(author).append(LINE_SEPARATOR); + } + } else if (authorCount > 1) { + String authors = LongStream.rangeClosed(1, authorCount) + .mapToObj(i -> getAuthorDetail(attributes, "author_" + i, "email_" + i)) + .collect(Collectors.joining("; ")); + + if (StringUtils.isNotBlank(authors)) { + sb.append(authors).append(LINE_SEPARATOR); + } + } + } + + private void appendDocumentAttributes(StringBuilder sb, Map attributes) { + attributes.forEach((k, v) -> { + if (!attributeToExclude.contains(k) && v != null && !v.toString().isEmpty()) + sb.append(COLON).append(k).append(COLON).append(" ").append(v).append(LINE_SEPARATOR); + }); + } + + private void appendRevisionDetails(StringBuilder sb, Map attributes) { + String revDetails = Stream.of(attributes.get("revnumber"), attributes.get("revdate")).filter(Objects::nonNull) + .filter(o -> !o.toString().isEmpty()).map(Object::toString) + .collect(Collectors.joining(", ")); + + if (!revDetails.isEmpty()) { + sb.append("v").append(revDetails).append(LINE_SEPARATOR); + } + } + + private String getAuthorDetail(Map attributes, String authorKey, String emailKey) { + String author = attributes.getOrDefault(authorKey, "").toString(); + String email = attributes.getOrDefault(emailKey, "").toString(); + if (StringUtils.isNotBlank(email)) { + email = " <" + email + ">"; + } + + return (author + email).trim(); + } + + private String convertInlineAnchor(PhraseNode node) { + logger.debug("convertInlineAnchor"); + String type = node.getType(); + switch (type) { + case "xref": { + String attrs; + String text; + String path = Optional.ofNullable(node.getAttributes().get("path")).orElse("").toString(); + if (StringUtils.isNotBlank(path)) { + ArrayList list = new ArrayList<>(); + if (StringUtils.isNotBlank(node.getRole())) { + list.add(" class=\"#{node.role}\""); + } + append_link_constraint_attrs(node, list); + attrs = String.join(" ", list); + text = StringUtils.isNotBlank(node.getText()) ? node.getText() : path; + } else { + attrs = StringUtils.isNotBlank(node.getRole()) ? " class=\"" + node.getRole() + "\"" : ""; + text = node.getText(); + if (StringUtils.isNotBlank(text)) { + text = node.getAttributes().get("refid").toString(); + } + } + return node.getTarget() + ATTRIBUTES_BEGIN + text + (StringUtils.isNotBlank(attrs) ? "," + attrs : "") + ATTRIBUTES_END; + } + case "ref": + return node.getId(); + case "link": { + ArrayList attrs = new ArrayList<>(); + String target = node.getTarget(); + String includePrefix = !StringUtils.startsWithAny(target, supportedUrlSchemes) ? "include::" : ""; + + String text = node.getText(); + if (!target.equals(text)) { + attrs.add(text); + } + if (StringUtils.isNotBlank(node.getId())) { + attrs.add("id=\"" + node.getId() + "\""); + } + String role = node.getRole(); + if (StringUtils.isNotBlank(role) && !role.equals("bare")) { + attrs.add("role=\"" + role + "\""); + } + String title = node.getAttribute("title", "").toString(); + if (StringUtils.isNotBlank(title)) { + attrs.add("title=\"" + title + "\""); + } + return includePrefix + target + ATTRIBUTES_BEGIN + String.join(",", attrs) + ATTRIBUTES_END; + } + case "bibref": + return node.getId() + ATTRIBUTES_BEGIN + (StringUtils.isNotBlank(node.getReftext()) ? node.getReftext() : node.getId()) + ATTRIBUTES_END; + default: + logger.warn("unknown anchor type: " + node.getType()); + return null; + } + } + + private String convertAdmonition(Block node) { + logger.debug("convertAdmonition"); + StringBuilder sb = new StringBuilder(); + + java.util.List blocks = node.getBlocks(); + if (blocks.isEmpty()) { + sb.append(node.getStyle()).append(": ").append(node.getSource()); + } else { + appendTitle(node, sb); + sb.append(ATTRIBUTES_BEGIN).append(node.getStyle()).append(ATTRIBUTES_END) + .append(LINE_SEPARATOR).append(DELIMITER_EXAMPLE).append(LINE_SEPARATOR); + appendChildBlocks(node, sb); + sb.append(DELIMITER_EXAMPLE).append(LINE_SEPARATOR); + } + return sb.toString(); + } + + private String convertInlineQuoted(PhraseNode node) { + logger.debug("convertInlineQuoted"); + StringBuilder sb = new StringBuilder(); + String marker = ""; + switch (node.getType()) { + case "monospaced": + marker = "`"; + break; + case "emphasis": + marker = "_"; + break; + case "strong": + marker = "*"; + break; + case "superscript": + marker = "^"; + break; + case "subscript": + marker = "~"; + break; + case "double": + case "single": + case "mark": + case "asciimath": + case "latexmath": + marker = ""; + break; + } + sb.append(marker).append(node.getText()).append(marker); + return sb.toString(); + } + + private String convertFloatingTitle(StructuralNode node) { + logger.debug("convertFloatingTitle"); + return ATTRIBUTES_BEGIN + "discrete" + ATTRIBUTES_END + LINE_SEPARATOR + + repeat(node.getLevel() + 1, TITLE) + ' ' + node.getTitle() + LINE_SEPARATOR; + } + + private String convertExample(Block node) { + logger.debug("convertExample"); + StringBuilder sb = new StringBuilder(); + appendTitle(node, sb); + sb.append(DELIMITER_EXAMPLE).append(LINE_SEPARATOR); + appendChildBlocks(node, sb); + sb.append(DELIMITER_EXAMPLE).append(LINE_SEPARATOR); + return sb.toString(); + } + + private String convertInlineButton(ContentNode node) { + logger.debug("convertInlineButton: name" + node.getNodeName()); + return "convertInlineButton"; + } + + private String convertInlineCallout(ContentNode node) { + logger.debug("convertInlineCallout: name" + node.getNodeName()); + return "convertInlineCallout"; + } + + private String convertInlineBreak(ContentNode node) { + logger.debug("convertInlineBreak: name" + node.getNodeName()); + return "convertInlineBreak"; + } + + private String convertInlineFootnote(ContentNode node) { + logger.debug("convertInlineFootnote: name" + node.getNodeName()); + return "convertInlineFootnote"; + } + + private String convertInlineImage(PhraseNode node) { + logger.debug("convertInlineImage"); + if (node.getType().equals("icon")) { + return (new IconNode(node)).toAsciiDocContent(); + } else { + return (new BlockImageNode(node)).toAsciiDocContent(); + } + } + + private String convertInlineIndexTerm(ContentNode node) { + logger.debug("convertInlineIndexTerm: name" + node.getNodeName()); + return "convertInlineIndexTerm"; + } + + private String convertInlineKbd(ContentNode node) { + logger.debug("convertInlineKbd: name" + node.getNodeName()); + return "convertInlineKbd"; + } + + private String convertInlineMenu(ContentNode node) { + logger.debug("convertInlineMenu: name" + node.getNodeName()); + return "convertInlineMenu"; + } + + private String convertOpen(StructuralNode node) { + logger.debug("convertOpen"); + StringBuilder sb = new StringBuilder(); + + switch (node.getStyle()) { + case "abstract": + sb.append(ATTRIBUTES_BEGIN).append("abstract").append(ATTRIBUTES_END).append(LINE_SEPARATOR); + break; + case "open": + sb.append(DELIMITER_OPEN_BLOCK).append(LINE_SEPARATOR); + } + sb.append(Optional.ofNullable(((Block) node).getSource()).orElse("")); + appendChildBlocks(node, sb); + + if ("open".equals(node.getStyle())) { + sb.append(DELIMITER_OPEN_BLOCK).append(LINE_SEPARATOR); + } + return sb.toString(); + } + + private String convertPageBreak(ContentNode node) { + logger.debug("convertPageBreak: name" + node.getNodeName()); + return DELIMITER_PAGE_BREAK + LINE_SEPARATOR; + } + + private String convertQuote(StructuralNode node) { + logger.debug("convertQuote"); + StringBuilder sb = new StringBuilder(); + appendTitle(node, sb); + sb.append(ATTRIBUTES_BEGIN); + java.util.List attrs = new ArrayList<>(); + if (StringUtils.isNotBlank(node.getStyle())) { + attrs.add("quote"); + } + appendAttributeTo(node, attrs, "attribution"); + appendAttributeTo(node, attrs, "citetitle"); + sb.append(String.join(",", attrs)).append(ATTRIBUTES_END).append(LINE_SEPARATOR); + java.util.List blocks = node.getBlocks(); + if (!blocks.isEmpty()) { + sb.append("____").append(LINE_SEPARATOR); + appendChildBlocks(node, sb); + sb.append("____").append(LINE_SEPARATOR); + } else { + sb.append(((Block) node).getSource()); + } + + return sb.toString(); + } + + private String convertSidebar(StructuralNode node) { + logger.debug("convertSidebar"); + StringBuilder sb = new StringBuilder(); + appendTitle(node, sb); + appendChildBlocks(node, sb); + return sb.toString(); + } + + private String convertStem(ContentNode node) { + logger.debug("convertStem: name" + node.getNodeName()); + return "convertStem"; + } + + private String convertThematicBreak(ContentNode node) { + logger.debug("convertThematicBreak: name" + node.getNodeName()); + return DELIMITER_THEMATIC_BREAK + LINE_SEPARATOR; + } + + private String convertVerse(StructuralNode node) { + logger.debug("convertVerse"); + StringBuilder sb = new StringBuilder(); + appendTitle(node, sb); + sb.append(ATTRIBUTES_BEGIN); + java.util.List attrs = new ArrayList<>(); + if (StringUtils.isNotBlank(node.getStyle())) { + attrs.add("verse"); + } + appendAttributeTo(node, attrs, "attribution"); + appendAttributeTo(node, attrs, "citetitle"); + sb.append(String.join(",", attrs)).append(ATTRIBUTES_END).append(LINE_SEPARATOR); + String source = ((Block) node).getSource(); + boolean matches = emptyLineOrStartWith.matcher(source).find(); + if (matches) { + sb.append(DELIMITER_VERSE).append(LINE_SEPARATOR); + } + sb.append(source); + if (matches) { + sb.append(LINE_SEPARATOR).append(DELIMITER_VERSE); + } + appendTrailingNewLine(sb); + return sb.toString(); + } + + private String convertVideo(ContentNode node) { + logger.debug("convertVideo: name" + node.getNodeName()); + return "convertVideo"; + } + + private String convertToc(ContentNode node) { + logger.debug("convertToc: name" + node.getNodeName()); + return "convertToc"; + } + + private String convertPass(ContentNode node) { + logger.debug("convertPass: name" + node.getNodeName()); + return "convertPass"; + } + + private String convertAudio(ContentNode node) { + logger.debug("convertAudio: name" + node.getNodeName()); + return "convertAudio"; + } + + private String convertCell(Cell node) { + logger.debug("convertCell"); + StringBuilder sb = new StringBuilder(); + String source = node.getSource(); + if (StringUtils.isNotBlank(source)) { + sb.append(source); + } + Document innerDocument = node.getInnerDocument(); + if (null != innerDocument) { + appendChildBlocks(innerDocument, sb, false); + } + return sb.toString().replaceAll(LINE_SEPARATOR + LINE_SEPARATOR + "+", LINE_SEPARATOR + LINE_SEPARATOR); + } + + private String convertRow(Row node, java.util.List columnStyles, String delimiterTableCell) { + logger.debug("convertRow"); + StringBuilder sb = new StringBuilder(); + node.getCells().forEach(cell -> { + boolean addNewLine = false; + int colspan = cell.getColspan(); + if (colspan != 0) { + addNewLine = true; + sb.append(colspan).append('+'); + } + int rowspan = cell.getRowspan(); + if (rowspan != 0) { + addNewLine = true; + sb.append('.').append(rowspan).append('+'); + } + int index = cell.getColumn().getColumnNumber() - 1; + TableCellStyle tableCellStyle = (columnStyles.size() > index) ? columnStyles.get(index) : null; + + boolean hAlignmentAdded = false; + TableCellHorizontalAlignment hAlignment = TableCellHorizontalAlignment.fromName(cell.getHorizontalAlignment().name()); + if ((null != hAlignment) && (null == tableCellStyle || hAlignment != tableCellStyle.horizontalAlignment)) { + hAlignmentAdded = true; + addNewLine = true; + sb.append(hAlignment.getDelimiter()); + } + + TableCellVerticalAlignment vAlignment = TableCellVerticalAlignment.fromName(cell.getVerticalAlignment().name()); + if ((null != vAlignment) && (null == tableCellStyle || hAlignmentAdded || vAlignment != tableCellStyle.verticalAlignment)) { + addNewLine = true; + sb.append(vAlignment.getDelimiter()); + } + + Style style = Style.fromName(cell.getAttribute("style", "").toString()); + if (null != style && (null == tableCellStyle || style != tableCellStyle.style)) { + addNewLine = true; + sb.append(style.getShortHand()); + } + sb.append(delimiterTableCell).append(convertCell(cell)); + if (addNewLine) { + sb.append(LINE_SEPARATOR); + } else { + sb.append(' '); + } + }); + return sb.toString(); + } + + private String convertTable(Table node) { + logger.debug("convertTable"); + java.util.List columnStyles = new ArrayList<>(); + for (String col : node.getAttribute("cols", "").toString().split(",")) { + Matcher matcher = tableColumnsStylePattern.matcher(col); + if (matcher.find()) { + int multiplier = 1; + String multiplierGroup = matcher.group(2); + if (null != multiplierGroup) { + try { + multiplier = Integer.parseInt(multiplierGroup); + } catch (NumberFormatException ignored) { + } + } + int width = 0; + try { + width = Integer.parseInt(matcher.group(5)); + } catch (NumberFormatException ignored) { + } + TableCellStyle tableCellStyle = new TableCellStyle( + TableCellHorizontalAlignment.fromString(matcher.group(3)), + TableCellVerticalAlignment.fromString(matcher.group(4)), + Style.fromString(matcher.group(6)), + width + ); + for (int i = 0; i < multiplier; i++) { + columnStyles.add(tableCellStyle); + } + } + } + + StringBuilder sb = new StringBuilder(); + appendTitle(node, sb); + sb.append(new TableNode(node).toAsciiDocContent()); + boolean innerTable = isInnerTable(node); + String tableDelimiter = innerTable ? DELIMITER_INNER_TABLE : DELIMITER_TABLE; + String cellDelimiter = innerTable ? DELIMITER_INNER_TABLE_CELL : DELIMITER_TABLE_CELL; + sb.append(tableDelimiter).append(LINE_SEPARATOR); + appendRows(node.getHeader(), sb, columnStyles, cellDelimiter); + appendRows(node.getBody(), sb, columnStyles, cellDelimiter); + appendRows(node.getFooter(), sb, columnStyles, cellDelimiter); + sb.append(tableDelimiter).append(LINE_SEPARATOR); + return sb.toString(); + } + + private boolean isInnerTable(ContentNode node) { + if(null != node) { + ContentNode parent = node.getParent(); + if (null != parent) { + return parent instanceof Table || isInnerTable(parent); + } + } + return false; + } + + private void appendRows(java.util.List rows, StringBuilder sb, java.util.List columnStyles, String delimiterTableCell) { + rows.forEach(row -> sb.append(convertRow(row, columnStyles, delimiterTableCell)).append(LINE_SEPARATOR)); + } + + private String convertDescriptionList(DescriptionList node) { + logger.debug("convertDescriptionList"); + StringBuilder sb = new StringBuilder(); + + appendTitle(node, sb); + String style = Optional.ofNullable(node.getStyle()).orElse(""); + switch (style) { + case STYLE_HORIZONTAL: + sb.append(ATTRIBUTES_BEGIN).append(STYLE_HORIZONTAL).append(ATTRIBUTES_END).append(LINE_SEPARATOR); + node.getItems().forEach(item -> sb.append(convertDescriptionListEntry(item, node.getLevel(), false))); + break; + case STYLE_Q_AND_A: + sb.append(ATTRIBUTES_BEGIN).append(STYLE_Q_AND_A).append(ATTRIBUTES_END).append(LINE_SEPARATOR); + default: + node.getItems().forEach(item -> sb.append(convertDescriptionListEntry(item, node.getLevel(), true))); + break; + } + appendTrailingNewLine(sb); + + return sb.toString(); + } + + private String convertDescriptionListEntry(DescriptionListEntry node, int level, Boolean descriptionOnNewLine) { + logger.debug("convertDescriptionListEntry"); + StringBuilder sb = new StringBuilder(); + String delimiter = repeat(level + 1, MARKER_D_LIST_ITEM); + String entryTerms = node.getTerms().stream() + .map(term -> Optional.ofNullable(term.getSource()).orElse("")) + .collect(Collectors.joining(delimiter + LINE_SEPARATOR, "", delimiter)); + sb.append(entryTerms); + ListItem description = node.getDescription(); + if (null != description) { + if (descriptionOnNewLine) { + sb.append(LINE_SEPARATOR); + } + String desc = Optional.ofNullable(description.getSource()).orElse(""); + if (StringUtils.isNotBlank(desc)) { + sb.append(desc).append(LINE_SEPARATOR); + } + appendChildBlocks(description, sb); + } + return sb.toString(); + } + + private String convertListing(Block node) { + logger.debug("convertListing"); + StringBuilder sb = new StringBuilder(); + appendTitle(node, sb); + if (STYLE_SOURCE.equals(node.getStyle())) { + sb.append(new SourceNode(node).toAsciiDocContent()); + } else { + sb.append(new BlockListingNode(node).toAsciiDocContent()); + } + return sb.toString(); + } + + private String convertUList(List node) { + logger.debug("convertUList"); + StringBuilder sb = new StringBuilder(); + appendStyle(node, sb); + appendTitle(node, sb); + appendChildBlocks(node, sb); + appendTrailingNewLine(sb); + return sb.toString(); + } + + private String convertOList(List node) { + logger.debug("convertOList"); + StringBuilder sb = new StringBuilder(); + java.util.List attrs = new ArrayList<>(); + String start = node.getAttribute("start", "").toString(); + if (StringUtils.isNotBlank(start)) { + attrs.add("start=" + start); + } + if (node.isOption("reversed")) { + attrs.add("%reversed"); + } + if (!attrs.isEmpty()) { + sb.append(ATTRIBUTES_BEGIN).append(String.join(",", attrs)).append(ATTRIBUTES_END).append(LINE_SEPARATOR); + } + appendTitle(node, sb); + appendChildBlocks(node, sb); + appendTrailingNewLine(sb); + return sb.toString(); + } + + private String convertCoList(List node) { + logger.debug("convertCoList"); + StringBuilder result = new StringBuilder(); + appendChildBlocks(node, result); + return result.toString(); + } + + private String convertListItem(ListItem node) { + logger.debug("convertListItem"); + StringBuilder sb = new StringBuilder(); + + String marker = Optional.ofNullable(node.getMarker()).orElse(repeat(node.getLevel(), MARKER_LIST_ITEM)); + + String coids = node.getAttribute("coids", "").toString(); + Matcher matcher = coListItemIdPattern.matcher(coids); + if (matcher.find()) { + marker = marker.replaceAll("\\d+", matcher.group(1)); + } + + sb.append(marker).append(" "); + + if (node.hasAttribute("checkbox")) { + sb.append('['); + if (node.hasAttribute("checked")) { + sb.append('x'); + } else { + sb.append(' '); + } + sb.append(']').append(' '); + } + + sb.append(Optional.ofNullable(node.getSource()).orElse("")); + appendTrailingNewLine(sb); + appendChildBlocks(node, sb); + return sb.toString(); + } + + private String convertList(List node) { + logger.debug("convertList"); + return node.getContent().toString(); + } + + private String convertPreamble(StructuralNode node) { + logger.debug("convertPreamble"); + return node.getContent().toString(); + } + + private String convertImage(StructuralNode node) { + logger.debug("convertImage"); + StringBuilder sb = new StringBuilder(); + appendTitle(node, sb); + appendRoles(node, sb); + sb.append(new BlockImageNode(node).toAsciiDocContent()); + return sb.toString(); + } + + private String convertLiteral(StructuralNode node) { + logger.debug("convertLiteral"); + return ATTRIBUTES_BEGIN + node.getContext() + ATTRIBUTES_END + LINE_SEPARATOR + + StringEscapeUtils.unescapeHtml4(node.getContent().toString()) + LINE_SEPARATOR; + } + + private String convertParagraph(StructuralNode node) { + logger.debug("convertParagraph"); + StringBuilder sb = new StringBuilder(); + appendTitle(node, sb); + sb.append(new ParagraphAttributes(node).toAsciiDocContent()); + appendSource((Block) node, sb); + appendTrailingNewLine(sb); + return sb.toString(); + } + + private String convertSection(Section node) { + logger.debug("convertSection"); + StringBuilder sb = new StringBuilder(); + appendId(node, sb); + sb.append(new DelimitedBlockNode(node).toAsciiDocContent()).append(StringUtils.repeat(TITLE, node.getLevel() + 1)) + .append(" ").append(StringEscapeUtils.unescapeHtml4(node.getTitle())).append(LINE_SEPARATOR); + appendChildBlocks(node, sb); + appendTrailingNewLine(sb); + return sb.toString(); + } + + private void append_link_constraint_attrs(ContentNode node, java.util.List attrs) { + String rel = node.getAttribute("nofollow-option").toString(); + String window = node.getAttributes().get("window").toString(); + if (StringUtils.isNotBlank(window)) { + attrs.add("target = \"#{window}\""); + if (window.equals("_blank") || (node.getAttributes().containsKey("option-noopener"))) { + if (StringUtils.isNotBlank(rel)) { + attrs.add("rel = \"" + rel + "noopener\""); + } else { + attrs.add(" rel=\"noopener\""); + } + } + } else if (StringUtils.isNotBlank(rel)) { + attrs.add("rel = " + rel + "\""); + } + } + + private String repeat(int count, String with) { + return new String(new char[count]).replace("\0", with); + } + + private void appendChildBlocks(StructuralNode parentNode, StringBuilder sb) { + appendChildBlocks(parentNode, sb, true); + } + + private void appendChildBlocks(StructuralNode parentNode, StringBuilder sb, boolean addTrailingLineSeparator) { + final boolean isParentAListItem = parentNode instanceof ListItem || parentNode instanceof DescriptionListEntry; + parentNode.getBlocks().forEach(childNode -> { + String childNodeValue = childNode.convert(); + if (StringUtils.isNotBlank(childNodeValue)) { + if (isParentAListItem && (sb.toString().contains("+" + LINE_SEPARATOR) || !(childNode instanceof List || childNode instanceof DescriptionList))) { + sb.append('+').append(LINE_SEPARATOR); + } + sb.append(childNodeValue); + if (addTrailingLineSeparator && !StringUtils.endsWith(childNodeValue, LINE_SEPARATOR)) { + sb.append(LINE_SEPARATOR); + } + } + }); + } + + private void appendTrailingNewLine(StringBuilder sb) { + if (!sb.toString().endsWith(LINE_SEPARATOR + LINE_SEPARATOR)) { + sb.append(LINE_SEPARATOR); + } + } + + private void appendId(StructuralNode node, StringBuilder sb) { + String id = node.getId(); + if (StringUtils.isNotBlank(id)) { + sb.append("[[").append(id).append("]]").append(LINE_SEPARATOR); + } + } + + private void appendSource(Block node, StringBuilder sb) { + String source = node.getSource(); + if (StringUtils.isNotBlank(source)) { + sb.append(source).append(LINE_SEPARATOR); + } + } + + private void appendTitle(StructuralNode node, StringBuilder sb) { + String title = node.getTitle(); + if (StringUtils.isNotBlank(title)) { + sb.append(".").append(StringEscapeUtils.unescapeHtml4(title)).append(LINE_SEPARATOR); + } + } + + private void appendStyle(StructuralNode node, StringBuilder sb) { + String style = node.getStyle(); + if (StringUtils.isNotBlank(style)) { + sb.append(ATTRIBUTES_BEGIN).append(style).append(ATTRIBUTES_END).append(LINE_SEPARATOR); + } + } + + private void appendRoles(StructuralNode node, StringBuilder sb) { + java.util.List roles = node.getRoles(); + if (!roles.isEmpty()) { + sb.append(ATTRIBUTES_BEGIN).append(".").append(String.join(".", roles)) + .append(ATTRIBUTES_END).append(LINE_SEPARATOR); + } + } + + private void appendAttributeTo(StructuralNode node, java.util.List attrs, String name) { + String attribution = node.getAttribute(name, "").toString(); + if (StringUtils.isNotBlank(attribution)) { + attrs.add(attribution); + } + } +} diff --git a/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/ast/impl/BlockImpl.java b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/ast/impl/BlockImpl.java new file mode 100644 index 00000000..a798653b --- /dev/null +++ b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/ast/impl/BlockImpl.java @@ -0,0 +1,70 @@ +package io.github.swagger2markup.adoc.ast.impl; + +import org.asciidoctor.ast.Block; +import org.asciidoctor.ast.StructuralNode; + +import java.util.*; + +public class BlockImpl extends StructuralNodeImpl implements Block { + + private List lines; + + public BlockImpl(StructuralNode parent, String context) { + this(parent, context, ""); + } + + public BlockImpl(StructuralNode parent, String context, Object content) { + this(parent, context, new HashMap<>(), content); + } + + public BlockImpl(StructuralNode parent, String context, Map attributes) { + this(parent, context, attributes, ""); + } + + public BlockImpl(StructuralNode parent, String context, Map attributes, Object content) { + this(parent, context, attributes, new ArrayList<>(), content, new ArrayList<>(), "", new ArrayList<>()); + } + + public BlockImpl(StructuralNode parent, String context, Map attributes, List roles, + Object content, List blocks, String contentModel, List subs) { + this(parent, context, attributes, roles, content, blocks, calculateLevel(parent), contentModel, subs); + } + + public BlockImpl(StructuralNode parent, String context, Map attributes, List roles, + Object content, List blocks, Integer level, String contentModel, List subs) { + super(parent, context, attributes, roles, content, blocks, level, contentModel, subs); + this.lines = new ArrayList<>(); + } + + @Override + @Deprecated + public List lines() { + return getLines(); + } + + @Override + public List getLines() { + return lines; + } + + @Override + public void setLines(List lines) { + this.lines = lines; + } + + @Override + @Deprecated + public String source() { + return getSource(); + } + + @Override + public String getSource() { + return String.join("\n", lines); + } + + @Override + public void setSource(String source) { + setLines(Arrays.asList(source.split("\n"))); + } +} diff --git a/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/ast/impl/CellImpl.java b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/ast/impl/CellImpl.java new file mode 100644 index 00000000..677f5fc7 --- /dev/null +++ b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/ast/impl/CellImpl.java @@ -0,0 +1,112 @@ +package io.github.swagger2markup.adoc.ast.impl; + +import org.asciidoctor.ast.Cell; +import org.asciidoctor.ast.Column; +import org.asciidoctor.ast.Document; +import org.asciidoctor.ast.Table; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class CellImpl extends ContentNodeImpl implements Cell { + + private final int colspan; + private final int rowspan; + private String text; + private String style; + private Document innerDocument; + + public CellImpl(Column parent, String text) { + this(parent, "table_cell", new HashMap<>(), new ArrayList<>(), 0, 0); + this.text = text; + } + + public CellImpl(Column parent, Document innerDocument) { + this(parent, "table_cell", new HashMap<>(), new ArrayList<>(), 0, 0); + this.innerDocument = innerDocument; + } + + public CellImpl(Column parent, String context, Map attributes, List roles, int colspan, int rowspan) { + super(parent, context, attributes, roles); + this.colspan = colspan; + this.rowspan = rowspan; + } + + @Override + public Column getColumn() { + return (Column) getParent(); + } + + @Override + public int getColspan() { + return colspan; + } + + @Override + public int getRowspan() { + return rowspan; + } + + @Override + public String getText() { + return text; + } + + @Override + public String getSource() { + return text; + } + + @Override + public void setSource(String source) { + this.text = source; + } + + @Override + public Object getContent() { + return text; + } + + @Override + public String getStyle() { + return style; + } + + @Override + public void setStyle(String style) { + this.style = style; + } + + @Override + public Table.HorizontalAlignment getHorizontalAlignment() { + return Table.HorizontalAlignment.valueOf(((String) getAttribute("halign", "left")).toUpperCase()); + } + + @Override + public void setHorizontalAlignment(Table.HorizontalAlignment halign) { + setAttribute("halign", halign.name().toLowerCase(), true); + } + + @Override + public Table.VerticalAlignment getVerticalAlignment() { + return Table.VerticalAlignment.valueOf(((String) getAttribute("valign", "top")).toUpperCase()); + } + + @Override + public void setVerticalAlignment(Table.VerticalAlignment valign) { + setAttribute("valign", valign.name().toLowerCase(), true); + } + + @Override + public Document getInnerDocument() { + return innerDocument; + } + + @Override + public void setInnerDocument(Document document) { + this.innerDocument = document; + } + +} diff --git a/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/ast/impl/ColumnImpl.java b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/ast/impl/ColumnImpl.java new file mode 100644 index 00000000..b3c139b5 --- /dev/null +++ b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/ast/impl/ColumnImpl.java @@ -0,0 +1,81 @@ +package io.github.swagger2markup.adoc.ast.impl; + +import org.asciidoctor.ast.Column; +import org.asciidoctor.ast.Table; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class ColumnImpl extends ContentNodeImpl implements Column { + + private String style; + private Number columnNumber = -1; + private Number width = 0; + + public ColumnImpl(Table parent) { + this(parent, "table_column", new HashMap<>(), new ArrayList<>()); + } + + public ColumnImpl(Table parent, String context, Map attributes, List roles) { + super(parent, context, attributes, roles); + } + + @Override + public String getStyle() { + return style; + } + + @Override + public void setStyle(String style) { + this.style = style; + } + + @Override + public Table getTable() { + return (Table) getParent(); + } + + @Override + public int getColumnNumber() { + return columnNumber.intValue(); + } + + public void setColumnNumber(Integer columnNumber) { + setAttribute("colnumber", columnNumber, true); + this.columnNumber = columnNumber; + } + + @Override + public int getWidth() { + return width.intValue(); + } + + @Override + public void setWidth(int width) { + setAttribute("width", width, true); + this.width = width; + } + + @Override + public Table.HorizontalAlignment getHorizontalAlignment() { + return Table.HorizontalAlignment.valueOf(((String) getAttribute("halign", "left")).toUpperCase()); + } + + @Override + public void setHorizontalAlignment(Table.HorizontalAlignment halign) { + setAttribute("halign", halign.name().toLowerCase(), true); + } + + @Override + public Table.VerticalAlignment getVerticalAlignment() { + return Table.VerticalAlignment.valueOf(((String) getAttribute("valign", "top")).toUpperCase()); + } + + @Override + public void setVerticalAlignment(Table.VerticalAlignment valign) { + setAttribute("valign", valign.name().toLowerCase(), true); + } + +} diff --git a/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/ast/impl/ContentNodeImpl.java b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/ast/impl/ContentNodeImpl.java new file mode 100644 index 00000000..5716776f --- /dev/null +++ b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/ast/impl/ContentNodeImpl.java @@ -0,0 +1,309 @@ +package io.github.swagger2markup.adoc.ast.impl; + +import org.asciidoctor.ast.ContentNode; +import org.asciidoctor.ast.Document; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@SuppressWarnings("SuspiciousMethodCalls") +public abstract class ContentNodeImpl implements ContentNode { + + private String id; + private final String context; + private final Map attributes; + private final List roles; + private final ContentNode parent; + + public ContentNodeImpl(ContentNode parent, String context) { + this(parent, context, new HashMap<>(), new ArrayList<>()); + } + + public ContentNodeImpl(ContentNode parent, String context, Map attributes, List roles) { + this.parent = parent; + this.context = context; + this.attributes = attributes; + this.roles = roles; + } + + @Override + @Deprecated + public String id() { + return getId(); + } + + @Override + public String getId() { + return id; + } + + @Override + public void setId(String id) { + this.id = id.toLowerCase().replaceAll("\\s+", "_"); + } + + @Override + @Deprecated + public String context() { + return getContext(); + } + + @Override + public String getContext() { + return context; + } + + @Override + @Deprecated + public ContentNode parent() { + return getParent(); + } + + @Override + public ContentNode getParent() { + return parent; + } + + @Override + @Deprecated + public Document document() { + return getDocument(); + } + + @Override + public Document getDocument() { + throw new UnsupportedOperationException("Not implemented, yet"); + } + + @Override + public String getNodeName() { + return getContext(); + } + + @Override + public boolean isInline() { + return false; + } + + @Override + public boolean isBlock() { + return false; + } + + @Override + public Map getAttributes() { + return attributes; + } + + @Override + @Deprecated + public Object getAttr(Object name, Object defaultValue, boolean inherit) { + return getAttribute(name, defaultValue, inherit); + } + + @Override + @Deprecated + public Object getAttr(Object name, Object defaultValue) { + return getAttribute(name, defaultValue); + } + + @Override + @Deprecated + public Object getAttr(Object name) { + return getAttribute(name); + } + + @Override + public Object getAttribute(Object name, Object defaultValue, boolean inherit) { + return getAttribute(name, defaultValue); + } + + @Override + public Object getAttribute(Object name, Object defaultValue) { + return attributes.getOrDefault(name, defaultValue); + } + + @Override + public Object getAttribute(Object name) { + return attributes.get(name); + } + + @Override + @Deprecated + public boolean isAttr(Object name, Object expected, boolean inherit) { + return isAttribute(name, expected, inherit); + } + + @Override + @Deprecated + public boolean isAttr(Object name, Object expected) { + return isAttribute(name, expected); + } + + @Override + public boolean isAttribute(Object name, Object expected, boolean inherit) { + return isAttribute(name, expected); + } + + @Override + public boolean isAttribute(Object name, Object expected) { + try { + if (attributes.containsKey(name)) { + return attributes.get(name).equals(expected); + } else return false; + } catch (Exception e) { + return false; + } + } + + @Override + @Deprecated + public boolean hasAttr(Object name) { + return hasAttribute(name); + } + + @Override + @Deprecated + public boolean hasAttr(Object name, boolean inherited) { + return hasAttribute(name, inherited); + } + + @Override + public boolean hasAttribute(Object name) { + return attributes.containsKey(name); + } + + @Override + public boolean hasAttribute(Object name, boolean inherited) { + return hasAttribute(name); + } + + @Override + @Deprecated + public boolean setAttr(Object name, Object value, boolean overwrite) { + return setAttribute(name, value, overwrite); + } + + @Override + public boolean setAttribute(Object name, Object value, boolean overwrite) { + return setAttribute((String)name, value, overwrite); + } + + public boolean setAttribute(String name, Object value, boolean overwrite) { + try { + if (overwrite) { + attributes.put(name, value); + } else { + attributes.putIfAbsent(name, value); + } + return true; + } catch (Exception e) { + return false; + } + } + + public Object removeAttribute(String name){ + return attributes.remove(name); + } + + public boolean removeAttribute(String name, Object value){ + return attributes.remove(name, value); + } + + @Override + public boolean isOption(Object name) { + try { + Object o = attributes.get(name + "-option"); + return null != o && o.toString().equals(""); + }catch (Exception ignored){ + return false; + } + } + + public boolean setOption(String name){ + return setAttribute(name + "-option", "", true); + } + + public Object removeOption(String name){ + return removeAttribute(name + "-option"); + } + + @Override + public boolean isRole() { + return false; + } + + @Override + public String getRole() { + return String.join(",", roles); + } + + @Override + @Deprecated + public String role() { + return getRole(); + } + + @Override + public List getRoles() { + return roles; + } + + @Override + public boolean hasRole(String role) { + return roles.contains(role); + } + + @Override + public void addRole(String role) { + roles.add(role); + } + + @Override + public void removeRole(String role) { + roles.remove(role); + } + + @Override + public boolean isReftext() { + throw new UnsupportedOperationException("Not implemented, yet"); + } + + @Override + public String getReftext() { + throw new UnsupportedOperationException("Not implemented, yet"); + } + + @Override + public String iconUri(String name) { + throw new UnsupportedOperationException("Not implemented, yet"); + } + + @Override + public String mediaUri(String target) { + throw new UnsupportedOperationException("Not implemented, yet"); + } + + @Override + public String imageUri(String targetImage) { + throw new UnsupportedOperationException("Not implemented, yet"); + } + + @Override + public String imageUri(String targetImage, String assetDirKey) { + throw new UnsupportedOperationException("Not implemented, yet"); + } + + @Override + public String readAsset(String path, Map opts) { + throw new UnsupportedOperationException("Not implemented, yet"); + } + + @Override + public String normalizeWebPath(String path, String start, boolean preserveUriTarget) { + throw new UnsupportedOperationException("Not implemented, yet"); + } + +} diff --git a/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/ast/impl/CursorImpl.java b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/ast/impl/CursorImpl.java new file mode 100644 index 00000000..3bae8dab --- /dev/null +++ b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/ast/impl/CursorImpl.java @@ -0,0 +1,36 @@ +package io.github.swagger2markup.adoc.ast.impl; + +import org.asciidoctor.ast.Cursor; + +public class CursorImpl implements Cursor { + + private int lineno; + + public CursorImpl() { + } + + @Override + public int getLineNumber() { + return lineno; + } + + @Override + public String getPath() { + throw new UnsupportedOperationException("Not implemented, yet"); + } + + @Override + public String getDir() { + throw new UnsupportedOperationException("Not implemented, yet"); + } + + @Override + public String getFile() { + throw new UnsupportedOperationException("Not implemented, yet"); + } + + @Override + public String toString() { + throw new UnsupportedOperationException("Not implemented, yet"); + } +} diff --git a/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/ast/impl/DescriptionListEntryImpl.java b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/ast/impl/DescriptionListEntryImpl.java new file mode 100644 index 00000000..a896609c --- /dev/null +++ b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/ast/impl/DescriptionListEntryImpl.java @@ -0,0 +1,66 @@ +package io.github.swagger2markup.adoc.ast.impl; + +import org.asciidoctor.ast.DescriptionListEntry; +import org.asciidoctor.ast.ListItem; +import org.asciidoctor.ast.StructuralNode; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class DescriptionListEntryImpl extends StructuralNodeImpl implements DescriptionListEntry { + + private final List terms; + private ListItem description; + + public DescriptionListEntryImpl(StructuralNode parent) { + this(parent, new ArrayList<>()); + } + + public DescriptionListEntryImpl(StructuralNode parent, List terms) { + this(parent, terms, null); + } + + public DescriptionListEntryImpl(StructuralNode parent, List terms, ListItem description) { + this(parent, null, terms, description); + } + + public DescriptionListEntryImpl(StructuralNode parent, Object content, List terms, ListItem description) { + this(parent, new HashMap<>(), new ArrayList<>(), content, new ArrayList<>(), "", new ArrayList<>(), terms, description); + } + + public DescriptionListEntryImpl(StructuralNode parent, Map attributes, List roles, + Object content, List blocks, String contentModel, List subs, + List terms, ListItem description) { + this(parent, attributes, roles, content, blocks, null != parent ? parent.getLevel() : 1, contentModel, subs, terms, description); + } + + public DescriptionListEntryImpl(StructuralNode parent, Map attributes, List roles, + Object content, List blocks, Integer level, String contentModel, + List subs, List terms, ListItem description) { + super(parent, "dlist_item", attributes, roles, content, blocks, level, contentModel, subs); + this.terms = terms; + this.description = description; + } + + @Override + public List getTerms() { + return terms; + } + + public boolean addTerm(ListItem term) { + return terms.add(term); + } + + @Override + public ListItem getDescription() { + return description; + } + + public void setDescription(final ListItem description) { + this.description = description; + } + + +} diff --git a/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/ast/impl/DescriptionListImpl.java b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/ast/impl/DescriptionListImpl.java new file mode 100644 index 00000000..39eeedcb --- /dev/null +++ b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/ast/impl/DescriptionListImpl.java @@ -0,0 +1,72 @@ +package io.github.swagger2markup.adoc.ast.impl; + +import org.asciidoctor.ast.DescriptionList; +import org.asciidoctor.ast.DescriptionListEntry; +import org.asciidoctor.ast.StructuralNode; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class DescriptionListImpl extends StructuralNodeImpl implements DescriptionList { + + public static final String CONTEXT = "dlist"; + private List items; + + public DescriptionListImpl(StructuralNode parent) { + this(parent, new ArrayList<>()); + } + + public DescriptionListImpl(StructuralNode parent, List items) { + this(parent, null, items); + } + + public DescriptionListImpl(StructuralNode parent, Object content, List items) { + this(parent, new HashMap<>(), new ArrayList<>(), content, new ArrayList<>(), "", new ArrayList<>(), items); + } + + public DescriptionListImpl(StructuralNode parent, Map attributes, List roles, + Object content, List blocks, String contentModel, + List subs, List items) { + this(parent, attributes, roles, content, blocks, calculateLevel(parent), contentModel, subs, items); + } + + public DescriptionListImpl(StructuralNode parent, Map attributes, List roles, + Object content, List blocks, Integer level, + String contentModel, List subs, List items) { + super(parent, CONTEXT, attributes, roles, content, blocks, level, contentModel, subs); + this.items = items; + } + + @Override + public List getItems() { + return items; + } + + public void setItems(List items) { + this.items = items; + } + + public void addEntry(DescriptionListEntry entry) { + this.items.add(entry); + } + + @Override + public boolean hasItems() { + return !items.isEmpty(); + } + + @Override + @Deprecated + public String render() { + return convert(); + } + + protected static Integer calculateLevel(StructuralNode parent) { + int level = 1; + if (parent instanceof DescriptionList) + level = parent.getLevel() + 1; + return level; + } +} diff --git a/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/ast/impl/DocumentImpl.java b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/ast/impl/DocumentImpl.java new file mode 100644 index 00000000..47db1bfa --- /dev/null +++ b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/ast/impl/DocumentImpl.java @@ -0,0 +1,89 @@ +package io.github.swagger2markup.adoc.ast.impl; + +import org.asciidoctor.ast.Document; +import org.asciidoctor.ast.StructuralNode; +import org.asciidoctor.ast.Title; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class DocumentImpl extends StructuralNodeImpl implements Document { + + public DocumentImpl() { + this(null); + } + + public DocumentImpl(StructuralNode parent) { + this(parent, "document", ""); + } + + public DocumentImpl(StructuralNode parent, String context, Object content) { + this(parent, context, new HashMap<>(), new ArrayList<>(), content, new ArrayList<>(), "", new ArrayList<>()); + } + + public DocumentImpl(StructuralNode parent, String context, Map attributes, List roles, + Object content, List blocks, String contentModel, + List subs) { + this(parent, context, attributes, roles, content, blocks, null != parent ? parent.getLevel() + 1 : 0, contentModel, subs); + } + + public DocumentImpl(StructuralNode parent, String context, Map attributes, List roles, + Object content, List blocks, Integer level, String contentModel, + List subs) { + super(parent, context, attributes, roles, content, blocks, level, contentModel, subs); + } + + @Override + public boolean isBasebackend(String backend) { + return isAttribute("basebackend", backend); + } + + @Override + @Deprecated + public boolean basebackend(String backend) { + return isBasebackend(backend); + } + + @Override + public Map getOptions() { + return null; + } + + @Override + public Title getStructuredDoctitle() { + return (Title) getOptions().get("doctitle"); + } + + @Override + public String getDoctitle() { + return getTitle(); + } + + @Override + @Deprecated + public String doctitle() { + return getDoctitle(); + } + + @Override + public int getAndIncrementCounter(String name) { + throw new UnsupportedOperationException("Not implemented, yet"); + } + + @Override + public int getAndIncrementCounter(String name, int initialValue) { + throw new UnsupportedOperationException("Not implemented, yet"); + } + + @Override + public boolean isSourcemap() { + throw new UnsupportedOperationException("Not implemented, yet"); + } + + @Override + public void setSourcemap(boolean state) { + throw new UnsupportedOperationException("Not implemented, yet"); + } +} diff --git a/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/ast/impl/ListImpl.java b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/ast/impl/ListImpl.java new file mode 100644 index 00000000..b029bb19 --- /dev/null +++ b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/ast/impl/ListImpl.java @@ -0,0 +1,56 @@ +package io.github.swagger2markup.adoc.ast.impl; + +import org.asciidoctor.ast.List; +import org.asciidoctor.ast.StructuralNode; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +public class ListImpl extends StructuralNodeImpl implements List { + + private final java.util.List items; + + public ListImpl(StructuralNode parent, String context) { + this(parent, context, new ArrayList<>()); + } + + + public ListImpl(StructuralNode parent, String context, java.util.List items) { + this(parent, context, null, items); + } + + public ListImpl(StructuralNode parent, String context, Object content, java.util.List items) { + this(parent, context, new HashMap<>(), new ArrayList<>(), content, new ArrayList<>(), "", new ArrayList<>(), items); + } + + public ListImpl(StructuralNode parent, String context, Map attributes, java.util.List roles, + Object content, java.util.List blocks, + String contentModel, java.util.List subs, java.util.List items) { + this(parent, context, attributes, roles, content, blocks, null != parent ? parent.getLevel() + 1 : 0, contentModel, subs, items); + } + + public ListImpl(StructuralNode parent, String context, Map attributes, java.util.List roles, + Object content, java.util.List blocks, + Integer level, String contentModel, java.util.List subs, java.util.List items) { + super(parent, context, attributes, roles, content, blocks, level, contentModel, subs); + this.items = items; + } + + @Override + public java.util.List getItems() { + return items; + } + + @Override + public boolean hasItems() { + return !items.isEmpty(); + } + + @Override + @Deprecated + public String render() { + return convert(); + } + +} diff --git a/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/ast/impl/ListItemImpl.java b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/ast/impl/ListItemImpl.java new file mode 100644 index 00000000..bbc3d60d --- /dev/null +++ b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/ast/impl/ListItemImpl.java @@ -0,0 +1,63 @@ +package io.github.swagger2markup.adoc.ast.impl; + +import org.apache.commons.lang3.StringUtils; +import org.asciidoctor.ast.ListItem; +import org.asciidoctor.ast.StructuralNode; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class ListItemImpl extends StructuralNodeImpl implements ListItem { + + private final String marker; + private String text; + + public ListItemImpl(StructuralNode parent, String text) { + this(parent, "list_item", null, "*", text); + } + + public ListItemImpl(StructuralNode parent, String context, Object content, String marker, String text) { + this(parent, context, new HashMap<>(), new ArrayList<>(), content, new ArrayList<>(), "", new ArrayList<>(), marker, text); + } + + public ListItemImpl(StructuralNode parent, String context, Map attributes, List roles, + Object content, List blocks, String contentModel, + List subs, String marker, String text) { + this(parent, context, attributes, roles, content, blocks, null != parent ? parent.getLevel() : 1, contentModel, subs, marker, text); + } + + public ListItemImpl(StructuralNode parent, String context, Map attributes, List roles, + Object content, List blocks, Integer level, + String contentModel, List subs, String marker, String text) { + super(parent, context, attributes, roles, content, blocks, level, contentModel, subs); + this.marker = marker; + this.text = text; + } + + @Override + public String getMarker() { + return marker; + } + + @Override + public String getText() { + return text; + } + + @Override + public String getSource() { + return text; + } + + @Override + public void setSource(String source) { + this.text = source; + } + + @Override + public boolean hasText() { + return StringUtils.isNotBlank(text); + } +} diff --git a/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/ast/impl/ParagraphBlockImpl.java b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/ast/impl/ParagraphBlockImpl.java new file mode 100644 index 00000000..8037a86d --- /dev/null +++ b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/ast/impl/ParagraphBlockImpl.java @@ -0,0 +1,38 @@ +package io.github.swagger2markup.adoc.ast.impl; + +import org.asciidoctor.ast.StructuralNode; + +import java.util.List; +import java.util.Map; + +public class ParagraphBlockImpl extends BlockImpl { + + public static final String CONTEXT = "paragraph"; + + public ParagraphBlockImpl(StructuralNode parent) { + super(parent, CONTEXT); + } + + public ParagraphBlockImpl(StructuralNode parent, Object content) { + super(parent, CONTEXT, content); + } + + public ParagraphBlockImpl(StructuralNode parent, Map attributes) { + super(parent, CONTEXT, attributes); + } + + public ParagraphBlockImpl(StructuralNode parent, Map attributes, Object content) { + super(parent, CONTEXT, attributes, content); + } + + public ParagraphBlockImpl(StructuralNode parent, Map attributes, List roles, + Object content, List blocks, String contentModel, List subs) { + super(parent, CONTEXT, attributes, roles, content, blocks, contentModel, subs); + } + + public ParagraphBlockImpl(StructuralNode parent, Map attributes, List roles, + Object content, List blocks, Integer level, String contentModel, + List subs) { + super(parent, CONTEXT, attributes, roles, content, blocks, level, contentModel, subs); + } +} diff --git a/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/ast/impl/PhraseNodeImpl.java b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/ast/impl/PhraseNodeImpl.java new file mode 100644 index 00000000..963788cc --- /dev/null +++ b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/ast/impl/PhraseNodeImpl.java @@ -0,0 +1,50 @@ +package io.github.swagger2markup.adoc.ast.impl; + +import io.github.swagger2markup.adoc.AsciidocConverter; +import org.asciidoctor.ast.ContentNode; +import org.asciidoctor.ast.PhraseNode; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class PhraseNodeImpl extends ContentNodeImpl implements PhraseNode { + + private final String type; + private final String text; + private final String target; + private final AsciidocConverter converter = new AsciidocConverter(AsciidocConverter.NAME, new HashMap<>()); + + public PhraseNodeImpl(ContentNode parent, String context, Map attributes, List roles, String type, String text, String target) { + super(parent, context, attributes, roles); + this.type = type; + this.text = text; + this.target = target; + } + + @Override + @Deprecated + public String render() { + return convert(); + } + + @Override + public String convert() { + return converter.convert(this, null, new HashMap<>()); + } + + @Override + public String getType() { + return type; + } + + @Override + public String getText() { + return text; + } + + @Override + public String getTarget() { + return target; + } +} diff --git a/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/ast/impl/RowImpl.java b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/ast/impl/RowImpl.java new file mode 100644 index 00000000..02f4c29d --- /dev/null +++ b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/ast/impl/RowImpl.java @@ -0,0 +1,21 @@ +package io.github.swagger2markup.adoc.ast.impl; + +import org.asciidoctor.ast.Cell; +import org.asciidoctor.ast.Row; + +import java.util.List; + +public class RowImpl implements Row { + + private final List cells; + + public RowImpl(List cells) { + this.cells = cells; + } + + @Override + public List getCells() { + return cells; + } + +} diff --git a/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/ast/impl/SectionImpl.java b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/ast/impl/SectionImpl.java new file mode 100644 index 00000000..f67d1d1f --- /dev/null +++ b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/ast/impl/SectionImpl.java @@ -0,0 +1,118 @@ +package io.github.swagger2markup.adoc.ast.impl; + +import org.asciidoctor.ast.Section; +import org.asciidoctor.ast.StructuralNode; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class SectionImpl extends StructuralNodeImpl implements Section { + + private final Integer index; + private final Integer number; + private final String numeral; + private final String sectionName; + private final boolean special; + private final boolean numbered; + + public SectionImpl(StructuralNode parent) { + this(parent, new HashMap<>()); + } + + public SectionImpl(StructuralNode parent, Map attributes) { + this(parent, "section", null, ""); + } + + + public SectionImpl(StructuralNode parent, String context, Object content, String sectionName) { + this(parent, context, content, null, null, "", sectionName, false, false); + } + + public SectionImpl(StructuralNode parent, String context, Object content, Integer index, Integer number, String numeral, + String sectionName, boolean special, boolean numbered) { + this(parent, context, new HashMap<>(), new ArrayList<>(), content, new ArrayList<>(), + "", new ArrayList<>(), index, number, numeral, sectionName, special, numbered); + } + + public SectionImpl(StructuralNode parent, String context, Map attributes, List roles, + Object content, List blocks, String contentModel, List subs, + Integer index, Integer number, String numeral, String sectionName, boolean special, boolean numbered) { + this(parent, context, attributes, roles, content, blocks, calculateLevel(parent), contentModel, subs, index, number, numeral, sectionName, special, numbered); + } + + public SectionImpl(StructuralNode parent, String context, Map attributes, List roles, + Object content, List blocks, Integer level, String contentModel, List subs, + Integer index, Integer number, String numeral, String sectionName, boolean special, boolean numbered) { + super(parent, context, attributes, roles, content, blocks, level, contentModel, subs); + this.index = index; + this.number = number; + this.numeral = numeral; + this.sectionName = sectionName; + this.special = special; + this.numbered = numbered; + } + + @Override + @Deprecated + public int index() { + return getIndex(); + } + + @Override + public int getIndex() { + return index; + } + + @Override + @Deprecated + public int number() { + return getNumber(); + } + + @Override + @Deprecated + public int getNumber() { + return number; + } + + @Override + public String getNumeral() { + return numeral; + } + + @Override + @Deprecated + public String sectname() { + return getSectionName(); + } + + @Override + public String getSectionName() { + return sectionName; + } + + @Override + @Deprecated + public boolean special() { + return isSpecial(); + } + + @Override + public boolean isSpecial() { + return special; + } + + @Override + @Deprecated + public boolean numbered() { + return isNumbered(); + } + + @Override + public boolean isNumbered() { + return numbered; + } + +} diff --git a/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/ast/impl/StructuralNodeImpl.java b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/ast/impl/StructuralNodeImpl.java new file mode 100644 index 00000000..cb7b3230 --- /dev/null +++ b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/ast/impl/StructuralNodeImpl.java @@ -0,0 +1,179 @@ +package io.github.swagger2markup.adoc.ast.impl; + +import io.github.swagger2markup.adoc.AsciidocConverter; +import org.asciidoctor.ast.Cursor; +import org.asciidoctor.ast.StructuralNode; + +import java.util.*; + +public class StructuralNodeImpl extends ContentNodeImpl implements StructuralNode { + + private String title; + private String caption; + private String style; + private final Object content; + private final List blocks; + private Integer level; + private final String contentModel; + private List subs; + private final AsciidocConverter converter = new AsciidocConverter(AsciidocConverter.NAME, new HashMap<>()); + + public StructuralNodeImpl(StructuralNode parent, String context) { + this(parent, context, new HashMap<>()); + } + + public StructuralNodeImpl(StructuralNode parent, String context, Map attributes) { + this(parent, context, attributes, null); + } + + public StructuralNodeImpl(StructuralNode parent, String context, Object content) { + this(parent, context, new HashMap<>(), content); + } + + public StructuralNodeImpl(StructuralNode parent, String context, Map attributes, Object content) { + this(parent, context, attributes, new ArrayList<>(), content, new ArrayList<>(), "", new ArrayList<>()); + } + + public StructuralNodeImpl(StructuralNode parent, String context, Map attributes, List roles, + Object content, List blocks, String contentModel, List subs) { + this(parent, context, attributes, roles, content, blocks, calculateLevel(parent), contentModel, subs); + } + + public StructuralNodeImpl(StructuralNode parent, String context, Map attributes, List roles, + Object content, List blocks, Integer level, String contentModel, List subs) { + super(parent, context, attributes, roles); + this.content = content; + this.blocks = blocks; + this.level = level; + this.contentModel = contentModel; + this.subs = subs; + } + + @Override + @Deprecated + public String title() { + return getTitle(); + } + + @Override + public String getTitle() { + return title; + } + + @Override + public void setTitle(String title) { + this.title = title; + } + + @Override + public String getCaption() { + return caption; + } + + @Override + public void setCaption(String caption) { + this.caption = caption; + } + + @Override + @Deprecated + public String style() { + return getStyle(); + } + + @Override + public String getStyle() { + return style; + } + + @Override + public void setStyle(String style) { + this.style = style; + } + + @Override + @Deprecated + public List blocks() { + return getBlocks(); + } + + @Override + public List getBlocks() { + return blocks; + } + + @Override + public void append(StructuralNode block) { + blocks.add(block); + } + + @Override + @Deprecated + public Object content() { + return getContent(); + } + + @Override + public Object getContent() { + return content; + } + + @Override + public String convert() { + return converter.convert(this, null, new HashMap<>()); + } + + @Override + public int getLevel() { + return level; + } + + @Override + public Cursor getSourceLocation() { + return new CursorImpl(); + } + + @Override + public String getContentModel() { + return contentModel; + } + + @Override + public List getSubstitutions() { + return subs; + } + + @Override + public boolean isSubstitutionEnabled(String substitution) { + return subs.contains(substitution); + } + + @Override + public void removeSubstitution(String substitution) { + subs.remove(substitution); + } + + @Override + public void addSubstitution(String substitution) { + subs.add(substitution); + } + + @Override + public void prependSubstitution(String substitution) { + } + + @Override + public void setSubstitutions(String... substitutions) { + subs = Arrays.asList(substitutions); + } + + @Override + public List findBy(Map selector) { + throw new UnsupportedOperationException("Not implemented, yet"); + } + + protected static Integer calculateLevel(StructuralNode parent) { + return null != parent ? parent.getLevel() + 1 : 0; + } + +} diff --git a/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/ast/impl/TableImpl.java b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/ast/impl/TableImpl.java new file mode 100644 index 00000000..80a19666 --- /dev/null +++ b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/ast/impl/TableImpl.java @@ -0,0 +1,306 @@ +package io.github.swagger2markup.adoc.ast.impl; + +import org.asciidoctor.ast.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.List; +import java.util.*; + +public class TableImpl extends StructuralNodeImpl implements Table { + public static final String OPTION_UNBREAKABLE = "unbreakable"; + public static final String OPTION_BREAKABLE = "breakable"; + private Logger logger = LoggerFactory.getLogger(getClass()); + public static final String CONTEXT = "table"; + private static final String FRAME_ATTR = "frame"; + private static final String GRID_ATTR = "grid"; + private RowList headerRows; + private RowList bodyRows; + private RowList footerRows; + + private List columns = new ArrayList<>(); + + public TableImpl(StructuralNode parent) { + this(parent, new HashMap<>(), new ArrayList<>()); + } + + public TableImpl(StructuralNode parent, Map attributes, List roles) { + this(parent, attributes, roles, calculateLevel(parent)); + } + + public TableImpl(StructuralNode parent, Map attributes, List roles, Integer level) { + this(parent, attributes, roles, null, new ArrayList<>(), level, "", new ArrayList<>()); + } + + public TableImpl(StructuralNode parent, Map attributes, List roles, + Object content, List blocks, Integer level, String contentModel, List subs) { + super(parent, CONTEXT, attributes, roles, content, blocks, level, contentModel, subs); + this.headerRows = new RowList(new ArrayList<>()); + this.bodyRows = new RowList(new ArrayList<>()); + this.footerRows = new RowList(new ArrayList<>()); + } + + @Override + public boolean hasHeaderOption() { + return isOption("header"); + } + + @Override + public String getFrame() { + return (String) getAttribute(FRAME_ATTR, "all"); + } + + @Override + public void setFrame(String frame) { + setAttribute(FRAME_ATTR, frame, true); + } + + @Override + public String getGrid() { + return (String) getAttribute(GRID_ATTR, "all"); + } + + @Override + public void setGrid(String grid) { + setAttribute(GRID_ATTR, grid, true); + } + + @Override + public List getColumns() { + return columns; + } + + @Override + public List getHeader() { + return headerRows; + } + + public void setHeaderRow(Row row) { + headerRows.clear(); + headerRows.add(row); + scanRowForColumns(row); + } + + public void setHeaderRow(List cells) { + setHeaderRow(new RowImpl(cells)); + } + + public void setHeaderRow(String... documentContents) { + headerRows.clear(); + headerRows.add(generateRow(documentContents)); + } + + public RowImpl generateRow(Document... innerDocs) { + List cells = new ArrayList<>(); + for (int i = 0; i < innerDocs.length; i++) { + + Column column = null; + try { + column = columns.get(i); + } catch (Exception ignored) { + } + + if (null == column) { + ColumnImpl newColumn = new ColumnImpl(this); + newColumn.setColumnNumber(i + 1); + column = newColumn; + addColumnAt(column, i); + } + cells.add(new CellImpl(column, innerDocs[i])); + + } + return new RowImpl(cells); + } + + public RowImpl generateRow(String... documentContents) { + Document[] documents = Arrays.stream(documentContents).map(documentContent -> { + Document innerDoc = new DocumentImpl(); + Block paragraph = new ParagraphBlockImpl(innerDoc); + paragraph.setSource(documentContent); + innerDoc.append(paragraph); + return innerDoc; + }).toArray(Document[]::new); + return generateRow(documents); + } + + @Override + public List getBody() { + return bodyRows; + } + + public void setBodyRows(List rows) { + bodyRows.clear(); + bodyRows.addAll(rows); + bodyRows.forEach(this::scanRowForColumns); + } + + public void addRow(Row row) { + bodyRows.add(row); + scanRowForColumns(row); + } + + public void addRow(List cells) { + bodyRows.add(new RowImpl(cells)); + } + + public RowImpl addRow(Document... documentContents) { + RowImpl row = generateRow(documentContents); + bodyRows.add(row); + return row; + } + + public RowImpl addRow(String... documentContents) { + RowImpl row = generateRow(documentContents); + bodyRows.add(row); + return row; + } + + @Override + public List getFooter() { + return footerRows; + } + + public void setFooterRow(Row row) { + footerRows.clear(); + footerRows.add(row); + scanRowForColumns(row); + } + + public void setFooterRow(String... documentContents) { + footerRows.clear(); + footerRows.add(generateRow(documentContents)); + } + + private void scanRowForColumns(Row row) { + row.getCells().forEach(cell -> { + Column column = cell.getColumn(); + int i = column.getColumnNumber() - 1; + addColumnAt(column, i); + }); + } + + private void addColumnAt(Column column, int i) { + if (columns.size() >= i) { + columns.add(i, column); + } else { + while (columns.size() < i) { + columns.add(columns.size(), null); + } + columns.add(column); + } + } + + public void setFooterRow(List cells) { + setFooterRow(new RowImpl(cells)); + } + + class RowList extends AbstractList { + + private final List rubyArray; + + private RowList(List rubyArray) { + this.rubyArray = rubyArray; + } + + @Override + public int size() { + return rubyArray.size(); + } + + @Override + public boolean isEmpty() { + return rubyArray.isEmpty(); + } + + @Override + public boolean contains(Object o) { + return rubyArray.contains(o); + } + + @Override + public boolean add(Row row) { + boolean changed = false; + try { + changed = rubyArray.add(row); + setAttribute("rowcount", size(), true); + } catch (Exception e) { + logger.debug("Couldn't add row", e); + } + return changed; + } + + @Override + public boolean remove(Object o) { + if (!(o instanceof RowImpl)) { + return false; + } + try { + boolean changed = rubyArray.remove(o); + setAttribute("rowcount", size(), true); + return changed; + } catch (Exception e) { + logger.debug("Couldn't add row", e); + return false; + } + } + + @Override + public boolean retainAll(Collection c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + rubyArray.clear(); + setAttribute("rowcount", size(), true); + } + + @Override + public Row get(int index) { + return rubyArray.get(index); + } + + @Override + public Row set(int index, Row element) { + Row oldRow = get(index); + rubyArray.set(index, element); + return oldRow; + } + + @Override + public void add(int index, Row element) { + rubyArray.add(index, element); + setAttribute("rowcount", size(), true); + } + + @Override + public Row remove(int index) { + Row removed = rubyArray.remove(index); + setAttribute("rowcount", size(), true); + return removed; + } + + @Override + public int indexOf(Object o) { + if (!(o instanceof RowImpl)) { + return -1; + } + return rubyArray.indexOf(o); + } + + @Override + public int lastIndexOf(Object o) { + if (!(o instanceof RowImpl)) { + return -1; + } + return rubyArray.lastIndexOf(o); + } + } + + protected static Integer calculateLevel(StructuralNode parent) { + int level = 1; + if (parent instanceof Table) + level = parent.getLevel() + 1; + return level; + } +} diff --git a/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/ast/impl/TitleImpl.java b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/ast/impl/TitleImpl.java new file mode 100644 index 00000000..ed594e04 --- /dev/null +++ b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/ast/impl/TitleImpl.java @@ -0,0 +1,34 @@ +package io.github.swagger2markup.adoc.ast.impl; + +import org.asciidoctor.ast.Title; + +public class TitleImpl implements Title { + + private final String main; + private final String subtitle; + + public TitleImpl(String main, String subtitle) { + this.main = main; + this.subtitle = subtitle; + } + + @Override + public String getMain() { + return main; + } + + @Override + public String getSubtitle() { + return subtitle; + } + + @Override + public String getCombined() { + return main + ": " + subtitle; + } + + @Override + public boolean isSanitized() { + return false; + } +} diff --git a/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/converter/internal/BlockImageNode.java b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/converter/internal/BlockImageNode.java new file mode 100644 index 00000000..d8711b01 --- /dev/null +++ b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/converter/internal/BlockImageNode.java @@ -0,0 +1,50 @@ +package io.github.swagger2markup.adoc.converter.internal; + +import org.apache.commons.lang3.StringUtils; +import org.asciidoctor.ast.ContentNode; + +public class BlockImageNode extends NodeAttributes { + + final private String target; + + public BlockImageNode(ContentNode node) { + super(node.getAttributes()); + target = pop("target").replaceAll("\\s", "{sp}"); + } + + public String getTarget() { + return target; + } + + @Override + public void processPositionalAttributes() { + String attr1 = pop("1", "alt"); + if (StringUtils.isNotBlank(attr1)) { + attrs.add(attr1); + } + + String attr2 = pop("2", "width"); + if (StringUtils.isNotBlank(attr2)) { + attrs.add(attr2); + } + + String attr3 = pop("3", "height"); + if (StringUtils.isNotBlank(attr3)) { + attrs.add(attr3); + } + } + + @Override + void processAttributes() { + attributes.forEach((k, v) -> { + if (!k.equals("role") && null != v) { + attrs.add(k + "=" + v); + } + }); + } + + @Override + public String processAsciiDocContent() { + return "image::" + target + '[' + String.join(",", attrs) + ']'; + } +} diff --git a/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/converter/internal/BlockListingNode.java b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/converter/internal/BlockListingNode.java new file mode 100644 index 00000000..87c67f6b --- /dev/null +++ b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/converter/internal/BlockListingNode.java @@ -0,0 +1,31 @@ +package io.github.swagger2markup.adoc.converter.internal; + +import org.asciidoctor.ast.Block; + +import java.util.List; + +import static io.github.swagger2markup.adoc.converter.internal.Delimiters.*; + +public class BlockListingNode extends ParagraphAttributes { + + final private Block node; + + public BlockListingNode(Block node) { + super(node); + this.node = node; + } + + @Override + public String processAsciiDocContent() { + StringBuilder sb = new StringBuilder(); + attrsToString(sb, attrs); + sb.append(LINE_SEPARATOR).append(DELIMITER_BLOCK).append(LINE_SEPARATOR).append(node.getSource()).append(LINE_SEPARATOR).append(DELIMITER_BLOCK).append(LINE_SEPARATOR); + return sb.toString(); + } + + void attrsToString(StringBuilder sb, List list) { + if (!list.isEmpty()) { + sb.append(ATTRIBUTES_BEGIN).append(String.join(",", list)).append(ATTRIBUTES_END).append(LINE_SEPARATOR); + } + } +} diff --git a/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/converter/internal/DelimitedBlockNode.java b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/converter/internal/DelimitedBlockNode.java new file mode 100644 index 00000000..64c05140 --- /dev/null +++ b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/converter/internal/DelimitedBlockNode.java @@ -0,0 +1,45 @@ +package io.github.swagger2markup.adoc.converter.internal; + +import org.apache.commons.lang3.StringUtils; +import org.asciidoctor.ast.StructuralNode; + +import java.util.ArrayList; +import java.util.List; + +import static io.github.swagger2markup.adoc.converter.internal.Delimiters.*; + +public class DelimitedBlockNode extends ParagraphAttributes { + + public DelimitedBlockNode(StructuralNode node) { + super(node); + } + + @Override + public void processPositionalAttributes() { + String source = pop("1", "style"); + StringBuilder options = new StringBuilder(); + List toRemove = new ArrayList<>(); + attributes.forEach((k, v) -> { + if (k.endsWith(OPTION_SUFFIX)) { + toRemove.add(k); + options.append('%').append(k.replace(OPTION_SUFFIX, "")); + } + }); + toRemove.forEach(attributes::remove); + source += options.toString(); + + if (StringUtils.isNotBlank(source)) { + attrs.add(source); + } + super.processPositionalAttributes(); + } + + @Override + public String processAsciiDocContent() { + StringBuilder sb = new StringBuilder(); + if (!attrs.isEmpty()) { + sb.append(ATTRIBUTES_BEGIN).append(String.join(",", attrs)).append(ATTRIBUTES_END).append(LINE_SEPARATOR); + } + return sb.toString(); + } +} diff --git a/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/converter/internal/Delimiters.java b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/converter/internal/Delimiters.java new file mode 100644 index 00000000..788351eb --- /dev/null +++ b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/converter/internal/Delimiters.java @@ -0,0 +1,26 @@ +package io.github.swagger2markup.adoc.converter.internal; + +public class Delimiters { + public static final String ATTRIBUTES_BEGIN = "["; + public static final String ATTRIBUTES_END = "]"; + public static final String COLON = ":"; + public static final String DELIMITER_BLOCK = "----"; + public static final String DELIMITER_EXAMPLE = "===="; + public static final String DELIMITER_INNER_TABLE_CELL = "!"; + public static final String DELIMITER_INNER_TABLE = "!==="; + public static final String DELIMITER_PAGE_BREAK = "<<<"; + public static final String DELIMITER_OPEN_BLOCK = "--"; + public static final String DELIMITER_SIDEBAR = "****"; + public static final String DELIMITER_TABLE = "|==="; + public static final String DELIMITER_TABLE_CELL = "|"; + public static final String DELIMITER_THEMATIC_BREAK = "'''"; + public static final String DELIMITER_VERSE = "____"; + public static final String DOCUMENT_TITLE = "="; + public static final String LINE_SEPARATOR = "\n"; + public static final String MARKER_LIST_ITEM = "*"; + public static final String MARKER_D_LIST_ITEM = ":"; + public static final String STYLE_HORIZONTAL = "horizontal"; + public static final String STYLE_Q_AND_A = "qanda"; + public static final String STYLE_SOURCE = "source"; + public static final String TITLE = "="; +} diff --git a/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/converter/internal/IconNode.java b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/converter/internal/IconNode.java new file mode 100644 index 00000000..a629d71c --- /dev/null +++ b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/converter/internal/IconNode.java @@ -0,0 +1,38 @@ +package io.github.swagger2markup.adoc.converter.internal; + +import org.apache.commons.lang3.StringUtils; +import org.asciidoctor.ast.ContentNode; + +public class IconNode extends NodeAttributes { + + final private String alt; + + public IconNode(ContentNode node) { + super(node.getAttributes()); + alt = pop("alt", "default-alt"); + } + + public String getAlt() { + return alt; + } + + @Override + void processPositionalAttributes() { + String attr1 = pop("1", "size"); + if (StringUtils.isNotBlank(attr1)) { + attrs.add(attr1); + } + } + + @Override + void processAttributes() { + attributes.forEach((k, v) -> { + attrs.add(k + "=" + v); + }); + } + + @Override + String processAsciiDocContent() { + return "icon:" + alt + '[' + String.join(",", attrs) + ']'; + } +} diff --git a/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/converter/internal/NodeAttributes.java b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/converter/internal/NodeAttributes.java new file mode 100644 index 00000000..ece2e5aa --- /dev/null +++ b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/converter/internal/NodeAttributes.java @@ -0,0 +1,64 @@ +package io.github.swagger2markup.adoc.converter.internal; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.atomic.AtomicReference; +import java.util.stream.Stream; + +import static io.github.swagger2markup.adoc.converter.internal.Delimiters.*; + +abstract class NodeAttributes { + public static final String TITLE = "title"; + + final Map attributes; + List attrs = new ArrayList<>(); + + NodeAttributes(Map attributes) { + this.attributes = attributes; + } + + public String pop(String... keys) { + AtomicReference value = new AtomicReference<>(""); + Stream.of(keys).forEach(key -> { + try { + String tmpValue = attributes.remove(key).toString(); + if (null != tmpValue && !tmpValue.isEmpty() && value.get().isEmpty()) { + value.set(tmpValue); + } + } catch (NullPointerException ignored) { + } + }); + return value.get(); + } + + String pop(String key) { + try { + String value = attributes.remove(key).toString(); + if (null == value) { + value = ""; + } + return value; + } catch (NullPointerException ignored) { + return ""; + } + } + + final public String toAsciiDocContent() { + processPositionalAttributes(); + processAttributes(); + return processAsciiDocContent(); + } + + abstract void processPositionalAttributes(); + + abstract void processAttributes(); + + String processAsciiDocContent() { + StringBuilder sb = new StringBuilder(); + if (!attrs.isEmpty()) { + sb.append(ATTRIBUTES_BEGIN).append(String.join(",", attrs)).append(ATTRIBUTES_END).append(LINE_SEPARATOR); + } + return sb.toString(); + } +} diff --git a/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/converter/internal/ParagraphAttributes.java b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/converter/internal/ParagraphAttributes.java new file mode 100644 index 00000000..4af628ec --- /dev/null +++ b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/converter/internal/ParagraphAttributes.java @@ -0,0 +1,63 @@ +package io.github.swagger2markup.adoc.converter.internal; + +import org.apache.commons.lang3.StringUtils; +import org.asciidoctor.ast.StructuralNode; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.List; + +public class ParagraphAttributes extends NodeAttributes { + + public static final String OPTION_SUFFIX = "-option"; + private Logger logger = LoggerFactory.getLogger(getClass()); + + public ParagraphAttributes(StructuralNode node) { + super(node.getAttributes()); + } + + @Override + public void processPositionalAttributes() { + String attr1 = pop("1", "style"); + if (StringUtils.isNotBlank(attr1)) { + attrs.add(attr1); + } + } + + @Override + void processAttributes() { + String id = pop("id"); + if (StringUtils.isNotBlank(id)) { + id = "#" + id; + } + String roles = String.join(".", pop("role").split(" ")); + if (StringUtils.isNotBlank(roles)) { + roles = "." + roles; + } + StringBuilder options = new StringBuilder(); + List namedAttributes = new ArrayList<>(); + + attributes.forEach((k, v) -> { + if (k.equals(TITLE)) { + logger.debug("Skipping attribute: " + TITLE); + } else if (k.endsWith(OPTION_SUFFIX)) { + options.append('%').append(k.replace(OPTION_SUFFIX, "")); + } else if (null != v) { + if(v.toString().contains(" ") || v.toString().contains(",")) { + namedAttributes.add(k + "=\"" + v +"\""); + } else { + namedAttributes.add(k + "=" + v); + } + } else { + logger.warn("Don't know how to handle key: " + k); + } + }); + + String nonNamedAttributes = id + roles + options.toString(); + if (StringUtils.isNotBlank(nonNamedAttributes)) { + attrs.add(nonNamedAttributes); + } + attrs.addAll(namedAttributes); + } +} diff --git a/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/converter/internal/SourceNode.java b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/converter/internal/SourceNode.java new file mode 100644 index 00000000..69339f1c --- /dev/null +++ b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/converter/internal/SourceNode.java @@ -0,0 +1,53 @@ +package io.github.swagger2markup.adoc.converter.internal; + +import org.apache.commons.lang3.StringUtils; +import org.asciidoctor.ast.Block; + +import java.util.ArrayList; +import java.util.List; + +import static io.github.swagger2markup.adoc.converter.internal.Delimiters.*; + +public class SourceNode extends BlockListingNode { + + private List sourceAttrs = new ArrayList<>(); + private final Block node; + + public SourceNode(Block node) { + super(node); + this.node = node; + } + + @Override + public void processPositionalAttributes() { + String source = pop("1", "style"); + String language = pop("2", "language"); + StringBuilder options = new StringBuilder(); + List toRemove = new ArrayList<>(); + attributes.forEach((k, v) -> { + if (k.endsWith(OPTION_SUFFIX)) { + toRemove.add(k); + options.append('%').append(k.replace(OPTION_SUFFIX, "")); + } + }); + toRemove.forEach(attributes::remove); + source += options.toString(); + + if (StringUtils.isNotBlank(source)) { + sourceAttrs.add(source); + } + if (StringUtils.isNotBlank(language)) { + sourceAttrs.add(language); + } + super.processPositionalAttributes(); + } + + @Override + public String processAsciiDocContent() { + StringBuilder sb = new StringBuilder(); + attrsToString(sb, attrs); + attrsToString(sb, sourceAttrs); + sb.append(LINE_SEPARATOR).append(DELIMITER_BLOCK).append(LINE_SEPARATOR).append(node.getSource()).append(LINE_SEPARATOR).append(DELIMITER_BLOCK).append(LINE_SEPARATOR); + return sb.toString(); + } +} diff --git a/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/converter/internal/Style.java b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/converter/internal/Style.java new file mode 100644 index 00000000..3589da40 --- /dev/null +++ b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/converter/internal/Style.java @@ -0,0 +1,35 @@ +package io.github.swagger2markup.adoc.converter.internal; + +import org.apache.commons.lang3.StringUtils; + +public enum Style { + ASCIIDOC("a"), EMPHASIS("e"), HEADER("h"), LITERAL("l"), MONOSPACED("m"), NONE("d"), STRONG("s"), VERSE("v"); + + String shortHand; + + Style(String h) { + this.shortHand = h; + } + + public static Style fromString(String text) { + if(StringUtils.isNotBlank(text)) { + for (Style s : Style.values()) { + if (s.shortHand.equalsIgnoreCase(text)) { + return s; + } + } + } + return null; + } + + public static Style fromName(String text) { + if(StringUtils.isNotBlank(text)) { + return valueOf(text.toUpperCase()); + } + return null; + } + + public String getShortHand() { + return shortHand; + } +} diff --git a/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/converter/internal/TableCellHorizontalAlignment.java b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/converter/internal/TableCellHorizontalAlignment.java new file mode 100644 index 00000000..579bdc43 --- /dev/null +++ b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/converter/internal/TableCellHorizontalAlignment.java @@ -0,0 +1,35 @@ +package io.github.swagger2markup.adoc.converter.internal; + +import org.apache.commons.lang3.StringUtils; + +public enum TableCellHorizontalAlignment { + LEFT("<"), CENTER("^"), RIGHT(">"); + + String delimiter; + + TableCellHorizontalAlignment(String s) { + this.delimiter = s; + } + + public static TableCellHorizontalAlignment fromString(String text) { + if(StringUtils.isNotBlank(text)) { + for (TableCellHorizontalAlignment a : TableCellHorizontalAlignment.values()) { + if (a.delimiter.equalsIgnoreCase(text)) { + return a; + } + } + } + return null; + } + + public static TableCellHorizontalAlignment fromName(String text) { + if(StringUtils.isNotBlank(text)) { + return valueOf(text.toUpperCase()); + } + return null; + } + + public String getDelimiter() { + return delimiter; + } +} diff --git a/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/converter/internal/TableCellStyle.java b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/converter/internal/TableCellStyle.java new file mode 100644 index 00000000..f2341e6a --- /dev/null +++ b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/converter/internal/TableCellStyle.java @@ -0,0 +1,15 @@ +package io.github.swagger2markup.adoc.converter.internal; + +public class TableCellStyle { + public final TableCellHorizontalAlignment horizontalAlignment; + public final TableCellVerticalAlignment verticalAlignment; + public final Style style; + public final int width; + + public TableCellStyle(TableCellHorizontalAlignment horizontalAlignment, TableCellVerticalAlignment verticalAlignment, Style style, int width) { + this.horizontalAlignment = horizontalAlignment; + this.verticalAlignment = verticalAlignment; + this.style = style; + this.width = width; + } +} diff --git a/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/converter/internal/TableCellVerticalAlignment.java b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/converter/internal/TableCellVerticalAlignment.java new file mode 100644 index 00000000..8fdf5751 --- /dev/null +++ b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/converter/internal/TableCellVerticalAlignment.java @@ -0,0 +1,35 @@ +package io.github.swagger2markup.adoc.converter.internal; + +import org.apache.commons.lang3.StringUtils; + +public enum TableCellVerticalAlignment { + TOP(".<"), MIDDLE(".^"), BOTTOM(".>"); + + String delimiter; + + TableCellVerticalAlignment(String s) { + this.delimiter = s; + } + + public static TableCellVerticalAlignment fromString(String text) { + if(StringUtils.isNotBlank(text)) { + for (TableCellVerticalAlignment a : TableCellVerticalAlignment.values()) { + if (a.delimiter.equalsIgnoreCase(text)) { + return a; + } + } + } + return null; + } + + public static TableCellVerticalAlignment fromName(String text) { + if(StringUtils.isNotBlank(text)) { + return valueOf(text.toUpperCase()); + } + return null; + } + + public String getDelimiter() { + return delimiter; + } +} diff --git a/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/converter/internal/TableNode.java b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/converter/internal/TableNode.java new file mode 100644 index 00000000..383d4e76 --- /dev/null +++ b/swagger2markup-asciidoc/src/main/java/io/github/swagger2markup/adoc/converter/internal/TableNode.java @@ -0,0 +1,15 @@ +package io.github.swagger2markup.adoc.converter.internal; + +import org.asciidoctor.ast.Table; + +public class TableNode extends DelimitedBlockNode { + public TableNode(Table table) { + super(table); + } + + @Override + void processAttributes() { + pop("colcount", "rowcount", "tablepcwidth"); + super.processAttributes(); + } +} diff --git a/swagger2markup-asciidoc/src/main/resources/servivces/org.asciidoctor.jruby.converter.spi.ConverterRegistry b/swagger2markup-asciidoc/src/main/resources/servivces/org.asciidoctor.jruby.converter.spi.ConverterRegistry new file mode 100644 index 00000000..815ad0bc --- /dev/null +++ b/swagger2markup-asciidoc/src/main/resources/servivces/org.asciidoctor.jruby.converter.spi.ConverterRegistry @@ -0,0 +1 @@ +io.github.swagger2markup.adoc.AsciiDocConverterRegistry diff --git a/swagger2markup-asciidoc/src/test/java/io/github/swagger2markup/adoc/AsciidocConverterTest.java b/swagger2markup-asciidoc/src/test/java/io/github/swagger2markup/adoc/AsciidocConverterTest.java new file mode 100644 index 00000000..30ea9e42 --- /dev/null +++ b/swagger2markup-asciidoc/src/test/java/io/github/swagger2markup/adoc/AsciidocConverterTest.java @@ -0,0 +1,50 @@ +package io.github.swagger2markup.adoc; + +import org.apache.commons.io.IOUtils; +import org.asciidoctor.Asciidoctor; +import org.asciidoctor.OptionsBuilder; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.Arrays; + +import static org.junit.Assert.*; + +@RunWith(Parameterized.class) +public class AsciidocConverterTest { + + private Asciidoctor asciidoctor = Asciidoctor.Factory.create(); + + @Parameterized.Parameters(name = "Run {index}: file={0}") + public static Iterable data() { + return Arrays.asList( + "simple.adoc", + "arrows-and-boxes-example.ad", + "brokeninclude.asciidoc", + "changeattribute.adoc", + "chronicles-example.adoc", + "document-with-arrays.adoc" + ); + } + + @Parameterized.Parameter + public String asciidocFile; + + + @Test + public void converts_asciidoc_to_asciidoc() throws IOException { + //Given + String originalAsciiDoc = IOUtils.toString(getClass().getResourceAsStream("/asciidoc/original/" + asciidocFile), StandardCharsets.UTF_8); + String expectedAsciiDoc = IOUtils.toString(getClass().getResourceAsStream("/asciidoc/expected/" + asciidocFile), StandardCharsets.UTF_8); + + //When + asciidoctor.javaConverterRegistry().register(AsciidocConverter.class, AsciidocConverter.NAME); + String result = asciidoctor.convert(originalAsciiDoc, OptionsBuilder.options().backend(AsciidocConverter.NAME).headerFooter(false).asMap()); + + //Then + assertEquals(expectedAsciiDoc, result); + } +} diff --git a/swagger2markup-asciidoc/src/test/resources/asciidoc/expected/arrows-and-boxes-example.ad b/swagger2markup-asciidoc/src/test/resources/asciidoc/expected/arrows-and-boxes-example.ad new file mode 100644 index 00000000..673ff0b2 --- /dev/null +++ b/swagger2markup-asciidoc/src/test/resources/asciidoc/expected/arrows-and-boxes-example.ad @@ -0,0 +1,34 @@ += Document Title +:tip-caption: Tip +:appendix-caption: Appendix +:appendix-refsig: Appendix +:toc-title: Table of Contents +:iconsdir: ./images/icons +:warning-caption: Warning +:figure-caption: Figure +:attribute-missing: skip +:section-refsig: Section +:toc-placement: auto +:important-caption: Important +:note-caption: Note +:stylesdir: . +:untitled-label: Untitled +:max-include-depth: 64 +:caution-caption: Caution +:user-home: . +:max-attribute-value-size: 4096 +:safe-mode-level: 20 +:safe-mode-name: secure +:table-caption: Table +:part-refsig: Part +:authorcount: 0 +:example-caption: Example +:version-label: Version +:last-update-label: Last updated +:doctype: article +:chapter-refsig: Chapter +:attribute-undefined: drop-line + +[arrowsAndBoxes] +(User) > (Admin) + diff --git a/swagger2markup-asciidoc/src/test/resources/asciidoc/expected/brokeninclude.asciidoc b/swagger2markup-asciidoc/src/test/resources/asciidoc/expected/brokeninclude.asciidoc new file mode 100644 index 00000000..89c7c6cd --- /dev/null +++ b/swagger2markup-asciidoc/src/test/resources/asciidoc/expected/brokeninclude.asciidoc @@ -0,0 +1,33 @@ += Title +:tip-caption: Tip +:appendix-caption: Appendix +:appendix-refsig: Appendix +:toc-title: Table of Contents +:iconsdir: ./images/icons +:warning-caption: Warning +:figure-caption: Figure +:attribute-missing: skip +:section-refsig: Section +:toc-placement: auto +:important-caption: Important +:note-caption: Note +:stylesdir: . +:untitled-label: Untitled +:max-include-depth: 64 +:caution-caption: Caution +:user-home: . +:max-attribute-value-size: 4096 +:safe-mode-level: 20 +:safe-mode-name: secure +:table-caption: Table +:part-refsig: Part +:authorcount: 0 +:example-caption: Example +:version-label: Version +:last-update-label: Last updated +:doctype: article +:chapter-refsig: Chapter +:attribute-undefined: drop-line + +link:b.adoc[] + diff --git a/swagger2markup-asciidoc/src/test/resources/asciidoc/expected/changeattribute.adoc b/swagger2markup-asciidoc/src/test/resources/asciidoc/expected/changeattribute.adoc new file mode 100644 index 00000000..df78baea --- /dev/null +++ b/swagger2markup-asciidoc/src/test/resources/asciidoc/expected/changeattribute.adoc @@ -0,0 +1,33 @@ += Document Title +:tip-caption: Tip +:appendix-caption: Appendix +:appendix-refsig: Appendix +:toc-title: Table of Contents +:iconsdir: ./images/icons +:warning-caption: Warning +:figure-caption: Figure +:attribute-missing: skip +:section-refsig: Section +:toc-placement: auto +:important-caption: Important +:note-caption: Note +:stylesdir: . +:untitled-label: Untitled +:max-include-depth: 64 +:caution-caption: Caution +:user-home: . +:max-attribute-value-size: 4096 +:safe-mode-level: 20 +:safe-mode-name: secure +:table-caption: Table +:part-refsig: Part +:authorcount: 0 +:example-caption: Example +:version-label: Version +:last-update-label: Last updated +:doctype: article +:chapter-refsig: Chapter +:attribute-undefined: drop-line + +sample {content} + diff --git a/swagger2markup-asciidoc/src/test/resources/asciidoc/expected/chronicles-example.adoc b/swagger2markup-asciidoc/src/test/resources/asciidoc/expected/chronicles-example.adoc new file mode 100644 index 00000000..09ab7923 --- /dev/null +++ b/swagger2markup-asciidoc/src/test/resources/asciidoc/expected/chronicles-example.adoc @@ -0,0 +1,535 @@ += The Dangerous & _Thrilling_ Documentation Chronicles: Based on True Events +Kismet Caméléon; Lazarus het Draeke +v1.0, 2014-01-01 +:tip-caption: Tip +:appendix-caption: Appendix +:toclevels: 3 +:appendix-refsig: Appendix +:author_2: Lazarus het Draeke +:uri-stbernardusabt12: http://www.sintbernardus.be/stbernardusabt12.php?l=en +:authorinitials: KC +:author_1: Kismet Caméléon +:toc-title: Table of Contents +:iconsdir: ./images/icons +:author: Kismet Caméléon +:warning-caption: Warning +:figure-caption: Figure +:lastname: Caméléon +:attribute-missing: skip +:lastname_1: Caméléon +:section-refsig: Section +:uri-devoxx: https://devoxx.be +:lastname_2: het Draeke +:toc-placement: auto +:important-caption: Important +:authors: Kismet Caméléon, Lazarus het Draeke +:note-caption: Note +:firstname: Kismet +:stylesdir: . +:uri-devoxx-top-talks: https://www.youtube.com/watch?v=1OpAgZvYXLQ&list=PLRsbF2sD7JVq7fv1GZGORShSUIae1ZAPy&index=1 +:untitled-label: Untitled +:description: This story chronicles the inexplicable hazards and vicious beasts a team must conquer and vanquish on their journey to discovering the true power of Open Source. +:max-include-depth: 64 +:caution-caption: Caution +:listing-caption: Listing +:user-home: . +:max-attribute-value-size: 4096 +:safe-mode-level: 20 +:safe-mode-name: secure +:table-caption: Table +:part-refsig: Part +:firstname_1: Kismet +:authorcount: 2 +:revdate: 2014-01-01 +:example-caption: Example +:firstname_2: Lazarus +:version-label: Version +:revnumber: 1.0 +:last-update-label: Last updated +:doctype: book +:chapter-refsig: Chapter +:uri-wolpertinger: http://en.wikipedia.org/wiki/Wolpertinger +:organization: Company Name +:authorinitials_1: KC +:authorinitials_2: Lh +:attribute-undefined: drop-line + +[abstract] +{description} +[[_its_a_city_under_siege]] +== It’s a City Under Siege +This journey begins one late Monday afternoon at {uri-devoxx}[((Devoxx))]. +Our team needs coffee, _desperately_, but none of us dare open the theater doors... + +During the {uri-devoxx-top-talks}[opening university session], a script-happy warlock inadvertently released a legion of Wolpertingers! +To leave now would mean *code dismemberment and certain death*. + +Behold -> the horror! + +.Wolpertinger, stuffed +[.left.thumb] +image::wolpertinger.jpg[Wolpertinger,link=http://en.wikipedia.org/wiki/Wolpertinger,pdfwidth=50%] +(((Wolpertinger))) +(((Ravenous Beast,Wolpertinger))) +You may not be familiar with these {uri-wolpertinger}[ravenous beasts]. +Trust us, they'll eat your shorts and suck loops from your code. +In light of this danger, we've searched high and wide for the security crew's defensive operations manual. +We can't find it and the DefOps{empty}footnote:defops[DefOps is a portmanteau of "`defensive`" and "`operations`".] werewolves haven't returned from their rendezvous at Bier Central. +They've either eaten each other or fallen victim to the Wolpertingers roaming the streets of ((Antwerp)). +Quick, hit kbd:[Ctrl,Alt,Backspace] or select menu:File[Quit] and let's bail out of here! + +WARNING: Working with DefOps{empty}footnote:defops[] werewolves leads to howling and trying to train aggressive regular expressions with Pavlovian reinforcement. +_Weak light from the hallway trickled across the theater, chased by a distant scream._ + +[[_rendezvous_point]] +=== Rendezvous Point +Come on, [[bier-central,Bier Central]]_Bier Central_, of course! +Did you have to ask? +If you beat me there, order me a {uri-stbernardusabt12}[St. Bernardus Abt 12]. +Here's some €. + +[[ravages]] +[#ravages] +== The Ravages of Writing +Crystalline XML tags relentlessly bombarded the theater. + +.XML tags +[source,xml] + +---- + + + Lazarus + het Draeke + + +---- +Despite the assault, we continued our pursuit to draft a DefOps{empty}footnote:defops[] plan. + +.DefOps Plan +==== +Click btn:[Download Zip] to download the defensive operation plan bundle. + +OMG! +Somebody please save us now! +I want my mum -- and an extra-large double macchiato, please. + +==== +Unfortunately, Lazarus and I had both come to the conclusion that we weren't going to get out of this without corrupted hardrives if we didn't locate caffeine within the next few hours. + +[[_a_recipe_for_potion_that_will_ensure_you_win_the_hearts_of_developers]] +=== A Recipe for Potion That Will Ensure You Win the Hearts of Developers +This potion for a sample document contains the following ingredients, which are listed in a very random, chaotically nested order. + +.Ingredients for Potion that Demystifies Documents +* all the headings +** syntax highlighted source code +*** non-syntax highlighted source code or just a listing block + +* quote block +** verse block +*** table with some cell formatting +**** sequential paragraphs +***** admonition blocks, but use them sparingly + +*** bullet list with nesting + +** numbered list with nesting +** definition list +*** sidebar + +* example block +** block image (no inline images) +*** inline formatting in a paragraph +**** two fresh Burdockian leaves +***** They must be harvested by the light of the teal moons. + +Are you square? + +[square] +* one +* two +* three + +What is there to do? + +* [x] Done +* [ ] Next +* Who's counting? + +[[_searching_for_burdockian]] +==== Searching for Burdockian +.Steps for finding and preparing Burdockian leaves +. Locate dusty botany +.. Sneeze +... Sneeze some more + +. Find section on Burdockian +.. Review its characteristics +... Take a picture of the diagram of its leaves +.... Don't rip out the picture like a troglodyte +..... Don't do it, I'm watching you + +. Put on your hiking boots +. Freeze your butt off on the side of a mountain at midnight + +Let's skip a few steps and start counting from 10. + +[start=10] +. arabic (10) +.. loweralpha (a) +... lowerroman (i) +... lowerroman (ii) +... lowerroman (iii) +... lowerroman (iv) +.... upperalpha (A) + +. arabic (11) + +It's time for a top 5 list, made using the `reversed` option on an ordered list! + +[%reversed] +. Stone Imperial Russian Stout +. Pliny the Elder +. Chimay Grande Réserve (Blue) +. St. Bernardus Abt 12 +. Westvleteren 12 (XII) + +How about a list with some terms? + +* Fruits +Apple:::: +The round fruit of a tree of the rose family, which typically has thin red or green skin and crisp flesh. +Yes, I said _flesh_. +Pear:::: +A yellowish- or brownish-green edible fruit that is typically narrow at the stalk and wider toward the base, with sweet, slightly gritty flesh. +More flesh. +Mmmmm. + +* Vegetables +Carrot:::: +An orange-colored root eaten as a vegetable. +Beware, it's a favorite of the Wolpertinger. + +[[_are_you_still_here]] +===== Are You Still Here? +.Move, move, move! +[CAUTION] +==== +The Wolpertingers can smell your procrastination. +It's not their fault you can't find your boots. + +==== +[[_sigh]] +====== Sigh…​ +TIP: Your boots are in your closet. + +[[_dawn_on_the_plateau]] +== Dawn on the Plateau +Lazarus was hanging from the bottom limb of a Burdockian tree, licking the bark. + +[quote,Mark Tobey] +On pavements and the bark of trees I have found whole worlds. +"`If there are whole worlds on that bark, he just swallowed them,`" Kizmet replied. + +[verse,The documentation attorneys] +____ +No bark was harmed in the making of this potion. + We're not so sure about a couple ants though. + + Nor those worlds... + + Crap, I smell an injunction. +____ +We'd retrieved the leaves, but we'd obviously lost our minds in the process. + +[verse] +Roses are +++red+++. +Violets are +++blue+++__-ish__. + +[[_words_seasoned_with_power]] +== Words Seasoned with Power +To _tame_ the [.wild]#wild# wolpertingers, we needed to build a *charm*. +But **ul**timate victory could only be won if we divined the *_true name_* of the __war__lock. + +"`What kind of charm?`" Lazarus asked. "`An odoriferous one or a mineral one?`" +Kizmet shrugged. "`The note from Olaf's desk says '`wormwood and licorice,`' but these could be normal groceries for werewolves.`" + +"`Well the H~2~O written on the security whiteboard could be part of a shopping list, but I don't think the local bodega also sells e = mc^2^,`" Lazarus replied. + +"`Wait!`" Indigo plucked a small vial from her desk's top drawer and held it toward us. +The vial's label read '```e = mc^2^ *_the scent of science_* _smells like a genius_```'. + +[[_can_i_get_some_code]] +=== Can I Get Some `Code`? +[%hardbreaks] +Sure. +Have a listing block. + +[listing] + +---- +This is an example of a listing block. +The content inside is rendered as

 text.
+----
+But I'm not giving you any highlighting shazam just yet.
+
+.What is a listing block?
+Like literal blocks, the content in listing blocks is displayed exactly as you entered it.
+Listing block content is rendered as `
` text.
+
+The `listing` style is applied to an element, such as a paragraph, by setting the `listing` attribute on that element.
+
+Let's get our #((highlighting))# on!
+
+<<<
+Install Prawn:
+
+[literal]
+$ gem install prawn
+Then create your first PDF document in Ruby!
+
+.Generates a basic PDF document using Prawn
+[source,ruby]
+
+----
+require 'prawn' # <1>
+
+Prawn::Document.generate 'output.pdf' do # <3>
+  text 'Hello, World!' # <2>
+end
+----
+<1> Imports Prawn library
+<3> Adds text “Hello, World!” to first page
+<2> Writes PDF to [file]_output.pdf_ after executing all statements
+How about some source code that styles code? So meta!
+
+[source,css]
+
+----
+code {
+  padding: 2px 4px;
+  font-size: 90%;
+  font-weight: normal;
+  color: #c7254e;
+  white-space: nowrap !important;
+  background-color: #f9f2f4;
+  border-radius: 4px;
+}
+----
+Where could we go without some Java(TM)?
+Naturally, some autosizing is necessary.
+
+[source%autofit,java]
+
+----
+package org.javaee7.cdi.events;
+
+import javax.annotation.PostConstruct;
+import javax.enterprise.context.SessionScoped;
+import javax.enterprise.event.Observes;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import javax.ws.rs.*;
+
+/**
+ * This session-scoped bean receives greeting strings from the event bus
+ * and provides access to the collection of these greetings via a REST API.
+ *
+ * @author The Duke
+ * @since 1.0
+ */
+@SessionScoped
+public class GreetingReceiver implements EventReceiver, Serializable {
+
+    private List greetings;
+
+    @PostConstruct
+    void init() {
+        this.greetings = new ArrayList();
+    }
+
+    void receive(@Observes String greet) {
+        this.greetings.add(greet);
+    }
+
+    @GET
+    @Produces("application/json")
+    public List listAll(@QueryParam("start") Integer start, @QueryParam("max") Integer max) {
+        int numGreetings = this.greetings.size();
+
+        if (numGreetings == 0 || max == 0) {
+            return Collections.emptyList();
+        }
+
+        if (start == null) {
+            start = 0;
+        }
+
+        if (max == null) {
+            max = numGreetings;
+        }
+
+        return this.greetings.subList(start, Math.min(max + start, numGreetings));
+    }
+
+}
+----
+We already showed you an XML example in <>, a language we often rant about over beers at <>.
+
+I'll trade you a little table for some of that bark.
+
+[table%header,grid=rows,cols=4,frame=topbot]
+|===
+<.<|Column 1
+<.<|Column 2
+<.<|Column 3
+<.<|Column 4
+
+^.|Prefix `{vbar}` with a `.` and `>` to align content to the bottom of the cell.
+^.^|Prefix `{vbar}` with a `^`, `.`, and `^` to place content in the middle of the cell.
+>.<|Prefix `{vbar}` with `>` to align content to the right horizontally within the cell.
+
+4+^.`:::
+an html tag that makes me crazy
+align:::
+something I never get going in the right direction.
+Also has to do with my poor verbal communication skills
+float:::
+style:::
+don't make me laugh
+
+Does anyone have the time?
+
+Tg lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
+Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
+Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
+Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborumj.
+
+[[_keeping_it_together]]
+== Keeping It Together
+On this page we have nested "`keep together`" logic.
+The combined block will be shifted to the next page if there isn't room available on this one.
+
+[verse]
+First,
+we
+need
+to
+waste
+several
+lines
+using
+a
+verse
+to
+push
+the
+next
+block
+to
+its
+breaking
+point.
+.What happens if there is both a field and a method with the same name?
+[NOTE]
+====
+Back to the previous example, suppose that we have both a field and a method with the same name, as in:
+
+.Java class with a field and method that share the same name
+[source,java]
+
+----
+public class Foo {
+  public String bar;
+
+  public String bar() {
+    return bar;
+  }
+}
+----
+*Golo resolves methods first, fields last.*
+Hence, the following Golo code will resolve the `bar()` method, not the `bar` field:
+
+.Golo picks the method over the field with the same name
+[source,golo]
+
+----
+let foo = Foo()
+
+foo: bar("baz") # <1>
+
+println(foo: bar()) # <2>
+----
+<1> Writes the field
+<2> Calls the `bar()` method
+====
+<<<
+Here's a preview of how each heading level is rendered.
+
+[discrete]
+= Heading 1 (Level 0)
+filler content
+
+[discrete]
+== Heading 2 (Level 1)
+filler content
+
+[discrete]
+=== Heading 3 (Level 2)
+filler content
+
+[discrete]
+==== Heading 4 (Level 3)
+filler content
+
+[discrete]
+===== Heading 5 (Level 4)
+filler content
+
+[discrete]
+====== Heading 6 (Level 5)
+filler content
+
+'''
+--
+Here's some content inside an open block.
+
+--
+
+[[_credits]]
+[appendix]
+== Credits
+.Brought to you with icon:heart[set=fas,role=love] by OpenDevise
+[table%footer%header,grid=rows,width=75%,cols="2,2s,^4",frame=topbot]
+|===
+<.<|Name
+<.<|Title
+.<|Alias
+
+<.<|Sarah White
+<.<|President
+.<|http://twitter.com/carbonfray[@carbonfray]
+
+<.<|Dan Allen
+<.<|Vice President
+.<|http://twitter.com/mojavelinux[@mojavelinux]
+
+3+^.
+v1.0.0
+:tip-caption: Tip
+:appendix-caption: Appendix
+:appendix-refsig: Appendix
+:authorinitials: Y
+:toc-title: Table of Contents
+:iconsdir: ./images/icons
+:author: You
+:warning-caption: Warning
+:figure-caption: Figure
+:attribute-missing: skip
+:section-refsig: Section
+:toc-placement: auto
+:important-caption: Important
+:authors: You
+:note-caption: Note
+:firstname: You
+:stylesdir: .
+:untitled-label: Untitled
+:max-include-depth: 64
+:caution-caption: Caution
+:user-home: .
+:max-attribute-value-size: 4096
+:safe-mode-level: 20
+:safe-mode-name: secure
+:table-caption: Table
+:part-refsig: Part
+:authorcount: 1
+:example-caption: Example
+:email: you@your-company.com
+:version-label: Version
+:revnumber: 1.0.0
+:last-update-label: Last updated
+:doctype: article
+:chapter-refsig: Chapter
+:attribute-undefined: drop-line
+
+[[_overview]]
+== Overview
+This is a simple API
+
+[[_license]]
+=== License
+[%hardbreaks]
+http://www.apache.org/licenses/LICENSE-2.0.html[Apache 2.0]
+
+[[_servers]]
+== Servers
+* https://{username}.gigantic-server.com:{port}/{basePath}
++
+The production API server
+
++
+.Variables
+username::
+*this* __value__ is assigned by the service provider, in this example `gigantic-server.com`
+Possible Values::
+Any
+Default::
+demo
+
+port::
+Possible Values::
+- 8443
+- 443
+
+Default::
+8443
+
+basePath::
+Possible Values::
+Any
+Default::
+v2
+
diff --git a/swagger2markup-asciidoc/src/test/resources/asciidoc/original/arrows-and-boxes-example.ad b/swagger2markup-asciidoc/src/test/resources/asciidoc/original/arrows-and-boxes-example.ad
new file mode 100644
index 00000000..98e22470
--- /dev/null
+++ b/swagger2markup-asciidoc/src/test/resources/asciidoc/original/arrows-and-boxes-example.ad
@@ -0,0 +1,4 @@
+= Document Title
+
+[arrowsAndBoxes]
+(User) > (Admin)
diff --git a/swagger2markup-asciidoc/src/test/resources/asciidoc/original/brokeninclude.asciidoc b/swagger2markup-asciidoc/src/test/resources/asciidoc/original/brokeninclude.asciidoc
new file mode 100644
index 00000000..6b8c04e1
--- /dev/null
+++ b/swagger2markup-asciidoc/src/test/resources/asciidoc/original/brokeninclude.asciidoc
@@ -0,0 +1,3 @@
+= Title
+
+include::b.adoc[]
diff --git a/swagger2markup-asciidoc/src/test/resources/asciidoc/original/changeattribute.adoc b/swagger2markup-asciidoc/src/test/resources/asciidoc/original/changeattribute.adoc
new file mode 100644
index 00000000..7132c0a9
--- /dev/null
+++ b/swagger2markup-asciidoc/src/test/resources/asciidoc/original/changeattribute.adoc
@@ -0,0 +1,4 @@
+
+= Document Title
+
+sample {content}
diff --git a/swagger2markup-asciidoc/src/test/resources/asciidoc/original/chronicles-example.adoc b/swagger2markup-asciidoc/src/test/resources/asciidoc/original/chronicles-example.adoc
new file mode 100644
index 00000000..8f8d2b7a
--- /dev/null
+++ b/swagger2markup-asciidoc/src/test/resources/asciidoc/original/chronicles-example.adoc
@@ -0,0 +1,529 @@
+= The Dangerous & _Thrilling_ Documentation Chronicles: Based on True Events
+Kismet Caméléon; Lazarus het_Draeke
+v1.0, 2014-01-01
+:description: This story chronicles the inexplicable hazards and vicious beasts a \
+team must conquer and vanquish on their journey to discovering the true power of \
+Open Source.
+:organization: Company Name
+:doctype: book
+// Settings:
+:experimental:
+:reproducible:
+:icons: font
+:listing-caption: Listing
+:sectnums:
+:toc:
+:toclevels: 3
+ifeval::["{asciidoctor-version}" < "1.5.7"]
+:legacy-footnoteref:
+endif::[]
+ifdef::backend-pdf[]
+:pdf-theme: chronicles
+:pdf-themesdir: {docdir}
+:title-logo-image: image:sample-banner.svg[pdfwidth=4.25in,align=center]
+:source-highlighter: rouge
+//:rouge-style: github
+endif::[]
+// URIs:
+:uri-devoxx: https://devoxx.be
+:uri-devoxx-top-talks: https://www.youtube.com/watch?v=1OpAgZvYXLQ&list=PLRsbF2sD7JVq7fv1GZGORShSUIae1ZAPy&index=1
+:uri-stbernardusabt12: http://www.sintbernardus.be/stbernardusabt12.php?l=en
+:uri-wolpertinger: http://en.wikipedia.org/wiki/Wolpertinger
+
+[abstract]
+{description}
+
+== It's a City Under Siege
+
+This journey begins one late Monday afternoon at {uri-devoxx}[((Devoxx))].
+Our team needs coffee, _desperately_, but none of us dare open the theater doors...
+
+During the {uri-devoxx-top-talks}[opening university session], a script-happy warlock inadvertently released a legion of Wolpertingers!
+To leave now would mean *code dismemberment and certain death*.
+
+Behold -> the horror!
+
+.Wolpertinger, stuffed
+[.left.thumb]
+image::wolpertinger.jpg[Wolpertinger,pdfwidth=50%,link={uri-wolpertinger}]
+
+(((Wolpertinger)))
+(((Ravenous Beast,Wolpertinger)))
+You may not be familiar with these {uri-wolpertinger}[ravenous beasts].
+Trust us, they'll eat your shorts and suck loops from your code.
+In light of this danger, we've searched high and wide for the security crew's defensive operations manual.
+ifndef::legacy-footnoteref[]
+We can't find it and the DefOps{empty}footnote:defops[DefOps is a portmanteau of "`defensive`" and "`operations`".] werewolves haven't returned from their rendezvous at Bier Central.
+endif::[]
+ifdef::legacy-footnoteref[]
+We can't find it and the DefOps{empty}footnoteref:[defops,DefOps is a portmanteau of "`defensive`" and "`operations`".] werewolves haven't returned from their rendezvous at Bier Central.
+endif::[]
+They've either eaten each other or fallen victim to the Wolpertingers roaming the streets of ((Antwerp)).
+Quick, hit kbd:[Ctrl,Alt,Backspace] or select menu:File[Quit] and let's bail out of here!
+
+ifndef::legacy-footnoteref[]
+WARNING: Working with DefOps{empty}footnote:defops[] werewolves leads to howling and trying to train aggressive regular expressions with Pavlovian reinforcement.
+endif::[]
+ifdef::legacy-footnoteref[]
+WARNING: Working with DefOps{empty}footnoteref:[defops] werewolves leads to howling and trying to train aggressive regular expressions with Pavlovian reinforcement.
+endif::[]
+
+_Weak light from the hallway trickled across the theater, chased by a distant scream._
+
+=== Rendezvous Point
+
+Come on, [[bier-central,Bier Central]]_Bier Central_, of course!
+Did you have to ask?
+If you beat me there, order me a {uri-stbernardusabt12}[St. Bernardus Abt 12].
+Here's some €.
+
+[#ravages]
+== The Ravages of Writing
+
+Crystalline XML tags relentlessly bombarded the theater.
+
+.XML tags
+[source,xml]
+----
+
+  
+    Lazarus
+    het Draeke
+  
+
+----
+
+ifndef::legacy-footnoteref[]
+Despite the assault, we continued our pursuit to draft a DefOps{empty}footnote:defops[] plan.
+endif::[]
+ifdef::legacy-footnoteref[]
+Despite the assault, we continued our pursuit to draft a DefOps{empty}footnoteref:[defops] plan.
+endif::[]
+
+.DefOps Plan
+====
+Click btn:[Download Zip] to download the defensive operation plan bundle.
+
+OMG!
+Somebody please save us now!
+I want my mum -- and an extra-large double macchiato, please.
+====
+
+Unfortunately, Lazarus and I had both come to the conclusion that we weren't going to get out of this without corrupted hardrives if we didn't locate caffeine within the next few hours.
+
+=== A Recipe for Potion That Will Ensure You Win the Hearts of Developers
+
+This potion for a sample document contains the following ingredients, which are listed in a very random, chaotically nested order.
+
+.Ingredients for Potion that Demystifies Documents
+* all the headings
+** syntax highlighted source code
+*** non-syntax highlighted source code or just a listing block
+* quote block
+** verse block
+*** table with some cell formatting
+**** sequential paragraphs
+***** admonition blocks, but use them sparingly
+*** bullet list with nesting
+** numbered list with nesting
+** definition list
+*** sidebar
+* example block
+** block image (no inline images)
+*** inline formatting in a paragraph
+**** two fresh Burdockian leaves
+***** They must be harvested by the light of the teal moons.
+
+Are you square?
+
+[square]
+* one
+* two
+* three
+
+What is there to do?
+
+* [x] Done
+* [ ] Next
+* Who's counting?
+
+==== Searching for Burdockian
+
+.Steps for finding and preparing Burdockian leaves
+. Locate dusty botany
+.. Sneeze
+... Sneeze some more
+. Find section on Burdockian
+.. Review its characteristics
+... Take a picture of the diagram of its leaves
+.... Don't rip out the picture like a troglodyte
+..... Don't do it, I'm watching you
+. Put on your hiking boots
+. Freeze your butt off on the side of a mountain at midnight
+
+Let's skip a few steps and start counting from 10.
+
+[start=10]
+. arabic (10)
+.. loweralpha (a)
+... lowerroman (i)
+... lowerroman (ii)
+... lowerroman (iii)
+... lowerroman (iv)
+.... upperalpha (A)
+. arabic (11)
+
+It's time for a top 5 list, made using the `reversed` option on an ordered list!
+
+[%reversed]
+. Stone Imperial Russian Stout
+. Pliny the Elder
+. Chimay Grande Réserve (Blue)
+. St. Bernardus Abt 12
+. Westvleteren 12 (XII)
+
+How about a list with some terms?
+
+* Fruits
+
+Apple::
+The round fruit of a tree of the rose family, which typically has thin red or green skin and crisp flesh.
+Yes, I said _flesh_.
+
+Pear::
+A yellowish- or brownish-green edible fruit that is typically narrow at the stalk and wider toward the base, with sweet, slightly gritty flesh.
+More flesh.
+Mmmmm.
+
+* Vegetables
+
+Carrot::
+An orange-colored root eaten as a vegetable.
+Beware, it's a favorite of the Wolpertinger.
+
+===== Are You Still Here?
+
+.Move, move, move!
+[CAUTION]
+====
+The Wolpertingers can smell your procrastination.
+It's not their fault you can't find your boots.
+====
+
+====== Sigh...
+
+TIP: Your boots are in your closet.
+
+== Dawn on the Plateau
+
+Lazarus was hanging from the bottom limb of a Burdockian tree, licking the bark.
+
+[quote,Mark Tobey]
+On pavements and the bark of trees I have found whole worlds.
+
+"`If there are whole worlds on that bark, he just swallowed them,`" Kizmet replied.
+
+[verse,The documentation attorneys]
+____
+No bark was harmed in the making of this potion.
+    We're not so sure about a couple ants though.
+
+        Nor those worlds...
+
+     Crap, I smell an injunction.
+____
+
+We'd retrieved the leaves, but we'd obviously lost our minds in the process.
+
+[verse]
+Roses are +++red+++.
+Violets are +++blue+++__-ish__.
+
+== Words Seasoned with Power
+
+To _tame_ the [.wild]#wild# wolpertingers, we needed to build a *charm*.
+But **ul**timate victory could only be won if we divined the *_true name_* of the __war__lock.
+
+"`What kind of charm?`" Lazarus asked. "`An odoriferous one or a mineral one?`"
+Kizmet shrugged. "`The note from Olaf's desk says '`wormwood and licorice,`' but these could be normal groceries for werewolves.`"
+
+"`Well the H~2~O written on the security whiteboard could be part of a shopping list, but I don't think the local bodega also sells e = mc^2^,`" Lazarus replied.
+
+"`Wait!`" Indigo plucked a small vial from her desk's top drawer and held it toward us.
+The vial's label read '```e = mc^2^ *_the scent of science_* _smells like a genius_```'.
+
+=== Can I Get Some `Code`?
+
+[%hardbreaks]
+Sure.
+Have a listing block.
+
+----
+This is an example of a listing block.
+The content inside is rendered as 
 text.
+----
+
+But I'm not giving you any highlighting shazam just yet.
+
+.What is a listing block?
+****
+Like literal blocks, the content in listing blocks is displayed exactly as you entered it.
+Listing block content is rendered as `
` text.
+
+The `listing` style is applied to an element, such as a paragraph, by setting the `listing` attribute on that element.
+****
+
+Let's get our #((highlighting))# on!
+
+<<<
+
+Install Prawn:
+
+ $ gem install prawn
+
+Then create your first PDF document in Ruby!
+
+.Generates a basic PDF document using Prawn
+[source,ruby]
+----
+require 'prawn' # <1>
+
+Prawn::Document.generate 'output.pdf' do # <3>
+  text 'Hello, World!' # <2>
+end
+----
+<1> Imports Prawn library
+<2> Adds text “Hello, World!” to first page
+<3> Writes PDF to [file]_output.pdf_ after executing all statements
+
+How about some source code that styles code? So meta!
+
+[source,css]
+----
+code {
+  padding: 2px 4px;
+  font-size: 90%;
+  font-weight: normal;
+  color: #c7254e;
+  white-space: nowrap !important;
+  background-color: #f9f2f4;
+  border-radius: 4px;
+}
+----
+
+Where could we go without some Java(TM)?
+Naturally, some autosizing is necessary.
+
+[source%autofit,java]
+----
+package org.javaee7.cdi.events;
+
+import javax.annotation.PostConstruct;
+import javax.enterprise.context.SessionScoped;
+import javax.enterprise.event.Observes;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import javax.ws.rs.*;
+
+/**
+ * This session-scoped bean receives greeting strings from the event bus
+ * and provides access to the collection of these greetings via a REST API.
+ *
+ * @author The Duke
+ * @since 1.0
+ */
+@SessionScoped
+public class GreetingReceiver implements EventReceiver, Serializable {
+
+    private List greetings;
+
+    @PostConstruct
+    void init() {
+        this.greetings = new ArrayList();
+    }
+
+    void receive(@Observes String greet) {
+        this.greetings.add(greet);
+    }
+
+    @GET
+    @Produces("application/json")
+    public List listAll(@QueryParam("start") Integer start, @QueryParam("max") Integer max) {
+        int numGreetings = this.greetings.size();
+
+        if (numGreetings == 0 || max == 0) {
+            return Collections.emptyList();
+        }
+
+        if (start == null) {
+            start = 0;
+        }
+
+        if (max == null) {
+            max = numGreetings;
+        }
+
+        return this.greetings.subList(start, Math.min(max + start, numGreetings));
+    }
+
+}
+----
+
+We already showed you an XML example in <>, a language we often rant about over beers at <>.
+
+I'll trade you a little table for some of that bark.
+
+[cols=4,frame=topbot,grid=rows]
+|===
+|Column 1 |Column 2 |Column 3 |Column 4
+
+^m|Prefix `{vbar}` with `{caret}` to center content horizontally within the cell.
+.>|Prefix `{vbar}` with a `.` and `>` to align content to the bottom of the cell.
+^.^|Prefix `{vbar}` with a `^`, `.`, and `^` to place content in the middle of the cell.
+>|Prefix `{vbar}` with `>` to align content to the right horizontally within the cell.
+
+4+^e|This content spans all four columns (`4{plus}`) and is centered horizontally (`{caret}`) within the cell.
+|===
+
+Wait.
+What?
+Where is this story going?
+
+``:: an html tag that makes me crazy
+
+align:: something I never get going in the right direction.
+Also has to do with my poor verbal communication skills
+
+float::
+style::
+don't make me laugh
+
+Does anyone have the time?
+
+Tg lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
+Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
+Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
+Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborumj.
+
+== Keeping It Together
+
+On this page we have nested "`keep together`" logic.
+The combined block will be shifted to the next page if there isn't room available on this one.
+
+[verse]
+First,
+we
+need
+to
+waste
+several
+lines
+using
+a
+verse
+to
+push
+the
+next
+block
+to
+its
+breaking
+point.
+
+[NOTE]
+.What happens if there is both a field and a method with the same name?
+====
+Back to the previous example, suppose that we have both a field and a method with the same name, as in:
+
+.Java class with a field and method that share the same name
+[source,java]
+----
+public class Foo {
+  public String bar;
+
+  public String bar() {
+    return bar;
+  }
+}
+----
+
+*Golo resolves methods first, fields last.*
+Hence, the following Golo code will resolve the `bar()` method, not the `bar` field:
+
+.Golo picks the method over the field with the same name
+[source,golo]
+----
+let foo = Foo()
+
+foo: bar("baz") # <1>
+
+println(foo: bar()) # <2>
+----
+<1> Writes the field
+<2> Calls the `bar()` method
+====
+
+<<<
+
+Here's a preview of how each heading level is rendered.
+
+[discrete]
+= Heading 1 (Level 0)
+
+filler content
+
+[discrete]
+== Heading 2 (Level 1)
+
+filler content
+
+[discrete]
+=== Heading 3 (Level 2)
+
+filler content
+
+[discrete]
+==== Heading 4 (Level 3)
+
+filler content
+
+[discrete]
+===== Heading 5 (Level 4)
+
+filler content
+
+[discrete]
+====== Heading 6 (Level 5)
+
+filler content
+
+---
+
+--
+Here's some content inside an open block.
+--
+
+[appendix]
+== Credits
+
+.Brought to you with icon:heart[set=fas,role=love] by OpenDevise
+[%header%footer,cols="2,2s,^4",grid=rows,frame=topbot,width=75%,caption=]
+|===
+|Name |Title |Alias
+
+|Sarah White
+|President
+|http://twitter.com/carbonfray[@carbonfray]
+
+|Dan Allen
+|Vice President
+|http://twitter.com/mojavelinux[@mojavelinux]
+
+3+^.e|Powered by Open Source
+|===
+
+[index]
+== Index
diff --git a/swagger2markup-asciidoc/src/test/resources/asciidoc/original/document-with-arrays.adoc b/swagger2markup-asciidoc/src/test/resources/asciidoc/original/document-with-arrays.adoc
new file mode 100644
index 00000000..0cfaa535
--- /dev/null
+++ b/swagger2markup-asciidoc/src/test/resources/asciidoc/original/document-with-arrays.adoc
@@ -0,0 +1,21 @@
+= Asciidoctor Changelog
+
+http://asciidoctor.org[Asciidoctor] is an open source text processor and publishing toolchain for converting http://asciidoctor.org[AsciiDoc] markup into HTML, DocBook and custom formats.
+
+This document provides a high-level view of the changes introduced in Asciidoctor by release.
+For a detailed view of what has changed, refer to the https://github.com/asciidoctor/asciidoctor/commits/master[commit history] on GitHub.
+
+== 0.1.4 (2013-09-05) - @mojavelinux
+
+Performance::
+
+  * 15% increase in speed compared to 0.1.3
+
+Enhancements::
+
+  * updated xref inline macro to support inter-document references (#417)
+
+
+Bug Fixes::
+
+  * lowercase attribute names passed to API (#508)
diff --git a/swagger2markup-asciidoc/src/test/resources/asciidoc/original/simple.adoc b/swagger2markup-asciidoc/src/test/resources/asciidoc/original/simple.adoc
new file mode 100644
index 00000000..a6659110
--- /dev/null
+++ b/swagger2markup-asciidoc/src/test/resources/asciidoc/original/simple.adoc
@@ -0,0 +1,28 @@
+= Simple Inventory API
+You 
+v1.0.0
+
+== Overview
+This is a simple API
+
+=== License
+[%hardbreaks]
+http://www.apache.org/licenses/LICENSE-2.0.html[Apache 2.0]
+
+== Servers
+* https://{username}.gigantic-server.com:{port}/{basePath}
++
+The production API server
++
+.Variables
+username:: *this* __value__ is assigned by the service provider, in this example `gigantic-server.com`
+  Possible Values::: Any
+  Default::: demo
+port::
+  Possible Values:::
+  - 8443
+  - 443
+  Default::: 8443
+basePath::
+  Possible Values::: Any
+  Default::: v2
diff --git a/swagger2markup-asciidoc/src/test/resources/logback.xml b/swagger2markup-asciidoc/src/test/resources/logback.xml
new file mode 100644
index 00000000..5666f523
--- /dev/null
+++ b/swagger2markup-asciidoc/src/test/resources/logback.xml
@@ -0,0 +1,14 @@
+
+
+    
+        
+            %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
+        
+    
+
+    
+
+    
+        
+    
+
diff --git a/swagger2markup-builder/src/main/java/io/github/swagger2markup/markup/builder/internal/asciidoc/AsciiDoc.java b/swagger2markup-builder/src/main/java/io/github/swagger2markup/markup/builder/internal/asciidoc/AsciiDoc.java
index c561a94f..70b6874b 100644
--- a/swagger2markup-builder/src/main/java/io/github/swagger2markup/markup/builder/internal/asciidoc/AsciiDoc.java
+++ b/swagger2markup-builder/src/main/java/io/github/swagger2markup/markup/builder/internal/asciidoc/AsciiDoc.java
@@ -25,6 +25,7 @@ import io.github.swagger2markup.markup.builder.internal.Markup;
  * @author Robert Winkler
  */
 public enum AsciiDoc implements Markup {
+    ATTRIBUTE(":"),
     TABLE("|==="),
     TABLE_COLUMN_DELIMITER("|"),
     TITLE("="),
diff --git a/swagger2markup-builder/src/test/resources/logback.xml b/swagger2markup-builder/src/test/resources/logback.xml
index 8b43a9e7..23c3c8d0 100644
--- a/swagger2markup-builder/src/test/resources/logback.xml
+++ b/swagger2markup-builder/src/test/resources/logback.xml
@@ -6,7 +6,7 @@
         
     
 
-    
+    
         
     
-
\ No newline at end of file
+
diff --git a/swagger2markup-core/build.gradle b/swagger2markup-core/build.gradle
index 00bd7643..9b022c7d 100644
--- a/swagger2markup-core/build.gradle
+++ b/swagger2markup-core/build.gradle
@@ -1,33 +1,25 @@
-ext.moduleName='io.github.swagger2markup.core'
+ext.moduleName="io.github.swagger2markup.core"
 
 dependencies {
     configurations.all {
         resolutionStrategy.force dependencyOverrides.commonsCodec
-        resolutionStrategy.force dependencyOverrides.commonsLang3
         resolutionStrategy.force dependencyOverrides.commonsIO
+        resolutionStrategy.force dependencyOverrides.commonsLang3
+        resolutionStrategy.force dependencyOverrides.jnrConstants
+        resolutionStrategy.force dependencyOverrides.jnrEnxio
+        resolutionStrategy.force dependencyOverrides.jnrPosix
+        resolutionStrategy.force dependencyOverrides.jodaTime
         resolutionStrategy.force dependencyOverrides.slf4j
         resolutionStrategy.force dependencyOverrides.jacksonDatabind
         resolutionStrategy.force dependencyOverrides.guava
         resolutionStrategy.force dependencyOverrides.findBugs
         resolutionStrategy.force dependencyOverrides.jaksonCore
-        // Test dependencies
-        resolutionStrategy.force dependencyOverrides.assertj
-        resolutionStrategy.force dependencyOverrides.jodaTime
-        resolutionStrategy.force dependencyOverrides.jnrConstants
-        resolutionStrategy.force dependencyOverrides.jnrEnxio
-        resolutionStrategy.force dependencyOverrides.jnrPosix
     }
-    compile project(':swagger2markup-builder')
-    implementation implLibraries.commonsBeanUtils
+    implementation implLibraries.commonsText
+    implementation implLibraries.slf4j
     implementation implLibraries.commonsCollections4
     implementation implLibraries.commonsConf2
-    implementation implLibraries.commonsText
-    implementation implLibraries.paleo
-    implementation implLibraries.swaggerConverterV2
-    implementation implLibraries.vavr
-    testImplementation testLibraries.asciiDocJ
-    testImplementation testLibraries.assertj
-    testImplementation testLibraries.assertjDiff
+    implementation implLibraries.guava
     testImplementation testLibraries.junit
     testImplementation testLibraries.logback
 }
diff --git a/swagger2markup-core/src/main/java/io/github/swagger2markup/AbstractSchema2MarkupConverter.java b/swagger2markup-core/src/main/java/io/github/swagger2markup/AbstractSchema2MarkupConverter.java
new file mode 100644
index 00000000..5e1edef0
--- /dev/null
+++ b/swagger2markup-core/src/main/java/io/github/swagger2markup/AbstractSchema2MarkupConverter.java
@@ -0,0 +1,146 @@
+/*
+ * Copyright 2017 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;
+
+import io.github.swagger2markup.config.Labels;
+import io.github.swagger2markup.config.Schema2MarkupConfig;
+import io.github.swagger2markup.extension.Schema2MarkupExtensionRegistry;
+import org.apache.commons.lang3.Validate;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.net.URI;
+import java.nio.file.Files;
+import java.nio.file.Path;
+
+
+/**
+ * Abstract implementation of Schema2Markup converter
+ *
+ * @author Balaji V
+ */
+public abstract class AbstractSchema2MarkupConverter {
+    protected Logger logger = LoggerFactory.getLogger(getClass());
+    private final Context context;
+
+    public AbstractSchema2MarkupConverter(Context context) {
+        this.context = context;
+    }
+
+    /**
+     * Returns the global Context
+     *
+     * @return the global Context
+     */
+    public Context getContext() {
+        return context;
+    }
+
+    /**
+     * Converts the Swagger specification into the {@code outputPath} which can be either a directory (e.g /tmp) or a file without extension (e.g /tmp/swagger).
+     * Internally the method invokes either {@code toFolder} or {@code toFile}. If the {@code outputPath} is a directory, the directory must exist.
+     * Otherwise it cannot be determined if the {@code outputPath} is a directory or not.
+     *
+     * @param outputPath the output path
+     */
+    public void toPath(Path outputPath) {
+        Validate.notNull(outputPath, "outputPath must not be null");
+        if (Files.isDirectory(outputPath)) {
+            toFolder(outputPath);
+        } else {
+            toFile(outputPath);
+        }
+    }
+
+    /**
+     * Converts the Swagger specification into the given {@code outputDirectory}.
+     *
+     * @param outputDirectory the output directory path
+     */
+    public abstract void toFolder(Path outputDirectory);
+
+    /**
+     * Converts the Swagger specification the given {@code outputFile}.
+ * An extension identifying the markup language will be automatically added to file name. + * + * @param outputFile the output file + */ + public abstract void toFile(Path outputFile); + + /** + * Converts the Swagger specification the given {@code outputFile}. + * + * @param outputFile the output file + */ + public abstract void toFileWithoutExtension(Path outputFile); + + /** + * Builds the document returns it as a String. + * + * @return the document as a String + */ + public abstract String toString(); + + public abstract static class Context { + private final Schema2MarkupConfig config; + private final T schema; + private final URI swaggerLocation; + private final Schema2MarkupExtensionRegistry extensionRegistry; + private final Labels labels; + private Path outputPath; + + public Context(Schema2MarkupConfig config, + Schema2MarkupExtensionRegistry extensionRegistry, + T schema, + URI swaggerLocation, + Labels labels) { + this.config = config; + this.extensionRegistry = extensionRegistry; + this.schema = schema; + this.swaggerLocation = swaggerLocation; + this.labels = labels; + } + + public Schema2MarkupConfig getConfig() { + return config; + } + + public T getSchema() { + return schema; + } + + public URI getSwaggerLocation() { + return swaggerLocation; + } + + public Schema2MarkupExtensionRegistry getExtensionRegistry() { + return extensionRegistry; + } + + public Labels getLabels() { + return labels; + } + + public Path getOutputPath() { + return outputPath; + } + + public void setOutputPath(Path outputPath) { + this.outputPath = outputPath; + } + } + +} diff --git a/swagger2markup-core/src/main/java/io/github/swagger2markup/Swagger2MarkupProperties.java b/swagger2markup-core/src/main/java/io/github/swagger2markup/Schema2MarkupProperties.java similarity index 96% rename from swagger2markup-core/src/main/java/io/github/swagger2markup/Swagger2MarkupProperties.java rename to swagger2markup-core/src/main/java/io/github/swagger2markup/Schema2MarkupProperties.java index 7bb229f9..a3060070 100644 --- a/swagger2markup-core/src/main/java/io/github/swagger2markup/Swagger2MarkupProperties.java +++ b/swagger2markup-core/src/main/java/io/github/swagger2markup/Schema2MarkupProperties.java @@ -15,9 +15,8 @@ */ package io.github.swagger2markup; -import io.github.swagger2markup.markup.builder.MarkupLanguage; +import io.github.swagger2markup.config.*; import io.github.swagger2markup.utils.URIUtils; - import org.apache.commons.collections4.IteratorUtils; import org.apache.commons.configuration2.Configuration; import org.apache.commons.configuration2.ConfigurationConverter; @@ -30,7 +29,7 @@ import java.nio.file.Paths; import java.util.*; import java.util.regex.Pattern; -public class Swagger2MarkupProperties { +public class Schema2MarkupProperties { /** * Prefix for Swagger2Markup properties @@ -78,18 +77,22 @@ public class Swagger2MarkupProperties { private final Configuration configuration; - public Swagger2MarkupProperties(Properties properties) { + public Schema2MarkupProperties(Properties properties) { this(ConfigurationConverter.getConfiguration(properties)); } - public Swagger2MarkupProperties(Map map) { + public Schema2MarkupProperties(Map map) { this(new MapConfiguration(map)); } - public Swagger2MarkupProperties(Configuration configuration) { + public Schema2MarkupProperties(Configuration configuration) { this.configuration = configuration; } + public Configuration getConfiguration() { + return configuration; + } + /** * Returns an optional String property value associated with the given key. * @@ -260,11 +263,11 @@ public class Swagger2MarkupProperties { } /** - * Return the MarkupLanguage property value associated with the given key, or + * Return the OutputLanguage property value associated with the given key, or * {@code defaultValue} if the key cannot be resolved. * * @param key the property name to resolve - * @return The MarkupLanguage property + * @return The OutputLanguage property */ public Optional getMarkupLanguage(String key) { Optional property = getString(key); @@ -272,10 +275,10 @@ public class Swagger2MarkupProperties { } /** - * Return the MarkupLanguage property value associated with the given key (never {@code null}). + * Return the OutputLanguage property value associated with the given key (never {@code null}). * * @param key the property name to resolve - * @return The MarkupLanguage property + * @return The OutputLanguage property * @throws IllegalStateException if the key cannot be resolved */ public MarkupLanguage getRequiredMarkupLanguage(String key) { diff --git a/swagger2markup-core/src/main/java/io/github/swagger2markup/GroupBy.java b/swagger2markup-core/src/main/java/io/github/swagger2markup/config/GroupBy.java similarity index 89% rename from swagger2markup-core/src/main/java/io/github/swagger2markup/GroupBy.java rename to swagger2markup-core/src/main/java/io/github/swagger2markup/config/GroupBy.java index 2230c103..d86044db 100644 --- a/swagger2markup-core/src/main/java/io/github/swagger2markup/GroupBy.java +++ b/swagger2markup-core/src/main/java/io/github/swagger2markup/config/GroupBy.java @@ -13,8 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.github.swagger2markup; +package io.github.swagger2markup.config; +/** + * GroupBy enum for ordering + */ public enum GroupBy { AS_IS, TAGS, diff --git a/swagger2markup-core/src/main/java/io/github/swagger2markup/config/Labels.java b/swagger2markup-core/src/main/java/io/github/swagger2markup/config/Labels.java new file mode 100644 index 00000000..d96c56b8 --- /dev/null +++ b/swagger2markup-core/src/main/java/io/github/swagger2markup/config/Labels.java @@ -0,0 +1,37 @@ +/* + * Copyright 2017 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.config; + +import java.util.ResourceBundle; + +public class Labels { + + private ResourceBundle resourceBundle; + + public Labels(ResourceBundle resourceBundle) { + this.resourceBundle = resourceBundle; + } + + /** + * Gets a label for the given key from this resource bundle. + * + * @param key the key for the desired label + * @return the label for the given key + */ + public String getLabel(String key) { + return resourceBundle.getString(key); + } +} diff --git a/swagger2markup-core/src/main/java/io/github/swagger2markup/Language.java b/swagger2markup-core/src/main/java/io/github/swagger2markup/config/Language.java similarity index 96% rename from swagger2markup-core/src/main/java/io/github/swagger2markup/Language.java rename to swagger2markup-core/src/main/java/io/github/swagger2markup/config/Language.java index fbd5ca29..353713a7 100644 --- a/swagger2markup-core/src/main/java/io/github/swagger2markup/Language.java +++ b/swagger2markup-core/src/main/java/io/github/swagger2markup/config/Language.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package io.github.swagger2markup; +package io.github.swagger2markup.config; import java.util.Locale; diff --git a/swagger2markup-core/src/main/java/io/github/swagger2markup/config/LineSeparator.java b/swagger2markup-core/src/main/java/io/github/swagger2markup/config/LineSeparator.java new file mode 100644 index 00000000..8b2b2c54 --- /dev/null +++ b/swagger2markup-core/src/main/java/io/github/swagger2markup/config/LineSeparator.java @@ -0,0 +1,45 @@ +/* + * + * Copyright 2015 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.config; + +public enum LineSeparator { + /** + * Line separator for Unix systems (\n). + */ + UNIX("\n"), + /** + * Line separator for Windows systems (\r\n). + */ + WINDOWS("\r\n"), + /** + * Line separator for Macintosh systems (\r). + */ + MAC("\r"); + + private String lineSeparator; + + LineSeparator(String lineSeparator) { + this.lineSeparator = lineSeparator; + } + + @Override + public String toString() { + return lineSeparator; + } +} diff --git a/swagger2markup-core/src/main/java/io/github/swagger2markup/config/MarkupLanguage.java b/swagger2markup-core/src/main/java/io/github/swagger2markup/config/MarkupLanguage.java new file mode 100644 index 00000000..79168dce --- /dev/null +++ b/swagger2markup-core/src/main/java/io/github/swagger2markup/config/MarkupLanguage.java @@ -0,0 +1,45 @@ +/* + * + * Copyright 2015 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.config; + +import java.util.Arrays; +import java.util.List; + +/** + * @author Robert Winkler + */ +public enum MarkupLanguage { + ASCIIDOC(".adoc,.asciidoc"), + MARKDOWN(".md,.markdown"), + CONFLUENCE_MARKUP(".txt"); + + private final String fileNameExtensions; + + /** + * @param fileNameExtensions file name suffix + */ + private MarkupLanguage(final String fileNameExtensions) { + this.fileNameExtensions = fileNameExtensions; + } + + public List getFileNameExtensions() { + return Arrays.asList(fileNameExtensions.split(",")); + } +} diff --git a/swagger2markup-core/src/main/java/io/github/swagger2markup/OrderBy.java b/swagger2markup-core/src/main/java/io/github/swagger2markup/config/OrderBy.java similarity index 94% rename from swagger2markup-core/src/main/java/io/github/swagger2markup/OrderBy.java rename to swagger2markup-core/src/main/java/io/github/swagger2markup/config/OrderBy.java index 01ded642..4b7313a0 100644 --- a/swagger2markup-core/src/main/java/io/github/swagger2markup/OrderBy.java +++ b/swagger2markup-core/src/main/java/io/github/swagger2markup/config/OrderBy.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.github.swagger2markup; +package io.github.swagger2markup.config; public enum OrderBy { AS_IS, diff --git a/swagger2markup-core/src/main/java/io/github/swagger2markup/config/PageBreakLocations.java b/swagger2markup-core/src/main/java/io/github/swagger2markup/config/PageBreakLocations.java new file mode 100644 index 00000000..fca12490 --- /dev/null +++ b/swagger2markup-core/src/main/java/io/github/swagger2markup/config/PageBreakLocations.java @@ -0,0 +1,23 @@ +/* + * Copyright 2017 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.config; + +/** + * Marker interface for PageBreak enums + */ +public interface PageBreakLocations { + +} \ No newline at end of file diff --git a/swagger2markup-core/src/main/java/io/github/swagger2markup/Swagger2MarkupConfig.java b/swagger2markup-core/src/main/java/io/github/swagger2markup/config/Schema2MarkupConfig.java similarity index 94% rename from swagger2markup-core/src/main/java/io/github/swagger2markup/Swagger2MarkupConfig.java rename to swagger2markup-core/src/main/java/io/github/swagger2markup/config/Schema2MarkupConfig.java index 89c18df8..dafdb708 100644 --- a/swagger2markup-core/src/main/java/io/github/swagger2markup/Swagger2MarkupConfig.java +++ b/swagger2markup-core/src/main/java/io/github/swagger2markup/config/Schema2MarkupConfig.java @@ -13,12 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.github.swagger2markup; +package io.github.swagger2markup.config; -import io.github.swagger2markup.markup.builder.LineSeparator; -import io.github.swagger2markup.markup.builder.MarkupLanguage; +import io.github.swagger2markup.Schema2MarkupProperties; +import io.github.swagger2markup.model.Parameter; import io.github.swagger2markup.model.PathOperation; -import io.swagger.models.parameters.Parameter; import java.util.Comparator; import java.util.List; @@ -27,7 +26,7 @@ import java.util.regex.Pattern; /** * Swagger2Markup configuration interface. */ -public interface Swagger2MarkupConfig { +public interface Schema2MarkupConfig { /** * Specifies the markup language which should be used to generate the files. @@ -38,11 +37,11 @@ public interface Swagger2MarkupConfig { /** * Specifies the markup language used in Swagger descriptions.
- * By default, {@link io.github.swagger2markup.markup.builder.MarkupLanguage#MARKDOWN} is assumed. + * By default, {@link MarkupLanguage#MARKDOWN} is assumed. * * @return Specifies the markup language used in Swagger descriptions. */ - MarkupLanguage getSwaggerMarkupLanguage(); + MarkupLanguage getSchemaMarkupLanguage(); /** * Include generated examples into the documents. @@ -91,7 +90,7 @@ public interface Swagger2MarkupConfig { * * @return Specifies labels language of output files. */ - Language getOutputLanguage(); + Language getLanguage(); /** * Specifies if inline schemas are detailed @@ -295,7 +294,7 @@ public interface Swagger2MarkupConfig { * * @return the extension properties */ - Swagger2MarkupProperties getExtensionsProperties(); + Schema2MarkupProperties getExtensionsProperties(); /** * Returns the list of page break locations diff --git a/swagger2markup-core/src/main/java/io/github/swagger2markup/builder/Swagger2MarkupConfigBuilder.java b/swagger2markup-core/src/main/java/io/github/swagger2markup/config/builder/Schema2MarkupConfigBuilder.java similarity index 68% rename from swagger2markup-core/src/main/java/io/github/swagger2markup/builder/Swagger2MarkupConfigBuilder.java rename to swagger2markup-core/src/main/java/io/github/swagger2markup/config/builder/Schema2MarkupConfigBuilder.java index 746be86b..7bdd2e19 100644 --- a/swagger2markup-core/src/main/java/io/github/swagger2markup/builder/Swagger2MarkupConfigBuilder.java +++ b/swagger2markup-core/src/main/java/io/github/swagger2markup/config/builder/Schema2MarkupConfigBuilder.java @@ -14,116 +14,103 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.github.swagger2markup.builder; +package io.github.swagger2markup.config.builder; import com.google.common.collect.Ordering; - -import io.github.swagger2markup.*; -import io.github.swagger2markup.markup.builder.LineSeparator; -import io.github.swagger2markup.markup.builder.MarkupLanguage; +import io.github.swagger2markup.Schema2MarkupProperties; +import io.github.swagger2markup.config.*; +import io.github.swagger2markup.model.Parameter; import io.github.swagger2markup.model.PathOperation; -import io.swagger.models.HttpMethod; -import io.swagger.models.parameters.Parameter; - -import org.apache.commons.configuration2.*; +import org.apache.commons.configuration2.AbstractConfiguration; +import org.apache.commons.configuration2.CompositeConfiguration; +import org.apache.commons.configuration2.Configuration; +import org.apache.commons.configuration2.SystemConfiguration; import org.apache.commons.configuration2.builder.fluent.Configurations; import org.apache.commons.configuration2.convert.DefaultListDelimiterHandler; import org.apache.commons.configuration2.ex.ConfigurationException; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.Validate; -import java.util.*; +import java.util.Comparator; +import java.util.List; +import java.util.Optional; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; -import static io.github.swagger2markup.Swagger2MarkupProperties.*; +import static io.github.swagger2markup.Schema2MarkupProperties.*; -public class Swagger2MarkupConfigBuilder { +public abstract class Schema2MarkupConfigBuilder { - static final Ordering OPERATION_METHOD_NATURAL_ORDERING = Ordering - .explicit(HttpMethod.POST, HttpMethod.GET, HttpMethod.PUT, HttpMethod.DELETE, HttpMethod.PATCH, HttpMethod.HEAD, HttpMethod.OPTIONS) - .onResultOf(PathOperation::getMethod); - static final Ordering OPERATION_PATH_NATURAL_ORDERING = Ordering + public static final Ordering OPERATION_METHOD_NATURAL_ORDERING = Ordering + .explicit("POST", "GET", "PUT", + "DELETE", "PATCH", "HEAD", "OPTIONS") + .onResultOf(PathOperation::getHttpMethod); + public static final Ordering OPERATION_PATH_NATURAL_ORDERING = Ordering .natural() .onResultOf(PathOperation::getPath); - static final Ordering PARAMETER_IN_NATURAL_ORDERING = Ordering + public static final Ordering PARAMETER_IN_NATURAL_ORDERING = Ordering .explicit("header", "path", "query", "formData", "body") .onResultOf(Parameter::getIn); - static final Ordering PARAMETER_NAME_NATURAL_ORDERING = Ordering + public static final Ordering PARAMETER_NAME_NATURAL_ORDERING = Ordering .natural() .onResultOf(Parameter::getName); + private static final String PROPERTIES_DEFAULT = "io/github/swagger2markup/config/default.properties"; - DefaultSwagger2MarkupConfig config = new DefaultSwagger2MarkupConfig(); + private DefaultSchema2MarkupConfig config; - public Swagger2MarkupConfigBuilder() { - this(new PropertiesConfiguration()); - } + public Schema2MarkupConfigBuilder(Schema2MarkupProperties schema2MarkupProperties, + Configuration configuration) { + this.config = createConfigInstance(); - public Swagger2MarkupConfigBuilder(Properties properties) { - this(ConfigurationConverter.getConfiguration(properties)); - } + config.listDelimiterEnabled = schema2MarkupProperties.getBoolean(LIST_DELIMITER_ENABLED, false); + config.listDelimiter = schema2MarkupProperties.getString(LIST_DELIMITER, ",").charAt(0); - public Swagger2MarkupConfigBuilder(Map map) { - this(new MapConfiguration(map)); - } - - public Swagger2MarkupConfigBuilder(Configuration configuration) { - CompositeConfiguration compositeConfiguration = new CompositeConfiguration(); - compositeConfiguration.addConfiguration(new SystemConfiguration()); - compositeConfiguration.addConfiguration(configuration); - compositeConfiguration.addConfiguration(getDefaultConfiguration()); - - Swagger2MarkupProperties swagger2MarkupProperties = new Swagger2MarkupProperties(compositeConfiguration); - - config.listDelimiterEnabled = swagger2MarkupProperties.getBoolean(LIST_DELIMITER_ENABLED, false); - config.listDelimiter = swagger2MarkupProperties.getString(LIST_DELIMITER, ",").charAt(0); - if (config.listDelimiterEnabled && configuration instanceof AbstractConfiguration) { - ((AbstractConfiguration)configuration).setListDelimiterHandler(new DefaultListDelimiterHandler(config.listDelimiter)); + ((AbstractConfiguration) configuration).setListDelimiterHandler(new DefaultListDelimiterHandler(config.listDelimiter)); } - config.markupLanguage = swagger2MarkupProperties.getRequiredMarkupLanguage(MARKUP_LANGUAGE); - config.swaggerMarkupLanguage = swagger2MarkupProperties.getRequiredMarkupLanguage(SWAGGER_MARKUP_LANGUAGE); - config.generatedExamplesEnabled = swagger2MarkupProperties.getRequiredBoolean(GENERATED_EXAMPLES_ENABLED); - config.hostnameEnabled = swagger2MarkupProperties.getRequiredBoolean(HOSTNAME_ENABLED); - config.basePathPrefixEnabled = swagger2MarkupProperties.getRequiredBoolean(BASE_PATH_PREFIX_ENABLED); - config.separatedDefinitionsEnabled = swagger2MarkupProperties.getRequiredBoolean(SEPARATED_DEFINITIONS_ENABLED); - config.separatedOperationsEnabled = swagger2MarkupProperties.getRequiredBoolean(SEPARATED_OPERATIONS_ENABLED); - config.pathsGroupedBy = swagger2MarkupProperties.getGroupBy(PATHS_GROUPED_BY); - config.outputLanguage = swagger2MarkupProperties.getLanguage(OUTPUT_LANGUAGE); - config.inlineSchemaEnabled = swagger2MarkupProperties.getRequiredBoolean(INLINE_SCHEMA_ENABLED); - config.interDocumentCrossReferencesEnabled = swagger2MarkupProperties.getRequiredBoolean(INTER_DOCUMENT_CROSS_REFERENCES_ENABLED); - config.interDocumentCrossReferencesPrefix = swagger2MarkupProperties.getString(INTER_DOCUMENT_CROSS_REFERENCES_PREFIX, null); - config.flatBodyEnabled = swagger2MarkupProperties.getRequiredBoolean(FLAT_BODY_ENABLED); - config.pathSecuritySectionEnabled = swagger2MarkupProperties.getRequiredBoolean(PATH_SECURITY_SECTION_ENABLED); - config.anchorPrefix = swagger2MarkupProperties.getString(ANCHOR_PREFIX, null); - config.overviewDocument = swagger2MarkupProperties.getRequiredString(OVERVIEW_DOCUMENT); - config.pathsDocument = swagger2MarkupProperties.getRequiredString(PATHS_DOCUMENT); - config.definitionsDocument = swagger2MarkupProperties.getRequiredString(DEFINITIONS_DOCUMENT); - config.securityDocument = swagger2MarkupProperties.getRequiredString(SECURITY_DOCUMENT); - config.separatedOperationsFolder = swagger2MarkupProperties.getRequiredString(SEPARATED_OPERATIONS_FOLDER); - config.separatedDefinitionsFolder = swagger2MarkupProperties.getRequiredString(SEPARATED_DEFINITIONS_FOLDER); - config.tagOrderBy = swagger2MarkupProperties.getOrderBy(TAG_ORDER_BY); - config.operationOrderBy = swagger2MarkupProperties.getOrderBy(OPERATION_ORDER_BY); - config.definitionOrderBy = swagger2MarkupProperties.getOrderBy(DEFINITION_ORDER_BY); - config.parameterOrderBy = swagger2MarkupProperties.getOrderBy(PARAMETER_ORDER_BY); - config.propertyOrderBy = swagger2MarkupProperties.getOrderBy(PROPERTY_ORDER_BY); - config.responseOrderBy = swagger2MarkupProperties.getOrderBy(RESPONSE_ORDER_BY); - Optional lineSeparator = swagger2MarkupProperties.getString(LINE_SEPARATOR); + config.markupLanguage = schema2MarkupProperties.getRequiredMarkupLanguage(MARKUP_LANGUAGE); + config.schemaMarkupLanguage = schema2MarkupProperties.getRequiredMarkupLanguage(SWAGGER_MARKUP_LANGUAGE); + config.generatedExamplesEnabled = schema2MarkupProperties.getRequiredBoolean(GENERATED_EXAMPLES_ENABLED); + config.hostnameEnabled = schema2MarkupProperties.getRequiredBoolean(HOSTNAME_ENABLED); + config.basePathPrefixEnabled = schema2MarkupProperties.getRequiredBoolean(BASE_PATH_PREFIX_ENABLED); + config.separatedDefinitionsEnabled = schema2MarkupProperties.getRequiredBoolean(SEPARATED_DEFINITIONS_ENABLED); + config.separatedOperationsEnabled = schema2MarkupProperties.getRequiredBoolean(SEPARATED_OPERATIONS_ENABLED); + config.pathsGroupedBy = schema2MarkupProperties.getGroupBy(PATHS_GROUPED_BY); + config.language = schema2MarkupProperties.getLanguage(OUTPUT_LANGUAGE); + config.inlineSchemaEnabled = schema2MarkupProperties.getRequiredBoolean(INLINE_SCHEMA_ENABLED); + config.interDocumentCrossReferencesEnabled = schema2MarkupProperties.getRequiredBoolean(INTER_DOCUMENT_CROSS_REFERENCES_ENABLED); + config.interDocumentCrossReferencesPrefix = schema2MarkupProperties.getString(INTER_DOCUMENT_CROSS_REFERENCES_PREFIX, null); + config.flatBodyEnabled = schema2MarkupProperties.getRequiredBoolean(FLAT_BODY_ENABLED); + config.pathSecuritySectionEnabled = schema2MarkupProperties.getRequiredBoolean(PATH_SECURITY_SECTION_ENABLED); + config.anchorPrefix = schema2MarkupProperties.getString(ANCHOR_PREFIX, null); + config.overviewDocument = schema2MarkupProperties.getRequiredString(OVERVIEW_DOCUMENT); + config.pathsDocument = schema2MarkupProperties.getRequiredString(PATHS_DOCUMENT); + config.definitionsDocument = schema2MarkupProperties.getRequiredString(DEFINITIONS_DOCUMENT); + config.securityDocument = schema2MarkupProperties.getRequiredString(SECURITY_DOCUMENT); + config.separatedOperationsFolder = schema2MarkupProperties.getRequiredString(SEPARATED_OPERATIONS_FOLDER); + config.separatedDefinitionsFolder = schema2MarkupProperties.getRequiredString(SEPARATED_DEFINITIONS_FOLDER); + config.tagOrderBy = schema2MarkupProperties.getOrderBy(TAG_ORDER_BY); + config.operationOrderBy = schema2MarkupProperties.getOrderBy(OPERATION_ORDER_BY); + config.definitionOrderBy = schema2MarkupProperties.getOrderBy(DEFINITION_ORDER_BY); + config.parameterOrderBy = schema2MarkupProperties.getOrderBy(PARAMETER_ORDER_BY); + config.propertyOrderBy = schema2MarkupProperties.getOrderBy(PROPERTY_ORDER_BY); + config.responseOrderBy = schema2MarkupProperties.getOrderBy(RESPONSE_ORDER_BY); + Optional lineSeparator = schema2MarkupProperties.getString(LINE_SEPARATOR); if (lineSeparator.isPresent() && StringUtils.isNoneBlank(lineSeparator.get())) { config.lineSeparator = LineSeparator.valueOf(lineSeparator.get()); } - config.pageBreakLocations = swagger2MarkupProperties.getPageBreakLocations(PAGE_BREAK_LOCATIONS); + config.pageBreakLocations = schema2MarkupProperties.getPageBreakLocations(PAGE_BREAK_LOCATIONS); - Optional headerPattern = swagger2MarkupProperties.getHeaderPattern(HEADER_REGEX); + Optional headerPattern = schema2MarkupProperties.getHeaderPattern(HEADER_REGEX); config.headerPattern = headerPattern.orElse(null); - - Configuration swagger2markupConfiguration = compositeConfiguration.subset(PROPERTIES_PREFIX); + + Configuration swagger2markupConfiguration = schema2MarkupProperties.getConfiguration().subset(PROPERTIES_PREFIX); Configuration extensionsConfiguration = swagger2markupConfiguration.subset(EXTENSION_PREFIX); - config.extensionsProperties = new Swagger2MarkupProperties(extensionsConfiguration); - config.asciidocPegdownTimeoutMillis = swagger2MarkupProperties.getRequiredInt(ASCIIDOC_PEGDOWN_TIMEOUT); + config.extensionsProperties = new Schema2MarkupProperties(extensionsConfiguration); + config.asciidocPegdownTimeoutMillis = schema2MarkupProperties.getRequiredInt(ASCIIDOC_PEGDOWN_TIMEOUT); } /** @@ -131,7 +118,7 @@ public class Swagger2MarkupConfigBuilder { * * @return the default properties */ - private Configuration getDefaultConfiguration() { + public static Configuration getDefaultConfiguration() { Configurations configs = new Configurations(); try { return configs.properties(PROPERTIES_DEFAULT); @@ -140,18 +127,7 @@ public class Swagger2MarkupConfigBuilder { } } - /** - * Builds the Swagger2MarkupConfig. - * - * @return the Swagger2MarkupConfig - */ - public Swagger2MarkupConfig build() { - buildNaturalOrdering(); - - return config; - } - - private void buildNaturalOrdering() { + protected void buildNaturalOrdering() { if (config.tagOrderBy == OrderBy.NATURAL) config.tagOrdering = Ordering.natural(); if (config.operationOrderBy == OrderBy.NATURAL) @@ -166,14 +142,23 @@ public class Swagger2MarkupConfigBuilder { config.responseOrdering = Ordering.natural(); } + public abstract DefaultSchema2MarkupConfig createConfigInstance(); + + /** + * Builds the OpenApi2MarkupConfig. + * + * @return the OpenApi2MarkupConfig + */ + public abstract DefaultSchema2MarkupConfig build(); + /** * Specifies the markup language which should be used to generate the files. * * @param markupLanguage the markup language which is used to generate the files * @return this builder */ - public Swagger2MarkupConfigBuilder withMarkupLanguage(MarkupLanguage markupLanguage) { - Validate.notNull(markupLanguage, "%s must not be null", "markupLanguage"); + public Schema2MarkupConfigBuilder withMarkupLanguage(MarkupLanguage markupLanguage) { + Validate.notNull(markupLanguage, "%s must not be null", "outputLanguage"); config.markupLanguage = markupLanguage; return this; } @@ -181,12 +166,12 @@ public class Swagger2MarkupConfigBuilder { /** * Specifies the markup language used in Swagger descriptions. * - * @param swaggerMarkupLanguage the markup language used in Swagger descriptions + * @param markupLanguage the markup language used in Swagger descriptions * @return this builder */ - public Swagger2MarkupConfigBuilder withSwaggerMarkupLanguage(MarkupLanguage swaggerMarkupLanguage) { - Validate.notNull(swaggerMarkupLanguage, "%s must not be null", "swaggerMarkupLanguage"); - config.swaggerMarkupLanguage = swaggerMarkupLanguage; + public Schema2MarkupConfigBuilder withSwaggerMarkupLanguage(MarkupLanguage markupLanguage) { + Validate.notNull(markupLanguage, "%s must not be null", "outputLanguage"); + config.schemaMarkupLanguage = markupLanguage; return this; } @@ -195,7 +180,7 @@ public class Swagger2MarkupConfigBuilder { * * @return this builder */ - public Swagger2MarkupConfigBuilder withGeneratedExamples() { + public Schema2MarkupConfigBuilder withGeneratedExamples() { config.generatedExamplesEnabled = true; return this; } @@ -205,7 +190,7 @@ public class Swagger2MarkupConfigBuilder { * * @return this builder */ - public Swagger2MarkupConfigBuilder withSeparatedDefinitions() { + public Schema2MarkupConfigBuilder withSeparatedDefinitions() { config.separatedDefinitionsEnabled = true; return this; } @@ -216,27 +201,28 @@ public class Swagger2MarkupConfigBuilder { * * @return this builder */ - public Swagger2MarkupConfigBuilder withSeparatedOperations() { + public Schema2MarkupConfigBuilder withSeparatedOperations() { config.separatedOperationsEnabled = true; return this; } - + /** * Allows properties to contain a list of elements delimited by a specified character. + * * @return this builder */ - public Swagger2MarkupConfigBuilder withListDelimiter() { + public Schema2MarkupConfigBuilder withListDelimiter() { config.listDelimiterEnabled = true; return this; } - + /** * Specifies the list delimiter which should be used. - * + * * @param delimiter the delimiter * @return this builder */ - public Swagger2MarkupConfigBuilder withListDelimiter(Character delimiter) { + public Schema2MarkupConfigBuilder withListDelimiter(Character delimiter) { Validate.notNull(delimiter, "%s must not be null", "delimiter"); config.listDelimiter = delimiter; config.listDelimiterEnabled = true; @@ -250,7 +236,7 @@ public class Swagger2MarkupConfigBuilder { * @param pathsGroupedBy the GroupBy enum * @return this builder */ - public Swagger2MarkupConfigBuilder withPathsGroupedBy(GroupBy pathsGroupedBy) { + public Schema2MarkupConfigBuilder withPathsGroupedBy(GroupBy pathsGroupedBy) { Validate.notNull(pathsGroupedBy, "%s must not be null", "pathsGroupedBy"); config.pathsGroupedBy = pathsGroupedBy; return this; @@ -263,7 +249,7 @@ public class Swagger2MarkupConfigBuilder { * @return this builder * @throws PatternSyntaxException when pattern cannot be compiled */ - public Swagger2MarkupConfigBuilder withHeaderRegex(String headerRegex) { + public Schema2MarkupConfigBuilder withHeaderRegex(String headerRegex) { Validate.notNull(headerRegex, "%s must not be null", headerRegex); config.headerPattern = Pattern.compile(headerRegex); return this; @@ -275,9 +261,9 @@ public class Swagger2MarkupConfigBuilder { * @param language the enum * @return this builder */ - public Swagger2MarkupConfigBuilder withOutputLanguage(Language language) { + public Schema2MarkupConfigBuilder withOutputLanguage(Language language) { Validate.notNull(language, "%s must not be null", "language"); - config.outputLanguage = language; + config.language = language; return this; } @@ -286,20 +272,20 @@ public class Swagger2MarkupConfigBuilder { * * @return this builder */ - public Swagger2MarkupConfigBuilder withoutInlineSchema() { + public Schema2MarkupConfigBuilder withoutInlineSchema() { config.inlineSchemaEnabled = false; return this; } /** * Specifies tag ordering.
- * By default tag ordering == {@link io.github.swagger2markup.OrderBy#NATURAL}.
+ * By default tag ordering == {@link OrderBy#NATURAL}.
* Use {@link #withTagOrdering(Comparator)} to set a custom ordering. * * @param orderBy tag ordering * @return this builder */ - public Swagger2MarkupConfigBuilder withTagOrdering(OrderBy orderBy) { + public Schema2MarkupConfigBuilder withTagOrdering(OrderBy orderBy) { Validate.notNull(orderBy, "%s must not be null", "orderBy"); Validate.isTrue(orderBy != OrderBy.CUSTOM, "You must provide a custom comparator if orderBy == OrderBy.CUSTOM"); config.tagOrderBy = orderBy; @@ -312,7 +298,7 @@ public class Swagger2MarkupConfigBuilder { * @param tagOrdering tag ordering * @return this builder */ - public Swagger2MarkupConfigBuilder withTagOrdering(Comparator tagOrdering) { + public Schema2MarkupConfigBuilder withTagOrdering(Comparator tagOrdering) { Validate.notNull(tagOrdering, "%s must not be null", "tagOrdering"); config.tagOrderBy = OrderBy.CUSTOM; config.tagOrdering = tagOrdering; @@ -321,13 +307,13 @@ public class Swagger2MarkupConfigBuilder { /** * Specifies operation ordering.
- * By default operation ordering == {@link io.github.swagger2markup.OrderBy#AS_IS}.
+ * By default operation ordering == {@link OrderBy#AS_IS}.
* Use {@link #withOperationOrdering(Comparator)} to set a custom ordering. * * @param orderBy operation ordering * @return this builder */ - public Swagger2MarkupConfigBuilder withOperationOrdering(OrderBy orderBy) { + public Schema2MarkupConfigBuilder withOperationOrdering(OrderBy orderBy) { Validate.notNull(orderBy, "%s must not be null", "orderBy"); Validate.isTrue(orderBy != OrderBy.CUSTOM, "You must provide a custom comparator if orderBy == OrderBy.CUSTOM"); config.operationOrderBy = orderBy; @@ -340,7 +326,7 @@ public class Swagger2MarkupConfigBuilder { * @param operationOrdering operation ordering * @return this builder */ - public Swagger2MarkupConfigBuilder withOperationOrdering(Comparator operationOrdering) { + public Schema2MarkupConfigBuilder withOperationOrdering(Comparator operationOrdering) { Validate.notNull(operationOrdering, "%s must not be null", "operationOrdering"); config.operationOrderBy = OrderBy.CUSTOM; config.operationOrdering = operationOrdering; @@ -349,13 +335,13 @@ public class Swagger2MarkupConfigBuilder { /** * Specifies definition ordering.
- * By default definition ordering == {@link io.github.swagger2markup.OrderBy#NATURAL}.
+ * By default definition ordering == {@link OrderBy#NATURAL}.
* Use {@link #withDefinitionOrdering(Comparator)} to set a custom ordering. * * @param orderBy definition ordering * @return this builder */ - public Swagger2MarkupConfigBuilder withDefinitionOrdering(OrderBy orderBy) { + public Schema2MarkupConfigBuilder withDefinitionOrdering(OrderBy orderBy) { Validate.notNull(orderBy, "%s must not be null", "orderBy"); Validate.isTrue(orderBy != OrderBy.CUSTOM, "You must provide a custom comparator if orderBy == OrderBy.CUSTOM"); config.definitionOrderBy = orderBy; @@ -368,7 +354,7 @@ public class Swagger2MarkupConfigBuilder { * @param definitionOrdering definition ordering * @return this builder */ - public Swagger2MarkupConfigBuilder withDefinitionOrdering(Comparator definitionOrdering) { + public Schema2MarkupConfigBuilder withDefinitionOrdering(Comparator definitionOrdering) { Validate.notNull(definitionOrdering, "%s must not be null", "definitionOrdering"); config.definitionOrderBy = OrderBy.CUSTOM; config.definitionOrdering = definitionOrdering; @@ -383,7 +369,7 @@ public class Swagger2MarkupConfigBuilder { * @param orderBy parameter ordering * @return this builder */ - public Swagger2MarkupConfigBuilder withParameterOrdering(OrderBy orderBy) { + public Schema2MarkupConfigBuilder withParameterOrdering(OrderBy orderBy) { Validate.notNull(orderBy, "%s must not be null", "orderBy"); Validate.isTrue(orderBy != OrderBy.CUSTOM, "You must provide a custom comparator if orderBy == OrderBy.CUSTOM"); config.parameterOrderBy = orderBy; @@ -396,7 +382,7 @@ public class Swagger2MarkupConfigBuilder { * @param parameterOrdering parameter ordering * @return this builder */ - public Swagger2MarkupConfigBuilder withParameterOrdering(Comparator parameterOrdering) { + public Schema2MarkupConfigBuilder withParameterOrdering(Comparator parameterOrdering) { Validate.notNull(parameterOrdering, "%s must not be null", "parameterOrdering"); config.parameterOrderBy = OrderBy.CUSTOM; @@ -406,13 +392,13 @@ public class Swagger2MarkupConfigBuilder { /** * Specifies property ordering.
- * By default property ordering == {@link io.github.swagger2markup.OrderBy#NATURAL}.
+ * By default property ordering == {@link OrderBy#NATURAL}.
* Use {@link #withPropertyOrdering(Comparator)} to set a custom ordering. * * @param orderBy property ordering * @return this builder */ - public Swagger2MarkupConfigBuilder withPropertyOrdering(OrderBy orderBy) { + public Schema2MarkupConfigBuilder withPropertyOrdering(OrderBy orderBy) { Validate.notNull(orderBy, "%s must not be null", "orderBy"); Validate.isTrue(orderBy != OrderBy.CUSTOM, "You must provide a custom comparator if orderBy == OrderBy.CUSTOM"); config.propertyOrderBy = orderBy; @@ -425,7 +411,7 @@ public class Swagger2MarkupConfigBuilder { * @param propertyOrdering property ordering * @return this builder */ - public Swagger2MarkupConfigBuilder withPropertyOrdering(Comparator propertyOrdering) { + public Schema2MarkupConfigBuilder withPropertyOrdering(Comparator propertyOrdering) { Validate.notNull(propertyOrdering, "%s must not be null", "propertyOrdering"); config.propertyOrderBy = OrderBy.CUSTOM; @@ -435,13 +421,13 @@ public class Swagger2MarkupConfigBuilder { /** * Specifies response ordering.
- * By default response ordering == {@link io.github.swagger2markup.OrderBy#NATURAL}.
+ * By default response ordering == {@link OrderBy#NATURAL}.
* Use {@link #withResponseOrdering(Comparator)} to set a custom ordering. * * @param orderBy response ordering * @return this builder */ - public Swagger2MarkupConfigBuilder withResponseOrdering(OrderBy orderBy) { + public Schema2MarkupConfigBuilder withResponseOrdering(OrderBy orderBy) { Validate.notNull(orderBy, "%s must not be null", "orderBy"); Validate.isTrue(orderBy != OrderBy.CUSTOM, "You must provide a custom comparator if orderBy == OrderBy.CUSTOM"); config.responseOrderBy = orderBy; @@ -454,7 +440,7 @@ public class Swagger2MarkupConfigBuilder { * @param responseOrdering response ordering * @return this builder */ - public Swagger2MarkupConfigBuilder withResponseOrdering(Comparator responseOrdering) { + public Schema2MarkupConfigBuilder withResponseOrdering(Comparator responseOrdering) { Validate.notNull(responseOrdering, "%s must not be null", "responseOrdering"); config.responseOrderBy = OrderBy.CUSTOM; @@ -468,7 +454,7 @@ public class Swagger2MarkupConfigBuilder { * @param prefix Prefix to document in all inter-document cross-references. * @return this builder */ - public Swagger2MarkupConfigBuilder withInterDocumentCrossReferences(String prefix) { + public Schema2MarkupConfigBuilder withInterDocumentCrossReferences(String prefix) { Validate.notNull(prefix, "%s must not be null", "prefix"); config.interDocumentCrossReferencesEnabled = true; config.interDocumentCrossReferencesPrefix = prefix; @@ -480,7 +466,7 @@ public class Swagger2MarkupConfigBuilder { * * @return this builder */ - public Swagger2MarkupConfigBuilder withInterDocumentCrossReferences() { + public Schema2MarkupConfigBuilder withInterDocumentCrossReferences() { config.interDocumentCrossReferencesEnabled = true; return this; } @@ -490,7 +476,7 @@ public class Swagger2MarkupConfigBuilder { * * @return this builder */ - public Swagger2MarkupConfigBuilder withFlatBody() { + public Schema2MarkupConfigBuilder withFlatBody() { config.flatBodyEnabled = true; return this; } @@ -500,7 +486,7 @@ public class Swagger2MarkupConfigBuilder { * * @return this builder */ - public Swagger2MarkupConfigBuilder withoutPathSecuritySection() { + public Schema2MarkupConfigBuilder withoutPathSecuritySection() { config.pathSecuritySectionEnabled = false; return this; } @@ -510,7 +496,7 @@ public class Swagger2MarkupConfigBuilder { * * @return this builder */ - public Swagger2MarkupConfigBuilder withBasePathPrefix() { + public Schema2MarkupConfigBuilder withBasePathPrefix() { config.basePathPrefixEnabled = true; return this; } @@ -521,7 +507,7 @@ public class Swagger2MarkupConfigBuilder { * @param anchorPrefix anchor prefix. * @return this builder */ - public Swagger2MarkupConfigBuilder withAnchorPrefix(String anchorPrefix) { + public Schema2MarkupConfigBuilder withAnchorPrefix(String anchorPrefix) { Validate.notNull(anchorPrefix, "%s must not be null", "anchorPrefix"); config.anchorPrefix = anchorPrefix; return this; @@ -533,7 +519,7 @@ public class Swagger2MarkupConfigBuilder { * @param locations List of locations to create new pages * @return this builder */ - public Swagger2MarkupConfigBuilder withPageBreaks(List locations) { + public Schema2MarkupConfigBuilder withPageBreaks(List locations) { Validate.notNull(locations, "%s must not be null", "locations"); config.pageBreakLocations = locations; return this; @@ -545,23 +531,33 @@ public class Swagger2MarkupConfigBuilder { * @param lineSeparator the lineSeparator * @return this builder */ - public Swagger2MarkupConfigBuilder withLineSeparator(LineSeparator lineSeparator) { + public Schema2MarkupConfigBuilder withLineSeparator(LineSeparator lineSeparator) { Validate.notNull(lineSeparator, "%s must no be null", "lineSeparator"); config.lineSeparator = lineSeparator; return this; } - static class DefaultSwagger2MarkupConfig implements Swagger2MarkupConfig { + protected static CompositeConfiguration getCompositeConfiguration(Configuration configuration) { + CompositeConfiguration compositeConfiguration = new CompositeConfiguration(); + compositeConfiguration.addConfiguration(new SystemConfiguration()); + compositeConfiguration.addConfiguration(configuration); + compositeConfiguration.addConfiguration(getDefaultConfiguration()); + return compositeConfiguration; + } + /** + * Default implementation of {@link Schema2MarkupConfig} + */ + public static class DefaultSchema2MarkupConfig implements Schema2MarkupConfig { private MarkupLanguage markupLanguage; - private MarkupLanguage swaggerMarkupLanguage; + private MarkupLanguage schemaMarkupLanguage; private boolean generatedExamplesEnabled; private boolean hostnameEnabled; private boolean basePathPrefixEnabled; private boolean separatedDefinitionsEnabled; private boolean separatedOperationsEnabled; private GroupBy pathsGroupedBy; - private Language outputLanguage; + private Language language; private boolean inlineSchemaEnabled; private OrderBy tagOrderBy; private Comparator tagOrdering; @@ -596,7 +592,7 @@ public class Swagger2MarkupConfigBuilder { private Pattern headerPattern; - private Swagger2MarkupProperties extensionsProperties; + private Schema2MarkupProperties extensionsProperties; @Override public MarkupLanguage getMarkupLanguage() { @@ -604,8 +600,8 @@ public class Swagger2MarkupConfigBuilder { } @Override - public MarkupLanguage getSwaggerMarkupLanguage() { - return swaggerMarkupLanguage; + public MarkupLanguage getSchemaMarkupLanguage() { + return schemaMarkupLanguage; } @Override @@ -629,8 +625,8 @@ public class Swagger2MarkupConfigBuilder { } @Override - public Language getOutputLanguage() { - return outputLanguage; + public Language getLanguage() { + return language; } @Override @@ -767,14 +763,14 @@ public class Swagger2MarkupConfigBuilder { public Character getListDelimiter() { return listDelimiter; } - + @Override public boolean isListDelimiterEnabled() { return listDelimiterEnabled; } @Override - public Swagger2MarkupProperties getExtensionsProperties() { + public Schema2MarkupProperties getExtensionsProperties() { return extensionsProperties; } diff --git a/swagger2markup-core/src/main/java/io/github/swagger2markup/extension/Schema2MarkupExtensionRegistry.java b/swagger2markup-core/src/main/java/io/github/swagger2markup/extension/Schema2MarkupExtensionRegistry.java new file mode 100644 index 00000000..17017371 --- /dev/null +++ b/swagger2markup-core/src/main/java/io/github/swagger2markup/extension/Schema2MarkupExtensionRegistry.java @@ -0,0 +1,23 @@ +/* + * Copyright 2017 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.extension; + +/** + * Marker interface for Extensions registry. + */ +public interface Schema2MarkupExtensionRegistry { + +} diff --git a/swagger2markup-core/src/main/java/io/github/swagger2markup/model/Parameter.java b/swagger2markup-core/src/main/java/io/github/swagger2markup/model/Parameter.java new file mode 100644 index 00000000..82f0846c --- /dev/null +++ b/swagger2markup-core/src/main/java/io/github/swagger2markup/model/Parameter.java @@ -0,0 +1,22 @@ +package io.github.swagger2markup.model; + +/** + * Parameter wrapper for Schema parameter model + */ +public class Parameter { + private String name; + private String in; + + public Parameter(String name, String in) { + this.name = name; + this.in = in; + } + + public String getName() { + return name; + } + + public String getIn() { + return in; + } +} diff --git a/swagger2markup-core/src/main/java/io/github/swagger2markup/model/PathOperation.java b/swagger2markup-core/src/main/java/io/github/swagger2markup/model/PathOperation.java index 8d102cdf..569f3513 100644 --- a/swagger2markup-core/src/main/java/io/github/swagger2markup/model/PathOperation.java +++ b/swagger2markup-core/src/main/java/io/github/swagger2markup/model/PathOperation.java @@ -1,80 +1,34 @@ -/* - * Copyright 2017 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.model; -import io.swagger.models.HttpMethod; -import io.swagger.models.Operation; - -import static org.apache.commons.lang3.StringUtils.isBlank; - +/** + * PathOperation wrapper for Schema operation model + */ public class PathOperation { - - private HttpMethod method; + private String httpMethod; private String path; - private Operation operation; + private String id; + private String title; - public PathOperation(HttpMethod method, String path, Operation operation) { - this.method = method; + public PathOperation(String httpMethod, String path, String id, String title) { + this.httpMethod = httpMethod; this.path = path; - this.operation = operation; + this.id = id; + this.title = title; } - public HttpMethod getMethod() { - return method; + public String getHttpMethod() { + return httpMethod; } public String getPath() { return path; } - /** - * Returns the display title for an operation - * - * @return the operation title - */ - public String getTitle() { - String operationName = operation.getSummary(); - if (isBlank(operationName)) { - operationName = getMethod().toString() + " " + getPath(); - } - return operationName; - } - - /** - * Returns an unique id for the operation.
- * Use {@code }, then {@code lowercase()} if operation id is not set. - * - * @return operation unique id - */ public String getId() { - String id = operation.getOperationId(); - - if (id == null) - id = getPath() + " " + getMethod().toString().toLowerCase(); - return id; } - public Operation getOperation() { - return operation; - } - - @Override - public String toString() { - return getId(); + public String getTitle() { + return title; } } diff --git a/swagger2markup-documentation/build.gradle b/swagger2markup-documentation/build.gradle index da3536ad..38c763c5 100644 --- a/swagger2markup-documentation/build.gradle +++ b/swagger2markup-documentation/build.gradle @@ -20,7 +20,7 @@ asciidoctor { sectanchors: '', hardbreaks: '', 'release-version': project.releaseVersion, - 'coreProjectDir': project(':swagger2markup-core').projectDir + 'coreProjectDir': project(':swagger2markup').projectDir ] } diff --git a/swagger2markup-documentation/src/docs/asciidoc/getting_started.adoc b/swagger2markup-documentation/src/docs/asciidoc/getting_started.adoc index 607a2e5d..602240d6 100644 --- a/swagger2markup-documentation/src/docs/asciidoc/getting_started.adoc +++ b/swagger2markup-documentation/src/docs/asciidoc/getting_started.adoc @@ -16,7 +16,7 @@ WARNING: The *groupId* has been changed from *io.github.robwin* to *io.github.sw [source,groovy, subs="attributes"] ---- repositories { - jcenter() + jCenter() } compile "io.github.swagger2markup:swagger2markup:{release-version}" diff --git a/swagger2markup/build.gradle b/swagger2markup/build.gradle new file mode 100644 index 00000000..4e7d535c --- /dev/null +++ b/swagger2markup/build.gradle @@ -0,0 +1,37 @@ +ext.moduleName='io.github.swagger2markup.swagger2markup' + +dependencies { + configurations.all { + resolutionStrategy.force dependencyOverrides.commonsCodec + resolutionStrategy.force dependencyOverrides.commonsIO + resolutionStrategy.force dependencyOverrides.commonsLang3 + resolutionStrategy.force dependencyOverrides.findBugs + resolutionStrategy.force dependencyOverrides.guava + resolutionStrategy.force dependencyOverrides.jaksonCore + resolutionStrategy.force dependencyOverrides.jacksonDatabind + resolutionStrategy.force dependencyOverrides.slf4j + // Test dependencies + resolutionStrategy.force dependencyOverrides.assertj + resolutionStrategy.force dependencyOverrides.jnrConstants + resolutionStrategy.force dependencyOverrides.jnrEnxio + resolutionStrategy.force dependencyOverrides.jnrPosix + resolutionStrategy.force dependencyOverrides.jodaTime + } + compile project(':swagger2markup-builder') + compile project(':swagger2markup-core') + implementation implLibraries.commonsBeanUtils + implementation implLibraries.commonsCollections4 + implementation implLibraries.commonsConf2 + implementation implLibraries.commonsIO + implementation implLibraries.commonsText + implementation implLibraries.jacksonDatabind + implementation implLibraries.guava + implementation implLibraries.paleo + implementation implLibraries.slf4j + implementation implLibraries.swaggerV2 + implementation implLibraries.vavr + testImplementation testLibraries.assertj + testImplementation testLibraries.assertjDiff + testImplementation testLibraries.junit + testImplementation testLibraries.logback +} diff --git a/swagger2markup-core/src/main/java/io/github/swagger2markup/Swagger2MarkupConverter.java b/swagger2markup/src/main/java/io/github/swagger2markup/Swagger2MarkupConverter.java similarity index 78% rename from swagger2markup-core/src/main/java/io/github/swagger2markup/Swagger2MarkupConverter.java rename to swagger2markup/src/main/java/io/github/swagger2markup/Swagger2MarkupConverter.java index 2b5fd885..9871bcfd 100644 --- a/swagger2markup-core/src/main/java/io/github/swagger2markup/Swagger2MarkupConverter.java +++ b/swagger2markup/src/main/java/io/github/swagger2markup/Swagger2MarkupConverter.java @@ -16,13 +16,18 @@ package io.github.swagger2markup; import io.github.swagger2markup.builder.Swagger2MarkupConfigBuilder; +import io.github.swagger2markup.builder.Swagger2MarkupConfigBuilder.Swagger2MarkupConfig; import io.github.swagger2markup.builder.Swagger2MarkupExtensionRegistryBuilder; +import io.github.swagger2markup.config.Labels; import io.github.swagger2markup.internal.document.DefinitionsDocument; import io.github.swagger2markup.internal.document.OverviewDocument; import io.github.swagger2markup.internal.document.PathsDocument; import io.github.swagger2markup.internal.document.SecurityDocument; +import io.github.swagger2markup.markup.builder.LineSeparator; import io.github.swagger2markup.markup.builder.MarkupDocBuilder; import io.github.swagger2markup.markup.builder.MarkupDocBuilders; +import io.github.swagger2markup.markup.builder.MarkupLanguage; +import io.github.swagger2markup.spi.Swagger2MarkupExtensionRegistry; import io.github.swagger2markup.utils.URIUtils; import io.swagger.models.Swagger; import io.swagger.parser.SwaggerParser; @@ -46,20 +51,20 @@ import java.nio.file.StandardOpenOption; /** * @author Robert Winkler */ -public class Swagger2MarkupConverter { - - private final Context context; +public class Swagger2MarkupConverter extends AbstractSchema2MarkupConverter { private final OverviewDocument overviewDocument; private final PathsDocument pathsDocument; private final DefinitionsDocument definitionsDocument; private final SecurityDocument securityDocument; + private final SwaggerContext swaggerContext; - public Swagger2MarkupConverter(Context context) { - this.context = context; - this.overviewDocument = new OverviewDocument(context); - this.pathsDocument = new PathsDocument(context); - this.definitionsDocument = new DefinitionsDocument(context); - this.securityDocument = new SecurityDocument(context); + public Swagger2MarkupConverter(SwaggerContext swaggerContext) { + super(swaggerContext); + this.swaggerContext = swaggerContext; + this.overviewDocument = new OverviewDocument(swaggerContext); + this.pathsDocument = new PathsDocument(swaggerContext); + this.definitionsDocument = new DefinitionsDocument(swaggerContext); + this.securityDocument = new SecurityDocument(swaggerContext); } /** @@ -163,8 +168,8 @@ public class Swagger2MarkupConverter { * * @return the global Context */ - public Context getContext() { - return context; + public SwaggerContext getContext() { + return swaggerContext; } /** @@ -175,40 +180,40 @@ public class Swagger2MarkupConverter { public void toFolder(Path outputDirectory) { Validate.notNull(outputDirectory, "outputDirectory must not be null"); - context.setOutputPath(outputDirectory); + swaggerContext.setOutputPath(outputDirectory); applyOverviewDocument() - .writeToFile(outputDirectory.resolve(context.config.getOverviewDocument()), StandardCharsets.UTF_8); + .writeToFile(outputDirectory.resolve(swaggerContext.config.getOverviewDocument()), StandardCharsets.UTF_8); applyPathsDocument() - .writeToFile(outputDirectory.resolve(context.config.getPathsDocument()), StandardCharsets.UTF_8); + .writeToFile(outputDirectory.resolve(swaggerContext.config.getPathsDocument()), StandardCharsets.UTF_8); applyDefinitionsDocument() - .writeToFile(outputDirectory.resolve(context.config.getDefinitionsDocument()), StandardCharsets.UTF_8); + .writeToFile(outputDirectory.resolve(swaggerContext.config.getDefinitionsDocument()), StandardCharsets.UTF_8); applySecurityDocument() - .writeToFile(outputDirectory.resolve(context.config.getSecurityDocument()), StandardCharsets.UTF_8); + .writeToFile(outputDirectory.resolve(swaggerContext.config.getSecurityDocument()), StandardCharsets.UTF_8); } private MarkupDocBuilder applyOverviewDocument() { return overviewDocument.apply( - context.createMarkupDocBuilder(), - OverviewDocument.parameters(context.getSwagger())); + swaggerContext.createMarkupDocBuilder(), + OverviewDocument.parameters(swaggerContext.getSchema())); } private MarkupDocBuilder applyPathsDocument() { return pathsDocument.apply( - context.createMarkupDocBuilder(), - PathsDocument.parameters(context.getSwagger().getPaths())); + swaggerContext.createMarkupDocBuilder(), + PathsDocument.parameters(swaggerContext.getSchema().getPaths())); } private MarkupDocBuilder applyDefinitionsDocument() { return definitionsDocument.apply( - context.createMarkupDocBuilder(), - DefinitionsDocument.parameters(context.getSwagger().getDefinitions())); + swaggerContext.createMarkupDocBuilder(), + DefinitionsDocument.parameters(swaggerContext.getSchema().getDefinitions())); } private MarkupDocBuilder applySecurityDocument() { return securityDocument.apply( - context.createMarkupDocBuilder(), - SecurityDocument.parameters(context.getSwagger().getSecurityDefinitions())); + swaggerContext.createMarkupDocBuilder(), + SecurityDocument.parameters(swaggerContext.getSchema().getSecurityDefinitions())); } /** @@ -343,8 +348,8 @@ public class Swagger2MarkupConverter { if (extensionRegistry == null) extensionRegistry = new Swagger2MarkupExtensionRegistryBuilder().build(); - - Context context = new Context(config, extensionRegistry, swagger, swaggerLocation); + SwaggerLabels swaggerLabels = new SwaggerLabels(config); + SwaggerContext context = new SwaggerContext(config, extensionRegistry, swagger, swaggerLocation, swaggerLabels); initExtensions(context); @@ -353,7 +358,7 @@ public class Swagger2MarkupConverter { return new Swagger2MarkupConverter(context); } - private void initExtensions(Context context) { + private void initExtensions(SwaggerContext context) { extensionRegistry.getSwaggerModelExtensions().forEach(extension -> extension.setGlobalContext(context)); extensionRegistry.getOverviewDocumentExtensions().forEach(extension -> extension.setGlobalContext(context)); extensionRegistry.getDefinitionsDocumentExtensions().forEach(extension -> extension.setGlobalContext(context)); @@ -361,61 +366,44 @@ public class Swagger2MarkupConverter { extensionRegistry.getSecurityDocumentExtensions().forEach(extension -> extension.setGlobalContext(context)); } - private void applySwaggerExtensions(Context context) { - extensionRegistry.getSwaggerModelExtensions().forEach(extension -> extension.apply(context.getSwagger())); + private void applySwaggerExtensions(SwaggerContext context) { + extensionRegistry.getSwaggerModelExtensions().forEach(extension -> extension.apply(context.getSchema())); } } - public static class Context { - private final Swagger2MarkupConfig config; - private final Swagger swagger; - private final URI swaggerLocation; - private final Swagger2MarkupExtensionRegistry extensionRegistry; - private final Labels labels; - private Path outputPath; + public static class SwaggerContext extends Context { + private Swagger2MarkupConfig config; + private Swagger2MarkupExtensionRegistry extensionRegistry; - public Context(Swagger2MarkupConfig config, - Swagger2MarkupExtensionRegistry extensionRegistry, - Swagger swagger, - URI swaggerLocation) { + public SwaggerContext(Swagger2MarkupConfig config, + Swagger2MarkupExtensionRegistry extensionRegistry, + Swagger schema, URI swaggerLocation, Labels labels) { + super(config, extensionRegistry, schema, swaggerLocation, labels); this.config = config; this.extensionRegistry = extensionRegistry; - this.swagger = swagger; - this.swaggerLocation = swaggerLocation; - this.labels = new Labels(config); } + @Override public Swagger2MarkupConfig getConfig() { return config; } - public Swagger getSwagger() { - return swagger; - } - - public URI getSwaggerLocation() { - return swaggerLocation; - } - + @Override public Swagger2MarkupExtensionRegistry getExtensionRegistry() { return extensionRegistry; } - public Labels getLabels() { - return labels; - } - public MarkupDocBuilder createMarkupDocBuilder() { - return MarkupDocBuilders.documentBuilder(config.getMarkupLanguage(), - config.getLineSeparator(), config.getAsciidocPegdownTimeoutMillis()).withAnchorPrefix(config.getAnchorPrefix()); - } - - public Path getOutputPath() { - return outputPath; - } - - public void setOutputPath(Path outputPath) { - this.outputPath = outputPath; + MarkupLanguage markupLanguage = null; + if (config.getMarkupLanguage() != null) { + markupLanguage = MarkupLanguage.valueOf(config.getMarkupLanguage().name()); + } + LineSeparator lineSeparator = null; + if (config.getLineSeparator() != null) { + lineSeparator = LineSeparator.valueOf(config.getLineSeparator().name()); + } + return MarkupDocBuilders.documentBuilder(markupLanguage, lineSeparator, + config.getAsciidocPegdownTimeoutMillis()).withAnchorPrefix(config.getAnchorPrefix()); } } diff --git a/swagger2markup/src/main/java/io/github/swagger2markup/Swagger2MarkupProperties.java b/swagger2markup/src/main/java/io/github/swagger2markup/Swagger2MarkupProperties.java new file mode 100644 index 00000000..edd18c80 --- /dev/null +++ b/swagger2markup/src/main/java/io/github/swagger2markup/Swagger2MarkupProperties.java @@ -0,0 +1,36 @@ +/* + * Copyright 2017 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; + +import org.apache.commons.configuration2.Configuration; + +import java.util.Map; +import java.util.Properties; + +public class Swagger2MarkupProperties extends Schema2MarkupProperties { + + public Swagger2MarkupProperties(Properties properties) { + super(properties); + } + + public Swagger2MarkupProperties(Map map) { + super(map); + } + + public Swagger2MarkupProperties(Configuration configuration) { + super(configuration); + } +} diff --git a/swagger2markup-core/src/main/java/io/github/swagger2markup/Labels.java b/swagger2markup/src/main/java/io/github/swagger2markup/SwaggerLabels.java similarity index 90% rename from swagger2markup-core/src/main/java/io/github/swagger2markup/Labels.java rename to swagger2markup/src/main/java/io/github/swagger2markup/SwaggerLabels.java index 6910f4e5..d49bec20 100644 --- a/swagger2markup-core/src/main/java/io/github/swagger2markup/Labels.java +++ b/swagger2markup/src/main/java/io/github/swagger2markup/SwaggerLabels.java @@ -15,9 +15,12 @@ */ package io.github.swagger2markup; +import io.github.swagger2markup.builder.Swagger2MarkupConfigBuilder.Swagger2MarkupConfig; +import io.github.swagger2markup.config.Labels; + import java.util.ResourceBundle; -public class Labels { +public class SwaggerLabels extends Labels { public static final String DEFAULT_COLUMN = "default_column"; public static final String MAXLENGTH_COLUMN = "maxlength_column"; @@ -97,19 +100,7 @@ public class Labels { public static final String DEPRECATED_OPERATION = "operation.deprecated"; public static final String UNKNOWN = "unknown"; - private ResourceBundle resourceBundle; - - public Labels(Swagger2MarkupConfig config) { - this.resourceBundle = ResourceBundle.getBundle("io/github/swagger2markup/lang/labels", config.getOutputLanguage().toLocale()); - } - - /** - * Gets a label for the given key from this resource bundle. - * - * @param key the key for the desired label - * @return the label for the given key - */ - public String getLabel(String key) { - return resourceBundle.getString(key); + public SwaggerLabels(Swagger2MarkupConfig config) { + super(ResourceBundle.getBundle("io/github/swagger2markup/lang/labels", config.getLanguage().toLocale())); } } diff --git a/swagger2markup-core/src/main/java/io/github/swagger2markup/PageBreakLocations.java b/swagger2markup/src/main/java/io/github/swagger2markup/SwaggerPageBreakLocations.java similarity index 92% rename from swagger2markup-core/src/main/java/io/github/swagger2markup/PageBreakLocations.java rename to swagger2markup/src/main/java/io/github/swagger2markup/SwaggerPageBreakLocations.java index fa663235..9def6f78 100644 --- a/swagger2markup-core/src/main/java/io/github/swagger2markup/PageBreakLocations.java +++ b/swagger2markup/src/main/java/io/github/swagger2markup/SwaggerPageBreakLocations.java @@ -15,7 +15,7 @@ */ package io.github.swagger2markup; -public enum PageBreakLocations { +public enum SwaggerPageBreakLocations implements io.github.swagger2markup.config.PageBreakLocations { BEFORE_OPERATION, BEFORE_OPERATION_DESCRIPTION, BEFORE_OPERATION_PARAMETERS, diff --git a/swagger2markup/src/main/java/io/github/swagger2markup/builder/Swagger2MarkupConfigBuilder.java b/swagger2markup/src/main/java/io/github/swagger2markup/builder/Swagger2MarkupConfigBuilder.java new file mode 100644 index 00000000..77fcaf69 --- /dev/null +++ b/swagger2markup/src/main/java/io/github/swagger2markup/builder/Swagger2MarkupConfigBuilder.java @@ -0,0 +1,52 @@ +package io.github.swagger2markup.builder; + +import io.github.swagger2markup.Schema2MarkupProperties; +import io.github.swagger2markup.config.builder.Schema2MarkupConfigBuilder; +import org.apache.commons.configuration2.Configuration; +import org.apache.commons.configuration2.ConfigurationConverter; +import org.apache.commons.configuration2.MapConfiguration; +import org.apache.commons.configuration2.PropertiesConfiguration; + +import java.util.Map; +import java.util.Properties; + +public class Swagger2MarkupConfigBuilder extends Schema2MarkupConfigBuilder { + protected Swagger2MarkupConfig config; + + public Swagger2MarkupConfigBuilder() { + this(new PropertiesConfiguration()); + } + + public Swagger2MarkupConfigBuilder(Properties properties) { + this(ConfigurationConverter.getConfiguration(properties)); + } + + public Swagger2MarkupConfigBuilder(Map map) { + this(new MapConfiguration(map)); + } + + public Swagger2MarkupConfigBuilder(Configuration configuration) { + super(new Schema2MarkupProperties(getCompositeConfiguration(configuration)), configuration); + } + + @Override + public DefaultSchema2MarkupConfig createConfigInstance() { + if(config == null) { + config = new Swagger2MarkupConfig(); + } + return config; + } + + @Override + public Swagger2MarkupConfig build() { + buildNaturalOrdering(); + return config; + } + + /** + * Swagger specific implementation of {@link io.github.swagger2markup.config.Schema2MarkupConfig} + */ + public static class Swagger2MarkupConfig extends DefaultSchema2MarkupConfig { + + } +} diff --git a/swagger2markup-core/src/main/java/io/github/swagger2markup/builder/Swagger2MarkupExtensionRegistryBuilder.java b/swagger2markup/src/main/java/io/github/swagger2markup/builder/Swagger2MarkupExtensionRegistryBuilder.java similarity index 83% rename from swagger2markup-core/src/main/java/io/github/swagger2markup/builder/Swagger2MarkupExtensionRegistryBuilder.java rename to swagger2markup/src/main/java/io/github/swagger2markup/builder/Swagger2MarkupExtensionRegistryBuilder.java index 1d8e0bc0..a700df0f 100644 --- a/swagger2markup-core/src/main/java/io/github/swagger2markup/builder/Swagger2MarkupExtensionRegistryBuilder.java +++ b/swagger2markup/src/main/java/io/github/swagger2markup/builder/Swagger2MarkupExtensionRegistryBuilder.java @@ -16,7 +16,6 @@ package io.github.swagger2markup.builder; -import io.github.swagger2markup.Swagger2MarkupExtensionRegistry; import io.github.swagger2markup.spi.*; import java.util.List; @@ -107,17 +106,17 @@ public class Swagger2MarkupExtensionRegistryBuilder { } private static class Context { - public final List swaggerModelExtensions; - public final List overviewDocumentExtensions; - public final List definitionsDocumentExtensions; - public final List pathsDocumentExtensions; - public final List securityDocumentExtensions; + final List swaggerModelExtensions; + final List overviewDocumentExtensions; + final List definitionsDocumentExtensions; + final List pathsDocumentExtensions; + final List securityDocumentExtensions; - public Context(List swaggerModelExtensions, - List overviewDocumentExtensions, - List definitionsDocumentExtensions, - List pathsDocumentExtensions, - List securityDocumentExtensions) { + Context(List swaggerModelExtensions, + List overviewDocumentExtensions, + List definitionsDocumentExtensions, + List pathsDocumentExtensions, + List securityDocumentExtensions) { this.swaggerModelExtensions = swaggerModelExtensions; this.overviewDocumentExtensions = overviewDocumentExtensions; this.definitionsDocumentExtensions = definitionsDocumentExtensions; @@ -125,4 +124,4 @@ public class Swagger2MarkupExtensionRegistryBuilder { this.securityDocumentExtensions = securityDocumentExtensions; } } -} +} \ No newline at end of file diff --git a/swagger2markup-core/src/main/java/io/github/swagger2markup/internal/adapter/ParameterAdapter.java b/swagger2markup/src/main/java/io/github/swagger2markup/internal/adapter/ParameterAdapter.java similarity index 86% rename from swagger2markup-core/src/main/java/io/github/swagger2markup/internal/adapter/ParameterAdapter.java rename to swagger2markup/src/main/java/io/github/swagger2markup/internal/adapter/ParameterAdapter.java index 72033093..0cd79feb 100644 --- a/swagger2markup-core/src/main/java/io/github/swagger2markup/internal/adapter/ParameterAdapter.java +++ b/swagger2markup/src/main/java/io/github/swagger2markup/internal/adapter/ParameterAdapter.java @@ -16,26 +16,18 @@ package io.github.swagger2markup.internal.adapter; import com.fasterxml.jackson.annotation.JsonIgnore; -import io.github.swagger2markup.Swagger2MarkupConfig; -import io.github.swagger2markup.Swagger2MarkupConverter; +import io.github.swagger2markup.Swagger2MarkupConverter.SwaggerContext; +import io.github.swagger2markup.builder.Swagger2MarkupConfigBuilder.Swagger2MarkupConfig; import io.github.swagger2markup.internal.resolver.DocumentResolver; -import io.github.swagger2markup.internal.type.ArrayType; -import io.github.swagger2markup.internal.type.BasicType; -import io.github.swagger2markup.internal.type.EnumType; -import io.github.swagger2markup.internal.type.ObjectType; -import io.github.swagger2markup.internal.type.RefType; -import io.github.swagger2markup.internal.type.Type; +import io.github.swagger2markup.internal.type.*; import io.github.swagger2markup.internal.utils.ExamplesUtil; import io.github.swagger2markup.internal.utils.InlineSchemaUtils; import io.github.swagger2markup.internal.utils.ModelUtils; import io.github.swagger2markup.markup.builder.MarkupDocBuilder; +import io.github.swagger2markup.markup.builder.MarkupLanguage; import io.github.swagger2markup.model.PathOperation; import io.swagger.models.Model; -import io.swagger.models.parameters.AbstractSerializableParameter; -import io.swagger.models.parameters.BodyParameter; -import io.swagger.models.parameters.Parameter; -import io.swagger.models.parameters.RefParameter; -import io.swagger.models.parameters.SerializableParameter; +import io.swagger.models.parameters.*; import io.swagger.util.Json; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.Validate; @@ -46,9 +38,7 @@ import java.util.List; import java.util.Map; import java.util.Optional; -import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.boldText; -import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.literalText; -import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.markupDescription; +import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.*; public class ParameterAdapter { @@ -57,13 +47,13 @@ public class ParameterAdapter { private final Swagger2MarkupConfig config; private Type type; - public ParameterAdapter(Swagger2MarkupConverter.Context context, + public ParameterAdapter(SwaggerContext context, PathOperation operation, Parameter parameter, DocumentResolver definitionDocumentResolver) { Validate.notNull(parameter, "parameter must not be null"); this.parameter = parameter; - type = getType(context.getSwagger().getDefinitions(), definitionDocumentResolver); + type = getType(context.getSchema().getDefinitions(), definitionDocumentResolver); config = context.getConfig(); if (config.isInlineSchemaEnabled()) { if (config.isFlatBodyEnabled()) { @@ -119,7 +109,8 @@ public class ParameterAdapter { } public String displayDescription(MarkupDocBuilder markupDocBuilder) { - return markupDescription(config.getSwaggerMarkupLanguage(), markupDocBuilder, getDescription()); + io.github.swagger2markup.config.MarkupLanguage schemaMarkupLanguage = config.getSchemaMarkupLanguage(); + return markupDescription(MarkupLanguage.valueOf(schemaMarkupLanguage.name()), markupDocBuilder, getDescription()); } public String displayType(MarkupDocBuilder markupDocBuilder) { diff --git a/swagger2markup-core/src/main/java/io/github/swagger2markup/internal/adapter/PropertyAdapter.java b/swagger2markup/src/main/java/io/github/swagger2markup/internal/adapter/PropertyAdapter.java similarity index 100% rename from swagger2markup-core/src/main/java/io/github/swagger2markup/internal/adapter/PropertyAdapter.java rename to swagger2markup/src/main/java/io/github/swagger2markup/internal/adapter/PropertyAdapter.java diff --git a/swagger2markup-core/src/main/java/io/github/swagger2markup/internal/component/BodyParameterComponent.java b/swagger2markup/src/main/java/io/github/swagger2markup/internal/component/BodyParameterComponent.java similarity index 88% rename from swagger2markup-core/src/main/java/io/github/swagger2markup/internal/component/BodyParameterComponent.java rename to swagger2markup/src/main/java/io/github/swagger2markup/internal/component/BodyParameterComponent.java index 8b07a391..a52b798b 100644 --- a/swagger2markup-core/src/main/java/io/github/swagger2markup/internal/component/BodyParameterComponent.java +++ b/swagger2markup/src/main/java/io/github/swagger2markup/internal/component/BodyParameterComponent.java @@ -16,14 +16,15 @@ package io.github.swagger2markup.internal.component; -import io.github.swagger2markup.GroupBy; import io.github.swagger2markup.Swagger2MarkupConverter; +import io.github.swagger2markup.config.GroupBy; import io.github.swagger2markup.internal.adapter.ParameterAdapter; import io.github.swagger2markup.internal.resolver.DocumentResolver; import io.github.swagger2markup.internal.type.ObjectType; import io.github.swagger2markup.internal.type.Type; import io.github.swagger2markup.markup.builder.MarkupDocBuilder; -import io.github.swagger2markup.model.PathOperation; +import io.github.swagger2markup.markup.builder.MarkupLanguage; +import io.github.swagger2markup.model.SwaggerPathOperation; import io.github.swagger2markup.spi.MarkupComponent; import io.swagger.models.parameters.Parameter; import org.apache.commons.collections4.CollectionUtils; @@ -34,7 +35,7 @@ import org.apache.commons.lang3.Validate; import java.util.ArrayList; import java.util.List; -import static io.github.swagger2markup.Labels.*; +import static io.github.swagger2markup.SwaggerLabels.*; import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.copyMarkupDocBuilder; import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.markupDescription; import static org.apache.commons.lang3.StringUtils.isNotBlank; @@ -44,21 +45,21 @@ public class BodyParameterComponent extends MarkupComponent inlineDefinitions) { return new BodyParameterComponent.Parameters(operation, inlineDefinitions); } @Override public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, Parameters params) { - PathOperation operation = params.operation; + SwaggerPathOperation operation = params.operation; List inlineDefinitions = params.inlineDefinitions; if (config.isFlatBodyEnabled()) { List parameters = operation.getOperation().getParameters(); @@ -74,7 +75,8 @@ public class BodyParameterComponent extends MarkupComponent inlineDefinitions; - private PathOperation operation; + private SwaggerPathOperation operation; - public Parameters(PathOperation operation, + public Parameters(SwaggerPathOperation operation, List inlineDefinitions) { Validate.notNull(operation, "Operation must not be null"); this.operation = operation; diff --git a/swagger2markup-core/src/main/java/io/github/swagger2markup/internal/component/ConsumesComponent.java b/swagger2markup/src/main/java/io/github/swagger2markup/internal/component/ConsumesComponent.java similarity index 92% rename from swagger2markup-core/src/main/java/io/github/swagger2markup/internal/component/ConsumesComponent.java rename to swagger2markup/src/main/java/io/github/swagger2markup/internal/component/ConsumesComponent.java index c1a343c7..985dee74 100644 --- a/swagger2markup-core/src/main/java/io/github/swagger2markup/internal/component/ConsumesComponent.java +++ b/swagger2markup/src/main/java/io/github/swagger2markup/internal/component/ConsumesComponent.java @@ -16,8 +16,8 @@ package io.github.swagger2markup.internal.component; -import io.github.swagger2markup.Labels; import io.github.swagger2markup.Swagger2MarkupConverter; +import io.github.swagger2markup.SwaggerLabels; import io.github.swagger2markup.markup.builder.MarkupDocBuilder; import io.github.swagger2markup.spi.MarkupComponent; import org.apache.commons.lang3.Validate; @@ -29,7 +29,7 @@ import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.lite public class ConsumesComponent extends MarkupComponent { - public ConsumesComponent(Swagger2MarkupConverter.Context context) { + public ConsumesComponent(Swagger2MarkupConverter.SwaggerContext context) { super(context); } @@ -40,7 +40,7 @@ public class ConsumesComponent extends MarkupComponent literalText(markupDocBuilder, value)).collect(Collectors.toList())); return markupDocBuilder; diff --git a/swagger2markup-core/src/main/java/io/github/swagger2markup/internal/component/ContactInfoComponent.java b/swagger2markup/src/main/java/io/github/swagger2markup/internal/component/ContactInfoComponent.java similarity index 87% rename from swagger2markup-core/src/main/java/io/github/swagger2markup/internal/component/ContactInfoComponent.java rename to swagger2markup/src/main/java/io/github/swagger2markup/internal/component/ContactInfoComponent.java index 89ee03f7..8faa5e08 100644 --- a/swagger2markup-core/src/main/java/io/github/swagger2markup/internal/component/ContactInfoComponent.java +++ b/swagger2markup/src/main/java/io/github/swagger2markup/internal/component/ContactInfoComponent.java @@ -16,8 +16,8 @@ package io.github.swagger2markup.internal.component; -import io.github.swagger2markup.Labels; import io.github.swagger2markup.Swagger2MarkupConverter; +import io.github.swagger2markup.SwaggerLabels; import io.github.swagger2markup.markup.builder.MarkupDocBuilder; import io.github.swagger2markup.spi.MarkupComponent; import io.swagger.models.Contact; @@ -28,7 +28,7 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank; public class ContactInfoComponent extends MarkupComponent { - public ContactInfoComponent(Swagger2MarkupConverter.Context context) { + public ContactInfoComponent(Swagger2MarkupConverter.SwaggerContext context) { super(context); } @@ -41,14 +41,14 @@ public class ContactInfoComponent extends MarkupComponent() {{ put(ObjectTypePolymorphism.Nature.COMPOSITION, labels.getLabel(POLYMORPHISM_NATURE_COMPOSITION)); @@ -81,16 +74,17 @@ public class DefinitionComponent extends MarkupComponent extension.apply(context)); } diff --git a/swagger2markup-core/src/main/java/io/github/swagger2markup/internal/component/ExternalDocsComponent.java b/swagger2markup/src/main/java/io/github/swagger2markup/internal/component/ExternalDocsComponent.java similarity index 91% rename from swagger2markup-core/src/main/java/io/github/swagger2markup/internal/component/ExternalDocsComponent.java rename to swagger2markup/src/main/java/io/github/swagger2markup/internal/component/ExternalDocsComponent.java index 643280e2..578485df 100644 --- a/swagger2markup-core/src/main/java/io/github/swagger2markup/internal/component/ExternalDocsComponent.java +++ b/swagger2markup/src/main/java/io/github/swagger2markup/internal/component/ExternalDocsComponent.java @@ -21,15 +21,13 @@ import io.github.swagger2markup.spi.MarkupComponent; import io.swagger.models.ExternalDocs; import org.apache.commons.lang3.Validate; -import static io.github.swagger2markup.Labels.EXTERNAL_DOCS; -import static io.github.swagger2markup.Labels.EXTERNAL_DOCS_DESC; -import static io.github.swagger2markup.Labels.EXTERNAL_DOCS_URL; +import static io.github.swagger2markup.SwaggerLabels.*; import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.copyMarkupDocBuilder; import static org.apache.commons.lang3.StringUtils.isNotBlank; public class ExternalDocsComponent extends MarkupComponent { - public ExternalDocsComponent(Swagger2MarkupConverter.Context context) { + public ExternalDocsComponent(Swagger2MarkupConverter.SwaggerContext context) { super(context); } diff --git a/swagger2markup-core/src/main/java/io/github/swagger2markup/internal/component/LicenseInfoComponent.java b/swagger2markup/src/main/java/io/github/swagger2markup/internal/component/LicenseInfoComponent.java similarity index 95% rename from swagger2markup-core/src/main/java/io/github/swagger2markup/internal/component/LicenseInfoComponent.java rename to swagger2markup/src/main/java/io/github/swagger2markup/internal/component/LicenseInfoComponent.java index 6dcca6fa..a7a5a94e 100644 --- a/swagger2markup-core/src/main/java/io/github/swagger2markup/internal/component/LicenseInfoComponent.java +++ b/swagger2markup/src/main/java/io/github/swagger2markup/internal/component/LicenseInfoComponent.java @@ -22,13 +22,13 @@ import io.swagger.models.Info; import io.swagger.models.License; import org.apache.commons.lang3.Validate; -import static io.github.swagger2markup.Labels.*; +import static io.github.swagger2markup.SwaggerLabels.*; import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.copyMarkupDocBuilder; import static org.apache.commons.lang3.StringUtils.isNotBlank; public class LicenseInfoComponent extends MarkupComponent { - public LicenseInfoComponent(Swagger2MarkupConverter.Context context) { + public LicenseInfoComponent(Swagger2MarkupConverter.SwaggerContext context) { super(context); } diff --git a/swagger2markup-core/src/main/java/io/github/swagger2markup/internal/component/ParameterTableComponent.java b/swagger2markup/src/main/java/io/github/swagger2markup/internal/component/ParameterTableComponent.java similarity index 90% rename from swagger2markup-core/src/main/java/io/github/swagger2markup/internal/component/ParameterTableComponent.java rename to swagger2markup/src/main/java/io/github/swagger2markup/internal/component/ParameterTableComponent.java index 82ae1f32..568afc83 100644 --- a/swagger2markup-core/src/main/java/io/github/swagger2markup/internal/component/ParameterTableComponent.java +++ b/swagger2markup/src/main/java/io/github/swagger2markup/internal/component/ParameterTableComponent.java @@ -22,7 +22,7 @@ import io.github.swagger2markup.internal.adapter.ParameterAdapter; import io.github.swagger2markup.internal.resolver.DocumentResolver; import io.github.swagger2markup.internal.type.ObjectType; import io.github.swagger2markup.markup.builder.MarkupDocBuilder; -import io.github.swagger2markup.model.PathOperation; +import io.github.swagger2markup.model.SwaggerPathOperation; import io.github.swagger2markup.spi.MarkupComponent; import io.github.swagger2markup.spi.PathsDocumentExtension; import io.swagger.models.parameters.Parameter; @@ -30,11 +30,12 @@ import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.Validate; +import java.util.Comparator; import java.util.List; import java.util.stream.Collectors; import static ch.netzwerg.paleo.ColumnIds.StringColumnId; -import static io.github.swagger2markup.Labels.*; +import static io.github.swagger2markup.SwaggerLabels.*; import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.copyMarkupDocBuilder; import static org.apache.commons.lang3.StringUtils.isNotBlank; @@ -44,7 +45,7 @@ public class ParameterTableComponent extends MarkupComponent inlineDefinitions, int titleLevel) { return new ParameterTableComponent.Parameters(operation, inlineDefinitions, titleLevel); @@ -60,11 +61,17 @@ public class ParameterTableComponent extends MarkupComponent inlineDefinitions = params.inlineDefinitions; List parameters = operation.getOperation().getParameters(); - if (config.getParameterOrdering() != null) - parameters.sort(config.getParameterOrdering()); + if (config.getParameterOrdering() != null) { + Comparator parameterOrdering = config.getParameterOrdering(); + parameters.sort((o1, o2) -> { + io.github.swagger2markup.model.Parameter p1 = new io.github.swagger2markup.model.Parameter(o1.getName(), o1.getIn()); + io.github.swagger2markup.model.Parameter p2 = new io.github.swagger2markup.model.Parameter(o2.getName(), o2.getIn()); + return parameterOrdering.compare(p1, p2); + }); + } // Filter parameters to display in parameters section List filteredParameters = parameters.stream() @@ -165,11 +172,11 @@ public class ParameterTableComponent extends MarkupComponent inlineDefinitions; - public Parameters(PathOperation operation, + public Parameters(SwaggerPathOperation operation, List inlineDefinitions, int titleLevel) { this.operation = Validate.notNull(operation, "PathOperation must not be null"); diff --git a/swagger2markup-core/src/main/java/io/github/swagger2markup/internal/component/PathOperationComponent.java b/swagger2markup/src/main/java/io/github/swagger2markup/internal/component/PathOperationComponent.java similarity index 88% rename from swagger2markup-core/src/main/java/io/github/swagger2markup/internal/component/PathOperationComponent.java rename to swagger2markup/src/main/java/io/github/swagger2markup/internal/component/PathOperationComponent.java index e5bff46e..75002da0 100644 --- a/swagger2markup-core/src/main/java/io/github/swagger2markup/internal/component/PathOperationComponent.java +++ b/swagger2markup/src/main/java/io/github/swagger2markup/internal/component/PathOperationComponent.java @@ -19,18 +19,18 @@ package io.github.swagger2markup.internal.component; import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -import io.github.swagger2markup.GroupBy; -import io.github.swagger2markup.PageBreakLocations; import io.github.swagger2markup.Swagger2MarkupConverter; +import io.github.swagger2markup.config.GroupBy; +import io.github.swagger2markup.config.PageBreakLocations; import io.github.swagger2markup.internal.resolver.DocumentResolver; import io.github.swagger2markup.internal.type.ObjectType; import io.github.swagger2markup.internal.utils.ExamplesUtil; import io.github.swagger2markup.markup.builder.MarkupAdmonition; import io.github.swagger2markup.markup.builder.MarkupBlockStyle; import io.github.swagger2markup.markup.builder.MarkupDocBuilder; -import io.github.swagger2markup.model.PathOperation; +import io.github.swagger2markup.markup.builder.MarkupLanguage; +import io.github.swagger2markup.model.SwaggerPathOperation; import io.github.swagger2markup.spi.MarkupComponent; -import io.github.swagger2markup.spi.PathsDocumentExtension; import io.swagger.models.Model; import io.swagger.util.Json; import org.apache.commons.collections4.CollectionUtils; @@ -42,10 +42,11 @@ import org.apache.commons.text.StringEscapeUtils; import java.util.*; import java.util.Map.Entry; -import static io.github.swagger2markup.Labels.*; -import static io.github.swagger2markup.PageBreakLocations.*; +import static io.github.swagger2markup.SwaggerLabels.*; +import static io.github.swagger2markup.SwaggerPageBreakLocations.*; import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.copyMarkupDocBuilder; import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.markupDescription; +import static io.github.swagger2markup.spi.PathsDocumentExtension.Context; import static io.github.swagger2markup.spi.PathsDocumentExtension.Position; import static org.apache.commons.lang3.StringUtils.isNotBlank; @@ -61,11 +62,11 @@ public class PathOperationComponent extends MarkupComponent locations = config.getPageBreakLocations(); - applyPathsDocumentExtension(new PathsDocumentExtension.Context(Position.OPERATION_BEFORE, markupDocBuilder, operation)); + applyPathsDocumentExtension(new Context(Position.OPERATION_BEFORE, markupDocBuilder, operation)); if (locations.contains(BEFORE_OPERATION)) markupDocBuilder.pageBreak(); buildOperationTitle(markupDocBuilder, operation); - applyPathsDocumentExtension(new PathsDocumentExtension.Context(Position.OPERATION_BEGIN, markupDocBuilder, operation)); + applyPathsDocumentExtension(new Context(Position.OPERATION_BEGIN, markupDocBuilder, operation)); buildDeprecatedSection(markupDocBuilder, operation); if (locations.contains(BEFORE_OPERATION_DESCRIPTION)) markupDocBuilder.pageBreak(); @@ -98,13 +99,13 @@ public class PathOperationComponent extends MarkupComponent buildParametersSection(MarkupDocBuilder markupDocBuilder, PathOperation operation) { + private List buildParametersSection(MarkupDocBuilder markupDocBuilder, SwaggerPathOperation operation) { List inlineDefinitions = new ArrayList<>(); @@ -211,7 +212,7 @@ public class PathOperationComponent extends MarkupComponent buildBodyParameterSection(MarkupDocBuilder markupDocBuilder, PathOperation operation) { + private List buildBodyParameterSection(MarkupDocBuilder markupDocBuilder, SwaggerPathOperation operation) { List inlineDefinitions = new ArrayList<>(); bodyParameterComponent.apply(markupDocBuilder, BodyParameterComponent.parameters( @@ -222,7 +223,7 @@ public class PathOperationComponent extends MarkupComponent buildResponsesSection(MarkupDocBuilder markupDocBuilder, PathOperation operation) { + private List buildResponsesSection(MarkupDocBuilder markupDocBuilder, SwaggerPathOperation operation) { List inlineDefinitions = new ArrayList<>(); responseComponent.apply(markupDocBuilder, ResponseComponent.parameters( @@ -285,7 +286,7 @@ public class PathOperationComponent extends MarkupComponent consumes = operation.getOperation().getConsumes(); if (CollectionUtils.isNotEmpty(consumes)) { consumesComponent.apply(markupDocBuilder, ConsumesComponent.parameters(consumes, @@ -294,7 +295,7 @@ public class PathOperationComponent extends MarkupComponent produces = operation.getOperation().getProduces(); if (CollectionUtils.isNotEmpty(produces)) { producesComponent.apply(markupDocBuilder, ProducesComponent.parameters(produces, @@ -302,7 +303,7 @@ public class PathOperationComponent extends MarkupComponent tags = operation.getOperation().getTags(); if (CollectionUtils.isNotEmpty(tags)) { @@ -320,7 +321,7 @@ public class PathOperationComponent extends MarkupComponent locations) { + private void buildExamplesSection(MarkupDocBuilder markupDocBuilder, SwaggerPathOperation operation, List locations) { Map generatedRequestExampleMap = ExamplesUtil.generateRequestExampleMap(config.isGeneratedExamplesEnabled(), operation, definitions, definitionDocumentResolver, markupDocBuilder); Map generatedResponseExampleMap = ExamplesUtil.generateResponseExampleMap(config.isGeneratedExamplesEnabled(), operation, definitions, definitionDocumentResolver, markupDocBuilder); @@ -495,15 +496,15 @@ public class PathOperationComponent extends MarkupComponent extension.apply(context)); } public static class Parameters { - private final PathOperation operation; + private final SwaggerPathOperation operation; - public Parameters(PathOperation operation) { + public Parameters(SwaggerPathOperation operation) { this.operation = Validate.notNull(operation, "PathOperation must not be null"); } } diff --git a/swagger2markup-core/src/main/java/io/github/swagger2markup/internal/component/ProducesComponent.java b/swagger2markup/src/main/java/io/github/swagger2markup/internal/component/ProducesComponent.java similarity index 92% rename from swagger2markup-core/src/main/java/io/github/swagger2markup/internal/component/ProducesComponent.java rename to swagger2markup/src/main/java/io/github/swagger2markup/internal/component/ProducesComponent.java index 7eaa73d8..2ae25b6d 100644 --- a/swagger2markup-core/src/main/java/io/github/swagger2markup/internal/component/ProducesComponent.java +++ b/swagger2markup/src/main/java/io/github/swagger2markup/internal/component/ProducesComponent.java @@ -16,8 +16,8 @@ package io.github.swagger2markup.internal.component; -import io.github.swagger2markup.Labels; import io.github.swagger2markup.Swagger2MarkupConverter; +import io.github.swagger2markup.SwaggerLabels; import io.github.swagger2markup.markup.builder.MarkupDocBuilder; import io.github.swagger2markup.spi.MarkupComponent; import org.apache.commons.lang3.Validate; @@ -30,7 +30,7 @@ import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.lite public class ProducesComponent extends MarkupComponent { - public ProducesComponent(Swagger2MarkupConverter.Context context) { + public ProducesComponent(Swagger2MarkupConverter.SwaggerContext context) { super(context); } @@ -41,7 +41,7 @@ public class ProducesComponent extends MarkupComponent literalText(markupDocBuilder, value)).collect(Collectors.toList())); return markupDocBuilder; diff --git a/swagger2markup-core/src/main/java/io/github/swagger2markup/internal/component/PropertiesTableComponent.java b/swagger2markup/src/main/java/io/github/swagger2markup/internal/component/PropertiesTableComponent.java similarity index 96% rename from swagger2markup-core/src/main/java/io/github/swagger2markup/internal/component/PropertiesTableComponent.java rename to swagger2markup/src/main/java/io/github/swagger2markup/internal/component/PropertiesTableComponent.java index f3e852ca..3d2e3cae 100755 --- a/swagger2markup-core/src/main/java/io/github/swagger2markup/internal/component/PropertiesTableComponent.java +++ b/swagger2markup/src/main/java/io/github/swagger2markup/internal/component/PropertiesTableComponent.java @@ -24,6 +24,7 @@ import io.github.swagger2markup.internal.type.ObjectType; import io.github.swagger2markup.internal.type.RefType; import io.github.swagger2markup.internal.type.Type; import io.github.swagger2markup.markup.builder.MarkupDocBuilder; +import io.github.swagger2markup.markup.builder.MarkupLanguage; import io.github.swagger2markup.spi.MarkupComponent; import io.swagger.models.properties.Property; import io.swagger.util.Json; @@ -37,7 +38,7 @@ import java.util.List; import java.util.Map; import java.util.Optional; -import static io.github.swagger2markup.Labels.*; +import static io.github.swagger2markup.SwaggerLabels.*; import static io.github.swagger2markup.internal.utils.InlineSchemaUtils.createInlineType; import static io.github.swagger2markup.internal.utils.MapUtils.toSortedMap; import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.copyMarkupDocBuilder; @@ -56,7 +57,7 @@ public class PropertiesTableComponent extends MarkupComponent definitions; private final DocumentResolver definitionDocumentResolver; - ResponseComponent(Swagger2MarkupConverter.Context context, + ResponseComponent(Swagger2MarkupConverter.SwaggerContext context, DocumentResolver definitionDocumentResolver) { super(context); - this.definitions = context.getSwagger().getDefinitions(); + this.definitions = context.getSchema().getDefinitions(); this.definitionDocumentResolver = Validate.notNull(definitionDocumentResolver, "DocumentResolver must not be null"); this.tableComponent = new TableComponent(context); } - public static ResponseComponent.Parameters parameters(PathOperation operation, + public static ResponseComponent.Parameters parameters(SwaggerPathOperation operation, int titleLevel, List inlineDefinitions) { return new ResponseComponent.Parameters(operation, titleLevel, inlineDefinitions); @@ -68,7 +69,7 @@ public class ResponseComponent extends MarkupComponent responses = operation.getOperation().getResponses(); MarkupDocBuilder responsesBuilder = copyMarkupDocBuilder(markupDocBuilder); @@ -105,7 +106,8 @@ public class ResponseComponent extends MarkupComponent headers = response.getHeaders(); if (MapUtils.isNotEmpty(headers)) { @@ -115,7 +117,8 @@ public class ResponseComponent extends MarkupComponent optionalDefaultValue = headerPropertyAdapter.getDefaultValue(); descriptionBuilder @@ -168,11 +171,11 @@ public class ResponseComponent extends MarkupComponent inlineDefinitions; - public Parameters(PathOperation operation, + public Parameters(SwaggerPathOperation operation, int titleLevel, List inlineDefinitions) { diff --git a/swagger2markup-core/src/main/java/io/github/swagger2markup/internal/component/SecuritySchemeComponent.java b/swagger2markup/src/main/java/io/github/swagger2markup/internal/component/SecuritySchemeComponent.java similarity index 92% rename from swagger2markup-core/src/main/java/io/github/swagger2markup/internal/component/SecuritySchemeComponent.java rename to swagger2markup/src/main/java/io/github/swagger2markup/internal/component/SecuritySchemeComponent.java index 16405310..43875c8f 100644 --- a/swagger2markup-core/src/main/java/io/github/swagger2markup/internal/component/SecuritySchemeComponent.java +++ b/swagger2markup/src/main/java/io/github/swagger2markup/internal/component/SecuritySchemeComponent.java @@ -21,7 +21,7 @@ import com.google.common.base.Joiner; import io.github.swagger2markup.Swagger2MarkupConverter; import io.github.swagger2markup.internal.resolver.DocumentResolver; import io.github.swagger2markup.markup.builder.MarkupDocBuilder; -import io.github.swagger2markup.model.PathOperation; +import io.github.swagger2markup.model.SwaggerPathOperation; import io.github.swagger2markup.spi.MarkupComponent; import io.github.swagger2markup.spi.PathsDocumentExtension; import io.swagger.models.auth.SecuritySchemeDefinition; @@ -32,7 +32,7 @@ import java.util.List; import java.util.Map; import static ch.netzwerg.paleo.ColumnIds.StringColumnId; -import static io.github.swagger2markup.Labels.*; +import static io.github.swagger2markup.SwaggerLabels.*; import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.*; import static org.apache.commons.lang3.StringUtils.isNotBlank; @@ -42,22 +42,22 @@ public class SecuritySchemeComponent extends MarkupComponent>> securitySchemes = operation.getOperation().getSecurity(); applyPathsDocumentExtension(new PathsDocumentExtension.Context(PathsDocumentExtension.Position.OPERATION_SECURITY_BEGIN, securityBuilder, operation)); @@ -111,10 +111,10 @@ public class SecuritySchemeComponent extends MarkupComponent extension.apply(context)); } diff --git a/swagger2markup-core/src/main/java/io/github/swagger2markup/internal/component/TableComponent.java b/swagger2markup/src/main/java/io/github/swagger2markup/internal/component/TableComponent.java similarity index 97% rename from swagger2markup-core/src/main/java/io/github/swagger2markup/internal/component/TableComponent.java rename to swagger2markup/src/main/java/io/github/swagger2markup/internal/component/TableComponent.java index 8e206e6f..f6d65966 100644 --- a/swagger2markup-core/src/main/java/io/github/swagger2markup/internal/component/TableComponent.java +++ b/swagger2markup/src/main/java/io/github/swagger2markup/internal/component/TableComponent.java @@ -33,7 +33,7 @@ public class TableComponent extends MarkupComponent { public static final String WIDTH_RATIO = "widthRatio"; public static final String HEADER_COLUMN = "headerColumn"; - public TableComponent(Swagger2MarkupConverter.Context context) { + public TableComponent(Swagger2MarkupConverter.SwaggerContext context) { super(context); } diff --git a/swagger2markup-core/src/main/java/io/github/swagger2markup/internal/component/TagsComponent.java b/swagger2markup/src/main/java/io/github/swagger2markup/internal/component/TagsComponent.java similarity index 94% rename from swagger2markup-core/src/main/java/io/github/swagger2markup/internal/component/TagsComponent.java rename to swagger2markup/src/main/java/io/github/swagger2markup/internal/component/TagsComponent.java index 4372389a..cc5c81a4 100644 --- a/swagger2markup-core/src/main/java/io/github/swagger2markup/internal/component/TagsComponent.java +++ b/swagger2markup/src/main/java/io/github/swagger2markup/internal/component/TagsComponent.java @@ -16,8 +16,8 @@ package io.github.swagger2markup.internal.component; -import io.github.swagger2markup.Labels; import io.github.swagger2markup.Swagger2MarkupConverter; +import io.github.swagger2markup.SwaggerLabels; import io.github.swagger2markup.markup.builder.MarkupDocBuilder; import io.github.swagger2markup.spi.MarkupComponent; import io.swagger.models.Tag; @@ -31,7 +31,7 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank; public class TagsComponent extends MarkupComponent { - public TagsComponent(Swagger2MarkupConverter.Context context) { + public TagsComponent(Swagger2MarkupConverter.SwaggerContext context) { super(context); } @@ -42,7 +42,7 @@ public class TagsComponent extends MarkupComponent { @Override public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, Parameters params) { - markupDocBuilder.sectionTitleLevel(params.titleLevel, labels.getLabel(Labels.TAGS)); + markupDocBuilder.sectionTitleLevel(params.titleLevel, labels.getLabel(SwaggerLabels.TAGS)); List tagsList = params.tags.stream() .map(this::mapToString).collect(Collectors.toList()); diff --git a/swagger2markup-core/src/main/java/io/github/swagger2markup/internal/component/UriSchemeComponent.java b/swagger2markup/src/main/java/io/github/swagger2markup/internal/component/UriSchemeComponent.java similarity index 87% rename from swagger2markup-core/src/main/java/io/github/swagger2markup/internal/component/UriSchemeComponent.java rename to swagger2markup/src/main/java/io/github/swagger2markup/internal/component/UriSchemeComponent.java index 1257e24c..2f5ee3b2 100644 --- a/swagger2markup-core/src/main/java/io/github/swagger2markup/internal/component/UriSchemeComponent.java +++ b/swagger2markup/src/main/java/io/github/swagger2markup/internal/component/UriSchemeComponent.java @@ -15,8 +15,8 @@ */ package io.github.swagger2markup.internal.component; -import io.github.swagger2markup.Labels; import io.github.swagger2markup.Swagger2MarkupConverter; +import io.github.swagger2markup.SwaggerLabels; import io.github.swagger2markup.markup.builder.MarkupDocBuilder; import io.github.swagger2markup.spi.MarkupComponent; import io.swagger.models.Swagger; @@ -33,7 +33,7 @@ import static org.apache.commons.lang3.StringUtils.join; public class UriSchemeComponent extends MarkupComponent { - public UriSchemeComponent(Swagger2MarkupConverter.Context context) { + public UriSchemeComponent(Swagger2MarkupConverter.SwaggerContext context) { super(context); } @@ -45,21 +45,21 @@ public class UriSchemeComponent extends MarkupComponent schemes = swagger.getSchemes().stream() .map(Enum::toString) .collect(Collectors.toList()); - paragraphBuilder.italicText(labels.getLabel(Labels.SCHEMES)) + paragraphBuilder.italicText(labels.getLabel(SwaggerLabels.SCHEMES)) .textLine(COLON + join(schemes, ", ")); } markupDocBuilder.paragraph(paragraphBuilder.toString(), true); diff --git a/swagger2markup-core/src/main/java/io/github/swagger2markup/internal/component/VersionInfoComponent.java b/swagger2markup/src/main/java/io/github/swagger2markup/internal/component/VersionInfoComponent.java similarity index 88% rename from swagger2markup-core/src/main/java/io/github/swagger2markup/internal/component/VersionInfoComponent.java rename to swagger2markup/src/main/java/io/github/swagger2markup/internal/component/VersionInfoComponent.java index 77f72b43..f090d4da 100644 --- a/swagger2markup-core/src/main/java/io/github/swagger2markup/internal/component/VersionInfoComponent.java +++ b/swagger2markup/src/main/java/io/github/swagger2markup/internal/component/VersionInfoComponent.java @@ -15,8 +15,8 @@ */ package io.github.swagger2markup.internal.component; -import io.github.swagger2markup.Labels; import io.github.swagger2markup.Swagger2MarkupConverter; +import io.github.swagger2markup.SwaggerLabels; import io.github.swagger2markup.markup.builder.MarkupDocBuilder; import io.github.swagger2markup.spi.MarkupComponent; import io.swagger.models.Info; @@ -28,7 +28,7 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank; public class VersionInfoComponent extends MarkupComponent { - public VersionInfoComponent(Swagger2MarkupConverter.Context context) { + public VersionInfoComponent(Swagger2MarkupConverter.SwaggerContext context) { super(context); } @@ -41,9 +41,9 @@ public class VersionInfoComponent extends MarkupComponent definitions = params.definitions; if (MapUtils.isNotEmpty(definitions)) { applyDefinitionsDocumentExtension(new Context(Position.DOCUMENT_BEFORE, markupDocBuilder)); - buildDefinitionsTitle(markupDocBuilder, labels.getLabel(Labels.DEFINITIONS)); + buildDefinitionsTitle(markupDocBuilder, labels.getLabel(SwaggerLabels.DEFINITIONS)); applyDefinitionsDocumentExtension(new Context(Position.DOCUMENT_BEGIN, markupDocBuilder)); buildDefinitionsSection(markupDocBuilder, definitions); applyDefinitionsDocumentExtension(new Context(Position.DOCUMENT_END, markupDocBuilder)); diff --git a/swagger2markup-core/src/main/java/io/github/swagger2markup/internal/document/OverviewDocument.java b/swagger2markup/src/main/java/io/github/swagger2markup/internal/document/OverviewDocument.java similarity index 93% rename from swagger2markup-core/src/main/java/io/github/swagger2markup/internal/document/OverviewDocument.java rename to swagger2markup/src/main/java/io/github/swagger2markup/internal/document/OverviewDocument.java index 660540c1..a65e13e8 100644 --- a/swagger2markup-core/src/main/java/io/github/swagger2markup/internal/document/OverviewDocument.java +++ b/swagger2markup/src/main/java/io/github/swagger2markup/internal/document/OverviewDocument.java @@ -15,18 +15,19 @@ */ package io.github.swagger2markup.internal.document; -import io.github.swagger2markup.Labels; import io.github.swagger2markup.Swagger2MarkupConverter; +import io.github.swagger2markup.SwaggerLabels; import io.github.swagger2markup.internal.component.*; import io.github.swagger2markup.markup.builder.MarkupDocBuilder; +import io.github.swagger2markup.markup.builder.MarkupLanguage; import io.github.swagger2markup.spi.MarkupComponent; +import io.github.swagger2markup.spi.OverviewDocumentExtension.Context; import io.swagger.models.*; import org.apache.commons.lang3.Validate; import java.util.List; import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.markupDescription; -import static io.github.swagger2markup.spi.OverviewDocumentExtension.Context; import static io.github.swagger2markup.spi.OverviewDocumentExtension.Position; import static org.apache.commons.collections4.CollectionUtils.isNotEmpty; import static org.apache.commons.lang3.StringUtils.isNotBlank; @@ -44,7 +45,7 @@ public class OverviewDocument extends MarkupComponent { private final OperationDocumentNameResolver operationDocumentNameResolver; private final OperationDocumentResolverDefault operationDocumentResolverDefault; - public PathsDocument(Swagger2MarkupConverter.Context context) { + public PathsDocument(SwaggerContext context) { super(context); this.pathOperationComponent = new PathOperationComponent(context, new DefinitionDocumentResolverFromOperation(context), @@ -113,16 +114,16 @@ public class PathsDocument extends MarkupComponent { * @param paths the Swagger paths */ private void buildsPathsSection(MarkupDocBuilder markupDocBuilder, Map paths) { - List pathOperations = PathUtils.toPathOperationsList(paths, getHostname(), getBasePath(), config.getOperationOrdering()); + List pathOperations = PathUtils.toPathOperationsList(paths, getHostname(), getBasePath(), config.getOperationOrdering()); if (CollectionUtils.isNotEmpty(pathOperations)) { if (config.getPathsGroupedBy() == GroupBy.AS_IS) { pathOperations.forEach(operation -> buildOperation(markupDocBuilder, operation, config)); } else if (config.getPathsGroupedBy() == GroupBy.TAGS) { - Validate.notEmpty(context.getSwagger().getTags(), "Tags must not be empty, when operations are grouped by tags"); + Validate.notEmpty(context.getSchema().getTags(), "Tags must not be empty, when operations are grouped by tags"); // Group operations by tag - Multimap operationsGroupedByTag = TagUtils.groupOperationsByTag(pathOperations, config.getOperationOrdering()); + Multimap operationsGroupedByTag = TagUtils.groupOperationsByTag(pathOperations, config.getOperationOrdering()); - Map tagsMap = TagUtils.toSortedMap(context.getSwagger().getTags(), config.getTagOrdering()); + Map tagsMap = TagUtils.toSortedMap(context.getSchema().getTags(), config.getTagOrdering()); tagsMap.forEach((String tagName, Tag tag) -> { markupDocBuilder.sectionTitleWithAnchorLevel2(WordUtils.capitalize(tagName), tagName + "_resource"); @@ -137,7 +138,7 @@ public class PathsDocument extends MarkupComponent { Validate.notNull(config.getHeaderPattern(), "Header regex pattern must not be empty when operations are grouped using regex"); Pattern headerPattern = config.getHeaderPattern(); - Multimap operationsGroupedByRegex = RegexUtils.groupOperationsByRegex(pathOperations, headerPattern); + Multimap operationsGroupedByRegex = RegexUtils.groupOperationsByRegex(pathOperations, headerPattern); Set keys = operationsGroupedByRegex.keySet(); String[] sortedHeaders = RegexUtils.toSortedArray(keys); @@ -154,11 +155,11 @@ public class PathsDocument extends MarkupComponent { */ private void buildPathsTitle(MarkupDocBuilder markupDocBuilder) { if (config.getPathsGroupedBy() == GroupBy.AS_IS) { - buildPathsTitle(markupDocBuilder, labels.getLabel(Labels.PATHS)); + buildPathsTitle(markupDocBuilder, labels.getLabel(SwaggerLabels.PATHS)); } else if (config.getPathsGroupedBy() == GroupBy.REGEX) { - buildPathsTitle(markupDocBuilder, labels.getLabel(Labels.OPERATIONS)); + buildPathsTitle(markupDocBuilder, labels.getLabel(SwaggerLabels.OPERATIONS)); } else { - buildPathsTitle(markupDocBuilder, labels.getLabel(Labels.RESOURCES)); + buildPathsTitle(markupDocBuilder, labels.getLabel(SwaggerLabels.RESOURCES)); } } @@ -169,7 +170,7 @@ public class PathsDocument extends MarkupComponent { */ private String getHostname() { if (config.isHostnameEnabled()) { - return StringUtils.defaultString(context.getSwagger().getHost()); + return StringUtils.defaultString(context.getSchema().getHost()); } return ""; } @@ -181,7 +182,7 @@ public class PathsDocument extends MarkupComponent { */ private String getBasePath() { if (config.isBasePathPrefixEnabled()) { - return StringUtils.defaultString(context.getSwagger().getBasePath()); + return StringUtils.defaultString(context.getSchema().getBasePath()); } return ""; } @@ -204,7 +205,7 @@ public class PathsDocument extends MarkupComponent { * * @param operation operation */ - private void buildOperation(MarkupDocBuilder markupDocBuilder, PathOperation operation, Swagger2MarkupConfig config) { + private void buildOperation(MarkupDocBuilder markupDocBuilder, SwaggerPathOperation operation, Swagger2MarkupConfig config) { if (config.isSeparatedOperationsEnabled()) { MarkupDocBuilder pathDocBuilder = copyMarkupDocBuilder(markupDocBuilder); applyPathOperationComponent(pathDocBuilder, operation); @@ -230,7 +231,7 @@ public class PathsDocument extends MarkupComponent { * @param markupDocBuilder the docbuilder do use for output * @param operation the Swagger Operation */ - private void applyPathOperationComponent(MarkupDocBuilder markupDocBuilder, PathOperation operation) { + private void applyPathOperationComponent(MarkupDocBuilder markupDocBuilder, SwaggerPathOperation operation) { if (operation != null) { pathOperationComponent.apply(markupDocBuilder, PathOperationComponent.parameters(operation)); } @@ -243,7 +244,8 @@ public class PathsDocument extends MarkupComponent { * @param operation the Swagger Operation */ private void buildOperationRef(MarkupDocBuilder markupDocBuilder, PathOperation operation) { - buildOperationTitle(markupDocBuilder, crossReference(markupDocBuilder, operationDocumentResolverDefault.apply(operation), operation.getId(), operation.getTitle()), "ref-" + operation.getId()); + buildOperationTitle(markupDocBuilder, crossReference(markupDocBuilder, operationDocumentResolverDefault.apply(operation), + operation.getId(), operation.getTitle()), "ref-" + operation.getId()); } /** diff --git a/swagger2markup-core/src/main/java/io/github/swagger2markup/internal/document/SecurityDocument.java b/swagger2markup/src/main/java/io/github/swagger2markup/internal/document/SecurityDocument.java similarity index 95% rename from swagger2markup-core/src/main/java/io/github/swagger2markup/internal/document/SecurityDocument.java rename to swagger2markup/src/main/java/io/github/swagger2markup/internal/document/SecurityDocument.java index 664b4f1f..770671a4 100644 --- a/swagger2markup-core/src/main/java/io/github/swagger2markup/internal/document/SecurityDocument.java +++ b/swagger2markup/src/main/java/io/github/swagger2markup/internal/document/SecurityDocument.java @@ -19,14 +19,14 @@ import io.github.swagger2markup.Swagger2MarkupConverter; import io.github.swagger2markup.internal.component.SecuritySchemeDefinitionComponent; import io.github.swagger2markup.markup.builder.MarkupDocBuilder; import io.github.swagger2markup.spi.MarkupComponent; +import io.github.swagger2markup.spi.SecurityDocumentExtension.Context; import io.swagger.models.auth.SecuritySchemeDefinition; import org.apache.commons.collections4.MapUtils; import java.util.Map; -import static io.github.swagger2markup.Labels.SECURITY; +import static io.github.swagger2markup.SwaggerLabels.SECURITY; import static io.github.swagger2markup.internal.utils.MapUtils.toSortedMap; -import static io.github.swagger2markup.spi.SecurityDocumentExtension.Context; import static io.github.swagger2markup.spi.SecurityDocumentExtension.Position; /** @@ -37,7 +37,7 @@ public class SecurityDocument extends MarkupComponent { MarkupDocBuilder markupDocBuilder; Swagger2MarkupConfig config; - public DocumentResolver(Swagger2MarkupConverter.Context context) { + public DocumentResolver(Swagger2MarkupConverter.SwaggerContext context) { this.context = context; this.markupDocBuilder = context.createMarkupDocBuilder(); this.config = context.getConfig(); diff --git a/swagger2markup-core/src/main/java/io/github/swagger2markup/internal/resolver/OperationDocumentNameResolver.java b/swagger2markup/src/main/java/io/github/swagger2markup/internal/resolver/OperationDocumentNameResolver.java similarity index 98% rename from swagger2markup-core/src/main/java/io/github/swagger2markup/internal/resolver/OperationDocumentNameResolver.java rename to swagger2markup/src/main/java/io/github/swagger2markup/internal/resolver/OperationDocumentNameResolver.java index 9def66a6..7f580b5a 100644 --- a/swagger2markup-core/src/main/java/io/github/swagger2markup/internal/resolver/OperationDocumentNameResolver.java +++ b/swagger2markup/src/main/java/io/github/swagger2markup/internal/resolver/OperationDocumentNameResolver.java @@ -25,7 +25,7 @@ import static io.github.swagger2markup.utils.IOUtils.normalizeName; public class OperationDocumentNameResolver extends OperationDocumentResolver { - public OperationDocumentNameResolver(Swagger2MarkupConverter.Context context) { + public OperationDocumentNameResolver(Swagger2MarkupConverter.SwaggerContext context) { super(context); } diff --git a/swagger2markup-core/src/main/java/io/github/swagger2markup/internal/resolver/OperationDocumentResolver.java b/swagger2markup/src/main/java/io/github/swagger2markup/internal/resolver/OperationDocumentResolver.java similarity index 88% rename from swagger2markup-core/src/main/java/io/github/swagger2markup/internal/resolver/OperationDocumentResolver.java rename to swagger2markup/src/main/java/io/github/swagger2markup/internal/resolver/OperationDocumentResolver.java index 61095dbf..a99c8352 100644 --- a/swagger2markup-core/src/main/java/io/github/swagger2markup/internal/resolver/OperationDocumentResolver.java +++ b/swagger2markup/src/main/java/io/github/swagger2markup/internal/resolver/OperationDocumentResolver.java @@ -16,8 +16,8 @@ package io.github.swagger2markup.internal.resolver; -import io.github.swagger2markup.Swagger2MarkupConfig; import io.github.swagger2markup.Swagger2MarkupConverter; +import io.github.swagger2markup.builder.Swagger2MarkupConfigBuilder.Swagger2MarkupConfig; import io.github.swagger2markup.markup.builder.MarkupDocBuilder; import io.github.swagger2markup.model.PathOperation; import io.vavr.Function1; @@ -31,7 +31,7 @@ public abstract class OperationDocumentResolver implements Function1 generateResponseExampleMap(boolean generateMissingExamples, PathOperation operation, Map definitions, DocumentResolver definitionDocumentResolver, MarkupDocBuilder markupDocBuilder) { + public static Map generateResponseExampleMap(boolean generateMissingExamples, SwaggerPathOperation operation, Map definitions, DocumentResolver definitionDocumentResolver, MarkupDocBuilder markupDocBuilder) { Map examples = new LinkedHashMap<>(); Map responses = operation.getOperation().getResponses(); if (responses != null) @@ -97,7 +97,7 @@ public class ExamplesUtil { * @param markupDocBuilder the markup builder * @return an Optional with the example content */ - public static Map generateRequestExampleMap(boolean generateMissingExamples, PathOperation pathOperation, Map definitions, DocumentResolver definitionDocumentResolver, MarkupDocBuilder markupDocBuilder) { + public static Map generateRequestExampleMap(boolean generateMissingExamples, SwaggerPathOperation pathOperation, Map definitions, DocumentResolver definitionDocumentResolver, MarkupDocBuilder markupDocBuilder) { Operation operation = pathOperation.getOperation(); List parameters = operation.getParameters(); Map examples = new LinkedHashMap<>(); diff --git a/swagger2markup-core/src/main/java/io/github/swagger2markup/internal/utils/InlineSchemaUtils.java b/swagger2markup/src/main/java/io/github/swagger2markup/internal/utils/InlineSchemaUtils.java similarity index 100% rename from swagger2markup-core/src/main/java/io/github/swagger2markup/internal/utils/InlineSchemaUtils.java rename to swagger2markup/src/main/java/io/github/swagger2markup/internal/utils/InlineSchemaUtils.java diff --git a/swagger2markup-core/src/main/java/io/github/swagger2markup/internal/utils/MapUtils.java b/swagger2markup/src/main/java/io/github/swagger2markup/internal/utils/MapUtils.java similarity index 100% rename from swagger2markup-core/src/main/java/io/github/swagger2markup/internal/utils/MapUtils.java rename to swagger2markup/src/main/java/io/github/swagger2markup/internal/utils/MapUtils.java diff --git a/swagger2markup-core/src/main/java/io/github/swagger2markup/internal/utils/MarkupDocBuilderUtils.java b/swagger2markup/src/main/java/io/github/swagger2markup/internal/utils/MarkupDocBuilderUtils.java similarity index 100% rename from swagger2markup-core/src/main/java/io/github/swagger2markup/internal/utils/MarkupDocBuilderUtils.java rename to swagger2markup/src/main/java/io/github/swagger2markup/internal/utils/MarkupDocBuilderUtils.java diff --git a/swagger2markup-core/src/main/java/io/github/swagger2markup/internal/utils/ModelUtils.java b/swagger2markup/src/main/java/io/github/swagger2markup/internal/utils/ModelUtils.java similarity index 100% rename from swagger2markup-core/src/main/java/io/github/swagger2markup/internal/utils/ModelUtils.java rename to swagger2markup/src/main/java/io/github/swagger2markup/internal/utils/ModelUtils.java diff --git a/swagger2markup-core/src/main/java/io/github/swagger2markup/internal/utils/PathUtils.java b/swagger2markup/src/main/java/io/github/swagger2markup/internal/utils/PathUtils.java similarity index 70% rename from swagger2markup-core/src/main/java/io/github/swagger2markup/internal/utils/PathUtils.java rename to swagger2markup/src/main/java/io/github/swagger2markup/internal/utils/PathUtils.java index 5721458a..12f7cb61 100644 --- a/swagger2markup-core/src/main/java/io/github/swagger2markup/internal/utils/PathUtils.java +++ b/swagger2markup/src/main/java/io/github/swagger2markup/internal/utils/PathUtils.java @@ -16,12 +16,15 @@ package io.github.swagger2markup.internal.utils; import io.github.swagger2markup.model.PathOperation; +import io.github.swagger2markup.model.SwaggerPathOperation; import io.swagger.models.HttpMethod; import io.swagger.models.Operation; import io.swagger.models.Path; import java.util.*; +import static org.apache.commons.lang3.StringUtils.isBlank; + public class PathUtils { /** @@ -67,11 +70,11 @@ public class PathUtils { * @param comparator the comparator to use. * @return the path operations */ - public static List toPathOperationsList(Map paths, - String host, - String basePath, - Comparator comparator) { - List pathOperations = new ArrayList<>(); + public static List toPathOperationsList(Map paths, + String host, + String basePath, + Comparator comparator) { + List pathOperations = new ArrayList<>(); paths.forEach((relativePath, path) -> pathOperations.addAll(toPathOperationsList(host + basePath + relativePath, path))); @@ -88,10 +91,19 @@ public class PathUtils { * @param pathModel the Swagger Path model * @return the path operations */ - public static List toPathOperationsList(String path, Path pathModel) { - List pathOperations = new ArrayList<>(); - getOperationMap(pathModel).forEach((httpMethod, operation) -> - pathOperations.add(new PathOperation(httpMethod, path, operation))); + public static List toPathOperationsList(String path, Path pathModel) { + List pathOperations = new ArrayList<>(); + getOperationMap(pathModel).forEach((httpMethod, operation) -> { + String id = operation.getOperationId(); + if (id == null) + id = path + " " + httpMethod.toString().toLowerCase(); + + String operationName = operation.getSummary(); + if (isBlank(operationName)) { + operationName = httpMethod.toString() + " " + path; + } + pathOperations.add(new SwaggerPathOperation(httpMethod.name(), path, id, operationName, operation)); + }); return pathOperations; } } diff --git a/swagger2markup-core/src/main/java/io/github/swagger2markup/internal/utils/RegexUtils.java b/swagger2markup/src/main/java/io/github/swagger2markup/internal/utils/RegexUtils.java similarity index 86% rename from swagger2markup-core/src/main/java/io/github/swagger2markup/internal/utils/RegexUtils.java rename to swagger2markup/src/main/java/io/github/swagger2markup/internal/utils/RegexUtils.java index ed9f99c1..698ac39b 100644 --- a/swagger2markup-core/src/main/java/io/github/swagger2markup/internal/utils/RegexUtils.java +++ b/swagger2markup/src/main/java/io/github/swagger2markup/internal/utils/RegexUtils.java @@ -18,7 +18,7 @@ package io.github.swagger2markup.internal.utils; import com.google.common.collect.LinkedHashMultimap; import com.google.common.collect.Multimap; -import io.github.swagger2markup.model.PathOperation; +import io.github.swagger2markup.model.SwaggerPathOperation; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -55,12 +55,12 @@ public class RegexUtils { * @param headerPattern regex pattern used for determining headers * @return Operations grouped by regex */ - public static Multimap groupOperationsByRegex(List allOperations, Pattern headerPattern) { + public static Multimap groupOperationsByRegex(List allOperations, Pattern headerPattern) { - Multimap operationsGroupedByRegex = LinkedHashMultimap.create(); + Multimap operationsGroupedByRegex = LinkedHashMultimap.create(); - for (PathOperation operation : allOperations) { + for (SwaggerPathOperation operation : allOperations) { String path = operation.getPath(); Matcher m = headerPattern.matcher(path); diff --git a/swagger2markup-core/src/main/java/io/github/swagger2markup/internal/utils/TagUtils.java b/swagger2markup/src/main/java/io/github/swagger2markup/internal/utils/TagUtils.java similarity index 88% rename from swagger2markup-core/src/main/java/io/github/swagger2markup/internal/utils/TagUtils.java rename to swagger2markup/src/main/java/io/github/swagger2markup/internal/utils/TagUtils.java index 09715ff7..c120bb72 100644 --- a/swagger2markup-core/src/main/java/io/github/swagger2markup/internal/utils/TagUtils.java +++ b/swagger2markup/src/main/java/io/github/swagger2markup/internal/utils/TagUtils.java @@ -19,6 +19,7 @@ import com.google.common.collect.LinkedHashMultimap; import com.google.common.collect.Multimap; import com.google.common.collect.MultimapBuilder; import io.github.swagger2markup.model.PathOperation; +import io.github.swagger2markup.model.SwaggerPathOperation; import io.swagger.models.Tag; import org.apache.commons.lang3.Validate; import org.slf4j.Logger; @@ -56,15 +57,15 @@ public class TagUtils { * @param operationOrdering comparator for operations, for a given tag * @return Operations grouped by Tag */ - public static Multimap groupOperationsByTag(List allOperations, Comparator operationOrdering) { + public static Multimap groupOperationsByTag(List allOperations, Comparator operationOrdering) { - Multimap operationsGroupedByTag; + Multimap operationsGroupedByTag; if (operationOrdering == null) { operationsGroupedByTag = LinkedHashMultimap.create(); } else { operationsGroupedByTag = MultimapBuilder.linkedHashKeys().treeSetValues(operationOrdering).build(); } - for (PathOperation operation : allOperations) { + for (SwaggerPathOperation operation : allOperations) { List tags = operation.getOperation().getTags(); Validate.notEmpty(tags, "Can't GroupBy.TAGS. Operation '%s' has no tags", operation); diff --git a/swagger2markup/src/main/java/io/github/swagger2markup/model/SwaggerPathOperation.java b/swagger2markup/src/main/java/io/github/swagger2markup/model/SwaggerPathOperation.java new file mode 100644 index 00000000..a76a2748 --- /dev/null +++ b/swagger2markup/src/main/java/io/github/swagger2markup/model/SwaggerPathOperation.java @@ -0,0 +1,21 @@ +package io.github.swagger2markup.model; + +import io.swagger.models.Operation; + +public class SwaggerPathOperation extends PathOperation { + private Operation operation; + + public SwaggerPathOperation(String httpMethod, String path, String id, String title, Operation operation) { + super(httpMethod, path, id, title); + this.operation = operation; + } + + public Operation getOperation() { + return operation; + } + + @Override + public String toString() { + return getId(); + } +} diff --git a/swagger2markup-core/src/main/java/io/github/swagger2markup/spi/AbstractExtension.java b/swagger2markup/src/main/java/io/github/swagger2markup/spi/AbstractExtension.java similarity index 80% rename from swagger2markup-core/src/main/java/io/github/swagger2markup/spi/AbstractExtension.java rename to swagger2markup/src/main/java/io/github/swagger2markup/spi/AbstractExtension.java index 50bafe1f..151425ec 100644 --- a/swagger2markup-core/src/main/java/io/github/swagger2markup/spi/AbstractExtension.java +++ b/swagger2markup/src/main/java/io/github/swagger2markup/spi/AbstractExtension.java @@ -16,21 +16,21 @@ package io.github.swagger2markup.spi; -import io.github.swagger2markup.Swagger2MarkupConverter; +import static io.github.swagger2markup.Swagger2MarkupConverter.SwaggerContext; /** * An abstract extension which must be extended by an extension */ abstract class AbstractExtension implements Extension { - protected Swagger2MarkupConverter.Context globalContext; + public SwaggerContext globalContext; /** * Global context lazy initialization * * @param globalContext Global context */ - public void setGlobalContext(Swagger2MarkupConverter.Context globalContext) { + public void setGlobalContext(SwaggerContext globalContext) { this.globalContext = globalContext; init(globalContext); } @@ -40,8 +40,7 @@ abstract class AbstractExtension implements Extension { * * @param globalContext Global context */ - public void init(Swagger2MarkupConverter.Context globalContext) { + public void init(SwaggerContext globalContext) { /* must be left empty */ } - } diff --git a/swagger2markup-core/src/main/java/io/github/swagger2markup/spi/ContentContext.java b/swagger2markup/src/main/java/io/github/swagger2markup/spi/ContentContext.java similarity index 100% rename from swagger2markup-core/src/main/java/io/github/swagger2markup/spi/ContentContext.java rename to swagger2markup/src/main/java/io/github/swagger2markup/spi/ContentContext.java diff --git a/swagger2markup-core/src/main/java/io/github/swagger2markup/spi/DefinitionsDocumentExtension.java b/swagger2markup/src/main/java/io/github/swagger2markup/spi/DefinitionsDocumentExtension.java similarity index 100% rename from swagger2markup-core/src/main/java/io/github/swagger2markup/spi/DefinitionsDocumentExtension.java rename to swagger2markup/src/main/java/io/github/swagger2markup/spi/DefinitionsDocumentExtension.java diff --git a/swagger2markup-core/src/main/java/io/github/swagger2markup/spi/Extension.java b/swagger2markup/src/main/java/io/github/swagger2markup/spi/Extension.java similarity index 86% rename from swagger2markup-core/src/main/java/io/github/swagger2markup/spi/Extension.java rename to swagger2markup/src/main/java/io/github/swagger2markup/spi/Extension.java index 5fe4e51d..239f0786 100644 --- a/swagger2markup-core/src/main/java/io/github/swagger2markup/spi/Extension.java +++ b/swagger2markup/src/main/java/io/github/swagger2markup/spi/Extension.java @@ -16,7 +16,7 @@ package io.github.swagger2markup.spi; -import io.github.swagger2markup.Swagger2MarkupConverter; +import io.github.swagger2markup.Swagger2MarkupConverter.SwaggerContext; /** * A marker interface which must be implemented by an extension @@ -28,6 +28,6 @@ interface Extension { * * @param globalContext Global context */ - void setGlobalContext(Swagger2MarkupConverter.Context globalContext); + void setGlobalContext(SwaggerContext globalContext); } diff --git a/swagger2markup-core/src/main/java/io/github/swagger2markup/spi/MarkupComponent.java b/swagger2markup/src/main/java/io/github/swagger2markup/spi/MarkupComponent.java similarity index 83% rename from swagger2markup-core/src/main/java/io/github/swagger2markup/spi/MarkupComponent.java rename to swagger2markup/src/main/java/io/github/swagger2markup/spi/MarkupComponent.java index 5ec95063..fc765818 100644 --- a/swagger2markup-core/src/main/java/io/github/swagger2markup/spi/MarkupComponent.java +++ b/swagger2markup/src/main/java/io/github/swagger2markup/spi/MarkupComponent.java @@ -16,10 +16,9 @@ package io.github.swagger2markup.spi; -import io.github.swagger2markup.Labels; -import io.github.swagger2markup.Swagger2MarkupConfig; import io.github.swagger2markup.Swagger2MarkupConverter; -import io.github.swagger2markup.Swagger2MarkupExtensionRegistry; +import io.github.swagger2markup.builder.Swagger2MarkupConfigBuilder.Swagger2MarkupConfig; +import io.github.swagger2markup.config.Labels; import io.github.swagger2markup.markup.builder.MarkupDocBuilder; import io.vavr.Function2; import org.slf4j.Logger; @@ -29,12 +28,12 @@ public abstract class MarkupComponent implements Function2 configMap = new HashMap<>(); configMap.put("swagger2markup.generatedExamplesEnabled", "true"); // enable examples generation //When - Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder(configMap) + Swagger2MarkupConfig config = (Swagger2MarkupConfig) new Swagger2MarkupConfigBuilder(configMap) .withMarkupLanguage(MarkupLanguage.ASCIIDOC) .build(); Swagger2MarkupConverter.from(file) @@ -751,7 +755,7 @@ public class AsciidocConverterTest { FileUtils.deleteQuietly(outputDirectory.toFile()); //When - Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() + Swagger2MarkupConfig config = (Swagger2MarkupConfig) new Swagger2MarkupConfigBuilder() .withPropertyOrdering(OrderBy.AS_IS) .build(); Swagger2MarkupConverter.from(file) @@ -844,8 +848,8 @@ public class AsciidocConverterTest { FileUtils.deleteQuietly(outputDirectory.toFile()); //When - Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() - .withPageBreaks(new ArrayList<>(asList(PageBreakLocations.BEFORE_OPERATION, PageBreakLocations.BEFORE_OPERATION_EXAMPLE_REQUEST))) + Swagger2MarkupConfig config = (Swagger2MarkupConfig) new Swagger2MarkupConfigBuilder() + .withPageBreaks(new ArrayList<>(asList(SwaggerPageBreakLocations.BEFORE_OPERATION, SwaggerPageBreakLocations.BEFORE_OPERATION_EXAMPLE_REQUEST))) .build(); Swagger2MarkupConverter.from(swaggerJsonString) @@ -868,8 +872,8 @@ public class AsciidocConverterTest { FileUtils.deleteQuietly(outputDirectory.toFile()); //When - Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() - .withPageBreaks(new ArrayList<>(asList(PageBreakLocations.BEFORE_OPERATION, PageBreakLocations.BEFORE_OPERATION_EXAMPLE_REQUEST))) + Swagger2MarkupConfig config = (Swagger2MarkupConfig) new Swagger2MarkupConfigBuilder() + .withPageBreaks(new ArrayList<>(asList(SwaggerPageBreakLocations.BEFORE_OPERATION, SwaggerPageBreakLocations.BEFORE_OPERATION_EXAMPLE_REQUEST))) .build(); Swagger2MarkupConverter.from(swaggerJsonString) @@ -892,8 +896,8 @@ public class AsciidocConverterTest { FileUtils.deleteQuietly(outputDirectory.toFile()); //When - Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() - .withPageBreaks(new ArrayList<>(asList(PageBreakLocations.BEFORE_OPERATION, PageBreakLocations.BEFORE_OPERATION_EXAMPLE_REQUEST))) + Swagger2MarkupConfig config = (Swagger2MarkupConfig) new Swagger2MarkupConfigBuilder() + .withPageBreaks(new ArrayList<>(asList(SwaggerPageBreakLocations.BEFORE_OPERATION, SwaggerPageBreakLocations.BEFORE_OPERATION_EXAMPLE_REQUEST))) .withGeneratedExamples() .build(); diff --git a/swagger2markup-core/src/test/java/io/github/swagger2markup/DocumentationTest.java b/swagger2markup/src/test/java/io/github/swagger2markup/DocumentationTest.java similarity index 93% rename from swagger2markup-core/src/test/java/io/github/swagger2markup/DocumentationTest.java rename to swagger2markup/src/test/java/io/github/swagger2markup/DocumentationTest.java index 4de44962..d74af712 100644 --- a/swagger2markup-core/src/test/java/io/github/swagger2markup/DocumentationTest.java +++ b/swagger2markup/src/test/java/io/github/swagger2markup/DocumentationTest.java @@ -17,8 +17,12 @@ package io.github.swagger2markup; import io.github.swagger2markup.builder.MyExtension; import io.github.swagger2markup.builder.Swagger2MarkupConfigBuilder; +import io.github.swagger2markup.builder.Swagger2MarkupConfigBuilder.Swagger2MarkupConfig; import io.github.swagger2markup.builder.Swagger2MarkupExtensionRegistryBuilder; +import io.github.swagger2markup.config.GroupBy; +import io.github.swagger2markup.config.Language; import io.github.swagger2markup.markup.builder.MarkupLanguage; +import io.github.swagger2markup.spi.Swagger2MarkupExtensionRegistry; import org.apache.commons.configuration2.Configuration; import org.apache.commons.configuration2.builder.fluent.Configurations; import org.apache.commons.configuration2.ex.ConfigurationException; @@ -84,8 +88,8 @@ public class DocumentationTest { Path localSwaggerFile = Paths.get("/path/to/swagger.yaml"); // tag::swagger2MarkupConfigBuilder[] - Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() //<1> - .withMarkupLanguage(MarkupLanguage.MARKDOWN) //<2> + Swagger2MarkupConfig config = (Swagger2MarkupConfig) new Swagger2MarkupConfigBuilder() //<1> + .withMarkupLanguage(io.github.swagger2markup.config.MarkupLanguage.MARKDOWN) //<2> .withOutputLanguage(Language.DE) //<3> .withPathsGroupedBy(GroupBy.TAGS) //<4> .build(); //<5> diff --git a/swagger2markup-core/src/test/java/io/github/swagger2markup/GeneralConverterTest.java b/swagger2markup/src/test/java/io/github/swagger2markup/GeneralConverterTest.java similarity index 100% rename from swagger2markup-core/src/test/java/io/github/swagger2markup/GeneralConverterTest.java rename to swagger2markup/src/test/java/io/github/swagger2markup/GeneralConverterTest.java diff --git a/swagger2markup-core/src/test/java/io/github/swagger2markup/MarkdownConverterTest.java b/swagger2markup/src/test/java/io/github/swagger2markup/MarkdownConverterTest.java similarity index 92% rename from swagger2markup-core/src/test/java/io/github/swagger2markup/MarkdownConverterTest.java rename to swagger2markup/src/test/java/io/github/swagger2markup/MarkdownConverterTest.java index d7e44f21..10160293 100644 --- a/swagger2markup-core/src/test/java/io/github/swagger2markup/MarkdownConverterTest.java +++ b/swagger2markup/src/test/java/io/github/swagger2markup/MarkdownConverterTest.java @@ -21,7 +21,8 @@ import com.google.common.collect.Maps; import com.google.common.collect.Sets; import io.github.swagger2markup.assertions.DiffUtils; import io.github.swagger2markup.builder.Swagger2MarkupConfigBuilder; -import io.github.swagger2markup.markup.builder.MarkupLanguage; +import io.github.swagger2markup.builder.Swagger2MarkupConfigBuilder.Swagger2MarkupConfig; +import io.github.swagger2markup.config.MarkupLanguage; import org.apache.commons.io.FileUtils; import org.junit.Before; import org.junit.Test; @@ -127,8 +128,8 @@ public class MarkdownConverterTest { FileUtils.deleteQuietly(outputDirectory.toFile()); //When - Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() - .withMarkupLanguage(MarkupLanguage.MARKDOWN) + Swagger2MarkupConfig config = (Swagger2MarkupConfig) new Swagger2MarkupConfigBuilder() + .withMarkupLanguage(io.github.swagger2markup.config.MarkupLanguage.MARKDOWN) .build(); Swagger2MarkupConverter.from(file) .withConfig(config) @@ -151,8 +152,8 @@ public class MarkdownConverterTest { FileUtils.deleteQuietly(outputDirectory.toFile()); //When - Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() - .withMarkupLanguage(MarkupLanguage.MARKDOWN) + Swagger2MarkupConfig config = (Swagger2MarkupConfig) new Swagger2MarkupConfigBuilder() + .withMarkupLanguage(io.github.swagger2markup.config.MarkupLanguage.MARKDOWN) .build(); Swagger2MarkupConverter.from(file) .withConfig(config) @@ -175,7 +176,7 @@ public class MarkdownConverterTest { FileUtils.deleteQuietly(outputDirectory.toFile()); //When - Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() + Swagger2MarkupConfig config = (Swagger2MarkupConfig) new Swagger2MarkupConfigBuilder() .withMarkupLanguage(MarkupLanguage.MARKDOWN) .withInterDocumentCrossReferences() .build(); @@ -199,7 +200,7 @@ public class MarkdownConverterTest { FileUtils.deleteQuietly(outputDirectory.toFile()); //When - Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() + Swagger2MarkupConfig config = (Swagger2MarkupConfig) new Swagger2MarkupConfigBuilder() .withSeparatedDefinitions() .withMarkupLanguage(MarkupLanguage.MARKDOWN) .build(); @@ -227,7 +228,7 @@ public class MarkdownConverterTest { FileUtils.deleteQuietly(outputDirectory.toFile()); //When - Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() + Swagger2MarkupConfig config = (Swagger2MarkupConfig) new Swagger2MarkupConfigBuilder() .withMarkupLanguage(MarkupLanguage.MARKDOWN) .build(); Swagger2MarkupConverter.from(file) @@ -251,7 +252,7 @@ public class MarkdownConverterTest { FileUtils.deleteQuietly(outputDirectory.toFile()); //When - Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() + Swagger2MarkupConfig config = (Swagger2MarkupConfig) new Swagger2MarkupConfigBuilder() .withSeparatedDefinitions() .withMarkupLanguage(MarkupLanguage.MARKDOWN) .build(); @@ -283,7 +284,7 @@ public class MarkdownConverterTest { FileUtils.deleteQuietly(outputDirectory.toFile()); //When - Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() + Swagger2MarkupConfig config = (Swagger2MarkupConfig) new Swagger2MarkupConfigBuilder() .withSeparatedDefinitions() .withMarkupLanguage(MarkupLanguage.MARKDOWN) .build(); diff --git a/swagger2markup/src/test/java/io/github/swagger2markup/assertions/DiffUtils.java b/swagger2markup/src/test/java/io/github/swagger2markup/assertions/DiffUtils.java new file mode 100644 index 00000000..0ca0ab4c --- /dev/null +++ b/swagger2markup/src/test/java/io/github/swagger2markup/assertions/DiffUtils.java @@ -0,0 +1,55 @@ +/* + * + * Copyright 2017 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.assertions; + +import io.github.robwin.diff.DiffAssertions; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.nio.file.DirectoryStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +public class DiffUtils { + + private static final Logger LOGGER = LoggerFactory.getLogger(DiffUtils.class); + + public static void assertThatAllFilesAreEqual(Path expectedDirectory, Path actualDirectory, String reportName) { + Path reportPath = Paths.get("build/diff-report/", reportName); + try { + try (DirectoryStream directoryStream = Files.newDirectoryStream(expectedDirectory)) { + for (Path expectedFile : directoryStream) { + Path actualFile = actualDirectory.resolve(expectedFile.getFileName()); + LOGGER.info("Diffing file '{}' with '{}'", actualFile, expectedFile); + DiffAssertions.assertThat(actualFile).isEqualTo(expectedFile, reportPath); + } + } + } catch (IOException e) { + throw new RuntimeException("Failed to assert that all files are equal", e); + } + } + + public static void assertThatFileIsEqual(Path expectedFile, Path actualFile, String reportName) { + Path reportPath = Paths.get("build/diff-report/", reportName); + LOGGER.info("Diffing file '{}' with '{}'", actualFile, expectedFile); + DiffAssertions.assertThat(actualFile).isEqualTo(expectedFile, reportPath); + } +} diff --git a/swagger2markup-core/src/test/java/io/github/swagger2markup/builder/MyExtension.java b/swagger2markup/src/test/java/io/github/swagger2markup/builder/MyExtension.java similarity index 87% rename from swagger2markup-core/src/test/java/io/github/swagger2markup/builder/MyExtension.java rename to swagger2markup/src/test/java/io/github/swagger2markup/builder/MyExtension.java index 8562a92e..826b2683 100644 --- a/swagger2markup-core/src/test/java/io/github/swagger2markup/builder/MyExtension.java +++ b/swagger2markup/src/test/java/io/github/swagger2markup/builder/MyExtension.java @@ -15,8 +15,8 @@ */ package io.github.swagger2markup.builder; +import io.github.swagger2markup.Schema2MarkupProperties; import io.github.swagger2markup.Swagger2MarkupConverter; -import io.github.swagger2markup.Swagger2MarkupProperties; import io.github.swagger2markup.markup.builder.MarkupDocBuilder; import io.github.swagger2markup.markup.builder.MarkupLanguage; import io.github.swagger2markup.spi.DefinitionsDocumentExtension; @@ -32,11 +32,11 @@ public class MyExtension extends DefinitionsDocumentExtension { private String extensionProperty; @Override - public void init(Swagger2MarkupConverter.Context globalContext) { + public void init(Swagger2MarkupConverter.SwaggerContext globalContext) { // init is executed once - Swagger2MarkupProperties extensionProperties = globalContext.getConfig().getExtensionsProperties(); //<1> + Schema2MarkupProperties extensionProperties = globalContext.getConfig().getExtensionsProperties(); //<1> extensionProperty = extensionProperties.getRequiredString(EXTENSION_ID + ".propertyName"); - Swagger model = globalContext.getSwagger(); + Swagger model = globalContext.getSchema(); } @Override diff --git a/swagger2markup-core/src/test/java/io/github/swagger2markup/builder/MySwaggerModelExtension.java b/swagger2markup/src/test/java/io/github/swagger2markup/builder/MySwaggerModelExtension.java similarity index 100% rename from swagger2markup-core/src/test/java/io/github/swagger2markup/builder/MySwaggerModelExtension.java rename to swagger2markup/src/test/java/io/github/swagger2markup/builder/MySwaggerModelExtension.java diff --git a/swagger2markup-core/src/test/java/io/github/swagger2markup/builder/Swagger2MarkupConfigBuilderTest.java b/swagger2markup/src/test/java/io/github/swagger2markup/builder/Swagger2MarkupConfigBuilderTest.java similarity index 93% rename from swagger2markup-core/src/test/java/io/github/swagger2markup/builder/Swagger2MarkupConfigBuilderTest.java rename to swagger2markup/src/test/java/io/github/swagger2markup/builder/Swagger2MarkupConfigBuilderTest.java index d8380aa1..f32e626f 100644 --- a/swagger2markup-core/src/test/java/io/github/swagger2markup/builder/Swagger2MarkupConfigBuilderTest.java +++ b/swagger2markup/src/test/java/io/github/swagger2markup/builder/Swagger2MarkupConfigBuilderTest.java @@ -16,7 +16,10 @@ package io.github.swagger2markup.builder; import com.google.common.collect.Ordering; -import io.github.swagger2markup.*; +import io.github.swagger2markup.Swagger2MarkupProperties; +import io.github.swagger2markup.config.GroupBy; +import io.github.swagger2markup.config.Language; +import io.github.swagger2markup.config.OrderBy; import io.github.swagger2markup.markup.builder.MarkupLanguage; import org.junit.Test; @@ -40,7 +43,7 @@ public class Swagger2MarkupConfigBuilderTest { configMap.put("swagger2markup.uniqueId1.customProperty1", "123"); configMap.put("swagger2markup.uniqueId1.customProperty2", "123"); - Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder(configMap) + Swagger2MarkupConfigBuilder.Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder(configMap) .build(); assertThat(config.getAnchorPrefix()).isNull(); @@ -50,10 +53,10 @@ public class Swagger2MarkupConfigBuilderTest { assertThat(config.isGeneratedExamplesEnabled()).isFalse(); assertThat(config.isInlineSchemaEnabled()).isEqualTo(true); assertThat(config.getInterDocumentCrossReferencesPrefix()).isNull(); - assertThat(config.getMarkupLanguage()).isEqualTo(MarkupLanguage.MARKDOWN); + assertThat(config.getMarkupLanguage().name()).isEqualTo(MarkupLanguage.MARKDOWN.name()); assertThat(config.getOperationOrderBy()).isEqualTo(OrderBy.NATURAL); assertThat(config.getOperationOrdering()).isNotNull(); - assertThat(config.getOutputLanguage()).isEqualTo(Language.EN); + assertThat(config.getLanguage()).isEqualTo(Language.EN); assertThat(config.getOverviewDocument()).isEqualTo("overview"); assertThat(config.getParameterOrderBy()).isEqualTo(OrderBy.NATURAL); assertThat(config.getParameterOrdering()).isEqualTo(Swagger2MarkupConfigBuilder.PARAMETER_IN_NATURAL_ORDERING.compound(Swagger2MarkupConfigBuilder.PARAMETER_NAME_NATURAL_ORDERING)); @@ -90,7 +93,7 @@ public class Swagger2MarkupConfigBuilderTest { Properties properties = new Properties(); properties.load(Swagger2MarkupConfigBuilderTest.class.getResourceAsStream("/config/config.properties")); - Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder(properties).build(); + Swagger2MarkupConfigBuilder.Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder(properties).build(); assertThat(config.getAnchorPrefix()).isEqualTo("anchorPrefix"); assertThat(config.getDefinitionOrderBy()).isEqualTo(OrderBy.AS_IS); @@ -100,10 +103,10 @@ public class Swagger2MarkupConfigBuilderTest { assertThat(config.isHostnameEnabled()).isEqualTo(false); assertThat(config.isInlineSchemaEnabled()).isEqualTo(false); assertThat(config.getInterDocumentCrossReferencesPrefix()).isEqualTo("xrefPrefix"); - assertThat(config.getMarkupLanguage()).isEqualTo(MarkupLanguage.MARKDOWN); + assertThat(config.getMarkupLanguage().name()).isEqualTo(MarkupLanguage.MARKDOWN.name()); assertThat(config.getOperationOrderBy()).isEqualTo(OrderBy.NATURAL); assertThat(config.getOperationOrdering()).isEqualTo(Swagger2MarkupConfigBuilder.OPERATION_PATH_NATURAL_ORDERING.compound(Swagger2MarkupConfigBuilder.OPERATION_METHOD_NATURAL_ORDERING)); - assertThat(config.getOutputLanguage()).isEqualTo(Language.RU); + assertThat(config.getLanguage()).isEqualTo(Language.RU); assertThat(config.getOverviewDocument()).isEqualTo("overviewTest"); assertThat(config.getParameterOrderBy()).isEqualTo(OrderBy.AS_IS); assertThat(config.getParameterOrdering()).isNull(); diff --git a/swagger2markup-core/src/test/java/io/github/swagger2markup/builder/Swagger2MarkupExtensionRegistryBuilderTest.java b/swagger2markup/src/test/java/io/github/swagger2markup/builder/Swagger2MarkupExtensionRegistryBuilderTest.java similarity index 96% rename from swagger2markup-core/src/test/java/io/github/swagger2markup/builder/Swagger2MarkupExtensionRegistryBuilderTest.java rename to swagger2markup/src/test/java/io/github/swagger2markup/builder/Swagger2MarkupExtensionRegistryBuilderTest.java index 22640bb7..ea88a51f 100644 --- a/swagger2markup-core/src/test/java/io/github/swagger2markup/builder/Swagger2MarkupExtensionRegistryBuilderTest.java +++ b/swagger2markup/src/test/java/io/github/swagger2markup/builder/Swagger2MarkupExtensionRegistryBuilderTest.java @@ -15,7 +15,7 @@ */ package io.github.swagger2markup.builder; -import io.github.swagger2markup.Swagger2MarkupExtensionRegistry; +import io.github.swagger2markup.spi.Swagger2MarkupExtensionRegistry; import io.github.swagger2markup.spi.SwaggerModelExtension; import io.swagger.models.Swagger; import org.junit.Test; diff --git a/swagger2markup-core/src/test/java/io/github/swagger2markup/helper/ContextUtils.java b/swagger2markup/src/test/java/io/github/swagger2markup/helper/ContextUtils.java similarity index 60% rename from swagger2markup-core/src/test/java/io/github/swagger2markup/helper/ContextUtils.java rename to swagger2markup/src/test/java/io/github/swagger2markup/helper/ContextUtils.java index 1b5e65f9..8ae853b5 100644 --- a/swagger2markup-core/src/test/java/io/github/swagger2markup/helper/ContextUtils.java +++ b/swagger2markup/src/test/java/io/github/swagger2markup/helper/ContextUtils.java @@ -15,28 +15,29 @@ */ package io.github.swagger2markup.helper; -import io.github.swagger2markup.Swagger2MarkupConfig; import io.github.swagger2markup.Swagger2MarkupConverter; -import io.github.swagger2markup.Swagger2MarkupExtensionRegistry; +import io.github.swagger2markup.SwaggerLabels; import io.github.swagger2markup.builder.Swagger2MarkupConfigBuilder; +import io.github.swagger2markup.builder.Swagger2MarkupConfigBuilder.Swagger2MarkupConfig; import io.github.swagger2markup.builder.Swagger2MarkupExtensionRegistryBuilder; +import io.github.swagger2markup.spi.Swagger2MarkupExtensionRegistry; import io.swagger.models.Swagger; public class ContextUtils { - public static Swagger2MarkupConverter.Context createContext() { + public static Swagger2MarkupConverter.SwaggerContext createContext() { Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder().build(); Swagger2MarkupExtensionRegistry extensionRegistry = new Swagger2MarkupExtensionRegistryBuilder().build(); - return new Swagger2MarkupConverter.Context(config, extensionRegistry, null, null); + return new Swagger2MarkupConverter.SwaggerContext(config, extensionRegistry, null, null, new SwaggerLabels(config)); } - public static Swagger2MarkupConverter.Context createContext(Swagger2MarkupConfig config) { + public static Swagger2MarkupConverter.SwaggerContext createContext(Swagger2MarkupConfig config) { Swagger2MarkupExtensionRegistry extensionRegistry = new Swagger2MarkupExtensionRegistryBuilder().build(); - return new Swagger2MarkupConverter.Context(config, extensionRegistry, null, null); + return new Swagger2MarkupConverter.SwaggerContext(config, extensionRegistry, null, null, new SwaggerLabels(config)); } - public static Swagger2MarkupConverter.Context createContext(Swagger2MarkupConfig config, Swagger swagger) { + public static Swagger2MarkupConverter.SwaggerContext createContext(Swagger2MarkupConfig config, Swagger swagger) { Swagger2MarkupExtensionRegistry extensionRegistry = new Swagger2MarkupExtensionRegistryBuilder().build(); - return new Swagger2MarkupConverter.Context(config, extensionRegistry, swagger, null); + return new Swagger2MarkupConverter.SwaggerContext(config, extensionRegistry, swagger, null, new SwaggerLabels(config)); } } diff --git a/swagger2markup-core/src/test/java/io/github/swagger2markup/internal/adapter/ParameterAdapterTest.java b/swagger2markup/src/test/java/io/github/swagger2markup/internal/adapter/ParameterAdapterTest.java similarity index 90% rename from swagger2markup-core/src/test/java/io/github/swagger2markup/internal/adapter/ParameterAdapterTest.java rename to swagger2markup/src/test/java/io/github/swagger2markup/internal/adapter/ParameterAdapterTest.java index 3e6061d8..28c62ced 100644 --- a/swagger2markup-core/src/test/java/io/github/swagger2markup/internal/adapter/ParameterAdapterTest.java +++ b/swagger2markup/src/test/java/io/github/swagger2markup/internal/adapter/ParameterAdapterTest.java @@ -23,7 +23,7 @@ import io.github.swagger2markup.internal.type.ObjectType; import io.github.swagger2markup.internal.type.RefType; import io.github.swagger2markup.internal.type.Type; import io.github.swagger2markup.internal.utils.PathUtils; -import io.github.swagger2markup.model.PathOperation; +import io.github.swagger2markup.model.SwaggerPathOperation; import io.swagger.models.Swagger; import io.swagger.models.parameters.Parameter; import org.junit.Test; @@ -42,13 +42,13 @@ public class ParameterAdapterTest { //Given Path file = Paths.get(ParameterAdapterTest.class.getResource("/yaml/swagger_inlineSchema.yaml").toURI()); Swagger2MarkupConverter converter = Swagger2MarkupConverter.from(file).build(); - Swagger2MarkupConverter.Context context = converter.getContext(); - Swagger swagger = context.getSwagger(); + Swagger2MarkupConverter.SwaggerContext context = converter.getContext(); + Swagger swagger = context.getSchema(); io.swagger.models.Path path = swagger.getPaths().get("/LaunchCommand"); - List pathOperations = PathUtils.toPathOperationsList("/LaunchCommand", path); + List pathOperations = PathUtils.toPathOperationsList("/LaunchCommand", path); - PathOperation operation = pathOperations.get(0); + SwaggerPathOperation operation = pathOperations.get(0); List parameters = operation.getOperation().getParameters(); DefinitionDocumentResolverFromOperation resolverFromOperation = new DefinitionDocumentResolverFromOperation(context); diff --git a/swagger2markup-core/src/test/java/io/github/swagger2markup/internal/component/AbstractComponentTest.java b/swagger2markup/src/test/java/io/github/swagger2markup/internal/component/AbstractComponentTest.java similarity index 100% rename from swagger2markup-core/src/test/java/io/github/swagger2markup/internal/component/AbstractComponentTest.java rename to swagger2markup/src/test/java/io/github/swagger2markup/internal/component/AbstractComponentTest.java diff --git a/swagger2markup-core/src/test/java/io/github/swagger2markup/internal/component/BodyParameterComponentTest.java b/swagger2markup/src/test/java/io/github/swagger2markup/internal/component/BodyParameterComponentTest.java similarity index 85% rename from swagger2markup-core/src/test/java/io/github/swagger2markup/internal/component/BodyParameterComponentTest.java rename to swagger2markup/src/test/java/io/github/swagger2markup/internal/component/BodyParameterComponentTest.java index 1f79d670..63a71512 100644 --- a/swagger2markup-core/src/test/java/io/github/swagger2markup/internal/component/BodyParameterComponentTest.java +++ b/swagger2markup/src/test/java/io/github/swagger2markup/internal/component/BodyParameterComponentTest.java @@ -16,14 +16,13 @@ package io.github.swagger2markup.internal.component; import io.github.swagger2markup.AsciidocConverterTest; -import io.github.swagger2markup.Swagger2MarkupConfig; import io.github.swagger2markup.Swagger2MarkupConverter; import io.github.swagger2markup.assertions.DiffUtils; import io.github.swagger2markup.builder.Swagger2MarkupConfigBuilder; import io.github.swagger2markup.internal.resolver.DefinitionDocumentResolverFromOperation; import io.github.swagger2markup.internal.utils.PathUtils; import io.github.swagger2markup.markup.builder.MarkupDocBuilder; -import io.github.swagger2markup.model.PathOperation; +import io.github.swagger2markup.model.SwaggerPathOperation; import io.swagger.models.Swagger; import org.apache.commons.io.FileUtils; import org.junit.Before; @@ -52,14 +51,14 @@ public class BodyParameterComponentTest extends AbstractComponentTest { public void testBodyParameterComponent() throws URISyntaxException { //Given Path file = Paths.get(AsciidocConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI()); - Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder().withFlatBody().build(); + Swagger2MarkupConfigBuilder.Swagger2MarkupConfig config = (Swagger2MarkupConfigBuilder.Swagger2MarkupConfig) new Swagger2MarkupConfigBuilder().withFlatBody().build(); Swagger2MarkupConverter converter = Swagger2MarkupConverter.from(file).withConfig(config).build(); - Swagger swagger = converter.getContext().getSwagger(); + Swagger swagger = converter.getContext().getSchema(); io.swagger.models.Path path = swagger.getPaths().get("/pets"); - List pathOperations = PathUtils.toPathOperationsList("/pets", path); + List pathOperations = PathUtils.toPathOperationsList("/pets", path); - Swagger2MarkupConverter.Context context = converter.getContext(); + Swagger2MarkupConverter.SwaggerContext context = converter.getContext(); MarkupDocBuilder markupDocBuilder = context.createMarkupDocBuilder(); //When diff --git a/swagger2markup-core/src/test/java/io/github/swagger2markup/internal/component/ConsumesComponentTest.java b/swagger2markup/src/test/java/io/github/swagger2markup/internal/component/ConsumesComponentTest.java similarity index 96% rename from swagger2markup-core/src/test/java/io/github/swagger2markup/internal/component/ConsumesComponentTest.java rename to swagger2markup/src/test/java/io/github/swagger2markup/internal/component/ConsumesComponentTest.java index 55129899..013d6c09 100644 --- a/swagger2markup-core/src/test/java/io/github/swagger2markup/internal/component/ConsumesComponentTest.java +++ b/swagger2markup/src/test/java/io/github/swagger2markup/internal/component/ConsumesComponentTest.java @@ -49,7 +49,7 @@ public class ConsumesComponentTest extends AbstractComponentTest { consumes.add("application/json"); consumes.add("application/xml"); - Swagger2MarkupConverter.Context context = createContext(); + Swagger2MarkupConverter.SwaggerContext context = createContext(); MarkupDocBuilder markupDocBuilder = context.createMarkupDocBuilder(); markupDocBuilder = new ConsumesComponent(context).apply(markupDocBuilder, ConsumesComponent.parameters( diff --git a/swagger2markup-core/src/test/java/io/github/swagger2markup/internal/component/ContactInfoComponentTest.java b/swagger2markup/src/test/java/io/github/swagger2markup/internal/component/ContactInfoComponentTest.java similarity index 96% rename from swagger2markup-core/src/test/java/io/github/swagger2markup/internal/component/ContactInfoComponentTest.java rename to swagger2markup/src/test/java/io/github/swagger2markup/internal/component/ContactInfoComponentTest.java index ccb694f3..919f36dc 100644 --- a/swagger2markup-core/src/test/java/io/github/swagger2markup/internal/component/ContactInfoComponentTest.java +++ b/swagger2markup/src/test/java/io/github/swagger2markup/internal/component/ContactInfoComponentTest.java @@ -46,7 +46,7 @@ public class ContactInfoComponentTest extends AbstractComponentTest { public void testVersionInfoComponent() throws URISyntaxException { Contact contact = new Contact().name("TestName").email("test@test.de"); - Swagger2MarkupConverter.Context context = createContext(); + Swagger2MarkupConverter.SwaggerContext context = createContext(); MarkupDocBuilder markupDocBuilder = context.createMarkupDocBuilder(); markupDocBuilder = new ContactInfoComponent(context).apply(markupDocBuilder, ContactInfoComponent.parameters( diff --git a/swagger2markup-core/src/test/java/io/github/swagger2markup/internal/component/DefinitionComponentTest.java b/swagger2markup/src/test/java/io/github/swagger2markup/internal/component/DefinitionComponentTest.java similarity index 94% rename from swagger2markup-core/src/test/java/io/github/swagger2markup/internal/component/DefinitionComponentTest.java rename to swagger2markup/src/test/java/io/github/swagger2markup/internal/component/DefinitionComponentTest.java index b4402bd3..ea2e2b8b 100644 --- a/swagger2markup-core/src/test/java/io/github/swagger2markup/internal/component/DefinitionComponentTest.java +++ b/swagger2markup/src/test/java/io/github/swagger2markup/internal/component/DefinitionComponentTest.java @@ -47,11 +47,11 @@ public class DefinitionComponentTest extends AbstractComponentTest { //Given Path file = Paths.get(DefinitionComponentTest.class.getResource("/yaml/swagger_petstore.yaml").toURI()); Swagger2MarkupConverter converter = Swagger2MarkupConverter.from(file).build(); - Swagger swagger = converter.getContext().getSwagger(); + Swagger swagger = converter.getContext().getSchema(); Model petModel = swagger.getDefinitions().get("Pet"); - Swagger2MarkupConverter.Context context = converter.getContext(); + Swagger2MarkupConverter.SwaggerContext context = converter.getContext(); MarkupDocBuilder markupDocBuilder = context.createMarkupDocBuilder(); //When diff --git a/swagger2markup-core/src/test/java/io/github/swagger2markup/internal/component/ExternalDocsComponentTest.java b/swagger2markup/src/test/java/io/github/swagger2markup/internal/component/ExternalDocsComponentTest.java similarity index 94% rename from swagger2markup-core/src/test/java/io/github/swagger2markup/internal/component/ExternalDocsComponentTest.java rename to swagger2markup/src/test/java/io/github/swagger2markup/internal/component/ExternalDocsComponentTest.java index 09925889..6de5dd82 100644 --- a/swagger2markup-core/src/test/java/io/github/swagger2markup/internal/component/ExternalDocsComponentTest.java +++ b/swagger2markup/src/test/java/io/github/swagger2markup/internal/component/ExternalDocsComponentTest.java @@ -48,12 +48,12 @@ public class ExternalDocsComponentTest extends AbstractComponentTest { //Given Path file = Paths.get(DefinitionComponentTest.class.getResource("/yaml/swagger_petstore_20160612.yaml").toURI()); Swagger2MarkupConverter converter = Swagger2MarkupConverter.from(file).build(); - Swagger swagger = converter.getContext().getSwagger(); + Swagger swagger = converter.getContext().getSchema(); ExternalDocs externalDocs = swagger.getExternalDocs(); Assert.assertNotNull(externalDocs); - Swagger2MarkupConverter.Context context = converter.getContext(); + Swagger2MarkupConverter.SwaggerContext context = converter.getContext(); MarkupDocBuilder markupDocBuilder = context.createMarkupDocBuilder(); //When diff --git a/swagger2markup-core/src/test/java/io/github/swagger2markup/internal/component/LicenseInfoComponentTest.java b/swagger2markup/src/test/java/io/github/swagger2markup/internal/component/LicenseInfoComponentTest.java similarity index 96% rename from swagger2markup-core/src/test/java/io/github/swagger2markup/internal/component/LicenseInfoComponentTest.java rename to swagger2markup/src/test/java/io/github/swagger2markup/internal/component/LicenseInfoComponentTest.java index 4e651c0b..9814b123 100644 --- a/swagger2markup-core/src/test/java/io/github/swagger2markup/internal/component/LicenseInfoComponentTest.java +++ b/swagger2markup/src/test/java/io/github/swagger2markup/internal/component/LicenseInfoComponentTest.java @@ -50,7 +50,7 @@ public class LicenseInfoComponentTest extends AbstractComponentTest { .license(new License().name("Apache 2.0").url("http://www.apache.org/licenses/LICENSE-2.0")) .termsOfService("Bla bla bla"); - Swagger2MarkupConverter.Context context = createContext(); + Swagger2MarkupConverter.SwaggerContext context = createContext(); MarkupDocBuilder markupDocBuilder = context.createMarkupDocBuilder(); markupDocBuilder = new LicenseInfoComponent(context).apply(markupDocBuilder, LicenseInfoComponent.parameters(info, OverviewDocument.SECTION_TITLE_LEVEL)); diff --git a/swagger2markup-core/src/test/java/io/github/swagger2markup/internal/component/ParameterTableComponentTest.java b/swagger2markup/src/test/java/io/github/swagger2markup/internal/component/ParameterTableComponentTest.java similarity index 89% rename from swagger2markup-core/src/test/java/io/github/swagger2markup/internal/component/ParameterTableComponentTest.java rename to swagger2markup/src/test/java/io/github/swagger2markup/internal/component/ParameterTableComponentTest.java index 2ffe1dae..e7cc0daf 100644 --- a/swagger2markup-core/src/test/java/io/github/swagger2markup/internal/component/ParameterTableComponentTest.java +++ b/swagger2markup/src/test/java/io/github/swagger2markup/internal/component/ParameterTableComponentTest.java @@ -20,7 +20,7 @@ import io.github.swagger2markup.assertions.DiffUtils; import io.github.swagger2markup.internal.resolver.DefinitionDocumentResolverFromOperation; import io.github.swagger2markup.internal.utils.PathUtils; import io.github.swagger2markup.markup.builder.MarkupDocBuilder; -import io.github.swagger2markup.model.PathOperation; +import io.github.swagger2markup.model.SwaggerPathOperation; import io.swagger.models.Swagger; import org.apache.commons.io.FileUtils; import org.junit.Before; @@ -50,12 +50,12 @@ public class ParameterTableComponentTest extends AbstractComponentTest { //Given Path file = Paths.get(ParameterTableComponentTest.class.getResource("/yaml/swagger_petstore.yaml").toURI()); Swagger2MarkupConverter converter = Swagger2MarkupConverter.from(file).build(); - Swagger swagger = converter.getContext().getSwagger(); + Swagger swagger = converter.getContext().getSchema(); io.swagger.models.Path path = swagger.getPaths().get("/pets"); - List pathOperations = PathUtils.toPathOperationsList("/pets", path); + List pathOperations = PathUtils.toPathOperationsList("/pets", path); - Swagger2MarkupConverter.Context context = converter.getContext(); + Swagger2MarkupConverter.SwaggerContext context = converter.getContext(); MarkupDocBuilder markupDocBuilder = context.createMarkupDocBuilder(); //When diff --git a/swagger2markup-core/src/test/java/io/github/swagger2markup/internal/component/PathOperationComponentTest.java b/swagger2markup/src/test/java/io/github/swagger2markup/internal/component/PathOperationComponentTest.java similarity index 85% rename from swagger2markup-core/src/test/java/io/github/swagger2markup/internal/component/PathOperationComponentTest.java rename to swagger2markup/src/test/java/io/github/swagger2markup/internal/component/PathOperationComponentTest.java index c42af4ad..86ef54a3 100644 --- a/swagger2markup-core/src/test/java/io/github/swagger2markup/internal/component/PathOperationComponentTest.java +++ b/swagger2markup/src/test/java/io/github/swagger2markup/internal/component/PathOperationComponentTest.java @@ -15,15 +15,15 @@ */ package io.github.swagger2markup.internal.component; -import io.github.swagger2markup.Swagger2MarkupConfig; import io.github.swagger2markup.Swagger2MarkupConverter; import io.github.swagger2markup.assertions.DiffUtils; import io.github.swagger2markup.builder.Swagger2MarkupConfigBuilder; +import io.github.swagger2markup.builder.Swagger2MarkupConfigBuilder.Swagger2MarkupConfig; import io.github.swagger2markup.internal.resolver.DefinitionDocumentResolverFromOperation; import io.github.swagger2markup.internal.resolver.SecurityDocumentResolver; import io.github.swagger2markup.internal.utils.PathUtils; import io.github.swagger2markup.markup.builder.MarkupDocBuilder; -import io.github.swagger2markup.model.PathOperation; +import io.github.swagger2markup.model.SwaggerPathOperation; import io.swagger.models.Swagger; import org.apache.commons.io.FileUtils; import org.junit.Test; @@ -48,12 +48,12 @@ public class PathOperationComponentTest extends AbstractComponentTest { //Given Path file = Paths.get(PathOperationComponentTest.class.getResource("/yaml/swagger_petstore.yaml").toURI()); Swagger2MarkupConverter converter = Swagger2MarkupConverter.from(file).build(); - Swagger swagger = converter.getContext().getSwagger(); + Swagger swagger = converter.getContext().getSchema(); io.swagger.models.Path path = swagger.getPaths().get("/pets"); - List pathOperations = PathUtils.toPathOperationsList("/pets", path); + List pathOperations = PathUtils.toPathOperationsList("/pets", path); - Swagger2MarkupConverter.Context context = converter.getContext(); + Swagger2MarkupConverter.SwaggerContext context = converter.getContext(); MarkupDocBuilder markupDocBuilder = context.createMarkupDocBuilder(); //When @@ -78,12 +78,12 @@ public class PathOperationComponentTest extends AbstractComponentTest { //Given Path file = Paths.get(PathOperationComponentTest.class.getResource("/yaml/swagger_inlineSchema.yaml").toURI()); Swagger2MarkupConverter converter = Swagger2MarkupConverter.from(file).build(); - Swagger swagger = converter.getContext().getSwagger(); + Swagger swagger = converter.getContext().getSchema(); io.swagger.models.Path path = swagger.getPaths().get("/LaunchCommand"); - List pathOperations = PathUtils.toPathOperationsList("/LaunchCommand", path); + List pathOperations = PathUtils.toPathOperationsList("/LaunchCommand", path); - Swagger2MarkupConverter.Context context = converter.getContext(); + Swagger2MarkupConverter.SwaggerContext context = converter.getContext(); MarkupDocBuilder markupDocBuilder = context.createMarkupDocBuilder(); //When @@ -113,12 +113,12 @@ public class PathOperationComponentTest extends AbstractComponentTest { Path file = Paths.get(PathOperationComponentTest.class.getResource("/yaml/swagger_petstore.yaml").toURI()); Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder(configMap).build(); Swagger2MarkupConverter converter = Swagger2MarkupConverter.from(file).withConfig(config) .build(); - Swagger swagger = converter.getContext().getSwagger(); + Swagger swagger = converter.getContext().getSchema(); io.swagger.models.Path path = swagger.getPaths().get("/pets/{petId}"); - List pathOperations = PathUtils.toPathOperationsList("/pets/{petId}", path); + List pathOperations = PathUtils.toPathOperationsList("/pets/{petId}", path); - Swagger2MarkupConverter.Context context = converter.getContext(); + Swagger2MarkupConverter.SwaggerContext context = converter.getContext(); MarkupDocBuilder markupDocBuilder = context.createMarkupDocBuilder(); //When @@ -147,12 +147,12 @@ public class PathOperationComponentTest extends AbstractComponentTest { Path file = Paths.get(PathOperationComponentTest.class.getResource("/yaml/swagger_petstore.yaml").toURI()); Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder(configMap).build(); Swagger2MarkupConverter converter = Swagger2MarkupConverter.from(file).withConfig(config) .build(); - Swagger swagger = converter.getContext().getSwagger(); + Swagger swagger = converter.getContext().getSchema(); io.swagger.models.Path path = swagger.getPaths().get("/pets/findByTags"); - List pathOperations = PathUtils.toPathOperationsList("/pets/findByTags", path); + List pathOperations = PathUtils.toPathOperationsList("/pets/findByTags", path); - Swagger2MarkupConverter.Context context = converter.getContext(); + Swagger2MarkupConverter.SwaggerContext context = converter.getContext(); MarkupDocBuilder markupDocBuilder = context.createMarkupDocBuilder(); //When @@ -181,12 +181,12 @@ public class PathOperationComponentTest extends AbstractComponentTest { Path file = Paths.get(PathOperationComponentTest.class.getResource("/yaml/swagger_petstore_body_examples.yaml").toURI()); Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder(configMap).build(); Swagger2MarkupConverter converter = Swagger2MarkupConverter.from(file).withConfig(config) .build(); - Swagger swagger = converter.getContext().getSwagger(); + Swagger swagger = converter.getContext().getSchema(); io.swagger.models.Path path = swagger.getPaths().get("/users"); - List pathOperations = PathUtils.toPathOperationsList("/users", path); + List pathOperations = PathUtils.toPathOperationsList("/users", path); - Swagger2MarkupConverter.Context context = converter.getContext(); + Swagger2MarkupConverter.SwaggerContext context = converter.getContext(); MarkupDocBuilder markupDocBuilder = context.createMarkupDocBuilder(); //When diff --git a/swagger2markup-core/src/test/java/io/github/swagger2markup/internal/component/ProducesComponentTest.java b/swagger2markup/src/test/java/io/github/swagger2markup/internal/component/ProducesComponentTest.java similarity index 96% rename from swagger2markup-core/src/test/java/io/github/swagger2markup/internal/component/ProducesComponentTest.java rename to swagger2markup/src/test/java/io/github/swagger2markup/internal/component/ProducesComponentTest.java index 0c03dc87..050b5236 100644 --- a/swagger2markup-core/src/test/java/io/github/swagger2markup/internal/component/ProducesComponentTest.java +++ b/swagger2markup/src/test/java/io/github/swagger2markup/internal/component/ProducesComponentTest.java @@ -49,7 +49,7 @@ public class ProducesComponentTest extends AbstractComponentTest { produces.add("application/json"); produces.add("application/xml"); - Swagger2MarkupConverter.Context context = createContext(); + Swagger2MarkupConverter.SwaggerContext context = createContext(); MarkupDocBuilder markupDocBuilder = context.createMarkupDocBuilder(); markupDocBuilder = new ProducesComponent(context) diff --git a/swagger2markup-core/src/test/java/io/github/swagger2markup/internal/component/PropertiesTableComponentTest.java b/swagger2markup/src/test/java/io/github/swagger2markup/internal/component/PropertiesTableComponentTest.java similarity index 95% rename from swagger2markup-core/src/test/java/io/github/swagger2markup/internal/component/PropertiesTableComponentTest.java rename to swagger2markup/src/test/java/io/github/swagger2markup/internal/component/PropertiesTableComponentTest.java index f18b215e..597601af 100644 --- a/swagger2markup-core/src/test/java/io/github/swagger2markup/internal/component/PropertiesTableComponentTest.java +++ b/swagger2markup/src/test/java/io/github/swagger2markup/internal/component/PropertiesTableComponentTest.java @@ -50,11 +50,11 @@ public class PropertiesTableComponentTest extends AbstractComponentTest { //Given Path file = Paths.get(PropertiesTableComponentTest.class.getResource("/yaml/swagger_petstore.yaml").toURI()); Swagger2MarkupConverter converter = Swagger2MarkupConverter.from(file).build(); - Swagger swagger = converter.getContext().getSwagger(); + Swagger swagger = converter.getContext().getSchema(); Model petModel = swagger.getDefinitions().get("Pet"); - Swagger2MarkupConverter.Context context = converter.getContext(); + Swagger2MarkupConverter.SwaggerContext context = converter.getContext(); MarkupDocBuilder markupDocBuilder = context.createMarkupDocBuilder(); List localDefinitions = new ArrayList<>(); diff --git a/swagger2markup-core/src/test/java/io/github/swagger2markup/internal/component/ResponsesComponentTest.java b/swagger2markup/src/test/java/io/github/swagger2markup/internal/component/ResponsesComponentTest.java similarity index 89% rename from swagger2markup-core/src/test/java/io/github/swagger2markup/internal/component/ResponsesComponentTest.java rename to swagger2markup/src/test/java/io/github/swagger2markup/internal/component/ResponsesComponentTest.java index 37e0de97..4487abfb 100644 --- a/swagger2markup-core/src/test/java/io/github/swagger2markup/internal/component/ResponsesComponentTest.java +++ b/swagger2markup/src/test/java/io/github/swagger2markup/internal/component/ResponsesComponentTest.java @@ -20,7 +20,7 @@ import io.github.swagger2markup.assertions.DiffUtils; import io.github.swagger2markup.internal.resolver.DefinitionDocumentResolverFromOperation; import io.github.swagger2markup.internal.utils.PathUtils; import io.github.swagger2markup.markup.builder.MarkupDocBuilder; -import io.github.swagger2markup.model.PathOperation; +import io.github.swagger2markup.model.SwaggerPathOperation; import io.swagger.models.Swagger; import org.apache.commons.io.FileUtils; import org.junit.Before; @@ -50,12 +50,12 @@ public class ResponsesComponentTest extends AbstractComponentTest { //Given Path file = Paths.get(ResponsesComponentTest.class.getResource("/yaml/swagger_petstore.yaml").toURI()); Swagger2MarkupConverter converter = Swagger2MarkupConverter.from(file).build(); - Swagger swagger = converter.getContext().getSwagger(); + Swagger swagger = converter.getContext().getSchema(); io.swagger.models.Path path = swagger.getPaths().get("/pets/findByStatus"); - List pathOperations = PathUtils.toPathOperationsList("/pets/findByStatus", path); + List pathOperations = PathUtils.toPathOperationsList("/pets/findByStatus", path); - Swagger2MarkupConverter.Context context = converter.getContext(); + Swagger2MarkupConverter.SwaggerContext context = converter.getContext(); MarkupDocBuilder markupDocBuilder = context.createMarkupDocBuilder(); //When diff --git a/swagger2markup-core/src/test/java/io/github/swagger2markup/internal/component/SecuritySchemeComponentTest.java b/swagger2markup/src/test/java/io/github/swagger2markup/internal/component/SecuritySchemeComponentTest.java similarity index 89% rename from swagger2markup-core/src/test/java/io/github/swagger2markup/internal/component/SecuritySchemeComponentTest.java rename to swagger2markup/src/test/java/io/github/swagger2markup/internal/component/SecuritySchemeComponentTest.java index 6603898d..8f75c8fb 100644 --- a/swagger2markup-core/src/test/java/io/github/swagger2markup/internal/component/SecuritySchemeComponentTest.java +++ b/swagger2markup/src/test/java/io/github/swagger2markup/internal/component/SecuritySchemeComponentTest.java @@ -20,7 +20,7 @@ import io.github.swagger2markup.assertions.DiffUtils; import io.github.swagger2markup.internal.resolver.SecurityDocumentResolver; import io.github.swagger2markup.internal.utils.PathUtils; import io.github.swagger2markup.markup.builder.MarkupDocBuilder; -import io.github.swagger2markup.model.PathOperation; +import io.github.swagger2markup.model.SwaggerPathOperation; import io.swagger.models.Swagger; import org.apache.commons.io.FileUtils; import org.junit.Before; @@ -49,12 +49,12 @@ public class SecuritySchemeComponentTest extends AbstractComponentTest { //Given Path file = Paths.get(SecuritySchemeComponentTest.class.getResource("/yaml/swagger_petstore.yaml").toURI()); Swagger2MarkupConverter converter = Swagger2MarkupConverter.from(file).build(); - Swagger swagger = converter.getContext().getSwagger(); + Swagger swagger = converter.getContext().getSchema(); - List pathOperations = PathUtils.toPathOperationsList(swagger.getPaths(), "", "", + List pathOperations = PathUtils.toPathOperationsList(swagger.getPaths(), "", "", converter.getContext().getConfig().getOperationOrdering()); - Swagger2MarkupConverter.Context context = converter.getContext(); + Swagger2MarkupConverter.SwaggerContext context = converter.getContext(); MarkupDocBuilder markupDocBuilder = context.createMarkupDocBuilder(); //When diff --git a/swagger2markup-core/src/test/java/io/github/swagger2markup/internal/component/SecuritySchemeDefinitionComponentTest.java b/swagger2markup/src/test/java/io/github/swagger2markup/internal/component/SecuritySchemeDefinitionComponentTest.java similarity index 93% rename from swagger2markup-core/src/test/java/io/github/swagger2markup/internal/component/SecuritySchemeDefinitionComponentTest.java rename to swagger2markup/src/test/java/io/github/swagger2markup/internal/component/SecuritySchemeDefinitionComponentTest.java index 1b66e37e..ec08f4cf 100644 --- a/swagger2markup-core/src/test/java/io/github/swagger2markup/internal/component/SecuritySchemeDefinitionComponentTest.java +++ b/swagger2markup/src/test/java/io/github/swagger2markup/internal/component/SecuritySchemeDefinitionComponentTest.java @@ -51,11 +51,11 @@ public class SecuritySchemeDefinitionComponentTest extends AbstractComponentTest //Given Path file = Paths.get(SecuritySchemeDefinitionComponentTest.class.getResource("/yaml/swagger_petstore.yaml").toURI()); Swagger2MarkupConverter converter = Swagger2MarkupConverter.from(file).build(); - Swagger swagger = converter.getContext().getSwagger(); + Swagger swagger = converter.getContext().getSchema(); SecuritySchemeDefinition securitySchemeDefinition = swagger.getSecurityDefinitions().get("petstore_auth"); - Swagger2MarkupConverter.Context context = converter.getContext(); + Swagger2MarkupConverter.SwaggerContext context = converter.getContext(); MarkupDocBuilder markupDocBuilder = context.createMarkupDocBuilder(); markupDocBuilder = new SecuritySchemeDefinitionComponent(context).apply( @@ -74,11 +74,11 @@ public class SecuritySchemeDefinitionComponentTest extends AbstractComponentTest //Given Path file = Paths.get(SecuritySchemeDefinitionComponentTest.class.getResource("/yaml/swagger_petstore.yaml").toURI()); Swagger2MarkupConverter converter = Swagger2MarkupConverter.from(file).build(); - Swagger swagger = converter.getContext().getSwagger(); + Swagger swagger = converter.getContext().getSchema(); SecuritySchemeDefinition securitySchemeDefinition = swagger.getSecurityDefinitions().get("api_key"); - Swagger2MarkupConverter.Context context = converter.getContext(); + Swagger2MarkupConverter.SwaggerContext context = converter.getContext(); MarkupDocBuilder markupDocBuilder = context.createMarkupDocBuilder(); markupDocBuilder = new SecuritySchemeDefinitionComponent(context).apply( diff --git a/swagger2markup-core/src/test/java/io/github/swagger2markup/internal/component/TableComponentTest.java b/swagger2markup/src/test/java/io/github/swagger2markup/internal/component/TableComponentTest.java similarity index 97% rename from swagger2markup-core/src/test/java/io/github/swagger2markup/internal/component/TableComponentTest.java rename to swagger2markup/src/test/java/io/github/swagger2markup/internal/component/TableComponentTest.java index 1ea3a448..104875df 100644 --- a/swagger2markup-core/src/test/java/io/github/swagger2markup/internal/component/TableComponentTest.java +++ b/swagger2markup/src/test/java/io/github/swagger2markup/internal/component/TableComponentTest.java @@ -52,7 +52,7 @@ public class TableComponentTest extends AbstractComponentTest { StringColumn.Builder descriptionColumnBuilder = StringColumn.builder(StringColumnId.of("description")); descriptionColumnBuilder.add("").add("").add(""); - Swagger2MarkupConverter.Context context = createContext(); + Swagger2MarkupConverter.SwaggerContext context = createContext(); MarkupDocBuilder markupDocBuilder = context.createMarkupDocBuilder(); markupDocBuilder = new TableComponent(context).apply(markupDocBuilder, diff --git a/swagger2markup-core/src/test/java/io/github/swagger2markup/internal/component/TagsComponentTest.java b/swagger2markup/src/test/java/io/github/swagger2markup/internal/component/TagsComponentTest.java similarity index 96% rename from swagger2markup-core/src/test/java/io/github/swagger2markup/internal/component/TagsComponentTest.java rename to swagger2markup/src/test/java/io/github/swagger2markup/internal/component/TagsComponentTest.java index 8568947e..4ed9be39 100644 --- a/swagger2markup-core/src/test/java/io/github/swagger2markup/internal/component/TagsComponentTest.java +++ b/swagger2markup/src/test/java/io/github/swagger2markup/internal/component/TagsComponentTest.java @@ -50,7 +50,7 @@ public class TagsComponentTest extends AbstractComponentTest { tags.add(new Tag().name("Tag1").description("description")); tags.add(new Tag().name("Tag2")); - Swagger2MarkupConverter.Context context = createContext(); + Swagger2MarkupConverter.SwaggerContext context = createContext(); MarkupDocBuilder markupDocBuilder = context.createMarkupDocBuilder(); markupDocBuilder = new TagsComponent(context).apply(markupDocBuilder, TagsComponent.parameters(tags, OverviewDocument.SECTION_TITLE_LEVEL)); diff --git a/swagger2markup-core/src/test/java/io/github/swagger2markup/internal/component/UriSchemeComponentTest.java b/swagger2markup/src/test/java/io/github/swagger2markup/internal/component/UriSchemeComponentTest.java similarity index 96% rename from swagger2markup-core/src/test/java/io/github/swagger2markup/internal/component/UriSchemeComponentTest.java rename to swagger2markup/src/test/java/io/github/swagger2markup/internal/component/UriSchemeComponentTest.java index 599cf72a..ee5e8b08 100644 --- a/swagger2markup-core/src/test/java/io/github/swagger2markup/internal/component/UriSchemeComponentTest.java +++ b/swagger2markup/src/test/java/io/github/swagger2markup/internal/component/UriSchemeComponentTest.java @@ -50,7 +50,7 @@ public class UriSchemeComponentTest extends AbstractComponentTest { swagger.addScheme(Scheme.HTTP); swagger.addScheme(Scheme.HTTPS); - Swagger2MarkupConverter.Context context = createContext(); + Swagger2MarkupConverter.SwaggerContext context = createContext(); MarkupDocBuilder markupDocBuilder = context.createMarkupDocBuilder(); markupDocBuilder = new UriSchemeComponent(context).apply(markupDocBuilder, UriSchemeComponent.parameters(swagger, OverviewDocument.SECTION_TITLE_LEVEL)); diff --git a/swagger2markup-core/src/test/java/io/github/swagger2markup/internal/component/VersionInfoComponentTest.java b/swagger2markup/src/test/java/io/github/swagger2markup/internal/component/VersionInfoComponentTest.java similarity index 96% rename from swagger2markup-core/src/test/java/io/github/swagger2markup/internal/component/VersionInfoComponentTest.java rename to swagger2markup/src/test/java/io/github/swagger2markup/internal/component/VersionInfoComponentTest.java index 703e8523..007ba3fc 100644 --- a/swagger2markup-core/src/test/java/io/github/swagger2markup/internal/component/VersionInfoComponentTest.java +++ b/swagger2markup/src/test/java/io/github/swagger2markup/internal/component/VersionInfoComponentTest.java @@ -47,7 +47,7 @@ public class VersionInfoComponentTest extends AbstractComponentTest { Info info = new Info().version("1.0"); - Swagger2MarkupConverter.Context context = createContext(); + Swagger2MarkupConverter.SwaggerContext context = createContext(); MarkupDocBuilder markupDocBuilder = context.createMarkupDocBuilder(); markupDocBuilder = new VersionInfoComponent(context).apply(markupDocBuilder, VersionInfoComponent.parameters(info, OverviewDocument.SECTION_TITLE_LEVEL)); diff --git a/swagger2markup-core/src/test/java/io/github/swagger2markup/internal/resolver/DefinitionDocumentNameResolverTest.java b/swagger2markup/src/test/java/io/github/swagger2markup/internal/resolver/DefinitionDocumentNameResolverTest.java similarity index 71% rename from swagger2markup-core/src/test/java/io/github/swagger2markup/internal/resolver/DefinitionDocumentNameResolverTest.java rename to swagger2markup/src/test/java/io/github/swagger2markup/internal/resolver/DefinitionDocumentNameResolverTest.java index ee3caa6e..2f5088a4 100644 --- a/swagger2markup-core/src/test/java/io/github/swagger2markup/internal/resolver/DefinitionDocumentNameResolverTest.java +++ b/swagger2markup/src/test/java/io/github/swagger2markup/internal/resolver/DefinitionDocumentNameResolverTest.java @@ -15,10 +15,9 @@ */ package io.github.swagger2markup.internal.resolver; -import io.github.swagger2markup.Swagger2MarkupConfig; import io.github.swagger2markup.Swagger2MarkupConverter; import io.github.swagger2markup.builder.Swagger2MarkupConfigBuilder; -import io.github.swagger2markup.markup.builder.MarkupLanguage; +import io.github.swagger2markup.config.MarkupLanguage; import org.junit.Test; import java.nio.file.Paths; @@ -30,17 +29,17 @@ public class DefinitionDocumentNameResolverTest { @Test public void testDefault() { - Swagger2MarkupConverter.Context context = createContext(); + Swagger2MarkupConverter.SwaggerContext context = createContext(); assertThat(new DefinitionDocumentNameResolver(context).apply("DefinitionName")).isEqualTo("definitions.adoc"); } @Test public void testWithInterDocumentCrossReferencesAndNoOutputPath() { - Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() + Swagger2MarkupConfigBuilder.Swagger2MarkupConfig config = (Swagger2MarkupConfigBuilder.Swagger2MarkupConfig) new Swagger2MarkupConfigBuilder() .withInterDocumentCrossReferences() .build(); - Swagger2MarkupConverter.Context context = createContext(config); + Swagger2MarkupConverter.SwaggerContext context = createContext(config); assertThat(new DefinitionDocumentNameResolver(context).apply("DefinitionName")) .isEqualTo("definitions.adoc"); @@ -48,10 +47,10 @@ public class DefinitionDocumentNameResolverTest { @Test public void testWithInterDocumentCrossReferences() { - Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() + Swagger2MarkupConfigBuilder.Swagger2MarkupConfig config = (Swagger2MarkupConfigBuilder.Swagger2MarkupConfig) new Swagger2MarkupConfigBuilder() .withInterDocumentCrossReferences() .build(); - Swagger2MarkupConverter.Context context = createContext(config); + Swagger2MarkupConverter.SwaggerContext context = createContext(config); context.setOutputPath(Paths.get("/tmp")); assertThat(new DefinitionDocumentNameResolver(context).apply("DefinitionName")) @@ -60,10 +59,10 @@ public class DefinitionDocumentNameResolverTest { @Test public void testWithInterDocumentCrossReferencesAndPrefix() { - Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() + Swagger2MarkupConfigBuilder.Swagger2MarkupConfig config = (Swagger2MarkupConfigBuilder.Swagger2MarkupConfig) new Swagger2MarkupConfigBuilder() .withInterDocumentCrossReferences("prefix_") .build(); - Swagger2MarkupConverter.Context context = createContext(config); + Swagger2MarkupConverter.SwaggerContext context = createContext(config); context.setOutputPath(Paths.get("/tmp")); assertThat(new DefinitionDocumentNameResolver(context).apply("DefinitionName")) @@ -72,11 +71,11 @@ public class DefinitionDocumentNameResolverTest { @Test public void testWithInterDocumentCrossReferencesAndMarkdown() { - Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() + Swagger2MarkupConfigBuilder.Swagger2MarkupConfig config = (Swagger2MarkupConfigBuilder.Swagger2MarkupConfig) new Swagger2MarkupConfigBuilder() .withInterDocumentCrossReferences() .withMarkupLanguage(MarkupLanguage.MARKDOWN) .build(); - Swagger2MarkupConverter.Context context = createContext(config); + Swagger2MarkupConverter.SwaggerContext context = createContext(config); context.setOutputPath(Paths.get("/tmp")); assertThat(new DefinitionDocumentNameResolver(context).apply("DefinitionName")) diff --git a/swagger2markup-core/src/test/java/io/github/swagger2markup/internal/resolver/DefinitionDocumentResolverDefaultTest.java b/swagger2markup/src/test/java/io/github/swagger2markup/internal/resolver/DefinitionDocumentResolverDefaultTest.java similarity index 70% rename from swagger2markup-core/src/test/java/io/github/swagger2markup/internal/resolver/DefinitionDocumentResolverDefaultTest.java rename to swagger2markup/src/test/java/io/github/swagger2markup/internal/resolver/DefinitionDocumentResolverDefaultTest.java index 89106afb..cd2d4f5f 100644 --- a/swagger2markup-core/src/test/java/io/github/swagger2markup/internal/resolver/DefinitionDocumentResolverDefaultTest.java +++ b/swagger2markup/src/test/java/io/github/swagger2markup/internal/resolver/DefinitionDocumentResolverDefaultTest.java @@ -15,10 +15,9 @@ */ package io.github.swagger2markup.internal.resolver; -import io.github.swagger2markup.Swagger2MarkupConfig; import io.github.swagger2markup.Swagger2MarkupConverter; import io.github.swagger2markup.builder.Swagger2MarkupConfigBuilder; -import io.github.swagger2markup.markup.builder.MarkupLanguage; +import io.github.swagger2markup.config.MarkupLanguage; import org.junit.Test; import java.nio.file.FileSystems; @@ -33,28 +32,28 @@ public class DefinitionDocumentResolverDefaultTest { @Test public void testDefault() { - Swagger2MarkupConverter.Context context = createContext(); + Swagger2MarkupConverter.SwaggerContext context = createContext(); assertThat(new DefinitionDocumentResolverDefault(context).apply("DefinitionName")).isNull(); } @Test public void testWithSeparatedDefinitions() { - Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() + Swagger2MarkupConfigBuilder.Swagger2MarkupConfig config = (Swagger2MarkupConfigBuilder.Swagger2MarkupConfig) new Swagger2MarkupConfigBuilder() .withSeparatedDefinitions() .build(); - Swagger2MarkupConverter.Context context = createContext(config); + Swagger2MarkupConverter.SwaggerContext context = createContext(config); assertThat(new DefinitionDocumentResolverDefault(context).apply("DefinitionName")).isNull(); } @Test public void testWithSeparatedDefinitionsAndInterDocumentCrossReferences() { - Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() + Swagger2MarkupConfigBuilder.Swagger2MarkupConfig config = (Swagger2MarkupConfigBuilder.Swagger2MarkupConfig) new Swagger2MarkupConfigBuilder() .withSeparatedDefinitions() .withInterDocumentCrossReferences() .build(); - Swagger2MarkupConverter.Context context = createContext(config); + Swagger2MarkupConverter.SwaggerContext context = createContext(config); context.setOutputPath(Paths.get("/tmp")); assertThat(new DefinitionDocumentResolverDefault(context).apply("DefinitionName")) @@ -63,10 +62,10 @@ public class DefinitionDocumentResolverDefaultTest { @Test public void testWithInterDocumentCrossReferences() { - Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() + Swagger2MarkupConfigBuilder.Swagger2MarkupConfig config = (Swagger2MarkupConfigBuilder.Swagger2MarkupConfig) new Swagger2MarkupConfigBuilder() .withInterDocumentCrossReferences() .build(); - Swagger2MarkupConverter.Context context = createContext(config); + Swagger2MarkupConverter.SwaggerContext context = createContext(config); context.setOutputPath(Paths.get("/tmp")); assertThat(new DefinitionDocumentResolverDefault(context).apply("DefinitionName")) @@ -75,10 +74,10 @@ public class DefinitionDocumentResolverDefaultTest { @Test public void testWithInterDocumentCrossReferencesAndPrefix() { - Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() + Swagger2MarkupConfigBuilder.Swagger2MarkupConfig config = (Swagger2MarkupConfigBuilder.Swagger2MarkupConfig) new Swagger2MarkupConfigBuilder() .withInterDocumentCrossReferences("prefix_") .build(); - Swagger2MarkupConverter.Context context = createContext(config); + Swagger2MarkupConverter.SwaggerContext context = createContext(config); context.setOutputPath(Paths.get("/tmp")); assertThat(new DefinitionDocumentResolverDefault(context).apply("DefinitionName")) @@ -87,11 +86,11 @@ public class DefinitionDocumentResolverDefaultTest { @Test public void testWithInterDocumentCrossReferencesAndMarkdown() { - Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() + Swagger2MarkupConfigBuilder.Swagger2MarkupConfig config = (Swagger2MarkupConfigBuilder.Swagger2MarkupConfig) new Swagger2MarkupConfigBuilder() .withInterDocumentCrossReferences() .withMarkupLanguage(MarkupLanguage.MARKDOWN) .build(); - Swagger2MarkupConverter.Context context = createContext(config); + Swagger2MarkupConverter.SwaggerContext context = createContext(config); context.setOutputPath(Paths.get("/tmp")); assertThat(new DefinitionDocumentResolverDefault(context).apply("DefinitionName")) diff --git a/swagger2markup-core/src/test/java/io/github/swagger2markup/internal/resolver/DefinitionDocumentResolverFromDefinitionTest.java b/swagger2markup/src/test/java/io/github/swagger2markup/internal/resolver/DefinitionDocumentResolverFromDefinitionTest.java similarity index 72% rename from swagger2markup-core/src/test/java/io/github/swagger2markup/internal/resolver/DefinitionDocumentResolverFromDefinitionTest.java rename to swagger2markup/src/test/java/io/github/swagger2markup/internal/resolver/DefinitionDocumentResolverFromDefinitionTest.java index b5681070..ed467041 100644 --- a/swagger2markup-core/src/test/java/io/github/swagger2markup/internal/resolver/DefinitionDocumentResolverFromDefinitionTest.java +++ b/swagger2markup/src/test/java/io/github/swagger2markup/internal/resolver/DefinitionDocumentResolverFromDefinitionTest.java @@ -15,10 +15,10 @@ */ package io.github.swagger2markup.internal.resolver; -import io.github.swagger2markup.Swagger2MarkupConfig; import io.github.swagger2markup.Swagger2MarkupConverter; import io.github.swagger2markup.builder.Swagger2MarkupConfigBuilder; -import io.github.swagger2markup.markup.builder.MarkupLanguage; +import io.github.swagger2markup.builder.Swagger2MarkupConfigBuilder.Swagger2MarkupConfig; +import io.github.swagger2markup.config.MarkupLanguage; import org.junit.Test; import java.nio.file.Paths; @@ -30,28 +30,28 @@ public class DefinitionDocumentResolverFromDefinitionTest { @Test public void testDefault() { - Swagger2MarkupConverter.Context context = createContext(); + Swagger2MarkupConverter.SwaggerContext context = createContext(); assertThat(new DefinitionDocumentResolverFromDefinition(context).apply("DefinitionName")).isNull(); } @Test public void testWithSeparatedDefinitions() { - Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() + Swagger2MarkupConfig config = (Swagger2MarkupConfig) new Swagger2MarkupConfigBuilder() .withSeparatedDefinitions() .build(); - Swagger2MarkupConverter.Context context = createContext(config); + Swagger2MarkupConverter.SwaggerContext context = createContext(config); assertThat(new DefinitionDocumentResolverFromDefinition(context).apply("DefinitionName")).isNull(); } @Test public void testWithSeparatedDefinitionsAndInterDocumentCrossReferences() { - Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() + Swagger2MarkupConfig config = (Swagger2MarkupConfig) new Swagger2MarkupConfigBuilder() .withSeparatedDefinitions() .withInterDocumentCrossReferences() .build(); - Swagger2MarkupConverter.Context context = createContext(config); + Swagger2MarkupConverter.SwaggerContext context = createContext(config); context.setOutputPath(Paths.get("/tmp")); assertThat(new DefinitionDocumentResolverFromDefinition(context).apply("DefinitionName")) @@ -60,10 +60,10 @@ public class DefinitionDocumentResolverFromDefinitionTest { @Test public void testWithInterDocumentCrossReferences() { - Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() + Swagger2MarkupConfig config = (Swagger2MarkupConfig) new Swagger2MarkupConfigBuilder() .withInterDocumentCrossReferences() .build(); - Swagger2MarkupConverter.Context context = createContext(config); + Swagger2MarkupConverter.SwaggerContext context = createContext(config); context.setOutputPath(Paths.get("/tmp")); assertThat(new DefinitionDocumentResolverFromDefinition(context).apply("DefinitionName")) @@ -72,10 +72,10 @@ public class DefinitionDocumentResolverFromDefinitionTest { @Test public void testWithInterDocumentCrossReferencesAndNoOutputPath() { - Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() + Swagger2MarkupConfig config = (Swagger2MarkupConfig) new Swagger2MarkupConfigBuilder() .withInterDocumentCrossReferences() .build(); - Swagger2MarkupConverter.Context context = createContext(config); + Swagger2MarkupConverter.SwaggerContext context = createContext(config); assertThat(new DefinitionDocumentResolverFromDefinition(context).apply("DefinitionName")) .isNull(); @@ -83,10 +83,10 @@ public class DefinitionDocumentResolverFromDefinitionTest { @Test public void testWithInterDocumentCrossReferencesAndPrefix() { - Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() + Swagger2MarkupConfig config = (Swagger2MarkupConfig) new Swagger2MarkupConfigBuilder() .withInterDocumentCrossReferences("prefix_") .build(); - Swagger2MarkupConverter.Context context = createContext(config); + Swagger2MarkupConverter.SwaggerContext context = createContext(config); context.setOutputPath(Paths.get("/tmp")); assertThat(new DefinitionDocumentResolverFromDefinition(context).apply("DefinitionName")) @@ -95,11 +95,11 @@ public class DefinitionDocumentResolverFromDefinitionTest { @Test public void testWithInterDocumentCrossReferencesAndMarkdown() { - Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() + Swagger2MarkupConfig config = (Swagger2MarkupConfig) new Swagger2MarkupConfigBuilder() .withInterDocumentCrossReferences() .withMarkupLanguage(MarkupLanguage.MARKDOWN) .build(); - Swagger2MarkupConverter.Context context = createContext(config); + Swagger2MarkupConverter.SwaggerContext context = createContext(config); context.setOutputPath(Paths.get("/tmp")); assertThat(new DefinitionDocumentResolverFromDefinition(context).apply("DefinitionName")) diff --git a/swagger2markup-core/src/test/java/io/github/swagger2markup/internal/resolver/DefinitionDocumentResolverFromOperationTest.java b/swagger2markup/src/test/java/io/github/swagger2markup/internal/resolver/DefinitionDocumentResolverFromOperationTest.java similarity index 73% rename from swagger2markup-core/src/test/java/io/github/swagger2markup/internal/resolver/DefinitionDocumentResolverFromOperationTest.java rename to swagger2markup/src/test/java/io/github/swagger2markup/internal/resolver/DefinitionDocumentResolverFromOperationTest.java index 3229982c..937ca270 100644 --- a/swagger2markup-core/src/test/java/io/github/swagger2markup/internal/resolver/DefinitionDocumentResolverFromOperationTest.java +++ b/swagger2markup/src/test/java/io/github/swagger2markup/internal/resolver/DefinitionDocumentResolverFromOperationTest.java @@ -15,10 +15,10 @@ */ package io.github.swagger2markup.internal.resolver; -import io.github.swagger2markup.Swagger2MarkupConfig; import io.github.swagger2markup.Swagger2MarkupConverter; import io.github.swagger2markup.builder.Swagger2MarkupConfigBuilder; -import io.github.swagger2markup.markup.builder.MarkupLanguage; +import io.github.swagger2markup.builder.Swagger2MarkupConfigBuilder.Swagger2MarkupConfig; +import io.github.swagger2markup.config.MarkupLanguage; import org.junit.Test; import java.nio.file.FileSystems; @@ -33,28 +33,28 @@ public class DefinitionDocumentResolverFromOperationTest { @Test public void testDefault() { - Swagger2MarkupConverter.Context context = createContext(); + Swagger2MarkupConverter.SwaggerContext context = createContext(); assertThat(new DefinitionDocumentResolverFromOperation(context).apply("DefinitionName")).isNull(); } @Test public void testWithSeparatedDefinitions() { - Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() + Swagger2MarkupConfig config = (Swagger2MarkupConfig) new Swagger2MarkupConfigBuilder() .withSeparatedDefinitions() .build(); - Swagger2MarkupConverter.Context context = createContext(config); + Swagger2MarkupConverter.SwaggerContext context = createContext(config); assertThat(new DefinitionDocumentResolverFromOperation(context).apply("DefinitionName")).isNull(); } @Test public void testWithSeparatedOperationsAndInterDocumentCrossReferences() { - Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() + Swagger2MarkupConfig config = (Swagger2MarkupConfig) new Swagger2MarkupConfigBuilder() .withSeparatedOperations() .withInterDocumentCrossReferences() .build(); - Swagger2MarkupConverter.Context context = createContext(config); + Swagger2MarkupConverter.SwaggerContext context = createContext(config); context.setOutputPath(Paths.get("/tmp")); assertThat(new DefinitionDocumentResolverFromOperation(context).apply("DefinitionName")) @@ -63,12 +63,12 @@ public class DefinitionDocumentResolverFromOperationTest { @Test public void testWithSeparatedOperationsAndSeparatedDefinitionsAndInterDocumentCrossReferences() { - Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() + Swagger2MarkupConfig config = (Swagger2MarkupConfig) new Swagger2MarkupConfigBuilder() .withSeparatedOperations() .withSeparatedDefinitions() .withInterDocumentCrossReferences() .build(); - Swagger2MarkupConverter.Context context = createContext(config); + Swagger2MarkupConverter.SwaggerContext context = createContext(config); context.setOutputPath(Paths.get("/tmp")); assertThat(new DefinitionDocumentResolverFromOperation(context).apply("DefinitionName")) @@ -77,10 +77,10 @@ public class DefinitionDocumentResolverFromOperationTest { @Test public void testWithInterDocumentCrossReferences() { - Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() + Swagger2MarkupConfig config = (Swagger2MarkupConfig) new Swagger2MarkupConfigBuilder() .withInterDocumentCrossReferences() .build(); - Swagger2MarkupConverter.Context context = createContext(config); + Swagger2MarkupConverter.SwaggerContext context = createContext(config); context.setOutputPath(Paths.get("/tmp")); assertThat(new DefinitionDocumentResolverFromOperation(context).apply("DefinitionName")) @@ -89,10 +89,10 @@ public class DefinitionDocumentResolverFromOperationTest { @Test public void testWithInterDocumentCrossReferencesAndNoOutputPath() { - Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() + Swagger2MarkupConfig config = (Swagger2MarkupConfig) new Swagger2MarkupConfigBuilder() .withInterDocumentCrossReferences() .build(); - Swagger2MarkupConverter.Context context = createContext(config); + Swagger2MarkupConverter.SwaggerContext context = createContext(config); assertThat(new DefinitionDocumentResolverFromOperation(context).apply("DefinitionName")) .isNull(); @@ -100,10 +100,10 @@ public class DefinitionDocumentResolverFromOperationTest { @Test public void testWithInterDocumentCrossReferencesAndPrefix() { - Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() + Swagger2MarkupConfig config = (Swagger2MarkupConfig) new Swagger2MarkupConfigBuilder() .withInterDocumentCrossReferences("prefix_") .build(); - Swagger2MarkupConverter.Context context = createContext(config); + Swagger2MarkupConverter.SwaggerContext context = createContext(config); context.setOutputPath(Paths.get("/tmp")); assertThat(new DefinitionDocumentResolverFromOperation(context).apply("DefinitionName")) @@ -112,11 +112,11 @@ public class DefinitionDocumentResolverFromOperationTest { @Test public void testWithInterDocumentCrossReferencesAndMarkdown() { - Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() + Swagger2MarkupConfig config = (Swagger2MarkupConfig) new Swagger2MarkupConfigBuilder() .withInterDocumentCrossReferences() .withMarkupLanguage(MarkupLanguage.MARKDOWN) .build(); - Swagger2MarkupConverter.Context context = createContext(config); + Swagger2MarkupConverter.SwaggerContext context = createContext(config); context.setOutputPath(Paths.get("/tmp")); assertThat(new DefinitionDocumentResolverFromOperation(context).apply("DefinitionName")) diff --git a/swagger2markup-core/src/test/java/io/github/swagger2markup/internal/resolver/OperationDocumentNameResolverTest.java b/swagger2markup/src/test/java/io/github/swagger2markup/internal/resolver/OperationDocumentNameResolverTest.java similarity index 64% rename from swagger2markup-core/src/test/java/io/github/swagger2markup/internal/resolver/OperationDocumentNameResolverTest.java rename to swagger2markup/src/test/java/io/github/swagger2markup/internal/resolver/OperationDocumentNameResolverTest.java index b15fcc62..885effbc 100644 --- a/swagger2markup-core/src/test/java/io/github/swagger2markup/internal/resolver/OperationDocumentNameResolverTest.java +++ b/swagger2markup/src/test/java/io/github/swagger2markup/internal/resolver/OperationDocumentNameResolverTest.java @@ -15,11 +15,11 @@ */ package io.github.swagger2markup.internal.resolver; -import io.github.swagger2markup.Swagger2MarkupConfig; import io.github.swagger2markup.Swagger2MarkupConverter; import io.github.swagger2markup.builder.Swagger2MarkupConfigBuilder; -import io.github.swagger2markup.markup.builder.MarkupLanguage; -import io.github.swagger2markup.model.PathOperation; +import io.github.swagger2markup.builder.Swagger2MarkupConfigBuilder.Swagger2MarkupConfig; +import io.github.swagger2markup.config.MarkupLanguage; +import io.github.swagger2markup.model.SwaggerPathOperation; import io.swagger.models.HttpMethod; import io.swagger.models.Operation; import org.junit.Before; @@ -35,26 +35,29 @@ public class OperationDocumentNameResolverTest { private final String fileSeparator = FileSystems.getDefault().getSeparator(); - private PathOperation operation; + private SwaggerPathOperation operation; @Before public void setUp() { - operation = new PathOperation(HttpMethod.GET, "/test", new Operation()); + String method = HttpMethod.GET.name(); + String path = "/test"; + operation = new SwaggerPathOperation(method, path, path + " " + method.toLowerCase(), + method + " " + path, new Operation()); } @Test public void testDefault() { - Swagger2MarkupConverter.Context context = createContext(); + Swagger2MarkupConverter.SwaggerContext context = createContext(); assertThat(new OperationDocumentNameResolver(context).apply(operation)).isEqualTo("paths.adoc"); } @Test public void testWithSeparatedOperations() { - Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() + Swagger2MarkupConfig config = (Swagger2MarkupConfig) new Swagger2MarkupConfigBuilder() .withSeparatedOperations() .build(); - Swagger2MarkupConverter.Context context = createContext(config); + Swagger2MarkupConverter.SwaggerContext context = createContext(config); assertThat(new OperationDocumentNameResolver(context).apply(operation)) .isEqualTo("operations" + fileSeparator + "test_get.adoc"); @@ -62,11 +65,11 @@ public class OperationDocumentNameResolverTest { @Test public void testWithSeparatedOperationsAndInterDocumentCrossReferences() { - Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() + Swagger2MarkupConfig config = (Swagger2MarkupConfig) new Swagger2MarkupConfigBuilder() .withSeparatedOperations() .withInterDocumentCrossReferences() .build(); - Swagger2MarkupConverter.Context context = createContext(config); + Swagger2MarkupConverter.SwaggerContext context = createContext(config); assertThat(new OperationDocumentNameResolver(context).apply(operation)) .isEqualTo("operations" + fileSeparator + "test_get.adoc"); @@ -74,10 +77,10 @@ public class OperationDocumentNameResolverTest { @Test public void testWithInterDocumentCrossReferencesAndNoOutputPath() { - Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() + Swagger2MarkupConfig config = (Swagger2MarkupConfig) new Swagger2MarkupConfigBuilder() .withInterDocumentCrossReferences() .build(); - Swagger2MarkupConverter.Context context = createContext(config); + Swagger2MarkupConverter.SwaggerContext context = createContext(config); assertThat(new OperationDocumentNameResolver(context).apply(operation)) .isEqualTo("paths.adoc"); @@ -85,10 +88,10 @@ public class OperationDocumentNameResolverTest { @Test public void testWithInterDocumentCrossReferences() { - Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() + Swagger2MarkupConfig config = (Swagger2MarkupConfig) new Swagger2MarkupConfigBuilder() .withInterDocumentCrossReferences() .build(); - Swagger2MarkupConverter.Context context = createContext(config); + Swagger2MarkupConverter.SwaggerContext context = createContext(config); context.setOutputPath(Paths.get("/tmp")); assertThat(new OperationDocumentNameResolver(context).apply(operation)) @@ -97,23 +100,27 @@ public class OperationDocumentNameResolverTest { @Test public void testWithInterDocumentCrossReferencesAndPrefix() { - Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() + Swagger2MarkupConfig config = (Swagger2MarkupConfig) new Swagger2MarkupConfigBuilder() .withInterDocumentCrossReferences("prefix_") .build(); - Swagger2MarkupConverter.Context context = createContext(config); + Swagger2MarkupConverter.SwaggerContext context = createContext(config); context.setOutputPath(Paths.get("/tmp")); - assertThat(new OperationDocumentNameResolver(context).apply(new PathOperation(HttpMethod.GET, "/test", new Operation()))) + String method = HttpMethod.GET.toString(); + String path = "/test"; + SwaggerPathOperation operation = new SwaggerPathOperation(method, path, path + " " + method.toLowerCase(), + method + " " + path, new Operation()); + assertThat(new OperationDocumentNameResolver(context).apply(operation)) .isEqualTo("paths.adoc"); } @Test public void testWithInterDocumentCrossReferencesAndMarkdown() { - Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() + Swagger2MarkupConfig config = (Swagger2MarkupConfig) new Swagger2MarkupConfigBuilder() .withInterDocumentCrossReferences() .withMarkupLanguage(MarkupLanguage.MARKDOWN) .build(); - Swagger2MarkupConverter.Context context = createContext(config); + Swagger2MarkupConverter.SwaggerContext context = createContext(config); context.setOutputPath(Paths.get("/tmp")); assertThat(new OperationDocumentNameResolver(context).apply(operation)) diff --git a/swagger2markup-core/src/test/java/io/github/swagger2markup/internal/resolver/OperationDocumentResolverDefaultTest.java b/swagger2markup/src/test/java/io/github/swagger2markup/internal/resolver/OperationDocumentResolverDefaultTest.java similarity index 70% rename from swagger2markup-core/src/test/java/io/github/swagger2markup/internal/resolver/OperationDocumentResolverDefaultTest.java rename to swagger2markup/src/test/java/io/github/swagger2markup/internal/resolver/OperationDocumentResolverDefaultTest.java index 143520f6..1eb30b4e 100644 --- a/swagger2markup-core/src/test/java/io/github/swagger2markup/internal/resolver/OperationDocumentResolverDefaultTest.java +++ b/swagger2markup/src/test/java/io/github/swagger2markup/internal/resolver/OperationDocumentResolverDefaultTest.java @@ -15,11 +15,12 @@ */ package io.github.swagger2markup.internal.resolver; -import io.github.swagger2markup.Swagger2MarkupConfig; import io.github.swagger2markup.Swagger2MarkupConverter; import io.github.swagger2markup.builder.Swagger2MarkupConfigBuilder; -import io.github.swagger2markup.markup.builder.MarkupLanguage; +import io.github.swagger2markup.builder.Swagger2MarkupConfigBuilder.Swagger2MarkupConfig; +import io.github.swagger2markup.config.MarkupLanguage; import io.github.swagger2markup.model.PathOperation; +import io.github.swagger2markup.model.SwaggerPathOperation; import io.swagger.models.HttpMethod; import io.swagger.models.Operation; import org.junit.Before; @@ -39,33 +40,36 @@ public class OperationDocumentResolverDefaultTest { @Before public void setUp() { - operation = new PathOperation(HttpMethod.GET, "/test", new Operation()); + String method = HttpMethod.GET.name(); + String path = "/test"; + operation = new SwaggerPathOperation(method, path, path + " " + method.toLowerCase(), + method + " " + path, new Operation()); } @Test public void testDefault() { - Swagger2MarkupConverter.Context context = createContext(); + Swagger2MarkupConverter.SwaggerContext context = createContext(); assertThat(new OperationDocumentResolverDefault(context).apply(operation)).isNull(); } @Test public void testWithSeparatedOperations() { - Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() + Swagger2MarkupConfig config = (Swagger2MarkupConfig) new Swagger2MarkupConfigBuilder() .withSeparatedOperations() .build(); - Swagger2MarkupConverter.Context context = createContext(config); + Swagger2MarkupConverter.SwaggerContext context = createContext(config); assertThat(new OperationDocumentResolverDefault(context).apply(operation)).isNull(); } @Test public void testWithSeparatedOperationsAndInterDocumentCrossReferences() { - Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() + Swagger2MarkupConfig config = (Swagger2MarkupConfig) new Swagger2MarkupConfigBuilder() .withSeparatedOperations() .withInterDocumentCrossReferences() .build(); - Swagger2MarkupConverter.Context context = createContext(config); + Swagger2MarkupConverter.SwaggerContext context = createContext(config); context.setOutputPath(Paths.get("/tmp")); assertThat(new OperationDocumentResolverDefault(context).apply(operation)) @@ -74,10 +78,10 @@ public class OperationDocumentResolverDefaultTest { @Test public void testWithInterDocumentCrossReferences() { - Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() + Swagger2MarkupConfig config = (Swagger2MarkupConfig) new Swagger2MarkupConfigBuilder() .withInterDocumentCrossReferences() .build(); - Swagger2MarkupConverter.Context context = createContext(config); + Swagger2MarkupConverter.SwaggerContext context = createContext(config); context.setOutputPath(Paths.get("/tmp")); assertThat(new OperationDocumentResolverDefault(context).apply(operation)) @@ -86,10 +90,10 @@ public class OperationDocumentResolverDefaultTest { @Test public void testWithInterDocumentCrossReferencesAndPrefix() { - Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() + Swagger2MarkupConfig config = (Swagger2MarkupConfig) new Swagger2MarkupConfigBuilder() .withInterDocumentCrossReferences("prefix_") .build(); - Swagger2MarkupConverter.Context context = createContext(config); + Swagger2MarkupConverter.SwaggerContext context = createContext(config); context.setOutputPath(Paths.get("/tmp")); assertThat(new OperationDocumentResolverDefault(context).apply(operation)) @@ -98,11 +102,11 @@ public class OperationDocumentResolverDefaultTest { @Test public void testWithInterDocumentCrossReferencesAndMarkdown() { - Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() + Swagger2MarkupConfig config = (Swagger2MarkupConfig) new Swagger2MarkupConfigBuilder() .withInterDocumentCrossReferences() .withMarkupLanguage(MarkupLanguage.MARKDOWN) .build(); - Swagger2MarkupConverter.Context context = createContext(config); + Swagger2MarkupConverter.SwaggerContext context = createContext(config); context.setOutputPath(Paths.get("/tmp")); assertThat(new OperationDocumentResolverDefault(context).apply(operation)) diff --git a/swagger2markup-core/src/test/java/io/github/swagger2markup/internal/resolver/SecurityDocumentResolverTest.java b/swagger2markup/src/test/java/io/github/swagger2markup/internal/resolver/SecurityDocumentResolverTest.java similarity index 73% rename from swagger2markup-core/src/test/java/io/github/swagger2markup/internal/resolver/SecurityDocumentResolverTest.java rename to swagger2markup/src/test/java/io/github/swagger2markup/internal/resolver/SecurityDocumentResolverTest.java index f9eb8542..3f912f60 100644 --- a/swagger2markup-core/src/test/java/io/github/swagger2markup/internal/resolver/SecurityDocumentResolverTest.java +++ b/swagger2markup/src/test/java/io/github/swagger2markup/internal/resolver/SecurityDocumentResolverTest.java @@ -15,10 +15,10 @@ */ package io.github.swagger2markup.internal.resolver; -import io.github.swagger2markup.Swagger2MarkupConfig; import io.github.swagger2markup.Swagger2MarkupConverter; import io.github.swagger2markup.builder.Swagger2MarkupConfigBuilder; -import io.github.swagger2markup.markup.builder.MarkupLanguage; +import io.github.swagger2markup.builder.Swagger2MarkupConfigBuilder.Swagger2MarkupConfig; +import io.github.swagger2markup.config.MarkupLanguage; import org.junit.Test; import java.nio.file.Paths; @@ -30,17 +30,17 @@ public class SecurityDocumentResolverTest { @Test public void testDefault() { - Swagger2MarkupConverter.Context context = createContext(); + Swagger2MarkupConverter.SwaggerContext context = createContext(); assertThat(new SecurityDocumentResolver(context).apply("petstore_auth")).isNull(); } @Test public void testWithInterDocumentCrossReferencesAndNoOutputPath() { - Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() + Swagger2MarkupConfig config = (Swagger2MarkupConfig) new Swagger2MarkupConfigBuilder() .withInterDocumentCrossReferences() .build(); - Swagger2MarkupConverter.Context context = createContext(config); + Swagger2MarkupConverter.SwaggerContext context = createContext(config); assertThat(new SecurityDocumentResolver(context).apply("petstore_auth")) .isNull(); @@ -48,10 +48,10 @@ public class SecurityDocumentResolverTest { @Test public void testWithInterDocumentCrossReferences() { - Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() + Swagger2MarkupConfig config = (Swagger2MarkupConfig) new Swagger2MarkupConfigBuilder() .withInterDocumentCrossReferences() .build(); - Swagger2MarkupConverter.Context context = createContext(config); + Swagger2MarkupConverter.SwaggerContext context = createContext(config); context.setOutputPath(Paths.get("/tmp")); assertThat(new SecurityDocumentResolver(context).apply("petstore_auth")) @@ -60,10 +60,10 @@ public class SecurityDocumentResolverTest { @Test public void testWithInterDocumentCrossReferencesAndPrefix() { - Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() + Swagger2MarkupConfig config = (Swagger2MarkupConfig) new Swagger2MarkupConfigBuilder() .withInterDocumentCrossReferences("prefix_") .build(); - Swagger2MarkupConverter.Context context = createContext(config); + Swagger2MarkupConverter.SwaggerContext context = createContext(config); context.setOutputPath(Paths.get("/tmp")); assertThat(new SecurityDocumentResolver(context).apply("petstore_auth")) @@ -72,11 +72,11 @@ public class SecurityDocumentResolverTest { @Test public void testWithInterDocumentCrossReferencesAndMarkdown() { - Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() + Swagger2MarkupConfig config = (Swagger2MarkupConfig) new Swagger2MarkupConfigBuilder() .withInterDocumentCrossReferences() .withMarkupLanguage(MarkupLanguage.MARKDOWN) .build(); - Swagger2MarkupConverter.Context context = createContext(config); + Swagger2MarkupConverter.SwaggerContext context = createContext(config); context.setOutputPath(Paths.get("/tmp")); assertThat(new SecurityDocumentResolver(context).apply("petstore_auth")) diff --git a/swagger2markup-core/src/test/resources/component/body_parameter.adoc b/swagger2markup/src/test/resources/component/body_parameter.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/component/body_parameter.adoc rename to swagger2markup/src/test/resources/component/body_parameter.adoc diff --git a/swagger2markup-core/src/test/resources/component/consumes.adoc b/swagger2markup/src/test/resources/component/consumes.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/component/consumes.adoc rename to swagger2markup/src/test/resources/component/consumes.adoc diff --git a/swagger2markup-core/src/test/resources/component/contact_info.adoc b/swagger2markup/src/test/resources/component/contact_info.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/component/contact_info.adoc rename to swagger2markup/src/test/resources/component/contact_info.adoc diff --git a/swagger2markup-core/src/test/resources/component/definition.adoc b/swagger2markup/src/test/resources/component/definition.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/component/definition.adoc rename to swagger2markup/src/test/resources/component/definition.adoc diff --git a/swagger2markup-core/src/test/resources/component/external_docs.adoc b/swagger2markup/src/test/resources/component/external_docs.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/component/external_docs.adoc rename to swagger2markup/src/test/resources/component/external_docs.adoc diff --git a/swagger2markup-core/src/test/resources/component/license_info.adoc b/swagger2markup/src/test/resources/component/license_info.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/component/license_info.adoc rename to swagger2markup/src/test/resources/component/license_info.adoc diff --git a/swagger2markup-core/src/test/resources/component/parameter_table.adoc b/swagger2markup/src/test/resources/component/parameter_table.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/component/parameter_table.adoc rename to swagger2markup/src/test/resources/component/parameter_table.adoc diff --git a/swagger2markup-core/src/test/resources/component/path_operation.adoc b/swagger2markup/src/test/resources/component/path_operation.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/component/path_operation.adoc rename to swagger2markup/src/test/resources/component/path_operation.adoc diff --git a/swagger2markup-core/src/test/resources/component/path_operation_inline_schema.adoc b/swagger2markup/src/test/resources/component/path_operation_inline_schema.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/component/path_operation_inline_schema.adoc rename to swagger2markup/src/test/resources/component/path_operation_inline_schema.adoc diff --git a/swagger2markup-core/src/test/resources/component/path_operation_with_body_param_example.adoc b/swagger2markup/src/test/resources/component/path_operation_with_body_param_example.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/component/path_operation_with_body_param_example.adoc rename to swagger2markup/src/test/resources/component/path_operation_with_body_param_example.adoc diff --git a/swagger2markup-core/src/test/resources/component/path_operation_with_path_param_example.adoc b/swagger2markup/src/test/resources/component/path_operation_with_path_param_example.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/component/path_operation_with_path_param_example.adoc rename to swagger2markup/src/test/resources/component/path_operation_with_path_param_example.adoc diff --git a/swagger2markup-core/src/test/resources/component/path_operation_with_query_param_example.adoc b/swagger2markup/src/test/resources/component/path_operation_with_query_param_example.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/component/path_operation_with_query_param_example.adoc rename to swagger2markup/src/test/resources/component/path_operation_with_query_param_example.adoc diff --git a/swagger2markup-core/src/test/resources/component/produces.adoc b/swagger2markup/src/test/resources/component/produces.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/component/produces.adoc rename to swagger2markup/src/test/resources/component/produces.adoc diff --git a/swagger2markup-core/src/test/resources/component/properties_table.adoc b/swagger2markup/src/test/resources/component/properties_table.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/component/properties_table.adoc rename to swagger2markup/src/test/resources/component/properties_table.adoc diff --git a/swagger2markup-core/src/test/resources/component/responses.adoc b/swagger2markup/src/test/resources/component/responses.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/component/responses.adoc rename to swagger2markup/src/test/resources/component/responses.adoc diff --git a/swagger2markup-core/src/test/resources/component/security_scheme.adoc b/swagger2markup/src/test/resources/component/security_scheme.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/component/security_scheme.adoc rename to swagger2markup/src/test/resources/component/security_scheme.adoc diff --git a/swagger2markup-core/src/test/resources/component/security_scheme_definition.adoc b/swagger2markup/src/test/resources/component/security_scheme_definition.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/component/security_scheme_definition.adoc rename to swagger2markup/src/test/resources/component/security_scheme_definition.adoc diff --git a/swagger2markup-core/src/test/resources/component/security_scheme_definition_api_key.adoc b/swagger2markup/src/test/resources/component/security_scheme_definition_api_key.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/component/security_scheme_definition_api_key.adoc rename to swagger2markup/src/test/resources/component/security_scheme_definition_api_key.adoc diff --git a/swagger2markup-core/src/test/resources/component/security_scheme_definition_oauth.adoc b/swagger2markup/src/test/resources/component/security_scheme_definition_oauth.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/component/security_scheme_definition_oauth.adoc rename to swagger2markup/src/test/resources/component/security_scheme_definition_oauth.adoc diff --git a/swagger2markup-core/src/test/resources/component/table.adoc b/swagger2markup/src/test/resources/component/table.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/component/table.adoc rename to swagger2markup/src/test/resources/component/table.adoc diff --git a/swagger2markup-core/src/test/resources/component/tags.adoc b/swagger2markup/src/test/resources/component/tags.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/component/tags.adoc rename to swagger2markup/src/test/resources/component/tags.adoc diff --git a/swagger2markup-core/src/test/resources/component/uri_scheme.adoc b/swagger2markup/src/test/resources/component/uri_scheme.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/component/uri_scheme.adoc rename to swagger2markup/src/test/resources/component/uri_scheme.adoc diff --git a/swagger2markup-core/src/test/resources/component/version_info.adoc b/swagger2markup/src/test/resources/component/version_info.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/component/version_info.adoc rename to swagger2markup/src/test/resources/component/version_info.adoc diff --git a/swagger2markup-core/src/test/resources/config/config.properties b/swagger2markup/src/test/resources/config/config.properties similarity index 100% rename from swagger2markup-core/src/test/resources/config/config.properties rename to swagger2markup/src/test/resources/config/config.properties diff --git a/swagger2markup-core/src/test/resources/docs/asciidoc/index.adoc b/swagger2markup/src/test/resources/docs/asciidoc/index.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/docs/asciidoc/index.adoc rename to swagger2markup/src/test/resources/docs/asciidoc/index.adoc diff --git a/swagger2markup-core/src/test/resources/docs/asciidoc/paths/addPet/curl-request.adoc b/swagger2markup/src/test/resources/docs/asciidoc/paths/addPet/curl-request.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/docs/asciidoc/paths/addPet/curl-request.adoc rename to swagger2markup/src/test/resources/docs/asciidoc/paths/addPet/curl-request.adoc diff --git a/swagger2markup-core/src/test/resources/docs/asciidoc/paths/addPet/http-request.adoc b/swagger2markup/src/test/resources/docs/asciidoc/paths/addPet/http-request.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/docs/asciidoc/paths/addPet/http-request.adoc rename to swagger2markup/src/test/resources/docs/asciidoc/paths/addPet/http-request.adoc diff --git a/swagger2markup-core/src/test/resources/docs/asciidoc/paths/addPet/http-response.adoc b/swagger2markup/src/test/resources/docs/asciidoc/paths/addPet/http-response.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/docs/asciidoc/paths/addPet/http-response.adoc rename to swagger2markup/src/test/resources/docs/asciidoc/paths/addPet/http-response.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/basepathprefix/definitions.adoc b/swagger2markup/src/test/resources/expected/asciidoc/basepathprefix/definitions.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/basepathprefix/definitions.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/basepathprefix/definitions.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/basepathprefix/overview.adoc b/swagger2markup/src/test/resources/expected/asciidoc/basepathprefix/overview.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/basepathprefix/overview.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/basepathprefix/overview.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/basepathprefix/paths.adoc b/swagger2markup/src/test/resources/expected/asciidoc/basepathprefix/paths.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/basepathprefix/paths.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/basepathprefix/paths.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/basepathprefix/security.adoc b/swagger2markup/src/test/resources/expected/asciidoc/basepathprefix/security.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/basepathprefix/security.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/basepathprefix/security.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/empty_tables/definitions.adoc b/swagger2markup/src/test/resources/expected/asciidoc/empty_tables/definitions.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/empty_tables/definitions.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/empty_tables/definitions.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/empty_tables/overview.adoc b/swagger2markup/src/test/resources/expected/asciidoc/empty_tables/overview.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/empty_tables/overview.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/empty_tables/overview.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/empty_tables/paths.adoc b/swagger2markup/src/test/resources/expected/asciidoc/empty_tables/paths.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/empty_tables/paths.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/empty_tables/paths.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/empty_tables/security.adoc b/swagger2markup/src/test/resources/expected/asciidoc/empty_tables/security.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/empty_tables/security.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/empty_tables/security.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/emptycontact/definitions.adoc b/swagger2markup/src/test/resources/expected/asciidoc/emptycontact/definitions.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/emptycontact/definitions.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/emptycontact/definitions.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/emptycontact/overview.adoc b/swagger2markup/src/test/resources/expected/asciidoc/emptycontact/overview.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/emptycontact/overview.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/emptycontact/overview.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/emptycontact/paths.adoc b/swagger2markup/src/test/resources/expected/asciidoc/emptycontact/paths.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/emptycontact/paths.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/emptycontact/paths.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/emptycontact/security.adoc b/swagger2markup/src/test/resources/expected/asciidoc/emptycontact/security.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/emptycontact/security.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/emptycontact/security.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/enums/definitions.adoc b/swagger2markup/src/test/resources/expected/asciidoc/enums/definitions.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/enums/definitions.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/enums/definitions.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/enums/overview.adoc b/swagger2markup/src/test/resources/expected/asciidoc/enums/overview.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/enums/overview.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/enums/overview.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/enums/paths.adoc b/swagger2markup/src/test/resources/expected/asciidoc/enums/paths.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/enums/paths.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/enums/paths.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/enums/security.adoc b/swagger2markup/src/test/resources/expected/asciidoc/enums/security.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/enums/security.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/enums/security.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/examples/definitions.adoc b/swagger2markup/src/test/resources/expected/asciidoc/examples/definitions.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/examples/definitions.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/examples/definitions.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/examples/overview.adoc b/swagger2markup/src/test/resources/expected/asciidoc/examples/overview.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/examples/overview.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/examples/overview.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/examples/paths.adoc b/swagger2markup/src/test/resources/expected/asciidoc/examples/paths.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/examples/paths.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/examples/paths.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/examples/security.adoc b/swagger2markup/src/test/resources/expected/asciidoc/examples/security.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/examples/security.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/examples/security.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/format/definitions.adoc b/swagger2markup/src/test/resources/expected/asciidoc/format/definitions.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/format/definitions.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/format/definitions.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/format/overview.adoc b/swagger2markup/src/test/resources/expected/asciidoc/format/overview.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/format/overview.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/format/overview.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/format/paths.adoc b/swagger2markup/src/test/resources/expected/asciidoc/format/paths.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/format/paths.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/format/paths.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/format/security.adoc b/swagger2markup/src/test/resources/expected/asciidoc/format/security.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/format/security.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/format/security.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/generated/definitions.adoc b/swagger2markup/src/test/resources/expected/asciidoc/generated/definitions.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/generated/definitions.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/generated/definitions.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/generated/definitions/Category.adoc b/swagger2markup/src/test/resources/expected/asciidoc/generated/definitions/Category.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/generated/definitions/Category.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/generated/definitions/Category.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/generated/definitions/Order.adoc b/swagger2markup/src/test/resources/expected/asciidoc/generated/definitions/Order.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/generated/definitions/Order.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/generated/definitions/Order.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/generated/definitions/Pet.adoc b/swagger2markup/src/test/resources/expected/asciidoc/generated/definitions/Pet.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/generated/definitions/Pet.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/generated/definitions/Pet.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/generated/definitions/Tag.adoc b/swagger2markup/src/test/resources/expected/asciidoc/generated/definitions/Tag.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/generated/definitions/Tag.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/generated/definitions/Tag.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/generated/definitions/User.adoc b/swagger2markup/src/test/resources/expected/asciidoc/generated/definitions/User.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/generated/definitions/User.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/generated/definitions/User.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/generated/overview.adoc b/swagger2markup/src/test/resources/expected/asciidoc/generated/overview.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/generated/overview.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/generated/overview.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/generated/paths.adoc b/swagger2markup/src/test/resources/expected/asciidoc/generated/paths.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/generated/paths.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/generated/paths.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/generated/security.adoc b/swagger2markup/src/test/resources/expected/asciidoc/generated/security.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/generated/security.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/generated/security.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/generated_examples/definitions.adoc b/swagger2markup/src/test/resources/expected/asciidoc/generated_examples/definitions.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/generated_examples/definitions.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/generated_examples/definitions.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/generated_examples/overview.adoc b/swagger2markup/src/test/resources/expected/asciidoc/generated_examples/overview.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/generated_examples/overview.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/generated_examples/overview.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/generated_examples/paths.adoc b/swagger2markup/src/test/resources/expected/asciidoc/generated_examples/paths.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/generated_examples/paths.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/generated_examples/paths.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/generated_examples/security.adoc b/swagger2markup/src/test/resources/expected/asciidoc/generated_examples/security.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/generated_examples/security.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/generated_examples/security.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/generated_examples_inline_response/definitions.adoc b/swagger2markup/src/test/resources/expected/asciidoc/generated_examples_inline_response/definitions.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/generated_examples_inline_response/definitions.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/generated_examples_inline_response/definitions.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/generated_examples_inline_response/overview.adoc b/swagger2markup/src/test/resources/expected/asciidoc/generated_examples_inline_response/overview.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/generated_examples_inline_response/overview.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/generated_examples_inline_response/overview.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/generated_examples_inline_response/paths.adoc b/swagger2markup/src/test/resources/expected/asciidoc/generated_examples_inline_response/paths.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/generated_examples_inline_response/paths.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/generated_examples_inline_response/paths.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/generated_examples_inline_response/security.adoc b/swagger2markup/src/test/resources/expected/asciidoc/generated_examples_inline_response/security.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/generated_examples_inline_response/security.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/generated_examples_inline_response/security.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/generated_examples_required_parameters/definitions.adoc b/swagger2markup/src/test/resources/expected/asciidoc/generated_examples_required_parameters/definitions.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/generated_examples_required_parameters/definitions.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/generated_examples_required_parameters/definitions.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/generated_examples_required_parameters/overview.adoc b/swagger2markup/src/test/resources/expected/asciidoc/generated_examples_required_parameters/overview.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/generated_examples_required_parameters/overview.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/generated_examples_required_parameters/overview.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/generated_examples_required_parameters/paths.adoc b/swagger2markup/src/test/resources/expected/asciidoc/generated_examples_required_parameters/paths.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/generated_examples_required_parameters/paths.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/generated_examples_required_parameters/paths.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/generated_examples_required_parameters/security.adoc b/swagger2markup/src/test/resources/expected/asciidoc/generated_examples_required_parameters/security.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/generated_examples_required_parameters/security.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/generated_examples_required_parameters/security.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/generated_recursion_examples/definitions.adoc b/swagger2markup/src/test/resources/expected/asciidoc/generated_recursion_examples/definitions.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/generated_recursion_examples/definitions.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/generated_recursion_examples/definitions.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/generated_recursion_examples/overview.adoc b/swagger2markup/src/test/resources/expected/asciidoc/generated_recursion_examples/overview.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/generated_recursion_examples/overview.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/generated_recursion_examples/overview.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/generated_recursion_examples/paths.adoc b/swagger2markup/src/test/resources/expected/asciidoc/generated_recursion_examples/paths.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/generated_recursion_examples/paths.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/generated_recursion_examples/paths.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/generated_recursion_examples/security.adoc b/swagger2markup/src/test/resources/expected/asciidoc/generated_recursion_examples/security.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/generated_recursion_examples/security.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/generated_recursion_examples/security.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/group_by_tags/definitions.adoc b/swagger2markup/src/test/resources/expected/asciidoc/group_by_tags/definitions.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/group_by_tags/definitions.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/group_by_tags/definitions.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/group_by_tags/overview.adoc b/swagger2markup/src/test/resources/expected/asciidoc/group_by_tags/overview.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/group_by_tags/overview.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/group_by_tags/overview.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/group_by_tags/paths.adoc b/swagger2markup/src/test/resources/expected/asciidoc/group_by_tags/paths.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/group_by_tags/paths.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/group_by_tags/paths.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/group_by_tags/security.adoc b/swagger2markup/src/test/resources/expected/asciidoc/group_by_tags/security.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/group_by_tags/security.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/group_by_tags/security.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/idxref/definitions.adoc b/swagger2markup/src/test/resources/expected/asciidoc/idxref/definitions.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/idxref/definitions.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/idxref/definitions.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/idxref/overview.adoc b/swagger2markup/src/test/resources/expected/asciidoc/idxref/overview.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/idxref/overview.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/idxref/overview.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/idxref/paths.adoc b/swagger2markup/src/test/resources/expected/asciidoc/idxref/paths.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/idxref/paths.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/idxref/paths.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/idxref/security.adoc b/swagger2markup/src/test/resources/expected/asciidoc/idxref/security.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/idxref/security.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/idxref/security.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/inline_schema/definitions.adoc b/swagger2markup/src/test/resources/expected/asciidoc/inline_schema/definitions.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/inline_schema/definitions.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/inline_schema/definitions.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/inline_schema/overview.adoc b/swagger2markup/src/test/resources/expected/asciidoc/inline_schema/overview.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/inline_schema/overview.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/inline_schema/overview.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/inline_schema/paths.adoc b/swagger2markup/src/test/resources/expected/asciidoc/inline_schema/paths.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/inline_schema/paths.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/inline_schema/paths.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/inline_schema/security.adoc b/swagger2markup/src/test/resources/expected/asciidoc/inline_schema/security.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/inline_schema/security.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/inline_schema/security.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/inline_schema_flat_body/definitions.adoc b/swagger2markup/src/test/resources/expected/asciidoc/inline_schema_flat_body/definitions.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/inline_schema_flat_body/definitions.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/inline_schema_flat_body/definitions.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/inline_schema_flat_body/overview.adoc b/swagger2markup/src/test/resources/expected/asciidoc/inline_schema_flat_body/overview.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/inline_schema_flat_body/overview.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/inline_schema_flat_body/overview.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/inline_schema_flat_body/paths.adoc b/swagger2markup/src/test/resources/expected/asciidoc/inline_schema_flat_body/paths.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/inline_schema_flat_body/paths.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/inline_schema_flat_body/paths.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/inline_schema_flat_body/security.adoc b/swagger2markup/src/test/resources/expected/asciidoc/inline_schema_flat_body/security.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/inline_schema_flat_body/security.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/inline_schema_flat_body/security.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/instagram/definitions.adoc b/swagger2markup/src/test/resources/expected/asciidoc/instagram/definitions.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/instagram/definitions.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/instagram/definitions.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/instagram/overview.adoc b/swagger2markup/src/test/resources/expected/asciidoc/instagram/overview.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/instagram/overview.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/instagram/overview.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/instagram/paths.adoc b/swagger2markup/src/test/resources/expected/asciidoc/instagram/paths.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/instagram/paths.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/instagram/paths.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/instagram/security.adoc b/swagger2markup/src/test/resources/expected/asciidoc/instagram/security.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/instagram/security.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/instagram/security.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/issue/definitions.adoc b/swagger2markup/src/test/resources/expected/asciidoc/issue/definitions.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/issue/definitions.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/issue/definitions.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/issue/overview.adoc b/swagger2markup/src/test/resources/expected/asciidoc/issue/overview.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/issue/overview.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/issue/overview.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/issue/paths.adoc b/swagger2markup/src/test/resources/expected/asciidoc/issue/paths.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/issue/paths.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/issue/paths.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/issue/security.adoc b/swagger2markup/src/test/resources/expected/asciidoc/issue/security.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/issue/security.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/issue/security.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/maps/definitions.adoc b/swagger2markup/src/test/resources/expected/asciidoc/maps/definitions.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/maps/definitions.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/maps/definitions.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/maps/overview.adoc b/swagger2markup/src/test/resources/expected/asciidoc/maps/overview.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/maps/overview.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/maps/overview.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/maps/paths.adoc b/swagger2markup/src/test/resources/expected/asciidoc/maps/paths.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/maps/paths.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/maps/paths.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/maps/security.adoc b/swagger2markup/src/test/resources/expected/asciidoc/maps/security.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/maps/security.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/maps/security.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/ordering_asis/definitions.adoc b/swagger2markup/src/test/resources/expected/asciidoc/ordering_asis/definitions.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/ordering_asis/definitions.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/ordering_asis/definitions.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/ordering_asis/overview.adoc b/swagger2markup/src/test/resources/expected/asciidoc/ordering_asis/overview.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/ordering_asis/overview.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/ordering_asis/overview.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/ordering_asis/paths.adoc b/swagger2markup/src/test/resources/expected/asciidoc/ordering_asis/paths.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/ordering_asis/paths.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/ordering_asis/paths.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/ordering_asis/security.adoc b/swagger2markup/src/test/resources/expected/asciidoc/ordering_asis/security.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/ordering_asis/security.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/ordering_asis/security.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/ordering_natural/definitions.adoc b/swagger2markup/src/test/resources/expected/asciidoc/ordering_natural/definitions.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/ordering_natural/definitions.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/ordering_natural/definitions.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/ordering_natural/overview.adoc b/swagger2markup/src/test/resources/expected/asciidoc/ordering_natural/overview.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/ordering_natural/overview.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/ordering_natural/overview.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/ordering_natural/paths.adoc b/swagger2markup/src/test/resources/expected/asciidoc/ordering_natural/paths.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/ordering_natural/paths.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/ordering_natural/paths.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/ordering_natural/security.adoc b/swagger2markup/src/test/resources/expected/asciidoc/ordering_natural/security.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/ordering_natural/security.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/ordering_natural/security.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/ordering_regex/definitions.adoc b/swagger2markup/src/test/resources/expected/asciidoc/ordering_regex/definitions.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/ordering_regex/definitions.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/ordering_regex/definitions.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/ordering_regex/overview.adoc b/swagger2markup/src/test/resources/expected/asciidoc/ordering_regex/overview.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/ordering_regex/overview.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/ordering_regex/overview.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/ordering_regex/paths.adoc b/swagger2markup/src/test/resources/expected/asciidoc/ordering_regex/paths.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/ordering_regex/paths.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/ordering_regex/paths.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/ordering_regex/security.adoc b/swagger2markup/src/test/resources/expected/asciidoc/ordering_regex/security.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/ordering_regex/security.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/ordering_regex/security.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/page_breaks/definitions.adoc b/swagger2markup/src/test/resources/expected/asciidoc/page_breaks/definitions.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/page_breaks/definitions.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/page_breaks/definitions.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/page_breaks/overview.adoc b/swagger2markup/src/test/resources/expected/asciidoc/page_breaks/overview.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/page_breaks/overview.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/page_breaks/overview.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/page_breaks/paths.adoc b/swagger2markup/src/test/resources/expected/asciidoc/page_breaks/paths.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/page_breaks/paths.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/page_breaks/paths.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/page_breaks/security.adoc b/swagger2markup/src/test/resources/expected/asciidoc/page_breaks/security.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/page_breaks/security.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/page_breaks/security.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/polymorphism/definitions.adoc b/swagger2markup/src/test/resources/expected/asciidoc/polymorphism/definitions.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/polymorphism/definitions.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/polymorphism/definitions.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/polymorphism/overview.adoc b/swagger2markup/src/test/resources/expected/asciidoc/polymorphism/overview.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/polymorphism/overview.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/polymorphism/overview.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/polymorphism/paths.adoc b/swagger2markup/src/test/resources/expected/asciidoc/polymorphism/paths.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/polymorphism/paths.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/polymorphism/paths.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/polymorphism/security.adoc b/swagger2markup/src/test/resources/expected/asciidoc/polymorphism/security.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/polymorphism/security.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/polymorphism/security.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/polymorphismAsIsOrdering/definitions.adoc b/swagger2markup/src/test/resources/expected/asciidoc/polymorphismAsIsOrdering/definitions.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/polymorphismAsIsOrdering/definitions.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/polymorphismAsIsOrdering/definitions.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/polymorphismAsIsOrdering/overview.adoc b/swagger2markup/src/test/resources/expected/asciidoc/polymorphismAsIsOrdering/overview.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/polymorphismAsIsOrdering/overview.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/polymorphismAsIsOrdering/overview.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/polymorphismAsIsOrdering/paths.adoc b/swagger2markup/src/test/resources/expected/asciidoc/polymorphismAsIsOrdering/paths.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/polymorphismAsIsOrdering/paths.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/polymorphismAsIsOrdering/paths.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/polymorphismAsIsOrdering/security.adoc b/swagger2markup/src/test/resources/expected/asciidoc/polymorphismAsIsOrdering/security.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/polymorphismAsIsOrdering/security.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/polymorphismAsIsOrdering/security.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/response_headers/definitions.adoc b/swagger2markup/src/test/resources/expected/asciidoc/response_headers/definitions.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/response_headers/definitions.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/response_headers/definitions.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/response_headers/overview.adoc b/swagger2markup/src/test/resources/expected/asciidoc/response_headers/overview.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/response_headers/overview.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/response_headers/overview.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/response_headers/paths.adoc b/swagger2markup/src/test/resources/expected/asciidoc/response_headers/paths.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/response_headers/paths.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/response_headers/paths.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/response_headers/security.adoc b/swagger2markup/src/test/resources/expected/asciidoc/response_headers/security.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/response_headers/security.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/response_headers/security.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/to_file/swagger.adoc b/swagger2markup/src/test/resources/expected/asciidoc/to_file/swagger.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/to_file/swagger.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/to_file/swagger.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/to_folder/definitions.adoc b/swagger2markup/src/test/resources/expected/asciidoc/to_folder/definitions.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/to_folder/definitions.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/to_folder/definitions.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/to_folder/overview.adoc b/swagger2markup/src/test/resources/expected/asciidoc/to_folder/overview.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/to_folder/overview.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/to_folder/overview.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/to_folder/paths.adoc b/swagger2markup/src/test/resources/expected/asciidoc/to_folder/paths.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/to_folder/paths.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/to_folder/paths.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/to_folder/security.adoc b/swagger2markup/src/test/resources/expected/asciidoc/to_folder/security.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/to_folder/security.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/to_folder/security.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/url_examples/definitions.adoc b/swagger2markup/src/test/resources/expected/asciidoc/url_examples/definitions.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/url_examples/definitions.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/url_examples/definitions.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/url_examples/overview.adoc b/swagger2markup/src/test/resources/expected/asciidoc/url_examples/overview.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/url_examples/overview.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/url_examples/overview.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/url_examples/paths.adoc b/swagger2markup/src/test/resources/expected/asciidoc/url_examples/paths.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/url_examples/paths.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/url_examples/paths.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/url_examples/security.adoc b/swagger2markup/src/test/resources/expected/asciidoc/url_examples/security.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/url_examples/security.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/url_examples/security.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/validators/definitions.adoc b/swagger2markup/src/test/resources/expected/asciidoc/validators/definitions.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/validators/definitions.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/validators/definitions.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/validators/overview.adoc b/swagger2markup/src/test/resources/expected/asciidoc/validators/overview.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/validators/overview.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/validators/overview.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/validators/paths.adoc b/swagger2markup/src/test/resources/expected/asciidoc/validators/paths.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/validators/paths.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/validators/paths.adoc diff --git a/swagger2markup-core/src/test/resources/expected/asciidoc/validators/security.adoc b/swagger2markup/src/test/resources/expected/asciidoc/validators/security.adoc similarity index 100% rename from swagger2markup-core/src/test/resources/expected/asciidoc/validators/security.adoc rename to swagger2markup/src/test/resources/expected/asciidoc/validators/security.adoc diff --git a/swagger2markup-core/src/test/resources/expected/markdown/freeform/definitions.md b/swagger2markup/src/test/resources/expected/markdown/freeform/definitions.md similarity index 100% rename from swagger2markup-core/src/test/resources/expected/markdown/freeform/definitions.md rename to swagger2markup/src/test/resources/expected/markdown/freeform/definitions.md diff --git a/swagger2markup-core/src/test/resources/expected/markdown/freeform/definitions/FreeForm.md b/swagger2markup/src/test/resources/expected/markdown/freeform/definitions/FreeForm.md similarity index 100% rename from swagger2markup-core/src/test/resources/expected/markdown/freeform/definitions/FreeForm.md rename to swagger2markup/src/test/resources/expected/markdown/freeform/definitions/FreeForm.md diff --git a/swagger2markup-core/src/test/resources/expected/markdown/freeform/overview.md b/swagger2markup/src/test/resources/expected/markdown/freeform/overview.md similarity index 100% rename from swagger2markup-core/src/test/resources/expected/markdown/freeform/overview.md rename to swagger2markup/src/test/resources/expected/markdown/freeform/overview.md diff --git a/swagger2markup-core/src/test/resources/expected/markdown/freeform/paths.md b/swagger2markup/src/test/resources/expected/markdown/freeform/paths.md similarity index 100% rename from swagger2markup-core/src/test/resources/expected/markdown/freeform/paths.md rename to swagger2markup/src/test/resources/expected/markdown/freeform/paths.md diff --git a/swagger2markup-core/src/test/resources/expected/markdown/freeform/security.md b/swagger2markup/src/test/resources/expected/markdown/freeform/security.md similarity index 100% rename from swagger2markup-core/src/test/resources/expected/markdown/freeform/security.md rename to swagger2markup/src/test/resources/expected/markdown/freeform/security.md diff --git a/swagger2markup-core/src/test/resources/expected/markdown/idxref/definitions.md b/swagger2markup/src/test/resources/expected/markdown/idxref/definitions.md similarity index 100% rename from swagger2markup-core/src/test/resources/expected/markdown/idxref/definitions.md rename to swagger2markup/src/test/resources/expected/markdown/idxref/definitions.md diff --git a/swagger2markup-core/src/test/resources/expected/markdown/idxref/overview.md b/swagger2markup/src/test/resources/expected/markdown/idxref/overview.md similarity index 100% rename from swagger2markup-core/src/test/resources/expected/markdown/idxref/overview.md rename to swagger2markup/src/test/resources/expected/markdown/idxref/overview.md diff --git a/swagger2markup-core/src/test/resources/expected/markdown/idxref/paths.md b/swagger2markup/src/test/resources/expected/markdown/idxref/paths.md similarity index 100% rename from swagger2markup-core/src/test/resources/expected/markdown/idxref/paths.md rename to swagger2markup/src/test/resources/expected/markdown/idxref/paths.md diff --git a/swagger2markup-core/src/test/resources/expected/markdown/idxref/security.md b/swagger2markup/src/test/resources/expected/markdown/idxref/security.md similarity index 100% rename from swagger2markup-core/src/test/resources/expected/markdown/idxref/security.md rename to swagger2markup/src/test/resources/expected/markdown/idxref/security.md diff --git a/swagger2markup-core/src/test/resources/expected/markdown/min_max_items/definitions.md b/swagger2markup/src/test/resources/expected/markdown/min_max_items/definitions.md similarity index 100% rename from swagger2markup-core/src/test/resources/expected/markdown/min_max_items/definitions.md rename to swagger2markup/src/test/resources/expected/markdown/min_max_items/definitions.md diff --git a/swagger2markup-core/src/test/resources/expected/markdown/min_max_items/overview.md b/swagger2markup/src/test/resources/expected/markdown/min_max_items/overview.md similarity index 100% rename from swagger2markup-core/src/test/resources/expected/markdown/min_max_items/overview.md rename to swagger2markup/src/test/resources/expected/markdown/min_max_items/overview.md diff --git a/swagger2markup-core/src/test/resources/expected/markdown/min_max_items/paths.md b/swagger2markup/src/test/resources/expected/markdown/min_max_items/paths.md similarity index 100% rename from swagger2markup-core/src/test/resources/expected/markdown/min_max_items/paths.md rename to swagger2markup/src/test/resources/expected/markdown/min_max_items/paths.md diff --git a/swagger2markup-core/src/test/resources/expected/markdown/min_max_items/security.md b/swagger2markup/src/test/resources/expected/markdown/min_max_items/security.md similarity index 100% rename from swagger2markup-core/src/test/resources/expected/markdown/min_max_items/security.md rename to swagger2markup/src/test/resources/expected/markdown/min_max_items/security.md diff --git a/swagger2markup-core/src/test/resources/expected/markdown/response_headers/definitions.md b/swagger2markup/src/test/resources/expected/markdown/response_headers/definitions.md similarity index 100% rename from swagger2markup-core/src/test/resources/expected/markdown/response_headers/definitions.md rename to swagger2markup/src/test/resources/expected/markdown/response_headers/definitions.md diff --git a/swagger2markup-core/src/test/resources/expected/markdown/response_headers/overview.md b/swagger2markup/src/test/resources/expected/markdown/response_headers/overview.md similarity index 100% rename from swagger2markup-core/src/test/resources/expected/markdown/response_headers/overview.md rename to swagger2markup/src/test/resources/expected/markdown/response_headers/overview.md diff --git a/swagger2markup-core/src/test/resources/expected/markdown/response_headers/paths.md b/swagger2markup/src/test/resources/expected/markdown/response_headers/paths.md similarity index 100% rename from swagger2markup-core/src/test/resources/expected/markdown/response_headers/paths.md rename to swagger2markup/src/test/resources/expected/markdown/response_headers/paths.md diff --git a/swagger2markup-core/src/test/resources/expected/markdown/response_headers/security.md b/swagger2markup/src/test/resources/expected/markdown/response_headers/security.md similarity index 100% rename from swagger2markup-core/src/test/resources/expected/markdown/response_headers/security.md rename to swagger2markup/src/test/resources/expected/markdown/response_headers/security.md diff --git a/swagger2markup-core/src/test/resources/expected/markdown/to_folder/definitions.md b/swagger2markup/src/test/resources/expected/markdown/to_folder/definitions.md similarity index 100% rename from swagger2markup-core/src/test/resources/expected/markdown/to_folder/definitions.md rename to swagger2markup/src/test/resources/expected/markdown/to_folder/definitions.md diff --git a/swagger2markup-core/src/test/resources/expected/markdown/to_folder/overview.md b/swagger2markup/src/test/resources/expected/markdown/to_folder/overview.md similarity index 100% rename from swagger2markup-core/src/test/resources/expected/markdown/to_folder/overview.md rename to swagger2markup/src/test/resources/expected/markdown/to_folder/overview.md diff --git a/swagger2markup-core/src/test/resources/expected/markdown/to_folder/paths.md b/swagger2markup/src/test/resources/expected/markdown/to_folder/paths.md similarity index 100% rename from swagger2markup-core/src/test/resources/expected/markdown/to_folder/paths.md rename to swagger2markup/src/test/resources/expected/markdown/to_folder/paths.md diff --git a/swagger2markup-core/src/test/resources/expected/markdown/to_folder/security.md b/swagger2markup/src/test/resources/expected/markdown/to_folder/security.md similarity index 100% rename from swagger2markup-core/src/test/resources/expected/markdown/to_folder/security.md rename to swagger2markup/src/test/resources/expected/markdown/to_folder/security.md diff --git a/swagger2markup-core/src/test/resources/json/error_swagger_12.json b/swagger2markup/src/test/resources/json/error_swagger_12.json similarity index 100% rename from swagger2markup-core/src/test/resources/json/error_swagger_12.json rename to swagger2markup/src/test/resources/json/error_swagger_12.json diff --git a/swagger2markup-core/src/test/resources/json/swagger_12.json b/swagger2markup/src/test/resources/json/swagger_12.json similarity index 100% rename from swagger2markup-core/src/test/resources/json/swagger_12.json rename to swagger2markup/src/test/resources/json/swagger_12.json diff --git a/swagger2markup-core/src/test/resources/json/swagger_empty_tables.json b/swagger2markup/src/test/resources/json/swagger_empty_tables.json similarity index 100% rename from swagger2markup-core/src/test/resources/json/swagger_empty_tables.json rename to swagger2markup/src/test/resources/json/swagger_empty_tables.json diff --git a/swagger2markup-core/src/test/resources/json/swagger_emptycontact.json b/swagger2markup/src/test/resources/json/swagger_emptycontact.json similarity index 100% rename from swagger2markup-core/src/test/resources/json/swagger_emptycontact.json rename to swagger2markup/src/test/resources/json/swagger_emptycontact.json diff --git a/swagger2markup-core/src/test/resources/json/swagger_enums.json b/swagger2markup/src/test/resources/json/swagger_enums.json similarity index 100% rename from swagger2markup-core/src/test/resources/json/swagger_enums.json rename to swagger2markup/src/test/resources/json/swagger_enums.json diff --git a/swagger2markup-core/src/test/resources/json/swagger_examples.json b/swagger2markup/src/test/resources/json/swagger_examples.json similarity index 100% rename from swagger2markup-core/src/test/resources/json/swagger_examples.json rename to swagger2markup/src/test/resources/json/swagger_examples.json diff --git a/swagger2markup-core/src/test/resources/json/swagger_maps.json b/swagger2markup/src/test/resources/json/swagger_maps.json similarity index 100% rename from swagger2markup-core/src/test/resources/json/swagger_maps.json rename to swagger2markup/src/test/resources/json/swagger_maps.json diff --git a/swagger2markup-core/src/test/resources/json/swagger_missing_tag.json b/swagger2markup/src/test/resources/json/swagger_missing_tag.json similarity index 100% rename from swagger2markup-core/src/test/resources/json/swagger_missing_tag.json rename to swagger2markup/src/test/resources/json/swagger_missing_tag.json diff --git a/swagger2markup-core/src/test/resources/json/swagger_polymorphism.json b/swagger2markup/src/test/resources/json/swagger_polymorphism.json similarity index 100% rename from swagger2markup-core/src/test/resources/json/swagger_polymorphism.json rename to swagger2markup/src/test/resources/json/swagger_polymorphism.json diff --git a/swagger2markup-core/src/test/resources/json/swagger_recursion.json b/swagger2markup/src/test/resources/json/swagger_recursion.json similarity index 100% rename from swagger2markup-core/src/test/resources/json/swagger_recursion.json rename to swagger2markup/src/test/resources/json/swagger_recursion.json diff --git a/swagger2markup-core/src/test/resources/json/swagger_validators.json b/swagger2markup/src/test/resources/json/swagger_validators.json similarity index 100% rename from swagger2markup-core/src/test/resources/json/swagger_validators.json rename to swagger2markup/src/test/resources/json/swagger_validators.json diff --git a/swagger2markup-core/src/test/resources/yaml/modules/definitions.yaml b/swagger2markup/src/test/resources/yaml/modules/definitions.yaml similarity index 100% rename from swagger2markup-core/src/test/resources/yaml/modules/definitions.yaml rename to swagger2markup/src/test/resources/yaml/modules/definitions.yaml diff --git a/swagger2markup-core/src/test/resources/yaml/modules/info.yaml b/swagger2markup/src/test/resources/yaml/modules/info.yaml similarity index 100% rename from swagger2markup-core/src/test/resources/yaml/modules/info.yaml rename to swagger2markup/src/test/resources/yaml/modules/info.yaml diff --git a/swagger2markup-core/src/test/resources/yaml/modules/parameters.yaml b/swagger2markup/src/test/resources/yaml/modules/parameters.yaml similarity index 100% rename from swagger2markup-core/src/test/resources/yaml/modules/parameters.yaml rename to swagger2markup/src/test/resources/yaml/modules/parameters.yaml diff --git a/swagger2markup-core/src/test/resources/yaml/modules/paths.yaml b/swagger2markup/src/test/resources/yaml/modules/paths.yaml similarity index 100% rename from swagger2markup-core/src/test/resources/yaml/modules/paths.yaml rename to swagger2markup/src/test/resources/yaml/modules/paths.yaml diff --git a/swagger2markup-core/src/test/resources/yaml/modules/responses.yaml b/swagger2markup/src/test/resources/yaml/modules/responses.yaml similarity index 100% rename from swagger2markup-core/src/test/resources/yaml/modules/responses.yaml rename to swagger2markup/src/test/resources/yaml/modules/responses.yaml diff --git a/swagger2markup-core/src/test/resources/yaml/modules/security_definitions.yaml b/swagger2markup/src/test/resources/yaml/modules/security_definitions.yaml similarity index 100% rename from swagger2markup-core/src/test/resources/yaml/modules/security_definitions.yaml rename to swagger2markup/src/test/resources/yaml/modules/security_definitions.yaml diff --git a/swagger2markup-core/src/test/resources/yaml/modules/swagger_petstore.yaml b/swagger2markup/src/test/resources/yaml/modules/swagger_petstore.yaml similarity index 100% rename from swagger2markup-core/src/test/resources/yaml/modules/swagger_petstore.yaml rename to swagger2markup/src/test/resources/yaml/modules/swagger_petstore.yaml diff --git a/swagger2markup-core/src/test/resources/yaml/modules/tags.yaml b/swagger2markup/src/test/resources/yaml/modules/tags.yaml similarity index 100% rename from swagger2markup-core/src/test/resources/yaml/modules/tags.yaml rename to swagger2markup/src/test/resources/yaml/modules/tags.yaml diff --git a/swagger2markup-core/src/test/resources/yaml/swagger_examples_inline_response.yaml b/swagger2markup/src/test/resources/yaml/swagger_examples_inline_response.yaml similarity index 100% rename from swagger2markup-core/src/test/resources/yaml/swagger_examples_inline_response.yaml rename to swagger2markup/src/test/resources/yaml/swagger_examples_inline_response.yaml diff --git a/swagger2markup-core/src/test/resources/yaml/swagger_examples_required_parameters.yaml b/swagger2markup/src/test/resources/yaml/swagger_examples_required_parameters.yaml similarity index 100% rename from swagger2markup-core/src/test/resources/yaml/swagger_examples_required_parameters.yaml rename to swagger2markup/src/test/resources/yaml/swagger_examples_required_parameters.yaml diff --git a/swagger2markup-core/src/test/resources/yaml/swagger_flatBody.yaml b/swagger2markup/src/test/resources/yaml/swagger_flatBody.yaml similarity index 100% rename from swagger2markup-core/src/test/resources/yaml/swagger_flatBody.yaml rename to swagger2markup/src/test/resources/yaml/swagger_flatBody.yaml diff --git a/swagger2markup-core/src/test/resources/yaml/swagger_format.yaml b/swagger2markup/src/test/resources/yaml/swagger_format.yaml similarity index 100% rename from swagger2markup-core/src/test/resources/yaml/swagger_format.yaml rename to swagger2markup/src/test/resources/yaml/swagger_format.yaml diff --git a/swagger2markup-core/src/test/resources/yaml/swagger_freeform_with_emtpy_curly_brackets.yaml b/swagger2markup/src/test/resources/yaml/swagger_freeform_with_emtpy_curly_brackets.yaml similarity index 100% rename from swagger2markup-core/src/test/resources/yaml/swagger_freeform_with_emtpy_curly_brackets.yaml rename to swagger2markup/src/test/resources/yaml/swagger_freeform_with_emtpy_curly_brackets.yaml diff --git a/swagger2markup-core/src/test/resources/yaml/swagger_inlineSchema.yaml b/swagger2markup/src/test/resources/yaml/swagger_inlineSchema.yaml similarity index 100% rename from swagger2markup-core/src/test/resources/yaml/swagger_inlineSchema.yaml rename to swagger2markup/src/test/resources/yaml/swagger_inlineSchema.yaml diff --git a/swagger2markup-core/src/test/resources/yaml/swagger_instagram.yaml b/swagger2markup/src/test/resources/yaml/swagger_instagram.yaml similarity index 100% rename from swagger2markup-core/src/test/resources/yaml/swagger_instagram.yaml rename to swagger2markup/src/test/resources/yaml/swagger_instagram.yaml diff --git a/swagger2markup-core/src/test/resources/yaml/swagger_ordering.yaml b/swagger2markup/src/test/resources/yaml/swagger_ordering.yaml similarity index 100% rename from swagger2markup-core/src/test/resources/yaml/swagger_ordering.yaml rename to swagger2markup/src/test/resources/yaml/swagger_ordering.yaml diff --git a/swagger2markup-core/src/test/resources/yaml/swagger_ordering_regex.yaml b/swagger2markup/src/test/resources/yaml/swagger_ordering_regex.yaml similarity index 100% rename from swagger2markup-core/src/test/resources/yaml/swagger_ordering_regex.yaml rename to swagger2markup/src/test/resources/yaml/swagger_ordering_regex.yaml diff --git a/swagger2markup-core/src/test/resources/yaml/swagger_overwrites.yaml b/swagger2markup/src/test/resources/yaml/swagger_overwrites.yaml similarity index 100% rename from swagger2markup-core/src/test/resources/yaml/swagger_overwrites.yaml rename to swagger2markup/src/test/resources/yaml/swagger_overwrites.yaml diff --git a/swagger2markup-core/src/test/resources/yaml/swagger_petstore.yaml b/swagger2markup/src/test/resources/yaml/swagger_petstore.yaml similarity index 100% rename from swagger2markup-core/src/test/resources/yaml/swagger_petstore.yaml rename to swagger2markup/src/test/resources/yaml/swagger_petstore.yaml diff --git a/swagger2markup-core/src/test/resources/yaml/swagger_petstore_20160612.yaml b/swagger2markup/src/test/resources/yaml/swagger_petstore_20160612.yaml similarity index 100% rename from swagger2markup-core/src/test/resources/yaml/swagger_petstore_20160612.yaml rename to swagger2markup/src/test/resources/yaml/swagger_petstore_20160612.yaml diff --git a/swagger2markup-core/src/test/resources/yaml/swagger_petstore_body_examples.yaml b/swagger2markup/src/test/resources/yaml/swagger_petstore_body_examples.yaml similarity index 100% rename from swagger2markup-core/src/test/resources/yaml/swagger_petstore_body_examples.yaml rename to swagger2markup/src/test/resources/yaml/swagger_petstore_body_examples.yaml diff --git a/swagger2markup-core/src/test/resources/yaml/swagger_petstore_min_max_items.yaml b/swagger2markup/src/test/resources/yaml/swagger_petstore_min_max_items.yaml similarity index 100% rename from swagger2markup-core/src/test/resources/yaml/swagger_petstore_min_max_items.yaml rename to swagger2markup/src/test/resources/yaml/swagger_petstore_min_max_items.yaml diff --git a/swagger2markup-core/src/test/resources/yaml/swagger_petstore_with_adoc_content.yaml b/swagger2markup/src/test/resources/yaml/swagger_petstore_with_adoc_content.yaml similarity index 100% rename from swagger2markup-core/src/test/resources/yaml/swagger_petstore_with_adoc_content.yaml rename to swagger2markup/src/test/resources/yaml/swagger_petstore_with_adoc_content.yaml diff --git a/swagger2markup-core/src/test/resources/yaml/swagger_response_headers.yaml b/swagger2markup/src/test/resources/yaml/swagger_response_headers.yaml similarity index 100% rename from swagger2markup-core/src/test/resources/yaml/swagger_response_headers.yaml rename to swagger2markup/src/test/resources/yaml/swagger_response_headers.yaml diff --git a/swagger2markup-core/src/test/resources/yaml/swagger_security.yaml b/swagger2markup/src/test/resources/yaml/swagger_security.yaml similarity index 100% rename from swagger2markup-core/src/test/resources/yaml/swagger_security.yaml rename to swagger2markup/src/test/resources/yaml/swagger_security.yaml diff --git a/swagger2markup-core/src/test/resources/yaml/swagger_should_contain_uri_scheme.yaml b/swagger2markup/src/test/resources/yaml/swagger_should_contain_uri_scheme.yaml similarity index 100% rename from swagger2markup-core/src/test/resources/yaml/swagger_should_contain_uri_scheme.yaml rename to swagger2markup/src/test/resources/yaml/swagger_should_contain_uri_scheme.yaml diff --git a/swagger2markup-core/src/test/resources/yaml/swagger_should_not_contain_uri_scheme.yaml b/swagger2markup/src/test/resources/yaml/swagger_should_not_contain_uri_scheme.yaml similarity index 100% rename from swagger2markup-core/src/test/resources/yaml/swagger_should_not_contain_uri_scheme.yaml rename to swagger2markup/src/test/resources/yaml/swagger_should_not_contain_uri_scheme.yaml diff --git a/swagger2markup-core/src/test/resources/yaml/swagger_url_examples.yaml b/swagger2markup/src/test/resources/yaml/swagger_url_examples.yaml similarity index 100% rename from swagger2markup-core/src/test/resources/yaml/swagger_url_examples.yaml rename to swagger2markup/src/test/resources/yaml/swagger_url_examples.yaml