fixed #80 : External folder path consistency
This commit is contained in:
@@ -31,6 +31,7 @@ import org.apache.commons.lang3.Validate;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
@@ -43,8 +44,8 @@ import java.util.Properties;
|
||||
public class Swagger2MarkupConverter {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(Swagger2MarkupConverter.class);
|
||||
|
||||
private Swagger2MarkupConfig config;
|
||||
private Swagger swagger;
|
||||
Swagger2MarkupConfig config;
|
||||
Swagger swagger;
|
||||
|
||||
/**
|
||||
* Creates a Swagger2MarkupConverter.Builder using a given Swagger source.
|
||||
@@ -126,10 +127,10 @@ public class Swagger2MarkupConverter {
|
||||
* @throws IOException if a file cannot be written
|
||||
*/
|
||||
private void buildDocuments(String directory) throws IOException {
|
||||
new OverviewDocument(swagger,config, directory).build().writeToFile(directory, config.getOverviewDocument(), StandardCharsets.UTF_8);
|
||||
new PathsDocument(swagger,config, directory).build().writeToFile(directory, config.getPathsDocument(), StandardCharsets.UTF_8);
|
||||
new DefinitionsDocument(swagger,config, directory).build().writeToFile(directory, config.getDefinitionsDocument(), StandardCharsets.UTF_8);
|
||||
new SecurityDocument(swagger,config, directory).build().writeToFile(directory, config.getSecurityDocument(), StandardCharsets.UTF_8);
|
||||
new OverviewDocument(swagger, config, directory).build().writeToFile(directory, config.getOverviewDocument(), StandardCharsets.UTF_8);
|
||||
new PathsDocument(swagger, config, directory).build().writeToFile(directory, config.getPathsDocument(), StandardCharsets.UTF_8);
|
||||
new DefinitionsDocument(swagger, config, directory).build().writeToFile(directory, config.getDefinitionsDocument(), StandardCharsets.UTF_8);
|
||||
new SecurityDocument(swagger, config, directory).build().writeToFile(directory, config.getSecurityDocument(), StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -139,15 +140,16 @@ public class Swagger2MarkupConverter {
|
||||
*/
|
||||
private String buildDocuments() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(new OverviewDocument(swagger,config, null).build().toString());
|
||||
sb.append(new PathsDocument(swagger,config, null).build().toString());
|
||||
sb.append(new DefinitionsDocument(swagger,config, null).build().toString());
|
||||
sb.append(new SecurityDocument(swagger,config, null).build().toString());
|
||||
sb.append(new OverviewDocument(swagger, config, null).build().toString());
|
||||
sb.append(new PathsDocument(swagger, config, null).build().toString());
|
||||
sb.append(new DefinitionsDocument(swagger, config, null).build().toString());
|
||||
sb.append(new SecurityDocument(swagger, config, null).build().toString());
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private final Swagger swagger;
|
||||
private final String swaggerLocation;
|
||||
private Swagger2MarkupConfig config;
|
||||
|
||||
/**
|
||||
@@ -156,6 +158,7 @@ public class Swagger2MarkupConverter {
|
||||
* @param swaggerLocation the Swagger location. Can be a HTTP url or a path to a local file.
|
||||
*/
|
||||
Builder(String swaggerLocation) {
|
||||
this.swaggerLocation = swaggerLocation;
|
||||
swagger = new SwaggerParser().read(swaggerLocation);
|
||||
if (swagger == null) {
|
||||
throw new IllegalArgumentException("Failed to read the Swagger source");
|
||||
@@ -169,6 +172,7 @@ public class Swagger2MarkupConverter {
|
||||
*/
|
||||
Builder(Swagger swagger) {
|
||||
this.swagger = swagger;
|
||||
this.swaggerLocation = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -200,6 +204,8 @@ public class Swagger2MarkupConverter {
|
||||
else
|
||||
converter.config = config;
|
||||
|
||||
converter.config.configurePathsDefaults(this.swaggerLocation == null ? null : new File(swaggerLocation).getParentFile());
|
||||
|
||||
return converter;
|
||||
}
|
||||
|
||||
|
||||
@@ -65,40 +65,17 @@ public class DefinitionsDocument extends MarkupDocument {
|
||||
private static final String XML_SCHEMA_EXTENSION = ".xsd";
|
||||
private static final String JSON = "json";
|
||||
private static final String XML = "xml";
|
||||
private static final String DESCRIPTION_FOLDER_NAME = "definitions";
|
||||
private static final String DESCRIPTION_FILE_NAME = "description";
|
||||
private boolean schemasEnabled;
|
||||
private String schemasFolderPath;
|
||||
private boolean descriptionsEnabled;
|
||||
private String descriptionsFolderPath;
|
||||
protected boolean definitionExtensionsEnabled;
|
||||
protected String definitionExtensionsFolderPath;
|
||||
private final int inlineSchemaDepthLevel;
|
||||
private final Comparator<String> definitionOrdering;
|
||||
|
||||
public DefinitionsDocument(Swagger swagger, Swagger2MarkupConfig swagger2MarkupConfig, String outputDirectory){
|
||||
super(swagger, swagger2MarkupConfig, outputDirectory);
|
||||
public DefinitionsDocument(Swagger swagger, Swagger2MarkupConfig config, String outputDirectory){
|
||||
super(swagger, config, outputDirectory);
|
||||
|
||||
ResourceBundle labels = ResourceBundle.getBundle("lang/labels",
|
||||
swagger2MarkupConfig.getOutputLanguage().toLocale());
|
||||
ResourceBundle labels = ResourceBundle.getBundle("lang/labels", config.getOutputLanguage().toLocale());
|
||||
DEFINITIONS = labels.getString("definitions");
|
||||
JSON_SCHEMA = labels.getString("json_schema");
|
||||
XML_SCHEMA = labels.getString("xml_schema");
|
||||
|
||||
this.inlineSchemaDepthLevel = swagger2MarkupConfig.getInlineSchemaDepthLevel();
|
||||
if(isNotBlank(swagger2MarkupConfig.getSchemasFolderPath())){
|
||||
this.schemasEnabled = true;
|
||||
this.schemasFolderPath = swagger2MarkupConfig.getSchemasFolderPath();
|
||||
}
|
||||
if(isNotBlank(swagger2MarkupConfig.getDescriptionsFolderPath())){
|
||||
this.descriptionsEnabled = true;
|
||||
this.descriptionsFolderPath = swagger2MarkupConfig.getDescriptionsFolderPath() + "/" + DESCRIPTION_FOLDER_NAME;
|
||||
}
|
||||
if(isNotBlank(swagger2MarkupConfig.getDefinitionExtensionsFolderPath())){
|
||||
this.definitionExtensionsEnabled = true;
|
||||
this.definitionExtensionsFolderPath = swagger2MarkupConfig.getDefinitionExtensionsFolderPath();
|
||||
}
|
||||
if(schemasEnabled){
|
||||
if(config.isSchemas()){
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Include schemas is enabled.");
|
||||
}
|
||||
@@ -107,16 +84,16 @@ public class DefinitionsDocument extends MarkupDocument {
|
||||
logger.debug("Include schemas is disabled.");
|
||||
}
|
||||
}
|
||||
if(descriptionsEnabled){
|
||||
if(config.isDefinitionDescriptions()){
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Include hand-written descriptions is enabled.");
|
||||
logger.debug("Include hand-written definition descriptions is enabled.");
|
||||
}
|
||||
}else{
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Include hand-written descriptions is disabled.");
|
||||
logger.debug("Include hand-written definition descriptions is disabled.");
|
||||
}
|
||||
}
|
||||
if(this.separatedDefinitionsEnabled){
|
||||
if(config.isSeparatedDefinitions()){
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Create separated definition files is enabled.");
|
||||
}
|
||||
@@ -126,7 +103,6 @@ public class DefinitionsDocument extends MarkupDocument {
|
||||
logger.debug("Create separated definition files is disabled.");
|
||||
}
|
||||
}
|
||||
this.definitionOrdering = swagger2MarkupConfig.getDefinitionOrdering();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -148,10 +124,10 @@ public class DefinitionsDocument extends MarkupDocument {
|
||||
if(MapUtils.isNotEmpty(definitions)){
|
||||
addDefinitionsTitle(DEFINITIONS);
|
||||
Set<String> definitionNames;
|
||||
if (definitionOrdering == null)
|
||||
if (config.getDefinitionOrdering() == null)
|
||||
definitionNames = new LinkedHashSet<>();
|
||||
else
|
||||
definitionNames = new TreeSet<>(definitionOrdering);
|
||||
definitionNames = new TreeSet<>(config.getDefinitionOrdering());
|
||||
definitionNames.addAll(definitions.keySet());
|
||||
for(String definitionName : definitionNames){
|
||||
Model model = definitions.get(definitionName);
|
||||
@@ -177,10 +153,10 @@ public class DefinitionsDocument extends MarkupDocument {
|
||||
* @return definition filename
|
||||
*/
|
||||
private String resolveDefinitionDocument(String definitionName) {
|
||||
if (separatedDefinitionsEnabled)
|
||||
return new File(separatedDefinitionsFolder, markupDocBuilder.addfileExtension(normalizeFileName(definitionName))).getPath();
|
||||
if (config.isSeparatedDefinitions())
|
||||
return new File(config.getSeparatedDefinitionsFolder(), markupDocBuilder.addfileExtension(normalizeFileName(definitionName))).getPath();
|
||||
else
|
||||
return markupDocBuilder.addfileExtension(definitionsDocument);
|
||||
return markupDocBuilder.addfileExtension(config.getDefinitionsDocument());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -191,7 +167,7 @@ public class DefinitionsDocument extends MarkupDocument {
|
||||
*/
|
||||
private void processDefinition(Map<String, Model> definitions, String definitionName, Model model) {
|
||||
|
||||
if (separatedDefinitionsEnabled) {
|
||||
if (config.isSeparatedDefinitions()) {
|
||||
MarkupDocBuilder defDocBuilder = this.markupDocBuilder.copy();
|
||||
definition(definitions, definitionName, model, defDocBuilder);
|
||||
File definitionFile = new File(outputDirectory, resolveDefinitionDocument(definitionName));
|
||||
@@ -236,7 +212,7 @@ public class DefinitionsDocument extends MarkupDocument {
|
||||
private void definition(Map<String, Model> definitions, String definitionName, Model model, MarkupDocBuilder docBuilder){
|
||||
addDefinitionTitle(definitionName, null, docBuilder);
|
||||
descriptionSection(definitionName, model, docBuilder);
|
||||
inlineDefinitions(propertiesSection(definitions, definitionName, model, docBuilder), definitionName, inlineSchemaDepthLevel, docBuilder);
|
||||
inlineDefinitions(propertiesSection(definitions, definitionName, model, docBuilder), definitionName, config.getInlineSchemaDepthLevel(), docBuilder);
|
||||
definitionSchema(definitionName, docBuilder);
|
||||
extensionsSection(definitionName, docBuilder);
|
||||
}
|
||||
@@ -273,7 +249,7 @@ public class DefinitionsDocument extends MarkupDocument {
|
||||
@Override
|
||||
public String getDescription(Property property, String propertyName) {
|
||||
String description;
|
||||
if(descriptionsEnabled){
|
||||
if(config.isDefinitionDescriptions()){
|
||||
description = handWrittenPathDescription(new File(normalizeFileName(type.getName()), normalizeFileName(propertyName)).toString(), DESCRIPTION_FILE_NAME);
|
||||
if(isBlank(description)) {
|
||||
if (logger.isInfoEnabled()) {
|
||||
@@ -336,13 +312,13 @@ public class DefinitionsDocument extends MarkupDocument {
|
||||
}
|
||||
|
||||
private void descriptionSection(String definitionName, Model model, MarkupDocBuilder docBuilder){
|
||||
if(descriptionsEnabled){
|
||||
if(config.isDefinitionDescriptions()){
|
||||
String description = handWrittenPathDescription(normalizeFileName(definitionName), DESCRIPTION_FILE_NAME);
|
||||
if(isNotBlank(description)){
|
||||
docBuilder.paragraph(description);
|
||||
}else{
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Hand-written description cannot be read. Trying to use description from Swagger source.");
|
||||
logger.info("Hand-written definition description cannot be read. Trying to use description from Swagger source.");
|
||||
}
|
||||
modelDescription(model, docBuilder);
|
||||
}
|
||||
@@ -367,8 +343,8 @@ public class DefinitionsDocument extends MarkupDocument {
|
||||
* @return the content of the file
|
||||
*/
|
||||
private String handWrittenPathDescription(String descriptionFolder, String descriptionFileName){
|
||||
for (String fileNameExtension : markupLanguage.getFileNameExtensions()) {
|
||||
java.nio.file.Path path = Paths.get(descriptionsFolderPath, descriptionFolder, descriptionFileName + fileNameExtension);
|
||||
for (String fileNameExtension : config.getMarkupLanguage().getFileNameExtensions()) {
|
||||
java.nio.file.Path path = Paths.get(config.getDefinitionDescriptionsPath(), descriptionFolder, descriptionFileName + fileNameExtension);
|
||||
if (Files.isReadable(path)) {
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Description file processed: {}", path);
|
||||
@@ -387,16 +363,16 @@ public class DefinitionsDocument extends MarkupDocument {
|
||||
}
|
||||
}
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.info("No description file found with correct file name extension in folder: {}", Paths.get(descriptionsFolderPath, descriptionFolder));
|
||||
logger.info("No description file found with correct file name extension in folder: {}", Paths.get(config.getDefinitionDescriptionsPath(), descriptionFolder));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void definitionSchema(String definitionName, MarkupDocBuilder docBuilder) {
|
||||
if(schemasEnabled) {
|
||||
if(config.isSchemas()) {
|
||||
if (isNotBlank(definitionName)) {
|
||||
schema(JSON_SCHEMA, schemasFolderPath, definitionName + JSON_SCHEMA_EXTENSION, JSON, docBuilder);
|
||||
schema(XML_SCHEMA, schemasFolderPath, definitionName + XML_SCHEMA_EXTENSION, XML, docBuilder);
|
||||
schema(JSON_SCHEMA, config.getSchemasPath(), definitionName + JSON_SCHEMA_EXTENSION, JSON, docBuilder);
|
||||
schema(XML_SCHEMA, config.getSchemasPath(), definitionName + XML_SCHEMA_EXTENSION, XML, docBuilder);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -462,13 +438,13 @@ public class DefinitionsDocument extends MarkupDocument {
|
||||
* @param docBuilder the MarkupDocBuilder document builder
|
||||
*/
|
||||
private void extensionsSection(String definitionName, MarkupDocBuilder docBuilder) {
|
||||
if (this.definitionExtensionsEnabled) {
|
||||
final Collection<String> filenameExtensions = Collections2.transform(markupLanguage.getFileNameExtensions(), new Function<String, String>() {
|
||||
if (config.isDefinitionExtensions()) {
|
||||
final Collection<String> filenameExtensions = Collections2.transform(config.getMarkupLanguage().getFileNameExtensions(), new Function<String, String>() {
|
||||
public String apply(String input) {
|
||||
return StringUtils.stripStart(input, ".");
|
||||
}
|
||||
});
|
||||
File definitionExtensionsPath = new File(new File(this.definitionExtensionsFolderPath), normalizeFileName(definitionName));
|
||||
File definitionExtensionsPath = new File(new File(config.getDefinitionExtensionsPath()), normalizeFileName(definitionName));
|
||||
|
||||
File[] extensionFiles = definitionExtensionsPath.listFiles(new FilenameFilter() {
|
||||
public boolean accept(File dir, String name) {
|
||||
@@ -506,8 +482,8 @@ public class DefinitionsDocument extends MarkupDocument {
|
||||
public String apply(String definitionName) {
|
||||
String defaultResolver = super.apply(definitionName);
|
||||
|
||||
if (defaultResolver != null && separatedDefinitionsEnabled)
|
||||
return interDocumentCrossReferencesPrefix + markupDocBuilder.addfileExtension(normalizeFileName(definitionName));
|
||||
if (defaultResolver != null && config.isSeparatedDefinitions())
|
||||
return defaultString(config.getInterDocumentCrossReferencesPrefix()) + markupDocBuilder.addfileExtension(normalizeFileName(definitionName));
|
||||
else
|
||||
return defaultResolver;
|
||||
}
|
||||
|
||||
@@ -75,30 +75,18 @@ public abstract class MarkupDocument {
|
||||
protected Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
protected Swagger swagger;
|
||||
protected MarkupLanguage markupLanguage;
|
||||
protected Swagger2MarkupConfig config;
|
||||
protected MarkupDocBuilder markupDocBuilder;
|
||||
protected boolean separatedDefinitionsEnabled;
|
||||
protected String separatedDefinitionsFolder;
|
||||
protected String definitionsDocument;
|
||||
protected String outputDirectory;
|
||||
protected boolean useInterDocumentCrossReferences;
|
||||
protected String interDocumentCrossReferencesPrefix;
|
||||
protected Comparator<String> propertyOrdering;
|
||||
|
||||
MarkupDocument(Swagger swagger, Swagger2MarkupConfig swagger2MarkupConfig, String outputDirectory) {
|
||||
MarkupDocument(Swagger swagger, Swagger2MarkupConfig config, String outputDirectory) {
|
||||
this.swagger = swagger;
|
||||
this.markupLanguage = swagger2MarkupConfig.getMarkupLanguage();
|
||||
this.markupDocBuilder = MarkupDocBuilders.documentBuilder(markupLanguage).withAnchorPrefix(swagger2MarkupConfig.getAnchorPrefix());
|
||||
this.separatedDefinitionsEnabled = swagger2MarkupConfig.isSeparatedDefinitions();
|
||||
this.separatedDefinitionsFolder = swagger2MarkupConfig.getSeparatedDefinitionsFolder();
|
||||
this.definitionsDocument = swagger2MarkupConfig.getDefinitionsDocument();
|
||||
this.config = config;
|
||||
this.outputDirectory = outputDirectory;
|
||||
this.useInterDocumentCrossReferences = swagger2MarkupConfig.isInterDocumentCrossReferences();
|
||||
this.interDocumentCrossReferencesPrefix = swagger2MarkupConfig.getInterDocumentCrossReferencesPrefix();
|
||||
this.propertyOrdering = swagger2MarkupConfig.getPropertyOrdering();
|
||||
|
||||
ResourceBundle labels = ResourceBundle.getBundle("lang/labels",
|
||||
swagger2MarkupConfig.getOutputLanguage().toLocale());
|
||||
this.markupDocBuilder = MarkupDocBuilders.documentBuilder(config.getMarkupLanguage()).withAnchorPrefix(config.getAnchorPrefix());
|
||||
|
||||
ResourceBundle labels = ResourceBundle.getBundle("lang/labels", config.getOutputLanguage().toLocale());
|
||||
DEFAULT_COLUMN = labels.getString("default_column");
|
||||
REQUIRED_COLUMN = labels.getString("required_column");
|
||||
SCHEMA_COLUMN = labels.getString("schema_column");
|
||||
@@ -173,10 +161,10 @@ public abstract class MarkupDocument {
|
||||
new MarkupTableColumn(DEFAULT_COLUMN, 1).withMarkupSpecifiers(MarkupLanguage.ASCIIDOC, ".^1"));
|
||||
if (MapUtils.isNotEmpty(type.getProperties())) {
|
||||
Set<String> propertyNames;
|
||||
if (this.propertyOrdering == null)
|
||||
if (config.getPropertyOrdering() == null)
|
||||
propertyNames = new LinkedHashSet<>();
|
||||
else
|
||||
propertyNames = new TreeSet<>(this.propertyOrdering);
|
||||
propertyNames = new TreeSet<>(config.getPropertyOrdering());
|
||||
propertyNames.addAll(type.getProperties().keySet());
|
||||
|
||||
for (String propertyName: propertyNames) {
|
||||
@@ -258,12 +246,12 @@ public abstract class MarkupDocument {
|
||||
public DefinitionDocumentResolverDefault() {}
|
||||
|
||||
public String apply(String definitionName) {
|
||||
if (!useInterDocumentCrossReferences || outputDirectory == null)
|
||||
if (!config.isInterDocumentCrossReferences() || outputDirectory == null)
|
||||
return null;
|
||||
else if (separatedDefinitionsEnabled)
|
||||
return interDocumentCrossReferencesPrefix + new File(separatedDefinitionsFolder, markupDocBuilder.addfileExtension(normalizeFileName(definitionName))).getPath();
|
||||
else if (config.isSeparatedDefinitions())
|
||||
return defaultString(config.getInterDocumentCrossReferencesPrefix()) + new File(config.getSeparatedDefinitionsFolder(), markupDocBuilder.addfileExtension(normalizeFileName(definitionName))).getPath();
|
||||
else
|
||||
return interDocumentCrossReferencesPrefix + markupDocBuilder.addfileExtension(definitionsDocument);
|
||||
return defaultString(config.getInterDocumentCrossReferencesPrefix()) + markupDocBuilder.addfileExtension(config.getDefinitionsDocument());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,11 +46,10 @@ public class OverviewDocument extends MarkupDocument {
|
||||
private final String BASE_PATH;
|
||||
private final String SCHEMES;
|
||||
|
||||
public OverviewDocument(Swagger swagger, Swagger2MarkupConfig swagger2MarkupConfig, String outputDirectory){
|
||||
super(swagger, swagger2MarkupConfig, outputDirectory);
|
||||
public OverviewDocument(Swagger swagger, Swagger2MarkupConfig config, String outputDirectory){
|
||||
super(swagger, config, outputDirectory);
|
||||
|
||||
ResourceBundle labels = ResourceBundle.getBundle("lang/labels",
|
||||
swagger2MarkupConfig.getOutputLanguage().toLocale());
|
||||
ResourceBundle labels = ResourceBundle.getBundle("lang/labels", config.getOutputLanguage().toLocale());
|
||||
OVERVIEW = labels.getString("overview");
|
||||
CURRENT_VERSION = labels.getString("current_version");
|
||||
VERSION = labels.getString("version");
|
||||
|
||||
@@ -86,32 +86,13 @@ public class PathsDocument extends MarkupDocument {
|
||||
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_FOLDER_NAME = "paths";
|
||||
private static final String DESCRIPTION_FILE_NAME = "description";
|
||||
|
||||
private boolean examplesEnabled;
|
||||
private String examplesFolderPath;
|
||||
private boolean descriptionsEnabled;
|
||||
private String descriptionsFolderPath;
|
||||
protected boolean operationExtensionsEnabled;
|
||||
protected String operationExtensionsFolderPath;
|
||||
private final GroupBy pathsGroupedBy;
|
||||
private final int inlineSchemaDepthLevel;
|
||||
private final Comparator<String> tagOrdering;
|
||||
private final Comparator<PathOperation> operationOrdering;
|
||||
private final Comparator<Parameter> parameterOrdering;
|
||||
private final Comparator<String> responseOrdering;
|
||||
private boolean separatedOperationsEnabled;
|
||||
private String separatedOperationsFolder;
|
||||
private String pathsDocument;
|
||||
private final boolean flatBody;
|
||||
|
||||
public PathsDocument(Swagger swagger, Swagger2MarkupConfig config, String outputDirectory){
|
||||
super(swagger,config, outputDirectory);
|
||||
|
||||
public PathsDocument(Swagger swagger, Swagger2MarkupConfig swagger2MarkupConfig, String outputDirectory){
|
||||
super(swagger,swagger2MarkupConfig, outputDirectory);
|
||||
|
||||
ResourceBundle labels = ResourceBundle.getBundle("lang/labels",
|
||||
swagger2MarkupConfig.getOutputLanguage().toLocale());
|
||||
ResourceBundle labels = ResourceBundle.getBundle("lang/labels", config.getOutputLanguage().toLocale());
|
||||
RESPONSE = labels.getString("response");
|
||||
PATHS = labels.getString("paths");
|
||||
RESOURCES = labels.getString("resources");
|
||||
@@ -125,22 +106,7 @@ public class PathsDocument extends MarkupDocument {
|
||||
TYPE_COLUMN = labels.getString("type_column");
|
||||
HTTP_CODE_COLUMN = labels.getString("http_code_column");
|
||||
|
||||
this.pathsDocument = swagger2MarkupConfig.getPathsDocument();
|
||||
this.inlineSchemaDepthLevel = swagger2MarkupConfig.getInlineSchemaDepthLevel();
|
||||
this.pathsGroupedBy = swagger2MarkupConfig.getPathsGroupedBy();
|
||||
if(isNotBlank(swagger2MarkupConfig.getExamplesFolderPath())){
|
||||
this.examplesEnabled = true;
|
||||
this.examplesFolderPath = swagger2MarkupConfig.getExamplesFolderPath();
|
||||
}
|
||||
if(isNotBlank(swagger2MarkupConfig.getDescriptionsFolderPath())){
|
||||
this.descriptionsEnabled = true;
|
||||
this.descriptionsFolderPath = swagger2MarkupConfig.getDescriptionsFolderPath() + "/" + DESCRIPTION_FOLDER_NAME;
|
||||
}
|
||||
if(isNotBlank(swagger2MarkupConfig.getOperationExtensionsFolderPath())){
|
||||
this.operationExtensionsEnabled = true;
|
||||
this.operationExtensionsFolderPath = swagger2MarkupConfig.getOperationExtensionsFolderPath();
|
||||
}
|
||||
if(examplesEnabled){
|
||||
if(config.isExamples()){
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Include examples is enabled.");
|
||||
}
|
||||
@@ -149,19 +115,17 @@ public class PathsDocument extends MarkupDocument {
|
||||
logger.debug("Include examples is disabled.");
|
||||
}
|
||||
}
|
||||
if(descriptionsEnabled){
|
||||
if(config.isOperationDescriptions()){
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Include hand-written descriptions is enabled.");
|
||||
logger.debug("Include hand-written operation descriptions is enabled.");
|
||||
}
|
||||
}else{
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Include hand-written descriptions is disabled.");
|
||||
logger.debug("Include hand-written operation descriptions is disabled.");
|
||||
}
|
||||
}
|
||||
|
||||
this.separatedOperationsEnabled = swagger2MarkupConfig.isSeparatedOperations();
|
||||
this.separatedOperationsFolder = swagger2MarkupConfig.getSeparatedOperationsFolder();
|
||||
if(this.separatedOperationsEnabled){
|
||||
if(config.isSeparatedOperations()){
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Create separated operation files is enabled.");
|
||||
}
|
||||
@@ -171,12 +135,6 @@ public class PathsDocument extends MarkupDocument {
|
||||
logger.debug("Create separated operation files is disabled.");
|
||||
}
|
||||
}
|
||||
this.tagOrdering = swagger2MarkupConfig.getTagOrdering();
|
||||
this.operationOrdering = swagger2MarkupConfig.getOperationOrdering();
|
||||
this.parameterOrdering = swagger2MarkupConfig.getParameterOrdering();
|
||||
this.responseOrdering = swagger2MarkupConfig.getResponseOrdering();
|
||||
|
||||
this.flatBody = swagger2MarkupConfig.isFlatBody();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -215,11 +173,11 @@ public class PathsDocument extends MarkupDocument {
|
||||
|
||||
if (allOperations.size() > 0) {
|
||||
|
||||
if (pathsGroupedBy == GroupBy.AS_IS) {
|
||||
if (config.getOperationsGroupedBy() == GroupBy.AS_IS) {
|
||||
addPathsTitle(PATHS);
|
||||
|
||||
if (this.operationOrdering != null) {
|
||||
Set<PathOperation> sortedOperations = new TreeSet<>(this.operationOrdering);
|
||||
if (config.getOperationOrdering() != null) {
|
||||
Set<PathOperation> sortedOperations = new TreeSet<>(config.getOperationOrdering());
|
||||
sortedOperations.addAll(allOperations);
|
||||
allOperations = sortedOperations;
|
||||
}
|
||||
@@ -232,7 +190,7 @@ public class PathsDocument extends MarkupDocument {
|
||||
} else {
|
||||
addPathsTitle(RESOURCES);
|
||||
|
||||
Multimap<String, PathOperation> operationsGroupedByTag = TagUtils.groupOperationsByTag(allOperations, tagOrdering, operationOrdering);
|
||||
Multimap<String, PathOperation> operationsGroupedByTag = TagUtils.groupOperationsByTag(allOperations, config.getTagOrdering(), config.getOperationOrdering());
|
||||
|
||||
Map<String, Tag> tagsMap = convertTagsListToMap(swagger.getTags());
|
||||
for (String tagName : operationsGroupedByTag.keySet()) {
|
||||
@@ -258,10 +216,10 @@ public class PathsDocument extends MarkupDocument {
|
||||
* @return operation filename
|
||||
*/
|
||||
private String resolveOperationDocument(PathOperation operation) {
|
||||
if (this.separatedOperationsEnabled)
|
||||
return new File(this.separatedOperationsFolder, this.markupDocBuilder.addfileExtension(normalizeFileName(operation.getId()))).getPath();
|
||||
if (config.isSeparatedOperations())
|
||||
return new File(config.getSeparatedOperationsFolder(), this.markupDocBuilder.addfileExtension(normalizeFileName(operation.getId()))).getPath();
|
||||
else
|
||||
return this.markupDocBuilder.addfileExtension(this.pathsDocument);
|
||||
return this.markupDocBuilder.addfileExtension(config.getPathsDocument());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -269,7 +227,7 @@ public class PathsDocument extends MarkupDocument {
|
||||
* @param operation operation
|
||||
*/
|
||||
private void processOperation(PathOperation operation) {
|
||||
if (separatedOperationsEnabled) {
|
||||
if (config.isSeparatedOperations()) {
|
||||
MarkupDocBuilder pathDocBuilder = this.markupDocBuilder.copy();
|
||||
operation(operation, pathDocBuilder);
|
||||
File operationFile = new File(outputDirectory, resolveOperationDocument(operation));
|
||||
@@ -320,9 +278,9 @@ public class PathsDocument extends MarkupDocument {
|
||||
if(operation != null){
|
||||
operationTitle(operation, docBuilder);
|
||||
descriptionSection(operation, docBuilder);
|
||||
inlineDefinitions(parametersSection(operation, docBuilder), operation.getPath() + " " + operation.getMethod(), inlineSchemaDepthLevel, docBuilder);
|
||||
inlineDefinitions(bodyParameterSection(operation, docBuilder), operation.getPath() + " " + operation.getMethod(), inlineSchemaDepthLevel, docBuilder);
|
||||
inlineDefinitions(responsesSection(operation, docBuilder), operation.getPath() + " " + operation.getMethod(), inlineSchemaDepthLevel, docBuilder);
|
||||
inlineDefinitions(parametersSection(operation, docBuilder), operation.getPath() + " " + operation.getMethod(), config.getInlineSchemaDepthLevel(), docBuilder);
|
||||
inlineDefinitions(bodyParameterSection(operation, docBuilder), operation.getPath() + " " + operation.getMethod(), config.getInlineSchemaDepthLevel(), docBuilder);
|
||||
inlineDefinitions(responsesSection(operation, docBuilder), operation.getPath() + " " + operation.getMethod(), config.getInlineSchemaDepthLevel(), docBuilder);
|
||||
consumesSection(operation, docBuilder);
|
||||
producesSection(operation, docBuilder);
|
||||
tagsSection(operation, docBuilder);
|
||||
@@ -368,7 +326,7 @@ public class PathsDocument extends MarkupDocument {
|
||||
* @param docBuilder the docbuilder do use for output
|
||||
*/
|
||||
private void addOperationTitle(String title, String anchor, MarkupDocBuilder docBuilder) {
|
||||
if(pathsGroupedBy == GroupBy.AS_IS){
|
||||
if(config.getOperationsGroupedBy() == GroupBy.AS_IS){
|
||||
docBuilder.sectionTitleWithAnchorLevel2(title, anchor);
|
||||
}else{
|
||||
docBuilder.sectionTitleWithAnchorLevel3(title, anchor);
|
||||
@@ -382,7 +340,7 @@ public class PathsDocument extends MarkupDocument {
|
||||
* @param docBuilder the docbuilder do use for output
|
||||
*/
|
||||
private void addOperationSectionTitle(String title, MarkupDocBuilder docBuilder) {
|
||||
if(pathsGroupedBy == GroupBy.AS_IS){
|
||||
if(config.getOperationsGroupedBy() == GroupBy.AS_IS){
|
||||
docBuilder.sectionTitleLevel3(title);
|
||||
}else{
|
||||
docBuilder.sectionTitleLevel4(title);
|
||||
@@ -402,7 +360,7 @@ public class PathsDocument extends MarkupDocument {
|
||||
* @param docBuilder the docbuilder do use for output
|
||||
*/
|
||||
private void descriptionSection(PathOperation operation, MarkupDocBuilder docBuilder) {
|
||||
if(descriptionsEnabled){
|
||||
if(config.isOperationDescriptions()){
|
||||
Optional<String> description = handWrittenOperationDescription(normalizeFileName(operation.getId()), DESCRIPTION_FILE_NAME);
|
||||
if (!description.isPresent())
|
||||
description = handWrittenOperationDescription(normalizeFileName(operation.getTitle()), DESCRIPTION_FILE_NAME);
|
||||
@@ -433,13 +391,13 @@ public class PathsDocument extends MarkupDocument {
|
||||
* @return true if parameter can be displayed
|
||||
*/
|
||||
private boolean filterParameter(Parameter parameter) {
|
||||
return (!this.flatBody || !StringUtils.equals(parameter.getIn(), "body"));
|
||||
return (!config.isFlatBody() || !StringUtils.equals(parameter.getIn(), "body"));
|
||||
}
|
||||
|
||||
private List<ObjectType> parametersSection(PathOperation operation, MarkupDocBuilder docBuilder) {
|
||||
List<Parameter> parameters = operation.getOperation().getParameters();
|
||||
if (this.parameterOrdering != null)
|
||||
Collections.sort(parameters, this.parameterOrdering);
|
||||
if (config.getParameterOrdering() != null)
|
||||
Collections.sort(parameters, config.getParameterOrdering());
|
||||
List<ObjectType> localDefinitions = new ArrayList<>();
|
||||
|
||||
boolean displayParameters = false;
|
||||
@@ -463,7 +421,7 @@ public class PathsDocument extends MarkupDocument {
|
||||
if (filterParameter(parameter)) {
|
||||
Type type = ParameterUtils.getType(parameter, new DefinitionDocumentResolverFromOperation());
|
||||
|
||||
if (inlineSchemaDepthLevel > 0 && type instanceof ObjectType) {
|
||||
if (config.getInlineSchemaDepthLevel() > 0 && type instanceof ObjectType) {
|
||||
if (MapUtils.isNotEmpty(((ObjectType) type).getProperties())) {
|
||||
String localTypeName = parameter.getName();
|
||||
|
||||
@@ -501,7 +459,7 @@ public class PathsDocument extends MarkupDocument {
|
||||
private List<ObjectType> bodyParameterSection(PathOperation operation, MarkupDocBuilder docBuilder) {
|
||||
List<ObjectType> localDefinitions = new ArrayList<>();
|
||||
|
||||
if (this.flatBody) {
|
||||
if (config.isFlatBody()) {
|
||||
List<Parameter> parameters = operation.getOperation().getParameters();
|
||||
if (CollectionUtils.isNotEmpty(parameters)) {
|
||||
for (Parameter parameter : parameters) {
|
||||
@@ -513,7 +471,7 @@ public class PathsDocument extends MarkupDocument {
|
||||
docBuilder.paragraph(parameter.getDescription());
|
||||
}
|
||||
|
||||
MarkupDocBuilder typeInfos = MarkupDocBuilders.documentBuilder(this.markupLanguage);
|
||||
MarkupDocBuilder typeInfos = MarkupDocBuilders.documentBuilder(config.getMarkupLanguage());
|
||||
typeInfos.italicText(REQUIRED_COLUMN).textLine(": " + parameter.getRequired());
|
||||
typeInfos.italicText(NAME_COLUMN).textLine(": " + parameter.getName());
|
||||
if (!(type instanceof ObjectType)) {
|
||||
@@ -523,7 +481,7 @@ public class PathsDocument extends MarkupDocument {
|
||||
} else {
|
||||
docBuilder.paragraph(typeInfos.toString());
|
||||
|
||||
localDefinitions.addAll(typeProperties((ObjectType)type, operation.getId(), this.inlineSchemaDepthLevel, new PropertyDescriptor(type), new DefinitionDocumentResolverFromOperation(), docBuilder));
|
||||
localDefinitions.addAll(typeProperties((ObjectType)type, operation.getId(), config.getInlineSchemaDepthLevel(), new PropertyDescriptor(type), new DefinitionDocumentResolverFromOperation(), docBuilder));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -547,7 +505,7 @@ public class PathsDocument extends MarkupDocument {
|
||||
* @return the description of a parameter.
|
||||
*/
|
||||
private String parameterDescription(final PathOperation operation, Parameter parameter){
|
||||
if (descriptionsEnabled) {
|
||||
if (config.isOperationDescriptions()) {
|
||||
final String parameterName = parameter.getName();
|
||||
if (isNotBlank(parameterName)) {
|
||||
Optional<String> description = handWrittenOperationDescription(new File(normalizeFileName(operation.getId()), parameterName).getPath(), DESCRIPTION_FILE_NAME);
|
||||
@@ -591,15 +549,15 @@ public class PathsDocument extends MarkupDocument {
|
||||
}
|
||||
|
||||
private void tagsSection(PathOperation operation, MarkupDocBuilder docBuilder) {
|
||||
if(pathsGroupedBy == GroupBy.AS_IS) {
|
||||
if(config.getOperationsGroupedBy() == GroupBy.AS_IS) {
|
||||
List<String> tags = operation.getOperation().getTags();
|
||||
if (CollectionUtils.isNotEmpty(tags)) {
|
||||
addOperationSectionTitle(TAGS, docBuilder);
|
||||
Set<String> sortedTags;
|
||||
if (tagOrdering == null)
|
||||
if (config.getTagOrdering() == null)
|
||||
sortedTags = new LinkedHashSet<>();
|
||||
else
|
||||
sortedTags = new TreeSet<>(this.tagOrdering);
|
||||
sortedTags = new TreeSet<>(config.getTagOrdering());
|
||||
sortedTags.addAll(tags);
|
||||
docBuilder.unorderedList(new ArrayList<>(sortedTags));
|
||||
}
|
||||
@@ -619,7 +577,7 @@ public class PathsDocument extends MarkupDocument {
|
||||
* @param docBuilder the docbuilder do use for output
|
||||
*/
|
||||
private void examplesSection(PathOperation operation, MarkupDocBuilder docBuilder) {
|
||||
if(examplesEnabled){
|
||||
if(config.isExamples()){
|
||||
Optional<String> curlExample = example(normalizeFileName(operation.getId()), CURL_EXAMPLE_FILE_NAME);
|
||||
if (!curlExample.isPresent())
|
||||
curlExample = example(normalizeFileName(operation.getTitle()), CURL_EXAMPLE_FILE_NAME);
|
||||
@@ -657,8 +615,8 @@ public class PathsDocument extends MarkupDocument {
|
||||
* @return the content of the file
|
||||
*/
|
||||
private Optional<String> example(String exampleFolder, String exampleFileName) {
|
||||
for (String fileNameExtension : markupLanguage.getFileNameExtensions()) {
|
||||
java.nio.file.Path path = Paths.get(examplesFolderPath, exampleFolder, exampleFileName + fileNameExtension);
|
||||
for (String fileNameExtension : config.getMarkupLanguage().getFileNameExtensions()) {
|
||||
java.nio.file.Path path = Paths.get(config.getExamplesPath(), exampleFolder, exampleFileName + fileNameExtension);
|
||||
if (Files.isReadable(path)) {
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Example file processed: {}", path);
|
||||
@@ -677,7 +635,7 @@ public class PathsDocument extends MarkupDocument {
|
||||
}
|
||||
}
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("No example file found with correct file name extension in folder: {}", Paths.get(examplesFolderPath, exampleFolder));
|
||||
logger.warn("No example file found with correct file name extension in folder: {}", Paths.get(config.getExamplesPath(), exampleFolder));
|
||||
}
|
||||
return Optional.absent();
|
||||
}
|
||||
@@ -722,8 +680,8 @@ public class PathsDocument extends MarkupDocument {
|
||||
* @return the content of the file
|
||||
*/
|
||||
private Optional<String> handWrittenOperationDescription(String descriptionFolder, String descriptionFileName){
|
||||
for (String fileNameExtension : markupLanguage.getFileNameExtensions()) {
|
||||
java.nio.file.Path path = Paths.get(descriptionsFolderPath, descriptionFolder, descriptionFileName + fileNameExtension);
|
||||
for (String fileNameExtension : config.getMarkupLanguage().getFileNameExtensions()) {
|
||||
java.nio.file.Path path = Paths.get(config.getOperationDescriptionsPath(), descriptionFolder, descriptionFileName + fileNameExtension);
|
||||
if (Files.isReadable(path)) {
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Description file processed: {}", path);
|
||||
@@ -742,7 +700,7 @@ public class PathsDocument extends MarkupDocument {
|
||||
}
|
||||
}
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("No description file found with correct file name extension in folder: {}", Paths.get(descriptionsFolderPath, descriptionFolder));
|
||||
logger.warn("No description file found with correct file name extension in folder: {}", Paths.get(config.getOperationDescriptionsPath(), descriptionFolder));
|
||||
}
|
||||
return Optional.absent();
|
||||
}
|
||||
@@ -758,10 +716,10 @@ public class PathsDocument extends MarkupDocument {
|
||||
new MarkupTableColumn(DESCRIPTION_COLUMN, 6).withMarkupSpecifiers(MarkupLanguage.ASCIIDOC, ".^6"),
|
||||
new MarkupTableColumn(SCHEMA_COLUMN, 1).withMarkupSpecifiers(MarkupLanguage.ASCIIDOC, ".^1"));
|
||||
Set<String> responseNames;
|
||||
if (this.responseOrdering == null)
|
||||
if (config.getResponseOrdering() == null)
|
||||
responseNames = new LinkedHashSet<>();
|
||||
else
|
||||
responseNames = new TreeSet<>(this.responseOrdering);
|
||||
responseNames = new TreeSet<>(config.getResponseOrdering());
|
||||
responseNames.addAll(responses.keySet());
|
||||
|
||||
for(String responseName : responseNames){
|
||||
@@ -770,7 +728,7 @@ public class PathsDocument extends MarkupDocument {
|
||||
if(response.getSchema() != null){
|
||||
Property property = response.getSchema();
|
||||
Type type = PropertyUtils.getType(property, new DefinitionDocumentResolverFromOperation());
|
||||
if (this.inlineSchemaDepthLevel > 0 && type instanceof ObjectType) {
|
||||
if (config.getInlineSchemaDepthLevel() > 0 && type instanceof ObjectType) {
|
||||
if (MapUtils.isNotEmpty(((ObjectType) type).getProperties())) {
|
||||
String localTypeName = RESPONSE + " " + responseName;
|
||||
|
||||
@@ -831,13 +789,13 @@ public class PathsDocument extends MarkupDocument {
|
||||
* @param docBuilder the MarkupDocBuilder document builder
|
||||
*/
|
||||
private void extensionsSection(PathOperation operation, MarkupDocBuilder docBuilder) {
|
||||
if (this.operationExtensionsEnabled) {
|
||||
final Collection<String> filenameExtensions = Collections2.transform(markupLanguage.getFileNameExtensions(), new Function<String, String>() {
|
||||
if (config.isOperationExtensions()) {
|
||||
final Collection<String> filenameExtensions = Collections2.transform(config.getMarkupLanguage().getFileNameExtensions(), new Function<String, String>() {
|
||||
public String apply(String input) {
|
||||
return StringUtils.stripStart(input, ".");
|
||||
}
|
||||
});
|
||||
File operationExtensionsPath = new File(new File(this.operationExtensionsFolderPath), normalizeFileName(operation.getId()));
|
||||
File operationExtensionsPath = new File(new File(config.getOperationExtensionsPath()), normalizeFileName(operation.getId()));
|
||||
|
||||
File[] extensionFiles = operationExtensionsPath.listFiles(new FilenameFilter() {
|
||||
public boolean accept(File dir, String name) {
|
||||
@@ -854,7 +812,7 @@ public class PathsDocument extends MarkupDocument {
|
||||
|
||||
if (extensionContent.isPresent()) {
|
||||
int levelOffset = 3;
|
||||
if (pathsGroupedBy == GroupBy.AS_IS) {
|
||||
if (config.getOperationsGroupedBy() == GroupBy.AS_IS) {
|
||||
levelOffset = 2;
|
||||
}
|
||||
try {
|
||||
@@ -879,8 +837,8 @@ public class PathsDocument extends MarkupDocument {
|
||||
public String apply(String definitionName) {
|
||||
String defaultResolver = super.apply(definitionName);
|
||||
|
||||
if (defaultResolver != null && separatedOperationsEnabled)
|
||||
return interDocumentCrossReferencesPrefix + new File("..", defaultResolver).getPath();
|
||||
if (defaultResolver != null && config.isSeparatedOperations())
|
||||
return defaultString(config.getInterDocumentCrossReferencesPrefix()) + new File("..", defaultResolver).getPath();
|
||||
else
|
||||
return defaultResolver;
|
||||
}
|
||||
|
||||
@@ -51,11 +51,10 @@ public class SecurityDocument extends MarkupDocument {
|
||||
private final String AUTHORIZATION_URL;
|
||||
private final String TOKEN_URL;
|
||||
|
||||
public SecurityDocument(Swagger swagger, Swagger2MarkupConfig swagger2MarkupConfig, String outputDirectory) {
|
||||
super(swagger, swagger2MarkupConfig, outputDirectory);
|
||||
public SecurityDocument(Swagger swagger, Swagger2MarkupConfig config, String outputDirectory) {
|
||||
super(swagger, config, outputDirectory);
|
||||
|
||||
ResourceBundle labels = ResourceBundle.getBundle("lang/labels",
|
||||
swagger2MarkupConfig.getOutputLanguage().toLocale());
|
||||
ResourceBundle labels = ResourceBundle.getBundle("lang/labels", config.getOutputLanguage().toLocale());
|
||||
SECURITY = labels.getString("security");
|
||||
TYPE = labels.getString("security_type");
|
||||
NAME = labels.getString("security_name");
|
||||
|
||||
@@ -26,24 +26,35 @@ import io.github.robwin.swagger2markup.Language;
|
||||
import io.github.robwin.swagger2markup.OrderBy;
|
||||
import io.github.robwin.swagger2markup.PathOperation;
|
||||
import io.swagger.models.HttpMethod;
|
||||
import io.swagger.models.Swagger;
|
||||
import io.swagger.models.parameters.Parameter;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Comparator;
|
||||
import java.util.Properties;
|
||||
|
||||
public class Swagger2MarkupConfig {
|
||||
|
||||
static final String OPERATIONS_FOLDER = "operations";
|
||||
static final String DEFINITIONS_FOLDER = "definitions";
|
||||
|
||||
private MarkupLanguage markupLanguage;
|
||||
private String examplesFolderPath;
|
||||
private String schemasFolderPath;
|
||||
private String descriptionsFolderPath;
|
||||
private String operationExtensionsFolderPath;
|
||||
private String definitionExtensionsFolderPath;
|
||||
private boolean examples;
|
||||
private String examplesPath;
|
||||
private boolean schemas;
|
||||
private String schemasPath;
|
||||
private boolean operationDescriptions;
|
||||
private String operationDescriptionsPath;
|
||||
private boolean definitionDescriptions;
|
||||
private String definitionDescriptionsPath;
|
||||
private boolean operationExtensions;
|
||||
private String operationExtensionsPath;
|
||||
private boolean definitionExtensions;
|
||||
private String definitionExtensionsPath;
|
||||
private boolean separatedDefinitions;
|
||||
private boolean separatedOperations;
|
||||
private GroupBy pathsGroupedBy;
|
||||
private GroupBy operationsGroupedBy;
|
||||
@Deprecated
|
||||
private OrderBy definitionsOrderedBy;
|
||||
private Language outputLanguage;
|
||||
@@ -74,28 +85,101 @@ public class Swagger2MarkupConfig {
|
||||
return new Builder(properties);
|
||||
}
|
||||
|
||||
/**
|
||||
* Automatically set default path for external files based on Swagger file base path.<br/>
|
||||
* If {@code basePath} is null, default path can't be set and a RuntimeException is thrown.
|
||||
*
|
||||
* @param basePath base path to set default paths
|
||||
* @throws RuntimeException if basePath == null and any path is not configured
|
||||
*/
|
||||
public void configurePathsDefaults(File basePath) {
|
||||
if (examples && examplesPath == null) {
|
||||
if (basePath == null)
|
||||
throw new RuntimeException(String.format("'%s' configuration entry is not set and has no default", "examplesPath"));
|
||||
examplesPath = new File(basePath, OPERATIONS_FOLDER).getPath();
|
||||
}
|
||||
|
||||
if (schemas && schemasPath == null) {
|
||||
if (basePath == null)
|
||||
throw new RuntimeException(String.format("'%s' configuration entry is not set and has no default", "schemasPath"));
|
||||
schemasPath = new File(basePath, DEFINITIONS_FOLDER).getPath();
|
||||
}
|
||||
|
||||
if (operationDescriptions && operationDescriptionsPath == null) {
|
||||
if (basePath == null)
|
||||
throw new RuntimeException(String.format("'%s' configuration entry is not set and has no default", "operationDescriptions"));
|
||||
operationDescriptionsPath = new File(basePath, OPERATIONS_FOLDER).getPath();
|
||||
}
|
||||
|
||||
if (definitionDescriptions && definitionDescriptionsPath == null) {
|
||||
if (basePath == null)
|
||||
throw new RuntimeException(String.format("'%s' configuration entry is not set and has no default", "definitionDescriptions"));
|
||||
definitionDescriptionsPath = new File(basePath, DEFINITIONS_FOLDER).getPath();
|
||||
}
|
||||
|
||||
if (operationExtensions && operationExtensionsPath == null) {
|
||||
if (basePath == null)
|
||||
throw new RuntimeException(String.format("'%s' configuration entry is not set and has no default", "operationExtensions"));
|
||||
operationExtensionsPath = new File(basePath, OPERATIONS_FOLDER).getPath();
|
||||
}
|
||||
|
||||
if (definitionExtensions && definitionExtensionsPath == null) {
|
||||
if (basePath == null)
|
||||
throw new RuntimeException(String.format("'%s' configuration entry is not set and has no default", "definitionExtensions"));
|
||||
definitionExtensionsPath = new File(basePath, DEFINITIONS_FOLDER).getPath();
|
||||
}
|
||||
}
|
||||
|
||||
public MarkupLanguage getMarkupLanguage() {
|
||||
return markupLanguage;
|
||||
}
|
||||
|
||||
public String getExamplesFolderPath() {
|
||||
return examplesFolderPath;
|
||||
public boolean isExamples() {
|
||||
return examples;
|
||||
}
|
||||
|
||||
public String getSchemasFolderPath() {
|
||||
return schemasFolderPath;
|
||||
public String getExamplesPath() {
|
||||
return examplesPath;
|
||||
}
|
||||
|
||||
public String getDescriptionsFolderPath() {
|
||||
return descriptionsFolderPath;
|
||||
public boolean isSchemas() {
|
||||
return schemas;
|
||||
}
|
||||
|
||||
public String getOperationExtensionsFolderPath() {
|
||||
return operationExtensionsFolderPath;
|
||||
public String getSchemasPath() {
|
||||
return schemasPath;
|
||||
}
|
||||
|
||||
public String getDefinitionExtensionsFolderPath() {
|
||||
return definitionExtensionsFolderPath;
|
||||
public boolean isOperationDescriptions() {
|
||||
return operationDescriptions;
|
||||
}
|
||||
|
||||
public String getOperationDescriptionsPath() {
|
||||
return operationDescriptionsPath;
|
||||
}
|
||||
|
||||
public boolean isDefinitionDescriptions() {
|
||||
return definitionDescriptions;
|
||||
}
|
||||
|
||||
public String getDefinitionDescriptionsPath() {
|
||||
return definitionDescriptionsPath;
|
||||
}
|
||||
|
||||
public boolean isOperationExtensions() {
|
||||
return operationExtensions;
|
||||
}
|
||||
|
||||
public String getOperationExtensionsPath() {
|
||||
return operationExtensionsPath;
|
||||
}
|
||||
|
||||
public boolean isDefinitionExtensions() {
|
||||
return definitionExtensions;
|
||||
}
|
||||
|
||||
public String getDefinitionExtensionsPath() {
|
||||
return definitionExtensionsPath;
|
||||
}
|
||||
|
||||
public boolean isSeparatedDefinitions() {
|
||||
@@ -106,8 +190,8 @@ public class Swagger2MarkupConfig {
|
||||
return separatedOperations;
|
||||
}
|
||||
|
||||
public GroupBy getPathsGroupedBy() {
|
||||
return pathsGroupedBy;
|
||||
public GroupBy getOperationsGroupedBy() {
|
||||
return operationsGroupedBy;
|
||||
}
|
||||
|
||||
public OrderBy getDefinitionsOrderedBy() {
|
||||
@@ -188,13 +272,8 @@ public class Swagger2MarkupConfig {
|
||||
|
||||
public static class Builder {
|
||||
|
||||
static final String OVERVIEW_DOCUMENT = "overview";
|
||||
static final String PATHS_DOCUMENT = "paths";
|
||||
static final String DEFINITIONS_DOCUMENT = "definitions";
|
||||
static final String SECURITY_DOCUMENT = "security";
|
||||
|
||||
static final String SEPARATED_DEFINITIONS_FOLDER = "definitions";
|
||||
static final String SEPARATED_OPERATIONS_FOLDER = "operations";
|
||||
private static final String PROPERTIES_PREFIX = "swagger2markup.";
|
||||
private static final String PROPERTIES_DEFAULT = "/io/github/robwin/swagger2markup/config/default.properties";
|
||||
|
||||
static final Ordering<PathOperation> OPERATION_METHOD_COMPARATOR = Ordering
|
||||
.explicit(HttpMethod.GET, HttpMethod.PUT, HttpMethod.POST, HttpMethod.DELETE, HttpMethod.PATCH, HttpMethod.HEAD, HttpMethod.OPTIONS)
|
||||
@@ -228,75 +307,69 @@ public class Swagger2MarkupConfig {
|
||||
}
|
||||
});
|
||||
|
||||
private static final String PROPERTIES_PREFIX = "swagger2markup.";
|
||||
|
||||
private Swagger2MarkupConfig config = new Swagger2MarkupConfig();
|
||||
|
||||
public Builder() {
|
||||
config.markupLanguage = MarkupLanguage.ASCIIDOC;
|
||||
config.separatedDefinitions = false;
|
||||
config.separatedOperations = false;
|
||||
config.pathsGroupedBy = GroupBy.AS_IS;
|
||||
config.definitionsOrderedBy = OrderBy.NATURAL;
|
||||
config.outputLanguage = Language.EN;
|
||||
config.inlineSchemaDepthLevel = 0;
|
||||
this(new Properties());
|
||||
}
|
||||
|
||||
public Builder(Properties properties) {
|
||||
|
||||
Properties safeProperties = new Properties(defaultProperties());
|
||||
safeProperties.putAll(properties);
|
||||
|
||||
config.markupLanguage = MarkupLanguage.valueOf(safeProperties.getProperty(PROPERTIES_PREFIX + "markupLanguage"));
|
||||
config.examples = Boolean.valueOf(safeProperties.getProperty(PROPERTIES_PREFIX + "examples"));
|
||||
config.examplesPath = safeProperties.getProperty(PROPERTIES_PREFIX + "examplesPath");
|
||||
config.schemas = Boolean.valueOf(safeProperties.getProperty(PROPERTIES_PREFIX + "schemas"));
|
||||
config.schemasPath = safeProperties.getProperty(PROPERTIES_PREFIX + "schemasPath");
|
||||
config.operationDescriptions = Boolean.valueOf(safeProperties.getProperty(PROPERTIES_PREFIX + "operationDescriptions"));
|
||||
config.operationDescriptionsPath = safeProperties.getProperty(PROPERTIES_PREFIX + "operationDescriptionsPath");
|
||||
config.definitionDescriptions = Boolean.valueOf(safeProperties.getProperty(PROPERTIES_PREFIX + "definitionDescriptions"));
|
||||
config.definitionDescriptionsPath = safeProperties.getProperty(PROPERTIES_PREFIX + "definitionDescriptionsPath");
|
||||
config.operationExtensions = Boolean.valueOf(safeProperties.getProperty(PROPERTIES_PREFIX + "operationExtensions"));
|
||||
config.operationExtensionsPath = safeProperties.getProperty(PROPERTIES_PREFIX + "operationExtensionsPath");
|
||||
config.definitionExtensions = Boolean.valueOf(safeProperties.getProperty(PROPERTIES_PREFIX + "definitionExtensions"));
|
||||
config.definitionExtensionsPath = safeProperties.getProperty(PROPERTIES_PREFIX + "definitionExtensionsPath");
|
||||
config.separatedDefinitions = Boolean.valueOf(safeProperties.getProperty(PROPERTIES_PREFIX + "separatedDefinitions"));
|
||||
config.separatedOperations = Boolean.valueOf(safeProperties.getProperty(PROPERTIES_PREFIX + "separatedOperations"));
|
||||
config.operationsGroupedBy = GroupBy.valueOf(safeProperties.getProperty(PROPERTIES_PREFIX + "operationsGroupedBy"));
|
||||
config.definitionsOrderedBy = OrderBy.valueOf(safeProperties.getProperty(PROPERTIES_PREFIX + "definitionsOrderedBy"));
|
||||
config.outputLanguage = Language.valueOf(safeProperties.getProperty(PROPERTIES_PREFIX + "outputLanguage"));
|
||||
config.inlineSchemaDepthLevel = Integer.valueOf(safeProperties.getProperty(PROPERTIES_PREFIX + "inlineSchemaDepthLevel"));
|
||||
config.interDocumentCrossReferences = Boolean.valueOf(safeProperties.getProperty(PROPERTIES_PREFIX + "interDocumentCrossReferences"));
|
||||
config.interDocumentCrossReferencesPrefix = safeProperties.getProperty(PROPERTIES_PREFIX + "interDocumentCrossReferencesPrefix");
|
||||
config.flatBody = Boolean.valueOf(safeProperties.getProperty(PROPERTIES_PREFIX + "flatBody"));
|
||||
config.anchorPrefix = safeProperties.getProperty(PROPERTIES_PREFIX + "anchorPrefix");
|
||||
config.overviewDocument = safeProperties.getProperty(PROPERTIES_PREFIX + "overviewDocument");
|
||||
config.pathsDocument = safeProperties.getProperty(PROPERTIES_PREFIX + "pathsDocument");
|
||||
config.definitionsDocument = safeProperties.getProperty(PROPERTIES_PREFIX + "definitionsDocument");
|
||||
config.securityDocument = safeProperties.getProperty(PROPERTIES_PREFIX + "securityDocument");
|
||||
config.separatedOperationsFolder = safeProperties.getProperty(PROPERTIES_PREFIX + "separatedOperationsFolder");
|
||||
config.separatedDefinitionsFolder = safeProperties.getProperty(PROPERTIES_PREFIX + "separatedDefinitionsFolder");
|
||||
|
||||
config.tagOrdering = Ordering.natural();
|
||||
config.operationOrdering = OPERATION_PATH_COMPARATOR.compound(OPERATION_METHOD_COMPARATOR);
|
||||
config.definitionOrdering = Ordering.natural();
|
||||
config.parameterOrdering = PARAMETER_IN_COMPARATOR.compound(PARAMETER_NAME_COMPARATOR);
|
||||
config.propertyOrdering = Ordering.natural();
|
||||
config.responseOrdering = Ordering.natural();
|
||||
config.interDocumentCrossReferences = false;
|
||||
config.interDocumentCrossReferencesPrefix = "";
|
||||
config.flatBody = false;
|
||||
|
||||
config.overviewDocument = OVERVIEW_DOCUMENT;
|
||||
config.pathsDocument = PATHS_DOCUMENT;
|
||||
config.definitionsDocument = DEFINITIONS_DOCUMENT;
|
||||
config.securityDocument = SECURITY_DOCUMENT;
|
||||
config.separatedOperationsFolder = SEPARATED_OPERATIONS_FOLDER;
|
||||
config.separatedDefinitionsFolder = SEPARATED_DEFINITIONS_FOLDER;
|
||||
|
||||
}
|
||||
|
||||
public Builder(Properties properties) {
|
||||
this();
|
||||
private Properties defaultProperties() {
|
||||
Properties defaultProperties = new Properties();
|
||||
try {
|
||||
InputStream defaultPropertiesStream = Swagger2MarkupConfig.class.getResourceAsStream(PROPERTIES_DEFAULT);
|
||||
if (defaultPropertiesStream == null)
|
||||
throw new RuntimeException(String.format("Can't load default properties '%s'", PROPERTIES_DEFAULT));
|
||||
defaultProperties.load(defaultPropertiesStream);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(String.format("Can't load default properties '%s'", PROPERTIES_DEFAULT), e);
|
||||
}
|
||||
|
||||
if (properties.containsKey(PROPERTIES_PREFIX + "markupLanguage"))
|
||||
config.markupLanguage = MarkupLanguage.valueOf(properties.getProperty(PROPERTIES_PREFIX + "markupLanguage"));
|
||||
if (properties.containsKey(PROPERTIES_PREFIX + "examplesFolderPath"))
|
||||
config.examplesFolderPath = properties.getProperty(PROPERTIES_PREFIX + "examplesFolderPath");
|
||||
if (properties.containsKey(PROPERTIES_PREFIX + "schemasFolderPath"))
|
||||
config.schemasFolderPath = properties.getProperty(PROPERTIES_PREFIX + "schemasFolderPath");
|
||||
if (properties.containsKey(PROPERTIES_PREFIX + "descriptionsFolderPath"))
|
||||
config.descriptionsFolderPath = properties.getProperty(PROPERTIES_PREFIX + "descriptionsFolderPath");
|
||||
if (properties.containsKey(PROPERTIES_PREFIX + "operationExtensionsFolderPath"))
|
||||
config.operationExtensionsFolderPath = properties.getProperty(PROPERTIES_PREFIX + "operationExtensionsFolderPath");
|
||||
if (properties.containsKey(PROPERTIES_PREFIX + "definitionExtensionsFolderPath"))
|
||||
config.definitionExtensionsFolderPath = properties.getProperty(PROPERTIES_PREFIX + "definitionExtensionsFolderPath");
|
||||
if (properties.containsKey(PROPERTIES_PREFIX + "separatedDefinitions"))
|
||||
config.separatedDefinitions = Boolean.valueOf(properties.getProperty(PROPERTIES_PREFIX + "separatedDefinitions"));
|
||||
if (properties.containsKey(PROPERTIES_PREFIX + "separatedOperations"))
|
||||
config.separatedOperations = Boolean.valueOf(properties.getProperty(PROPERTIES_PREFIX + "separatedOperations"));
|
||||
if (properties.containsKey(PROPERTIES_PREFIX + "pathsGroupedBy"))
|
||||
config.pathsGroupedBy = GroupBy.valueOf(properties.getProperty(PROPERTIES_PREFIX + "pathsGroupedBy"));
|
||||
if (properties.containsKey(PROPERTIES_PREFIX + "definitionsOrderedBy"))
|
||||
config.definitionsOrderedBy = OrderBy.valueOf(properties.getProperty(PROPERTIES_PREFIX + "definitionsOrderedBy"));
|
||||
if (properties.containsKey(PROPERTIES_PREFIX + "outputLanguage"))
|
||||
config.outputLanguage = Language.valueOf(properties.getProperty(PROPERTIES_PREFIX + "outputLanguage"));
|
||||
if (properties.containsKey(PROPERTIES_PREFIX + "inlineSchemaDepthLevel"))
|
||||
config.inlineSchemaDepthLevel = Integer.valueOf(properties.getProperty(PROPERTIES_PREFIX + "inlineSchemaDepthLevel"));
|
||||
if (properties.containsKey(PROPERTIES_PREFIX + "interDocumentCrossReferences"))
|
||||
config.interDocumentCrossReferences = Boolean.valueOf(properties.getProperty(PROPERTIES_PREFIX + "interDocumentCrossReferences"));
|
||||
if (properties.containsKey(PROPERTIES_PREFIX + "interDocumentCrossReferencesPrefix"))
|
||||
config.interDocumentCrossReferencesPrefix = properties.getProperty(PROPERTIES_PREFIX + "interDocumentCrossReferencesPrefix");
|
||||
if (properties.containsKey(PROPERTIES_PREFIX + "flatBody"))
|
||||
config.flatBody = Boolean.valueOf(properties.getProperty(PROPERTIES_PREFIX + "flatBody"));
|
||||
if (properties.containsKey(PROPERTIES_PREFIX + "anchorPrefix"))
|
||||
config.anchorPrefix = properties.getProperty(PROPERTIES_PREFIX + "anchorPrefix");
|
||||
return defaultProperties;
|
||||
}
|
||||
|
||||
|
||||
public Swagger2MarkupConfig build() {
|
||||
return config;
|
||||
}
|
||||
@@ -315,56 +388,138 @@ public class Swagger2MarkupConfig {
|
||||
/**
|
||||
* Include examples into the Paths document
|
||||
*
|
||||
* @param examplesFolderPath the path to the folder where the example documents reside
|
||||
* @param examplesPath the path to the folder where the example documents reside. Use default path if null.
|
||||
* @return this builder
|
||||
*/
|
||||
public Builder withExamples(String examplesFolderPath) {
|
||||
config.examplesFolderPath = examplesFolderPath;
|
||||
public Builder withExamples(String examplesPath) {
|
||||
config.examples = true;
|
||||
config.examplesPath = examplesPath;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Include examples into the Paths document.<br/>
|
||||
* This is an alias for {@link #withExamples(String) withExamples(null)}.
|
||||
*
|
||||
* @return this builder
|
||||
*/
|
||||
public Builder withExamples() {
|
||||
withExamples(null);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Include (JSON, XML) schemas into the Definitions document
|
||||
*
|
||||
* @param schemasFolderPath the path to the folder where the schema documents reside
|
||||
* @param schemasPath the path to the folder where the schema documents reside. Use default path if null.
|
||||
* @return this builder
|
||||
*/
|
||||
public Builder withSchemas(String schemasFolderPath) {
|
||||
config.schemasFolderPath = schemasFolderPath;
|
||||
public Builder withSchemas(String schemasPath) {
|
||||
config.schemas = true;
|
||||
config.schemasPath = schemasPath;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Include hand-written descriptions into the Paths and Definitions document
|
||||
* Include (JSON, XML) schemas into the Definitions document.<br/>
|
||||
* This is an alias for {@link #withSchemas(String) withSchemas(null)}.
|
||||
*
|
||||
* @param descriptionsFolderPath the path to the folder where the description documents reside
|
||||
* @return this builder
|
||||
*/
|
||||
public Builder withDescriptions(String descriptionsFolderPath) {
|
||||
config.descriptionsFolderPath = descriptionsFolderPath;
|
||||
public Builder withSchemas() {
|
||||
withSchemas(null);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Include hand-written descriptions into the Paths document
|
||||
*
|
||||
* @param operationDescriptionsPath the path to the folder where the description documents reside. Use default path if null.
|
||||
* @return this builder
|
||||
*/
|
||||
public Builder withOperationDescriptions(String operationDescriptionsPath) {
|
||||
config.operationDescriptions = true;
|
||||
config.operationDescriptionsPath = operationDescriptionsPath;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Include hand-written descriptions into the Paths document.<br/>
|
||||
* This is an alias for {@link #withOperationDescriptions(String) withOperationDescriptions(null)}.
|
||||
*
|
||||
* @return this builder
|
||||
*/
|
||||
public Builder withOperationDescriptions() {
|
||||
withOperationDescriptions(null);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Include hand-written descriptions into the Definitions document
|
||||
*
|
||||
* @param definitionDescriptionsPath the path to the folder where the description documents reside. Use default path if null.
|
||||
* @return this builder
|
||||
*/
|
||||
public Builder withDefinitionDescriptions(String definitionDescriptionsPath) {
|
||||
config.definitionDescriptions = true;
|
||||
config.definitionDescriptionsPath = definitionDescriptionsPath;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Include hand-written descriptions into the Paths document.<br/>
|
||||
* This is an alias for {@link #withDefinitionDescriptions(String) withDefinitionDescriptions(null)}.
|
||||
*
|
||||
* @return this builder
|
||||
*/
|
||||
public Builder withDefinitionDescriptions() {
|
||||
withDefinitionDescriptions(null);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Include extensions into Paths document
|
||||
*
|
||||
* @param operationExtensionsFolderPath the path to the folder where the operation extension documents reside
|
||||
* @param operationExtensionsFolderPath the path to the folder where the operation extension documents reside. Use default path if null.
|
||||
* @return this builder
|
||||
*/
|
||||
public Builder withOperationExtensions(String operationExtensionsFolderPath) {
|
||||
config.operationExtensionsFolderPath = operationExtensionsFolderPath;
|
||||
config.operationExtensions = true;
|
||||
config.operationExtensionsPath = operationExtensionsFolderPath;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Include extensions into Paths document.<br/>
|
||||
* This is an alias for {@link #withOperationExtensions(String) withOperationExtensions(null)}.
|
||||
*
|
||||
* @return this builder
|
||||
*/
|
||||
public Builder withOperationExtensions() {
|
||||
withOperationExtensions(null);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Include extensions into Definitions document
|
||||
*
|
||||
* @param definitionExtensionsFolderPath the path to the folder where the definition extension documents reside
|
||||
* @param definitionExtensionsFolderPath the path to the folder where the definition extension documents reside. Use default path if null.
|
||||
* @return this builder
|
||||
*/
|
||||
public Builder withDefinitionExtensions(String definitionExtensionsFolderPath) {
|
||||
config.definitionExtensionsFolderPath = definitionExtensionsFolderPath;
|
||||
config.definitionExtensions = true;
|
||||
config.definitionExtensionsPath = definitionExtensionsFolderPath;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Include extensions into Definitions document.<br/>
|
||||
* This is an alias for {@link #withDefinitionExtensions(String) withDefinitionExtensions(null)}.
|
||||
*
|
||||
* @return this builder
|
||||
*/
|
||||
public Builder withDefinitionExtensions() {
|
||||
withDefinitionExtensions(null);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -397,7 +552,7 @@ public class Swagger2MarkupConfig {
|
||||
* @return this builder
|
||||
*/
|
||||
public Builder withPathsGroupedBy(GroupBy pathsGroupedBy) {
|
||||
config.pathsGroupedBy = pathsGroupedBy;
|
||||
config.operationsGroupedBy = pathsGroupedBy;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -522,17 +677,6 @@ public class Swagger2MarkupConfig {
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Enable use of inter-document cross-references when needed
|
||||
*
|
||||
* @return this builder
|
||||
*/
|
||||
public Builder withInterDocumentCrossReferences() {
|
||||
config.interDocumentCrossReferences = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable use of inter-document cross-references when needed
|
||||
*
|
||||
@@ -540,14 +684,22 @@ public class Swagger2MarkupConfig {
|
||||
* @return this builder
|
||||
*/
|
||||
public Builder withInterDocumentCrossReferences(String prefix) {
|
||||
if (prefix == null)
|
||||
return withInterDocumentCrossReferences();
|
||||
|
||||
config.interDocumentCrossReferences = true;
|
||||
config.interDocumentCrossReferencesPrefix = prefix;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable use of inter-document cross-references when needed.<br/>
|
||||
* This is an alias for {@link #withInterDocumentCrossReferences(String) withInterDocumentCrossReferences(null)}.
|
||||
*
|
||||
* @return this builder
|
||||
*/
|
||||
public Builder withInterDocumentCrossReferences() {
|
||||
withInterDocumentCrossReferences(null);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Optionally isolate the body parameter, if any, from other parameters
|
||||
*
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
swagger2markup.markupLanguage=ASCIIDOC
|
||||
swagger2markup.examples=false
|
||||
swagger2markup.schemas=false
|
||||
swagger2markup.operationDescriptions=false
|
||||
swagger2markup.definitionDescriptions=false
|
||||
swagger2markup.operationExtensions=false
|
||||
swagger2markup.definitionExtensions=false
|
||||
swagger2markup.separatedDefinitions=false
|
||||
swagger2markup.separatedOperations=false
|
||||
swagger2markup.operationsGroupedBy=AS_IS
|
||||
swagger2markup.definitionsOrderedBy=NATURAL
|
||||
swagger2markup.outputLanguage=EN
|
||||
swagger2markup.inlineSchemaDepthLevel=0
|
||||
swagger2markup.interDocumentCrossReferences=false
|
||||
swagger2markup.flatBody=false
|
||||
swagger2markup.overviewDocument=overview
|
||||
swagger2markup.pathsDocument=paths
|
||||
swagger2markup.definitionsDocument=definitions
|
||||
swagger2markup.securityDocument=security
|
||||
swagger2markup.separatedOperationsFolder=operations
|
||||
swagger2markup.separatedDefinitionsFolder=definitions
|
||||
@@ -18,9 +18,13 @@
|
||||
*/
|
||||
package io.github.robwin.swagger2markup;
|
||||
|
||||
import com.google.common.collect.*;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import io.github.robwin.markup.builder.MarkupLanguage;
|
||||
import io.github.robwin.swagger2markup.config.Swagger2MarkupConfig;
|
||||
import io.swagger.models.Swagger;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.junit.Test;
|
||||
@@ -181,7 +185,7 @@ public class Swagger2MarkupConverterTest {
|
||||
|
||||
//When
|
||||
Swagger2MarkupConfig config = Swagger2MarkupConfig.ofDefaults()
|
||||
.withDescriptions("src/docs/asciidoc")
|
||||
.withDefinitionDescriptions("src/docs/asciidoc/definitions")
|
||||
.build();
|
||||
|
||||
Swagger2MarkupConverter.from(file.getAbsolutePath())
|
||||
@@ -265,7 +269,7 @@ public class Swagger2MarkupConverterTest {
|
||||
|
||||
//When
|
||||
Swagger2MarkupConfig config = Swagger2MarkupConfig.ofDefaults()
|
||||
.withDescriptions("src/docs/markdown")
|
||||
.withDefinitionDescriptions("src/docs/markdown/definitions")
|
||||
.withMarkupLanguage(MarkupLanguage.MARKDOWN)
|
||||
.build();
|
||||
Swagger2MarkupConverter.from(file.getAbsolutePath())
|
||||
@@ -460,6 +464,82 @@ public class Swagger2MarkupConverterTest {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSwagger2MarkupConfigDefaultPaths() {
|
||||
//Given
|
||||
File file = new File(Swagger2MarkupConverterTest.class.getResource("/json/swagger.json").getFile());
|
||||
|
||||
//When
|
||||
Swagger2MarkupConfig config = Swagger2MarkupConfig.ofDefaults()
|
||||
.withDefinitionDescriptions()
|
||||
.withDefinitionExtensions()
|
||||
.withExamples()
|
||||
.withOperationDescriptions()
|
||||
.withOperationExtensions()
|
||||
.withSchemas()
|
||||
.build();
|
||||
|
||||
Swagger2MarkupConverter converterBuilder = Swagger2MarkupConverter.from(file.getPath())
|
||||
.withConfig(config)
|
||||
.build();
|
||||
|
||||
//Then
|
||||
assertThat(converterBuilder.config.getDefinitionDescriptionsPath()).isEqualTo(new File(file.getParent(), "definitions").getPath());
|
||||
assertThat(converterBuilder.config.getDefinitionExtensionsPath()).isEqualTo(new File(file.getParent(), "definitions").getPath());
|
||||
assertThat(converterBuilder.config.getExamplesPath()).isEqualTo(new File(file.getParent(), "operations").getPath());
|
||||
assertThat(converterBuilder.config.getOperationDescriptionsPath()).isEqualTo(new File(file.getParent(), "operations").getPath());
|
||||
assertThat(converterBuilder.config.getOperationExtensionsPath()).isEqualTo(new File(file.getParent(), "operations").getPath());
|
||||
assertThat(converterBuilder.config.getSchemasPath()).isEqualTo(new File(file.getParent(), "definitions").getPath());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSwagger2MarkupConfigDefaultPathsWithUrl() {
|
||||
//Given
|
||||
|
||||
//When
|
||||
Swagger2MarkupConfig config = Swagger2MarkupConfig.ofDefaults()
|
||||
.withDefinitionDescriptions()
|
||||
.withDefinitionExtensions()
|
||||
.withExamples()
|
||||
.withOperationDescriptions()
|
||||
.withOperationExtensions()
|
||||
.withSchemas()
|
||||
.build();
|
||||
|
||||
Swagger2MarkupConverter converterBuilder = Swagger2MarkupConverter.from("http://petstore.swagger.io/v2/swagger.json")
|
||||
.withConfig(config)
|
||||
.build();
|
||||
|
||||
//Then
|
||||
assertThat(converterBuilder.config.getDefinitionDescriptionsPath()).isEqualTo("http:/petstore.swagger.io/v2/definitions");
|
||||
assertThat(converterBuilder.config.getDefinitionExtensionsPath()).isEqualTo("http:/petstore.swagger.io/v2/definitions");
|
||||
assertThat(converterBuilder.config.getExamplesPath()).isEqualTo("http:/petstore.swagger.io/v2/operations");
|
||||
assertThat(converterBuilder.config.getOperationDescriptionsPath()).isEqualTo("http:/petstore.swagger.io/v2/operations");
|
||||
assertThat(converterBuilder.config.getOperationExtensionsPath()).isEqualTo("http:/petstore.swagger.io/v2/operations");
|
||||
assertThat(converterBuilder.config.getSchemasPath()).isEqualTo("http:/petstore.swagger.io/v2/definitions");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSwagger2MarkupConfigDefaultPathsWithoutFile() {
|
||||
//Given
|
||||
|
||||
//When
|
||||
Swagger2MarkupConfig config = Swagger2MarkupConfig.ofDefaults()
|
||||
.withDefinitionDescriptions()
|
||||
.build();
|
||||
|
||||
//Then
|
||||
try {
|
||||
Swagger2MarkupConverter.from(new Swagger())
|
||||
.withConfig(config)
|
||||
.build();
|
||||
fail("No RuntimeException thrown");
|
||||
} catch (RuntimeException e) {
|
||||
assertThat(e.getMessage()).isEqualTo("'definitionDescriptions' configuration entry is not set and has no default");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a markdown document to search, this checks to see if the specified tables
|
||||
* have all of the expected fields listed.
|
||||
|
||||
@@ -18,28 +18,16 @@
|
||||
*/
|
||||
package io.github.robwin.swagger2markup.config;
|
||||
|
||||
import com.google.common.collect.*;
|
||||
import com.google.common.collect.Ordering;
|
||||
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.github.robwin.swagger2markup.Swagger2MarkupConverter;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.Files;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
import static org.assertj.core.api.Assertions.failBecauseExceptionWasNotThrown;
|
||||
import static org.assertj.core.api.BDDAssertions.assertThat;
|
||||
|
||||
public class Swagger2MarkupConfigTest {
|
||||
@@ -49,28 +37,35 @@ public class Swagger2MarkupConfigTest {
|
||||
Swagger2MarkupConfig config = Swagger2MarkupConfig.ofDefaults().build();
|
||||
|
||||
assertThat(config.getAnchorPrefix()).isNull();
|
||||
assertThat(config.getDefinitionExtensionsFolderPath()).isNull();
|
||||
assertThat(config.isDefinitionExtensions()).isFalse();
|
||||
assertThat(config.getDefinitionExtensionsPath()).isNull();
|
||||
assertThat(config.getDefinitionOrdering()).isEqualTo(Ordering.natural());
|
||||
assertThat(config.getDefinitionsDocument()).isEqualTo(Swagger2MarkupConfig.Builder.DEFINITIONS_DOCUMENT);
|
||||
assertThat(config.getDefinitionsDocument()).isEqualTo("definitions");
|
||||
assertThat(config.getDefinitionsOrderedBy()).isEqualTo(OrderBy.NATURAL);
|
||||
assertThat(config.getDescriptionsFolderPath()).isNull();
|
||||
assertThat(config.getExamplesFolderPath()).isNull();
|
||||
assertThat(config.isOperationDescriptions()).isFalse();
|
||||
assertThat(config.getOperationDescriptionsPath()).isNull();
|
||||
assertThat(config.isDefinitionDescriptions()).isFalse();
|
||||
assertThat(config.getDefinitionDescriptionsPath()).isNull();
|
||||
assertThat(config.isExamples()).isFalse();
|
||||
assertThat(config.getExamplesPath()).isNull();
|
||||
assertThat(config.getInlineSchemaDepthLevel()).isEqualTo(0);
|
||||
assertThat(config.getInterDocumentCrossReferencesPrefix()).isEqualTo("");
|
||||
assertThat(config.getInterDocumentCrossReferencesPrefix()).isNull();
|
||||
assertThat(config.getMarkupLanguage()).isEqualTo(MarkupLanguage.ASCIIDOC);
|
||||
assertThat(config.getOperationExtensionsFolderPath()).isNull();
|
||||
assertThat(config.isOperationExtensions()).isFalse();
|
||||
assertThat(config.getOperationExtensionsPath()).isNull();
|
||||
assertThat(config.getOperationOrdering()).isEqualTo(Swagger2MarkupConfig.Builder.OPERATION_PATH_COMPARATOR.compound(Swagger2MarkupConfig.Builder.OPERATION_METHOD_COMPARATOR));
|
||||
assertThat(config.getOutputLanguage()).isEqualTo(Language.EN);
|
||||
assertThat(config.getOverviewDocument()).isEqualTo(Swagger2MarkupConfig.Builder.OVERVIEW_DOCUMENT);
|
||||
assertThat(config.getOverviewDocument()).isEqualTo("overview");
|
||||
assertThat(config.getParameterOrdering()).isEqualTo(Swagger2MarkupConfig.Builder.PARAMETER_IN_COMPARATOR.compound(Swagger2MarkupConfig.Builder.PARAMETER_NAME_COMPARATOR));
|
||||
assertThat(config.getPathsDocument()).isEqualTo(Swagger2MarkupConfig.Builder.PATHS_DOCUMENT);
|
||||
assertThat(config.getPathsGroupedBy()).isEqualTo(GroupBy.AS_IS);
|
||||
assertThat(config.getPathsDocument()).isEqualTo("paths");
|
||||
assertThat(config.getOperationsGroupedBy()).isEqualTo(GroupBy.AS_IS);
|
||||
assertThat(config.getPropertyOrdering()).isEqualTo(Ordering.natural());
|
||||
assertThat(config.getResponseOrdering()).isEqualTo(Ordering.natural());
|
||||
assertThat(config.getSchemasFolderPath()).isNull();
|
||||
assertThat(config.getSecurityDocument()).isEqualTo(Swagger2MarkupConfig.Builder.SECURITY_DOCUMENT);
|
||||
assertThat(config.getSeparatedDefinitionsFolder()).isEqualTo(Swagger2MarkupConfig.Builder.SEPARATED_DEFINITIONS_FOLDER);
|
||||
assertThat(config.getSeparatedOperationsFolder()).isEqualTo(Swagger2MarkupConfig.Builder.SEPARATED_OPERATIONS_FOLDER);
|
||||
assertThat(config.isSchemas()).isFalse();
|
||||
assertThat(config.getSchemasPath()).isNull();
|
||||
assertThat(config.getSecurityDocument()).isEqualTo("security");
|
||||
assertThat(config.getSeparatedDefinitionsFolder()).isEqualTo("definitions");
|
||||
assertThat(config.getSeparatedOperationsFolder()).isEqualTo("operations");
|
||||
assertThat(config.getTagOrdering()).isEqualTo(Ordering.natural());
|
||||
assertThat(config.isFlatBody()).isFalse();
|
||||
assertThat(config.isInterDocumentCrossReferences()).isFalse();
|
||||
@@ -80,7 +75,7 @@ public class Swagger2MarkupConfigTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void testSwagger2MarkupConfig() throws IOException {
|
||||
public void testSwagger2MarkupConfigOfProperties() throws IOException {
|
||||
|
||||
Properties properties = new Properties();
|
||||
properties.load(Swagger2MarkupConfigTest.class.getResourceAsStream("/config/config.properties"));
|
||||
@@ -88,25 +83,32 @@ public class Swagger2MarkupConfigTest {
|
||||
Swagger2MarkupConfig config = Swagger2MarkupConfig.ofProperties(properties).build();
|
||||
|
||||
assertThat(config.getAnchorPrefix()).isEqualTo("anchorPrefix");
|
||||
assertThat(config.getDefinitionExtensionsFolderPath()).isEqualTo("definitionExtensions");
|
||||
assertThat(config.isDefinitionExtensions()).isTrue();
|
||||
assertThat(config.getDefinitionExtensionsPath()).isEqualTo("definitionExtensions");
|
||||
//assertThat(config.getDefinitionOrdering()).isEqualTo(Ordering.natural()); // Not supported
|
||||
//assertThat(config.getDefinitionsDocument()).isEqualTo(Swagger2MarkupConfig.Builder.DEFINITIONS_DOCUMENT); // Not supported
|
||||
assertThat(config.getDefinitionsOrderedBy()).isEqualTo(OrderBy.AS_IS);
|
||||
assertThat(config.getDescriptionsFolderPath()).isEqualTo("descriptions");
|
||||
assertThat(config.getExamplesFolderPath()).isEqualTo("examples");
|
||||
assertThat(config.isOperationDescriptions()).isTrue();
|
||||
assertThat(config.getOperationDescriptionsPath()).isEqualTo("operationDescriptions");
|
||||
assertThat(config.isDefinitionDescriptions()).isTrue();
|
||||
assertThat(config.getDefinitionDescriptionsPath()).isEqualTo("definitionDescriptions");
|
||||
assertThat(config.isExamples()).isTrue();
|
||||
assertThat(config.getExamplesPath()).isEqualTo("examples");
|
||||
assertThat(config.getInlineSchemaDepthLevel()).isEqualTo(2);
|
||||
assertThat(config.getInterDocumentCrossReferencesPrefix()).isEqualTo("xrefPrefix");
|
||||
assertThat(config.getMarkupLanguage()).isEqualTo(MarkupLanguage.MARKDOWN);
|
||||
assertThat(config.getOperationExtensionsFolderPath()).isEqualTo("operationExtensions");
|
||||
assertThat(config.isOperationExtensions()).isTrue();
|
||||
assertThat(config.getOperationExtensionsPath()).isEqualTo("operationExtensions");
|
||||
//assertThat(config.getOperationOrdering()).isEqualTo(Swagger2MarkupConfig.Builder.OPERATION_PATH_COMPARATOR.compound(Swagger2MarkupConfig.Builder.OPERATION_METHOD_COMPARATOR)); // Not supported
|
||||
assertThat(config.getOutputLanguage()).isEqualTo(Language.RU);
|
||||
//assertThat(config.getOverviewDocument()).isEqualTo(Swagger2MarkupConfig.Builder.OVERVIEW_DOCUMENT); // Not supported
|
||||
//assertThat(config.getParameterOrdering()).isEqualTo(Swagger2MarkupConfig.Builder.PARAMETER_IN_COMPARATOR.compound(Swagger2MarkupConfig.Builder.PARAMETER_NAME_COMPARATOR)); // Not supported
|
||||
//assertThat(config.getPathsDocument()).isEqualTo(Swagger2MarkupConfig.Builder.PATHS_DOCUMENT); // Not supported
|
||||
assertThat(config.getPathsGroupedBy()).isEqualTo(GroupBy.TAGS);
|
||||
assertThat(config.getOperationsGroupedBy()).isEqualTo(GroupBy.TAGS);
|
||||
//assertThat(config.getPropertyOrdering()).isEqualTo(Ordering.natural()); // Not supported
|
||||
//assertThat(config.getResponseOrdering()).isEqualTo(Ordering.natural()); // Not supported
|
||||
assertThat(config.getSchemasFolderPath()).isEqualTo("schemas");
|
||||
assertThat(config.isSchemas()).isTrue();
|
||||
assertThat(config.getSchemasPath()).isEqualTo("schemas");
|
||||
//assertThat(config.getSecurityDocument()).isEqualTo(Swagger2MarkupConfig.Builder.SECURITY_DOCUMENT); // Not supported
|
||||
//assertThat(config.getSeparatedDefinitionsFolder()).isEqualTo(Swagger2MarkupConfig.Builder.SEPARATED_DEFINITIONS_FOLDER); // Not supported
|
||||
//assertThat(config.getSeparatedOperationsFolder()).isEqualTo(Swagger2MarkupConfig.Builder.SEPARATED_OPERATIONS_FOLDER); // Not supported
|
||||
|
||||
@@ -1,12 +1,19 @@
|
||||
swagger2markup.markupLanguage=MARKDOWN
|
||||
swagger2markup.examplesFolderPath=examples
|
||||
swagger2markup.schemasFolderPath=schemas
|
||||
swagger2markup.descriptionsFolderPath=descriptions
|
||||
swagger2markup.operationExtensionsFolderPath=operationExtensions
|
||||
swagger2markup.definitionExtensionsFolderPath=definitionExtensions
|
||||
swagger2markup.examples=true
|
||||
swagger2markup.examplesPath=examples
|
||||
swagger2markup.schemasPath=schemas
|
||||
swagger2markup.schemas=true
|
||||
swagger2markup.operationDescriptions=true
|
||||
swagger2markup.operationDescriptionsPath=operationDescriptions
|
||||
swagger2markup.definitionDescriptions=true
|
||||
swagger2markup.definitionDescriptionsPath=definitionDescriptions
|
||||
swagger2markup.operationExtensions=true
|
||||
swagger2markup.operationExtensionsPath=operationExtensions
|
||||
swagger2markup.definitionExtensions=true
|
||||
swagger2markup.definitionExtensionsPath=definitionExtensions
|
||||
swagger2markup.separatedDefinitions=true
|
||||
swagger2markup.separatedOperations=true
|
||||
swagger2markup.pathsGroupedBy=TAGS
|
||||
swagger2markup.operationsGroupedBy=TAGS
|
||||
swagger2markup.definitionsOrderedBy=AS_IS
|
||||
swagger2markup.outputLanguage=RU
|
||||
swagger2markup.inlineSchemaDepthLevel=2
|
||||
|
||||
Reference in New Issue
Block a user