Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6396b8fdb7 | ||
|
|
e27ba4304d |
@@ -1,6 +1,6 @@
|
||||
= Swagger2Markup
|
||||
:author: Robert Winkler
|
||||
:version: 0.2.3
|
||||
:version: 0.3.0
|
||||
:hardbreaks:
|
||||
|
||||
image:https://travis-ci.org/RobWin/swagger2markup.svg["Build Status", link="https://travis-ci.org/RobWin/swagger2markup"] image:https://coveralls.io/repos/RobWin/swagger2markup/badge.svg["Coverage Status", link="https://coveralls.io/r/RobWin/swagger2markup"] image:https://api.bintray.com/packages/robwin/maven/swagger2markup/images/download.svg[link="https://bintray.com/robwin/maven/swagger2markup/_latestVersion"] image:http://img.shields.io/badge/license-ASF2-blue.svg["Apache License 2", link="http://www.apache.org/licenses/LICENSE-2.0.txt"]
|
||||
@@ -38,7 +38,7 @@ The project is published in JCenter and Maven Central.
|
||||
<dependency>
|
||||
<groupId>io.github.robwin</groupId>
|
||||
<artifactId>swagger2markup</artifactId>
|
||||
<version>0.2.3</version>
|
||||
<version>0.3.0</version>
|
||||
</dependency>
|
||||
----
|
||||
|
||||
@@ -50,7 +50,7 @@ repositories {
|
||||
jcenter()
|
||||
}
|
||||
|
||||
compile "io.github.robwin:swagger2markup:0.2.3"
|
||||
compile "io.github.robwin:swagger2markup:0.3.0"
|
||||
----
|
||||
|
||||
=== Using Swagger2Markup
|
||||
|
||||
@@ -17,4 +17,7 @@
|
||||
|
||||
=== Version 0.2.4
|
||||
* Fixed issue #8: logback.xml on the classpath
|
||||
* Fixed issue #13: unknown format not supported for properties
|
||||
* Fixed issue #13: unknown format not supported for properties
|
||||
|
||||
== Version 0.3.0
|
||||
* Support of YAML or JSON String as input.
|
||||
@@ -13,7 +13,7 @@ buildscript {
|
||||
}
|
||||
}
|
||||
description = 'swagger2markup Build'
|
||||
version = '0.2.4'
|
||||
version = '0.3.0'
|
||||
group = 'io.github.robwin'
|
||||
|
||||
apply plugin: 'java'
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
package io.github.robwin.swagger2markup;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.wordnik.swagger.models.Swagger;
|
||||
import com.wordnik.swagger.util.Json;
|
||||
import com.wordnik.swagger.util.Yaml;
|
||||
import io.github.robwin.markup.builder.MarkupLanguage;
|
||||
import io.github.robwin.swagger2markup.builder.document.DefinitionsDocument;
|
||||
import io.github.robwin.swagger2markup.builder.document.PathsDocument;
|
||||
@@ -41,12 +45,12 @@ public class Swagger2MarkupConverter {
|
||||
/**
|
||||
* Creates a Swagger2MarkupConverter.Builder using a given Swagger source.
|
||||
*
|
||||
* @param swaggerSource the Swagger source. Can be a HTTP url or a path to a local file.
|
||||
* @param swaggerLocation the Swagger location. Can be a HTTP url or a path to a local file.
|
||||
* @return a Swagger2MarkupConverter
|
||||
*/
|
||||
public static Builder from(String swaggerSource){
|
||||
Validate.notEmpty(swaggerSource, "swaggerSource must not be empty!");
|
||||
return new Builder(swaggerSource);
|
||||
public static Builder from(String swaggerLocation){
|
||||
Validate.notEmpty(swaggerLocation, "swaggerLocation must not be empty!");
|
||||
return new Builder(swaggerLocation);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -60,6 +64,30 @@ public class Swagger2MarkupConverter {
|
||||
return new Builder(swagger);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Swagger2MarkupConverter.Builder from a given Swagger YAML or JSON String.
|
||||
*
|
||||
* @param swagger the Swagger YAML or JSON String.
|
||||
* @return a Swagger2MarkupConverter
|
||||
*/
|
||||
public static Builder fromString(String swagger) throws IOException {
|
||||
Validate.notEmpty(swagger, "swagger must not be null!");
|
||||
ObjectMapper mapper;
|
||||
if(swagger.trim().startsWith("{")) {
|
||||
mapper = Json.mapper();
|
||||
}else {
|
||||
mapper = Yaml.mapper();
|
||||
}
|
||||
JsonNode rootNode = mapper.readTree(swagger);
|
||||
|
||||
// must have swagger node set
|
||||
JsonNode swaggerNode = rootNode.get("swagger");
|
||||
if(swaggerNode == null)
|
||||
throw new IllegalArgumentException("Swagger String is in the wrong format");
|
||||
|
||||
return new Builder(mapper.convertValue(rootNode, Swagger.class));
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the document with the given markup language and stores
|
||||
* the files in the given folder.
|
||||
@@ -112,10 +140,10 @@ public class Swagger2MarkupConverter {
|
||||
/**
|
||||
* Creates a Builder using a given Swagger source.
|
||||
*
|
||||
* @param swaggerSource the Swagger source. Can be a HTTP url or a path to a local file.
|
||||
* @param swaggerLocation the Swagger location. Can be a HTTP url or a path to a local file.
|
||||
*/
|
||||
Builder(String swaggerSource){
|
||||
swagger = new SwaggerParser().read(swaggerSource);
|
||||
Builder(String swaggerLocation){
|
||||
swagger = new SwaggerParser().read(swaggerLocation);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -127,8 +155,6 @@ public class Swagger2MarkupConverter {
|
||||
this.swagger = swagger;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Swagger2MarkupConverter build(){
|
||||
return new Swagger2MarkupConverter(markupLanguage, swagger, examplesFolderPath, schemasFolderPath);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user