Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
04fed3d4d5 | ||
|
|
1ead6614ba | ||
|
|
887e63464d | ||
|
|
47e5d5e56e | ||
|
|
c505c1e88e | ||
|
|
6a8c04c031 | ||
|
|
33f68a7f41 | ||
|
|
c5af8676e5 | ||
|
|
618898cb09 | ||
|
|
36bdcc57d9 |
27
README.adoc
@@ -9,25 +9,22 @@ image:https://travis-ci.org/Swagger2Markup/swagger2markup.svg?branch=master["Bui
|
||||
|
||||
The primary goal of this project is to *simplify the generation of an up-to-date RESTful API documentation by combining documentation that's been hand-written with auto-generated API documentation* produced by https://github.com/swagger-api[Swagger]. The result is intended to be an *up-to-date, easy-to-read, on- and offline user guide*, comparable to https://developer.github.com/v3/[GitHub's API documentation]. The output of Swagger2Markup can be used as an alternative to https://github.com/swagger-api/swagger-ui[swagger-ui] and can be served as static content.
|
||||
|
||||
Swagger2Markup converts a Swagger JSON or YAML file into several *AsciiDoc* or *GitHub Flavored Markdown* documents which can be combined with hand-written documentation. The Swagger source file can be located locally or remotely via HTTP. Swagger2Markup supports the Swagger 1.2 and 2.0 specification. Internally it uses the _official_ https://github.com/swagger-api/swagger-parser[swagger-parser] and my https://github.com/RobWin/markup-document-builder[markup-document-builder].
|
||||
Swagger2Markup converts a Swagger JSON or YAML file into several *AsciiDoc* or *GitHub Flavored Markdown* documents which can be combined with hand-written documentation. The Swagger source file can be located locally or remotely via HTTP. Swagger2Markup supports the Swagger 1.2 and 2.0 specification. Internally it uses the _official_ https://github.com/swagger-api/swagger-parser[swagger-parser] and my https://github.com/RobWin/markup-document-builder[markup-document-builder].
|
||||
|
||||
You can use Swagger2Markup to convert your contract-first Swagger YAML file into a human-readable format and combine it with hand-written documentation. As an alternative, you can choose the code-first approach and use Swagger2Markup together with https://github.com/swagger-api/swagger-core/wiki/Swagger-Core-JAX-RS-Project-Setup-1.5.X[Swagger JAX-RS], https://github.com/springfox/springfox[springfox] or https://github.com/spring-projects/spring-restdocs[spring-restdocs]. If you are Gradle or Maven user, you can also use the https://github.com/RobWin/swagger2markup-gradle-plugin[Swagger2Markup Gradle Plugin] or https://github.com/redowl/swagger2markup-maven-plugin[Swagger2markup Maven Plugin].
|
||||
|
||||
http://asciidoctor.org/docs/asciidoc-writers-guide/[AsciiDoc] is preferable to Markdown as it has more features. AsciiDoc is a text document format for writing documentation, articles, books, ebooks, slideshows, web pages and blogs. AsciiDoc files can be converted to *HTML*, *PDF* and *EPUB*. AsciiDoc is much better suited for describing public APIs than *JavaDoc* or *Annotations*.
|
||||
|
||||
You can generate your HTML5, PDF and EPUB documentation via https://github.com/asciidoctor/asciidoctorj[asciidoctorj] or even better via the https://github.com/asciidoctor/asciidoctor-gradle-plugin[asciidoctor-gradle-plugin] or https://github.com/asciidoctor/asciidoctor-maven-plugin[asciidoctor-maven-plugin]. You can publish your AsciiDoc documentation using https://github.com/RobWin/asciidocular[Asciidocular]. Asciidocular is a small AngularJS web app that loads your AsciiDoc files via Ajax and renders them as a full web site.
|
||||
|
||||
Advantages:
|
||||
|
||||
* No server-side components needed to convert your AsciiDoc files into HTML
|
||||
* No build process and tools needed
|
||||
* Deployable via GitHub Pages
|
||||
* Responsive Bootswatch (Bootstrap) theme
|
||||
|
||||
You can publish your Markdown documentation using https://github.com/jbake-org/jbake[JBake], https://github.com/tomchristie/mkdocs[MkDocs] or https://github.com/rtfd/readthedocs.org[ReadTheDocs].
|
||||
You can generate your HTML5, PDF and EPUB documentation via https://github.com/asciidoctor/asciidoctorj[asciidoctorj] or even better via the https://github.com/asciidoctor/asciidoctor-gradle-plugin[asciidoctor-gradle-plugin] or https://github.com/asciidoctor/asciidoctor-maven-plugin[asciidoctor-maven-plugin].
|
||||
|
||||
The project requires at least JDK 7.
|
||||
|
||||
== Example
|
||||
|
||||
image::images/Swagger2Markup.PNG[]
|
||||
|
||||
image::images/Swagger2Markup_definitions.PNG[]
|
||||
|
||||
== Reference documentation
|
||||
- http://swagger2markup.readme.io/[Reference Documentation]
|
||||
- https://github.com/Swagger2Markup/swagger2markup/blob/master/RELEASENOTES.adoc[Release notes]
|
||||
@@ -38,11 +35,13 @@ The project requires at least JDK 7.
|
||||
|
||||
Pull requests are welcome.
|
||||
|
||||
* New feature https://github.com/Swagger2Markup/swagger2markup/issues/18[RobWin/Swagger2Markup#18] by https://github.com/sg-ad[@sg-ad]: In addition to the definitions.adoc you can also generate separate files for each definition model (ex: person.adoc, address.adoc, purchase.adoc).
|
||||
* New feature https://github.com/Swagger2Markup/swagger2markup/issues/18[Swagger2Markup/swagger2Markup#18] by https://github.com/sg-ad[@sg-ad]: In addition to the definitions.adoc you can also generate separate files for each definition model (ex: person.adoc, address.adoc, purchase.adoc).
|
||||
|
||||
* New feature https://github.com/Swagger2Markup/swagger2markup/issues/21[RobWin/Swagger2Markup#21] by https://github.com/redowl[@redowl]: Support for both reference models and composed models.
|
||||
* New feature https://github.com/Swagger2Markup/swagger2markup/issues/21[Swagger2Markup/swagger2Markup#21] by https://github.com/redowl[@redowl]: Support for both reference models and composed models.
|
||||
|
||||
* New feature https://github.com/Swagger2Markup/swagger2markup/issues/27[RobWin/Swagger2Markup#27] by https://github.com/zmitrok[@zmitrok]: Added a hook to preprocess a Swagger Model before it is converted.
|
||||
* New feature https://github.com/Swagger2Markup/swagger2markup/issues/27[Swagger2Markup/swagger2Markup#27] by https://github.com/zmitrok[@zmitrok]: Added a hook to preprocess a Swagger Model before it is converted.
|
||||
|
||||
* New feature https://github.com/Swagger2Markup/swagger2markup/issues/48[Swagger2Markup/swagger2Markup#48] by https://github.com/MeteorBoom[@MeteorBoom]: Multi language support.
|
||||
|
||||
=== Questions
|
||||
You can ask questions about Swagger2Markup in https://gitter.im/Swagger2Markup/swagger2markup[Gitter].
|
||||
|
||||
@@ -71,4 +71,7 @@
|
||||
|
||||
=== Version 0.9.1
|
||||
* Added support to group the paths by tags or as-is
|
||||
* Added support to order the definitions by natural ordering or as-is
|
||||
* Added support to order the definitions by natural ordering or as-is
|
||||
|
||||
=== Version 0.9.2
|
||||
* Multi language support. Added russian.
|
||||
@@ -13,7 +13,7 @@ buildscript {
|
||||
}
|
||||
}
|
||||
description = 'swagger2markup Build'
|
||||
version = '0.9.1'
|
||||
version = '0.9.2'
|
||||
group = 'io.github.robwin'
|
||||
|
||||
apply plugin: 'java'
|
||||
|
||||
BIN
images/Swagger2Markup.PNG
Normal file
|
After Width: | Height: | Size: 126 KiB |
BIN
images/Swagger2Markup_definitions.PNG
Normal file
|
After Width: | Height: | Size: 124 KiB |
|
Before Width: | Height: | Size: 44 KiB |
|
Before Width: | Height: | Size: 104 KiB |
|
Before Width: | Height: | Size: 109 KiB |
|
Before Width: | Height: | Size: 138 KiB |
|
Before Width: | Height: | Size: 24 KiB |
|
Before Width: | Height: | Size: 39 KiB |
|
Before Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 29 KiB |
|
Before Width: | Height: | Size: 87 KiB |
|
Before Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 26 KiB |
21
src/main/java/io/github/robwin/swagger2markup/Language.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package io.github.robwin.swagger2markup;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* @author Maksim Myshkin
|
||||
*/
|
||||
public enum Language {
|
||||
EN(new Locale("en")),
|
||||
RU(new Locale("ru"));
|
||||
|
||||
private final Locale lang;
|
||||
|
||||
Language(final Locale lang) {
|
||||
this.lang = lang;
|
||||
}
|
||||
|
||||
public Locale toLocale() {
|
||||
return lang;
|
||||
}
|
||||
}
|
||||
@@ -141,6 +141,7 @@ public class Swagger2MarkupConverter {
|
||||
private GroupBy pathsGroupedBy = GroupBy.AS_IS;
|
||||
private OrderBy definitionsOrderedBy = OrderBy.NATURAL;
|
||||
private MarkupLanguage markupLanguage = MarkupLanguage.ASCIIDOC;
|
||||
private Language outputLanguage = Language.EN;
|
||||
|
||||
/**
|
||||
* Creates a Builder using a given Swagger source.
|
||||
@@ -164,7 +165,9 @@ public class Swagger2MarkupConverter {
|
||||
}
|
||||
|
||||
public Swagger2MarkupConverter build(){
|
||||
return new Swagger2MarkupConverter(new Swagger2MarkupConfig(swagger, markupLanguage, examplesFolderPath, schemasFolderPath, descriptionsFolderPath, separatedDefinitions, pathsGroupedBy, definitionsOrderedBy));
|
||||
return new Swagger2MarkupConverter(new Swagger2MarkupConfig(swagger, markupLanguage, examplesFolderPath,
|
||||
schemasFolderPath, descriptionsFolderPath, separatedDefinitions, pathsGroupedBy, definitionsOrderedBy,
|
||||
outputLanguage));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -252,6 +255,17 @@ public class Swagger2MarkupConverter {
|
||||
this.definitionsOrderedBy = definitionsOrderedBy;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies labels language of output files
|
||||
*
|
||||
* @param language the enum
|
||||
* @return the Swagger2MarkupConverter.Builder
|
||||
*/
|
||||
public Builder withOutputLanguage(Language language) {
|
||||
this.outputLanguage = language;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -46,10 +46,10 @@ import static org.apache.commons.lang3.StringUtils.*;
|
||||
*/
|
||||
public class DefinitionsDocument extends MarkupDocument {
|
||||
|
||||
private static final String DEFINITIONS = "Definitions";
|
||||
private final String DEFINITIONS;
|
||||
private static final List<String> IGNORED_DEFINITIONS = Collections.singletonList("Void");
|
||||
private static final String JSON_SCHEMA = "JSON Schema";
|
||||
private static final String XML_SCHEMA = "XML Schema";
|
||||
private final String JSON_SCHEMA;
|
||||
private final String XML_SCHEMA;
|
||||
private static final String JSON_SCHEMA_EXTENSION = ".json";
|
||||
private static final String XML_SCHEMA_EXTENSION = ".xsd";
|
||||
private static final String JSON = "json";
|
||||
@@ -65,6 +65,13 @@ public class DefinitionsDocument extends MarkupDocument {
|
||||
|
||||
public DefinitionsDocument(Swagger2MarkupConfig swagger2MarkupConfig, String outputDirectory){
|
||||
super(swagger2MarkupConfig);
|
||||
|
||||
ResourceBundle labels = ResourceBundle.getBundle("lang/labels",
|
||||
swagger2MarkupConfig.getOutputLanguage().toLocale());
|
||||
DEFINITIONS = labels.getString("definitions");
|
||||
JSON_SCHEMA = labels.getString("json_schema");
|
||||
XML_SCHEMA = labels.getString("xml_schema");
|
||||
|
||||
this.definitionsOrderedBy = swagger2MarkupConfig.getDefinitionsOrderedBy();
|
||||
if(isNotBlank(swagger2MarkupConfig.getSchemasFolderPath())){
|
||||
this.schemasEnabled = true;
|
||||
|
||||
@@ -18,16 +18,17 @@
|
||||
*/
|
||||
package io.github.robwin.swagger2markup.builder.document;
|
||||
|
||||
import io.github.robwin.swagger2markup.config.Swagger2MarkupConfig;
|
||||
import io.swagger.models.Swagger;
|
||||
import io.github.robwin.markup.builder.MarkupDocBuilder;
|
||||
import io.github.robwin.markup.builder.MarkupDocBuilders;
|
||||
import io.github.robwin.markup.builder.MarkupLanguage;
|
||||
import io.github.robwin.swagger2markup.config.Swagger2MarkupConfig;
|
||||
import io.swagger.models.Swagger;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
@@ -35,15 +36,15 @@ import java.nio.charset.Charset;
|
||||
public abstract class MarkupDocument {
|
||||
|
||||
protected static final String DELIMITER = "|";
|
||||
protected static final String DEFAULT_COLUMN = "Default";
|
||||
protected static final String REQUIRED_COLUMN = "Required";
|
||||
protected static final String SCHEMA_COLUMN = "Schema";
|
||||
protected static final String NAME_COLUMN = "Name";
|
||||
protected static final String DESCRIPTION_COLUMN = "Description";
|
||||
protected static final String DESCRIPTION = DESCRIPTION_COLUMN;
|
||||
protected static final String PRODUCES = "Produces";
|
||||
protected static final String CONSUMES = "Consumes";
|
||||
protected static final String TAGS = "Tags";
|
||||
protected final String DEFAULT_COLUMN;
|
||||
protected final String REQUIRED_COLUMN;
|
||||
protected final String SCHEMA_COLUMN;
|
||||
protected final String NAME_COLUMN;
|
||||
protected final String DESCRIPTION_COLUMN;
|
||||
protected final String DESCRIPTION;
|
||||
protected final String PRODUCES;
|
||||
protected final String CONSUMES;
|
||||
protected final String TAGS;
|
||||
protected Logger logger = LoggerFactory.getLogger(getClass());
|
||||
protected Swagger swagger;
|
||||
protected MarkupLanguage markupLanguage;
|
||||
@@ -53,6 +54,18 @@ public abstract class MarkupDocument {
|
||||
this.swagger = swagger2MarkupConfig.getSwagger();
|
||||
this.markupLanguage = swagger2MarkupConfig.getMarkupLanguage();
|
||||
this.markupDocBuilder = MarkupDocBuilders.documentBuilder(markupLanguage);
|
||||
|
||||
ResourceBundle labels = ResourceBundle.getBundle("lang/labels",
|
||||
swagger2MarkupConfig.getOutputLanguage().toLocale());
|
||||
DEFAULT_COLUMN = labels.getString("default_column");
|
||||
REQUIRED_COLUMN = labels.getString("required_column");
|
||||
SCHEMA_COLUMN = labels.getString("schema_column");
|
||||
NAME_COLUMN = labels.getString("name_column");
|
||||
DESCRIPTION_COLUMN = labels.getString("description_column");
|
||||
DESCRIPTION = DESCRIPTION_COLUMN;
|
||||
PRODUCES = labels.getString("produces");
|
||||
CONSUMES = labels.getString("consumes");
|
||||
TAGS = labels.getString("tags");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -23,29 +23,47 @@ import io.swagger.models.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import static org.apache.commons.collections.CollectionUtils.isNotEmpty;
|
||||
import static org.apache.commons.lang3.StringUtils.*;
|
||||
|
||||
public class OverviewDocument extends MarkupDocument {
|
||||
|
||||
private static final String OVERVIEW = "Overview";
|
||||
private static final String CURRENT_VERSION = "Version information";
|
||||
private static final String VERSION = "Version: ";
|
||||
private static final String CONTACT_INFORMATION = "Contact information";
|
||||
private static final String CONTACT_NAME = "Contact: ";
|
||||
private static final String CONTACT_EMAIL = "Contact Email: ";
|
||||
private static final String LICENSE_INFORMATION = "License information";
|
||||
private static final String LICENSE = "License: ";
|
||||
private static final String LICENSE_URL = "License URL: ";
|
||||
private static final String TERMS_OF_SERVICE = "Terms of service: ";
|
||||
private static final String URI_SCHEME = "URI scheme";
|
||||
private static final String HOST = "Host: ";
|
||||
private static final String BASE_PATH = "BasePath: ";
|
||||
private static final String SCHEMES = "Schemes: ";
|
||||
private final String OVERVIEW;
|
||||
private final String CURRENT_VERSION;
|
||||
private final String VERSION;
|
||||
private final String CONTACT_INFORMATION;
|
||||
private final String CONTACT_NAME;
|
||||
private final String CONTACT_EMAIL;
|
||||
private final String LICENSE_INFORMATION;
|
||||
private final String LICENSE;
|
||||
private final String LICENSE_URL;
|
||||
private final String TERMS_OF_SERVICE;
|
||||
private final String URI_SCHEME;
|
||||
private final String HOST;
|
||||
private final String BASE_PATH;
|
||||
private final String SCHEMES;
|
||||
|
||||
public OverviewDocument(Swagger2MarkupConfig swagger2MarkupConfig){
|
||||
super(swagger2MarkupConfig);
|
||||
|
||||
ResourceBundle labels = ResourceBundle.getBundle("lang/labels",
|
||||
swagger2MarkupConfig.getOutputLanguage().toLocale());
|
||||
OVERVIEW = labels.getString("overview");
|
||||
CURRENT_VERSION = labels.getString("current_version");
|
||||
VERSION = labels.getString("version");
|
||||
CONTACT_INFORMATION = labels.getString("contact_information");
|
||||
CONTACT_NAME = labels.getString("contact_name");
|
||||
CONTACT_EMAIL = labels.getString("contact_email");
|
||||
LICENSE_INFORMATION = labels.getString("license_information");
|
||||
LICENSE = labels.getString("license");
|
||||
LICENSE_URL = labels.getString("license_url");
|
||||
TERMS_OF_SERVICE = labels.getString("terms_of_service");
|
||||
URI_SCHEME = labels.getString("uri_scheme");
|
||||
HOST = labels.getString("host");
|
||||
BASE_PATH = labels.getString("base_path");
|
||||
SCHEMES = labels.getString("schemes");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -47,20 +47,20 @@ import static org.apache.commons.lang3.StringUtils.*;
|
||||
*/
|
||||
public class PathsDocument extends MarkupDocument {
|
||||
|
||||
private static final String PATHS = "Paths";
|
||||
private static final String RESOURCES = "Resources";
|
||||
private static final String PARAMETERS = "Parameters";
|
||||
private static final String RESPONSES = "Responses";
|
||||
private static final String EXAMPLE_CURL = "Example CURL request";
|
||||
private static final String EXAMPLE_REQUEST = "Example HTTP request";
|
||||
private static final String EXAMPLE_RESPONSE = "Example HTTP response";
|
||||
private static final String TYPE_COLUMN = "Type";
|
||||
private static final String HTTP_CODE_COLUMN = "HTTP Code";
|
||||
private static final String REQUEST_EXAMPLE_FILE_NAME = "http-request";
|
||||
private static final String RESPONSE_EXAMPLE_FILE_NAME = "http-response";
|
||||
private static final String CURL_EXAMPLE_FILE_NAME = "curl-request";
|
||||
private static final String DESCRIPTION_FILE_NAME = "description";
|
||||
private static final String PARAMETER = "Parameter";
|
||||
private final String PATHS;
|
||||
private final String RESOURCES;
|
||||
private final String PARAMETERS;
|
||||
private final String RESPONSES;
|
||||
private final String EXAMPLE_CURL;
|
||||
private final String EXAMPLE_REQUEST;
|
||||
private final String EXAMPLE_RESPONSE;
|
||||
private final String TYPE_COLUMN;
|
||||
private final String HTTP_CODE_COLUMN;
|
||||
private final String REQUEST_EXAMPLE_FILE_NAME;
|
||||
private final String RESPONSE_EXAMPLE_FILE_NAME;
|
||||
private final String CURL_EXAMPLE_FILE_NAME;
|
||||
private final String DESCRIPTION_FILE_NAME;
|
||||
private final String PARAMETER;
|
||||
|
||||
private boolean examplesEnabled;
|
||||
private String examplesFolderPath;
|
||||
@@ -70,6 +70,24 @@ public class PathsDocument extends MarkupDocument {
|
||||
|
||||
public PathsDocument(Swagger2MarkupConfig swagger2MarkupConfig){
|
||||
super(swagger2MarkupConfig);
|
||||
|
||||
ResourceBundle labels = ResourceBundle.getBundle("lang/labels",
|
||||
swagger2MarkupConfig.getOutputLanguage().toLocale());
|
||||
PATHS = labels.getString("paths");
|
||||
RESOURCES = labels.getString("resources");
|
||||
PARAMETERS = labels.getString("parameters");
|
||||
RESPONSES = labels.getString("responses");
|
||||
EXAMPLE_CURL = labels.getString("example_curl");
|
||||
EXAMPLE_REQUEST = labels.getString("example_request");
|
||||
EXAMPLE_RESPONSE = labels.getString("example_response");
|
||||
TYPE_COLUMN = labels.getString("type_column");
|
||||
HTTP_CODE_COLUMN = labels.getString("http_code_column");
|
||||
REQUEST_EXAMPLE_FILE_NAME = labels.getString("request_example_file_name");
|
||||
RESPONSE_EXAMPLE_FILE_NAME = labels.getString("response_example_file_name");
|
||||
CURL_EXAMPLE_FILE_NAME = labels.getString("curl_example_file_name");
|
||||
DESCRIPTION_FILE_NAME = labels.getString("description_file_name");
|
||||
PARAMETER = labels.getString("parameter");
|
||||
|
||||
this.pathsGroupedBy = swagger2MarkupConfig.getPathsGroupedBy();
|
||||
if(isNotBlank(swagger2MarkupConfig.getExamplesFolderPath())){
|
||||
this.examplesEnabled = true;
|
||||
@@ -103,7 +121,6 @@ public class PathsDocument extends MarkupDocument {
|
||||
* Builds the paths markup document.
|
||||
*
|
||||
* @return the the paths markup document
|
||||
* @throws IOException
|
||||
*/
|
||||
@Override
|
||||
public MarkupDocument build(){
|
||||
|
||||
@@ -20,6 +20,7 @@ package io.github.robwin.swagger2markup.config;
|
||||
|
||||
import io.github.robwin.markup.builder.MarkupLanguage;
|
||||
import io.github.robwin.swagger2markup.GroupBy;
|
||||
import io.github.robwin.swagger2markup.Language;
|
||||
import io.github.robwin.swagger2markup.OrderBy;
|
||||
import io.swagger.models.Swagger;
|
||||
|
||||
@@ -33,6 +34,7 @@ public class Swagger2MarkupConfig {
|
||||
private final boolean separatedDefinitions;
|
||||
private final GroupBy pathsGroupedBy;
|
||||
private final OrderBy definitionsOrderedBy;
|
||||
private final Language outputLanguage;
|
||||
|
||||
/**
|
||||
* @param swagger the Swagger source
|
||||
@@ -43,8 +45,11 @@ public class Swagger2MarkupConfig {
|
||||
* @param separatedDefinitions specified if in addition to the definitions file, also separate definition files for each model definition should be created
|
||||
* @param pathsGroupedBy specifies if the paths should be grouped by tags or stay as-is
|
||||
* @param definitionsOrderedBy specifies if the definitions should be ordered by natural ordering or stay as-is
|
||||
* @param outputLanguage specifies language of labels in output files
|
||||
*/
|
||||
public Swagger2MarkupConfig(Swagger swagger, MarkupLanguage markupLanguage, String examplesFolderPath, String schemasFolderPath, String descriptionsFolderPath, boolean separatedDefinitions, GroupBy pathsGroupedBy, OrderBy definitionsOrderedBy) {
|
||||
public Swagger2MarkupConfig(Swagger swagger, MarkupLanguage markupLanguage, String examplesFolderPath,
|
||||
String schemasFolderPath, String descriptionsFolderPath, boolean separatedDefinitions,
|
||||
GroupBy pathsGroupedBy, OrderBy definitionsOrderedBy, Language outputLanguage) {
|
||||
this.swagger = swagger;
|
||||
this.markupLanguage = markupLanguage;
|
||||
this.examplesFolderPath = examplesFolderPath;
|
||||
@@ -53,6 +58,7 @@ public class Swagger2MarkupConfig {
|
||||
this.separatedDefinitions = separatedDefinitions;
|
||||
this.pathsGroupedBy = pathsGroupedBy;
|
||||
this.definitionsOrderedBy = definitionsOrderedBy;
|
||||
this.outputLanguage = outputLanguage;
|
||||
}
|
||||
|
||||
public Swagger getSwagger() {
|
||||
@@ -83,8 +89,11 @@ public class Swagger2MarkupConfig {
|
||||
return pathsGroupedBy;
|
||||
}
|
||||
|
||||
|
||||
public OrderBy getDefinitionsOrderedBy() {
|
||||
return definitionsOrderedBy;
|
||||
}
|
||||
|
||||
public Language getOutputLanguage() {
|
||||
return outputLanguage;
|
||||
}
|
||||
}
|
||||
|
||||
42
src/main/resources/lang/labels_en.properties
Normal file
@@ -0,0 +1,42 @@
|
||||
definitions=Definitions
|
||||
json_schema=JSON Schema
|
||||
xml_schema=XML Schema
|
||||
|
||||
default_column=Default
|
||||
required_column=Required
|
||||
schema_column=Schema
|
||||
name_column=Name
|
||||
description_column=Description
|
||||
produces=Produces
|
||||
consumes=Consumes
|
||||
tags=Tags
|
||||
|
||||
overview=Overview
|
||||
current_version=Version information
|
||||
version=Version\:\u0020
|
||||
contact_information=Contact information
|
||||
contact_name=Contact\:\u0020
|
||||
contact_email=Contact Email\:\u0020
|
||||
license_information=License information
|
||||
license=License\:\u0020
|
||||
license_url=License URL\:\u0020
|
||||
terms_of_service=Terms of service\:\u0020
|
||||
uri_scheme=URI scheme
|
||||
host=Host\:\u0020
|
||||
base_path=BasePath\:\u0020
|
||||
schemes=Schemes\:\u0020
|
||||
|
||||
paths=Paths
|
||||
resources=Resources
|
||||
parameters=Parameters
|
||||
responses=Responses
|
||||
example_curl=Example CURL request
|
||||
example_request=Example HTTP request
|
||||
example_response=Example HTTP response
|
||||
type_column=Type
|
||||
http_code_column=HTTP Code
|
||||
request_example_file_name=http-request
|
||||
response_example_file_name=http-response
|
||||
curl_example_file_name=curl-request
|
||||
description_file_name=description
|
||||
parameter=Parameter
|
||||
42
src/main/resources/lang/labels_ru.properties
Normal file
@@ -0,0 +1,42 @@
|
||||
definitions=\u041E\u043F\u0440\u0435\u0434\u0435\u043B\u0435\u043D\u0438\u044F
|
||||
json_schema=JSON \u0441\u0445\u0435\u043C\u0430
|
||||
xml_schema=XML \u0441\u0445\u0435\u043C\u0430
|
||||
|
||||
default_column=\u041F\u043E \u0443\u043C\u043E\u043B\u0447\u0430\u043D\u0438\u044E
|
||||
required_column=\u041E\u0431\u044F\u0437\u0430\u0442\u0435\u043B\u044C\u043D\u043E
|
||||
schema_column=\u0421\u0445\u0435\u043C\u0430
|
||||
name_column=\u0418\u043C\u044F
|
||||
description_column=\u041E\u043F\u0438\u0441\u0430\u043D\u0438\u0435
|
||||
produces=\u0412\u043E\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442
|
||||
consumes=\u041F\u0440\u0438\u043D\u0438\u043C\u0430\u0435\u0442
|
||||
tags=\u0422\u044D\u0433\u0438
|
||||
|
||||
overview=\u041E\u0431\u0437\u043E\u0440
|
||||
current_version=\u0418\u043D\u0444\u043E\u0440\u043C\u0430\u0446\u0438\u044F \u043E \u0432\u0435\u0440\u0441\u0438\u0438
|
||||
version=\u0412\u0435\u0440\u0441\u0438\u044F\:\u0020
|
||||
contact_information=\u041A\u043E\u043D\u0442\u0430\u043A\u0442\u043D\u0430\u044F \u0438\u043D\u0444\u043E\u0440\u043C\u0430\u0446\u0438\u044F
|
||||
contact_name=\u041A\u043E\u043D\u0442\u0430\u043A\u0442\:\u0020
|
||||
contact_email=Email \u043A\u043E\u043D\u0442\u0430\u043A\u0442\u0430\:\u0020
|
||||
license_information=\u0418\u043D\u0444\u043E\u0440\u043C\u0430\u0446\u0438\u044F \u043E \u043B\u0438\u0446\u0435\u043D\u0446\u0438\u0438
|
||||
license=\u041B\u0438\u0446\u0435\u043D\u0437\u0438\u044F\:\u0020
|
||||
license_url=URL \u043B\u0438\u0446\u0435\u043D\u0437\u0438\u0438\:\u0020
|
||||
terms_of_service=\u0423\u0441\u043B\u043E\u0432\u0438\u044F \u0438\u0441\u043F\u043E\u043B\u044C\u0437\u043E\u0432\u0430\u043D\u0438\u044F\:\u0020
|
||||
uri_scheme=\u0421\u0445\u0435\u043C\u0430 URI
|
||||
host=\u0423\u0437\u0435\u043B\:\u0020
|
||||
base_path=\u041E\u0441\u043D\u043E\u0432\u043D\u043E\u0439 \u043F\u0443\u0442\u044C\:\u0020
|
||||
schemes=\u0421\u0445\u0435\u043C\u044B\:\u0020
|
||||
|
||||
paths=\u041F\u0443\u0442\u0438
|
||||
resources=\u041E\u0442\u0432\u0435\u0442\u044B
|
||||
parameters=\u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440\u044B
|
||||
responses=\u041E\u0442\u0432\u0435\u0442\u044B
|
||||
example_curl=\u041F\u0440\u0438\u043C\u0435\u0440 CURL \u0437\u0430\u043F\u0440\u043E\u0441\u0430
|
||||
example_request=\u041F\u0440\u0438\u043C\u0435\u0440 HTTP \u0437\u0430\u043F\u0440\u043E\u0441\u0430
|
||||
example_response=\u041F\u0440\u0438\u043C\u0435\u0440 HTTP \u0437\u0430\u043F\u0440\u043E\u0441\u0430
|
||||
type_column=\u0422\u0438\u043F
|
||||
http_code_column=HTTP \u043A\u043E\u0434
|
||||
request_example_file_name=http-request
|
||||
response_example_file_name=http-response
|
||||
curl_example_file_name=curl-request
|
||||
description_file_name=\u043E\u043F\u0438\u0441\u0430\u043D\u0438\u0435
|
||||
parameter=\u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440
|
||||
@@ -24,6 +24,7 @@ import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import io.github.robwin.markup.builder.MarkupLanguage;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
@@ -42,6 +43,24 @@ import static org.assertj.core.api.BDDAssertions.assertThat;
|
||||
|
||||
public class Swagger2MarkupConverterTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void testSwagger2AsciiDocConversionFromString() throws IOException {
|
||||
//Given
|
||||
String swaggerJsonString = IOUtils.toString(getClass().getResourceAsStream("/json/swagger.json"));
|
||||
File outputDirectory = new File("build/docs/asciidoc/generated");
|
||||
FileUtils.deleteQuietly(outputDirectory);
|
||||
|
||||
//When
|
||||
Swagger2MarkupConverter.fromString(swaggerJsonString).build()
|
||||
.intoFolder(outputDirectory.getAbsolutePath());
|
||||
|
||||
//Then
|
||||
String[] directories = outputDirectory.list();
|
||||
assertThat(directories).hasSize(3).containsAll(asList("definitions.adoc", "overview.adoc", "paths.adoc"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSwagger2AsciiDocConversion() throws IOException {
|
||||
//Given
|
||||
@@ -274,6 +293,24 @@ public class Swagger2MarkupConverterTest {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSwagger2AsciiDocConversionWithRussianOutputLanguage() throws IOException {
|
||||
//Given
|
||||
File file = new File(Swagger2MarkupConverterTest.class.getResource("/json/swagger.json").getFile());
|
||||
File outputDirectory = new File("build/docs/asciidoc/generated");
|
||||
FileUtils.deleteQuietly(outputDirectory);
|
||||
|
||||
//When
|
||||
Swagger2MarkupConverter.from(file.getAbsolutePath())
|
||||
.withOutputLanguage(Language.RU)
|
||||
.build()
|
||||
.intoFolder(outputDirectory.getAbsolutePath());
|
||||
|
||||
//Then
|
||||
assertThat(new String(Files.readAllBytes(Paths.get(outputDirectory + File.separator + "definitions.adoc"))))
|
||||
.contains("== Определения");
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a markdown document to search, this checks to see if the specified tables
|
||||
* have all of the expected fields listed.
|
||||
|
||||