Compare commits
238 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
04fed3d4d5 | ||
|
|
1ead6614ba | ||
|
|
887e63464d | ||
|
|
47e5d5e56e | ||
|
|
c505c1e88e | ||
|
|
6a8c04c031 | ||
|
|
33f68a7f41 | ||
|
|
c5af8676e5 | ||
|
|
618898cb09 | ||
|
|
36bdcc57d9 | ||
|
|
eb418c07f5 | ||
|
|
9a265fbbc3 | ||
|
|
cf32d6cf29 | ||
|
|
9d216e3dc2 | ||
|
|
9d387b3e80 | ||
|
|
1e6be2f26d | ||
|
|
e56f824cd2 | ||
|
|
d38014f4b5 | ||
|
|
b331062fa6 | ||
|
|
88df748451 | ||
|
|
5384197bd1 | ||
|
|
2b5d4b7fe9 | ||
|
|
c15d074488 | ||
|
|
b0c3aa71b9 | ||
|
|
32d85ffb55 | ||
|
|
59fcd61738 | ||
|
|
7ce969882d | ||
|
|
ee70cdb94f | ||
|
|
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 | ||
|
|
8d4bc8c0bc | ||
|
|
76df322bb4 | ||
|
|
36cdd3cebb | ||
|
|
ca4587cb29 | ||
|
|
ce958ba798 | ||
|
|
7c5c0fea8c | ||
|
|
5bc557a5d2 | ||
|
|
e23a649c17 | ||
|
|
a5300ceab5 | ||
|
|
fdb405e52a | ||
|
|
79cdd26ef0 | ||
|
|
87c24c8f31 | ||
|
|
6216165515 | ||
|
|
77640d21be | ||
|
|
57282f4933 | ||
|
|
1a12e0dc11 | ||
|
|
2b0317d1f6 | ||
|
|
8fce706f31 | ||
|
|
ae0f3ab31d | ||
|
|
34cb438757 | ||
|
|
8747ba2c1d | ||
|
|
bef4e3c735 | ||
|
|
6396b8fdb7 | ||
|
|
e27ba4304d | ||
|
|
4c86e73c4e | ||
|
|
9f9fa8c444 | ||
|
|
9647116572 | ||
|
|
736891fbdd | ||
|
|
acec733af7 | ||
|
|
73cdc35c80 | ||
|
|
cae91b3565 | ||
|
|
ec610f4fbb | ||
|
|
edf9ba01bd | ||
|
|
e942252d9a | ||
|
|
04d1773c03 | ||
|
|
448899c193 | ||
|
|
23d1db4fd5 | ||
|
|
903d3ed452 | ||
|
|
1ad78ba9f6 | ||
|
|
82416a33cc | ||
|
|
e67b32d537 | ||
|
|
dbb6f9ace8 | ||
|
|
19384f97b9 | ||
|
|
90de0a3c6a | ||
|
|
ae77e814f7 | ||
|
|
d165a0f842 | ||
|
|
0833a74c37 | ||
|
|
4ec7ecf25b | ||
|
|
99dd062fc9 | ||
|
|
52462466ff | ||
|
|
d2c69abb71 | ||
|
|
11d4311986 | ||
|
|
e2f1bca8f1 | ||
|
|
1db1af705b | ||
|
|
dd140a532b | ||
|
|
1f51a9bc91 | ||
|
|
5f28eb4073 | ||
|
|
97541bfc83 | ||
|
|
9144155200 | ||
|
|
84d64ec6f6 | ||
|
|
e7c9ed54db | ||
|
|
44838f0b6f | ||
|
|
d7efd403c7 | ||
|
|
31a4c21aa1 | ||
|
|
6c50292563 | ||
|
|
3d116dd7f8 | ||
|
|
e6f7372c9f | ||
|
|
0ca91ea930 | ||
|
|
efea76d243 | ||
|
|
cd4ef60cc3 | ||
|
|
6ed557b4ac | ||
|
|
139c294f25 | ||
|
|
68a433b76b | ||
|
|
b0dba05b48 | ||
|
|
55bb2bdd71 | ||
|
|
3d4d87c0b0 | ||
|
|
ad0d03c95c | ||
|
|
0675beaa45 | ||
|
|
cb6526d0e5 | ||
|
|
f5a8454817 | ||
|
|
5bf8270f2e | ||
|
|
6c794e75fd | ||
|
|
b472bf97bb |
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:
|
||||
|
||||
127
README.adoc
127
README.adoc
@@ -1,104 +1,63 @@
|
||||
= Swagger2Markup
|
||||
:author: Robert Winkler
|
||||
:version: 0.1.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:http://img.shields.io/:version-{version}-blue.svg["Semantic Versioning", link="http://semver.org"] 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://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"]
|
||||
|
||||
WARNING: Still under heavy development
|
||||
|
||||
== Overview
|
||||
|
||||
This project is a Swagger to Markup (AsciiDoc and Markdown) converter. The *Swagger2MarkupConverter* takes a swagger.json or swagger.yaml file as source and converts it into an AsciiDoc or Markdown document. The Swagger source file can be located locally or remotely accessible via HTTP. The Swagger2MarkupConverter supports the Swagger 1.2 and 2.0 specification. Internally it uses the _official_ https://github.com/swagger-api/swagger-parser[swagger-parser].
|
||||
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.
|
||||
|
||||
The primary goal of this project is to simplify the documentation of RESTful APIs. The result is intended to be an easy-to-read, on- and offline user guide, comparable to https://developer.github.com/v3/[GitHub's API documentation].
|
||||
Swagger2Markup 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].
|
||||
|
||||
== Usage
|
||||
You can use Swagger2Markup to convert your contract-first Swagger YAML file into a human-readable format and combine it with hand-written documentation. As an alternative, you can choose the code-first approach and use Swagger2Markup together with https://github.com/swagger-api/swagger-core/wiki/Swagger-Core-JAX-RS-Project-Setup-1.5.X[Swagger JAX-RS], https://github.com/springfox/springfox[springfox] or https://github.com/spring-projects/spring-restdocs[spring-restdocs]. If you are Gradle or Maven user, you can also use the https://github.com/RobWin/swagger2markup-gradle-plugin[Swagger2Markup Gradle Plugin] or https://github.com/redowl/swagger2markup-maven-plugin[Swagger2markup Maven Plugin].
|
||||
|
||||
Using the Swagger2MarkupConverter is simple. For instance, you can generate your AsciiDoc/Markdown documentation using https://github.com/spring-projects/spring-boot[Spring Boot] and https://github.com/martypitt/swagger-springmvc[swagger-springmvc] as follows:
|
||||
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*.
|
||||
|
||||
[source,java]
|
||||
----
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(classes = SpringBootSwaggerConfig.class)
|
||||
@IntegrationTest
|
||||
@WebAppConfiguration
|
||||
public class Swagger2MarkupTest {
|
||||
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].
|
||||
|
||||
@Test
|
||||
public void convertSwaggerToMarkup() {
|
||||
//Remote
|
||||
Swagger2MarkupConverter.from("http://localhost:8080/api-docs").
|
||||
toAsciiDoc("src/docs/asciidoc/example.adoc");
|
||||
|
||||
Swagger2MarkupConverter.from("http://localhost:8080/api-docs").
|
||||
toMarkdown("src/docs/markdown/example.md");
|
||||
|
||||
//Local
|
||||
File file = new File(Swagger2MarkupTest.class.getResource("/json/swagger.json").getFile());
|
||||
Swagger2MarkupConverter.from(file.getAbsolutePath()).toAsciiDoc("src/docs/asciidoc/swagger.adoc")
|
||||
}
|
||||
|
||||
}
|
||||
----
|
||||
|
||||
[source,java]
|
||||
----
|
||||
@SpringBootApplication
|
||||
@EnableSwagger
|
||||
public class SpringBootSwaggerConfig {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(SpringBootTestConfig.class, args);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private SpringSwaggerConfig springSwaggerConfig;
|
||||
|
||||
@Bean
|
||||
public SwaggerSpringMvcPlugin customImplementation(){
|
||||
return new SwaggerSpringMvcPlugin(this.springSwaggerConfig)
|
||||
.apiInfo(apiInfo()).excludeAnnotations(Controller.class);
|
||||
}
|
||||
|
||||
private ApiInfo apiInfo() {
|
||||
ApiInfo apiInfo = new ApiInfo(
|
||||
"My Apps API Title",
|
||||
"My Apps API Description",
|
||||
"My Apps API terms of service",
|
||||
"My Apps API Contact Email",
|
||||
"My Apps API Licence Type",
|
||||
"My Apps API License URL"
|
||||
);
|
||||
return apiInfo;
|
||||
}
|
||||
}
|
||||
----
|
||||
|
||||
You can then generate 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] and https://github.com/aalmiray/markdown-gradle-plugin[markdown-gradle-plugin].
|
||||
The project requires at least JDK 7.
|
||||
|
||||
== Example
|
||||
== swagger.json
|
||||
image::images/swagger_json.PNG[swagger_json]
|
||||
|
||||
=== Generated AsciiDoc file
|
||||
image::images/asciidoc.PNG[asciidoc]
|
||||
image::images/Swagger2Markup.PNG[]
|
||||
|
||||
=== Generated Markdown file
|
||||
image::images/markdown.PNG[asciidoc]
|
||||
image::images/Swagger2Markup_definitions.PNG[]
|
||||
|
||||
=== Generated HTML
|
||||
image::images/asciidoc_html.PNG[asciidoc_html]
|
||||
== Reference documentation
|
||||
- http://swagger2markup.readme.io/[Reference Documentation]
|
||||
- https://github.com/Swagger2Markup/swagger2markup/blob/master/RELEASENOTES.adoc[Release notes]
|
||||
|
||||
== Document Builder
|
||||
The converter allows to build an AsciiDoc or Markdown document via the Builder pattern:
|
||||
[source,java]
|
||||
----
|
||||
String asciiDoc = new AsciiDocBuilder().documentTitle("Title")
|
||||
.sectionTitleLevel1("Section1").paragraph("Text text")
|
||||
.sectionTitleLevel2("Code examples").listing("Code example").toString();
|
||||
== Contributing
|
||||
|
||||
String markdown = new MarkdownBuilder().documentTitle("Title")
|
||||
.sectionTitleLevel1("Section1").paragraph("Text text")
|
||||
.sectionTitleLevel2("Code examples").listing("Code example").toString();
|
||||
----
|
||||
=== Community contributions
|
||||
|
||||
Pull requests are welcome.
|
||||
|
||||
* New feature https://github.com/Swagger2Markup/swagger2markup/issues/18[Swagger2Markup/swagger2Markup#18] by https://github.com/sg-ad[@sg-ad]: In addition to the definitions.adoc you can also generate separate files for each definition model (ex: person.adoc, address.adoc, purchase.adoc).
|
||||
|
||||
* New feature https://github.com/Swagger2Markup/swagger2markup/issues/21[Swagger2Markup/swagger2Markup#21] by https://github.com/redowl[@redowl]: Support for both reference models and composed models.
|
||||
|
||||
* New feature https://github.com/Swagger2Markup/swagger2markup/issues/27[Swagger2Markup/swagger2Markup#27] by https://github.com/zmitrok[@zmitrok]: Added a hook to preprocess a Swagger Model before it is converted.
|
||||
|
||||
* New feature https://github.com/Swagger2Markup/swagger2markup/issues/48[Swagger2Markup/swagger2Markup#48] by https://github.com/MeteorBoom[@MeteorBoom]: Multi language support.
|
||||
|
||||
=== Questions
|
||||
You can ask questions about Swagger2Markup in https://gitter.im/Swagger2Markup/swagger2markup[Gitter].
|
||||
|
||||
=== 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.
|
||||
|
||||
=== 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.
|
||||
|
||||
== License
|
||||
|
||||
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.
|
||||
|
||||
@@ -1,4 +1,77 @@
|
||||
= Release Notes
|
||||
|
||||
== Version 0.1.0
|
||||
* Initial version with support for AsciiDoc and Markdown
|
||||
* Initial version with support for AsciiDoc and Markdown
|
||||
|
||||
== Version 0.2.0
|
||||
* This version is not downward compatible. This version supports includes of example files and JSON/XML Schema files. See documentation.
|
||||
|
||||
=== Version 0.2.1
|
||||
* Signed jar files and published in Maven Central
|
||||
|
||||
=== Version 0.2.2
|
||||
* Fixed wrong dependency version to io.github.robwin:markup-document-builder
|
||||
|
||||
=== Version 0.2.3
|
||||
* Fixed issue #7: @ApiModelProperty metadata are ignored for definitions file
|
||||
|
||||
=== Version 0.2.4
|
||||
* Fixed issue #8: logback.xml on the classpath
|
||||
* Fixed issue #13: unknown format not supported for properties
|
||||
|
||||
== Version 0.3.0
|
||||
* Support of YAML or JSON String as input.
|
||||
|
||||
== Version 0.4.0
|
||||
* Updated Swagger-Parser from 1.0.0 to 1.0.5
|
||||
* 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
|
||||
|
||||
== 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
|
||||
|
||||
== Version 0.9.0
|
||||
* Updated swagger-parser from v1.0.8 to v1.0.13
|
||||
* Support for global responses and parameters
|
||||
|
||||
=== Version 0.9.1
|
||||
* Added support to group the paths by tags or as-is
|
||||
* Added support to order the definitions by natural ordering or as-is
|
||||
|
||||
=== Version 0.9.2
|
||||
* Multi language support. Added russian.
|
||||
74
build.gradle
74
build.gradle
@@ -5,23 +5,19 @@ 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.3.1.RELEASE'
|
||||
classpath 'org.asciidoctor:asciidoctorj-pdf:1.5.0-alpha.8'
|
||||
classpath 'io.spring.gradle:dependency-management-plugin:0.5.3.RELEASE'
|
||||
classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.0.1'
|
||||
classpath 'me.champeau.gradle:jbake-gradle-plugin:0.2'
|
||||
classpath 'org.jbake:jbake-core:2.3.2'
|
||||
classpath 'org.asciidoctor:asciidoctorj:1.5.2'
|
||||
classpath 'org.freemarker:freemarker:2.3.19'
|
||||
classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.2.1.RELEASE'
|
||||
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.1.0'
|
||||
group = 'io.swagger2markup'
|
||||
version = '0.9.2'
|
||||
group = 'io.github.robwin'
|
||||
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'maven'
|
||||
apply plugin: 'maven-publish'
|
||||
apply plugin: 'org.asciidoctor.convert'
|
||||
apply plugin: 'jacoco'
|
||||
apply plugin: 'com.github.kt3k.coveralls'
|
||||
@@ -44,26 +40,64 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile 'io.github.robwin:markup-document-builder'
|
||||
compile 'io.swagger:swagger-compat-spec-parser'
|
||||
compile 'commons-collections:commons-collections'
|
||||
compile 'commons-io:commons-io'
|
||||
compile 'org.slf4j:slf4j-api'
|
||||
testCompile 'junit:junit'
|
||||
testCompile 'org.asciidoctor:asciidoctorj:1.5.2'
|
||||
testCompile 'ch.qos.logback:logback-classic'
|
||||
testCompile 'org.assertj:assertj-core'
|
||||
}
|
||||
|
||||
dependencyManagement {
|
||||
dependencies {
|
||||
"io.swagger:swagger-compat-spec-parser" "1.0.0"
|
||||
"commons-collections:commons-collections" "3.2.1"
|
||||
"com.mangofactory:swagger-springmvc" "0.9.5"
|
||||
"com.jayway.restassured:spring-mock-mvc" "2.4.0"
|
||||
"junit:junit" "4.11"
|
||||
dependency "io.github.robwin:markup-document-builder:0.1.5"
|
||||
dependency "io.swagger:swagger-compat-spec-parser:1.0.13"
|
||||
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.2.0"
|
||||
}
|
||||
}
|
||||
|
||||
task sourcesJar(type: Jar, dependsOn: classes) {
|
||||
classifier = 'sources'
|
||||
from sourceSets.main.allSource
|
||||
}
|
||||
|
||||
task javadocJar(type: Jar, dependsOn: javadoc) {
|
||||
classifier = 'javadoc'
|
||||
from javadoc.destinationDir
|
||||
}
|
||||
|
||||
artifacts {
|
||||
archives sourcesJar
|
||||
archives javadocJar
|
||||
}
|
||||
|
||||
ext {
|
||||
generatedDocumentation = file('build/docs/asciidoc/generated')
|
||||
}
|
||||
|
||||
asciidoctor {
|
||||
dependsOn test
|
||||
sources {
|
||||
include 'index.adoc'
|
||||
}
|
||||
backends = ['html5', 'pdf']
|
||||
attributes = [
|
||||
doctype: 'book',
|
||||
toc: 'left',
|
||||
toclevels: '1'
|
||||
toclevels: '2',
|
||||
numbered: '',
|
||||
sectlinks: '',
|
||||
sectanchors: '',
|
||||
hardbreaks: '',
|
||||
generated: generatedDocumentation
|
||||
]
|
||||
}
|
||||
|
||||
@@ -78,6 +112,10 @@ tasks.coveralls {
|
||||
dependsOn 'check'
|
||||
}
|
||||
|
||||
tasks.asciidoctor {
|
||||
dependsOn 'check'
|
||||
}
|
||||
|
||||
task wrapper(type: Wrapper) {
|
||||
gradleVersion = '2.2.1'
|
||||
}
|
||||
gradleVersion = '2.4'
|
||||
}
|
||||
|
||||
@@ -25,9 +25,76 @@ jar {
|
||||
|
||||
if (!project.hasProperty('bintrayUsername')) ext.bintrayUsername = ''
|
||||
if (!project.hasProperty('bintrayApiKey')) ext.bintrayApiKey = ''
|
||||
if (!project.hasProperty('gpgPassphrase')) ext.gpgPassphrase = ''
|
||||
if (!project.hasProperty('ossUser')) ext.ossUser = ''
|
||||
if (!project.hasProperty('ossPassword')) ext.ossPassword = ''
|
||||
|
||||
bintray {
|
||||
user = project.bintrayUsername
|
||||
key = project.bintrayApiKey
|
||||
pkg.repo = 'swagger2markup'
|
||||
dryRun = false //Whether to run this as dry-run, without deploying
|
||||
publish = true //If version should be auto published after an upload
|
||||
publications = ['mavenJava']
|
||||
pkg {
|
||||
repo = 'maven'
|
||||
name = 'swagger2markup'
|
||||
websiteUrl = 'https://github.com/Swagger2Markup/swagger2markup'
|
||||
issueTrackerUrl = 'https://github.com/Swagger2Markup/swagger2markup/issues'
|
||||
vcsUrl = 'https://github.com/Swagger2Markup/swagger2markup.git'
|
||||
desc = 'A Swagger to Markup (AsciiDoc and Markdown) converter.'
|
||||
licenses = ['Apache-2.0']
|
||||
version {
|
||||
vcsTag = project.version
|
||||
gpg {
|
||||
sign = true //Determines whether to GPG sign the files. The default is false
|
||||
passphrase = project.gpgPassphrase //Optional. The passphrase for GPG signing'
|
||||
}
|
||||
mavenCentralSync {
|
||||
sync = true //Optional (true by default). Determines whether to sync the version to Maven Central.
|
||||
user = ossUser //OSS user token
|
||||
password = ossPassword //OSS user password
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
mavenJava(MavenPublication) {
|
||||
from components.java
|
||||
pom.withXml {
|
||||
def devs = ['RobWin': 'Robert Winkler']
|
||||
def root = asNode()
|
||||
|
||||
root.dependencies.'*'.findAll() {
|
||||
it.scope.text() == 'runtime' && project.configurations.compile.allDependencies.find { dep ->
|
||||
dep.name == it.artifactId.text()
|
||||
}
|
||||
}.each() {
|
||||
it.scope*.value = 'compile'
|
||||
}
|
||||
|
||||
root.appendNode('name', 'swagger2markup')
|
||||
root.appendNode('packaging', 'jar')
|
||||
root.appendNode('url', 'https://github.com/Swagger2Markup/swagger2markup')
|
||||
root.appendNode('description', 'A Swagger to Markup (AsciiDoc and Markdown) converter.')
|
||||
|
||||
def license = root.appendNode('licenses').appendNode('license')
|
||||
license.appendNode('name', 'Apache-2.0')
|
||||
license.appendNode('url', 'https://github.com/Swagger2Markup/swagger2markup/blob/master/LICENSE.txt')
|
||||
license.appendNode('distribution', 'repo')
|
||||
|
||||
root.appendNode('scm').appendNode('url', 'https://github.com/Swagger2Markup/swagger2markup.git')
|
||||
|
||||
def developers = root.appendNode('developers')
|
||||
devs.each {
|
||||
def d = developers.appendNode('developer')
|
||||
d.appendNode('id', it.key)
|
||||
d.appendNode('name', it.value)
|
||||
}
|
||||
}
|
||||
artifact sourcesJar
|
||||
artifact javadocJar
|
||||
}
|
||||
}
|
||||
}
|
||||
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
|
||||
|
||||
BIN
images/Swagger2Markup.PNG
Normal file
BIN
images/Swagger2Markup.PNG
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 126 KiB |
BIN
images/Swagger2Markup_definitions.PNG
Normal file
BIN
images/Swagger2Markup_definitions.PNG
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 124 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 19 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 96 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 13 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 26 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*
|
||||
3
src/docs/asciidoc/index.adoc
Normal file
3
src/docs/asciidoc/index.adoc
Normal file
@@ -0,0 +1,3 @@
|
||||
include::{generated}/overview.adoc[]
|
||||
include::{generated}/paths.adoc[]
|
||||
include::{generated}/definitions.adoc[]
|
||||
@@ -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
|
||||
@@ -1,534 +0,0 @@
|
||||
= Swagger Petstore
|
||||
This is a sample server Petstore server.
|
||||
|
||||
[Learn about Swagger](http://swagger.wordnik.com) or join the IRC channel `#swagger` on irc.freenode.net.
|
||||
|
||||
For this sample, you can use the api key `special-key` to test the authorization filters
|
||||
|
||||
Version: 1.0.0
|
||||
|
||||
== Update an existing pet
|
||||
----
|
||||
PUT /pets
|
||||
----
|
||||
|
||||
=== Parameters
|
||||
[format="csv", options="header"]
|
||||
|===
|
||||
Name,Located in,Description,Required
|
||||
body,body,Pet object that needs to be added to the store,false
|
||||
|===
|
||||
|
||||
=== Responses
|
||||
[format="csv", options="header"]
|
||||
|===
|
||||
Code,Description
|
||||
400,Invalid ID supplied
|
||||
404,Pet not found
|
||||
405,Validation exception
|
||||
|===
|
||||
|
||||
=== Consumes
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
=== Produces
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
== Add a new pet to the store
|
||||
----
|
||||
POST /pets
|
||||
----
|
||||
|
||||
=== Parameters
|
||||
[format="csv", options="header"]
|
||||
|===
|
||||
Name,Located in,Description,Required
|
||||
body,body,Pet object that needs to be added to the store,false
|
||||
|===
|
||||
|
||||
=== Responses
|
||||
[format="csv", options="header"]
|
||||
|===
|
||||
Code,Description
|
||||
405,Invalid input
|
||||
|===
|
||||
|
||||
=== Consumes
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
=== Produces
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
== Finds Pets by status
|
||||
----
|
||||
GET /pets/findByStatus
|
||||
----
|
||||
|
||||
=== Description
|
||||
:hardbreaks:
|
||||
Multiple status values can be provided with comma seperated strings
|
||||
|
||||
=== Parameters
|
||||
[format="csv", options="header"]
|
||||
|===
|
||||
Name,Located in,Description,Required
|
||||
status,query,Status values that need to be considered for filter,false
|
||||
|===
|
||||
|
||||
=== Responses
|
||||
[format="csv", options="header"]
|
||||
|===
|
||||
Code,Description
|
||||
200,successful operation
|
||||
400,Invalid status value
|
||||
|===
|
||||
|
||||
=== Produces
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
== 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
|
||||
[format="csv", options="header"]
|
||||
|===
|
||||
Name,Located in,Description,Required
|
||||
tags,query,Tags to filter by,false
|
||||
|===
|
||||
|
||||
=== Responses
|
||||
[format="csv", options="header"]
|
||||
|===
|
||||
Code,Description
|
||||
200,successful operation
|
||||
400,Invalid tag value
|
||||
|===
|
||||
|
||||
=== Produces
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
== 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
|
||||
[format="csv", options="header"]
|
||||
|===
|
||||
Name,Located in,Description,Required
|
||||
petId,path,ID of pet that needs to be fetched,true
|
||||
|===
|
||||
|
||||
=== Responses
|
||||
[format="csv", options="header"]
|
||||
|===
|
||||
Code,Description
|
||||
200,successful operation
|
||||
400,Invalid ID supplied
|
||||
404,Pet not found
|
||||
|===
|
||||
|
||||
=== Produces
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
== Deletes a pet
|
||||
----
|
||||
DELETE /pets/{petId}
|
||||
----
|
||||
|
||||
=== Parameters
|
||||
[format="csv", options="header"]
|
||||
|===
|
||||
Name,Located in,Description,Required
|
||||
api_key,header,,true
|
||||
petId,path,Pet id to delete,true
|
||||
|===
|
||||
|
||||
=== Responses
|
||||
[format="csv", options="header"]
|
||||
|===
|
||||
Code,Description
|
||||
400,Invalid pet value
|
||||
|===
|
||||
|
||||
=== Produces
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
== Updates a pet in the store with form data
|
||||
----
|
||||
POST /pets/{petId}
|
||||
----
|
||||
|
||||
=== Parameters
|
||||
[format="csv", options="header"]
|
||||
|===
|
||||
Name,Located in,Description,Required
|
||||
petId,path,ID of pet that needs to be updated,true
|
||||
name,formData,Updated name of the pet,true
|
||||
status,formData,Updated status of the pet,true
|
||||
|===
|
||||
|
||||
=== Responses
|
||||
[format="csv", options="header"]
|
||||
|===
|
||||
Code,Description
|
||||
405,Invalid input
|
||||
|===
|
||||
|
||||
=== Consumes
|
||||
* application/x-www-form-urlencoded
|
||||
|
||||
=== Produces
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
== Place an order for a pet
|
||||
----
|
||||
POST /stores/order
|
||||
----
|
||||
|
||||
=== Parameters
|
||||
[format="csv", options="header"]
|
||||
|===
|
||||
Name,Located in,Description,Required
|
||||
body,body,order placed for purchasing the pet,false
|
||||
|===
|
||||
|
||||
=== Responses
|
||||
[format="csv", options="header"]
|
||||
|===
|
||||
Code,Description
|
||||
200,successful operation
|
||||
400,Invalid Order
|
||||
|===
|
||||
|
||||
=== Produces
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
== 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
|
||||
[format="csv", options="header"]
|
||||
|===
|
||||
Name,Located in,Description,Required
|
||||
orderId,path,ID of pet that needs to be fetched,true
|
||||
|===
|
||||
|
||||
=== Responses
|
||||
[format="csv", options="header"]
|
||||
|===
|
||||
Code,Description
|
||||
200,successful operation
|
||||
400,Invalid ID supplied
|
||||
404,Order not found
|
||||
|===
|
||||
|
||||
=== Produces
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
== 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
|
||||
[format="csv", options="header"]
|
||||
|===
|
||||
Name,Located in,Description,Required
|
||||
orderId,path,ID of the order that needs to be deleted,true
|
||||
|===
|
||||
|
||||
=== Responses
|
||||
[format="csv", options="header"]
|
||||
|===
|
||||
Code,Description
|
||||
400,Invalid ID supplied
|
||||
404,Order not found
|
||||
|===
|
||||
|
||||
=== Produces
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
== Create user
|
||||
----
|
||||
POST /users
|
||||
----
|
||||
|
||||
=== Description
|
||||
:hardbreaks:
|
||||
This can only be done by the logged in user.
|
||||
|
||||
=== Parameters
|
||||
[format="csv", options="header"]
|
||||
|===
|
||||
Name,Located in,Description,Required
|
||||
body,body,Created user object,false
|
||||
|===
|
||||
|
||||
=== Responses
|
||||
[format="csv", options="header"]
|
||||
|===
|
||||
Code,Description
|
||||
default,successful operation
|
||||
|===
|
||||
|
||||
=== Produces
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
== Creates list of users with given input array
|
||||
----
|
||||
POST /users/createWithArray
|
||||
----
|
||||
|
||||
=== Parameters
|
||||
[format="csv", options="header"]
|
||||
|===
|
||||
Name,Located in,Description,Required
|
||||
body,body,List of user object,false
|
||||
|===
|
||||
|
||||
=== Responses
|
||||
[format="csv", options="header"]
|
||||
|===
|
||||
Code,Description
|
||||
default,successful operation
|
||||
|===
|
||||
|
||||
=== Produces
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
== Creates list of users with given input array
|
||||
----
|
||||
POST /users/createWithList
|
||||
----
|
||||
|
||||
=== Parameters
|
||||
[format="csv", options="header"]
|
||||
|===
|
||||
Name,Located in,Description,Required
|
||||
body,body,List of user object,false
|
||||
|===
|
||||
|
||||
=== Responses
|
||||
[format="csv", options="header"]
|
||||
|===
|
||||
Code,Description
|
||||
default,successful operation
|
||||
|===
|
||||
|
||||
=== Produces
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
== Logs user into the system
|
||||
----
|
||||
GET /users/login
|
||||
----
|
||||
|
||||
=== Parameters
|
||||
[format="csv", options="header"]
|
||||
|===
|
||||
Name,Located in,Description,Required
|
||||
username,query,The user name for login,false
|
||||
password,query,The password for login in clear text,false
|
||||
|===
|
||||
|
||||
=== Responses
|
||||
[format="csv", options="header"]
|
||||
|===
|
||||
Code,Description
|
||||
200,successful operation
|
||||
400,Invalid username/password supplied
|
||||
|===
|
||||
|
||||
=== Produces
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
== Logs out current logged in user session
|
||||
----
|
||||
GET /users/logout
|
||||
----
|
||||
|
||||
=== Responses
|
||||
[format="csv", options="header"]
|
||||
|===
|
||||
Code,Description
|
||||
default,successful operation
|
||||
|===
|
||||
|
||||
=== Produces
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
== Get user by user name
|
||||
----
|
||||
GET /users/{username}
|
||||
----
|
||||
|
||||
=== Parameters
|
||||
[format="csv", options="header"]
|
||||
|===
|
||||
Name,Located in,Description,Required
|
||||
username,path,The name that needs to be fetched. Use user1 for testing.,true
|
||||
|===
|
||||
|
||||
=== Responses
|
||||
[format="csv", options="header"]
|
||||
|===
|
||||
Code,Description
|
||||
200,successful operation
|
||||
400,Invalid username supplied
|
||||
404,User not found
|
||||
|===
|
||||
|
||||
=== Produces
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
== Updated user
|
||||
----
|
||||
PUT /users/{username}
|
||||
----
|
||||
|
||||
=== Description
|
||||
:hardbreaks:
|
||||
This can only be done by the logged in user.
|
||||
|
||||
=== Parameters
|
||||
[format="csv", options="header"]
|
||||
|===
|
||||
Name,Located in,Description,Required
|
||||
username,path,name that need to be deleted,true
|
||||
body,body,Updated user object,false
|
||||
|===
|
||||
|
||||
=== Responses
|
||||
[format="csv", options="header"]
|
||||
|===
|
||||
Code,Description
|
||||
400,Invalid user supplied
|
||||
404,User not found
|
||||
|===
|
||||
|
||||
=== Produces
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
== Delete user
|
||||
----
|
||||
DELETE /users/{username}
|
||||
----
|
||||
|
||||
=== Description
|
||||
:hardbreaks:
|
||||
This can only be done by the logged in user.
|
||||
|
||||
=== Parameters
|
||||
[format="csv", options="header"]
|
||||
|===
|
||||
Name,Located in,Description,Required
|
||||
username,path,The name that needs to be deleted,true
|
||||
|===
|
||||
|
||||
=== Responses
|
||||
[format="csv", options="header"]
|
||||
|===
|
||||
Code,Description
|
||||
400,Invalid username supplied
|
||||
404,User not found
|
||||
|===
|
||||
|
||||
=== Produces
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
== Definitions
|
||||
=== User
|
||||
[format="csv", options="header"]
|
||||
|===
|
||||
Name,Type,Required
|
||||
id,integer,false
|
||||
username,string,false
|
||||
firstName,string,false
|
||||
lastName,string,false
|
||||
email,string,false
|
||||
password,string,false
|
||||
phone,string,false
|
||||
userStatus,integer,false
|
||||
|===
|
||||
|
||||
=== Category
|
||||
[format="csv", options="header"]
|
||||
|===
|
||||
Name,Type,Required
|
||||
id,integer,false
|
||||
name,string,false
|
||||
|===
|
||||
|
||||
=== Pet
|
||||
[format="csv", options="header"]
|
||||
|===
|
||||
Name,Type,Required
|
||||
id,integer,false
|
||||
category,ref,false
|
||||
name,string,true
|
||||
photoUrls,array,true
|
||||
tags,array,false
|
||||
status,string,false
|
||||
|===
|
||||
|
||||
=== Tag
|
||||
[format="csv", options="header"]
|
||||
|===
|
||||
Name,Type,Required
|
||||
id,integer,false
|
||||
name,string,false
|
||||
|===
|
||||
|
||||
=== Order
|
||||
[format="csv", options="header"]
|
||||
|===
|
||||
Name,Type,Required
|
||||
id,integer,false
|
||||
petId,integer,false
|
||||
quantity,integer,false
|
||||
shipDate,string,false
|
||||
status,string,false
|
||||
complete,boolean,false
|
||||
|===
|
||||
|
||||
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*
|
||||
@@ -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,494 +0,0 @@
|
||||
# Swagger Petstore
|
||||
This is a sample server Petstore server.
|
||||
|
||||
[Learn about Swagger](http://swagger.wordnik.com) or join the IRC channel `#swagger` on irc.freenode.net.
|
||||
|
||||
For this sample, you can use the api key `special-key` to test the authorization filters
|
||||
|
||||
Version: 1.0.0
|
||||
|
||||
## Update an existing pet
|
||||
```
|
||||
PUT /pets
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|Name|Located in|Description|Required|
|
||||
|----|----|----|----|
|
||||
|body|body|Pet object that needs to be added to the store|false|
|
||||
|
||||
|
||||
### Responses
|
||||
|Code|Description|
|
||||
|----|----|
|
||||
|400|Invalid ID supplied|
|
||||
|404|Pet not found|
|
||||
|405|Validation exception|
|
||||
|
||||
|
||||
### Consumes
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
### Produces
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
## Add a new pet to the store
|
||||
```
|
||||
POST /pets
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|Name|Located in|Description|Required|
|
||||
|----|----|----|----|
|
||||
|body|body|Pet object that needs to be added to the store|false|
|
||||
|
||||
|
||||
### Responses
|
||||
|Code|Description|
|
||||
|----|----|
|
||||
|405|Invalid input|
|
||||
|
||||
|
||||
### Consumes
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
### Produces
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
## Finds Pets by status
|
||||
```
|
||||
GET /pets/findByStatus
|
||||
```
|
||||
|
||||
### Description
|
||||
|
||||
Multiple status values can be provided with comma seperated strings
|
||||
|
||||
### Parameters
|
||||
|Name|Located in|Description|Required|
|
||||
|----|----|----|----|
|
||||
|status|query|Status values that need to be considered for filter|false|
|
||||
|
||||
|
||||
### Responses
|
||||
|Code|Description|
|
||||
|----|----|
|
||||
|200|successful operation|
|
||||
|400|Invalid status value|
|
||||
|
||||
|
||||
### Produces
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
## Finds Pets by tags
|
||||
```
|
||||
GET /pets/findByTags
|
||||
```
|
||||
|
||||
### Description
|
||||
|
||||
Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.
|
||||
|
||||
### Parameters
|
||||
|Name|Located in|Description|Required|
|
||||
|----|----|----|----|
|
||||
|tags|query|Tags to filter by|false|
|
||||
|
||||
|
||||
### Responses
|
||||
|Code|Description|
|
||||
|----|----|
|
||||
|200|successful operation|
|
||||
|400|Invalid tag value|
|
||||
|
||||
|
||||
### Produces
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
## Find pet by ID
|
||||
```
|
||||
GET /pets/{petId}
|
||||
```
|
||||
|
||||
### Description
|
||||
|
||||
Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions
|
||||
|
||||
### Parameters
|
||||
|Name|Located in|Description|Required|
|
||||
|----|----|----|----|
|
||||
|petId|path|ID of pet that needs to be fetched|true|
|
||||
|
||||
|
||||
### Responses
|
||||
|Code|Description|
|
||||
|----|----|
|
||||
|200|successful operation|
|
||||
|400|Invalid ID supplied|
|
||||
|404|Pet not found|
|
||||
|
||||
|
||||
### Produces
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
## Deletes a pet
|
||||
```
|
||||
DELETE /pets/{petId}
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|Name|Located in|Description|Required|
|
||||
|----|----|----|----|
|
||||
|api_key|header||true|
|
||||
|petId|path|Pet id to delete|true|
|
||||
|
||||
|
||||
### Responses
|
||||
|Code|Description|
|
||||
|----|----|
|
||||
|400|Invalid pet value|
|
||||
|
||||
|
||||
### Produces
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
## Updates a pet in the store with form data
|
||||
```
|
||||
POST /pets/{petId}
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|Name|Located in|Description|Required|
|
||||
|----|----|----|----|
|
||||
|petId|path|ID of pet that needs to be updated|true|
|
||||
|name|formData|Updated name of the pet|true|
|
||||
|status|formData|Updated status of the pet|true|
|
||||
|
||||
|
||||
### Responses
|
||||
|Code|Description|
|
||||
|----|----|
|
||||
|405|Invalid input|
|
||||
|
||||
|
||||
### Consumes
|
||||
* application/x-www-form-urlencoded
|
||||
|
||||
### Produces
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
## Place an order for a pet
|
||||
```
|
||||
POST /stores/order
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|Name|Located in|Description|Required|
|
||||
|----|----|----|----|
|
||||
|body|body|order placed for purchasing the pet|false|
|
||||
|
||||
|
||||
### Responses
|
||||
|Code|Description|
|
||||
|----|----|
|
||||
|200|successful operation|
|
||||
|400|Invalid Order|
|
||||
|
||||
|
||||
### Produces
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
## 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
|
||||
|Name|Located in|Description|Required|
|
||||
|----|----|----|----|
|
||||
|orderId|path|ID of pet that needs to be fetched|true|
|
||||
|
||||
|
||||
### Responses
|
||||
|Code|Description|
|
||||
|----|----|
|
||||
|200|successful operation|
|
||||
|400|Invalid ID supplied|
|
||||
|404|Order not found|
|
||||
|
||||
|
||||
### Produces
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
## 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
|
||||
|Name|Located in|Description|Required|
|
||||
|----|----|----|----|
|
||||
|orderId|path|ID of the order that needs to be deleted|true|
|
||||
|
||||
|
||||
### Responses
|
||||
|Code|Description|
|
||||
|----|----|
|
||||
|400|Invalid ID supplied|
|
||||
|404|Order not found|
|
||||
|
||||
|
||||
### Produces
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
## Create user
|
||||
```
|
||||
POST /users
|
||||
```
|
||||
|
||||
### Description
|
||||
|
||||
This can only be done by the logged in user.
|
||||
|
||||
### Parameters
|
||||
|Name|Located in|Description|Required|
|
||||
|----|----|----|----|
|
||||
|body|body|Created user object|false|
|
||||
|
||||
|
||||
### Responses
|
||||
|Code|Description|
|
||||
|----|----|
|
||||
|default|successful operation|
|
||||
|
||||
|
||||
### Produces
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
## Creates list of users with given input array
|
||||
```
|
||||
POST /users/createWithArray
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|Name|Located in|Description|Required|
|
||||
|----|----|----|----|
|
||||
|body|body|List of user object|false|
|
||||
|
||||
|
||||
### Responses
|
||||
|Code|Description|
|
||||
|----|----|
|
||||
|default|successful operation|
|
||||
|
||||
|
||||
### Produces
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
## Creates list of users with given input array
|
||||
```
|
||||
POST /users/createWithList
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|Name|Located in|Description|Required|
|
||||
|----|----|----|----|
|
||||
|body|body|List of user object|false|
|
||||
|
||||
|
||||
### Responses
|
||||
|Code|Description|
|
||||
|----|----|
|
||||
|default|successful operation|
|
||||
|
||||
|
||||
### Produces
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
## Logs user into the system
|
||||
```
|
||||
GET /users/login
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|Name|Located in|Description|Required|
|
||||
|----|----|----|----|
|
||||
|username|query|The user name for login|false|
|
||||
|password|query|The password for login in clear text|false|
|
||||
|
||||
|
||||
### Responses
|
||||
|Code|Description|
|
||||
|----|----|
|
||||
|200|successful operation|
|
||||
|400|Invalid username/password supplied|
|
||||
|
||||
|
||||
### Produces
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
## Logs out current logged in user session
|
||||
```
|
||||
GET /users/logout
|
||||
```
|
||||
|
||||
### Responses
|
||||
|Code|Description|
|
||||
|----|----|
|
||||
|default|successful operation|
|
||||
|
||||
|
||||
### Produces
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
## Get user by user name
|
||||
```
|
||||
GET /users/{username}
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|Name|Located in|Description|Required|
|
||||
|----|----|----|----|
|
||||
|username|path|The name that needs to be fetched. Use user1 for testing.|true|
|
||||
|
||||
|
||||
### Responses
|
||||
|Code|Description|
|
||||
|----|----|
|
||||
|200|successful operation|
|
||||
|400|Invalid username supplied|
|
||||
|404|User not found|
|
||||
|
||||
|
||||
### Produces
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
## Updated user
|
||||
```
|
||||
PUT /users/{username}
|
||||
```
|
||||
|
||||
### Description
|
||||
|
||||
This can only be done by the logged in user.
|
||||
|
||||
### Parameters
|
||||
|Name|Located in|Description|Required|
|
||||
|----|----|----|----|
|
||||
|username|path|name that need to be deleted|true|
|
||||
|body|body|Updated user object|false|
|
||||
|
||||
|
||||
### Responses
|
||||
|Code|Description|
|
||||
|----|----|
|
||||
|400|Invalid user supplied|
|
||||
|404|User not found|
|
||||
|
||||
|
||||
### Produces
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
## Delete user
|
||||
```
|
||||
DELETE /users/{username}
|
||||
```
|
||||
|
||||
### Description
|
||||
|
||||
This can only be done by the logged in user.
|
||||
|
||||
### Parameters
|
||||
|Name|Located in|Description|Required|
|
||||
|----|----|----|----|
|
||||
|username|path|The name that needs to be deleted|true|
|
||||
|
||||
|
||||
### Responses
|
||||
|Code|Description|
|
||||
|----|----|
|
||||
|400|Invalid username supplied|
|
||||
|404|User not found|
|
||||
|
||||
|
||||
### Produces
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
## Definitions
|
||||
### User
|
||||
|Name|Type|Required|
|
||||
|----|----|----|
|
||||
|id|integer|false|
|
||||
|username|string|false|
|
||||
|firstName|string|false|
|
||||
|lastName|string|false|
|
||||
|email|string|false|
|
||||
|password|string|false|
|
||||
|phone|string|false|
|
||||
|userStatus|integer|false|
|
||||
|
||||
|
||||
### Category
|
||||
|Name|Type|Required|
|
||||
|----|----|----|
|
||||
|id|integer|false|
|
||||
|name|string|false|
|
||||
|
||||
|
||||
### Pet
|
||||
|Name|Type|Required|
|
||||
|----|----|----|
|
||||
|id|integer|false|
|
||||
|category|ref|false|
|
||||
|name|string|true|
|
||||
|photoUrls|array|true|
|
||||
|tags|array|false|
|
||||
|status|string|false|
|
||||
|
||||
|
||||
### Tag
|
||||
|Name|Type|Required|
|
||||
|----|----|----|
|
||||
|id|integer|false|
|
||||
|name|string|false|
|
||||
|
||||
|
||||
### Order
|
||||
|Name|Type|Required|
|
||||
|----|----|----|
|
||||
|id|integer|false|
|
||||
|petId|integer|false|
|
||||
|quantity|integer|false|
|
||||
|shipDate|string|false|
|
||||
|status|string|false|
|
||||
|complete|boolean|false|
|
||||
|
||||
|
||||
24
src/main/java/io/github/robwin/swagger2markup/GroupBy.java
Normal file
24
src/main/java/io/github/robwin/swagger2markup/GroupBy.java
Normal file
@@ -0,0 +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;
|
||||
|
||||
public enum GroupBy {
|
||||
AS_IS,
|
||||
TAGS
|
||||
}
|
||||
21
src/main/java/io/github/robwin/swagger2markup/Language.java
Normal file
21
src/main/java/io/github/robwin/swagger2markup/Language.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package io.github.robwin.swagger2markup;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* @author Maksim Myshkin
|
||||
*/
|
||||
public enum Language {
|
||||
EN(new Locale("en")),
|
||||
RU(new Locale("ru"));
|
||||
|
||||
private final Locale lang;
|
||||
|
||||
Language(final Locale lang) {
|
||||
this.lang = lang;
|
||||
}
|
||||
|
||||
public Locale toLocale() {
|
||||
return lang;
|
||||
}
|
||||
}
|
||||
23
src/main/java/io/github/robwin/swagger2markup/OrderBy.java
Normal file
23
src/main/java/io/github/robwin/swagger2markup/OrderBy.java
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
*
|
||||
* 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;
|
||||
public enum OrderBy {
|
||||
AS_IS,
|
||||
NATURAL
|
||||
}
|
||||
@@ -0,0 +1,271 @@
|
||||
/*
|
||||
*
|
||||
* 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 io.github.robwin.markup.builder.MarkupLanguage;
|
||||
import io.github.robwin.swagger2markup.config.Swagger2MarkupConfig;
|
||||
import io.github.robwin.swagger2markup.builder.document.*;
|
||||
import io.github.robwin.swagger2markup.utils.Consumer;
|
||||
import io.swagger.models.Swagger;
|
||||
import io.swagger.parser.SwaggerParser;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public class Swagger2MarkupConverter {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(Swagger2MarkupConverter.class);
|
||||
|
||||
private final Swagger2MarkupConfig swagger2MarkupConfig;
|
||||
private static final String OVERVIEW_DOCUMENT = "overview";
|
||||
private static final String PATHS_DOCUMENT = "paths";
|
||||
private static final String DEFINITIONS_DOCUMENT = "definitions";
|
||||
|
||||
/**
|
||||
* @param swagger2MarkupConfig the configuration
|
||||
*/
|
||||
Swagger2MarkupConverter(Swagger2MarkupConfig swagger2MarkupConfig){
|
||||
this.swagger2MarkupConfig = swagger2MarkupConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Swagger2MarkupConverter.Builder using a given Swagger source.
|
||||
*
|
||||
* @param swaggerLocation the Swagger location. Can be a HTTP url or a path to a local file.
|
||||
* @return a Swagger2MarkupConverter
|
||||
*/
|
||||
public static Builder from(String swaggerLocation){
|
||||
Validate.notEmpty(swaggerLocation, "swaggerLocation must not be empty!");
|
||||
return new Builder(swaggerLocation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Swagger2MarkupConverter.Builder from a given Swagger model.
|
||||
*
|
||||
* @param swagger the Swagger source.
|
||||
* @return a Swagger2MarkupConverter
|
||||
*/
|
||||
public static Builder from(Swagger swagger){
|
||||
Validate.notNull(swagger, "Swagger must not be null!");
|
||||
return new Builder(swagger);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Swagger2MarkupConverter.Builder from a given Swagger YAML or JSON String.
|
||||
*
|
||||
* @param swaggerAsString the Swagger YAML or JSON String.
|
||||
* @return a Swagger2MarkupConverter
|
||||
* @throws java.io.IOException if String can not be parsed
|
||||
*/
|
||||
public static Builder fromString(String swaggerAsString) throws IOException {
|
||||
Validate.notEmpty(swaggerAsString, "Swagger String must not be null!");
|
||||
Swagger swagger = new SwaggerParser().parse(swaggerAsString);
|
||||
if(swagger == null)
|
||||
throw new IllegalArgumentException("Swagger String is in the wrong format");
|
||||
|
||||
return new Builder(swagger);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the document with the given markup language and stores
|
||||
* the files in the given folder.
|
||||
*
|
||||
* @param targetFolderPath the target folder
|
||||
* @throws IOException if the files cannot be written
|
||||
*/
|
||||
public void intoFolder(String targetFolderPath) throws IOException {
|
||||
Validate.notEmpty(targetFolderPath, "folderPath must not be null!");
|
||||
buildDocuments(targetFolderPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(swagger2MarkupConfig).build().writeToFile(directory, OVERVIEW_DOCUMENT, StandardCharsets.UTF_8);
|
||||
new PathsDocument(swagger2MarkupConfig).build().writeToFile(directory, PATHS_DOCUMENT, StandardCharsets.UTF_8);
|
||||
new DefinitionsDocument(swagger2MarkupConfig, directory).build().writeToFile(directory, DEFINITIONS_DOCUMENT, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all documents as a String
|
||||
|
||||
* @return a the document as a String
|
||||
*/
|
||||
private String buildDocuments() {
|
||||
return new OverviewDocument(swagger2MarkupConfig).build().toString()
|
||||
.concat(new PathsDocument(swagger2MarkupConfig).build().toString()
|
||||
.concat(new DefinitionsDocument(swagger2MarkupConfig, null).build().toString()));
|
||||
}
|
||||
|
||||
|
||||
public static class Builder{
|
||||
private final Swagger swagger;
|
||||
private String examplesFolderPath;
|
||||
private String schemasFolderPath;
|
||||
private String descriptionsFolderPath;
|
||||
private boolean separatedDefinitions;
|
||||
private GroupBy pathsGroupedBy = GroupBy.AS_IS;
|
||||
private OrderBy definitionsOrderedBy = OrderBy.NATURAL;
|
||||
private MarkupLanguage markupLanguage = MarkupLanguage.ASCIIDOC;
|
||||
private Language outputLanguage = Language.EN;
|
||||
|
||||
/**
|
||||
* Creates a Builder using a given Swagger source.
|
||||
*
|
||||
* @param swaggerLocation the Swagger location. Can be a HTTP url or a path to a local file.
|
||||
*/
|
||||
Builder(String swaggerLocation){
|
||||
swagger = new SwaggerParser().read(swaggerLocation);
|
||||
if(swagger == null){
|
||||
throw new IllegalArgumentException("Failed to read the Swagger file. ");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Builder using a given Swagger model.
|
||||
*
|
||||
* @param swagger the Swagger source.
|
||||
*/
|
||||
Builder(Swagger swagger){
|
||||
this.swagger = swagger;
|
||||
}
|
||||
|
||||
public Swagger2MarkupConverter build(){
|
||||
return new Swagger2MarkupConverter(new Swagger2MarkupConfig(swagger, markupLanguage, examplesFolderPath,
|
||||
schemasFolderPath, descriptionsFolderPath, separatedDefinitions, pathsGroupedBy, definitionsOrderedBy,
|
||||
outputLanguage));
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies the markup language which should be used to generate the files
|
||||
*
|
||||
* @param markupLanguage the markup language which is used to generate the files
|
||||
* @return the Swagger2MarkupConverter.Builder
|
||||
*/
|
||||
public Builder withMarkupLanguage(MarkupLanguage markupLanguage){
|
||||
this.markupLanguage = markupLanguage;
|
||||
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
|
||||
*
|
||||
* @param examplesFolderPath the path to the folder where the example documents reside
|
||||
* @return the Swagger2MarkupConverter.Builder
|
||||
*/
|
||||
public Builder withExamples(String examplesFolderPath){
|
||||
this.examplesFolderPath = examplesFolderPath;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Include (JSON, XML) schemas into the Definitions document
|
||||
*
|
||||
* @param schemasFolderPath the path to the folder where the schema documents reside
|
||||
* @return the Swagger2MarkupConverter.Builder
|
||||
*/
|
||||
public Builder withSchemas(String schemasFolderPath){
|
||||
this.schemasFolderPath = schemasFolderPath;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies if the paths should be grouped by tags or stay as-is.
|
||||
*
|
||||
* @param pathsGroupedBy the GroupBy enum
|
||||
* @return the Swagger2MarkupConverter.Builder
|
||||
*/
|
||||
public Builder withPathsGroupedBy(GroupBy pathsGroupedBy) {
|
||||
this.pathsGroupedBy = pathsGroupedBy;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies if the definitions should be ordered by natural ordering or stay as-is.
|
||||
*
|
||||
* @param definitionsOrderedBy the OrderBy enum
|
||||
* @return the Swagger2MarkupConverter.Builder
|
||||
*/
|
||||
public Builder withDefinitionsOrderedBy(OrderBy definitionsOrderedBy) {
|
||||
this.definitionsOrderedBy = definitionsOrderedBy;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies labels language of output files
|
||||
*
|
||||
* @param language the enum
|
||||
* @return the Swagger2MarkupConverter.Builder
|
||||
*/
|
||||
public Builder withOutputLanguage(Language language) {
|
||||
this.outputLanguage = language;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,350 @@
|
||||
/*
|
||||
*
|
||||
* 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.google.common.collect.ImmutableMap;
|
||||
import io.github.robwin.markup.builder.MarkupDocBuilder;
|
||||
import io.github.robwin.markup.builder.MarkupDocBuilders;
|
||||
import io.github.robwin.swagger2markup.OrderBy;
|
||||
import io.github.robwin.swagger2markup.config.Swagger2MarkupConfig;
|
||||
import io.github.robwin.swagger2markup.utils.PropertyUtils;
|
||||
import io.swagger.models.ComposedModel;
|
||||
import io.swagger.models.Model;
|
||||
import io.swagger.models.RefModel;
|
||||
import io.swagger.models.properties.Property;
|
||||
import io.swagger.models.refs.RefFormat;
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
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.*;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.*;
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public class DefinitionsDocument extends MarkupDocument {
|
||||
|
||||
private final String DEFINITIONS;
|
||||
private static final List<String> IGNORED_DEFINITIONS = Collections.singletonList("Void");
|
||||
private final String JSON_SCHEMA;
|
||||
private final String XML_SCHEMA;
|
||||
private static final String JSON_SCHEMA_EXTENSION = ".json";
|
||||
private static final String XML_SCHEMA_EXTENSION = ".xsd";
|
||||
private static final String JSON = "json";
|
||||
private static final String XML = "xml";
|
||||
private static final String DESCRIPTION_FILE_NAME = "description";
|
||||
private boolean schemasEnabled;
|
||||
private String schemasFolderPath;
|
||||
private boolean handWrittenDescriptionsEnabled;
|
||||
private String descriptionsFolderPath;
|
||||
private boolean separatedDefinitionsEnabled;
|
||||
private String outputDirectory;
|
||||
private final OrderBy definitionsOrderedBy;
|
||||
|
||||
public DefinitionsDocument(Swagger2MarkupConfig swagger2MarkupConfig, String outputDirectory){
|
||||
super(swagger2MarkupConfig);
|
||||
|
||||
ResourceBundle labels = ResourceBundle.getBundle("lang/labels",
|
||||
swagger2MarkupConfig.getOutputLanguage().toLocale());
|
||||
DEFINITIONS = labels.getString("definitions");
|
||||
JSON_SCHEMA = labels.getString("json_schema");
|
||||
XML_SCHEMA = labels.getString("xml_schema");
|
||||
|
||||
this.definitionsOrderedBy = swagger2MarkupConfig.getDefinitionsOrderedBy();
|
||||
if(isNotBlank(swagger2MarkupConfig.getSchemasFolderPath())){
|
||||
this.schemasEnabled = true;
|
||||
this.schemasFolderPath = swagger2MarkupConfig.getSchemasFolderPath();
|
||||
}
|
||||
if(isNotBlank(swagger2MarkupConfig.getDescriptionsFolderPath())){
|
||||
this.handWrittenDescriptionsEnabled = true;
|
||||
this.descriptionsFolderPath = swagger2MarkupConfig.getDescriptionsFolderPath() + "/" + DEFINITIONS.toLowerCase();
|
||||
}
|
||||
if(schemasEnabled){
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Include schemas is enabled.");
|
||||
}
|
||||
}else{
|
||||
if (logger.isDebugEnabled()) {
|
||||
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 = swagger2MarkupConfig.isSeparatedDefinitions();
|
||||
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(){
|
||||
definitions(swagger.getDefinitions(), this.markupDocBuilder);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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, MarkupDocBuilder docBuilder){
|
||||
if(MapUtils.isNotEmpty(definitions)){
|
||||
docBuilder.sectionTitleLevel1(DEFINITIONS);
|
||||
Set<String> definitionNames;
|
||||
if(definitionsOrderedBy.equals(OrderBy.AS_IS)){
|
||||
definitionNames = definitions.keySet();
|
||||
}else{
|
||||
definitionNames = new TreeSet<>(definitions.keySet());
|
||||
}
|
||||
for(String definitionName : definitionNames){
|
||||
Model model = definitions.get(definitionName);
|
||||
if(isNotBlank(definitionName)) {
|
||||
if (checkThatDefinitionIsNotInIgnoreList(definitionName)) {
|
||||
definition(definitions, definitionName, model, docBuilder);
|
||||
definitionSchema(definitionName, docBuilder);
|
||||
if (separatedDefinitionsEnabled) {
|
||||
MarkupDocBuilder defDocBuilder = MarkupDocBuilders.documentBuilder(markupLanguage);
|
||||
definition(definitions, definitionName, model, defDocBuilder);
|
||||
definitionSchema(definitionName, defDocBuilder);
|
||||
try {
|
||||
defDocBuilder.writeToFile(outputDirectory, definitionName.toLowerCase(), StandardCharsets.UTF_8);
|
||||
} catch (IOException e) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn(String.format("Failed to write definition file: %s", definitionName), e);
|
||||
}
|
||||
}
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Separate definition file produced: {}", definitionName);
|
||||
}
|
||||
}
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Definition processed: {}", definitionName);
|
||||
}
|
||||
}else{
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Definition was ignored: {}", definitionName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that the definition is not in the list of ignored definitions.
|
||||
*
|
||||
* @param definitionName the name of the definition
|
||||
* @return true if the definition can be processed
|
||||
*/
|
||||
private boolean checkThatDefinitionIsNotInIgnoreList(String definitionName) {
|
||||
return !IGNORED_DEFINITIONS.contains(definitionName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a concrete definition
|
||||
*
|
||||
* @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(Map<String, Model> definitions, String definitionName, Model model, MarkupDocBuilder docBuilder){
|
||||
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){
|
||||
Map<String, Property> properties = getAllProperties(definitions, model);
|
||||
List<String> headerAndContent = new ArrayList<>();
|
||||
List<String> header = Arrays.asList(NAME_COLUMN, DESCRIPTION_COLUMN, REQUIRED_COLUMN, SCHEMA_COLUMN, DEFAULT_COLUMN);
|
||||
headerAndContent.add(join(header, DELIMITER));
|
||||
if(MapUtils.isNotEmpty(properties)){
|
||||
for (Map.Entry<String, Property> propertyEntry : properties.entrySet()) {
|
||||
Property property = propertyEntry.getValue();
|
||||
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(join(content, DELIMITER));
|
||||
}
|
||||
docBuilder.tableWithHeaderRow(headerAndContent);
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, Property> getAllProperties(Map<String, Model> definitions, Model model) {
|
||||
if(model instanceof RefModel) {
|
||||
RefModel refModel = (RefModel)model;
|
||||
String ref;
|
||||
if(refModel.getRefFormat().equals(RefFormat.INTERNAL)){
|
||||
ref = refModel.getSimpleRef();
|
||||
}else{
|
||||
ref = model.getReference();
|
||||
}
|
||||
return definitions.containsKey(ref)
|
||||
? getAllProperties(definitions, definitions.get(ref))
|
||||
: 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){
|
||||
if(handWrittenDescriptionsEnabled){
|
||||
String description = handWrittenPathDescription(definitionName.toLowerCase(), DESCRIPTION_FILE_NAME);
|
||||
if(isNotBlank(description)){
|
||||
docBuilder.paragraph(description);
|
||||
}else{
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Hand-written description cannot be read. Trying to use description from Swagger source.");
|
||||
}
|
||||
modelDescription(model, docBuilder);
|
||||
}
|
||||
}
|
||||
else{
|
||||
modelDescription(model, docBuilder);
|
||||
}
|
||||
}
|
||||
|
||||
private void modelDescription(Model model, MarkupDocBuilder docBuilder) {
|
||||
String description = model.getDescription();
|
||||
if (isNotBlank(description)) {
|
||||
docBuilder.paragraph(description);
|
||||
}
|
||||
}
|
||||
|
||||
private String propertyDescription(String definitionName, String propertyName, Property property) {
|
||||
String description;
|
||||
if(handWrittenDescriptionsEnabled){
|
||||
description = handWrittenPathDescription(definitionName.toLowerCase() + "/" + propertyName.toLowerCase(), DESCRIPTION_FILE_NAME);
|
||||
if(isBlank(description)) {
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Hand-written description file cannot be read. Trying to use description from Swagger source.");
|
||||
}
|
||||
description = defaultString(property.getDescription());
|
||||
}
|
||||
}
|
||||
else{
|
||||
description = 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
|
||||
*/
|
||||
private String handWrittenPathDescription(String descriptionFolder, String descriptionFileName){
|
||||
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);
|
||||
}
|
||||
try {
|
||||
return FileUtils.readFileToString(path.toFile(), StandardCharsets.UTF_8).trim();
|
||||
} catch (IOException e) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn(String.format("Failed to read description file: %s", path), e);
|
||||
}
|
||||
}
|
||||
} 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) {
|
||||
if(schemasEnabled) {
|
||||
if (isNotBlank(definitionName)) {
|
||||
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, MarkupDocBuilder docBuilder) {
|
||||
java.nio.file.Path path = Paths.get(schemasFolderPath, schemaName);
|
||||
if (Files.isReadable(path)) {
|
||||
docBuilder.sectionTitleLevel3(title);
|
||||
try {
|
||||
docBuilder.source(FileUtils.readFileToString(path.toFile(), StandardCharsets.UTF_8).trim(), language);
|
||||
} catch (IOException e) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn(String.format("Failed to read schema file: %s", path), e);
|
||||
}
|
||||
}
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Schema file processed: {}", path);
|
||||
}
|
||||
} else {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Schema file is not readable: {}", path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
*
|
||||
* 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 io.github.robwin.markup.builder.MarkupDocBuilder;
|
||||
import io.github.robwin.markup.builder.MarkupDocBuilders;
|
||||
import io.github.robwin.markup.builder.MarkupLanguage;
|
||||
import io.github.robwin.swagger2markup.config.Swagger2MarkupConfig;
|
||||
import io.swagger.models.Swagger;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public abstract class MarkupDocument {
|
||||
|
||||
protected static final String DELIMITER = "|";
|
||||
protected final String DEFAULT_COLUMN;
|
||||
protected final String REQUIRED_COLUMN;
|
||||
protected final String SCHEMA_COLUMN;
|
||||
protected final String NAME_COLUMN;
|
||||
protected final String DESCRIPTION_COLUMN;
|
||||
protected final String DESCRIPTION;
|
||||
protected final String PRODUCES;
|
||||
protected final String CONSUMES;
|
||||
protected final String TAGS;
|
||||
protected Logger logger = LoggerFactory.getLogger(getClass());
|
||||
protected Swagger swagger;
|
||||
protected MarkupLanguage markupLanguage;
|
||||
protected MarkupDocBuilder markupDocBuilder;
|
||||
|
||||
MarkupDocument(Swagger2MarkupConfig swagger2MarkupConfig){
|
||||
this.swagger = swagger2MarkupConfig.getSwagger();
|
||||
this.markupLanguage = swagger2MarkupConfig.getMarkupLanguage();
|
||||
this.markupDocBuilder = MarkupDocBuilders.documentBuilder(markupLanguage);
|
||||
|
||||
ResourceBundle labels = ResourceBundle.getBundle("lang/labels",
|
||||
swagger2MarkupConfig.getOutputLanguage().toLocale());
|
||||
DEFAULT_COLUMN = labels.getString("default_column");
|
||||
REQUIRED_COLUMN = labels.getString("required_column");
|
||||
SCHEMA_COLUMN = labels.getString("schema_column");
|
||||
NAME_COLUMN = labels.getString("name_column");
|
||||
DESCRIPTION_COLUMN = labels.getString("description_column");
|
||||
DESCRIPTION = DESCRIPTION_COLUMN;
|
||||
PRODUCES = labels.getString("produces");
|
||||
CONSUMES = labels.getString("consumes");
|
||||
TAGS = labels.getString("tags");
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the MarkupDocument.
|
||||
*
|
||||
* @return the built MarkupDocument
|
||||
* @throws IOException if the files to include are not readable
|
||||
*/
|
||||
public abstract MarkupDocument build() throws IOException ;
|
||||
|
||||
/**
|
||||
* Returns a string representation of the document.
|
||||
*/
|
||||
public String toString(){
|
||||
return markupDocBuilder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the content of the builder to a file and clears the builder.
|
||||
*
|
||||
* @param directory the directory where the generated file should be stored
|
||||
* @param fileName the name of the file
|
||||
* @param charset the the charset to use for encoding
|
||||
* @throws IOException if the file cannot be written
|
||||
*/
|
||||
public void writeToFile(String directory, String fileName, Charset charset) throws IOException{
|
||||
markupDocBuilder.writeToFile(directory, fileName, charset);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
/*
|
||||
*
|
||||
* 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 io.github.robwin.swagger2markup.config.Swagger2MarkupConfig;
|
||||
import io.swagger.models.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import static org.apache.commons.collections.CollectionUtils.isNotEmpty;
|
||||
import static org.apache.commons.lang3.StringUtils.*;
|
||||
|
||||
public class OverviewDocument extends MarkupDocument {
|
||||
|
||||
private final String OVERVIEW;
|
||||
private final String CURRENT_VERSION;
|
||||
private final String VERSION;
|
||||
private final String CONTACT_INFORMATION;
|
||||
private final String CONTACT_NAME;
|
||||
private final String CONTACT_EMAIL;
|
||||
private final String LICENSE_INFORMATION;
|
||||
private final String LICENSE;
|
||||
private final String LICENSE_URL;
|
||||
private final String TERMS_OF_SERVICE;
|
||||
private final String URI_SCHEME;
|
||||
private final String HOST;
|
||||
private final String BASE_PATH;
|
||||
private final String SCHEMES;
|
||||
|
||||
public OverviewDocument(Swagger2MarkupConfig swagger2MarkupConfig){
|
||||
super(swagger2MarkupConfig);
|
||||
|
||||
ResourceBundle labels = ResourceBundle.getBundle("lang/labels",
|
||||
swagger2MarkupConfig.getOutputLanguage().toLocale());
|
||||
OVERVIEW = labels.getString("overview");
|
||||
CURRENT_VERSION = labels.getString("current_version");
|
||||
VERSION = labels.getString("version");
|
||||
CONTACT_INFORMATION = labels.getString("contact_information");
|
||||
CONTACT_NAME = labels.getString("contact_name");
|
||||
CONTACT_EMAIL = labels.getString("contact_email");
|
||||
LICENSE_INFORMATION = labels.getString("license_information");
|
||||
LICENSE = labels.getString("license");
|
||||
LICENSE_URL = labels.getString("license_url");
|
||||
TERMS_OF_SERVICE = labels.getString("terms_of_service");
|
||||
URI_SCHEME = labels.getString("uri_scheme");
|
||||
HOST = labels.getString("host");
|
||||
BASE_PATH = labels.getString("base_path");
|
||||
SCHEMES = labels.getString("schemes");
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the MarkupDocument.
|
||||
*
|
||||
* @return the built MarkupDocument
|
||||
*/
|
||||
@Override
|
||||
public MarkupDocument build(){
|
||||
overview();
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Builds the document header of the swagger model
|
||||
*/
|
||||
private void overview() {
|
||||
Info info = swagger.getInfo();
|
||||
this.markupDocBuilder.documentTitle(info.getTitle());
|
||||
this.markupDocBuilder.sectionTitleLevel1(OVERVIEW);
|
||||
if(isNotBlank(info.getDescription())){
|
||||
this.markupDocBuilder.textLine(info.getDescription());
|
||||
this.markupDocBuilder.newLine();
|
||||
}
|
||||
if(isNotBlank(info.getVersion())){
|
||||
this.markupDocBuilder.sectionTitleLevel2(CURRENT_VERSION);
|
||||
this.markupDocBuilder.textLine(VERSION + info.getVersion());
|
||||
this.markupDocBuilder.newLine();
|
||||
}
|
||||
Contact contact = info.getContact();
|
||||
if(contact != null){
|
||||
this.markupDocBuilder.sectionTitleLevel2(CONTACT_INFORMATION);
|
||||
if(isNotBlank(contact.getName())){
|
||||
this.markupDocBuilder.textLine(CONTACT_NAME + contact.getName());
|
||||
}
|
||||
if(isNotBlank(contact.getEmail())){
|
||||
this.markupDocBuilder.textLine(CONTACT_EMAIL + contact.getEmail());
|
||||
}
|
||||
this.markupDocBuilder.newLine();
|
||||
}
|
||||
|
||||
License license = info.getLicense();
|
||||
if(license != null && (isNotBlank(license.getName()) || isNotBlank(license.getUrl()))) {
|
||||
this.markupDocBuilder.sectionTitleLevel2(LICENSE_INFORMATION);
|
||||
if (isNotBlank(license.getName())) {
|
||||
this.markupDocBuilder.textLine(LICENSE + license.getName());
|
||||
}
|
||||
if (isNotBlank(license.getUrl())) {
|
||||
this.markupDocBuilder.textLine(LICENSE_URL + license.getUrl());
|
||||
}
|
||||
this.markupDocBuilder.newLine();
|
||||
}
|
||||
if(isNotBlank(info.getTermsOfService())){
|
||||
this.markupDocBuilder.textLine(TERMS_OF_SERVICE + info.getTermsOfService());
|
||||
this.markupDocBuilder.newLine();
|
||||
}
|
||||
|
||||
if(isNotBlank(swagger.getHost()) || isNotBlank(swagger.getBasePath()) || isNotEmpty(swagger.getSchemes())) {
|
||||
this.markupDocBuilder.sectionTitleLevel2(URI_SCHEME);
|
||||
if (isNotBlank(swagger.getHost())) {
|
||||
this.markupDocBuilder.textLine(HOST + swagger.getHost());
|
||||
}
|
||||
if (isNotBlank(swagger.getBasePath())) {
|
||||
this.markupDocBuilder.textLine(BASE_PATH + swagger.getBasePath());
|
||||
}
|
||||
if (isNotEmpty(swagger.getSchemes())) {
|
||||
List<String> schemes = new ArrayList<>();
|
||||
for (Scheme scheme : swagger.getSchemes()) {
|
||||
schemes.add(scheme.toString());
|
||||
}
|
||||
this.markupDocBuilder.textLine(SCHEMES + join(schemes, ", "));
|
||||
}
|
||||
this.markupDocBuilder.newLine();
|
||||
}
|
||||
|
||||
if(isNotEmpty(swagger.getTags())){
|
||||
this.markupDocBuilder.sectionTitleLevel2(TAGS);
|
||||
List<String> tags = new ArrayList<>();
|
||||
for(Tag tag : swagger.getTags()){
|
||||
String name = tag.getName();
|
||||
String description = tag.getDescription();
|
||||
if(isNoneBlank(description)){
|
||||
tags.add(name + ": " + description);
|
||||
}else{
|
||||
tags.add(name);
|
||||
}
|
||||
}
|
||||
this.markupDocBuilder.unorderedList(tags);
|
||||
this.markupDocBuilder.newLine();
|
||||
}
|
||||
|
||||
if(isNotEmpty(swagger.getConsumes())){
|
||||
this.markupDocBuilder.sectionTitleLevel2(CONSUMES);
|
||||
this.markupDocBuilder.unorderedList(swagger.getConsumes());
|
||||
this.markupDocBuilder.newLine();
|
||||
}
|
||||
|
||||
if(isNotEmpty(swagger.getProduces())){
|
||||
this.markupDocBuilder.sectionTitleLevel2(PRODUCES);
|
||||
this.markupDocBuilder.unorderedList(swagger.getProduces());
|
||||
this.markupDocBuilder.newLine();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,506 @@
|
||||
/*
|
||||
*
|
||||
* 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.google.common.base.Optional;
|
||||
import com.google.common.collect.Multimap;
|
||||
import io.github.robwin.swagger2markup.GroupBy;
|
||||
import io.github.robwin.swagger2markup.config.Swagger2MarkupConfig;
|
||||
import io.github.robwin.swagger2markup.utils.ParameterUtils;
|
||||
import io.github.robwin.swagger2markup.utils.PropertyUtils;
|
||||
import io.swagger.models.*;
|
||||
import io.swagger.models.parameters.Parameter;
|
||||
import io.swagger.models.properties.Property;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.lang3.text.WordUtils;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.*;
|
||||
|
||||
import static io.github.robwin.swagger2markup.utils.TagUtils.*;
|
||||
import static org.apache.commons.lang3.StringUtils.*;
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public class PathsDocument extends MarkupDocument {
|
||||
|
||||
private final String PATHS;
|
||||
private final String RESOURCES;
|
||||
private final String PARAMETERS;
|
||||
private final String RESPONSES;
|
||||
private final String EXAMPLE_CURL;
|
||||
private final String EXAMPLE_REQUEST;
|
||||
private final String EXAMPLE_RESPONSE;
|
||||
private final String TYPE_COLUMN;
|
||||
private final String HTTP_CODE_COLUMN;
|
||||
private final String REQUEST_EXAMPLE_FILE_NAME;
|
||||
private final String RESPONSE_EXAMPLE_FILE_NAME;
|
||||
private final String CURL_EXAMPLE_FILE_NAME;
|
||||
private final String DESCRIPTION_FILE_NAME;
|
||||
private final String PARAMETER;
|
||||
|
||||
private boolean examplesEnabled;
|
||||
private String examplesFolderPath;
|
||||
private boolean handWrittenDescriptionsEnabled;
|
||||
private String descriptionsFolderPath;
|
||||
private final GroupBy pathsGroupedBy;
|
||||
|
||||
public PathsDocument(Swagger2MarkupConfig swagger2MarkupConfig){
|
||||
super(swagger2MarkupConfig);
|
||||
|
||||
ResourceBundle labels = ResourceBundle.getBundle("lang/labels",
|
||||
swagger2MarkupConfig.getOutputLanguage().toLocale());
|
||||
PATHS = labels.getString("paths");
|
||||
RESOURCES = labels.getString("resources");
|
||||
PARAMETERS = labels.getString("parameters");
|
||||
RESPONSES = labels.getString("responses");
|
||||
EXAMPLE_CURL = labels.getString("example_curl");
|
||||
EXAMPLE_REQUEST = labels.getString("example_request");
|
||||
EXAMPLE_RESPONSE = labels.getString("example_response");
|
||||
TYPE_COLUMN = labels.getString("type_column");
|
||||
HTTP_CODE_COLUMN = labels.getString("http_code_column");
|
||||
REQUEST_EXAMPLE_FILE_NAME = labels.getString("request_example_file_name");
|
||||
RESPONSE_EXAMPLE_FILE_NAME = labels.getString("response_example_file_name");
|
||||
CURL_EXAMPLE_FILE_NAME = labels.getString("curl_example_file_name");
|
||||
DESCRIPTION_FILE_NAME = labels.getString("description_file_name");
|
||||
PARAMETER = labels.getString("parameter");
|
||||
|
||||
this.pathsGroupedBy = swagger2MarkupConfig.getPathsGroupedBy();
|
||||
if(isNotBlank(swagger2MarkupConfig.getExamplesFolderPath())){
|
||||
this.examplesEnabled = true;
|
||||
this.examplesFolderPath = swagger2MarkupConfig.getExamplesFolderPath();
|
||||
}
|
||||
if(isNotBlank(swagger2MarkupConfig.getDescriptionsFolderPath())){
|
||||
this.handWrittenDescriptionsEnabled = true;
|
||||
this.descriptionsFolderPath = swagger2MarkupConfig.getDescriptionsFolderPath() + "/" + PATHS.toLowerCase();
|
||||
}
|
||||
if(examplesEnabled){
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Include examples is enabled.");
|
||||
}
|
||||
}else{
|
||||
if (logger.isDebugEnabled()) {
|
||||
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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the paths markup document.
|
||||
*
|
||||
* @return the the paths markup document
|
||||
*/
|
||||
@Override
|
||||
public MarkupDocument build(){
|
||||
paths();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds all paths of the Swagger model. Either grouped as-is or by tags.
|
||||
*/
|
||||
private void paths(){
|
||||
Map<String, Path> paths = swagger.getPaths();
|
||||
if(MapUtils.isNotEmpty(paths)) {
|
||||
if(pathsGroupedBy.equals(GroupBy.AS_IS)){
|
||||
this.markupDocBuilder.sectionTitleLevel1(PATHS);
|
||||
for (Map.Entry<String, Path> pathEntry : paths.entrySet()) {
|
||||
Path path = pathEntry.getValue();
|
||||
if(path != null) {
|
||||
createPathSections(pathEntry.getKey(), path);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
this.markupDocBuilder.sectionTitleLevel1(RESOURCES);
|
||||
Multimap<String, Pair<String, Path>> pathsGroupedByTag = groupPathsByTag(paths);
|
||||
Map<String, Tag> tagsMap = convertTagsListToMap(swagger.getTags());
|
||||
for(String tagName : pathsGroupedByTag.keySet()){
|
||||
this.markupDocBuilder.sectionTitleLevel2(WordUtils.capitalize(tagName));
|
||||
Optional<String> tagDescription = getTagDescription(tagsMap, tagName);
|
||||
if(tagDescription.isPresent()) {
|
||||
this.markupDocBuilder.paragraph(tagDescription.get());
|
||||
}
|
||||
Collection<Pair<String, Path>> pathsOfTag = pathsGroupedByTag.get(tagName);
|
||||
for(Pair<String, Path> pathPair : pathsOfTag){
|
||||
Path path = pathPair.getValue();
|
||||
if(path != null) {
|
||||
createPathSections(pathPair.getKey(), path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void createPathSections(String pathUrl, Path path){
|
||||
for(Map.Entry<HttpMethod, Operation> operationEntry : path.getOperationMap().entrySet()){
|
||||
String methodAndPath = operationEntry.getKey() + " " + pathUrl;
|
||||
path(methodAndPath, operationEntry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a path.
|
||||
*
|
||||
* @param methodAndPath the Method of the operation and the URL of the path
|
||||
* @param operation the Swagger Operation
|
||||
*/
|
||||
private void path(String methodAndPath, Operation operation) {
|
||||
if(operation != null){
|
||||
pathTitle(methodAndPath, operation);
|
||||
descriptionSection(operation);
|
||||
parametersSection(operation);
|
||||
responsesSection(operation);
|
||||
consumesSection(operation);
|
||||
producesSection(operation);
|
||||
tagsSection(operation);
|
||||
examplesSection(operation);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the path title to the document. If the operation has a summary, the title is the summary.
|
||||
* Otherwise the title is the method of the operation and the URL of the path.
|
||||
*
|
||||
* @param methodAndPath the Method of the operation and the URL of the path
|
||||
* @param operation the Swagger Operation
|
||||
*/
|
||||
private void pathTitle(String methodAndPath, Operation operation) {
|
||||
String summary = operation.getSummary();
|
||||
String title;
|
||||
if(isNotBlank(summary)) {
|
||||
title = summary;
|
||||
addPathTitle(title);
|
||||
this.markupDocBuilder.listing(methodAndPath);
|
||||
}else{
|
||||
addPathTitle(methodAndPath);
|
||||
}
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Path processed: {}", methodAndPath);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a path title to the document.
|
||||
*
|
||||
* @param title the path title
|
||||
*/
|
||||
private void addPathTitle(String title) {
|
||||
if(pathsGroupedBy.equals(GroupBy.AS_IS)){
|
||||
this.markupDocBuilder.sectionTitleLevel2(title);
|
||||
}else{
|
||||
this.markupDocBuilder.sectionTitleLevel3(title);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a path description to the document.
|
||||
*
|
||||
* @param operation the Swagger Operation
|
||||
*/
|
||||
private void descriptionSection(Operation operation) {
|
||||
if(handWrittenDescriptionsEnabled){
|
||||
String summary = operation.getSummary();
|
||||
if(isNotBlank(summary)) {
|
||||
String operationFolder = summary.replace(".", "").replace(" ", "_").toLowerCase();
|
||||
Optional<String> description = handWrittenPathDescription(operationFolder, DESCRIPTION_FILE_NAME);
|
||||
if(description.isPresent()){
|
||||
pathDescription(description.get());
|
||||
}else{
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Hand-written description cannot be read. Trying to use description from Swagger source.");
|
||||
}
|
||||
pathDescription(operation.getDescription());
|
||||
}
|
||||
}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.getDescription());
|
||||
}
|
||||
}else {
|
||||
pathDescription(operation.getDescription());
|
||||
}
|
||||
}
|
||||
|
||||
private void pathDescription(String description) {
|
||||
if (isNotBlank(description)) {
|
||||
if(pathsGroupedBy.equals(GroupBy.AS_IS)){
|
||||
this.markupDocBuilder.sectionTitleLevel3(DESCRIPTION);
|
||||
}else{
|
||||
this.markupDocBuilder.sectionTitleLevel4(DESCRIPTION);
|
||||
}
|
||||
this.markupDocBuilder.paragraph(description);
|
||||
}
|
||||
}
|
||||
|
||||
private void parametersSection(Operation operation) {
|
||||
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, DEFAULT_COLUMN);
|
||||
headerAndContent.add(join(header, DELIMITER));
|
||||
for(Parameter parameter : parameters){
|
||||
String type = ParameterUtils.getType(parameter, markupLanguage);
|
||||
String parameterType = WordUtils.capitalize(parameter.getIn() + PARAMETER);
|
||||
// Table content row
|
||||
List<String> content = Arrays.asList(
|
||||
parameterType,
|
||||
parameter.getName(),
|
||||
parameterDescription(operation, parameter),
|
||||
Boolean.toString(parameter.getRequired()), type,
|
||||
ParameterUtils.getDefaultValue(parameter));
|
||||
headerAndContent.add(join(content, DELIMITER));
|
||||
}
|
||||
if(pathsGroupedBy.equals(GroupBy.AS_IS)){
|
||||
this.markupDocBuilder.sectionTitleLevel3(PARAMETERS);
|
||||
}else{
|
||||
this.markupDocBuilder.sectionTitleLevel4(PARAMETERS);
|
||||
}
|
||||
this.markupDocBuilder.tableWithHeaderRow(headerAndContent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the description of a parameter, or otherwise an empty String.
|
||||
* If hand-written descriptions are enabled, it tries to load the description from a file.
|
||||
* If the file cannot be read, the description the parameter is returned.
|
||||
*
|
||||
* @param operation the Swagger Operation
|
||||
* @param parameter the Swagger Parameter
|
||||
* @return the description of a parameter.
|
||||
*/
|
||||
private String parameterDescription(Operation operation, Parameter parameter){
|
||||
if(handWrittenDescriptionsEnabled){
|
||||
String summary = operation.getSummary();
|
||||
String operationFolder = summary.replace(".", "").replace(" ", "_").toLowerCase();
|
||||
String parameterName = parameter.getName();
|
||||
if(isNotBlank(operationFolder) && isNotBlank(parameterName)) {
|
||||
Optional<String> description = handWrittenPathDescription(operationFolder + "/" + parameterName, DESCRIPTION_FILE_NAME);
|
||||
if(description.isPresent()){
|
||||
return description.get();
|
||||
}
|
||||
else{
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("Hand-written description file cannot be read. Trying to use description from Swagger source.");
|
||||
}
|
||||
return defaultString(parameter.getDescription());
|
||||
}
|
||||
}else{
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("Hand-written description file cannot be read, because summary of operation or name of parameter is empty. Trying to use description from Swagger source.");
|
||||
}
|
||||
return defaultString(parameter.getDescription());
|
||||
}
|
||||
}else {
|
||||
return defaultString(parameter.getDescription());
|
||||
}
|
||||
}
|
||||
|
||||
private void consumesSection(Operation operation) {
|
||||
List<String> consumes = operation.getConsumes();
|
||||
if(CollectionUtils.isNotEmpty(consumes)){
|
||||
if(pathsGroupedBy.equals(GroupBy.AS_IS)){
|
||||
this.markupDocBuilder.sectionTitleLevel3(CONSUMES);
|
||||
}else{
|
||||
this.markupDocBuilder.sectionTitleLevel4(CONSUMES);
|
||||
}
|
||||
this.markupDocBuilder.unorderedList(consumes);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void producesSection(Operation operation) {
|
||||
List<String> produces = operation.getProduces();
|
||||
if(CollectionUtils.isNotEmpty(produces)){
|
||||
if(pathsGroupedBy.equals(GroupBy.AS_IS)){
|
||||
this.markupDocBuilder.sectionTitleLevel3(PRODUCES);
|
||||
}else{
|
||||
this.markupDocBuilder.sectionTitleLevel4(PRODUCES);
|
||||
}
|
||||
this.markupDocBuilder.unorderedList(produces);
|
||||
}
|
||||
}
|
||||
|
||||
private void tagsSection(Operation operation) {
|
||||
if(pathsGroupedBy.equals(GroupBy.AS_IS)) {
|
||||
List<String> tags = operation.getTags();
|
||||
if (CollectionUtils.isNotEmpty(tags)) {
|
||||
this.markupDocBuilder.sectionTitleLevel3(TAGS);
|
||||
this.markupDocBuilder.unorderedList(tags);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the example section of a Swagger Operation. Tries to load the examples from
|
||||
* curl-request.adoc, http-request.adoc and http-response.adoc or
|
||||
* curl-request.md, http-request.md and http-response.md.
|
||||
*
|
||||
* @param operation the Swagger Operation
|
||||
*/
|
||||
private void examplesSection(Operation operation) {
|
||||
if(examplesEnabled){
|
||||
String summary = operation.getSummary();
|
||||
if(isNotBlank(summary)) {
|
||||
String exampleFolder = summary.replace(".", "").replace(" ", "_").toLowerCase();
|
||||
Optional<String> curlExample = example(exampleFolder, CURL_EXAMPLE_FILE_NAME);
|
||||
if(curlExample.isPresent()){
|
||||
if(pathsGroupedBy.equals(GroupBy.AS_IS)){
|
||||
this.markupDocBuilder.sectionTitleLevel3(EXAMPLE_CURL);
|
||||
}else{
|
||||
this.markupDocBuilder.sectionTitleLevel4(EXAMPLE_CURL);
|
||||
}
|
||||
this.markupDocBuilder.paragraph(curlExample.get());
|
||||
}
|
||||
|
||||
Optional<String> requestExample = example(exampleFolder, REQUEST_EXAMPLE_FILE_NAME);
|
||||
if(requestExample.isPresent()){
|
||||
if(pathsGroupedBy.equals(GroupBy.AS_IS)){
|
||||
this.markupDocBuilder.sectionTitleLevel3(EXAMPLE_REQUEST);
|
||||
}else{
|
||||
this.markupDocBuilder.sectionTitleLevel4(EXAMPLE_REQUEST);
|
||||
}
|
||||
this.markupDocBuilder.paragraph(requestExample.get());
|
||||
}
|
||||
Optional<String> responseExample = example(exampleFolder, RESPONSE_EXAMPLE_FILE_NAME);
|
||||
if(responseExample.isPresent()){
|
||||
if(pathsGroupedBy.equals(GroupBy.AS_IS)){
|
||||
this.markupDocBuilder.sectionTitleLevel3(EXAMPLE_RESPONSE);
|
||||
}else{
|
||||
this.markupDocBuilder.sectionTitleLevel4(EXAMPLE_RESPONSE);
|
||||
}
|
||||
this.markupDocBuilder.paragraph(responseExample.get());
|
||||
}
|
||||
}else{
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("Example file cannot be read, because summary of operation is empty.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an 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
|
||||
*/
|
||||
private Optional<String> example(String exampleFolder, String exampleFileName) {
|
||||
for (String fileNameExtension : markupLanguage.getFileNameExtensions()) {
|
||||
java.nio.file.Path path = Paths.get(examplesFolderPath, exampleFolder, exampleFileName + fileNameExtension);
|
||||
if (Files.isReadable(path)) {
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Example file processed: {}", path);
|
||||
}
|
||||
try {
|
||||
return Optional.fromNullable(FileUtils.readFileToString(path.toFile(), StandardCharsets.UTF_8).trim());
|
||||
} catch (IOException e) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn(String.format("Failed to read example file: %s", path), e);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("Example file is not readable: {}", path);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("No example file found with correct file name extension in folder: {}", Paths.get(examplesFolderPath, exampleFolder));
|
||||
}
|
||||
return Optional.absent();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
private Optional<String> handWrittenPathDescription(String descriptionFolder, String descriptionFileName){
|
||||
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);
|
||||
}
|
||||
try {
|
||||
return Optional.fromNullable(FileUtils.readFileToString(path.toFile(), StandardCharsets.UTF_8).trim());
|
||||
} catch (IOException e) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn(String.format("Failed to read description file: %s", path), e);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("Description file is not readable: {}", path);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("No description file found with correct file name extension in folder: {}", Paths.get(descriptionsFolderPath, descriptionFolder));
|
||||
}
|
||||
return Optional.absent();
|
||||
}
|
||||
|
||||
private void responsesSection(Operation operation) {
|
||||
Map<String, Response> responses = operation.getResponses();
|
||||
if(MapUtils.isNotEmpty(responses)){
|
||||
List<String> csvContent = new ArrayList<>();
|
||||
csvContent.add(HTTP_CODE_COLUMN + DELIMITER + DESCRIPTION_COLUMN + DELIMITER + SCHEMA_COLUMN);
|
||||
for(Map.Entry<String, Response> entry : responses.entrySet()){
|
||||
Response response = entry.getValue();
|
||||
if(response.getSchema() != null){
|
||||
Property property = response.getSchema();
|
||||
String type = PropertyUtils.getType(property, markupLanguage);
|
||||
csvContent.add(entry.getKey() + DELIMITER + response.getDescription() + DELIMITER + type);
|
||||
}else{
|
||||
csvContent.add(entry.getKey() + DELIMITER + response.getDescription() + DELIMITER + "No Content");
|
||||
}
|
||||
}
|
||||
if(pathsGroupedBy.equals(GroupBy.AS_IS)){
|
||||
this.markupDocBuilder.sectionTitleLevel3(RESPONSES);
|
||||
}else{
|
||||
this.markupDocBuilder.sectionTitleLevel4(RESPONSES);
|
||||
}
|
||||
this.markupDocBuilder.tableWithHeaderRow(csvContent);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
*
|
||||
* 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.config;
|
||||
|
||||
import io.github.robwin.markup.builder.MarkupLanguage;
|
||||
import io.github.robwin.swagger2markup.GroupBy;
|
||||
import io.github.robwin.swagger2markup.Language;
|
||||
import io.github.robwin.swagger2markup.OrderBy;
|
||||
import io.swagger.models.Swagger;
|
||||
|
||||
public class Swagger2MarkupConfig {
|
||||
|
||||
private final Swagger swagger;
|
||||
private final MarkupLanguage markupLanguage;
|
||||
private final String examplesFolderPath;
|
||||
private final String schemasFolderPath;
|
||||
private final String descriptionsFolderPath;
|
||||
private final boolean separatedDefinitions;
|
||||
private final GroupBy pathsGroupedBy;
|
||||
private final OrderBy definitionsOrderedBy;
|
||||
private final Language outputLanguage;
|
||||
|
||||
/**
|
||||
* @param swagger the Swagger source
|
||||
* @param markupLanguage the markup language which is used to generate the files
|
||||
* @param examplesFolderPath examplesFolderPath the path to the folder where the example documents reside
|
||||
* @param schemasFolderPath the path to the folder where the schema documents reside
|
||||
* @param descriptionsFolderPath the path to the folder where the description documents reside
|
||||
* @param separatedDefinitions specified if in addition to the definitions file, also separate definition files for each model definition should be created
|
||||
* @param pathsGroupedBy specifies if the paths should be grouped by tags or stay as-is
|
||||
* @param definitionsOrderedBy specifies if the definitions should be ordered by natural ordering or stay as-is
|
||||
* @param outputLanguage specifies language of labels in output files
|
||||
*/
|
||||
public Swagger2MarkupConfig(Swagger swagger, MarkupLanguage markupLanguage, String examplesFolderPath,
|
||||
String schemasFolderPath, String descriptionsFolderPath, boolean separatedDefinitions,
|
||||
GroupBy pathsGroupedBy, OrderBy definitionsOrderedBy, Language outputLanguage) {
|
||||
this.swagger = swagger;
|
||||
this.markupLanguage = markupLanguage;
|
||||
this.examplesFolderPath = examplesFolderPath;
|
||||
this.schemasFolderPath = schemasFolderPath;
|
||||
this.descriptionsFolderPath = descriptionsFolderPath;
|
||||
this.separatedDefinitions = separatedDefinitions;
|
||||
this.pathsGroupedBy = pathsGroupedBy;
|
||||
this.definitionsOrderedBy = definitionsOrderedBy;
|
||||
this.outputLanguage = outputLanguage;
|
||||
}
|
||||
|
||||
public Swagger getSwagger() {
|
||||
return swagger;
|
||||
}
|
||||
|
||||
public MarkupLanguage getMarkupLanguage() {
|
||||
return markupLanguage;
|
||||
}
|
||||
|
||||
public String getExamplesFolderPath() {
|
||||
return examplesFolderPath;
|
||||
}
|
||||
|
||||
public String getSchemasFolderPath() {
|
||||
return schemasFolderPath;
|
||||
}
|
||||
|
||||
public String getDescriptionsFolderPath() {
|
||||
return descriptionsFolderPath;
|
||||
}
|
||||
|
||||
public boolean isSeparatedDefinitions() {
|
||||
return separatedDefinitions;
|
||||
}
|
||||
|
||||
public GroupBy getPathsGroupedBy() {
|
||||
return pathsGroupedBy;
|
||||
}
|
||||
|
||||
public OrderBy getDefinitionsOrderedBy() {
|
||||
return definitionsOrderedBy;
|
||||
}
|
||||
|
||||
public Language getOutputLanguage() {
|
||||
return outputLanguage;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
*
|
||||
* 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 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;
|
||||
|
||||
public final class ModelUtils {
|
||||
|
||||
/**
|
||||
* Retrieves the type of a model, or otherwise "NOT FOUND"
|
||||
*
|
||||
* @param model the model
|
||||
* @param markupLanguage the markup language which is used to generate the files
|
||||
* @return the type of the model, or otherwise "NOT FOUND"
|
||||
*/
|
||||
public static String getType(Model model, MarkupLanguage markupLanguage) {
|
||||
Validate.notNull(model, "model must not be null!");
|
||||
if (model instanceof ModelImpl) {
|
||||
return ((ModelImpl) model).getType();
|
||||
} else if (model instanceof RefModel) {
|
||||
switch (markupLanguage){
|
||||
case ASCIIDOC: return "<<" + ((RefModel) model).getSimpleRef() + ">>";
|
||||
default: return ((RefModel) model).getSimpleRef();
|
||||
}
|
||||
} else if (model instanceof ArrayModel) {
|
||||
ArrayModel arrayModel = ((ArrayModel) model);
|
||||
return PropertyUtils.getType(arrayModel.getItems(), markupLanguage) + " " + arrayModel.getType();
|
||||
}
|
||||
return "NOT FOUND";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
*
|
||||
* 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 io.github.robwin.markup.builder.MarkupLanguage;
|
||||
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 org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.*;
|
||||
|
||||
|
||||
public final class ParameterUtils {
|
||||
|
||||
/**
|
||||
* Retrieves the type of a parameter, or otherwise an empty String
|
||||
*
|
||||
* @param parameter the parameter
|
||||
* @param markupLanguage the markup language which is used to generate the files
|
||||
* @return the type of the parameter, or otherwise an empty String
|
||||
*/
|
||||
public static String getType(Parameter parameter, MarkupLanguage markupLanguage){
|
||||
Validate.notNull(parameter, "property must not be null!");
|
||||
String type = "NOT FOUND";
|
||||
if(parameter instanceof BodyParameter){
|
||||
BodyParameter bodyParameter = (BodyParameter)parameter;
|
||||
Model model = bodyParameter.getSchema();
|
||||
if(model != null){
|
||||
type = ModelUtils.getType(model, markupLanguage);
|
||||
}else{
|
||||
type = "string";
|
||||
}
|
||||
|
||||
}
|
||||
else if(parameter instanceof AbstractSerializableParameter){
|
||||
AbstractSerializableParameter serializableParameter = (AbstractSerializableParameter)parameter;
|
||||
List enums = serializableParameter.getEnum();
|
||||
if(CollectionUtils.isNotEmpty(enums)){
|
||||
type = "enum" + " (" + join(enums, ", ") + ")";
|
||||
}else{
|
||||
type = getTypeWithFormat(serializableParameter.getType(), serializableParameter.getFormat());
|
||||
}
|
||||
if(type.equals("array")){
|
||||
String collectionFormat = serializableParameter.getCollectionFormat();
|
||||
type = collectionFormat + " " + PropertyUtils.getType(serializableParameter.getItems(), markupLanguage) + " " + type;
|
||||
}
|
||||
}
|
||||
else if(parameter instanceof RefParameter){
|
||||
RefParameter refParameter = (RefParameter)parameter;
|
||||
switch (markupLanguage){
|
||||
case ASCIIDOC: return "<<" + refParameter.getSimpleRef() + ">>";
|
||||
default: return refParameter.getSimpleRef();
|
||||
}
|
||||
}
|
||||
return defaultString(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the format to the type, if a format is available
|
||||
*
|
||||
* @param typeWithoutFormat the type
|
||||
* @param format the format
|
||||
* @return returns the type and format, if a format is available
|
||||
*/
|
||||
private static String getTypeWithFormat(String typeWithoutFormat, String format) {
|
||||
String type;
|
||||
if(isNotBlank(format)){
|
||||
type = defaultString(typeWithoutFormat) + " (" + format + ")";
|
||||
}else{
|
||||
type = defaultString(typeWithoutFormat);
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the default value of a parameter, or otherwise an empty String
|
||||
*
|
||||
* @param parameter the parameter
|
||||
* @return the default value of the parameter, or otherwise an empty String
|
||||
*/
|
||||
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 defaultString(defaultValue);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
*
|
||||
* 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 io.github.robwin.markup.builder.MarkupLanguage;
|
||||
import io.swagger.models.properties.*;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.*;
|
||||
|
||||
public final class PropertyUtils {
|
||||
|
||||
/**
|
||||
* Retrieves the type and format of a property.
|
||||
*
|
||||
* @param property the property
|
||||
* @param markupLanguage the markup language which is used to generate the files
|
||||
* @return the type of the property
|
||||
*/
|
||||
public static String getType(Property property, MarkupLanguage markupLanguage){
|
||||
Validate.notNull(property, "property must not be null!");
|
||||
String type;
|
||||
if(property instanceof RefProperty){
|
||||
RefProperty refProperty = (RefProperty)property;
|
||||
switch (markupLanguage){
|
||||
case ASCIIDOC: return "<<" + refProperty.getSimpleRef() + ">>";
|
||||
default: return refProperty.getSimpleRef();
|
||||
}
|
||||
}else if(property instanceof ArrayProperty){
|
||||
ArrayProperty arrayProperty = (ArrayProperty)property;
|
||||
Property items = arrayProperty.getItems();
|
||||
type = getType(items, markupLanguage) + " " + arrayProperty.getType();
|
||||
}else if(property instanceof StringProperty){
|
||||
StringProperty stringProperty = (StringProperty)property;
|
||||
List<String> enums = stringProperty.getEnum();
|
||||
if(CollectionUtils.isNotEmpty(enums)){
|
||||
type = "enum" + " (" + join(enums, ", ") + ")";
|
||||
}else{
|
||||
type = property.getType();
|
||||
}
|
||||
}
|
||||
else{
|
||||
if(isNotBlank(property.getFormat())){
|
||||
type = defaultString(property.getType()) + " (" + property.getFormat() + ")";
|
||||
}else{
|
||||
type = property.getType();
|
||||
}
|
||||
}
|
||||
return defaultString(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the default value of a property, or otherwise returns an empty String.
|
||||
*
|
||||
* @param property the property
|
||||
* @return the default value of the property, or otherwise an empty String
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
*
|
||||
* 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.google.common.base.Optional;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.MultimapBuilder;
|
||||
import io.swagger.models.HttpMethod;
|
||||
import io.swagger.models.Operation;
|
||||
import io.swagger.models.Path;
|
||||
import io.swagger.models.Tag;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class TagUtils {
|
||||
|
||||
private static Logger LOG = LoggerFactory.getLogger(TagUtils.class);
|
||||
|
||||
/**
|
||||
* Converts the global Tag list into a Map where the tag name is the key and the Tag the value.
|
||||
*
|
||||
* @param tags the List of tags
|
||||
* @return the Map of tags
|
||||
*/
|
||||
public static Map<String, Tag> convertTagsListToMap(List<Tag> tags) {
|
||||
if (tags == null) {
|
||||
tags = new ArrayList<>();
|
||||
}
|
||||
Map<String, Tag> tagsMap = new HashMap<>();
|
||||
for (Tag tag : tags) tagsMap.put(tag.getName(), tag);
|
||||
return tagsMap;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the optional description of a tag.
|
||||
*
|
||||
* @param tagsMap the Map of tags
|
||||
* @param tagName the name of the tag
|
||||
* @return the optional description of the tag
|
||||
*/
|
||||
public static Optional<String> getTagDescription(Map<String, Tag> tagsMap, String tagName) {
|
||||
Tag tag = tagsMap.get(tagName);
|
||||
if(tag != null){
|
||||
return Optional.fromNullable(tag.getDescription());
|
||||
}
|
||||
return Optional.absent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Groups the paths by tag. The key of the Multimap is the tag name.
|
||||
* The value of the Multimap is a Pair which contains the Method and the Path.
|
||||
*
|
||||
* @param paths the Paths
|
||||
* @return Paths grouped by Tag
|
||||
*/
|
||||
public static Multimap<String, Pair<String, Path>> groupPathsByTag(Map<String, Path> paths) {
|
||||
Multimap<String, Pair<String, Path>> pathsGroupedByTag = MultimapBuilder.SortedSetMultimapBuilder.treeKeys().hashSetValues().build();
|
||||
for (Map.Entry<String, Path> pathEntry : paths.entrySet()) {
|
||||
String resourcePath = pathEntry.getKey();
|
||||
Path path = pathEntry.getValue();
|
||||
for(Map.Entry<HttpMethod, Operation> operationEntry : path.getOperationMap().entrySet()){
|
||||
HttpMethod httpMethod = operationEntry.getKey();
|
||||
Operation operation = operationEntry.getValue();
|
||||
if(operation != null) {
|
||||
List<String> tags = operation.getTags();
|
||||
Validate.notEmpty(tags, "Path operations must have tags, if you want to group by tags! The operation '%s %s' has not tags.", httpMethod, resourcePath);
|
||||
for (String tag : tags) {
|
||||
if (LOG.isInfoEnabled()) {
|
||||
LOG.info("Added path operation '{} {}' to tag '{}'", httpMethod, resourcePath, tag);
|
||||
}
|
||||
pathsGroupedByTag.put(tag, Pair.of(resourcePath, pathEntry.getValue()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return pathsGroupedByTag;
|
||||
}
|
||||
}
|
||||
@@ -1,203 +0,0 @@
|
||||
package io.swagger2markup;
|
||||
|
||||
import com.wordnik.swagger.models.*;
|
||||
import com.wordnik.swagger.models.parameters.Parameter;
|
||||
import com.wordnik.swagger.models.properties.Property;
|
||||
import io.swagger.parser.SwaggerParser;
|
||||
import io.swagger2markup.builder.DocumentBuilder;
|
||||
import io.swagger2markup.builder.asciidoc.AsciiDocBuilder;
|
||||
import io.swagger2markup.builder.markdown.MarkdownBuilder;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public class Swagger2MarkupConverter {
|
||||
private static final Logger logger = LoggerFactory.getLogger(Swagger2MarkupConverter.class);
|
||||
private static final String VERSION = "Version: ";
|
||||
private static final String SUMMARY = "Summary";
|
||||
private static final String DESCRIPTION = "Description";
|
||||
private static final String PARAMETERS = "Parameters";
|
||||
private static final String PRODUCES = "Produces";
|
||||
private static final String CONSUMES = "Consumes";
|
||||
private static final String RESPONSES = "Responses";
|
||||
private static final String DEFINITIONS = "Definitions";
|
||||
private static final List<String> IGNORED_DEFINITIONS = Arrays.asList("Void");
|
||||
private final Swagger swagger;
|
||||
private DocumentBuilder documentBuilder;
|
||||
|
||||
private Swagger2MarkupConverter(String swaggerFileLocation){
|
||||
swagger = new SwaggerParser().read(swaggerFileLocation);
|
||||
}
|
||||
|
||||
public static Swagger2MarkupConverter from(String swaggerFileLocation){
|
||||
return new Swagger2MarkupConverter(swaggerFileLocation);
|
||||
}
|
||||
|
||||
public void toAsciiDoc(String fileLocation) throws IOException {
|
||||
documentBuilder = new AsciiDocBuilder();
|
||||
buildDocument();
|
||||
writeAsciiDocFile(fileLocation);
|
||||
}
|
||||
|
||||
public void toMarkdown(String fileLocation) throws IOException {
|
||||
documentBuilder = new MarkdownBuilder();
|
||||
buildDocument();
|
||||
writeAsciiDocFile(fileLocation);
|
||||
}
|
||||
|
||||
private void buildDocument(){
|
||||
documentHeader(swagger.getInfo());
|
||||
paths(swagger.getPaths());
|
||||
definitions(swagger.getDefinitions());
|
||||
}
|
||||
|
||||
private void writeAsciiDocFile(String asciiDocFileLocation) throws IOException {
|
||||
try (BufferedWriter writer = Files.newBufferedWriter(Paths.get(asciiDocFileLocation),
|
||||
StandardCharsets.UTF_8)){
|
||||
writer.write(documentBuilder.toString());
|
||||
} catch (IOException e) {
|
||||
logger.warn("Failed to convert Swagger file to AsciiDoc", e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
private void paths(Map<String, Path> paths) {
|
||||
for(Map.Entry<String, Path> entry : paths.entrySet()){
|
||||
Path path = entry.getValue();
|
||||
path("GET", entry.getKey(), path.getGet());
|
||||
path("PUT", entry.getKey(), path.getPut());
|
||||
path("DELETE", entry.getKey(), path.getDelete());
|
||||
path("POST", entry.getKey(), path.getPost());
|
||||
path("PATCH", entry.getKey(), path.getPatch());
|
||||
}
|
||||
}
|
||||
|
||||
private void documentHeader(Info info) {
|
||||
documentBuilder
|
||||
.documentTitle(info.getTitle())
|
||||
.textLine(info.getDescription())
|
||||
.textLine(VERSION + info.getVersion())
|
||||
.newLine();
|
||||
}
|
||||
|
||||
private void path(String httpMethod, String resourcePath, Operation operation) {
|
||||
if(operation != null){
|
||||
pathTitle(httpMethod, resourcePath, operation);
|
||||
descriptionSection(operation);
|
||||
parametersSection(operation);
|
||||
responsesSection(operation);
|
||||
consumesSection(operation);
|
||||
producesSection(operation);
|
||||
}
|
||||
}
|
||||
|
||||
private void pathTitle(String httpMethod, String resourcePath, Operation operation) {
|
||||
String summary = operation.getSummary();
|
||||
if(StringUtils.isNotBlank(summary)) {
|
||||
documentBuilder.sectionTitleLevel1(operation.getSummary());
|
||||
documentBuilder.listing(httpMethod + " " + resourcePath);
|
||||
}else{
|
||||
documentBuilder.sectionTitleLevel1(httpMethod + " " + resourcePath);
|
||||
}
|
||||
}
|
||||
|
||||
private void descriptionSection(Operation operation) {
|
||||
String description = operation.getDescription();
|
||||
if(StringUtils.isNotBlank(description)){
|
||||
documentBuilder.sectionTitleLevel2(DESCRIPTION);
|
||||
documentBuilder.paragraph(description);
|
||||
}
|
||||
}
|
||||
|
||||
private void consumesSection(Operation operation) {
|
||||
List<String> consumes = operation.getConsumes();
|
||||
if(CollectionUtils.isNotEmpty(consumes)){
|
||||
documentBuilder.sectionTitleLevel2(CONSUMES);
|
||||
documentBuilder.unorderedList(consumes);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void producesSection(Operation operation) {
|
||||
List<String> produces = operation.getProduces();
|
||||
if(CollectionUtils.isNotEmpty(produces)){
|
||||
documentBuilder.sectionTitleLevel2(PRODUCES);
|
||||
documentBuilder.unorderedList(produces);
|
||||
}
|
||||
}
|
||||
|
||||
private void parametersSection(Operation operation) {
|
||||
List<Parameter> parameters = operation.getParameters();
|
||||
if(CollectionUtils.isNotEmpty(parameters)){
|
||||
List<String> csvContent = new ArrayList<>();
|
||||
csvContent.add("Name,Located in,Description,Required");
|
||||
for(Parameter parameter : parameters){
|
||||
StringBuilder rowBuilder = new StringBuilder();
|
||||
rowBuilder.append(parameter.getName()).append(",").
|
||||
append(parameter.getIn()).append(",").
|
||||
append(parameter.getDescription()).append(",").
|
||||
append(parameter.getRequired());
|
||||
csvContent.add(rowBuilder.toString());
|
||||
}
|
||||
documentBuilder.sectionTitleLevel2(PARAMETERS);
|
||||
documentBuilder.tableWithHeaderRow(csvContent);
|
||||
}
|
||||
}
|
||||
|
||||
private void responsesSection(Operation operation) {
|
||||
Map<String, Response> responses = operation.getResponses();
|
||||
if(MapUtils.isNotEmpty(responses)){
|
||||
List<String> csvContent = new ArrayList<>();
|
||||
csvContent.add("Code,Description");
|
||||
for(Map.Entry<String, Response> entry : responses.entrySet()){
|
||||
Response response = entry.getValue();
|
||||
StringBuilder rowBuilder = new StringBuilder();
|
||||
rowBuilder.append(entry.getKey()).append(",").
|
||||
append(response.getDescription());
|
||||
csvContent.add(rowBuilder.toString());
|
||||
}
|
||||
documentBuilder.sectionTitleLevel2(RESPONSES);
|
||||
documentBuilder.tableWithHeaderRow(csvContent);
|
||||
}
|
||||
}
|
||||
|
||||
private void definitions(Map<String, Model> definitions) {
|
||||
if(MapUtils.isNotEmpty(definitions)){
|
||||
documentBuilder.sectionTitleLevel1(DEFINITIONS);
|
||||
for(Map.Entry<String, Model> definitionsEntry : definitions.entrySet()){
|
||||
String definitionName = definitionsEntry.getKey();
|
||||
if(!IGNORED_DEFINITIONS.contains(definitionName)) {
|
||||
documentBuilder.sectionTitleLevel2(definitionName);
|
||||
Model model = definitionsEntry.getValue();
|
||||
Map<String, Property> properties = model.getProperties();
|
||||
List<String> csvContent = new ArrayList<>();
|
||||
csvContent.add("Name,Type,Required");
|
||||
for (Map.Entry<String, Property> propertyEntry : properties.entrySet()) {
|
||||
Property property = propertyEntry.getValue();
|
||||
StringBuilder rowBuilder = new StringBuilder();
|
||||
rowBuilder.append(propertyEntry.getKey()).append(",").
|
||||
append(property.getType()).append(",").append(property.getRequired());
|
||||
csvContent.add(rowBuilder.toString());
|
||||
}
|
||||
documentBuilder.tableWithHeaderRow(csvContent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
package io.swagger2markup.builder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public abstract class AbstractDocumentBuilder implements DocumentBuilder {
|
||||
|
||||
protected StringBuilder documentBuilder = new StringBuilder();
|
||||
protected String newLine = System.getProperty("line.separator");
|
||||
|
||||
protected void documentTitle(Markup markup, String title){
|
||||
documentBuilder.append(markup).append(title).append(newLine);
|
||||
}
|
||||
|
||||
protected void sectionTitleLevel1(Markup markup, String title){
|
||||
documentBuilder.append(markup).append(title).append(newLine);
|
||||
}
|
||||
|
||||
protected void sectionTitleLevel2(Markup markup, String title){
|
||||
documentBuilder.append(markup).append(title).append(newLine);
|
||||
}
|
||||
|
||||
protected void sectionTitleLevel3(Markup markup, String title){
|
||||
documentBuilder.append(markup).append(title).append(newLine);
|
||||
}
|
||||
|
||||
public DocumentBuilder textLine(String text){
|
||||
documentBuilder.append(text).append(newLine);
|
||||
return this;
|
||||
}
|
||||
|
||||
protected void paragraph(Markup markup, String text){
|
||||
documentBuilder.append(markup).append(newLine).append(text).append(newLine).append(newLine);
|
||||
}
|
||||
|
||||
protected void listing(Markup markup, String text){
|
||||
delimitedTextLine(markup, text);
|
||||
}
|
||||
|
||||
private void delimitedTextLine(Markup markup, String text){
|
||||
documentBuilder.append(markup).append(newLine).append(text).append(newLine).append(markup).append(newLine).append(newLine);
|
||||
}
|
||||
|
||||
protected void preserveLineBreaks(Markup markup){
|
||||
documentBuilder.append(markup).append(newLine);
|
||||
}
|
||||
|
||||
protected void boldTextLine(Markup markup, String text){
|
||||
delimitedTextLine(markup, text);
|
||||
}
|
||||
|
||||
protected void italicTextLine(Markup markup, String text){
|
||||
delimitedTextLine(markup, text);
|
||||
}
|
||||
|
||||
protected void unorderedList(Markup markup, List<String> list){
|
||||
for(String listEntry : list){
|
||||
documentBuilder.append(markup).append(listEntry).append(newLine);
|
||||
}
|
||||
documentBuilder.append(newLine);
|
||||
}
|
||||
|
||||
public DocumentBuilder newLine(){
|
||||
documentBuilder.append(newLine);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return documentBuilder.toString();
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package io.swagger2markup.builder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public interface DocumentBuilder {
|
||||
DocumentBuilder documentTitle(String title);
|
||||
|
||||
DocumentBuilder sectionTitleLevel1(String title);
|
||||
|
||||
DocumentBuilder sectionTitleLevel2(String title);
|
||||
|
||||
DocumentBuilder sectionTitleLevel3(String title);
|
||||
|
||||
DocumentBuilder textLine(String text);
|
||||
|
||||
DocumentBuilder paragraph(String text);
|
||||
|
||||
DocumentBuilder listing(String text);
|
||||
|
||||
DocumentBuilder boldTextLine(String text);
|
||||
|
||||
DocumentBuilder italicTextLine(String text);
|
||||
|
||||
DocumentBuilder unorderedList(List<String> list);
|
||||
|
||||
DocumentBuilder tableWithHeaderRow(List<String> rowsInCSV);
|
||||
|
||||
DocumentBuilder newLine();
|
||||
|
||||
String toString();
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package io.swagger2markup.builder;
|
||||
|
||||
/**
|
||||
* Project: swagger2asciidoc
|
||||
* Copyright: Deutsche Telekom AG
|
||||
*
|
||||
* @author Robert Winkler <robert.winkler@telekom.de>
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public interface Markup {
|
||||
public String toString();
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
package io.swagger2markup.builder.asciidoc;
|
||||
|
||||
import io.swagger2markup.builder.Markup;
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public enum AsciiDoc implements Markup {
|
||||
LABELED(":: "),
|
||||
TABLE("|==="),
|
||||
LISTING("----"),
|
||||
HARDBREAKS(":hardbreaks:"),
|
||||
DOCUMENT_TITLE("= "),
|
||||
SECTION_TITLE_LEVEL1("== "),
|
||||
SECTION_TITLE_LEVEL2("=== "),
|
||||
SECTION_TITLE_LEVEL3("==== "),
|
||||
BOLD("*"),
|
||||
ITALIC("*"),
|
||||
LIST_ENTRY("* ");
|
||||
|
||||
private final String markup;
|
||||
|
||||
/**
|
||||
* @param markup AsciiDoc markup
|
||||
*/
|
||||
private AsciiDoc(final String markup) {
|
||||
this.markup = markup;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Enum#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return markup;
|
||||
}
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
package io.swagger2markup.builder.asciidoc;
|
||||
|
||||
import io.swagger2markup.builder.AbstractDocumentBuilder;
|
||||
import io.swagger2markup.builder.DocumentBuilder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public class AsciiDocBuilder extends AbstractDocumentBuilder{
|
||||
|
||||
@Override
|
||||
public DocumentBuilder documentTitle(String title){
|
||||
documentTitle(AsciiDoc.DOCUMENT_TITLE, title);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DocumentBuilder sectionTitleLevel1(String title){
|
||||
sectionTitleLevel1(AsciiDoc.SECTION_TITLE_LEVEL1, title);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DocumentBuilder sectionTitleLevel2(String title){
|
||||
sectionTitleLevel2(AsciiDoc.SECTION_TITLE_LEVEL2, title);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DocumentBuilder sectionTitleLevel3(String title){
|
||||
sectionTitleLevel3(AsciiDoc.SECTION_TITLE_LEVEL3, title);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DocumentBuilder paragraph(String text){
|
||||
paragraph(AsciiDoc.HARDBREAKS, text);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DocumentBuilder listing(String text){
|
||||
listing(AsciiDoc.LISTING, text);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DocumentBuilder boldTextLine(String text){
|
||||
boldTextLine(AsciiDoc.BOLD, text);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DocumentBuilder italicTextLine(String text) {
|
||||
italicTextLine(AsciiDoc.ITALIC, text);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DocumentBuilder unorderedList(List<String> list){
|
||||
unorderedList(AsciiDoc.LIST_ENTRY, list);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DocumentBuilder tableWithHeaderRow(List<String> rowsInCSV){
|
||||
documentBuilder.append("[format=\"csv\", options=\"header\"]").append(newLine);
|
||||
documentBuilder.append(AsciiDoc.TABLE).append(newLine);
|
||||
for(String row : rowsInCSV){
|
||||
documentBuilder.append(row).append(newLine);
|
||||
}
|
||||
documentBuilder.append(AsciiDoc.TABLE).append(newLine).append(newLine);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
package io.swagger2markup.builder.markdown;
|
||||
|
||||
import io.swagger2markup.builder.Markup;
|
||||
|
||||
/**
|
||||
* Project: swagger2asciidoc
|
||||
* Copyright: Deutsche Telekom AG
|
||||
*
|
||||
* @author Robert Winkler <robert.winkler@telekom.de>
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public enum Markdown implements Markup {
|
||||
HARDBREAKS(""),
|
||||
TABLE_COLUMN("|"),
|
||||
TABLE_ROW("-"),
|
||||
LISTING("```"),
|
||||
DOCUMENT_TITLE("# "),
|
||||
SECTION_TITLE_LEVEL1("## "),
|
||||
SECTION_TITLE_LEVEL2("### "),
|
||||
SECTION_TITLE_LEVEL3("### "),
|
||||
BOLD("**"),
|
||||
ITALIC("*"),
|
||||
LIST_ENTRY("* ");
|
||||
|
||||
private final String markup;
|
||||
|
||||
/**
|
||||
* @param markup AsciiDoc markup
|
||||
*/
|
||||
private Markdown(final String markup) {
|
||||
this.markup = markup;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Enum#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return markup;
|
||||
}
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
package io.swagger2markup.builder.markdown;
|
||||
|
||||
import io.swagger2markup.builder.AbstractDocumentBuilder;
|
||||
import io.swagger2markup.builder.DocumentBuilder;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Project: swagger2asciidoc
|
||||
* Copyright: Deutsche Telekom AG
|
||||
*
|
||||
* @author Robert Winkler <robert.winkler@telekom.de>
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public class MarkdownBuilder extends AbstractDocumentBuilder
|
||||
{
|
||||
@Override
|
||||
public DocumentBuilder documentTitle(String title){
|
||||
documentTitle(Markdown.DOCUMENT_TITLE, title);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DocumentBuilder sectionTitleLevel1(String title){
|
||||
sectionTitleLevel1(Markdown.SECTION_TITLE_LEVEL1, title);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DocumentBuilder sectionTitleLevel2(String title){
|
||||
sectionTitleLevel2(Markdown.SECTION_TITLE_LEVEL2, title);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DocumentBuilder sectionTitleLevel3(String title){
|
||||
sectionTitleLevel3(Markdown.SECTION_TITLE_LEVEL3, title);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DocumentBuilder paragraph(String text){
|
||||
paragraph(Markdown.HARDBREAKS, text);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DocumentBuilder listing(String text){
|
||||
listing(Markdown.LISTING, text);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DocumentBuilder boldTextLine(String text){
|
||||
boldTextLine(Markdown.BOLD, text);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DocumentBuilder italicTextLine(String text) {
|
||||
italicTextLine(Markdown.ITALIC, text);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DocumentBuilder unorderedList(List<String> list){
|
||||
unorderedList(Markdown.LIST_ENTRY, list);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DocumentBuilder tableWithHeaderRow(List<String> rowsInCSV){
|
||||
String headersInCSV = rowsInCSV.get(0);
|
||||
List<String> contentRowsInCSV = rowsInCSV.subList(1, rowsInCSV.size());
|
||||
List<String> headers = Arrays.asList(headersInCSV.split(","));
|
||||
// Header
|
||||
documentBuilder.append(Markdown.TABLE_COLUMN);
|
||||
for(String header : headers){
|
||||
documentBuilder.append(header).append(Markdown.TABLE_COLUMN);
|
||||
}
|
||||
newLine();
|
||||
// Header/Content separator
|
||||
documentBuilder.append(Markdown.TABLE_COLUMN);
|
||||
for(String header : headers){
|
||||
for(int i = 1; i<5; i++) {
|
||||
documentBuilder.append(Markdown.TABLE_ROW);
|
||||
}
|
||||
documentBuilder.append(Markdown.TABLE_COLUMN);
|
||||
}
|
||||
newLine();
|
||||
// Content
|
||||
for(String contentRow : contentRowsInCSV){
|
||||
documentBuilder.append(Markdown.TABLE_COLUMN);
|
||||
List<String> columns = Arrays.asList(contentRow.split(","));
|
||||
for(String columnText : columns){
|
||||
documentBuilder.append(columnText).append(Markdown.TABLE_COLUMN);
|
||||
}
|
||||
newLine();
|
||||
}
|
||||
newLine().newLine();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
42
src/main/resources/lang/labels_en.properties
Normal file
42
src/main/resources/lang/labels_en.properties
Normal file
@@ -0,0 +1,42 @@
|
||||
definitions=Definitions
|
||||
json_schema=JSON Schema
|
||||
xml_schema=XML Schema
|
||||
|
||||
default_column=Default
|
||||
required_column=Required
|
||||
schema_column=Schema
|
||||
name_column=Name
|
||||
description_column=Description
|
||||
produces=Produces
|
||||
consumes=Consumes
|
||||
tags=Tags
|
||||
|
||||
overview=Overview
|
||||
current_version=Version information
|
||||
version=Version\:\u0020
|
||||
contact_information=Contact information
|
||||
contact_name=Contact\:\u0020
|
||||
contact_email=Contact Email\:\u0020
|
||||
license_information=License information
|
||||
license=License\:\u0020
|
||||
license_url=License URL\:\u0020
|
||||
terms_of_service=Terms of service\:\u0020
|
||||
uri_scheme=URI scheme
|
||||
host=Host\:\u0020
|
||||
base_path=BasePath\:\u0020
|
||||
schemes=Schemes\:\u0020
|
||||
|
||||
paths=Paths
|
||||
resources=Resources
|
||||
parameters=Parameters
|
||||
responses=Responses
|
||||
example_curl=Example CURL request
|
||||
example_request=Example HTTP request
|
||||
example_response=Example HTTP response
|
||||
type_column=Type
|
||||
http_code_column=HTTP Code
|
||||
request_example_file_name=http-request
|
||||
response_example_file_name=http-response
|
||||
curl_example_file_name=curl-request
|
||||
description_file_name=description
|
||||
parameter=Parameter
|
||||
42
src/main/resources/lang/labels_ru.properties
Normal file
42
src/main/resources/lang/labels_ru.properties
Normal file
@@ -0,0 +1,42 @@
|
||||
definitions=\u041E\u043F\u0440\u0435\u0434\u0435\u043B\u0435\u043D\u0438\u044F
|
||||
json_schema=JSON \u0441\u0445\u0435\u043C\u0430
|
||||
xml_schema=XML \u0441\u0445\u0435\u043C\u0430
|
||||
|
||||
default_column=\u041F\u043E \u0443\u043C\u043E\u043B\u0447\u0430\u043D\u0438\u044E
|
||||
required_column=\u041E\u0431\u044F\u0437\u0430\u0442\u0435\u043B\u044C\u043D\u043E
|
||||
schema_column=\u0421\u0445\u0435\u043C\u0430
|
||||
name_column=\u0418\u043C\u044F
|
||||
description_column=\u041E\u043F\u0438\u0441\u0430\u043D\u0438\u0435
|
||||
produces=\u0412\u043E\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442
|
||||
consumes=\u041F\u0440\u0438\u043D\u0438\u043C\u0430\u0435\u0442
|
||||
tags=\u0422\u044D\u0433\u0438
|
||||
|
||||
overview=\u041E\u0431\u0437\u043E\u0440
|
||||
current_version=\u0418\u043D\u0444\u043E\u0440\u043C\u0430\u0446\u0438\u044F \u043E \u0432\u0435\u0440\u0441\u0438\u0438
|
||||
version=\u0412\u0435\u0440\u0441\u0438\u044F\:\u0020
|
||||
contact_information=\u041A\u043E\u043D\u0442\u0430\u043A\u0442\u043D\u0430\u044F \u0438\u043D\u0444\u043E\u0440\u043C\u0430\u0446\u0438\u044F
|
||||
contact_name=\u041A\u043E\u043D\u0442\u0430\u043A\u0442\:\u0020
|
||||
contact_email=Email \u043A\u043E\u043D\u0442\u0430\u043A\u0442\u0430\:\u0020
|
||||
license_information=\u0418\u043D\u0444\u043E\u0440\u043C\u0430\u0446\u0438\u044F \u043E \u043B\u0438\u0446\u0435\u043D\u0446\u0438\u0438
|
||||
license=\u041B\u0438\u0446\u0435\u043D\u0437\u0438\u044F\:\u0020
|
||||
license_url=URL \u043B\u0438\u0446\u0435\u043D\u0437\u0438\u0438\:\u0020
|
||||
terms_of_service=\u0423\u0441\u043B\u043E\u0432\u0438\u044F \u0438\u0441\u043F\u043E\u043B\u044C\u0437\u043E\u0432\u0430\u043D\u0438\u044F\:\u0020
|
||||
uri_scheme=\u0421\u0445\u0435\u043C\u0430 URI
|
||||
host=\u0423\u0437\u0435\u043B\:\u0020
|
||||
base_path=\u041E\u0441\u043D\u043E\u0432\u043D\u043E\u0439 \u043F\u0443\u0442\u044C\:\u0020
|
||||
schemes=\u0421\u0445\u0435\u043C\u044B\:\u0020
|
||||
|
||||
paths=\u041F\u0443\u0442\u0438
|
||||
resources=\u041E\u0442\u0432\u0435\u0442\u044B
|
||||
parameters=\u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440\u044B
|
||||
responses=\u041E\u0442\u0432\u0435\u0442\u044B
|
||||
example_curl=\u041F\u0440\u0438\u043C\u0435\u0440 CURL \u0437\u0430\u043F\u0440\u043E\u0441\u0430
|
||||
example_request=\u041F\u0440\u0438\u043C\u0435\u0440 HTTP \u0437\u0430\u043F\u0440\u043E\u0441\u0430
|
||||
example_response=\u041F\u0440\u0438\u043C\u0435\u0440 HTTP \u0437\u0430\u043F\u0440\u043E\u0441\u0430
|
||||
type_column=\u0422\u0438\u043F
|
||||
http_code_column=HTTP \u043A\u043E\u0434
|
||||
request_example_file_name=http-request
|
||||
response_example_file_name=http-response
|
||||
curl_example_file_name=curl-request
|
||||
description_file_name=\u043E\u043F\u0438\u0441\u0430\u043D\u0438\u0435
|
||||
parameter=\u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440
|
||||
@@ -0,0 +1,389 @@
|
||||
/*
|
||||
*
|
||||
* 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.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.Files;
|
||||
import java.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.Assertions.failBecauseExceptionWasNotThrown;
|
||||
import static org.assertj.core.api.BDDAssertions.assertThat;
|
||||
|
||||
public class Swagger2MarkupConverterTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void testSwagger2AsciiDocConversionFromString() throws IOException {
|
||||
//Given
|
||||
String swaggerJsonString = IOUtils.toString(getClass().getResourceAsStream("/json/swagger.json"));
|
||||
File outputDirectory = new File("build/docs/asciidoc/generated");
|
||||
FileUtils.deleteQuietly(outputDirectory);
|
||||
|
||||
//When
|
||||
Swagger2MarkupConverter.fromString(swaggerJsonString).build()
|
||||
.intoFolder(outputDirectory.getAbsolutePath());
|
||||
|
||||
//Then
|
||||
String[] directories = outputDirectory.list();
|
||||
assertThat(directories).hasSize(3).containsAll(asList("definitions.adoc", "overview.adoc", "paths.adoc"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSwagger2AsciiDocConversion() throws IOException {
|
||||
//Given
|
||||
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()).build()
|
||||
.intoFolder(outputDirectory.getAbsolutePath());
|
||||
|
||||
//Then
|
||||
String[] directories = outputDirectory.list();
|
||||
assertThat(directories).hasSize(3).containsAll(asList("definitions.adoc", "overview.adoc", "paths.adoc"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSwagger2AsciiDocGroupedByTags() 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())
|
||||
.withPathsGroupedBy(GroupBy.TAGS)
|
||||
.build()
|
||||
.intoFolder(outputDirectory.getAbsolutePath());
|
||||
|
||||
//Then
|
||||
String[] directories = outputDirectory.list();
|
||||
assertThat(directories).hasSize(3).containsAll(asList("definitions.adoc", "overview.adoc", "paths.adoc"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSwagger2AsciiDocGroupedByTagsWithMissingTag() throws IOException {
|
||||
//Given
|
||||
File file = new File(Swagger2MarkupConverterTest.class.getResource("/json/swagger_missing_tag.json").getFile());
|
||||
File outputDirectory = new File("build/docs/asciidoc/generated");
|
||||
FileUtils.deleteQuietly(outputDirectory);
|
||||
//When
|
||||
try {
|
||||
Swagger2MarkupConverter.from(file.getAbsolutePath())
|
||||
.withPathsGroupedBy(GroupBy.TAGS)
|
||||
.build()
|
||||
.intoFolder(outputDirectory.getAbsolutePath());
|
||||
// If NullPointerException was not thrown, test would fail the specified message
|
||||
failBecauseExceptionWasNotThrown(NullPointerException.class);
|
||||
} catch (Exception e) {
|
||||
assertThat(e).hasMessage("Path operations must have tags, if you want to group by tags! The operation 'PUT /pets' has not tags.");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOldSwaggerSpec2AsciiDocConversion() throws IOException {
|
||||
//Given
|
||||
File file = new File(Swagger2MarkupConverterTest.class.getResource("/json/error_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 testSwagger2AsciiDocConversionDoesNotContainUriScheme() throws IOException {
|
||||
//Given
|
||||
File file = new File(Swagger2MarkupConverterTest.class.getResource("/yaml/swagger_should_not_contain_uri_scheme.yaml").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"));
|
||||
|
||||
assertThat(new String(Files.readAllBytes(Paths.get(outputDirectory + File.separator + "overview.adoc"))))
|
||||
.doesNotContain("=== URI scheme");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSwagger2AsciiDocConversionContainsUriScheme() throws IOException {
|
||||
//Given
|
||||
File file = new File(Swagger2MarkupConverterTest.class.getResource("/yaml/swagger_should_contain_uri_scheme.yaml").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"));
|
||||
|
||||
assertThat(new String(Files.readAllBytes(Paths.get(outputDirectory + File.separator + "overview.adoc"))))
|
||||
.contains("=== URI scheme");
|
||||
}
|
||||
|
||||
@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).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/markdown/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/markdown/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()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSwagger2AsciiDocConversionWithRussianOutputLanguage() throws IOException {
|
||||
//Given
|
||||
File file = new File(Swagger2MarkupConverterTest.class.getResource("/json/swagger.json").getFile());
|
||||
File outputDirectory = new File("build/docs/asciidoc/generated");
|
||||
FileUtils.deleteQuietly(outputDirectory);
|
||||
|
||||
//When
|
||||
Swagger2MarkupConverter.from(file.getAbsolutePath())
|
||||
.withOutputLanguage(Language.RU)
|
||||
.build()
|
||||
.intoFolder(outputDirectory.getAbsolutePath());
|
||||
|
||||
//Then
|
||||
assertThat(new String(Files.readAllBytes(Paths.get(outputDirectory + File.separator + "definitions.adoc"))))
|
||||
.contains("== Определения");
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a markdown document to search, this checks to see if the specified tables
|
||||
* have all of the expected fields listed.
|
||||
*
|
||||
* @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 = "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); }
|
||||
String asciiDocAsHtml = Asciidoctor.Factory.create().convert(asciiDoc,
|
||||
OptionsBuilder.options().backend("html5").headerFooter(true).safe(SafeMode.UNSAFE).docType("book").attributes(AttributesBuilder.attributes()
|
||||
.tableOfContents(true).tableOfContents(Placement.LEFT).sectionNumbers(true).hardbreaks(true).setAnchors(true).attribute("sectlinks")));
|
||||
try (BufferedWriter writer = Files.newBufferedWriter(Paths.get(path, "swagger.html"), StandardCharsets.UTF_8)){
|
||||
writer.write(asciiDocAsHtml);
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package io.swagger2markup;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public class Swagger2MarkupConverterTest {
|
||||
|
||||
@Test
|
||||
public void testSwagger2AsciiDocConverter() throws IOException {
|
||||
File file = new File(Swagger2MarkupConverterTest.class.getResource("/json/swagger.json").getFile());
|
||||
Swagger2MarkupConverter.from(file.getAbsolutePath()).toAsciiDoc("src/docs/asciidoc/swagger.adoc");
|
||||
|
||||
Swagger2MarkupConverter.from(file.getAbsolutePath()).toMarkdown("src/docs/markdown/swagger.md");
|
||||
}
|
||||
}
|
||||
108
src/test/resources/json/error_swagger_12.json
Normal file
108
src/test/resources/json/error_swagger_12.json
Normal file
@@ -0,0 +1,108 @@
|
||||
{
|
||||
"apiVersion": "1",
|
||||
"swaggerVersion": "1.2",
|
||||
"basePath": "http://localhost:8082/query-rs",
|
||||
"resourcePath": "/query-services",
|
||||
"apis": [
|
||||
{
|
||||
"path": "/query-services/timesheet",
|
||||
"operations": [
|
||||
{
|
||||
"method": "GET",
|
||||
"summary": "testTimesheet",
|
||||
"responseClass": "void",
|
||||
"nickname": "testTimeSheet",
|
||||
"position": 0,
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"name": "body",
|
||||
"required": false,
|
||||
"allowMultiple": false,
|
||||
"dataType": "TimesheetEntryWireBase",
|
||||
"paramType": "body"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"models": {
|
||||
"TimesheetEntryWireBase": {
|
||||
"id": "TimesheetEntryWireBase",
|
||||
"name": "TimesheetEntryWireBase",
|
||||
"qualifiedType": "com.yt.nss.rest.domain.test.TimesheetEntryWireBase",
|
||||
"required": [
|
||||
"type"
|
||||
],
|
||||
"properties": {
|
||||
"type": {
|
||||
"type": "string",
|
||||
"qualifiedType": "java.lang.String",
|
||||
"position": 0,
|
||||
"allowableValues": {
|
||||
"values": [
|
||||
"STRING"
|
||||
],
|
||||
"valueType": "LIST"
|
||||
}
|
||||
}
|
||||
},
|
||||
"description": "Basic class for timesheet entry",
|
||||
"baseModel": "java.lang.Void",
|
||||
"discriminator": "type",
|
||||
"subTypes": [
|
||||
"com.yt.nss.rest.domain.test.TimesheetProjectEntryWire",
|
||||
"com.yt.nss.rest.domain.test.TimesheetAdminEntryWire"
|
||||
]
|
||||
},
|
||||
"TimesheetProjectEntryWire": {
|
||||
"id": "TimesheetProjectEntryWire",
|
||||
"name": "TimesheetProjectEntryWire",
|
||||
"qualifiedType": "com.yt.nss.rest.domain.test.TimesheetProjectEntryWire",
|
||||
"required": [
|
||||
"type"
|
||||
],
|
||||
"properties": {
|
||||
"type": {
|
||||
"type": "string",
|
||||
"qualifiedType": "java.lang.String",
|
||||
"position": 0,
|
||||
"allowableValues": {
|
||||
"values": [
|
||||
"STRING"
|
||||
],
|
||||
"valueType": "LIST"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"TimesheetAdminEntryWire": {
|
||||
"id": "TimesheetAdminEntryWire",
|
||||
"name": "TimesheetAdminEntryWire",
|
||||
"qualifiedType": "com.yt.nss.rest.domain.test.TimesheetAdminEntryWire",
|
||||
"required": [
|
||||
"type"
|
||||
],
|
||||
"properties": {
|
||||
"type": {
|
||||
"type": "string",
|
||||
"qualifiedType": "java.lang.String",
|
||||
"position": 0,
|
||||
"allowableValues": {
|
||||
"values": [
|
||||
"STRING"
|
||||
],
|
||||
"valueType": "LIST"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"position": 1
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
"info": {
|
||||
"description": "This is a sample server Petstore server.\n\n[Learn about Swagger](http://swagger.wordnik.com) or join the IRC channel `#swagger` on irc.freenode.net.\n\nFor this sample, you can use the api key `special-key` to test the authorization filters\n",
|
||||
"version": "1.0.0",
|
||||
"title": "Swagger Petstore",
|
||||
"title": "Swagger Petstore API",
|
||||
"termsOfService": "http://helloreverb.com/terms/",
|
||||
"contact": {
|
||||
"name": "apiteam@wordnik.com"
|
||||
@@ -18,6 +18,20 @@
|
||||
"schemes": [
|
||||
"http"
|
||||
],
|
||||
"tags": [
|
||||
{
|
||||
"name": "pet",
|
||||
"description": "Pet resource"
|
||||
},
|
||||
{
|
||||
"name": "store",
|
||||
"description": "Store resource"
|
||||
},
|
||||
{
|
||||
"name": "user",
|
||||
"description": "User resource"
|
||||
}
|
||||
],
|
||||
"paths": {
|
||||
"/pets": {
|
||||
"post": {
|
||||
@@ -134,13 +148,7 @@
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "successful operation",
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/Pet"
|
||||
}
|
||||
}
|
||||
"$ref": "#/responses/FoundPets"
|
||||
},
|
||||
"400": {
|
||||
"description": "Invalid status value"
|
||||
@@ -183,13 +191,7 @@
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "successful operation",
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/Pet"
|
||||
}
|
||||
}
|
||||
"$ref": "#/responses/FoundPets"
|
||||
},
|
||||
"400": {
|
||||
"description": "Invalid tag value"
|
||||
@@ -219,12 +221,7 @@
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"in": "path",
|
||||
"name": "petId",
|
||||
"description": "ID of pet that needs to be fetched",
|
||||
"required": true,
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
"$ref": "#/parameters/petId"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
@@ -563,14 +560,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 +622,8 @@
|
||||
"name": "username",
|
||||
"description": "The name that needs to be fetched. Use user1 for testing.",
|
||||
"required": true,
|
||||
"type": "string"
|
||||
"type": "string",
|
||||
"default": "testUser"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
@@ -726,38 +726,77 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"responses":{
|
||||
"FoundPets": {
|
||||
"description": "successful operation",
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/Pet"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"parameters":{
|
||||
"petId": {
|
||||
"in": "path",
|
||||
"name": "petId",
|
||||
"description": "ID of the pet",
|
||||
"required": true,
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
}
|
||||
},
|
||||
"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"
|
||||
},
|
||||
"pictures": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string",
|
||||
"format": "byte"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"Category": {
|
||||
"properties": {
|
||||
"id": {
|
||||
@@ -770,6 +809,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" ]
|
||||
} ]
|
||||
} ]
|
||||
}
|
||||
883
src/test/resources/json/swagger_missing_tag.json
Normal file
883
src/test/resources/json/swagger_missing_tag.json
Normal file
@@ -0,0 +1,883 @@
|
||||
{
|
||||
"swagger": "2.0",
|
||||
"info": {
|
||||
"description": "This is a sample server Petstore server.\n\n[Learn about Swagger](http://swagger.wordnik.com) or join the IRC channel `#swagger` on irc.freenode.net.\n\nFor this sample, you can use the api key `special-key` to test the authorization filters\n",
|
||||
"version": "1.0.0",
|
||||
"title": "Swagger Petstore API",
|
||||
"termsOfService": "http://helloreverb.com/terms/",
|
||||
"contact": {
|
||||
"name": "apiteam@wordnik.com"
|
||||
},
|
||||
"license": {
|
||||
"name": "Apache 2.0",
|
||||
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
|
||||
}
|
||||
},
|
||||
"host": "petstore.swagger.wordnik.com",
|
||||
"basePath": "/v2",
|
||||
"schemes": [
|
||||
"http"
|
||||
],
|
||||
"tags": [
|
||||
{
|
||||
"name": "pet",
|
||||
"description": "Pet resource"
|
||||
},
|
||||
{
|
||||
"name": "store",
|
||||
"description": "Store resource"
|
||||
},
|
||||
{
|
||||
"name": "user",
|
||||
"description": "User resource"
|
||||
}
|
||||
],
|
||||
"paths": {
|
||||
"/pets": {
|
||||
"post": {
|
||||
"tags": [
|
||||
"pet"
|
||||
],
|
||||
"summary": "Add a new pet to the store",
|
||||
"description": "",
|
||||
"operationId": "addPet",
|
||||
"consumes": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"in": "body",
|
||||
"name": "body",
|
||||
"description": "Pet object that needs to be added to the store",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Pet"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"405": {
|
||||
"description": "Invalid input"
|
||||
}
|
||||
},
|
||||
"security": [
|
||||
{
|
||||
"petstore_auth": [
|
||||
"write_pets",
|
||||
"read_pets"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"put": {
|
||||
"summary": "Update an existing pet",
|
||||
"description": "",
|
||||
"operationId": "updatePet",
|
||||
"consumes": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"in": "body",
|
||||
"name": "body",
|
||||
"description": "Pet object that needs to be added to the store",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Pet"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"400": {
|
||||
"description": "Invalid ID supplied"
|
||||
},
|
||||
"404": {
|
||||
"description": "Pet not found"
|
||||
},
|
||||
"405": {
|
||||
"description": "Validation exception"
|
||||
}
|
||||
},
|
||||
"security": [
|
||||
{
|
||||
"petstore_auth": [
|
||||
"write_pets",
|
||||
"read_pets"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"/pets/findByStatus": {
|
||||
"get": {
|
||||
"tags": [
|
||||
"pet"
|
||||
],
|
||||
"summary": "Finds Pets by status",
|
||||
"description": "Multiple status values can be provided with comma seperated strings",
|
||||
"operationId": "findPetsByStatus",
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"in": "query",
|
||||
"name": "status",
|
||||
"description": "Status values that need to be considered for filter",
|
||||
"required": false,
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"collectionFormat": "multi"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"$ref": "#/responses/FoundPets"
|
||||
},
|
||||
"400": {
|
||||
"description": "Invalid status value"
|
||||
}
|
||||
},
|
||||
"security": [
|
||||
{
|
||||
"petstore_auth": [
|
||||
"write_pets",
|
||||
"read_pets"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"/pets/findByTags": {
|
||||
"get": {
|
||||
"tags": [
|
||||
"pet"
|
||||
],
|
||||
"summary": "Finds Pets by tags",
|
||||
"description": "Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.",
|
||||
"operationId": "findPetsByTags",
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"in": "query",
|
||||
"name": "tags",
|
||||
"description": "Tags to filter by",
|
||||
"required": false,
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"collectionFormat": "multi"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"$ref": "#/responses/FoundPets"
|
||||
},
|
||||
"400": {
|
||||
"description": "Invalid tag value"
|
||||
}
|
||||
},
|
||||
"security": [
|
||||
{
|
||||
"petstore_auth": [
|
||||
"write_pets",
|
||||
"read_pets"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"/pets/{petId}": {
|
||||
"get": {
|
||||
"tags": [
|
||||
"pet"
|
||||
],
|
||||
"summary": "Find pet by ID",
|
||||
"description": "Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions",
|
||||
"operationId": "getPetById",
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"$ref": "#/parameters/petId"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "successful operation",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Pet"
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Invalid ID supplied"
|
||||
},
|
||||
"404": {
|
||||
"description": "Pet not found"
|
||||
}
|
||||
},
|
||||
"security": [
|
||||
{
|
||||
"api_key": []
|
||||
},
|
||||
{
|
||||
"petstore_auth": [
|
||||
"write_pets",
|
||||
"read_pets"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"post": {
|
||||
"tags": [
|
||||
"pet"
|
||||
],
|
||||
"summary": "Updates a pet in the store with form data",
|
||||
"description": "",
|
||||
"operationId": "updatePetWithForm",
|
||||
"consumes": [
|
||||
"application/x-www-form-urlencoded"
|
||||
],
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"in": "path",
|
||||
"name": "petId",
|
||||
"description": "ID of pet that needs to be updated",
|
||||
"required": true,
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"in": "formData",
|
||||
"name": "name",
|
||||
"description": "Updated name of the pet",
|
||||
"required": true,
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"in": "formData",
|
||||
"name": "status",
|
||||
"description": "Updated status of the pet",
|
||||
"required": true,
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"405": {
|
||||
"description": "Invalid input"
|
||||
}
|
||||
},
|
||||
"security": [
|
||||
{
|
||||
"petstore_auth": [
|
||||
"write_pets",
|
||||
"read_pets"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"delete": {
|
||||
"tags": [
|
||||
"pet"
|
||||
],
|
||||
"summary": "Deletes a pet",
|
||||
"description": "",
|
||||
"operationId": "deletePet",
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"in": "header",
|
||||
"name": "api_key",
|
||||
"description": "",
|
||||
"required": true,
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"in": "path",
|
||||
"name": "petId",
|
||||
"description": "Pet id to delete",
|
||||
"required": true,
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"400": {
|
||||
"description": "Invalid pet value"
|
||||
}
|
||||
},
|
||||
"security": [
|
||||
{
|
||||
"petstore_auth": [
|
||||
"write_pets",
|
||||
"read_pets"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"/stores/order": {
|
||||
"post": {
|
||||
"tags": [
|
||||
"store"
|
||||
],
|
||||
"summary": "Place an order for a pet",
|
||||
"description": "",
|
||||
"operationId": "placeOrder",
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"in": "body",
|
||||
"name": "body",
|
||||
"description": "order placed for purchasing the pet",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Order"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "successful operation",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Order"
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Invalid Order"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/stores/order/{orderId}": {
|
||||
"get": {
|
||||
"tags": [
|
||||
"store"
|
||||
],
|
||||
"summary": "Find purchase order by ID",
|
||||
"description": "For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions",
|
||||
"operationId": "getOrderById",
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"in": "path",
|
||||
"name": "orderId",
|
||||
"description": "ID of pet that needs to be fetched",
|
||||
"required": true,
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "successful operation",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Order"
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Invalid ID supplied"
|
||||
},
|
||||
"404": {
|
||||
"description": "Order not found"
|
||||
}
|
||||
}
|
||||
},
|
||||
"delete": {
|
||||
"tags": [
|
||||
"store"
|
||||
],
|
||||
"summary": "Delete purchase order by ID",
|
||||
"description": "For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors",
|
||||
"operationId": "deleteOrder",
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"in": "path",
|
||||
"name": "orderId",
|
||||
"description": "ID of the order that needs to be deleted",
|
||||
"required": true,
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"400": {
|
||||
"description": "Invalid ID supplied"
|
||||
},
|
||||
"404": {
|
||||
"description": "Order not found"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/users": {
|
||||
"post": {
|
||||
"tags": [
|
||||
"user"
|
||||
],
|
||||
"summary": "Create user",
|
||||
"description": "This can only be done by the logged in user.",
|
||||
"operationId": "createUser",
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"in": "body",
|
||||
"name": "body",
|
||||
"description": "Created user object",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/User"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"default": {
|
||||
"description": "successful operation"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/users/createWithArray": {
|
||||
"post": {
|
||||
"tags": [
|
||||
"user"
|
||||
],
|
||||
"summary": "Creates list of users with given input array",
|
||||
"description": "",
|
||||
"operationId": "createUsersWithArrayInput",
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"in": "body",
|
||||
"name": "body",
|
||||
"description": "List of user object",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/User"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"default": {
|
||||
"description": "successful operation"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/users/createWithList": {
|
||||
"post": {
|
||||
"tags": [
|
||||
"user"
|
||||
],
|
||||
"summary": "Creates list of users with given input array",
|
||||
"description": "",
|
||||
"operationId": "createUsersWithListInput",
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"in": "body",
|
||||
"name": "body",
|
||||
"description": "List of user object",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/User"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"default": {
|
||||
"description": "successful operation"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/users/login": {
|
||||
"get": {
|
||||
"tags": [
|
||||
"user"
|
||||
],
|
||||
"summary": "Logs user into the system",
|
||||
"description": "",
|
||||
"operationId": "loginUser",
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"in": "query",
|
||||
"name": "username",
|
||||
"description": "The user name for login",
|
||||
"required": false,
|
||||
"type": "string",
|
||||
"default": "testUser"
|
||||
},
|
||||
{
|
||||
"in": "query",
|
||||
"name": "password",
|
||||
"description": "The password for login in clear text",
|
||||
"required": false,
|
||||
"type": "string",
|
||||
"default": "testPassword"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "successful operation",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Invalid username/password supplied"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/users/logout": {
|
||||
"get": {
|
||||
"tags": [
|
||||
"user"
|
||||
],
|
||||
"summary": "Logs out current logged in user session",
|
||||
"description": "",
|
||||
"operationId": "logoutUser",
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"responses": {
|
||||
"default": {
|
||||
"description": "successful operation"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/users/{username}": {
|
||||
"get": {
|
||||
"tags": [
|
||||
"user"
|
||||
],
|
||||
"summary": "Get user by user name",
|
||||
"description": "",
|
||||
"operationId": "getUserByName",
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"in": "path",
|
||||
"name": "username",
|
||||
"description": "The name that needs to be fetched. Use user1 for testing.",
|
||||
"required": true,
|
||||
"type": "string",
|
||||
"default": "testUser"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "successful operation",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/User"
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Invalid username supplied"
|
||||
},
|
||||
"404": {
|
||||
"description": "User not found"
|
||||
}
|
||||
}
|
||||
},
|
||||
"put": {
|
||||
"tags": [
|
||||
"user"
|
||||
],
|
||||
"summary": "Updated user",
|
||||
"description": "This can only be done by the logged in user.",
|
||||
"operationId": "updateUser",
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"in": "path",
|
||||
"name": "username",
|
||||
"description": "name that need to be deleted",
|
||||
"required": true,
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"in": "body",
|
||||
"name": "body",
|
||||
"description": "Updated user object",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/User"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"400": {
|
||||
"description": "Invalid user supplied"
|
||||
},
|
||||
"404": {
|
||||
"description": "User not found"
|
||||
}
|
||||
}
|
||||
},
|
||||
"delete": {
|
||||
"tags": [
|
||||
"user"
|
||||
],
|
||||
"summary": "Delete user",
|
||||
"description": "This can only be done by the logged in user.",
|
||||
"operationId": "deleteUser",
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"in": "path",
|
||||
"name": "username",
|
||||
"description": "The name that needs to be deleted",
|
||||
"required": true,
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"400": {
|
||||
"description": "Invalid username supplied"
|
||||
},
|
||||
"404": {
|
||||
"description": "User not found"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"securityDefinitions": {
|
||||
"api_key": {
|
||||
"type": "apiKey",
|
||||
"name": "api_key",
|
||||
"in": "header"
|
||||
},
|
||||
"petstore_auth": {
|
||||
"type": "oauth2",
|
||||
"authorizationUrl": "http://petstore.swagger.wordnik.com/api/oauth/dialog",
|
||||
"flow": "implicit",
|
||||
"scopes": {
|
||||
"write_pets": "modify pets in your account",
|
||||
"read_pets": "read your pets"
|
||||
}
|
||||
}
|
||||
},
|
||||
"responses":{
|
||||
"FoundPets": {
|
||||
"description": "successful operation",
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/Pet"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"parameters":{
|
||||
"petId": {
|
||||
"in": "path",
|
||||
"name": "petId",
|
||||
"description": "ID of the pet",
|
||||
"required": true,
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
"Identified": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
}
|
||||
}
|
||||
},
|
||||
"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"
|
||||
},
|
||||
"pictures": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string",
|
||||
"format": "byte"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"Category": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"Pet": {
|
||||
"description" : "Test description",
|
||||
"required": [
|
||||
"name",
|
||||
"photoUrls"
|
||||
],
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
},
|
||||
"category": {
|
||||
"$ref": "#/definitions/Category"
|
||||
},
|
||||
"name": {
|
||||
"type": "string",
|
||||
"example": "doggie"
|
||||
},
|
||||
"photoUrls": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"tags": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/Tag"
|
||||
}
|
||||
},
|
||||
"status": {
|
||||
"type": "string",
|
||||
"description": "pet status in the store"
|
||||
}
|
||||
}
|
||||
},
|
||||
"Tag": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"Order": {
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
},
|
||||
"petId": {
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
},
|
||||
"quantity": {
|
||||
"type": "integer",
|
||||
"format": "int32"
|
||||
},
|
||||
"shipDate": {
|
||||
"type": "string",
|
||||
"format": "date-time"
|
||||
},
|
||||
"status": {
|
||||
"type": "string",
|
||||
"description": "Order Status"
|
||||
},
|
||||
"complete": {
|
||||
"type": "boolean"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
48
src/test/resources/yaml/swagger_overwrites.yml
Normal file
48
src/test/resources/yaml/swagger_overwrites.yml
Normal file
@@ -0,0 +1,48 @@
|
||||
swagger: '2.0'
|
||||
info:
|
||||
description: TODO
|
||||
version: 0.0.1
|
||||
title: API Spec
|
||||
termsOfService: TODO
|
||||
basePath: /v1
|
||||
schemes:
|
||||
- http
|
||||
paths:
|
||||
/aaa:
|
||||
post:
|
||||
tags:
|
||||
- AAA
|
||||
summary: TODO
|
||||
description: TODO
|
||||
operationId: aaa
|
||||
consumes:
|
||||
- application/json
|
||||
produces:
|
||||
- application/json
|
||||
parameters:
|
||||
- in: body
|
||||
name: body
|
||||
description: TODO
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/AAA'
|
||||
responses:
|
||||
'200':
|
||||
description: Success
|
||||
'405':
|
||||
description: Invalid data
|
||||
definitions:
|
||||
AAA:
|
||||
allOf:
|
||||
- $ref: '#/definitions/BBB'
|
||||
- type: object
|
||||
properties:
|
||||
propA:
|
||||
type: string
|
||||
propB:
|
||||
type: string
|
||||
BBB:
|
||||
type: object
|
||||
properties:
|
||||
propA:
|
||||
type: string
|
||||
@@ -0,0 +1,21 @@
|
||||
swagger: '2.0'
|
||||
info:
|
||||
version: "0.0.0"
|
||||
title: Test - Should contain URI scheme
|
||||
|
||||
host: localhost
|
||||
|
||||
schemes:
|
||||
- http
|
||||
- https
|
||||
|
||||
basePath: /api
|
||||
|
||||
paths:
|
||||
/test:
|
||||
get:
|
||||
responses:
|
||||
200:
|
||||
description: OK
|
||||
schema:
|
||||
type: string
|
||||
@@ -0,0 +1,13 @@
|
||||
swagger: '2.0'
|
||||
info:
|
||||
version: "0.0.0"
|
||||
title: Test - Should not contain URI scheme
|
||||
|
||||
paths:
|
||||
/test:
|
||||
get:
|
||||
responses:
|
||||
200:
|
||||
description: OK
|
||||
schema:
|
||||
type: string
|
||||
Reference in New Issue
Block a user