Compare commits
127 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f21fce7730 | ||
|
|
c426c7b341 | ||
|
|
1231d1e0c2 | ||
|
|
66073aebb8 | ||
|
|
882d9e5709 | ||
|
|
ba9ec45d9e | ||
|
|
f2787a41ae | ||
|
|
3469523225 | ||
|
|
1dc9a07cb9 | ||
|
|
a34807e5c9 | ||
|
|
85ef33a720 | ||
|
|
3163c077a1 | ||
|
|
fbb446875d | ||
|
|
e8cdcabffe | ||
|
|
832813d40a | ||
|
|
e2f28bca7d | ||
|
|
3ed894688c | ||
|
|
bb7422d755 | ||
|
|
b2f3f4a6c7 | ||
|
|
f21794a253 | ||
|
|
ffa96e56a5 | ||
|
|
38e50dfe77 | ||
|
|
1d3ec2d5a3 | ||
|
|
495751433b | ||
|
|
de7d73eae9 | ||
|
|
f825cf9613 | ||
|
|
6e32056c26 | ||
|
|
85bc2aa8f9 | ||
|
|
d56de83368 | ||
|
|
065e65a31c | ||
|
|
a68980bc76 | ||
|
|
90880a00f3 | ||
|
|
675dd762a8 | ||
|
|
7cdd436b10 | ||
|
|
a78126c551 | ||
|
|
f729bf15c3 | ||
|
|
ce129703f8 | ||
|
|
c99bba90a4 | ||
|
|
914a8ed5fb | ||
|
|
85b95c189e | ||
|
|
8722bdc8cb | ||
|
|
2ce724cdd0 | ||
|
|
922b6b8534 | ||
|
|
a05f4b2e29 | ||
|
|
e4e32f3f9f | ||
|
|
bf0b864c0d | ||
|
|
4948c8bea1 | ||
|
|
9397bf4255 | ||
|
|
a6d85d7b0c | ||
|
|
16371443e8 | ||
|
|
5738d86988 | ||
|
|
e1bf3fbe94 | ||
|
|
7ce98408f4 | ||
|
|
1a7b219c40 | ||
|
|
8a8e93f3ca | ||
|
|
1d95d9afc2 | ||
|
|
5b49187cb7 | ||
|
|
7b99565636 | ||
|
|
32980d1476 | ||
|
|
490a6d974f | ||
|
|
4e971817a2 | ||
|
|
f649553727 | ||
|
|
3576a80872 | ||
|
|
2bbb9ffd8e | ||
|
|
7d2acae537 | ||
|
|
1e68587097 | ||
|
|
71d77ce6ab | ||
|
|
de849b69d4 | ||
|
|
a8e84995ea | ||
|
|
edffd47067 | ||
|
|
cef474955e | ||
|
|
00dffe7b57 | ||
|
|
fea79bd4f9 | ||
|
|
fb5d30f700 | ||
|
|
ab15b393d0 | ||
|
|
7d1cf12c48 | ||
|
|
14d8acc385 | ||
|
|
e91d639d93 | ||
|
|
3671873349 | ||
|
|
f920a3e954 | ||
|
|
cb35f1f319 | ||
|
|
c8805f5018 | ||
|
|
cc04be6790 | ||
|
|
13eb453c2a | ||
|
|
d20dfa9027 | ||
|
|
38429152f2 | ||
|
|
cf382e9890 | ||
|
|
81b1846fcd | ||
|
|
7d48a65ec1 | ||
|
|
dc50cdff15 | ||
|
|
165e615698 | ||
|
|
2559bef4ce | ||
|
|
7847a74104 | ||
|
|
685596c213 | ||
|
|
20862d3ee4 | ||
|
|
2527792b58 | ||
|
|
d85d307e30 | ||
|
|
58e01e96e1 | ||
|
|
1b425b83b6 | ||
|
|
96d7195365 | ||
|
|
e14af63a4c | ||
|
|
925f1a1f81 | ||
|
|
1e5e2b20dd | ||
|
|
d209718987 | ||
|
|
31619b26c9 | ||
|
|
2277c7410b | ||
|
|
90d8b088d2 | ||
|
|
a5d9588a7d | ||
|
|
ff17b1d857 | ||
|
|
2a5bd83bb8 | ||
|
|
aa7800ba37 | ||
|
|
8a1a1a9d91 | ||
|
|
e7b59f8a2f | ||
|
|
8e75655346 | ||
|
|
e45498a1d7 | ||
|
|
5f838ca2b4 | ||
|
|
85e53ce89f | ||
|
|
51c1cd3fe5 | ||
|
|
29c7db1980 | ||
|
|
663323cd1e | ||
|
|
ab13a6ec0e | ||
|
|
d78eb490cb | ||
|
|
48e724cb4b | ||
|
|
0a3db6c013 | ||
|
|
a843fad921 | ||
|
|
de41e3b058 | ||
|
|
6bf3a5aab4 |
10
.travis.yml
10
.travis.yml
@@ -4,4 +4,12 @@ jdk:
|
||||
before_install:
|
||||
- chmod +x gradlew
|
||||
after_success:
|
||||
- ./gradlew jacocoTestReport coveralls
|
||||
- ./gradlew jacocoTestReport coveralls
|
||||
notifications:
|
||||
webhooks:
|
||||
urls:
|
||||
- https://webhooks.gitter.im/e/9c620e84679284b7d621
|
||||
on_success: change # options: [always|never|change] default: always
|
||||
on_failure: always # options: [always|never|change] default: always
|
||||
on_start: false # default: false
|
||||
Your unique webhook url for this service:
|
||||
|
||||
295
README.adoc
295
README.adoc
@@ -1,296 +1,53 @@
|
||||
= Swagger2Markup
|
||||
:author: Robert Winkler
|
||||
:version: 0.4.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"]
|
||||
image:https://travis-ci.org/Swagger2Markup/swagger2markup.svg?branch=master["Build Status", link="https://travis-ci.org/Swagger2Markup/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://img.shields.io/badge/Twitter-rbrtwnklr-blue.svg["Twitter", link="https://twitter.com/rbrtwnklr"] 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
|
||||
|
||||
The primary goal of this project is to simplify the documentation of a RESTful API by combining documentation that's been hand-written with auto-generated API documentation produced by https://github.com/swagger-api[Swagger]. The result is intended to be an easy-to-read, on- and offline user guide, comparable to https://developer.github.com/v3/[GitHub's API documentation].
|
||||
The primary goal of this project is to *simplify the generation of an up-to-date RESTful API documentation by combining documentation that's been hand-written with auto-generated API documentation* produced by https://github.com/swagger-api[Swagger]. The result is intended to be an *up-to-date, easy-to-read, on- and offline user guide*, comparable to https://developer.github.com/v3/[GitHub's API documentation]. The output of Swagger2Markup can be used as an alternative to https://github.com/swagger-api/swagger-ui[swagger-ui] and can be served as static content.
|
||||
|
||||
This project is a Swagger to Markup (AsciiDoc and GitHub Flavored Markdown) converter. The *Swagger2MarkupConverter* takes a swagger.json or swagger.yaml file as source and converts it into three documents (Overview, Paths and Definitions) which can be combined with hand-written documentation. The Swagger source file can be located locally or remotely 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].
|
||||
Swagger2Markup converts a Swagger JSON or YAML file into several *AsciiDoc* or *GitHub Flavored Markdown* documents which can be combined with hand-written documentation. The Swagger source file can be located locally or remotely via HTTP. Swagger2Markup supports the Swagger 1.2 and 2.0 specification. Internally it uses the _official_ https://github.com/swagger-api/swagger-parser[swagger-parser] and my https://github.com/RobWin/markup-document-builder[markup-document-builder].
|
||||
|
||||
http://asciidoctor.org/docs/asciidoc-writers-guide/[AsciiDoc] is a text document format for writing documentation, articles, books, ebooks, slideshows, web pages and blogs. AsciiDoc files can be converted to many formats including HTML, PDF and EPUB. You write an AsciiDoc document the same way you would write a normal text document.
|
||||
You can use Swagger2Markup to convert your contract-first Swagger YAML file into a human-readable format and combine it with hand-written documentation. As an alternative, you can choose the code-first approach and use Swagger2Markup together with https://github.com/swagger-api/swagger-core/wiki/Swagger-Core-JAX-RS-Project-Setup-1.5.X[Swagger JAX-RS], https://github.com/springfox/springfox[springfox] or https://github.com/spring-projects/spring-restdocs[spring-restdocs]. If you are are Gradle or Maven user, you can also use the https://github.com/RobWin/swagger2markup-gradle-plugin[Swagger2Markup Gradle Plugin] or https://github.com/redowl/swagger2markup-maven-plugin[Swagger2markup Maven Plugin].
|
||||
|
||||
You can use Swagger2Markup to convert your design-first Swagger YAML file into a human-readable format and combine it with hand-written documentation. As an alternative, you can choose the implementation-first approach and use Swagger2Markup together with https://github.com/swagger-api/swagger-core/tree/master/samples/java-jersey2[Swagger JAX-RS], https://github.com/springfox/springfox[springfox] or https://github.com/spring-projects/spring-restdocs[spring-restdocs]. See usage guide below and <<integration-with-spring-restdocs, Integration with spring-restdocs>>.
|
||||
http://asciidoctor.org/docs/asciidoc-writers-guide/[AsciiDoc] is preferable to Markdown as it has more features. AsciiDoc is a text document format for writing documentation, articles, books, ebooks, slideshows, web pages and blogs. AsciiDoc files can be converted to *HTML*, *PDF* and *EPUB*. AsciiDoc is much better suited for describing public APIs than *JavaDoc* or *Annotations*.
|
||||
|
||||
You can generate your HTML5 and PDF documentation via https://github.com/asciidoctor/asciidoctorj[asciidoctorj] or even better via the https://github.com/asciidoctor/asciidoctor-gradle-plugin[asciidoctor-gradle-plugin] or https://github.com/aalmiray/markdown-gradle-plugin[markdown-gradle-plugin]. You can also use https://github.com/jbake-org/jbake[JBake], https://github.com/tomchristie/mkdocs[MkDocs], https://github.com/rtfd/readthedocs.org[ReadTheDocs] or https://github.com/tripit/slate[slate] to publish your AsciiDoc or Markdown documentation.
|
||||
You can generate your HTML5, PDF and EPUB documentation via https://github.com/asciidoctor/asciidoctorj[asciidoctorj] or even better via the https://github.com/asciidoctor/asciidoctor-gradle-plugin[asciidoctor-gradle-plugin] or https://github.com/asciidoctor/asciidoctor-maven-plugin[asciidoctor-maven-plugin]. You can also use https://readme.io/[ReadMe.io], https://github.com/jbake-org/jbake[JBake], https://github.com/tomchristie/mkdocs[MkDocs], https://github.com/rtfd/readthedocs.org[ReadTheDocs] or https://github.com/tripit/slate[slate] to publish your AsciiDoc or Markdown documentation.
|
||||
|
||||
The project requires at least JDK 7.
|
||||
|
||||
== Usage
|
||||
== Reference documentation
|
||||
- http://swagger2markup.readme.io/[Reference Documentation]
|
||||
- https://github.com/Swagger2Markup/swagger2markup/blob/master/RELEASENOTES.adoc[Release notes]
|
||||
|
||||
=== Adding Swagger2Markup to your project
|
||||
The project is published in JCenter and Maven Central.
|
||||
== Contributing
|
||||
|
||||
==== Maven
|
||||
=== Community contributions
|
||||
|
||||
[source,xml]
|
||||
----
|
||||
<repositories>
|
||||
<repository>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
<id>central</id>
|
||||
<name>bintray</name>
|
||||
<url>http://jcenter.bintray.com</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
Pull requests are welcome.
|
||||
|
||||
<dependency>
|
||||
<groupId>io.github.robwin</groupId>
|
||||
<artifactId>swagger2markup</artifactId>
|
||||
<version>0.4.0</version>
|
||||
</dependency>
|
||||
----
|
||||
* New feature https://github.com/Swagger2Markup/swagger2markup/issues/18[RobWin/Swagger2Markup#18] by https://github.com/sg-ad[@sg-ad]: In addition to the definitions.adoc you can also generate separate files for each definition model (ex: person.adoc, address.adoc, purchase.adoc).
|
||||
|
||||
==== Gradle
|
||||
* New feature https://github.com/Swagger2Markup/swagger2markup/issues/21[RobWin/Swagger2Markup#21] by https://github.com/redowl[@redowl]: Support for both reference models and composed models.
|
||||
|
||||
[source,groovy]
|
||||
----
|
||||
repositories {
|
||||
jcenter()
|
||||
}
|
||||
=== Questions
|
||||
You can ask questions about Swagger2Markup in https://gitter.im/Swagger2Markup/swagger2markup[Gitter].
|
||||
|
||||
compile "io.github.robwin:swagger2markup:0.4.0"
|
||||
----
|
||||
=== Bugs
|
||||
If you believe you have found a bug, please take a moment to search the existing issues. If no one else has reported the problem, please open a new issue that describes the problem in detail and, ideally, includes a test that reproduces it.
|
||||
|
||||
=== Using Swagger2Markup
|
||||
=== Enhancements
|
||||
If you’d like an enhancement to be made to Swagger2Markup, pull requests are most welcome. The source code is on GitHub. You may want to search the existing issues and pull requests to see if the enhancement is already being worked on. You may also want to open a new issue to discuss a possible enhancement before work on it begins.
|
||||
|
||||
Using the Swagger2MarkupConverter is simple. For example, you can generate your AsciiDoc or Markdown documentation using https://github.com/spring-projects/spring-boot[Spring Boot] and https://github.com/springfox/springfox[springfox] during the unit or integration test phase, copy the documentation into the Jar file and serve it as static content.
|
||||
The quickest way to get started is to look at the demo project https://github.com/RobWin/spring-swagger2markup-demo[spring-swagger2markup-demo]. The demo shows how to generate static docs (HTML5 and PDF) with Swagger2Markup and serve them as static content in a Spring Boot App under http://localhost:9080/docs/index.html and http://localhost:9080/docs/index.pdf.
|
||||
== License
|
||||
|
||||
==== Integration Test
|
||||
Copyright 2015 Robert Winkler
|
||||
|
||||
Swagger2MarkupConverter can be used to make a request to a Swagger endpoint during an integration test. The Swagger2MarkupConverter writes the documents into the folder "src/docs/asciidoc".
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
|
||||
|
||||
[source,java]
|
||||
----
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(classes = Application.class)
|
||||
@IntegrationTest
|
||||
@WebAppConfiguration
|
||||
public class Swagger2MarkupTest {
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
@Test
|
||||
public void convertRemoteSwaggerToAsciiDoc() {
|
||||
//Remote Swagger source
|
||||
//Default is AsciiDoc
|
||||
Swagger2MarkupConverter.from("http://localhost:8080/v2/api-docs").build()
|
||||
.intoFolder("src/docs/asciidoc");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertRemoteSwaggerToMarkdown() {
|
||||
//Remote Swagger source
|
||||
//Markdown
|
||||
Swagger2MarkupConverter.from("http://localhost:8080/v2/api-docs").
|
||||
withMarkupLanguage(MarkupLanguage.MARKDOWN).build()
|
||||
.intoFolder("src/docs/markdown");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertLocalSwaggerToAsciiDoc() {
|
||||
//Local Swagger source
|
||||
//Default is AsciiDoc
|
||||
File file = new File(Swagger2MarkupTest.class.getResource("/json/swagger.json").getFile());
|
||||
Swagger2MarkupConverter.from(file.getAbsolutePath()).build()
|
||||
.intoFolder("src/docs/asciidoc");
|
||||
}
|
||||
}
|
||||
----
|
||||
|
||||
==== Unit Test
|
||||
|
||||
Spring's MVC Test framework can also be used to make a request to a https://github.com/springfox/springfox[springfox] Swagger endpoint during an unit test. A custom ResultHandler is used to automatically convert the Swagger JSON response into an AsciiDoc document.
|
||||
That way you verify that your Swagger endpoint is working, too. The test cycle is much faster then.
|
||||
|
||||
[source,java]
|
||||
----
|
||||
@WebAppConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = Application.class, loader = SpringApplicationContextLoader.class)
|
||||
public class Swagger2MarkupTest {
|
||||
|
||||
@Autowired
|
||||
private WebApplicationContext context;
|
||||
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertSwaggerToAsciiDoc() throws Exception {
|
||||
this.mockMvc.perform(get("/v2/api-docs")
|
||||
.accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(Swagger2MarkupDocumentation.document("swagger_adoc"))
|
||||
.andExpect(status().isOk());
|
||||
}
|
||||
}
|
||||
----
|
||||
|
||||
==== Springfox configuration
|
||||
|
||||
The following is a complete https://github.com/springfox/springfox[springfox] configuration to use Swagger in a Spring Boot Application.
|
||||
|
||||
[source,java]
|
||||
----
|
||||
@SpringBootApplication
|
||||
@EnableSwagger2
|
||||
public class Application {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Docket restApi() {
|
||||
return new Docket(DocumentationType.SWAGGER_2)
|
||||
.apiInfo(apiInfo())
|
||||
.select()
|
||||
.paths(ant("/api/**"))
|
||||
.build();
|
||||
}
|
||||
|
||||
private ApiInfo apiInfo() {
|
||||
return new ApiInfoBuilder()
|
||||
.title("Petstore API Title")
|
||||
.description("Petstore API Description")
|
||||
.contact("Petstore API Contact Email")
|
||||
.version("1.0.0")
|
||||
.build();
|
||||
}
|
||||
}
|
||||
----
|
||||
|
||||
==== Combine generated documentation with your hand-written documentation
|
||||
|
||||
The following shows how you can combine the generated documentation with your hand-written documentation with AsciiDoc.
|
||||
|
||||
image::images/generated_docs.PNG[generated_docs]
|
||||
|
||||
You can generate your HTML5 and PDF documentation via the https://github.com/asciidoctor/asciidoctor-gradle-plugin[asciidoctor-gradle-plugin]. The following shows how to configure the asciidoctor-gradle-plugin. By default it searches for AsciiDoc files in "src/docs/asciidoc" and puts the HTML and PDF output into "build/asciidoc/html5" and "build/asciidoc/pdf".
|
||||
|
||||
[source]
|
||||
----
|
||||
asciidoctor {
|
||||
sources {
|
||||
include 'index.adoc'
|
||||
}
|
||||
backends = ['html5', 'pdf']
|
||||
attributes = [
|
||||
doctype: 'book',
|
||||
toc: 'left',
|
||||
toclevels: '2',
|
||||
numbered: '',
|
||||
sectlinks: '',
|
||||
sectanchors: ''
|
||||
]
|
||||
}
|
||||
----
|
||||
|
||||
You can copy the output into your Jar file and serve the documentation as static content.
|
||||
|
||||
[source]
|
||||
----
|
||||
jar {
|
||||
dependsOn asciidoctor
|
||||
from ("${asciidoctor.outputDir}/html5") {
|
||||
into 'static/docs'
|
||||
}
|
||||
from ("${asciidoctor.outputDir}/pdf") {
|
||||
into 'static/docs'
|
||||
}
|
||||
}
|
||||
----
|
||||
|
||||
== Examples
|
||||
== Swagger source file
|
||||
image::images/swagger_json.PNG[swagger_json]
|
||||
|
||||
=== Generated AsciiDoc file
|
||||
image::images/asciidoc.PNG[asciidoc]
|
||||
|
||||
=== Generated Markdown file
|
||||
image::images/markdown.PNG[markdown]
|
||||
|
||||
=== Generated HTML using AsciidoctorJ
|
||||
image::images/asciidoc_html.PNG[asciidoc_html]
|
||||
|
||||
=== Generated PDF using AsciidoctorJ
|
||||
image::images/asciidoc_pdf.PNG[asciidoc_pdf]
|
||||
|
||||
|
||||
== Integration with spring-restdocs
|
||||
https://github.com/spring-projects/spring-restdocs[spring-restdocs] can be used together with Swagger2Markup.
|
||||
Swagger2Markup can include the generated examples from spring-restdocs into the generated AsciiDoc document.
|
||||
Currently it does not work for Markdown, since spring-restdocs generates only AsciiDoc files.
|
||||
|
||||
Let's say I have a Swagger-annotated Spring RestController method with an ApiOperation value: _"Create a quota"_
|
||||
|
||||
[source,java]
|
||||
----
|
||||
@ApiOperation(value = "Create a quota", notes = "Create a quota allows bla bla bla bla")
|
||||
public void createMailStorageQuota(@ApiParam(name = "MailStorageQuota",
|
||||
value = "MailStorageQuota", required = true) @RequestBody MailStorageQuota mailStorageQuota) {
|
||||
}
|
||||
----
|
||||
|
||||
I'm using spring-restdocs in combination with https://github.com/jayway/rest-assured to test the Controller.
|
||||
The target folder of the generated request and response example files must be _"create_a_quota"_ (similar to the value of the ApiOperation).
|
||||
|
||||
[source,java]
|
||||
----
|
||||
given().contentType(ContentType.XML).body(storageQuota).resultHandlers(document("create_a_quota")).
|
||||
when().put("/quotas").
|
||||
then().statusCode(204);
|
||||
----
|
||||
|
||||
The spring-restdocs output directory is configured as follows:
|
||||
|
||||
[source]
|
||||
----
|
||||
io.restdocumented.outputDir = docs/generated
|
||||
----
|
||||
|
||||
The Swagger2MarkupConverter must know the output directory of spring-restdocs.
|
||||
|
||||
[source,java]
|
||||
----
|
||||
Swagger2MarkupConverter.from("http://localhost:8080/api-docs").
|
||||
withExamples("docs/generated").build()
|
||||
.intoFolder("src/docs/asciidoc");
|
||||
----
|
||||
|
||||
The Swagger2MarkupConverter searches for a Swagger ApiOperation with value: _"Create a quota"_ in a folder called _"docs/generated/create_a_quota"_ and includes the _request.asciidoc_ and _response.asciidoc_ files, if they are available.
|
||||
|
||||
== Integration of JSON and XML Schema files.
|
||||
Swagger2Markup can also include JSON and XML Schema files into the generated document.
|
||||
|
||||
[source,java]
|
||||
----
|
||||
Swagger2MarkupConverter.from("http://localhost:8080/api-docs").
|
||||
withMarkupLanguage(MarkupLanguage.MARKDOWN).
|
||||
withExamples("docs/generated").withSchemas("docs/schemas").build()
|
||||
.intoFolder("src/docs/markdown");
|
||||
----
|
||||
|
||||
I create the Schemas files in Unit-Tests as follows:
|
||||
|
||||
[source,java]
|
||||
----
|
||||
RestDocumented restDocumented = RestDocumented.fromProperties();
|
||||
restDocumented.documentJsonSchema(MailStorageQuota.class, "docs/schemas");
|
||||
restDocumented.documentXmlSchema(MailStorageQuota.class, "docs/schemas");
|
||||
----
|
||||
|
||||
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]
|
||||
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
||||
|
||||
@@ -27,4 +27,40 @@
|
||||
* Updated commons-lang to commons-lang3
|
||||
* Swagger2MarkupConverter generates three documents now: overview, paths and definitions
|
||||
* Support for enums in HeaderParameter, QueryParameter, FormParameter and QueryParameter
|
||||
* Support for global consumes, produces and tags
|
||||
* Support for global consumes, produces and tags
|
||||
|
||||
== Version 0.5.0
|
||||
* Support for including hand-written descriptions instead of using Swagger Annotations for descriptions
|
||||
|
||||
=== Version 0.5.1
|
||||
* Bugfix: Definition name must be lowercase so that descriptions file can be found
|
||||
|
||||
=== Version 0.5.2
|
||||
* Swagger License is not mandatory anymore
|
||||
* Updated markup-document-builder from v0.1.3 to v0.1.4
|
||||
|
||||
=== Version 0.5.3
|
||||
* Fixed compiler warning: [options] bootstrap class path not set in conjunction with -source 1.7
|
||||
|
||||
== Version 0.6.0
|
||||
* Updated swagger-parser from v1.0.5 to v1.0.6
|
||||
* Support for default values in Parameters and Model properties
|
||||
|
||||
=== Version 0.6.1
|
||||
* Updated swagger-parser from v1.0.6 to v1.0.8
|
||||
|
||||
=== Version 0.6.2
|
||||
* curl-request.adoc from spring-restdocs is also added to the example chapters
|
||||
|
||||
=== Version 0.6.3
|
||||
* Added possibility to write object definitions to separate files. Issue #19
|
||||
|
||||
== Version 0.7.0
|
||||
* Added support for both reference models and composed models
|
||||
|
||||
=== Version 0.7.1
|
||||
* Workaround: If the type of a BodyParameter is String and not a Model, the schema is null and lost. Therefore the fallback type of a BodyParameter is String now.
|
||||
|
||||
== Version 0.8.0
|
||||
* Enhancement #26 and #27: Added a pre-process hook to modify a Swagger Model before it is converted.
|
||||
* Bugfix #29: Tags are rendered twice
|
||||
26
build.gradle
26
build.gradle
@@ -5,15 +5,15 @@ buildscript {
|
||||
}
|
||||
dependencies {
|
||||
classpath 'org.asciidoctor:asciidoctor-gradle-plugin:1.5.2'
|
||||
classpath 'org.asciidoctor:asciidoctorj-pdf:1.5.0-alpha.6'
|
||||
classpath 'io.spring.gradle:dependency-management-plugin:0.5.0.RELEASE'
|
||||
classpath 'org.asciidoctor:asciidoctorj-pdf:1.5.0-alpha.8'
|
||||
classpath 'io.spring.gradle:dependency-management-plugin:0.5.1.RELEASE'
|
||||
classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.0.1'
|
||||
classpath 'org.asciidoctor:asciidoctorj:1.5.2'
|
||||
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
|
||||
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.2'
|
||||
}
|
||||
}
|
||||
description = 'swagger2markup Build'
|
||||
version = '0.4.0'
|
||||
version = '0.8.0'
|
||||
group = 'io.github.robwin'
|
||||
|
||||
apply plugin: 'java'
|
||||
@@ -47,19 +47,20 @@ dependencies {
|
||||
compile 'org.slf4j:slf4j-api'
|
||||
testCompile 'junit:junit'
|
||||
testCompile 'org.asciidoctor:asciidoctorj:1.5.2'
|
||||
testCompile 'org.asciidoctor:asciidoctorj-pdf:1.5.0-alpha.6'
|
||||
testCompile 'ch.qos.logback:logback-classic'
|
||||
testCompile 'org.assertj:assertj-core'
|
||||
}
|
||||
|
||||
dependencyManagement {
|
||||
dependencies {
|
||||
dependency "io.github.robwin:markup-document-builder:0.1.3"
|
||||
dependency "io.swagger:swagger-compat-spec-parser:1.0.5"
|
||||
dependency "io.github.robwin:markup-document-builder:0.1.4"
|
||||
dependency "io.swagger:swagger-compat-spec-parser:1.0.8"
|
||||
dependency "commons-collections:commons-collections:3.2.1"
|
||||
dependency "commons-io:commons-io:2.4"
|
||||
dependency "junit:junit:4.11"
|
||||
dependency "org.slf4j:slf4j-api:1.7.12"
|
||||
dependency "ch.qos.logback:logback-classic:1.1.2"
|
||||
dependency "org.assertj:assertj-core:2.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,7 +79,12 @@ artifacts {
|
||||
archives javadocJar
|
||||
}
|
||||
|
||||
ext {
|
||||
generatedDocumentation = file('build/docs/asciidoc/generated')
|
||||
}
|
||||
|
||||
asciidoctor {
|
||||
dependsOn test
|
||||
sources {
|
||||
include 'index.adoc'
|
||||
}
|
||||
@@ -89,7 +95,9 @@ asciidoctor {
|
||||
toclevels: '2',
|
||||
numbered: '',
|
||||
sectlinks: '',
|
||||
sectanchors: ''
|
||||
sectanchors: '',
|
||||
hardbreaks: '',
|
||||
generated: generatedDocumentation
|
||||
]
|
||||
}
|
||||
|
||||
@@ -109,5 +117,5 @@ tasks.asciidoctor {
|
||||
}
|
||||
|
||||
task wrapper(type: Wrapper) {
|
||||
gradleVersion = '2.2.1'
|
||||
gradleVersion = '2.4'
|
||||
}
|
||||
|
||||
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
4
gradle/wrapper/gradle-wrapper.properties
vendored
4
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,6 +1,6 @@
|
||||
#Fri Feb 13 13:57:45 CET 2015
|
||||
#Mon Jun 08 08:20:09 CEST 2015
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 24 KiB |
BIN
images/handwritten_descr_asciidoc.PNG
Normal file
BIN
images/handwritten_descr_asciidoc.PNG
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 39 KiB |
BIN
images/handwritten_descriptions.PNG
Normal file
BIN
images/handwritten_descriptions.PNG
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 18 KiB |
BIN
images/springrestdocs_examples.PNG
Normal file
BIN
images/springrestdocs_examples.PNG
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 27 KiB |
5
src/docs/asciidoc/definitions/user/description.adoc
Normal file
5
src/docs/asciidoc/definitions/user/description.adoc
Normal file
@@ -0,0 +1,5 @@
|
||||
This is a hand-written description.
|
||||
AsciiDoc is better suited for descriptions than:
|
||||
|
||||
* JavaDoc
|
||||
* Annotations
|
||||
1
src/docs/asciidoc/definitions/user/id/description.adoc
Normal file
1
src/docs/asciidoc/definitions/user/id/description.adoc
Normal file
@@ -0,0 +1 @@
|
||||
This is a hand-written description. AsciiDoc is better suited for descriptions than *JavaDoc* and *Annotations*
|
||||
@@ -0,0 +1 @@
|
||||
This is a hand-written description. AsciiDoc is better suited for descriptions than *JavaDoc* and *Annotations*
|
||||
@@ -1,55 +0,0 @@
|
||||
== 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
|
||||
|===
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
= Swagger Petstore API
|
||||
|
||||
== Overview
|
||||
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 information
|
||||
Version: 1.0.0
|
||||
|
||||
=== Contact information
|
||||
Contact: apiteam@wordnik.com
|
||||
|
||||
=== License information
|
||||
License: Apache 2.0
|
||||
License URL: http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
|
||||
Terms of service: http://helloreverb.com/terms/
|
||||
|
||||
=== URI scheme
|
||||
Host: petstore.swagger.wordnik.com
|
||||
BasePath: /v2
|
||||
Schemes: HTTP
|
||||
|
||||
@@ -1,564 +0,0 @@
|
||||
== 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
|
||||
|
||||
@@ -1,13 +1,3 @@
|
||||
:doctype: book
|
||||
:toc: left
|
||||
:toclevels: 2
|
||||
:numbered:
|
||||
:sectlinks:
|
||||
:sectanchors:
|
||||
:hardbreaks:
|
||||
|
||||
include::generated/overview.adoc[]
|
||||
include::manual_content1.adoc[]
|
||||
include::manual_content2.adoc[]
|
||||
include::generated/paths.adoc[]
|
||||
include::generated/definitions.adoc[]
|
||||
include::{generated}/overview.adoc[]
|
||||
include::{generated}/paths.adoc[]
|
||||
include::{generated}/definitions.adoc[]
|
||||
@@ -1,9 +0,0 @@
|
||||
== Chapter of manual content 1
|
||||
|
||||
This is some dummy text
|
||||
|
||||
=== Sub chapter
|
||||
|
||||
Dummy text of sub chapter
|
||||
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
== Chapter of manual content 2
|
||||
|
||||
This is some dummy text
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
|
||||
[source,bash]
|
||||
----
|
||||
$ curl 'http://localhost:8080/api/pet/' -i -X POST -H 'Content-Type: application/json' -H 'Content-Length: 111' -d '{"id":1,"category":{"id":1,"name":"Hund"},"name":"Wuffy","photoUrls":[],"tags":[],"status":null,"identifier":1}'
|
||||
----
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
|
||||
[source,http]
|
||||
----
|
||||
POST /api/pet/ HTTP/1.1
|
||||
Content-Type: application/json
|
||||
Content-Length: 111
|
||||
|
||||
{"id":1,"category":{"id":1,"name":"Hund"},"name":"Wuffy","photoUrls":[],"tags":[],"status":null,"identifier":1}
|
||||
----
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
|
||||
[source,http]
|
||||
----
|
||||
HTTP/1.1 200 OK
|
||||
Content-Type: application/json
|
||||
Content-Length: 7
|
||||
|
||||
SUCCESS
|
||||
----
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
This is a hand-written description.
|
||||
AsciiDoc is better suited for descriptions than *JavaDoc* and *Annotations*
|
||||
@@ -0,0 +1,5 @@
|
||||
This is a hand-written description.
|
||||
AsciiDoc is better suited for descriptions than:
|
||||
|
||||
* JavaDoc
|
||||
* Annotations
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,646 +0,0 @@
|
||||
= Swagger Petstore API
|
||||
|
||||
== Overview
|
||||
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 information
|
||||
Version: 1.0.0
|
||||
|
||||
=== Contact information
|
||||
Contact: apiteam@wordnik.com
|
||||
|
||||
=== License information
|
||||
License: Apache 2.0
|
||||
License URL: http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
|
||||
Terms of service: http://helloreverb.com/terms/
|
||||
|
||||
=== URI scheme
|
||||
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
|
||||
|===
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
5
src/docs/markdown/definitions/user/description.md
Normal file
5
src/docs/markdown/definitions/user/description.md
Normal file
@@ -0,0 +1,5 @@
|
||||
This is a hand-written description.
|
||||
AsciiDoc is better suited for descriptions than:
|
||||
|
||||
* JavaDoc
|
||||
* Annotations
|
||||
1
src/docs/markdown/definitions/user/id/description.md
Normal file
1
src/docs/markdown/definitions/user/id/description.md
Normal file
@@ -0,0 +1 @@
|
||||
This is a hand-written description. AsciiDoc is better suited for descriptions than *JavaDoc* and *Annotations*
|
||||
@@ -0,0 +1 @@
|
||||
This is a hand-written description. AsciiDoc is better suited for descriptions than *JavaDoc* and *Annotations*
|
||||
@@ -1,50 +0,0 @@
|
||||
## 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|
|
||||
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
# Swagger Petstore API
|
||||
|
||||
## Overview
|
||||
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 information
|
||||
Version: 1.0.0
|
||||
|
||||
### Contact information
|
||||
Contact: apiteam@wordnik.com
|
||||
|
||||
### License information
|
||||
License: Apache 2.0
|
||||
License URL: http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
|
||||
Terms of service: http://helloreverb.com/terms/
|
||||
|
||||
### URI scheme
|
||||
Host: petstore.swagger.wordnik.com
|
||||
BasePath: /v2
|
||||
Schemes: HTTP
|
||||
|
||||
@@ -1,529 +0,0 @@
|
||||
## 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
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
This is a hand-written description. AsciiDoc is better suited for descriptions than *JavaDoc* and *Annotations*
|
||||
@@ -0,0 +1,5 @@
|
||||
This is a hand-written description.
|
||||
It is better suited for adding descriptions than:
|
||||
|
||||
* JavaDoc
|
||||
* Annotations
|
||||
@@ -1,15 +1,34 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2015 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*
|
||||
*/
|
||||
package io.github.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.OverviewDocument;
|
||||
import io.github.robwin.swagger2markup.builder.document.PathsDocument;
|
||||
import io.github.robwin.swagger2markup.utils.Consumer;
|
||||
import io.swagger.models.Swagger;
|
||||
import io.swagger.parser.SwaggerParser;
|
||||
import io.swagger.util.Json;
|
||||
import io.swagger.util.Yaml;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -27,6 +46,8 @@ public class Swagger2MarkupConverter {
|
||||
private final MarkupLanguage markupLanguage;
|
||||
private final String examplesFolderPath;
|
||||
private final String schemasFolderPath;
|
||||
private final String descriptionsFolderPath;
|
||||
private final boolean separatedDefinitions;
|
||||
private static final String OVERVIEW_DOCUMENT = "overview";
|
||||
private static final String PATHS_DOCUMENT = "paths";
|
||||
private static final String DEFINITIONS_DOCUMENT = "definitions";
|
||||
@@ -36,12 +57,16 @@ public class Swagger2MarkupConverter {
|
||||
* @param swagger the Swagger object
|
||||
* @param examplesFolderPath the folderPath where examples are stored
|
||||
* @param schemasFolderPath the folderPath where (XML, JSON)-Schema files are stored
|
||||
* @param descriptionsFolderPath the folderPath where descriptions are stored
|
||||
* @param separatedDefinitions create separate definition files for each model definition.
|
||||
*/
|
||||
Swagger2MarkupConverter(MarkupLanguage markupLanguage, Swagger swagger, String examplesFolderPath, String schemasFolderPath){
|
||||
Swagger2MarkupConverter(MarkupLanguage markupLanguage, Swagger swagger, String examplesFolderPath, String schemasFolderPath, String descriptionsFolderPath, boolean separatedDefinitions){
|
||||
this.markupLanguage = markupLanguage;
|
||||
this.swagger = swagger;
|
||||
this.examplesFolderPath = examplesFolderPath;
|
||||
this.schemasFolderPath = schemasFolderPath;
|
||||
this.descriptionsFolderPath = descriptionsFolderPath;
|
||||
this.separatedDefinitions = separatedDefinitions;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -71,6 +96,7 @@ public class Swagger2MarkupConverter {
|
||||
*
|
||||
* @param swagger the Swagger YAML or JSON String.
|
||||
* @return a Swagger2MarkupConverter
|
||||
* @throws java.io.IOException if String can not be parsed
|
||||
*/
|
||||
public static Builder fromString(String swagger) throws IOException {
|
||||
Validate.notEmpty(swagger, "swagger must not be null!");
|
||||
@@ -106,32 +132,33 @@ public class Swagger2MarkupConverter {
|
||||
* Builds the document with the given markup language and returns it as a String
|
||||
*
|
||||
* @return a the document as a String
|
||||
* @throws java.io.IOException if files can not be read
|
||||
*/
|
||||
public String asString() throws IOException{
|
||||
return buildDocuments();
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a file for the Paths (API) and a file for the Definitions (Model)
|
||||
* Builds all documents and writes them to a directory
|
||||
|
||||
* @param directory the directory where the generated file should be stored
|
||||
* @throws IOException if a file cannot be written
|
||||
*/
|
||||
private void buildDocuments(String directory) throws IOException {
|
||||
new OverviewDocument(swagger, markupLanguage).build().writeToFile(directory, OVERVIEW_DOCUMENT, StandardCharsets.UTF_8);
|
||||
new PathsDocument(swagger, markupLanguage, examplesFolderPath).build().writeToFile(directory, PATHS_DOCUMENT, StandardCharsets.UTF_8);
|
||||
new DefinitionsDocument(swagger, markupLanguage, schemasFolderPath).build().writeToFile(directory, DEFINITIONS_DOCUMENT, StandardCharsets.UTF_8);
|
||||
new PathsDocument(swagger, markupLanguage, examplesFolderPath, descriptionsFolderPath).build().writeToFile(directory, PATHS_DOCUMENT, StandardCharsets.UTF_8);
|
||||
new DefinitionsDocument(swagger, markupLanguage, schemasFolderPath, descriptionsFolderPath, separatedDefinitions, directory).build().writeToFile(directory, DEFINITIONS_DOCUMENT, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a file for the Paths (API) and a file for the Definitions (Model)
|
||||
* Returns all documents as a String
|
||||
|
||||
* @return a the document as a String
|
||||
*/
|
||||
private String buildDocuments() throws IOException {
|
||||
return new OverviewDocument(swagger, markupLanguage).build().toString().concat(
|
||||
new PathsDocument(swagger, markupLanguage, examplesFolderPath).build().toString()
|
||||
.concat(new DefinitionsDocument(swagger, markupLanguage, schemasFolderPath).build().toString()));
|
||||
new PathsDocument(swagger, markupLanguage, examplesFolderPath, schemasFolderPath).build().toString()
|
||||
.concat(new DefinitionsDocument(swagger, markupLanguage, schemasFolderPath, schemasFolderPath, false, null).build().toString()));
|
||||
}
|
||||
|
||||
|
||||
@@ -139,6 +166,8 @@ public class Swagger2MarkupConverter {
|
||||
private final Swagger swagger;
|
||||
private String examplesFolderPath;
|
||||
private String schemasFolderPath;
|
||||
private String descriptionsFolderPath;
|
||||
private boolean separatedDefinitions;
|
||||
private MarkupLanguage markupLanguage = MarkupLanguage.ASCIIDOC;
|
||||
|
||||
/**
|
||||
@@ -148,6 +177,9 @@ public class Swagger2MarkupConverter {
|
||||
*/
|
||||
Builder(String swaggerLocation){
|
||||
swagger = new SwaggerParser().read(swaggerLocation);
|
||||
if(swagger == null){
|
||||
throw new IllegalArgumentException("Failed to read the Swagger file. ");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -160,7 +192,7 @@ public class Swagger2MarkupConverter {
|
||||
}
|
||||
|
||||
public Swagger2MarkupConverter build(){
|
||||
return new Swagger2MarkupConverter(markupLanguage, swagger, examplesFolderPath, schemasFolderPath);
|
||||
return new Swagger2MarkupConverter(markupLanguage, swagger, examplesFolderPath, schemasFolderPath, descriptionsFolderPath, separatedDefinitions);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -174,6 +206,26 @@ public class Swagger2MarkupConverter {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Include hand-written descriptions into the Paths and Definitions document
|
||||
*
|
||||
* @param descriptionsFolderPath the path to the folder where the description documents reside
|
||||
* @return the Swagger2MarkupConverter.Builder
|
||||
*/
|
||||
public Builder withDescriptions(String descriptionsFolderPath){
|
||||
this.descriptionsFolderPath = descriptionsFolderPath;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* In addition to the definitions file, also create separate definition files for each model definition.
|
||||
* @return the Swagger2MarkupConverter.Builder
|
||||
*/
|
||||
public Builder withSeparatedDefinitions() {
|
||||
this.separatedDefinitions = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Include examples into the Paths document
|
||||
*
|
||||
@@ -196,6 +248,15 @@ public class Swagger2MarkupConverter {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Customize the Swagger data in any useful way
|
||||
* @param preProcessor function object to mutate the swagger object
|
||||
* @return the Swagger2MarkupConverter.Builder
|
||||
*/
|
||||
public Builder preProcessSwagger(Consumer<Swagger> preProcessor) {
|
||||
preProcessor.accept(this.swagger);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,23 +1,43 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2015 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*
|
||||
*/
|
||||
package io.github.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 com.google.common.collect.ImmutableMap;
|
||||
import io.github.robwin.markup.builder.MarkupDocBuilder;
|
||||
import io.github.robwin.markup.builder.MarkupDocBuilders;
|
||||
import io.swagger.models.ComposedModel;
|
||||
import io.swagger.models.Model;
|
||||
import io.swagger.models.RefModel;
|
||||
import io.swagger.models.Swagger;
|
||||
import io.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.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
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;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
@@ -25,22 +45,31 @@ import java.util.Map;
|
||||
public class DefinitionsDocument extends MarkupDocument {
|
||||
|
||||
private static final String DEFINITIONS = "Definitions";
|
||||
private static final List<String> IGNORED_DEFINITIONS = Arrays.asList("Void");
|
||||
private static final List<String> IGNORED_DEFINITIONS = Collections.singletonList("Void");
|
||||
private static final String JSON_SCHEMA = "JSON Schema";
|
||||
private static final String XML_SCHEMA = "XML Schema";
|
||||
public static final String JSON_SCHEMA_EXTENSION = ".json";
|
||||
public static final String XML_SCHEMA_EXTENSION = ".xsd";
|
||||
public static final String JSON = "json";
|
||||
public static final String XML = "xml";
|
||||
private static final String JSON_SCHEMA_EXTENSION = ".json";
|
||||
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_FILE_NAME = "description";
|
||||
private boolean schemasEnabled;
|
||||
private String schemasFolderPath;
|
||||
private String schemasFolderPath;
|
||||
private boolean handWrittenDescriptionsEnabled;
|
||||
private String descriptionsFolderPath;
|
||||
private boolean separatedDefinitionsEnabled;
|
||||
private String outputDirectory;
|
||||
|
||||
public DefinitionsDocument(Swagger swagger, MarkupLanguage markupLanguage, String schemasFolderPath){
|
||||
public DefinitionsDocument(Swagger swagger, MarkupLanguage markupLanguage, String schemasFolderPath, String descriptionsFolderPath, boolean separatedDefinitionsEnabled, String outputDirectory){
|
||||
super(swagger, markupLanguage);
|
||||
if(StringUtils.isNotBlank(schemasFolderPath)){
|
||||
this.schemasEnabled = true;
|
||||
this.schemasFolderPath = schemasFolderPath;
|
||||
}
|
||||
if(StringUtils.isNotBlank(descriptionsFolderPath)){
|
||||
this.handWrittenDescriptionsEnabled = true;
|
||||
this.descriptionsFolderPath = descriptionsFolderPath + "/" + DEFINITIONS.toLowerCase();
|
||||
}
|
||||
if(schemasEnabled){
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Include schemas is enabled.");
|
||||
@@ -50,11 +79,32 @@ public class DefinitionsDocument extends MarkupDocument {
|
||||
logger.debug("Include schemas is disabled.");
|
||||
}
|
||||
}
|
||||
if(handWrittenDescriptionsEnabled){
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Include hand-written descriptions is enabled.");
|
||||
}
|
||||
}else{
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Include hand-written descriptions is disabled.");
|
||||
}
|
||||
}
|
||||
this.separatedDefinitionsEnabled = separatedDefinitionsEnabled;
|
||||
if(this.separatedDefinitionsEnabled){
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Create separated definition files is enabled.");
|
||||
}
|
||||
Validate.notEmpty(outputDirectory, "Output directory is required for separated definition files!");
|
||||
}else{
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Create separated definition files is disabled.");
|
||||
}
|
||||
}
|
||||
this.outputDirectory = outputDirectory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocument build() throws IOException {
|
||||
definitions(swagger.getDefinitions());
|
||||
definitions(swagger.getDefinitions(), this.markupDocBuilder);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -62,16 +112,26 @@ public class DefinitionsDocument extends MarkupDocument {
|
||||
* Builds the Swagger definitions.
|
||||
*
|
||||
* @param definitions the Swagger definitions
|
||||
* @param docBuilder the doc builder to use for output
|
||||
*/
|
||||
private void definitions(Map<String, Model> definitions) throws IOException {
|
||||
private void definitions(Map<String, Model> definitions, MarkupDocBuilder docBuilder) throws IOException {
|
||||
if(MapUtils.isNotEmpty(definitions)){
|
||||
this.markupDocBuilder.sectionTitleLevel1(DEFINITIONS);
|
||||
docBuilder.sectionTitleLevel1(DEFINITIONS);
|
||||
for(Map.Entry<String, Model> definitionsEntry : definitions.entrySet()){
|
||||
String definitionName = definitionsEntry.getKey();
|
||||
if(StringUtils.isNotBlank(definitionName)) {
|
||||
if (checkThatDefinitionIsNotInIgnoreList(definitionName)) {
|
||||
definition(definitionName, definitionsEntry.getValue());
|
||||
definitionSchema(definitionName);
|
||||
definition(definitions, definitionName, definitionsEntry.getValue(), docBuilder);
|
||||
definitionSchema(definitionName, docBuilder);
|
||||
if (separatedDefinitionsEnabled) {
|
||||
MarkupDocBuilder defDocBuilder = MarkupDocBuilders.documentBuilder(markupLanguage);
|
||||
definition(definitions, definitionName, definitionsEntry.getValue(), defDocBuilder);
|
||||
definitionSchema(definitionName, defDocBuilder);
|
||||
defDocBuilder.writeToFile(outputDirectory, definitionName.toLowerCase(), StandardCharsets.UTF_8);
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Separate definition file produced: {}", definitionName);
|
||||
}
|
||||
}
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Definition processed: {}", definitionName);
|
||||
}
|
||||
@@ -100,44 +160,144 @@ public class DefinitionsDocument extends MarkupDocument {
|
||||
*
|
||||
* @param definitionName the name of the definition
|
||||
* @param model the Swagger Model of the definition
|
||||
* @param docBuilder the docbuilder do use for output
|
||||
*/
|
||||
private void definition(String definitionName, Model model) {
|
||||
this.markupDocBuilder.sectionTitleLevel2(definitionName);
|
||||
Map<String, Property> properties = model.getProperties();
|
||||
private void definition(Map<String, Model> definitions, String definitionName, Model model, MarkupDocBuilder docBuilder) throws IOException {
|
||||
docBuilder.sectionTitleLevel2(definitionName);
|
||||
descriptionSection(definitionName, model, docBuilder);
|
||||
propertiesSection(definitions, definitionName, model, docBuilder);
|
||||
}
|
||||
|
||||
private void propertiesSection(Map<String, Model> definitions, String definitionName, Model model, MarkupDocBuilder docBuilder) throws IOException {
|
||||
Map<String, Property> properties = getAllProperties(definitions, model);
|
||||
List<String> headerAndContent = new ArrayList<>();
|
||||
List<String> header = Arrays.asList(NAME_COLUMN, DESCRIPTION_COLUMN, SCHEMA_COLUMN, REQUIRED_COLUMN);
|
||||
List<String> header = Arrays.asList(NAME_COLUMN, DESCRIPTION_COLUMN, REQUIRED_COLUMN, SCHEMA_COLUMN, DEFAULT_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()));
|
||||
String propertyName = propertyEntry.getKey();
|
||||
List<String> content = Arrays.asList(
|
||||
propertyName,
|
||||
propertyDescription(definitionName, propertyName, property),
|
||||
Boolean.toString(property.getRequired()),
|
||||
PropertyUtils.getType(property, markupLanguage),
|
||||
PropertyUtils.getDefaultValue(property));
|
||||
headerAndContent.add(StringUtils.join(content, DELIMITER));
|
||||
}
|
||||
this.markupDocBuilder.tableWithHeaderRow(headerAndContent);
|
||||
docBuilder.tableWithHeaderRow(headerAndContent);
|
||||
}
|
||||
}
|
||||
|
||||
private void definitionSchema(String definitionName) throws IOException {
|
||||
private Map<String, Property> getAllProperties(Map<String, Model> definitions, Model model) {
|
||||
if(model instanceof RefModel) {
|
||||
final String ref = model.getReference();
|
||||
return definitions.containsKey(ref)
|
||||
? getAllProperties(definitions, definitions.get(model.getReference()))
|
||||
: null;
|
||||
}
|
||||
if(model instanceof ComposedModel) {
|
||||
ComposedModel composedModel = (ComposedModel)model;
|
||||
ImmutableMap.Builder<String, Property> allProperties = ImmutableMap.builder();
|
||||
if(composedModel.getAllOf() != null) {
|
||||
for(Model innerModel : composedModel.getAllOf()) {
|
||||
Map<String, Property> innerProperties = getAllProperties(definitions, innerModel);
|
||||
if(innerProperties != null) {
|
||||
allProperties.putAll(innerProperties);
|
||||
}
|
||||
}
|
||||
}
|
||||
return allProperties.build();
|
||||
}
|
||||
else {
|
||||
return model.getProperties();
|
||||
}
|
||||
}
|
||||
|
||||
private void descriptionSection(String definitionName, Model model, MarkupDocBuilder docBuilder) throws IOException {
|
||||
if(handWrittenDescriptionsEnabled){
|
||||
String description = handWrittenPathDescription(definitionName.toLowerCase(), DESCRIPTION_FILE_NAME);
|
||||
if(StringUtils.isNotBlank(description)){
|
||||
docBuilder.paragraph(description);
|
||||
}else{
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Hand-written description cannot be read. Trying to use description from Swagger source.");
|
||||
}
|
||||
modelDescription(model, docBuilder);
|
||||
}
|
||||
}
|
||||
else{
|
||||
modelDescription(model, docBuilder);
|
||||
}
|
||||
}
|
||||
|
||||
private void modelDescription(Model model, MarkupDocBuilder docBuilder) {
|
||||
String description = model.getDescription();
|
||||
if (StringUtils.isNotBlank(description)) {
|
||||
docBuilder.paragraph(description);
|
||||
}
|
||||
}
|
||||
|
||||
private String propertyDescription(String definitionName, String propertyName, Property property) throws IOException {
|
||||
String description;
|
||||
if(handWrittenDescriptionsEnabled){
|
||||
description = handWrittenPathDescription(definitionName.toLowerCase() + "/" + propertyName.toLowerCase(), DESCRIPTION_FILE_NAME);
|
||||
if(StringUtils.isBlank(description)) {
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Hand-written description file cannot be read. Trying to use description from Swagger source.");
|
||||
}
|
||||
description = StringUtils.defaultString(property.getDescription());
|
||||
}
|
||||
}
|
||||
else{
|
||||
description = StringUtils.defaultString(property.getDescription());
|
||||
}
|
||||
return description;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reads a hand-written description
|
||||
*
|
||||
* @param descriptionFolder the name of the folder where the description file resides
|
||||
* @param descriptionFileName the name of the description file
|
||||
* @return the content of the file
|
||||
* @throws IOException
|
||||
*/
|
||||
private String handWrittenPathDescription(String descriptionFolder, String descriptionFileName) throws IOException {
|
||||
for (String fileNameExtension : markupLanguage.getFileNameExtensions()) {
|
||||
java.nio.file.Path path = Paths.get(descriptionsFolderPath, descriptionFolder, descriptionFileName + fileNameExtension);
|
||||
if (Files.isReadable(path)) {
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Description file processed: {}", path);
|
||||
}
|
||||
return FileUtils.readFileToString(path.toFile(), StandardCharsets.UTF_8).trim();
|
||||
} else {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Description file is not readable: {}", path);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.info("No description file found with correct file name extension in folder: {}", Paths.get(descriptionsFolderPath, descriptionFolder));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void definitionSchema(String definitionName, MarkupDocBuilder docBuilder) throws IOException {
|
||||
if(schemasEnabled) {
|
||||
if (StringUtils.isNotBlank(definitionName)) {
|
||||
schema(JSON_SCHEMA, schemasFolderPath, definitionName + JSON_SCHEMA_EXTENSION, JSON);
|
||||
schema(XML_SCHEMA, schemasFolderPath, definitionName + XML_SCHEMA_EXTENSION, XML);
|
||||
schema(JSON_SCHEMA, schemasFolderPath, definitionName + JSON_SCHEMA_EXTENSION, JSON, docBuilder);
|
||||
schema(XML_SCHEMA, schemasFolderPath, definitionName + XML_SCHEMA_EXTENSION, XML, docBuilder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void schema(String title, String schemasFolderPath, String schemaName, String language) throws IOException {
|
||||
private void schema(String title, String schemasFolderPath, String schemaName, String language, MarkupDocBuilder docBuilder) throws IOException {
|
||||
java.nio.file.Path path = Paths.get(schemasFolderPath, schemaName);
|
||||
if (Files.isReadable(path)) {
|
||||
this.markupDocBuilder.sectionTitleLevel3(title);
|
||||
this.markupDocBuilder.source(FileUtils.readFileToString(path.toFile(), StandardCharsets.UTF_8).trim(), language);
|
||||
docBuilder.sectionTitleLevel3(title);
|
||||
docBuilder.source(FileUtils.readFileToString(path.toFile(), StandardCharsets.UTF_8).trim(), language);
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Schema file processed: {}", path);
|
||||
}
|
||||
@@ -146,6 +306,5 @@ public class DefinitionsDocument extends MarkupDocument {
|
||||
logger.debug("Schema file is not readable: {}", path);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,24 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2015 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*
|
||||
*/
|
||||
package io.github.robwin.swagger2markup.builder.document;
|
||||
|
||||
import com.wordnik.swagger.models.Swagger;
|
||||
import io.swagger.models.Swagger;
|
||||
import io.github.robwin.markup.builder.MarkupDocBuilder;
|
||||
import io.github.robwin.markup.builder.MarkupDocBuilders;
|
||||
import io.github.robwin.markup.builder.MarkupLanguage;
|
||||
@@ -16,6 +34,7 @@ import java.nio.charset.Charset;
|
||||
public abstract class MarkupDocument {
|
||||
|
||||
protected static final String DELIMITER = "|";
|
||||
protected static final String DEFAULT_COLUMN = "Default";
|
||||
protected static final String REQUIRED_COLUMN = "Required";
|
||||
protected static final String SCHEMA_COLUMN = "Schema";
|
||||
protected static final String NAME_COLUMN = "Name";
|
||||
|
||||
@@ -1,6 +1,24 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2015 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*
|
||||
*/
|
||||
package io.github.robwin.swagger2markup.builder.document;
|
||||
|
||||
import com.wordnik.swagger.models.*;
|
||||
import io.swagger.models.*;
|
||||
import io.github.robwin.markup.builder.MarkupLanguage;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -72,7 +90,7 @@ public class OverviewDocument extends MarkupDocument {
|
||||
}
|
||||
|
||||
License license = info.getLicense();
|
||||
if(license != null) {
|
||||
if(license != null && (StringUtils.isNotBlank(license.getName()) || StringUtils.isNotBlank(license.getUrl()))) {
|
||||
this.markupDocBuilder.sectionTitleLevel2(LICENSE_INFORMATION);
|
||||
if (StringUtils.isNotBlank(license.getName())) {
|
||||
this.markupDocBuilder.textLine(LICENSE + license.getName());
|
||||
@@ -112,8 +130,9 @@ public class OverviewDocument extends MarkupDocument {
|
||||
String description = tag.getDescription();
|
||||
if(StringUtils.isNoneBlank(description)){
|
||||
tags.add(name + ": " + description);
|
||||
}else{
|
||||
tags.add(name);
|
||||
}
|
||||
tags.add(name);
|
||||
}
|
||||
this.markupDocBuilder.unorderedList(tags);
|
||||
this.markupDocBuilder.newLine();
|
||||
|
||||
@@ -1,11 +1,29 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2015 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*
|
||||
*/
|
||||
package io.github.robwin.swagger2markup.builder.document;
|
||||
|
||||
import com.wordnik.swagger.models.Operation;
|
||||
import com.wordnik.swagger.models.Path;
|
||||
import com.wordnik.swagger.models.Response;
|
||||
import com.wordnik.swagger.models.Swagger;
|
||||
import com.wordnik.swagger.models.parameters.Parameter;
|
||||
import com.wordnik.swagger.models.properties.Property;
|
||||
import io.swagger.models.Operation;
|
||||
import io.swagger.models.Path;
|
||||
import io.swagger.models.Response;
|
||||
import io.swagger.models.Swagger;
|
||||
import io.swagger.models.parameters.Parameter;
|
||||
import io.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;
|
||||
@@ -31,24 +49,33 @@ public class PathsDocument extends MarkupDocument {
|
||||
|
||||
private static final String PATHS = "Paths";
|
||||
private static final String PARAMETERS = "Parameters";
|
||||
|
||||
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 EXAMPLE_CURL = "Example CURL request";
|
||||
private static final String EXAMPLE_REQUEST = "Example HTTP request";
|
||||
private static final String EXAMPLE_RESPONSE = "Example HTTP response";
|
||||
private static final String TYPE_COLUMN = "Type";
|
||||
private static final String HTTP_CODE_COLUMN = "HTTP Code";
|
||||
private static final String REQUEST_EXAMPLE_FILE_NAME = "http-request";
|
||||
private static final String RESPONSE_EXAMPLE_FILE_NAME = "http-response";
|
||||
private static final String CURL_EXAMPLE_FILE_NAME = "curl-request";
|
||||
private static final String DESCRIPTION_FILE_NAME = "description";
|
||||
private static final String PARAMETER = "Parameter";
|
||||
|
||||
private boolean examplesEnabled;
|
||||
private String examplesFolderPath;
|
||||
private boolean handWrittenDescriptionsEnabled;
|
||||
private String descriptionsFolderPath;
|
||||
|
||||
public PathsDocument(Swagger swagger, MarkupLanguage markupLanguage, String examplesFolderPath){
|
||||
public PathsDocument(Swagger swagger, MarkupLanguage markupLanguage, String examplesFolderPath, String descriptionsFolderPath){
|
||||
super(swagger, markupLanguage);
|
||||
if(StringUtils.isNotBlank(examplesFolderPath)){
|
||||
this.examplesEnabled = true;
|
||||
this.examplesFolderPath = examplesFolderPath;
|
||||
}
|
||||
if(StringUtils.isNotBlank(descriptionsFolderPath)){
|
||||
this.handWrittenDescriptionsEnabled = true;
|
||||
this.descriptionsFolderPath = descriptionsFolderPath + "/" + PATHS.toLowerCase();
|
||||
}
|
||||
if(examplesEnabled){
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Include examples is enabled.");
|
||||
@@ -58,6 +85,15 @@ public class PathsDocument extends MarkupDocument {
|
||||
logger.debug("Include examples is disabled.");
|
||||
}
|
||||
}
|
||||
if(handWrittenDescriptionsEnabled){
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Include hand-written descriptions is enabled.");
|
||||
}
|
||||
}else{
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Include hand-written descriptions is disabled.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -122,26 +158,57 @@ public class PathsDocument extends MarkupDocument {
|
||||
}
|
||||
}
|
||||
|
||||
private void descriptionSection(Operation operation) {
|
||||
private void descriptionSection(Operation operation) throws IOException {
|
||||
if(handWrittenDescriptionsEnabled){
|
||||
String summary = operation.getSummary();
|
||||
if(StringUtils.isNotBlank(summary)) {
|
||||
String operationFolder = summary.replace(".", "").replace(" ", "_").toLowerCase();
|
||||
String description = handWrittenPathDescription(operationFolder, DESCRIPTION_FILE_NAME);
|
||||
if(StringUtils.isNotBlank(description)){
|
||||
this.markupDocBuilder.sectionTitleLevel3(DESCRIPTION);
|
||||
this.markupDocBuilder.paragraph(description);
|
||||
}else{
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Hand-written description cannot be read. Trying to use description from Swagger source.");
|
||||
}
|
||||
pathDescription(operation);
|
||||
}
|
||||
}else{
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Hand-written description cannot be read, because summary of operation is empty. Trying to use description from Swagger source.");
|
||||
}
|
||||
pathDescription(operation);
|
||||
}
|
||||
}else {
|
||||
pathDescription(operation);
|
||||
}
|
||||
}
|
||||
|
||||
private void pathDescription(Operation operation) {
|
||||
String description = operation.getDescription();
|
||||
if(StringUtils.isNotBlank(description)){
|
||||
if (StringUtils.isNotBlank(description)) {
|
||||
this.markupDocBuilder.sectionTitleLevel3(DESCRIPTION);
|
||||
this.markupDocBuilder.paragraph(description);
|
||||
}
|
||||
}
|
||||
|
||||
private void parametersSection(Operation operation) {
|
||||
private void parametersSection(Operation operation) throws IOException {
|
||||
List<Parameter> parameters = operation.getParameters();
|
||||
if(CollectionUtils.isNotEmpty(parameters)){
|
||||
List<String> headerAndContent = new ArrayList<>();
|
||||
// Table header row
|
||||
List<String> header = Arrays.asList(TYPE_COLUMN, NAME_COLUMN, DESCRIPTION_COLUMN, REQUIRED_COLUMN, SCHEMA_COLUMN);
|
||||
List<String> header = Arrays.asList(TYPE_COLUMN, NAME_COLUMN, DESCRIPTION_COLUMN, REQUIRED_COLUMN, SCHEMA_COLUMN, DEFAULT_COLUMN);
|
||||
headerAndContent.add(StringUtils.join(header, DELIMITER));
|
||||
for(Parameter parameter : parameters){
|
||||
String type = ParameterUtils.getType(parameter, markupLanguage);
|
||||
String parameterType = WordUtils.capitalize(parameter.getIn() + "Parameter");
|
||||
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);
|
||||
List<String> content = Arrays.asList(
|
||||
parameterType,
|
||||
parameter.getName(),
|
||||
parameterDescription(operation, parameter),
|
||||
Boolean.toString(parameter.getRequired()), type,
|
||||
ParameterUtils.getDefaultValue(parameter));
|
||||
headerAndContent.add(StringUtils.join(content, DELIMITER));
|
||||
}
|
||||
this.markupDocBuilder.sectionTitleLevel3(PARAMETERS);
|
||||
@@ -149,6 +216,32 @@ public class PathsDocument extends MarkupDocument {
|
||||
}
|
||||
}
|
||||
|
||||
private String parameterDescription(Operation operation, Parameter parameter) throws IOException {
|
||||
String description;
|
||||
if(handWrittenDescriptionsEnabled){
|
||||
String summary = operation.getSummary();
|
||||
String operationFolder = summary.replace(".", "").replace(" ", "_").toLowerCase();
|
||||
String parameterName = parameter.getName();
|
||||
if(StringUtils.isNotBlank(operationFolder) && StringUtils.isNotBlank(parameterName)) {
|
||||
description = handWrittenPathDescription(operationFolder + "/" + parameterName, DESCRIPTION_FILE_NAME);
|
||||
if(StringUtils.isBlank(description)) {
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Hand-written description file cannot be read. Trying to use description from Swagger source.");
|
||||
}
|
||||
description = StringUtils.defaultString(parameter.getDescription());
|
||||
}
|
||||
}else{
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Hand-written description file cannot be read, because summary of operation or name of parameter is empty. Trying to use description from Swagger source.");
|
||||
}
|
||||
description = StringUtils.defaultString(parameter.getDescription());
|
||||
}
|
||||
}else {
|
||||
description = StringUtils.defaultString(parameter.getDescription());
|
||||
}
|
||||
return description;
|
||||
}
|
||||
|
||||
private void consumesSection(Operation operation) {
|
||||
List<String> consumes = operation.getConsumes();
|
||||
if(CollectionUtils.isNotEmpty(consumes)){
|
||||
@@ -185,36 +278,84 @@ public class PathsDocument extends MarkupDocument {
|
||||
String summary = operation.getSummary();
|
||||
if(StringUtils.isNotBlank(summary)) {
|
||||
String exampleFolder = summary.replace(".", "").replace(" ", "_").toLowerCase();
|
||||
example(EXAMPLE_REQUEST, exampleFolder, REQUEST_EXAMPLE_FILE_NAME);
|
||||
example(EXAMPLE_RESPONSE, exampleFolder, RESPONSE_EXAMPLE_FILE_NAME);
|
||||
String curlExample = example(exampleFolder, CURL_EXAMPLE_FILE_NAME);
|
||||
if(StringUtils.isNotBlank(curlExample)){
|
||||
this.markupDocBuilder.sectionTitleLevel3(EXAMPLE_CURL);
|
||||
this.markupDocBuilder.paragraph(curlExample);
|
||||
}
|
||||
|
||||
String requestExample = example(exampleFolder, REQUEST_EXAMPLE_FILE_NAME);
|
||||
if(StringUtils.isNotBlank(requestExample)){
|
||||
this.markupDocBuilder.sectionTitleLevel3(EXAMPLE_REQUEST);
|
||||
this.markupDocBuilder.paragraph(requestExample);
|
||||
}
|
||||
String responseExample = example(exampleFolder, RESPONSE_EXAMPLE_FILE_NAME);
|
||||
if(StringUtils.isNotBlank(responseExample)){
|
||||
this.markupDocBuilder.sectionTitleLevel3(EXAMPLE_RESPONSE);
|
||||
this.markupDocBuilder.paragraph(responseExample);
|
||||
}
|
||||
}else{
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("Example file cannot be read, because summary of operation is empty.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a concrete example
|
||||
* Reads an example
|
||||
*
|
||||
* @param title the title of the example
|
||||
* @param exampleFolder the name of the folder where the example file resides
|
||||
* @param exampleFileName the name of the example file
|
||||
* @return the content of the file
|
||||
* @throws IOException
|
||||
*/
|
||||
private void example(String title, String exampleFolder, String exampleFileName) throws IOException {
|
||||
private String example(String exampleFolder, String exampleFileName) throws IOException {
|
||||
for (String fileNameExtension : markupLanguage.getFileNameExtensions()) {
|
||||
java.nio.file.Path path = Paths.get(examplesFolderPath, exampleFolder, exampleFileName + fileNameExtension);
|
||||
if (Files.isReadable(path)) {
|
||||
this.markupDocBuilder.sectionTitleLevel3(title);
|
||||
this.markupDocBuilder.paragraph(FileUtils.readFileToString(path.toFile(), StandardCharsets.UTF_8).trim());
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Example file processed: {}", path);
|
||||
}
|
||||
break;
|
||||
return FileUtils.readFileToString(path.toFile(), StandardCharsets.UTF_8).trim();
|
||||
} else {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Example file is not readable: {}", path);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.info("No example file found with correct file name extension in folder: {}", Paths.get(examplesFolderPath, exampleFolder));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a hand-written description
|
||||
*
|
||||
* @param descriptionFolder the name of the folder where the description file resides
|
||||
* @param descriptionFileName the name of the description file
|
||||
* @return the content of the file
|
||||
* @throws IOException
|
||||
*/
|
||||
private String handWrittenPathDescription(String descriptionFolder, String descriptionFileName) throws IOException {
|
||||
for (String fileNameExtension : markupLanguage.getFileNameExtensions()) {
|
||||
java.nio.file.Path path = Paths.get(descriptionsFolderPath, descriptionFolder, descriptionFileName + fileNameExtension);
|
||||
if (Files.isReadable(path)) {
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Description file processed: {}", path);
|
||||
}
|
||||
return FileUtils.readFileToString(path.toFile(), StandardCharsets.UTF_8).trim();
|
||||
} else {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Description file is not readable: {}", path);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.info("No description file found with correct file name extension in folder: {}", Paths.get(descriptionsFolderPath, descriptionFolder));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void responsesSection(Operation operation) {
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package io.github.robwin.swagger2markup.utils;
|
||||
|
||||
/**
|
||||
* Java 8 style Consumer functional interface
|
||||
*/
|
||||
public interface Consumer<T> {
|
||||
|
||||
/**
|
||||
* The function itself
|
||||
* @param t the function argument
|
||||
*/
|
||||
void accept(T t);
|
||||
|
||||
}
|
||||
@@ -1,9 +1,27 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2015 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*
|
||||
*/
|
||||
package io.github.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.swagger.models.ArrayModel;
|
||||
import io.swagger.models.Model;
|
||||
import io.swagger.models.ModelImpl;
|
||||
import io.swagger.models.RefModel;
|
||||
import io.github.robwin.markup.builder.MarkupLanguage;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
|
||||
@@ -1,7 +1,28 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2015 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*
|
||||
*/
|
||||
package io.github.robwin.swagger2markup.utils;
|
||||
|
||||
import com.wordnik.swagger.models.Model;
|
||||
import com.wordnik.swagger.models.parameters.*;
|
||||
import io.swagger.models.Model;
|
||||
import io.swagger.models.parameters.AbstractSerializableParameter;
|
||||
import io.swagger.models.parameters.BodyParameter;
|
||||
import io.swagger.models.parameters.Parameter;
|
||||
import io.swagger.models.parameters.RefParameter;
|
||||
import io.github.robwin.markup.builder.MarkupLanguage;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -18,62 +39,24 @@ public final class ParameterUtils {
|
||||
if(parameter instanceof BodyParameter){
|
||||
BodyParameter bodyParameter = (BodyParameter)parameter;
|
||||
Model model = bodyParameter.getSchema();
|
||||
type = ModelUtils.getType(model, markupLanguage);
|
||||
if(model != null){
|
||||
type = ModelUtils.getType(model, markupLanguage);
|
||||
}else{
|
||||
type = "string";
|
||||
}
|
||||
|
||||
}
|
||||
else if(parameter instanceof PathParameter){
|
||||
PathParameter pathParameter = (PathParameter)parameter;
|
||||
type = getTypeWithFormat(pathParameter.getType(), pathParameter.getFormat());
|
||||
}
|
||||
else if(parameter instanceof QueryParameter){
|
||||
QueryParameter queryParameter = (QueryParameter)parameter;
|
||||
List<String> enums = queryParameter.getEnum();
|
||||
else if(parameter instanceof AbstractSerializableParameter){
|
||||
AbstractSerializableParameter serializableParameter = (AbstractSerializableParameter)parameter;
|
||||
List enums = serializableParameter.getEnum();
|
||||
if(CollectionUtils.isNotEmpty(enums)){
|
||||
type = "enum" + " (" + StringUtils.join(enums, ", ") + ")";
|
||||
}else{
|
||||
type = getTypeWithFormat(queryParameter.getType(), queryParameter.getFormat());
|
||||
type = getTypeWithFormat(serializableParameter.getType(), serializableParameter.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;
|
||||
List<String> enums = headerParameter.getEnum();
|
||||
if(CollectionUtils.isNotEmpty(enums)){
|
||||
type = "enum" + " (" + StringUtils.join(enums, ", ") + ")";
|
||||
}else{
|
||||
type = getTypeWithFormat(headerParameter.getType(), headerParameter.getFormat());
|
||||
}
|
||||
if(type.equals("array")){
|
||||
String collectionFormat = headerParameter.getCollectionFormat();
|
||||
type = collectionFormat + " " + PropertyUtils.getType(headerParameter.getItems(), markupLanguage) + " " + type;
|
||||
}
|
||||
}
|
||||
else if(parameter instanceof FormParameter){
|
||||
FormParameter formParameter = (FormParameter)parameter;
|
||||
List<String> enums = formParameter.getEnum();
|
||||
if(CollectionUtils.isNotEmpty(enums)){
|
||||
type = "enum" + " (" + StringUtils.join(enums, ", ") + ")";
|
||||
}else{
|
||||
type = getTypeWithFormat(formParameter.getType(), formParameter.getFormat());
|
||||
}
|
||||
if(type.equals("array")){
|
||||
String collectionFormat = formParameter.getCollectionFormat();
|
||||
type = collectionFormat + " " + PropertyUtils.getType(formParameter.getItems(), markupLanguage) + " " + type;
|
||||
}
|
||||
}
|
||||
else if(parameter instanceof CookieParameter){
|
||||
CookieParameter cookieParameter = (CookieParameter)parameter;
|
||||
List<String> enums = cookieParameter.getEnum();
|
||||
if(CollectionUtils.isNotEmpty(enums)){
|
||||
type = "enum" + " (" + StringUtils.join(enums, ", ") + ")";
|
||||
}else{
|
||||
type = getTypeWithFormat(cookieParameter.getType(), cookieParameter.getFormat());
|
||||
}
|
||||
if(type.equals("array")){
|
||||
String collectionFormat = cookieParameter.getCollectionFormat();
|
||||
type = collectionFormat + " " + PropertyUtils.getType(cookieParameter.getItems(), markupLanguage) + " " + type;
|
||||
String collectionFormat = serializableParameter.getCollectionFormat();
|
||||
type = collectionFormat + " " + PropertyUtils.getType(serializableParameter.getItems(), markupLanguage) + " " + type;
|
||||
}
|
||||
}
|
||||
else if(parameter instanceof RefParameter){
|
||||
@@ -83,16 +66,27 @@ public final class ParameterUtils {
|
||||
default: return refParameter.getSimpleRef();
|
||||
}
|
||||
}
|
||||
return type;
|
||||
return StringUtils.defaultString(type);
|
||||
}
|
||||
|
||||
private static String getTypeWithFormat(String typeWithoutFormat, String format) {
|
||||
String type;
|
||||
if(StringUtils.isNotBlank(format)){
|
||||
type = typeWithoutFormat + " (" + format + ")";
|
||||
type = StringUtils.defaultString(typeWithoutFormat) + " (" + format + ")";
|
||||
}else{
|
||||
type = typeWithoutFormat;
|
||||
type = StringUtils.defaultString(typeWithoutFormat);
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
public static String getDefaultValue(Parameter parameter){
|
||||
Validate.notNull(parameter, "property must not be null!");
|
||||
String defaultValue = "";
|
||||
if(parameter instanceof AbstractSerializableParameter){
|
||||
AbstractSerializableParameter serializableParameter = (AbstractSerializableParameter)parameter;
|
||||
defaultValue = serializableParameter.getDefaultValue();
|
||||
}
|
||||
return StringUtils.defaultString(defaultValue);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,15 +1,31 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2015 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*
|
||||
*/
|
||||
package io.github.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.swagger.models.properties.*;
|
||||
import io.github.robwin.markup.builder.MarkupLanguage;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public final class PropertyUtils {
|
||||
|
||||
@@ -37,11 +53,41 @@ public final class PropertyUtils {
|
||||
}
|
||||
else{
|
||||
if(StringUtils.isNotBlank(property.getFormat())){
|
||||
type = property.getType() + " (" + property.getFormat() + ")";
|
||||
type = StringUtils.defaultString(property.getType()) + " (" + property.getFormat() + ")";
|
||||
}else{
|
||||
type = property.getType();
|
||||
}
|
||||
}
|
||||
return type;
|
||||
return StringUtils.defaultString(type);
|
||||
}
|
||||
|
||||
public static String getDefaultValue(Property property){
|
||||
Validate.notNull(property, "property must not be null!");
|
||||
String defaultValue = "";
|
||||
if(property instanceof BooleanProperty){
|
||||
BooleanProperty booleanProperty = (BooleanProperty)property;
|
||||
defaultValue = Objects.toString(booleanProperty.getDefault(), "");
|
||||
}else if(property instanceof StringProperty){
|
||||
StringProperty stringProperty = (StringProperty)property;
|
||||
defaultValue = Objects.toString(stringProperty.getDefault(), "");
|
||||
}else if(property instanceof DoubleProperty){
|
||||
DoubleProperty doubleProperty = (DoubleProperty)property;
|
||||
defaultValue = Objects.toString(doubleProperty.getDefault(), "");
|
||||
}else if(property instanceof FloatProperty){
|
||||
FloatProperty floatProperty = (FloatProperty)property;
|
||||
defaultValue = Objects.toString(floatProperty.getDefault(), "");
|
||||
}else if(property instanceof IntegerProperty){
|
||||
IntegerProperty integerProperty = (IntegerProperty)property;
|
||||
defaultValue = Objects.toString(integerProperty.getDefault(), "");
|
||||
}
|
||||
else if(property instanceof LongProperty){
|
||||
LongProperty longProperty = (LongProperty)property;
|
||||
defaultValue = Objects.toString(longProperty.getDefault(), "");
|
||||
}
|
||||
else if(property instanceof UUIDProperty){
|
||||
UUIDProperty uuidProperty = (UUIDProperty)property;
|
||||
defaultValue = Objects.toString(uuidProperty.getDefault(), "");
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,45 +1,269 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2015 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*
|
||||
*/
|
||||
package io.github.robwin.swagger2markup;
|
||||
|
||||
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 org.asciidoctor.*;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
import static org.assertj.core.api.BDDAssertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public class Swagger2MarkupConverterTest {
|
||||
|
||||
@Test
|
||||
public void testSwagger2AsciiDocConversion() throws IOException {
|
||||
//Given
|
||||
File file = new File(Swagger2MarkupConverterTest.class.getResource("/json/swagger.json").getFile());
|
||||
File outputDirectory = new File("build/docs/asciidoc/generated");
|
||||
FileUtils.deleteQuietly(outputDirectory);
|
||||
|
||||
Swagger2MarkupConverter.from(file.getAbsolutePath()).
|
||||
withExamples("docs").withSchemas("docs/schemas").build()
|
||||
.intoFolder("src/docs/asciidoc/generated");
|
||||
//When
|
||||
Swagger2MarkupConverter.from(file.getAbsolutePath()).build()
|
||||
.intoFolder(outputDirectory.getAbsolutePath());
|
||||
|
||||
//Then
|
||||
String[] directories = outputDirectory.list();
|
||||
assertThat(directories).hasSize(3).containsAll(asList("definitions.adoc", "overview.adoc", "paths.adoc"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testOldSwaggerSpec2AsciiDocConversion() throws IOException {
|
||||
//Given
|
||||
File file = new File(Swagger2MarkupConverterTest.class.getResource("/json/swagger_12.json").getFile());
|
||||
File outputDirectory = new File("build/docs/asciidoc/generated");
|
||||
FileUtils.deleteQuietly(outputDirectory);
|
||||
|
||||
//When
|
||||
Swagger2MarkupConverter.from(file.getAbsolutePath()).build()
|
||||
.intoFolder(outputDirectory.getAbsolutePath());
|
||||
|
||||
//Then
|
||||
String[] directories = outputDirectory.list();
|
||||
assertThat(directories).hasSize(3).containsAll(asList("definitions.adoc", "overview.adoc", "paths.adoc"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSwagger2AsciiDocConversionWithDescriptionsAndExamples() throws IOException {
|
||||
//Given
|
||||
File file = new File(Swagger2MarkupConverterTest.class.getResource("/json/swagger.json").getFile());
|
||||
File outputDirectory = new File("build/docs/asciidoc/generated");
|
||||
FileUtils.deleteQuietly(outputDirectory);
|
||||
|
||||
//When
|
||||
Swagger2MarkupConverter.from(file.getAbsolutePath()).withDescriptions("src/docs/asciidoc")
|
||||
.withExamples("src/docs/asciidoc/paths").build()
|
||||
.intoFolder(outputDirectory.getAbsolutePath());
|
||||
|
||||
//Then
|
||||
String[] directories = outputDirectory.list();
|
||||
assertThat(directories).hasSize(3).containsAll(asList("definitions.adoc", "overview.adoc", "paths.adoc"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSwagger2MarkdownConversion() throws IOException {
|
||||
//Given
|
||||
File file = new File(Swagger2MarkupConverterTest.class.getResource("/json/swagger.json").getFile());
|
||||
File outputDirectory = new File("build/docs/markdown/generated");
|
||||
FileUtils.deleteQuietly(outputDirectory);
|
||||
|
||||
//When
|
||||
Swagger2MarkupConverter.from(file.getAbsolutePath()).
|
||||
withMarkupLanguage(MarkupLanguage.MARKDOWN).
|
||||
withExamples("docs").withSchemas("docs/schemas").build()
|
||||
.intoFolder("src/docs/markdown/generated");
|
||||
withMarkupLanguage(MarkupLanguage.MARKDOWN).build()
|
||||
.intoFolder(outputDirectory.getAbsolutePath());
|
||||
|
||||
//Then
|
||||
String[] directories = outputDirectory.list();
|
||||
assertThat(directories).hasSize(3).containsAll(asList("definitions.md", "overview.md", "paths.md"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSwagger2MarkdownConversionWithDescriptions() throws IOException {
|
||||
//Given
|
||||
File file = new File(Swagger2MarkupConverterTest.class.getResource("/json/swagger.json").getFile());
|
||||
File outputDirectory = new File("build/docs/markdown/generated");
|
||||
FileUtils.deleteQuietly(outputDirectory);
|
||||
|
||||
//When
|
||||
Swagger2MarkupConverter.from(file.getAbsolutePath()).withDescriptions("src/docs/markdown").
|
||||
withMarkupLanguage(MarkupLanguage.MARKDOWN).build()
|
||||
.intoFolder(outputDirectory.getAbsolutePath());
|
||||
|
||||
//Then
|
||||
String[] directories = outputDirectory.list();
|
||||
assertThat(directories).hasSize(3).containsAll(asList("definitions.md", "overview.md", "paths.md"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSwagger2AsciiDocConversionWithSeparatedDefinitions() throws IOException {
|
||||
//Given
|
||||
File file = new File(Swagger2MarkupConverterTest.class.getResource("/json/swagger.json").getFile());
|
||||
File outputDirectory = new File("build/docs/asciidoc/generated");
|
||||
FileUtils.deleteQuietly(outputDirectory);
|
||||
|
||||
//When
|
||||
Swagger2MarkupConverter.from(file.getAbsolutePath()).withSeparatedDefinitions().build()
|
||||
.intoFolder(outputDirectory.getAbsolutePath());
|
||||
|
||||
//Then
|
||||
String[] directories = outputDirectory.list();
|
||||
assertThat(directories).hasSize(9).containsAll(
|
||||
asList("definitions.adoc", "overview.adoc", "paths.adoc", "identified.adoc",
|
||||
"user.adoc", "category.adoc", "pet.adoc", "tag.adoc", "order.adoc"));
|
||||
assertThat(new String(Files.readAllBytes(Paths.get(outputDirectory + File.separator + "definitions.adoc"))))
|
||||
.contains(new String(Files.readAllBytes(Paths.get(outputDirectory + File.separator + "user.adoc"))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSwagger2MarkdownConversionWithSeparatedDefinitions() throws IOException {
|
||||
//Given
|
||||
File file = new File(Swagger2MarkupConverterTest.class.getResource("/json/swagger.json").getFile());
|
||||
File outputDirectory = new File("build/docs/asciidoc/generated");
|
||||
FileUtils.deleteQuietly(outputDirectory);
|
||||
|
||||
//When
|
||||
Swagger2MarkupConverter.from(file.getAbsolutePath()).withSeparatedDefinitions().
|
||||
withMarkupLanguage(MarkupLanguage.MARKDOWN).build()
|
||||
.intoFolder(outputDirectory.getAbsolutePath());
|
||||
|
||||
//Then
|
||||
String[] directories = outputDirectory.list();
|
||||
assertThat(directories).hasSize(9).containsAll(
|
||||
asList("definitions.md", "overview.md", "paths.md", "identified.md",
|
||||
"user.md", "category.md", "pet.md", "tag.md", "order.md"));
|
||||
assertThat(new String(Files.readAllBytes(Paths.get(outputDirectory + File.separator + "definitions.md"))))
|
||||
.contains(new String(Files.readAllBytes(Paths.get(outputDirectory + File.separator + "user.md"))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSwagger2MarkdownConversionHandlesComposition() throws IOException {
|
||||
//Given
|
||||
File file = new File(Swagger2MarkupConverterTest.class.getResource("/json/swagger.json").getFile());
|
||||
File outputDirectory = new File("build/docs/asciidoc/generated");
|
||||
FileUtils.deleteQuietly(outputDirectory);
|
||||
|
||||
//When
|
||||
Swagger2MarkupConverter.from(file.getAbsolutePath()).withSeparatedDefinitions().
|
||||
withMarkupLanguage(MarkupLanguage.MARKDOWN).build()
|
||||
.intoFolder(outputDirectory.getAbsolutePath());
|
||||
|
||||
// Then
|
||||
String[] directories = outputDirectory.list();
|
||||
assertThat(directories).hasSize(9).containsAll(
|
||||
asList("definitions.md", "overview.md", "paths.md", "identified.md",
|
||||
"user.md", "category.md", "pet.md", "tag.md", "order.md"));
|
||||
verifyMarkdownContainsFieldsInTables(
|
||||
outputDirectory + File.separator + "definitions.md",
|
||||
ImmutableMap.<String, Set<String>>builder()
|
||||
.put("Identified", ImmutableSet.of("id"))
|
||||
.put("User", ImmutableSet.of("id", "username", "firstName",
|
||||
"lastName", "email", "password", "phone", "userStatus"))
|
||||
.build());
|
||||
verifyMarkdownContainsFieldsInTables(
|
||||
outputDirectory + File.separator + "user.md",
|
||||
ImmutableMap.<String, Set<String>>builder()
|
||||
.put("User", ImmutableSet.of("id", "username", "firstName",
|
||||
"lastName", "email", "password", "phone", "userStatus"))
|
||||
.build()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a markdown document to search, this checks to see if the specified tables
|
||||
* have all of the expected fields listed.
|
||||
*
|
||||
* @param doc path of markdown document to inspect
|
||||
* @param fieldsByTable map of table name (header) to field names expected
|
||||
* to be found in that table.
|
||||
* @throws IOException if the markdown document could not be read
|
||||
*/
|
||||
private static void verifyMarkdownContainsFieldsInTables(String doc, Map<String, Set<String>> fieldsByTable) throws IOException {
|
||||
final List<String> lines = Files.readAllLines(Paths.get(doc), Charset.defaultCharset());
|
||||
final Map<String, Set<String>> fieldsLeftByTable = Maps.newHashMap();
|
||||
for(Map.Entry<String, Set<String>> entry : fieldsByTable.entrySet()) {
|
||||
fieldsLeftByTable.put(entry.getKey(), Sets.newHashSet(entry.getValue()));
|
||||
}
|
||||
String inTable = null;
|
||||
for(String line : lines) {
|
||||
// If we've found every field we care about, quit early
|
||||
if(fieldsLeftByTable.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Transition to a new table if we encounter a header
|
||||
final String currentHeader = getTableHeader(line);
|
||||
if(inTable == null || currentHeader != null) {
|
||||
inTable = currentHeader;
|
||||
}
|
||||
|
||||
// If we're in a table that we care about, inspect this potential table row
|
||||
if (inTable != null && fieldsLeftByTable.containsKey(inTable)){
|
||||
// If we're still in a table, read the row and check for the field name
|
||||
// NOTE: If there was at least one pipe, then there's at least 2 fields
|
||||
String[] parts = line.split("\\|");
|
||||
if(parts.length > 1) {
|
||||
final String fieldName = parts[1];
|
||||
final Set<String> fieldsLeft = fieldsLeftByTable.get(inTable);
|
||||
// Mark the field as found and if this table has no more fields to find,
|
||||
// remove it from the "fieldsLeftByTable" map to mark the table as done
|
||||
if(fieldsLeft.remove(fieldName) && fieldsLeft.isEmpty()) {
|
||||
fieldsLeftByTable.remove(inTable);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// After reading the file, if there were still types, fail
|
||||
if(!fieldsLeftByTable.isEmpty()) {
|
||||
fail(String.format("Markdown file '%s' did not contain expected fields (by table): %s",
|
||||
doc, fieldsLeftByTable));
|
||||
}
|
||||
}
|
||||
|
||||
private static String getTableHeader(String line) {
|
||||
return line.startsWith("###")
|
||||
? line.replace("###", "").trim()
|
||||
: null;
|
||||
}
|
||||
|
||||
/*
|
||||
@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/generated/asciidocAsString";
|
||||
String path = "build/docs/generated/asciidocAsString";
|
||||
Files.createDirectories(Paths.get(path));
|
||||
try (BufferedWriter writer = Files.newBufferedWriter(Paths.get(path, "swagger.adoc"), StandardCharsets.UTF_8)){
|
||||
writer.write(asciiDoc); }
|
||||
@@ -50,20 +274,5 @@ public class Swagger2MarkupConverterTest {
|
||||
writer.write(asciiDocAsHtml);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSpica2HtmlConversion() 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/generated/asciidocAsString";
|
||||
Files.createDirectories(Paths.get(path));
|
||||
try (BufferedWriter writer = Files.newBufferedWriter(Paths.get(path, "spica.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, "spica.html"), StandardCharsets.UTF_8)){
|
||||
writer.write(asciiDocAsHtml);
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
@@ -563,14 +563,16 @@
|
||||
"name": "username",
|
||||
"description": "The user name for login",
|
||||
"required": false,
|
||||
"type": "string"
|
||||
"type": "string",
|
||||
"default": "testUser"
|
||||
},
|
||||
{
|
||||
"in": "query",
|
||||
"name": "password",
|
||||
"description": "The password for login in clear text",
|
||||
"required": false,
|
||||
"type": "string"
|
||||
"type": "string",
|
||||
"default": "testPassword"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
@@ -623,7 +625,8 @@
|
||||
"name": "username",
|
||||
"description": "The name that needs to be fetched. Use user1 for testing.",
|
||||
"required": true,
|
||||
"type": "string"
|
||||
"type": "string",
|
||||
"default": "testUser"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
@@ -727,37 +730,48 @@
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
"User": {
|
||||
"Identified": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
},
|
||||
"username": {
|
||||
"type": "string"
|
||||
},
|
||||
"firstName": {
|
||||
"type": "string"
|
||||
},
|
||||
"lastName": {
|
||||
"type": "string"
|
||||
},
|
||||
"email": {
|
||||
"type": "string"
|
||||
},
|
||||
"password": {
|
||||
"type": "string"
|
||||
},
|
||||
"phone": {
|
||||
"type": "string"
|
||||
},
|
||||
"userStatus": {
|
||||
"type": "integer",
|
||||
"format": "int32",
|
||||
"description": "User Status"
|
||||
}
|
||||
}
|
||||
},
|
||||
"User": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/Identified"
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
"username": {
|
||||
"type": "string"
|
||||
},
|
||||
"firstName": {
|
||||
"type": "string"
|
||||
},
|
||||
"lastName": {
|
||||
"type": "string"
|
||||
},
|
||||
"email": {
|
||||
"type": "string"
|
||||
},
|
||||
"password": {
|
||||
"type": "string"
|
||||
},
|
||||
"phone": {
|
||||
"type": "string"
|
||||
},
|
||||
"userStatus": {
|
||||
"type": "integer",
|
||||
"format": "int32",
|
||||
"description": "User Status"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"Category": {
|
||||
"properties": {
|
||||
"id": {
|
||||
@@ -770,6 +784,7 @@
|
||||
}
|
||||
},
|
||||
"Pet": {
|
||||
"description" : "Test description",
|
||||
"required": [
|
||||
"name",
|
||||
"photoUrls"
|
||||
|
||||
54
src/test/resources/json/swagger_12.json
Normal file
54
src/test/resources/json/swagger_12.json
Normal file
@@ -0,0 +1,54 @@
|
||||
{
|
||||
"apiVersion" : "0.0.1-SNAPSHOT",
|
||||
"swaggerVersion" : "1.2",
|
||||
"basePath" : "",
|
||||
"resourcePath" : "/resource/x/v2",
|
||||
"apis" : [ {
|
||||
"path" : "/resource/x/v2",
|
||||
"operations" : [ {
|
||||
"method" : "POST",
|
||||
"nickname" : "createX",
|
||||
"type" : "string",
|
||||
"parameters" : [ {
|
||||
"type": "string",
|
||||
"description" : "The x in JSON format",
|
||||
"paramType" : "body",
|
||||
"name" : "body",
|
||||
"required" : true
|
||||
} ],
|
||||
"summary" : "Creates a x x.",
|
||||
"notes" : "If id already exists, the x is updated.",
|
||||
"responseMessages" : [ {
|
||||
"code" : 200,
|
||||
"message" : "ok"
|
||||
}, {
|
||||
"code" : 500,
|
||||
"message" : "error"
|
||||
} ],
|
||||
"consumes" : [ "application/json" ]
|
||||
} ]
|
||||
}, {
|
||||
"path" : "/resource/x/v2/{id}",
|
||||
"operations" : [ {
|
||||
"method" : "GET",
|
||||
"nickname" : "getX",
|
||||
"type" : "string",
|
||||
"parameters" : [ {
|
||||
"type" : "integer",
|
||||
"description" : "A valid x x UUID",
|
||||
"paramType" : "path",
|
||||
"name" : "id",
|
||||
"required" : true
|
||||
} ],
|
||||
"summary" : "Gets the x x with the specified id.",
|
||||
"responseMessages" : [ {
|
||||
"code" : 200,
|
||||
"message" : "ok"
|
||||
}, {
|
||||
"code" : 404,
|
||||
"message" : "not found"
|
||||
} ],
|
||||
"produces" : [ "application/json" ]
|
||||
} ]
|
||||
} ]
|
||||
}
|
||||
Reference in New Issue
Block a user