Compare commits
21 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6396b8fdb7 | ||
|
|
e27ba4304d | ||
|
|
4c86e73c4e | ||
|
|
9f9fa8c444 | ||
|
|
9647116572 | ||
|
|
736891fbdd | ||
|
|
acec733af7 | ||
|
|
73cdc35c80 | ||
|
|
cae91b3565 | ||
|
|
ec610f4fbb | ||
|
|
edf9ba01bd | ||
|
|
e942252d9a | ||
|
|
04d1773c03 | ||
|
|
448899c193 | ||
|
|
23d1db4fd5 | ||
|
|
903d3ed452 | ||
|
|
1ad78ba9f6 | ||
|
|
82416a33cc | ||
|
|
e67b32d537 | ||
|
|
dbb6f9ace8 | ||
|
|
d2c69abb71 |
29
README.adoc
@@ -1,16 +1,17 @@
|
||||
= Swagger2Markup
|
||||
:author: Robert Winkler
|
||||
:version: 0.2.1
|
||||
: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"]
|
||||
image:https://badges.gitter.im/Join%20Chat.svg[link="https://gitter.im/RobWin/swagger2markup?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge"]
|
||||
|
||||
== Overview
|
||||
|
||||
This project is a Swagger to Markup (AsciiDoc and Markdown) converter. The *Swagger2MarkupConverter* takes a swagger.json or swagger.yaml file as source and converts it into an AsciiDoc or Markdown document. The Swagger source file can be located locally or remotely accessible via HTTP. The Swagger2MarkupConverter 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].
|
||||
|
||||
The primary goal of this project is to simplify the documentation of RESTful APIs. The result is intended to be an easy-to-read, on- and offline user guide, comparable to https://developer.github.com/v3/[GitHub's API documentation].
|
||||
Swagger2Markup can be used together with https://github.com/spring-projects/spring-restdocs[spring-restdocs]. See <<integration-with-spring-restdocs, Integration with spring-restdocs>>.
|
||||
Swagger2Markup can be used together with https://github.com/springfox/springfox[springfox] and https://github.com/spring-projects/spring-restdocs[spring-restdocs]. See <<integration-with-spring-restdocs, Integration with spring-restdocs>>.
|
||||
|
||||
The project requires at least JDK 7.
|
||||
|
||||
@@ -37,7 +38,7 @@ The project is published in JCenter and Maven Central.
|
||||
<dependency>
|
||||
<groupId>io.github.robwin</groupId>
|
||||
<artifactId>swagger2markup</artifactId>
|
||||
<version>0.2.1</version>
|
||||
<version>0.3.0</version>
|
||||
</dependency>
|
||||
----
|
||||
|
||||
@@ -49,12 +50,12 @@ repositories {
|
||||
jcenter()
|
||||
}
|
||||
|
||||
compile "io.github.robwin:swagger2markup:0.2.1"
|
||||
compile "io.github.robwin:swagger2markup:0.3.0"
|
||||
----
|
||||
|
||||
=== Using Swagger2Markup
|
||||
|
||||
Using the Swagger2MarkupConverter is simple. For instance, you can generate your AsciiDoc/Markdown documentation using https://github.com/spring-projects/spring-boot[Spring Boot] and https://github.com/martypitt/swagger-springmvc[swagger-springmvc] as follows.
|
||||
Using the Swagger2MarkupConverter is simple. For instance, you can generate your AsciiDoc/Markdown documentation using https://github.com/spring-projects/spring-boot[Spring Boot] and https://github.com/springfox/springfox[springfox] as follows.
|
||||
See demo project https://github.com/RobWin/spring-swagger2markup-demo[spring-swagger2markup-demo].
|
||||
|
||||
[source,java]
|
||||
@@ -84,6 +85,22 @@ public class Swagger2MarkupTest {
|
||||
Swagger2MarkupConverter.from(file.getAbsolutePath()).build()
|
||||
.intoFolder("src/docs/asciidoc");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSwagger2HtmlConversion() throws IOException {
|
||||
File file = new File(Swagger2MarkupConverterTest.class.getResource("/json/swagger.json").getFile());
|
||||
String asciiDoc = Swagger2MarkupConverter.from(file.getAbsolutePath()).build().asString();
|
||||
String path = "src/docs/asciidocAsString";
|
||||
Files.createDirectories(Paths.get(path));
|
||||
try (BufferedWriter writer = Files.newBufferedWriter(Paths.get(path, "swagger.adoc"), StandardCharsets.UTF_8)){
|
||||
writer.write(asciiDoc); }
|
||||
String asciiDocAsHtml = Asciidoctor.Factory.create().convert(asciiDoc,
|
||||
OptionsBuilder.options().backend("html5").headerFooter(true).safe(SafeMode.UNSAFE).docType("book").attributes(AttributesBuilder.attributes()
|
||||
.tableOfContents(true).tableOfContents(Placement.LEFT).sectionNumbers(true).hardbreaks(true).setAnchors(true).attribute("sectlinks")));
|
||||
try (BufferedWriter writer = Files.newBufferedWriter(Paths.get(path, "swagger.html"), StandardCharsets.UTF_8)){
|
||||
writer.write(asciiDocAsHtml);
|
||||
}
|
||||
}
|
||||
}
|
||||
----
|
||||
|
||||
@@ -210,4 +227,4 @@ I create the Schemas files in Unit-Tests as follows:
|
||||
I will make RestDocumented public soon. RestDocumented creates a MailStorageQuota.xsd and MailStorageQuota.json file in the folder "docs/schemas".
|
||||
The Swagger2MarkupConverter will include the JSON and XML Schemas, if a Swagger Operation uses the MailStorageQuota class as Input or Output.
|
||||
|
||||
See example: http://spring-swagger2markup-demo.readthedocs.org/en/latest/generated/definitions/[ReadTheDocs-demo]
|
||||
See example: http://spring-swagger2markup-demo.readthedocs.org/en/latest/generated/definitions/[ReadTheDocs-demo]
|
||||
|
||||
@@ -7,4 +7,17 @@
|
||||
* This version is not downward compatible. This version supports includes of example files and JSON/XML Schema files. See documentation.
|
||||
|
||||
=== Version 0.2.1
|
||||
* Signed jar files and published in Maven Central
|
||||
* Signed jar files and published in Maven Central
|
||||
|
||||
=== Version 0.2.2
|
||||
* Fixed wrong dependency version to io.github.robwin:markup-document-builder
|
||||
|
||||
=== Version 0.2.3
|
||||
* Fixed issue #7: @ApiModelProperty metadata are ignored for definitions file
|
||||
|
||||
=== Version 0.2.4
|
||||
* Fixed issue #8: logback.xml on the classpath
|
||||
* Fixed issue #13: unknown format not supported for properties
|
||||
|
||||
== Version 0.3.0
|
||||
* Support of YAML or JSON String as input.
|
||||
16
build.gradle
@@ -13,7 +13,7 @@ buildscript {
|
||||
}
|
||||
}
|
||||
description = 'swagger2markup Build'
|
||||
version = '0.2.1'
|
||||
version = '0.3.0'
|
||||
group = 'io.github.robwin'
|
||||
|
||||
apply plugin: 'java'
|
||||
@@ -36,6 +36,7 @@ tasks.withType(JavaCompile) {
|
||||
repositories {
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
mavenLocal()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
@@ -45,11 +46,13 @@ dependencies {
|
||||
compile 'commons-io:commons-io'
|
||||
compile 'ch.qos.logback:logback-classic'
|
||||
testCompile 'junit:junit'
|
||||
testCompile 'org.asciidoctor:asciidoctorj:1.5.2'
|
||||
testCompile 'org.asciidoctor:asciidoctorj-pdf:1.5.0-alpha.6'
|
||||
}
|
||||
|
||||
dependencyManagement {
|
||||
dependencies {
|
||||
"io.github.robwin:markup-document-builder" "0.1.0"
|
||||
"io.github.robwin:markup-document-builder" "0.1.2"
|
||||
"io.swagger:swagger-compat-spec-parser" "1.0.0"
|
||||
"commons-collections:commons-collections" "3.2.1"
|
||||
"commons-io:commons-io" "2.4"
|
||||
@@ -76,12 +79,17 @@ artifacts {
|
||||
}
|
||||
|
||||
asciidoctor {
|
||||
sources {
|
||||
include 'index.adoc'
|
||||
}
|
||||
backends = ['html5', 'pdf']
|
||||
attributes = [
|
||||
doctype: 'book',
|
||||
toc: 'left',
|
||||
toclevels: '2',
|
||||
numbered: ''
|
||||
numbered: '',
|
||||
sectlinks: '',
|
||||
sectanchors: ''
|
||||
]
|
||||
}
|
||||
|
||||
@@ -102,4 +110,4 @@ tasks.asciidoctor {
|
||||
|
||||
task wrapper(type: Wrapper) {
|
||||
gradleVersion = '2.2.1'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,6 +65,15 @@ publishing {
|
||||
pom.withXml {
|
||||
def devs = ['RobWin': 'Robert Winkler']
|
||||
def root = asNode()
|
||||
|
||||
root.dependencies.'*'.findAll() {
|
||||
it.scope.text() == 'runtime' && project.configurations.compile.allDependencies.find { dep ->
|
||||
dep.name == it.artifactId.text()
|
||||
}
|
||||
}.each() {
|
||||
it.scope*.value = 'compile'
|
||||
}
|
||||
|
||||
root.appendNode('name', 'swagger2markup')
|
||||
root.appendNode('packaging', 'jar')
|
||||
root.appendNode('url', 'https://github.com/RobWin/swagger2markup')
|
||||
|
||||
|
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 44 KiB |
BIN
images/asciidoc2_html.PNG
Normal file
|
After Width: | Height: | Size: 104 KiB |
|
Before Width: | Height: | Size: 105 KiB After Width: | Height: | Size: 95 KiB |
|
Before Width: | Height: | Size: 153 KiB After Width: | Height: | Size: 124 KiB |
|
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 29 KiB |
55
src/docs/asciidoc/definitions.adoc
Normal file
@@ -0,0 +1,55 @@
|
||||
== Definitions
|
||||
=== User
|
||||
[options="header"]
|
||||
|===
|
||||
|Name|Description|Schema|Required
|
||||
|id||integer (int64)|false
|
||||
|username||string|false
|
||||
|firstName||string|false
|
||||
|lastName||string|false
|
||||
|email||string|false
|
||||
|password||string|false
|
||||
|phone||string|false
|
||||
|userStatus|User Status|integer (int32)|false
|
||||
|===
|
||||
|
||||
=== Category
|
||||
[options="header"]
|
||||
|===
|
||||
|Name|Description|Schema|Required
|
||||
|id||integer (int64)|false
|
||||
|name||string|false
|
||||
|===
|
||||
|
||||
=== Pet
|
||||
[options="header"]
|
||||
|===
|
||||
|Name|Description|Schema|Required
|
||||
|id||integer (int64)|false
|
||||
|category||<<Category>>|false
|
||||
|name||string|true
|
||||
|photoUrls||string array|true
|
||||
|tags||<<Tag>> array|false
|
||||
|status|pet status in the store|string|false
|
||||
|===
|
||||
|
||||
=== Tag
|
||||
[options="header"]
|
||||
|===
|
||||
|Name|Description|Schema|Required
|
||||
|id||integer (int64)|false
|
||||
|name||string|false
|
||||
|===
|
||||
|
||||
=== Order
|
||||
[options="header"]
|
||||
|===
|
||||
|Name|Description|Schema|Required
|
||||
|id||integer (int64)|false
|
||||
|petId||integer (int64)|false
|
||||
|quantity||integer (int32)|false
|
||||
|shipDate||string (date-time)|false
|
||||
|status|Order Status|string|false
|
||||
|complete||boolean|false
|
||||
|===
|
||||
|
||||
9
src/docs/asciidoc/index.adoc
Normal file
@@ -0,0 +1,9 @@
|
||||
:doctype: book
|
||||
:toc: left
|
||||
:toclevels: 2
|
||||
:numbered:
|
||||
:sectlinks:
|
||||
:sectanchors:
|
||||
|
||||
include::paths.adoc[]
|
||||
include::definitions.adoc[]
|
||||
582
src/docs/asciidoc/paths.adoc
Normal file
@@ -0,0 +1,582 @@
|
||||
= Swagger Petstore
|
||||
|
||||
This is a sample server Petstore server.
|
||||
|
||||
[Learn about Swagger](http://swagger.wordnik.com) or join the IRC channel `#swagger` on irc.freenode.net.
|
||||
|
||||
For this sample, you can use the api key `special-key` to test the authorization filters
|
||||
|
||||
Version: 1.0.0
|
||||
Contact: apiteam@wordnik.com
|
||||
License: Apache 2.0
|
||||
License URL: http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
Terms of service: http://helloreverb.com/terms/
|
||||
|
||||
Host: petstore.swagger.wordnik.com
|
||||
BasePath: /v2
|
||||
Schemes: HTTP
|
||||
|
||||
== Paths
|
||||
=== Update an existing pet
|
||||
----
|
||||
PUT /pets
|
||||
----
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|BodyParameter|body|Pet object that needs to be added to the store|false|<<Pet>>
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|400|Invalid ID supplied|No Content
|
||||
|404|Pet not found|No Content
|
||||
|405|Validation exception|No Content
|
||||
|===
|
||||
|
||||
==== Consumes
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* pet
|
||||
|
||||
=== Add a new pet to the store
|
||||
----
|
||||
POST /pets
|
||||
----
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|BodyParameter|body|Pet object that needs to be added to the store|false|<<Pet>>
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|405|Invalid input|No Content
|
||||
|===
|
||||
|
||||
==== Consumes
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* pet
|
||||
|
||||
=== Finds Pets by status
|
||||
----
|
||||
GET /pets/findByStatus
|
||||
----
|
||||
|
||||
==== Description
|
||||
:hardbreaks:
|
||||
Multiple status values can be provided with comma seperated strings
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|QueryParameter|status|Status values that need to be considered for filter|false|multi string array
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|200|successful operation|<<Pet>> array
|
||||
|400|Invalid status value|No Content
|
||||
|===
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* pet
|
||||
|
||||
=== Finds Pets by tags
|
||||
----
|
||||
GET /pets/findByTags
|
||||
----
|
||||
|
||||
==== Description
|
||||
:hardbreaks:
|
||||
Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|QueryParameter|tags|Tags to filter by|false|multi string array
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|200|successful operation|<<Pet>> array
|
||||
|400|Invalid tag value|No Content
|
||||
|===
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* pet
|
||||
|
||||
=== Find pet by ID
|
||||
----
|
||||
GET /pets/{petId}
|
||||
----
|
||||
|
||||
==== Description
|
||||
:hardbreaks:
|
||||
Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|PathParameter|petId|ID of pet that needs to be fetched|true|integer (int64)
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|200|successful operation|<<Pet>>
|
||||
|400|Invalid ID supplied|No Content
|
||||
|404|Pet not found|No Content
|
||||
|===
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* pet
|
||||
|
||||
=== Deletes a pet
|
||||
----
|
||||
DELETE /pets/{petId}
|
||||
----
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|HeaderParameter|api_key||true|string
|
||||
|PathParameter|petId|Pet id to delete|true|integer (int64)
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|400|Invalid pet value|No Content
|
||||
|===
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* pet
|
||||
|
||||
=== Updates a pet in the store with form data
|
||||
----
|
||||
POST /pets/{petId}
|
||||
----
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|PathParameter|petId|ID of pet that needs to be updated|true|string
|
||||
|FormDataParameter|name|Updated name of the pet|true|string
|
||||
|FormDataParameter|status|Updated status of the pet|true|string
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|405|Invalid input|No Content
|
||||
|===
|
||||
|
||||
==== Consumes
|
||||
|
||||
* application/x-www-form-urlencoded
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* pet
|
||||
|
||||
=== Place an order for a pet
|
||||
----
|
||||
POST /stores/order
|
||||
----
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|BodyParameter|body|order placed for purchasing the pet|false|<<Order>>
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|200|successful operation|<<Order>>
|
||||
|400|Invalid Order|No Content
|
||||
|===
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* store
|
||||
|
||||
=== Find purchase order by ID
|
||||
----
|
||||
GET /stores/order/{orderId}
|
||||
----
|
||||
|
||||
==== Description
|
||||
:hardbreaks:
|
||||
For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|PathParameter|orderId|ID of pet that needs to be fetched|true|string
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|200|successful operation|<<Order>>
|
||||
|400|Invalid ID supplied|No Content
|
||||
|404|Order not found|No Content
|
||||
|===
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* store
|
||||
|
||||
=== Delete purchase order by ID
|
||||
----
|
||||
DELETE /stores/order/{orderId}
|
||||
----
|
||||
|
||||
==== Description
|
||||
:hardbreaks:
|
||||
For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|PathParameter|orderId|ID of the order that needs to be deleted|true|string
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|400|Invalid ID supplied|No Content
|
||||
|404|Order not found|No Content
|
||||
|===
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* store
|
||||
|
||||
=== Create user
|
||||
----
|
||||
POST /users
|
||||
----
|
||||
|
||||
==== Description
|
||||
:hardbreaks:
|
||||
This can only be done by the logged in user.
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|BodyParameter|body|Created user object|false|<<User>>
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|default|successful operation|No Content
|
||||
|===
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* user
|
||||
|
||||
=== Creates list of users with given input array
|
||||
----
|
||||
POST /users/createWithArray
|
||||
----
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|BodyParameter|body|List of user object|false|<<User>> array
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|default|successful operation|No Content
|
||||
|===
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* user
|
||||
|
||||
=== Creates list of users with given input array
|
||||
----
|
||||
POST /users/createWithList
|
||||
----
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|BodyParameter|body|List of user object|false|<<User>> array
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|default|successful operation|No Content
|
||||
|===
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* user
|
||||
|
||||
=== Logs user into the system
|
||||
----
|
||||
GET /users/login
|
||||
----
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|QueryParameter|username|The user name for login|false|string
|
||||
|QueryParameter|password|The password for login in clear text|false|string
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|200|successful operation|string
|
||||
|400|Invalid username/password supplied|No Content
|
||||
|===
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* user
|
||||
|
||||
=== Logs out current logged in user session
|
||||
----
|
||||
GET /users/logout
|
||||
----
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|default|successful operation|No Content
|
||||
|===
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* user
|
||||
|
||||
=== Get user by user name
|
||||
----
|
||||
GET /users/{username}
|
||||
----
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|PathParameter|username|The name that needs to be fetched. Use user1 for testing.|true|string
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|200|successful operation|<<User>>
|
||||
|400|Invalid username supplied|No Content
|
||||
|404|User not found|No Content
|
||||
|===
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* user
|
||||
|
||||
=== Updated user
|
||||
----
|
||||
PUT /users/{username}
|
||||
----
|
||||
|
||||
==== Description
|
||||
:hardbreaks:
|
||||
This can only be done by the logged in user.
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|PathParameter|username|name that need to be deleted|true|string
|
||||
|BodyParameter|body|Updated user object|false|<<User>>
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|400|Invalid user supplied|No Content
|
||||
|404|User not found|No Content
|
||||
|===
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* user
|
||||
|
||||
=== Delete user
|
||||
----
|
||||
DELETE /users/{username}
|
||||
----
|
||||
|
||||
==== Description
|
||||
:hardbreaks:
|
||||
This can only be done by the logged in user.
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|PathParameter|username|The name that needs to be deleted|true|string
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|400|Invalid username supplied|No Content
|
||||
|404|User not found|No Content
|
||||
|===
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* user
|
||||
|
||||
637
src/docs/asciidocAsString/swagger.adoc
Normal file
@@ -0,0 +1,637 @@
|
||||
= Swagger Petstore
|
||||
|
||||
This is a sample server Petstore server.
|
||||
|
||||
[Learn about Swagger](http://swagger.wordnik.com) or join the IRC channel `#swagger` on irc.freenode.net.
|
||||
|
||||
For this sample, you can use the api key `special-key` to test the authorization filters
|
||||
|
||||
Version: 1.0.0
|
||||
Contact: apiteam@wordnik.com
|
||||
License: Apache 2.0
|
||||
License URL: http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
Terms of service: http://helloreverb.com/terms/
|
||||
|
||||
Host: petstore.swagger.wordnik.com
|
||||
BasePath: /v2
|
||||
Schemes: HTTP
|
||||
|
||||
== Paths
|
||||
=== Update an existing pet
|
||||
----
|
||||
PUT /pets
|
||||
----
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|BodyParameter|body|Pet object that needs to be added to the store|false|<<Pet>>
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|400|Invalid ID supplied|No Content
|
||||
|404|Pet not found|No Content
|
||||
|405|Validation exception|No Content
|
||||
|===
|
||||
|
||||
==== Consumes
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* pet
|
||||
|
||||
=== Add a new pet to the store
|
||||
----
|
||||
POST /pets
|
||||
----
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|BodyParameter|body|Pet object that needs to be added to the store|false|<<Pet>>
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|405|Invalid input|No Content
|
||||
|===
|
||||
|
||||
==== Consumes
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* pet
|
||||
|
||||
=== Finds Pets by status
|
||||
----
|
||||
GET /pets/findByStatus
|
||||
----
|
||||
|
||||
==== Description
|
||||
:hardbreaks:
|
||||
Multiple status values can be provided with comma seperated strings
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|QueryParameter|status|Status values that need to be considered for filter|false|multi string array
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|200|successful operation|<<Pet>> array
|
||||
|400|Invalid status value|No Content
|
||||
|===
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* pet
|
||||
|
||||
=== Finds Pets by tags
|
||||
----
|
||||
GET /pets/findByTags
|
||||
----
|
||||
|
||||
==== Description
|
||||
:hardbreaks:
|
||||
Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|QueryParameter|tags|Tags to filter by|false|multi string array
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|200|successful operation|<<Pet>> array
|
||||
|400|Invalid tag value|No Content
|
||||
|===
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* pet
|
||||
|
||||
=== Find pet by ID
|
||||
----
|
||||
GET /pets/{petId}
|
||||
----
|
||||
|
||||
==== Description
|
||||
:hardbreaks:
|
||||
Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|PathParameter|petId|ID of pet that needs to be fetched|true|integer (int64)
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|200|successful operation|<<Pet>>
|
||||
|400|Invalid ID supplied|No Content
|
||||
|404|Pet not found|No Content
|
||||
|===
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* pet
|
||||
|
||||
=== Deletes a pet
|
||||
----
|
||||
DELETE /pets/{petId}
|
||||
----
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|HeaderParameter|api_key||true|string
|
||||
|PathParameter|petId|Pet id to delete|true|integer (int64)
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|400|Invalid pet value|No Content
|
||||
|===
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* pet
|
||||
|
||||
=== Updates a pet in the store with form data
|
||||
----
|
||||
POST /pets/{petId}
|
||||
----
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|PathParameter|petId|ID of pet that needs to be updated|true|string
|
||||
|FormDataParameter|name|Updated name of the pet|true|string
|
||||
|FormDataParameter|status|Updated status of the pet|true|string
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|405|Invalid input|No Content
|
||||
|===
|
||||
|
||||
==== Consumes
|
||||
|
||||
* application/x-www-form-urlencoded
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* pet
|
||||
|
||||
=== Place an order for a pet
|
||||
----
|
||||
POST /stores/order
|
||||
----
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|BodyParameter|body|order placed for purchasing the pet|false|<<Order>>
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|200|successful operation|<<Order>>
|
||||
|400|Invalid Order|No Content
|
||||
|===
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* store
|
||||
|
||||
=== Find purchase order by ID
|
||||
----
|
||||
GET /stores/order/{orderId}
|
||||
----
|
||||
|
||||
==== Description
|
||||
:hardbreaks:
|
||||
For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|PathParameter|orderId|ID of pet that needs to be fetched|true|string
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|200|successful operation|<<Order>>
|
||||
|400|Invalid ID supplied|No Content
|
||||
|404|Order not found|No Content
|
||||
|===
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* store
|
||||
|
||||
=== Delete purchase order by ID
|
||||
----
|
||||
DELETE /stores/order/{orderId}
|
||||
----
|
||||
|
||||
==== Description
|
||||
:hardbreaks:
|
||||
For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|PathParameter|orderId|ID of the order that needs to be deleted|true|string
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|400|Invalid ID supplied|No Content
|
||||
|404|Order not found|No Content
|
||||
|===
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* store
|
||||
|
||||
=== Create user
|
||||
----
|
||||
POST /users
|
||||
----
|
||||
|
||||
==== Description
|
||||
:hardbreaks:
|
||||
This can only be done by the logged in user.
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|BodyParameter|body|Created user object|false|<<User>>
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|default|successful operation|No Content
|
||||
|===
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* user
|
||||
|
||||
=== Creates list of users with given input array
|
||||
----
|
||||
POST /users/createWithArray
|
||||
----
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|BodyParameter|body|List of user object|false|<<User>> array
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|default|successful operation|No Content
|
||||
|===
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* user
|
||||
|
||||
=== Creates list of users with given input array
|
||||
----
|
||||
POST /users/createWithList
|
||||
----
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|BodyParameter|body|List of user object|false|<<User>> array
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|default|successful operation|No Content
|
||||
|===
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* user
|
||||
|
||||
=== Logs user into the system
|
||||
----
|
||||
GET /users/login
|
||||
----
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|QueryParameter|username|The user name for login|false|string
|
||||
|QueryParameter|password|The password for login in clear text|false|string
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|200|successful operation|string
|
||||
|400|Invalid username/password supplied|No Content
|
||||
|===
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* user
|
||||
|
||||
=== Logs out current logged in user session
|
||||
----
|
||||
GET /users/logout
|
||||
----
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|default|successful operation|No Content
|
||||
|===
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* user
|
||||
|
||||
=== Get user by user name
|
||||
----
|
||||
GET /users/{username}
|
||||
----
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|PathParameter|username|The name that needs to be fetched. Use user1 for testing.|true|string
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|200|successful operation|<<User>>
|
||||
|400|Invalid username supplied|No Content
|
||||
|404|User not found|No Content
|
||||
|===
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* user
|
||||
|
||||
=== Updated user
|
||||
----
|
||||
PUT /users/{username}
|
||||
----
|
||||
|
||||
==== Description
|
||||
:hardbreaks:
|
||||
This can only be done by the logged in user.
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|PathParameter|username|name that need to be deleted|true|string
|
||||
|BodyParameter|body|Updated user object|false|<<User>>
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|400|Invalid user supplied|No Content
|
||||
|404|User not found|No Content
|
||||
|===
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* user
|
||||
|
||||
=== Delete user
|
||||
----
|
||||
DELETE /users/{username}
|
||||
----
|
||||
|
||||
==== Description
|
||||
:hardbreaks:
|
||||
This can only be done by the logged in user.
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|PathParameter|username|The name that needs to be deleted|true|string
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|400|Invalid username supplied|No Content
|
||||
|404|User not found|No Content
|
||||
|===
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* user
|
||||
|
||||
== Definitions
|
||||
=== User
|
||||
[options="header"]
|
||||
|===
|
||||
|Name|Description|Schema|Required
|
||||
|id||integer (int64)|false
|
||||
|username||string|false
|
||||
|firstName||string|false
|
||||
|lastName||string|false
|
||||
|email||string|false
|
||||
|password||string|false
|
||||
|phone||string|false
|
||||
|userStatus|User Status|integer (int32)|false
|
||||
|===
|
||||
|
||||
=== Category
|
||||
[options="header"]
|
||||
|===
|
||||
|Name|Description|Schema|Required
|
||||
|id||integer (int64)|false
|
||||
|name||string|false
|
||||
|===
|
||||
|
||||
=== Pet
|
||||
[options="header"]
|
||||
|===
|
||||
|Name|Description|Schema|Required
|
||||
|id||integer (int64)|false
|
||||
|category||<<Category>>|false
|
||||
|name||string|true
|
||||
|photoUrls||string array|true
|
||||
|tags||<<Tag>> array|false
|
||||
|status|pet status in the store|string|false
|
||||
|===
|
||||
|
||||
=== Tag
|
||||
[options="header"]
|
||||
|===
|
||||
|Name|Description|Schema|Required
|
||||
|id||integer (int64)|false
|
||||
|name||string|false
|
||||
|===
|
||||
|
||||
=== Order
|
||||
[options="header"]
|
||||
|===
|
||||
|Name|Description|Schema|Required
|
||||
|id||integer (int64)|false
|
||||
|petId||integer (int64)|false
|
||||
|quantity||integer (int32)|false
|
||||
|shipDate||string (date-time)|false
|
||||
|status|Order Status|string|false
|
||||
|complete||boolean|false
|
||||
|===
|
||||
|
||||
2438
src/docs/asciidocAsString/swagger.html
Normal file
50
src/docs/markdown/definitions.md
Normal file
@@ -0,0 +1,50 @@
|
||||
## Definitions
|
||||
### User
|
||||
|Name|Description|Schema|Required|
|
||||
|----|----|----|----|
|
||||
|id||integer (int64)|false|
|
||||
|username||string|false|
|
||||
|firstName||string|false|
|
||||
|lastName||string|false|
|
||||
|email||string|false|
|
||||
|password||string|false|
|
||||
|phone||string|false|
|
||||
|userStatus|User Status|integer (int32)|false|
|
||||
|
||||
|
||||
### Category
|
||||
|Name|Description|Schema|Required|
|
||||
|----|----|----|----|
|
||||
|id||integer (int64)|false|
|
||||
|name||string|false|
|
||||
|
||||
|
||||
### Pet
|
||||
|Name|Description|Schema|Required|
|
||||
|----|----|----|----|
|
||||
|id||integer (int64)|false|
|
||||
|category||Category|false|
|
||||
|name||string|true|
|
||||
|photoUrls||string array|true|
|
||||
|tags||Tag array|false|
|
||||
|status|pet status in the store|string|false|
|
||||
|
||||
|
||||
### Tag
|
||||
|Name|Description|Schema|Required|
|
||||
|----|----|----|----|
|
||||
|id||integer (int64)|false|
|
||||
|name||string|false|
|
||||
|
||||
|
||||
### Order
|
||||
|Name|Description|Schema|Required|
|
||||
|----|----|----|----|
|
||||
|id||integer (int64)|false|
|
||||
|petId||integer (int64)|false|
|
||||
|quantity||integer (int32)|false|
|
||||
|shipDate||string (date-time)|false|
|
||||
|status|Order Status|string|false|
|
||||
|complete||boolean|false|
|
||||
|
||||
|
||||
547
src/docs/markdown/paths.md
Normal file
@@ -0,0 +1,547 @@
|
||||
# Swagger Petstore
|
||||
|
||||
This is a sample server Petstore server.
|
||||
|
||||
[Learn about Swagger](http://swagger.wordnik.com) or join the IRC channel `#swagger` on irc.freenode.net.
|
||||
|
||||
For this sample, you can use the api key `special-key` to test the authorization filters
|
||||
|
||||
Version: 1.0.0
|
||||
Contact: apiteam@wordnik.com
|
||||
License: Apache 2.0
|
||||
License URL: http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
Terms of service: http://helloreverb.com/terms/
|
||||
|
||||
Host: petstore.swagger.wordnik.com
|
||||
BasePath: /v2
|
||||
Schemes: HTTP
|
||||
|
||||
## Paths
|
||||
### Update an existing pet
|
||||
```
|
||||
PUT /pets
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|Type|Name|Description|Required|Schema|
|
||||
|----|----|----|----|----|
|
||||
|BodyParameter|body|Pet object that needs to be added to the store|false|Pet|
|
||||
|
||||
|
||||
### Responses
|
||||
|HTTP Code|Description|Schema|
|
||||
|----|----|----|
|
||||
|400|Invalid ID supplied|No Content|
|
||||
|404|Pet not found|No Content|
|
||||
|405|Validation exception|No Content|
|
||||
|
||||
|
||||
### Consumes
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
### Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
### Tags
|
||||
|
||||
* pet
|
||||
|
||||
### Add a new pet to the store
|
||||
```
|
||||
POST /pets
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|Type|Name|Description|Required|Schema|
|
||||
|----|----|----|----|----|
|
||||
|BodyParameter|body|Pet object that needs to be added to the store|false|Pet|
|
||||
|
||||
|
||||
### Responses
|
||||
|HTTP Code|Description|Schema|
|
||||
|----|----|----|
|
||||
|405|Invalid input|No Content|
|
||||
|
||||
|
||||
### Consumes
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
### Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
### Tags
|
||||
|
||||
* pet
|
||||
|
||||
### Finds Pets by status
|
||||
```
|
||||
GET /pets/findByStatus
|
||||
```
|
||||
|
||||
### Description
|
||||
|
||||
Multiple status values can be provided with comma seperated strings
|
||||
|
||||
### Parameters
|
||||
|Type|Name|Description|Required|Schema|
|
||||
|----|----|----|----|----|
|
||||
|QueryParameter|status|Status values that need to be considered for filter|false|multi string array|
|
||||
|
||||
|
||||
### Responses
|
||||
|HTTP Code|Description|Schema|
|
||||
|----|----|----|
|
||||
|200|successful operation|Pet array|
|
||||
|400|Invalid status value|No Content|
|
||||
|
||||
|
||||
### Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
### Tags
|
||||
|
||||
* pet
|
||||
|
||||
### Finds Pets by tags
|
||||
```
|
||||
GET /pets/findByTags
|
||||
```
|
||||
|
||||
### Description
|
||||
|
||||
Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.
|
||||
|
||||
### Parameters
|
||||
|Type|Name|Description|Required|Schema|
|
||||
|----|----|----|----|----|
|
||||
|QueryParameter|tags|Tags to filter by|false|multi string array|
|
||||
|
||||
|
||||
### Responses
|
||||
|HTTP Code|Description|Schema|
|
||||
|----|----|----|
|
||||
|200|successful operation|Pet array|
|
||||
|400|Invalid tag value|No Content|
|
||||
|
||||
|
||||
### Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
### Tags
|
||||
|
||||
* pet
|
||||
|
||||
### Find pet by ID
|
||||
```
|
||||
GET /pets/{petId}
|
||||
```
|
||||
|
||||
### Description
|
||||
|
||||
Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions
|
||||
|
||||
### Parameters
|
||||
|Type|Name|Description|Required|Schema|
|
||||
|----|----|----|----|----|
|
||||
|PathParameter|petId|ID of pet that needs to be fetched|true|integer (int64)|
|
||||
|
||||
|
||||
### Responses
|
||||
|HTTP Code|Description|Schema|
|
||||
|----|----|----|
|
||||
|200|successful operation|Pet|
|
||||
|400|Invalid ID supplied|No Content|
|
||||
|404|Pet not found|No Content|
|
||||
|
||||
|
||||
### Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
### Tags
|
||||
|
||||
* pet
|
||||
|
||||
### Deletes a pet
|
||||
```
|
||||
DELETE /pets/{petId}
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|Type|Name|Description|Required|Schema|
|
||||
|----|----|----|----|----|
|
||||
|HeaderParameter|api_key||true|string|
|
||||
|PathParameter|petId|Pet id to delete|true|integer (int64)|
|
||||
|
||||
|
||||
### Responses
|
||||
|HTTP Code|Description|Schema|
|
||||
|----|----|----|
|
||||
|400|Invalid pet value|No Content|
|
||||
|
||||
|
||||
### Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
### Tags
|
||||
|
||||
* pet
|
||||
|
||||
### Updates a pet in the store with form data
|
||||
```
|
||||
POST /pets/{petId}
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|Type|Name|Description|Required|Schema|
|
||||
|----|----|----|----|----|
|
||||
|PathParameter|petId|ID of pet that needs to be updated|true|string|
|
||||
|FormDataParameter|name|Updated name of the pet|true|string|
|
||||
|FormDataParameter|status|Updated status of the pet|true|string|
|
||||
|
||||
|
||||
### Responses
|
||||
|HTTP Code|Description|Schema|
|
||||
|----|----|----|
|
||||
|405|Invalid input|No Content|
|
||||
|
||||
|
||||
### Consumes
|
||||
|
||||
* application/x-www-form-urlencoded
|
||||
|
||||
### Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
### Tags
|
||||
|
||||
* pet
|
||||
|
||||
### Place an order for a pet
|
||||
```
|
||||
POST /stores/order
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|Type|Name|Description|Required|Schema|
|
||||
|----|----|----|----|----|
|
||||
|BodyParameter|body|order placed for purchasing the pet|false|Order|
|
||||
|
||||
|
||||
### Responses
|
||||
|HTTP Code|Description|Schema|
|
||||
|----|----|----|
|
||||
|200|successful operation|Order|
|
||||
|400|Invalid Order|No Content|
|
||||
|
||||
|
||||
### Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
### Tags
|
||||
|
||||
* store
|
||||
|
||||
### Find purchase order by ID
|
||||
```
|
||||
GET /stores/order/{orderId}
|
||||
```
|
||||
|
||||
### Description
|
||||
|
||||
For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
|
||||
|
||||
### Parameters
|
||||
|Type|Name|Description|Required|Schema|
|
||||
|----|----|----|----|----|
|
||||
|PathParameter|orderId|ID of pet that needs to be fetched|true|string|
|
||||
|
||||
|
||||
### Responses
|
||||
|HTTP Code|Description|Schema|
|
||||
|----|----|----|
|
||||
|200|successful operation|Order|
|
||||
|400|Invalid ID supplied|No Content|
|
||||
|404|Order not found|No Content|
|
||||
|
||||
|
||||
### Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
### Tags
|
||||
|
||||
* store
|
||||
|
||||
### Delete purchase order by ID
|
||||
```
|
||||
DELETE /stores/order/{orderId}
|
||||
```
|
||||
|
||||
### Description
|
||||
|
||||
For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
||||
|
||||
### Parameters
|
||||
|Type|Name|Description|Required|Schema|
|
||||
|----|----|----|----|----|
|
||||
|PathParameter|orderId|ID of the order that needs to be deleted|true|string|
|
||||
|
||||
|
||||
### Responses
|
||||
|HTTP Code|Description|Schema|
|
||||
|----|----|----|
|
||||
|400|Invalid ID supplied|No Content|
|
||||
|404|Order not found|No Content|
|
||||
|
||||
|
||||
### Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
### Tags
|
||||
|
||||
* store
|
||||
|
||||
### Create user
|
||||
```
|
||||
POST /users
|
||||
```
|
||||
|
||||
### Description
|
||||
|
||||
This can only be done by the logged in user.
|
||||
|
||||
### Parameters
|
||||
|Type|Name|Description|Required|Schema|
|
||||
|----|----|----|----|----|
|
||||
|BodyParameter|body|Created user object|false|User|
|
||||
|
||||
|
||||
### Responses
|
||||
|HTTP Code|Description|Schema|
|
||||
|----|----|----|
|
||||
|default|successful operation|No Content|
|
||||
|
||||
|
||||
### Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
### Tags
|
||||
|
||||
* user
|
||||
|
||||
### Creates list of users with given input array
|
||||
```
|
||||
POST /users/createWithArray
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|Type|Name|Description|Required|Schema|
|
||||
|----|----|----|----|----|
|
||||
|BodyParameter|body|List of user object|false|User array|
|
||||
|
||||
|
||||
### Responses
|
||||
|HTTP Code|Description|Schema|
|
||||
|----|----|----|
|
||||
|default|successful operation|No Content|
|
||||
|
||||
|
||||
### Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
### Tags
|
||||
|
||||
* user
|
||||
|
||||
### Creates list of users with given input array
|
||||
```
|
||||
POST /users/createWithList
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|Type|Name|Description|Required|Schema|
|
||||
|----|----|----|----|----|
|
||||
|BodyParameter|body|List of user object|false|User array|
|
||||
|
||||
|
||||
### Responses
|
||||
|HTTP Code|Description|Schema|
|
||||
|----|----|----|
|
||||
|default|successful operation|No Content|
|
||||
|
||||
|
||||
### Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
### Tags
|
||||
|
||||
* user
|
||||
|
||||
### Logs user into the system
|
||||
```
|
||||
GET /users/login
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|Type|Name|Description|Required|Schema|
|
||||
|----|----|----|----|----|
|
||||
|QueryParameter|username|The user name for login|false|string|
|
||||
|QueryParameter|password|The password for login in clear text|false|string|
|
||||
|
||||
|
||||
### Responses
|
||||
|HTTP Code|Description|Schema|
|
||||
|----|----|----|
|
||||
|200|successful operation|string|
|
||||
|400|Invalid username/password supplied|No Content|
|
||||
|
||||
|
||||
### Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
### Tags
|
||||
|
||||
* user
|
||||
|
||||
### Logs out current logged in user session
|
||||
```
|
||||
GET /users/logout
|
||||
```
|
||||
|
||||
### Responses
|
||||
|HTTP Code|Description|Schema|
|
||||
|----|----|----|
|
||||
|default|successful operation|No Content|
|
||||
|
||||
|
||||
### Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
### Tags
|
||||
|
||||
* user
|
||||
|
||||
### Get user by user name
|
||||
```
|
||||
GET /users/{username}
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|Type|Name|Description|Required|Schema|
|
||||
|----|----|----|----|----|
|
||||
|PathParameter|username|The name that needs to be fetched. Use user1 for testing.|true|string|
|
||||
|
||||
|
||||
### Responses
|
||||
|HTTP Code|Description|Schema|
|
||||
|----|----|----|
|
||||
|200|successful operation|User|
|
||||
|400|Invalid username supplied|No Content|
|
||||
|404|User not found|No Content|
|
||||
|
||||
|
||||
### Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
### Tags
|
||||
|
||||
* user
|
||||
|
||||
### Updated user
|
||||
```
|
||||
PUT /users/{username}
|
||||
```
|
||||
|
||||
### Description
|
||||
|
||||
This can only be done by the logged in user.
|
||||
|
||||
### Parameters
|
||||
|Type|Name|Description|Required|Schema|
|
||||
|----|----|----|----|----|
|
||||
|PathParameter|username|name that need to be deleted|true|string|
|
||||
|BodyParameter|body|Updated user object|false|User|
|
||||
|
||||
|
||||
### Responses
|
||||
|HTTP Code|Description|Schema|
|
||||
|----|----|----|
|
||||
|400|Invalid user supplied|No Content|
|
||||
|404|User not found|No Content|
|
||||
|
||||
|
||||
### Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
### Tags
|
||||
|
||||
* user
|
||||
|
||||
### Delete user
|
||||
```
|
||||
DELETE /users/{username}
|
||||
```
|
||||
|
||||
### Description
|
||||
|
||||
This can only be done by the logged in user.
|
||||
|
||||
### Parameters
|
||||
|Type|Name|Description|Required|Schema|
|
||||
|----|----|----|----|----|
|
||||
|PathParameter|username|The name that needs to be deleted|true|string|
|
||||
|
||||
|
||||
### Responses
|
||||
|HTTP Code|Description|Schema|
|
||||
|----|----|----|
|
||||
|400|Invalid username supplied|No Content|
|
||||
|404|User not found|No Content|
|
||||
|
||||
|
||||
### Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
### Tags
|
||||
|
||||
* user
|
||||
|
||||
@@ -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,47 @@ 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 null!");
|
||||
return new Builder(swaggerSource);
|
||||
public static Builder from(String swaggerLocation){
|
||||
Validate.notEmpty(swaggerLocation, "swaggerLocation must not be empty!");
|
||||
return new Builder(swaggerLocation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Swagger2MarkupConverter.Builder from a given Swagger model.
|
||||
*
|
||||
* @param swagger the Swagger source.
|
||||
* @return a Swagger2MarkupConverter
|
||||
*/
|
||||
public static Builder from(Swagger swagger){
|
||||
Validate.notNull(swagger, "swagger must not be null!");
|
||||
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));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -61,6 +100,15 @@ public class Swagger2MarkupConverter {
|
||||
buildDocuments(targetFolderPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the document with the given markup language and returns it as a String
|
||||
*
|
||||
* @return a the document as a String
|
||||
*/
|
||||
public String asString() throws IOException{
|
||||
return buildDocuments();
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a file for the Paths (API) and a file for the Definitions (Model)
|
||||
|
||||
@@ -72,6 +120,16 @@ public class Swagger2MarkupConverter {
|
||||
new DefinitionsDocument(swagger, markupLanguage, schemasFolderPath).build().writeToFile(directory, DEFINITIONS_DOCUMENT, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a file for the Paths (API) and a file for the Definitions (Model)
|
||||
|
||||
* @return a the document as a String
|
||||
*/
|
||||
private String buildDocuments() throws IOException {
|
||||
return new PathsDocument(swagger, markupLanguage, examplesFolderPath).build().toString()
|
||||
.concat(new DefinitionsDocument(swagger, markupLanguage, schemasFolderPath).build().toString());
|
||||
}
|
||||
|
||||
|
||||
public static class Builder{
|
||||
private final Swagger swagger;
|
||||
@@ -82,10 +140,19 @@ 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Builder using a given Swagger model.
|
||||
*
|
||||
* @param swagger the Swagger source.
|
||||
*/
|
||||
Builder(Swagger swagger){
|
||||
this.swagger = swagger;
|
||||
}
|
||||
|
||||
public Swagger2MarkupConverter build(){
|
||||
|
||||
@@ -2,8 +2,10 @@ package io.github.robwin.swagger2markup.builder.document;
|
||||
|
||||
import com.wordnik.swagger.models.Model;
|
||||
import com.wordnik.swagger.models.Swagger;
|
||||
import com.wordnik.swagger.models.properties.AbstractProperty;
|
||||
import com.wordnik.swagger.models.properties.Property;
|
||||
import io.github.robwin.markup.builder.MarkupLanguage;
|
||||
import io.github.robwin.swagger2markup.utils.PropertyUtils;
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
@@ -26,8 +28,6 @@ public class DefinitionsDocument extends MarkupDocument {
|
||||
private static final List<String> IGNORED_DEFINITIONS = Arrays.asList("Void");
|
||||
private static final String JSON_SCHEMA = "JSON Schema";
|
||||
private static final String XML_SCHEMA = "XML Schema";
|
||||
private static final String NAME_COLUMN = "Name";
|
||||
private static final String TYPE_COLUMN = "Type";
|
||||
public static final String JSON_SCHEMA_EXTENSION = ".json";
|
||||
public static final String XML_SCHEMA_EXTENSION = ".xsd";
|
||||
public static final String JSON = "json";
|
||||
@@ -104,13 +104,24 @@ public class DefinitionsDocument extends MarkupDocument {
|
||||
private void definition(String definitionName, Model model) {
|
||||
this.markupDocBuilder.sectionTitleLevel2(definitionName);
|
||||
Map<String, Property> properties = model.getProperties();
|
||||
List<String> csvContent = new ArrayList<>();
|
||||
csvContent.add(NAME_COLUMN + DELIMITER + TYPE_COLUMN + DELIMITER + REQUIRED_COLUMN);
|
||||
for (Map.Entry<String, Property> propertyEntry : properties.entrySet()) {
|
||||
Property property = propertyEntry.getValue();
|
||||
csvContent.add(propertyEntry.getKey() + DELIMITER + property.getType() + DELIMITER + property.getRequired());
|
||||
List<String> headerAndContent = new ArrayList<>();
|
||||
List<String> header = Arrays.asList(NAME_COLUMN, DESCRIPTION_COLUMN, SCHEMA_COLUMN, REQUIRED_COLUMN);
|
||||
headerAndContent.add(StringUtils.join(header, DELIMITER));
|
||||
if(MapUtils.isNotEmpty(properties)){
|
||||
for (Map.Entry<String, Property> propertyEntry : properties.entrySet()) {
|
||||
Property property = propertyEntry.getValue();
|
||||
String description = "";
|
||||
if(property instanceof AbstractProperty){
|
||||
if(StringUtils.isNotBlank(property.getDescription())){
|
||||
description = property.getDescription();
|
||||
}
|
||||
}
|
||||
String type = PropertyUtils.getType(property, markupLanguage);
|
||||
List<String> content = Arrays.asList(propertyEntry.getKey(), description, type, Boolean.toString(property.getRequired()));
|
||||
headerAndContent.add(StringUtils.join(content, DELIMITER));
|
||||
}
|
||||
this.markupDocBuilder.tableWithHeaderRow(headerAndContent);
|
||||
}
|
||||
this.markupDocBuilder.tableWithHeaderRow(csvContent);
|
||||
}
|
||||
|
||||
private void definitionSchema(String definitionName) throws IOException {
|
||||
|
||||
@@ -15,8 +15,12 @@ import java.nio.charset.Charset;
|
||||
*/
|
||||
public abstract class MarkupDocument {
|
||||
|
||||
protected static final String DELIMITER = ",";
|
||||
protected static final String DELIMITER = "|";
|
||||
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 Logger logger = LoggerFactory.getLogger(getClass());
|
||||
protected Swagger swagger;
|
||||
protected MarkupLanguage markupLanguage;
|
||||
|
||||
@@ -2,17 +2,22 @@ package io.github.robwin.swagger2markup.builder.document;
|
||||
|
||||
import com.wordnik.swagger.models.*;
|
||||
import com.wordnik.swagger.models.parameters.Parameter;
|
||||
import com.wordnik.swagger.models.properties.Property;
|
||||
import io.github.robwin.markup.builder.MarkupLanguage;
|
||||
import io.github.robwin.swagger2markup.utils.ParameterUtils;
|
||||
import io.github.robwin.swagger2markup.utils.PropertyUtils;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang.WordUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -21,20 +26,27 @@ import java.util.Map;
|
||||
*/
|
||||
public class PathsDocument extends MarkupDocument {
|
||||
|
||||
private static final String PATHS = "Paths";
|
||||
private static final String VERSION = "Version: ";
|
||||
private static final String DESCRIPTION_COLUMN = "Description";
|
||||
private static final String DESCRIPTION = DESCRIPTION_COLUMN;
|
||||
private static final String CONTACT_NAME = "Contact: ";
|
||||
private static final String CONTACT_EMAIL = "Contact Email: ";
|
||||
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 HOST = "Host: ";
|
||||
private static final String BASE_PATH = "BasePath: ";
|
||||
private static final String SCHEMES = "Schemes: ";
|
||||
private static final String PARAMETERS = "Parameters";
|
||||
private static final String PRODUCES = "Produces";
|
||||
private static final String CONSUMES = "Consumes";
|
||||
private static final String TAGS = "Tags";
|
||||
private static final String RESPONSES = "Responses";
|
||||
private static final String EXAMPLE_REQUEST = "Example request";
|
||||
private static final String EXAMPLE_RESPONSE = "Example response";
|
||||
private static final String NAME_COLUMN = "Name";
|
||||
private static final String LOCATED_IN_COLUMN = "Located in";
|
||||
private static final String CODE_COLUMN = "Code";
|
||||
public static final String REQUEST_EXAMPLE_FILE_NAME = "request";
|
||||
public static final String RESPONSE_EXAMPLE_FILE_NAME = "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 = "request";
|
||||
private static final String RESPONSE_EXAMPLE_FILE_NAME = "response";
|
||||
|
||||
private boolean examplesEnabled;
|
||||
private String examplesFolderPath;
|
||||
@@ -58,39 +70,78 @@ public class PathsDocument extends MarkupDocument {
|
||||
|
||||
@Override
|
||||
public MarkupDocument build() throws IOException {
|
||||
documentHeader(swagger.getInfo());
|
||||
paths(swagger.getPaths());
|
||||
documentHeader();
|
||||
paths();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the document header
|
||||
*
|
||||
* @param info the Swagger Info
|
||||
* Builds the document header of the swagger model
|
||||
*/
|
||||
private void documentHeader(Info info) {
|
||||
this.markupDocBuilder
|
||||
.documentTitle(info.getTitle())
|
||||
.textLine(info.getDescription())
|
||||
.textLine(VERSION + info.getVersion())
|
||||
.newLine();
|
||||
private void documentHeader() {
|
||||
Info info = swagger.getInfo();
|
||||
this.markupDocBuilder.documentTitle(info.getTitle());
|
||||
if(StringUtils.isNotBlank(info.getDescription())){
|
||||
this.markupDocBuilder.textLine(info.getDescription());
|
||||
}
|
||||
if(StringUtils.isNotBlank(info.getVersion())){
|
||||
this.markupDocBuilder.textLine(VERSION + info.getVersion());
|
||||
}
|
||||
Contact contact = info.getContact();
|
||||
if(contact != null){
|
||||
if(StringUtils.isNotBlank(contact.getName())){
|
||||
this.markupDocBuilder.textLine(CONTACT_NAME + contact.getName());
|
||||
}
|
||||
if(StringUtils.isNotBlank(contact.getEmail())){
|
||||
this.markupDocBuilder.textLine(CONTACT_EMAIL + contact.getEmail());
|
||||
}
|
||||
}
|
||||
License license = info.getLicense();
|
||||
if(license != null) {
|
||||
if (StringUtils.isNotBlank(license.getName())) {
|
||||
this.markupDocBuilder.textLine(LICENSE + license.getName());
|
||||
}
|
||||
if (StringUtils.isNotBlank(license.getUrl())) {
|
||||
this.markupDocBuilder.textLine(LICENSE_URL + license.getUrl());
|
||||
}
|
||||
}
|
||||
if(StringUtils.isNotBlank(info.getTermsOfService())){
|
||||
this.markupDocBuilder.textLine(TERMS_OF_SERVICE + info.getTermsOfService());
|
||||
}
|
||||
this.markupDocBuilder.newLine();
|
||||
|
||||
if(StringUtils.isNotBlank(swagger.getHost())){
|
||||
this.markupDocBuilder.textLine(HOST + swagger.getHost());
|
||||
}
|
||||
if(StringUtils.isNotBlank(swagger.getBasePath())){
|
||||
this.markupDocBuilder.textLine(BASE_PATH + swagger.getBasePath());
|
||||
}
|
||||
if(CollectionUtils.isNotEmpty(swagger.getSchemes())){
|
||||
List<String> schemes = new ArrayList<>();
|
||||
for(Scheme scheme : swagger.getSchemes()){
|
||||
schemes.add(scheme.toString());
|
||||
}
|
||||
this.markupDocBuilder.textLine(SCHEMES + StringUtils.join(schemes, ", "));
|
||||
}
|
||||
this.markupDocBuilder.newLine();
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds all paths of the Swagger file
|
||||
*
|
||||
* @param paths a Map of Swagger Paths
|
||||
* Builds all paths of the Swagger model
|
||||
*/
|
||||
private void paths(Map<String, Path> paths) throws IOException {
|
||||
private void paths() throws IOException {
|
||||
Map<String, Path> paths = swagger.getPaths();
|
||||
if(MapUtils.isNotEmpty(paths)) {
|
||||
//this.documentBuilder.sectionTitleLevel1(FEATURES);
|
||||
this.markupDocBuilder.sectionTitleLevel1(PATHS);
|
||||
for (Map.Entry<String, Path> entry : paths.entrySet()) {
|
||||
Path path = entry.getValue();
|
||||
path("GET", entry.getKey(), path.getGet());
|
||||
path("PUT", entry.getKey(), path.getPut());
|
||||
path("DELETE", entry.getKey(), path.getDelete());
|
||||
path("POST", entry.getKey(), path.getPost());
|
||||
path("PATCH", entry.getKey(), path.getPatch());
|
||||
if(path != null) {
|
||||
path("GET", entry.getKey(), path.getGet());
|
||||
path("PUT", entry.getKey(), path.getPut());
|
||||
path("DELETE", entry.getKey(), path.getDelete());
|
||||
path("POST", entry.getKey(), path.getPost());
|
||||
path("PATCH", entry.getKey(), path.getPatch());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -110,21 +161,21 @@ public class PathsDocument extends MarkupDocument {
|
||||
responsesSection(operation);
|
||||
consumesSection(operation);
|
||||
producesSection(operation);
|
||||
tagsSection(operation);
|
||||
examplesSection(operation);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void pathTitle(String httpMethod, String resourcePath, Operation operation) {
|
||||
String summary = operation.getSummary();
|
||||
String title;
|
||||
if(StringUtils.isNotBlank(summary)) {
|
||||
title = summary;
|
||||
this.markupDocBuilder.sectionTitleLevel1(title);
|
||||
this.markupDocBuilder.sectionTitleLevel2(title);
|
||||
this.markupDocBuilder.listing(httpMethod + " " + resourcePath);
|
||||
}else{
|
||||
title = httpMethod + " " + resourcePath;
|
||||
this.markupDocBuilder.sectionTitleLevel1(title);
|
||||
this.markupDocBuilder.sectionTitleLevel2(title);
|
||||
}
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Path processed: {}", title);
|
||||
@@ -134,7 +185,7 @@ public class PathsDocument extends MarkupDocument {
|
||||
private void descriptionSection(Operation operation) {
|
||||
String description = operation.getDescription();
|
||||
if(StringUtils.isNotBlank(description)){
|
||||
this.markupDocBuilder.sectionTitleLevel2(DESCRIPTION);
|
||||
this.markupDocBuilder.sectionTitleLevel3(DESCRIPTION);
|
||||
this.markupDocBuilder.paragraph(description);
|
||||
}
|
||||
}
|
||||
@@ -142,20 +193,26 @@ public class PathsDocument extends MarkupDocument {
|
||||
private void parametersSection(Operation operation) {
|
||||
List<Parameter> parameters = operation.getParameters();
|
||||
if(CollectionUtils.isNotEmpty(parameters)){
|
||||
List<String> csvContent = new ArrayList<>();
|
||||
csvContent.add(NAME_COLUMN + DELIMITER + LOCATED_IN_COLUMN + DELIMITER + DESCRIPTION_COLUMN + DELIMITER + REQUIRED_COLUMN);
|
||||
List<String> headerAndContent = new ArrayList<>();
|
||||
// Table header row
|
||||
List<String> header = Arrays.asList(TYPE_COLUMN, NAME_COLUMN, DESCRIPTION_COLUMN, REQUIRED_COLUMN, SCHEMA_COLUMN);
|
||||
headerAndContent.add(StringUtils.join(header, DELIMITER));
|
||||
for(Parameter parameter : parameters){
|
||||
csvContent.add(parameter.getName() + DELIMITER + parameter.getIn() + DELIMITER + parameter.getDescription() + DELIMITER + parameter.getRequired());
|
||||
String type = ParameterUtils.getType(parameter, markupLanguage);
|
||||
String parameterType = WordUtils.capitalize(parameter.getIn() + "Parameter");
|
||||
// Table content row
|
||||
List<String> content = Arrays.asList(parameterType, parameter.getName(), parameter.getDescription(), Boolean.toString(parameter.getRequired()), type);
|
||||
headerAndContent.add(StringUtils.join(content, DELIMITER));
|
||||
}
|
||||
this.markupDocBuilder.sectionTitleLevel2(PARAMETERS);
|
||||
this.markupDocBuilder.tableWithHeaderRow(csvContent);
|
||||
this.markupDocBuilder.sectionTitleLevel3(PARAMETERS);
|
||||
this.markupDocBuilder.tableWithHeaderRow(headerAndContent);
|
||||
}
|
||||
}
|
||||
|
||||
private void consumesSection(Operation operation) {
|
||||
List<String> consumes = operation.getConsumes();
|
||||
if(CollectionUtils.isNotEmpty(consumes)){
|
||||
this.markupDocBuilder.sectionTitleLevel2(CONSUMES);
|
||||
this.markupDocBuilder.sectionTitleLevel3(CONSUMES);
|
||||
this.markupDocBuilder.unorderedList(consumes);
|
||||
}
|
||||
|
||||
@@ -164,11 +221,19 @@ public class PathsDocument extends MarkupDocument {
|
||||
private void producesSection(Operation operation) {
|
||||
List<String> produces = operation.getProduces();
|
||||
if(CollectionUtils.isNotEmpty(produces)){
|
||||
this.markupDocBuilder.sectionTitleLevel2(PRODUCES);
|
||||
this.markupDocBuilder.sectionTitleLevel3(PRODUCES);
|
||||
this.markupDocBuilder.unorderedList(produces);
|
||||
}
|
||||
}
|
||||
|
||||
private void tagsSection(Operation operation) {
|
||||
List<String> tags = operation.getTags();
|
||||
if(CollectionUtils.isNotEmpty(tags)){
|
||||
this.markupDocBuilder.sectionTitleLevel3(TAGS);
|
||||
this.markupDocBuilder.unorderedList(tags);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the example section of a Swagger Operation
|
||||
*
|
||||
@@ -198,7 +263,7 @@ public class PathsDocument extends MarkupDocument {
|
||||
for (String fileNameExtension : markupLanguage.getFileNameExtensions()) {
|
||||
java.nio.file.Path path = Paths.get(examplesFolderPath, exampleFolder, exampleFileName + fileNameExtension);
|
||||
if (Files.isReadable(path)) {
|
||||
this.markupDocBuilder.sectionTitleLevel2(title);
|
||||
this.markupDocBuilder.sectionTitleLevel3(title);
|
||||
this.markupDocBuilder.paragraph(FileUtils.readFileToString(path.toFile(), StandardCharsets.UTF_8).trim());
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Example file processed: {}", path);
|
||||
@@ -216,12 +281,18 @@ public class PathsDocument extends MarkupDocument {
|
||||
Map<String, Response> responses = operation.getResponses();
|
||||
if(MapUtils.isNotEmpty(responses)){
|
||||
List<String> csvContent = new ArrayList<>();
|
||||
csvContent.add(CODE_COLUMN + DELIMITER + DESCRIPTION_COLUMN);
|
||||
csvContent.add(HTTP_CODE_COLUMN + DELIMITER + DESCRIPTION_COLUMN + DELIMITER + SCHEMA_COLUMN);
|
||||
for(Map.Entry<String, Response> entry : responses.entrySet()){
|
||||
Response response = entry.getValue();
|
||||
csvContent.add(entry.getKey() + DELIMITER + response.getDescription());
|
||||
if(response.getSchema() != null){
|
||||
Property property = response.getSchema();
|
||||
String type = PropertyUtils.getType(property, markupLanguage);
|
||||
csvContent.add(entry.getKey() + DELIMITER + response.getDescription() + DELIMITER + type);
|
||||
}else{
|
||||
csvContent.add(entry.getKey() + DELIMITER + response.getDescription() + DELIMITER + "No Content");
|
||||
}
|
||||
}
|
||||
this.markupDocBuilder.sectionTitleLevel2(RESPONSES);
|
||||
this.markupDocBuilder.sectionTitleLevel3(RESPONSES);
|
||||
this.markupDocBuilder.tableWithHeaderRow(csvContent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package io.github.robwin.swagger2markup.utils;
|
||||
|
||||
import com.wordnik.swagger.models.ArrayModel;
|
||||
import com.wordnik.swagger.models.Model;
|
||||
import com.wordnik.swagger.models.ModelImpl;
|
||||
import com.wordnik.swagger.models.RefModel;
|
||||
import io.github.robwin.markup.builder.MarkupLanguage;
|
||||
import org.apache.commons.lang.Validate;
|
||||
|
||||
public final class ModelUtils {
|
||||
|
||||
public static String getType(Model model, MarkupLanguage markupLanguage) {
|
||||
Validate.notNull(model, "model must not be null!");
|
||||
if (model instanceof ModelImpl) {
|
||||
return ((ModelImpl) model).getType();
|
||||
} else if (model instanceof RefModel) {
|
||||
switch (markupLanguage){
|
||||
case ASCIIDOC: return "<<" + ((RefModel) model).getSimpleRef() + ">>";
|
||||
default: return ((RefModel) model).getSimpleRef();
|
||||
}
|
||||
} else if (model instanceof ArrayModel) {
|
||||
ArrayModel arrayModel = ((ArrayModel) model);
|
||||
return PropertyUtils.getType(arrayModel.getItems(), markupLanguage) + " " + arrayModel.getType();
|
||||
}
|
||||
return "NOT FOUND";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package io.github.robwin.swagger2markup.utils;
|
||||
|
||||
import com.wordnik.swagger.models.Model;
|
||||
import com.wordnik.swagger.models.parameters.*;
|
||||
import io.github.robwin.markup.builder.MarkupLanguage;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang.Validate;
|
||||
|
||||
public final class ParameterUtils {
|
||||
|
||||
public static String getType(Parameter parameter, MarkupLanguage markupLanguage){
|
||||
Validate.notNull(parameter, "property must not be null!");
|
||||
String type = "NOT FOUND";
|
||||
if(parameter instanceof BodyParameter){
|
||||
BodyParameter bodyParameter = (BodyParameter)parameter;
|
||||
Model model = bodyParameter.getSchema();
|
||||
type = ModelUtils.getType(model, markupLanguage);
|
||||
}
|
||||
else if(parameter instanceof PathParameter){
|
||||
PathParameter pathParameter = (PathParameter)parameter;
|
||||
type = getTypeWithFormat(pathParameter.getType(), pathParameter.getFormat());
|
||||
}
|
||||
else if(parameter instanceof QueryParameter){
|
||||
QueryParameter queryParameter = (QueryParameter)parameter;
|
||||
type = getTypeWithFormat(queryParameter.getType(), queryParameter.getFormat());
|
||||
if(type.equals("array")){
|
||||
String collectionFormat = queryParameter.getCollectionFormat();
|
||||
type = collectionFormat + " " + PropertyUtils.getType(queryParameter.getItems(), markupLanguage) + " " + type;
|
||||
}
|
||||
}
|
||||
else if(parameter instanceof HeaderParameter){
|
||||
HeaderParameter headerParameter = (HeaderParameter)parameter;
|
||||
type = getTypeWithFormat(headerParameter.getType(), headerParameter.getFormat());
|
||||
}
|
||||
else if(parameter instanceof FormParameter){
|
||||
FormParameter formParameter = (FormParameter)parameter;
|
||||
type = formParameter.getType();
|
||||
}
|
||||
else if(parameter instanceof CookieParameter){
|
||||
CookieParameter cookieParameter = (CookieParameter)parameter;
|
||||
type = getTypeWithFormat(cookieParameter.getType(), cookieParameter.getFormat());
|
||||
}
|
||||
else if(parameter instanceof RefParameter){
|
||||
RefParameter refParameter = (RefParameter)parameter;
|
||||
switch (markupLanguage){
|
||||
case ASCIIDOC: return "<<" + refParameter.getSimpleRef() + ">>";
|
||||
default: return refParameter.getSimpleRef();
|
||||
}
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
private static String getTypeWithFormat(String typeWithoutFormat, String format) {
|
||||
String type;
|
||||
if(StringUtils.isNotBlank(format)){
|
||||
type = typeWithoutFormat + " (" + format + ")";
|
||||
}else{
|
||||
type = typeWithoutFormat;
|
||||
}
|
||||
return type;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package io.github.robwin.swagger2markup.utils;
|
||||
|
||||
import com.wordnik.swagger.models.properties.ArrayProperty;
|
||||
import com.wordnik.swagger.models.properties.Property;
|
||||
import com.wordnik.swagger.models.properties.RefProperty;
|
||||
import com.wordnik.swagger.models.properties.StringProperty;
|
||||
import io.github.robwin.markup.builder.MarkupLanguage;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang.Validate;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public final class PropertyUtils {
|
||||
|
||||
public static String getType(Property property, MarkupLanguage markupLanguage){
|
||||
Validate.notNull(property, "property must not be null!");
|
||||
String type;
|
||||
if(property instanceof RefProperty){
|
||||
RefProperty refProperty = (RefProperty)property;
|
||||
switch (markupLanguage){
|
||||
case ASCIIDOC: return "<<" + refProperty.getSimpleRef() + ">>";
|
||||
default: return refProperty.getSimpleRef();
|
||||
}
|
||||
}else if(property instanceof ArrayProperty){
|
||||
ArrayProperty arrayProperty = (ArrayProperty)property;
|
||||
Property items = arrayProperty.getItems();
|
||||
type = getType(items, markupLanguage) + " " + arrayProperty.getType();
|
||||
}else if(property instanceof StringProperty){
|
||||
StringProperty stringProperty = (StringProperty)property;
|
||||
List<String> enums = stringProperty.getEnum();
|
||||
if(CollectionUtils.isNotEmpty(enums)){
|
||||
type = "enum" + " (" + StringUtils.join(enums, ", ") + ")";
|
||||
}else{
|
||||
type = property.getType();
|
||||
}
|
||||
}
|
||||
else{
|
||||
if(StringUtils.isNotBlank(property.getFormat())){
|
||||
type = property.getType() + " (" + property.getFormat() + ")";
|
||||
}else{
|
||||
type = property.getType();
|
||||
}
|
||||
}
|
||||
return type;
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration scan="true">
|
||||
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="DEBUG">
|
||||
<appender-ref ref="CONSOLE" />
|
||||
</root>
|
||||
</configuration>
|
||||
@@ -1,10 +1,15 @@
|
||||
package io.github.robwin.swagger2markup;
|
||||
|
||||
import io.github.robwin.markup.builder.MarkupLanguage;
|
||||
import org.asciidoctor.*;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
@@ -12,7 +17,7 @@ import java.io.IOException;
|
||||
public class Swagger2MarkupConverterTest {
|
||||
|
||||
@Test
|
||||
public void testSwagger2AsciiDocConverter() throws IOException {
|
||||
public void testSwagger2MarkupConversion() throws IOException {
|
||||
File file = new File(Swagger2MarkupConverterTest.class.getResource("/json/swagger.json").getFile());
|
||||
|
||||
Swagger2MarkupConverter.from(file.getAbsolutePath()).
|
||||
@@ -25,4 +30,37 @@ public class Swagger2MarkupConverterTest {
|
||||
.intoFolder("src/docs/asciidoc");
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSwagger2HtmlConversion() throws IOException {
|
||||
File file = new File(Swagger2MarkupConverterTest.class.getResource("/json/swagger.json").getFile());
|
||||
String asciiDoc = Swagger2MarkupConverter.from(file.getAbsolutePath()).build().asString();
|
||||
String path = "src/docs/asciidocAsString";
|
||||
Files.createDirectories(Paths.get(path));
|
||||
try (BufferedWriter writer = Files.newBufferedWriter(Paths.get(path, "swagger.adoc"), StandardCharsets.UTF_8)){
|
||||
writer.write(asciiDoc); }
|
||||
String asciiDocAsHtml = Asciidoctor.Factory.create().convert(asciiDoc,
|
||||
OptionsBuilder.options().backend("html5").headerFooter(true).safe(SafeMode.UNSAFE).docType("book").attributes(AttributesBuilder.attributes()
|
||||
.tableOfContents(true).tableOfContents(Placement.LEFT).sectionNumbers(true).hardbreaks(true).setAnchors(true).attribute("sectlinks")));
|
||||
try (BufferedWriter writer = Files.newBufferedWriter(Paths.get(path, "swagger.html"), StandardCharsets.UTF_8)){
|
||||
writer.write(asciiDocAsHtml);
|
||||
}
|
||||
}
|
||||
/*
|
||||
@Test
|
||||
public void testSwagger2PdfConversion() throws IOException {
|
||||
File file = new File(Swagger2MarkupConverterTest.class.getResource("/json/spica.json").getFile());
|
||||
String asciiDoc = Swagger2MarkupConverter.from(file.getAbsolutePath()).build().asString();
|
||||
String path = "src/docs/asciidocAsString";
|
||||
Files.createDirectories(Paths.get(path));
|
||||
try (BufferedWriter writer = Files.newBufferedWriter(Paths.get(path, "spica.adoc"), StandardCharsets.UTF_8)){
|
||||
writer.write(asciiDoc);
|
||||
}
|
||||
String asciiDocAsPdf= Asciidoctor.Factory.create().convert(asciiDoc, OptionsBuilder.options().backend("pdf"));
|
||||
try (BufferedWriter writer = Files.newBufferedWriter(Paths.get(path, "spica.pdf"), StandardCharsets.UTF_8)){
|
||||
writer.write(asciiDocAsPdf);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||