Compare commits

...

685 Commits

Author SHA1 Message Date
qingmo
ac22f63404 fix(gradlebuildconfig): add pom.xml & change swaggerV2 from runtime to compile for maven project (#438)
add new pom.xml generate task in jar task && change swaggerV2 from implementation to api
2022-04-26 08:34:27 +02:00
rui
aeaab37c8a ci: remove travis (#434)
* ci: remove travis

* docs: remove travis
2022-02-28 13:25:25 +01:00
ShubhamRwt
8dd6426f90 Resolving issues with build.gradle 2022-02-17 15:09:07 +05:30
ShubhamRwt
198bcfe22f Resolving issues with build.gradle 2022-02-17 15:06:50 +05:30
ShubhamRwt
3614b469d6 Resolving issues with build.gradle 2022-02-17 14:31:03 +05:30
ShubhamRwt
7d28f3344c Resolving issues with github actions 2022-02-17 12:13:26 +05:30
Shubham Rawat
32a42b1da5 Merge pull request #428 from ShubhamRwt/code
Added the sonar organization in build.gradle
2022-02-16 16:54:14 +05:30
ShubhamRwt
a9e18732c8 changes 2022-02-16 16:51:06 +05:30
ShubhamRwt
5b56e1af8a changes 2022-02-16 16:44:50 +05:30
Shubham Rawat
352977eef5 Merge pull request #425 from Swagger2Markup/githubActions
Moving from the travis.yml to github actions
2022-02-16 15:14:28 +05:30
Shubham Rawat
743624ee77 Merge pull request #424 from ShubhamRwt/releaseProcess
Moving from Bintray to Sonatype and other additional changes
2022-02-16 15:14:12 +05:30
ShubhamRwt
5f910fd564 changes 2022-02-14 14:47:25 +05:30
Shubham Rawat
fb03267275 Create gradle-build.yml 2022-02-14 14:22:05 +05:30
ShubhamRwt
c665d1f5cd changes 2022-02-14 14:16:19 +05:30
ShubhamRwt
da23c929c0 Move from bintray to SonaType 2022-02-14 14:10:11 +05:30
ShubhamRwt
7141fc094b changes 2022-02-14 13:01:32 +05:30
ShubhamRwt
f6152f6c9b changes 2022-02-14 12:52:22 +05:30
ShubhamRwt
9f89c40280 changes 2022-02-14 12:38:53 +05:30
ShubhamRwt
f60999dd9f changes 2022-02-11 16:38:55 +05:30
ShubhamRwt
a45caa4d19 changes 2022-02-11 16:34:41 +05:30
Stefan Larsson
9de5ad0157 Fix Javadoc, added missing parameters and replaced with valid html (#415) 2020-11-05 08:45:30 +01:00
Aaron Watry
61df613cd2 tests: Update swagger petstore URLs from http to https to fix failing tests (#411)
Accessing the http URLs was doing a 302 redirect to https.

Co-authored-by: Aaron Watry <aaron.watry@advarra.com>
2020-10-02 09:57:43 +02:00
Sergei Khramkov
b70d6ca9ca Fixed the description of getMax in PropertyAdapter (#412)
Co-authored-by: Sergey.Khramkov <Sergey.Khramkov@nexign-systems.com>
2020-10-02 09:57:25 +02:00
Robert Winkler
0e15676cb7 Fixed failing test. 2020-06-16 11:36:27 +02:00
Robert Winkler
5f419a0d02 Removed SwaggerPageBreakLocations for backward compability. 2020-06-16 11:27:38 +02:00
Robert Winkler
a0efe7dd26 Removed SwaggerPageBreakLocations for backward compability. 2020-06-16 11:23:57 +02:00
Robert Winkler
21afb5adcd Removed SwaggerPageBreakLocations for backward compability. 2020-06-16 11:19:37 +02:00
Robert Winkler
7d0d73cd51 Moved classes for backward compability. 2020-06-16 11:07:28 +02:00
Robert Winkler
e8a51345a8 Delimiters should use the system line separator by default 2020-06-16 09:40:31 +02:00
Robert Winkler
f471774da9 Updated release notes. 2020-06-16 09:39:23 +02:00
Robert Winkler
0facccf009 Moved Swagger2MarkupConfig back into the main package for backward compability. 2020-06-16 09:35:09 +02:00
Robert Winkler
835c8fec03 Moved Swagger2MarkupConfig back into the main package for backward compability. 2020-06-16 09:18:04 +02:00
Robert Winkler
eea093acd4 Merge remote-tracking branch 'origin/master' 2020-06-15 13:07:14 +02:00
Robert Winkler
b32bfb3e54 Moved Swagger2MarkupConfig back into the main package for backward compability. 2020-06-15 12:25:19 +02:00
Robert Winkler
65f330baae Updated to 2.0.0-SNAPSHOT 2020-06-15 11:24:26 +02:00
Klaus Schwartz
b43a677744 Issue #248: Added a curl request example (#408)
* Issue #248 Add a curl request example

added configurable 3 kinds of request examples:

- basic (default, no source highlight)
- curl (bash source highlight)
- Invoke-WebRequest (powershell source highlight)

* updated default.properties to support curl example request feature

Issue #248 Add a curl request example

added configurable 3 kinds of request examples:

- basic (default, no source highlight)
- curl (bash source highlight)
- Invoke-WebRequest (powershell source highlight)

* added few tests, fixed extra space before query "?" delimiter, added builder configuration methods

Issue #248 Add a curl request example

* fix missig headers in example, fix Content-Type header name spelling

Issue #248 Add a curl request example
2020-06-10 15:42:27 +02:00
Paolo Patierno
4b69d6a150 Added support for MIME types with structured syntax suffixes (#410) 2020-06-08 15:47:44 +02:00
Robert Winkler
4a3ee6c5ca Feature/open api v3 support (#405) 2020-03-06 08:31:21 +01:00
Ali Ustek
69baeb6339 Merge pull request #400 from kolbdaniel1/patch-1
renamed jCenter() repository to jcenter()
2020-01-29 19:00:36 +00:00
Daniel
f7fe2b0cca renamed jCenter() repository to jcenter() 2020-01-29 14:39:45 +01:00
Ali Ustek
f853550748 Migrated markup document builder (#374)
* Initial commit

* Updated documentation

* Test travis CI

* Added library to bintray

* Updated documentation

* Updated documentation

* Updated documentation

* Published Version 1.1 to Maven Central

* Updated Bintray Badge

* Updated Bintray Badge

* Fixed maven pom issue

* Fixed issue: Comma should be escapes when constructing table in csv format in asciidoc
Fixed issue: logback.xml on the classpath

* New version number

* New version number

* Added Apache2 Copyright Header

* Updated documentation

* Updated documentation

* Updates documentation

* Fix Markdown level 3 title

* Fixed SECTION_TITLE_LEVEL3 in Markdown enum

* Added twitter batch

* Updated documentation

* Added method sectionTitleLevel4

* Added Artifactory Gradle Plugin in order to deploy snapshots to oss.jfrog.org

* Added artifactoryPublish task to TravisCI to publish SNAPSHOTS to OSS Artifactory

* Fixed coveralls badge

* Introduced new commands : anchor(anchor), crossReference(anchor, text)
Refactored writeToFile for robustness
Cleanups and fixes

* Enhanced support for tables

* Introduce inline commands : inlineAnchor, inlineCrossReference for easier markup composition

* More tests

* Renamed inline* to *AsString

* Implemented anchors and crossReferences for Markdown (GFM style)

* Updated readme

* Fixed anchor normalization

* Cleanups

* Cleanups

* Fixed replacing error

* Renamed TableColumnSpec to MarkupTableColumn

* Travis Secure Environment variables must be escaped

* Fixed travis.yml

* Fixed travis.yml

* fixed anchor normalization (again). Asciidoc anchor normalization differs between title and custom anchors => introducted crossReferenceTitle

* fixed tests compilation

* Update dependency-management-plugin to work with Gradle versions newer than 2.5

* Update Gradle wrapper to 2.10

* Fixed inter-document cross-references

* renamed crossReference -> crossReferenceAnchor and crossReferenceTitle -> crossReference as it's the default behavior
introduced addFilenameExtension (e.g. needed for inter-document cross-references)
fixed anchor normalization (support for ASCII characters in AsciiDoc)
Several workarounds with inter-document cross-references
Removed documentTitleWithAttributes as it's no use as-is

* Support for inter-document cross-references in Markdown

* fixed #9 Refactor anchor and cross-reference interface and implementation

* Updated asciidoctor-gradle-plugin: and asciidoctorj-pdf Gradle plugins to newer versions.

* [Bug] The document title must not have a anchor in front of it.

* Ignore punctuation in normalizeAnchor
Added new functions to create sections with a custom anchor not directly derived from the title

* Use paragrah local hardbreaks instead of global attribute

* fixed normalization and provided tests for normalization (finally) !

* missing Mockito in Gradle
fixed tests

* anchor normalization better manages beginning and ending escape characters, and intermediate punctuation

* introduce text, italicText, boldText
remove *AsString builders, use a new MarkupDocBuilder with toString() method instead

* Create a builder instance from another builder instance, for easier composition

* introduce forceLineBreak on all *Line methods

* Introduce new sectionTitleWithAnchor* to allow users to create titles without anchor, with a custom anchor (will be normalized anyway), or with an auto-generated anchor.

* sectionTitleWithAnchor* consistency fix when anchor == null => auto-generate anchor

* Introduce global builder configuration .withAnchorPrefix
Introduce copy() method to easily duplicate builders with configuration

* Introduce Markup-dependent specifiers on tables

* Added public interface complete documentation

* Added 2 newlines at the end of generated output when output are files. This protect the final AsciiDoc when you later include these files.

* MarkupTableColumn documentation enhancements

* Added importMarkup(markupText, levelOffset)

* Check for levelOffset < 0 in importMarkup(markupText, levelOffset)

* Support for levelOffset < 0 in importMarkup

* Use Reader in importMarkup instead of a String

* MAX_TITLE_LEVEL = 4 -> 5

* Added new interface methods to support java.nio.file.Path parameters

* Added new block methods (supporting title and admonitions)
Refactored listing() and method() methods
Does not flush buffer anymore when writeToFile

* Renamed addfileExtension to addFileExtension

* logging fix

* Support level 5 titles.
Added sectionTitleLevel(int level, String title) for convenience.

* Line separators (Mac, Windows, Linux) of input data are replaced by the system line separator.

* Removed source folder mainpjava.

* Fixed AbstractMarkupDocBuilderTest on windows machines by setting newLine to a fixed value.

* Added validation that input values are not null and empty.

* Added the functionality to provide a custom line separator which should be used.

* Added Mac line separator.

* Removed io.spring.gradle:dependency-management-plugin

* Added default line separator if provided lineSeparator is null.

* Updated versions of commons-collection, commons-lang3, commons-codec and slf4j-api.

* Removed Guava library.

* New lines in Table headers are replaced by a whitespace
New lines in Table cells are replaced by the configured line separator.

* Opens MarkupDocBuilders for additional/external markup builders (includes an example for Confluence wiki markup)

* Make changes Java 1.7 compatible.

* Adds a markup builder for Atlassian's Jira/Confluence wiki markup.

* Updated README.

* Renamed ATLASSIAN to ATLASSIAN_WIKI

* Updated publishing and coverage gradle scripts.

* Updated publishing gradle script.

* Moved source code which does not belong to the external API into an internal package.

* Copy newLine in copy() method + non regression test

* simplify empty constructors
added missing copyright headers

* factored importMarkupStyle1/2 + Style2 tests
removed deprecated tableWithHeaderRow
refactored ConfluenceMarkupBuilder

* copy with optional copyBuffer

* Added assertj-diff.

* fixing ConfluenceMarkupBuilder
fixed MarkdownBuilder with null block styles

* remove FILE_EXTENSION from Markups, use MarkupLanguage::getFileNameExtensions instead

* fixed documentTitle level for ConfluenceMarkupBuilder

* fixed LINE_BREAK for ConfluenceMarkupBuilder

* fixed empty cells for ConfluenceMarkupBuilder

* fixed crossReferences for ConfluenceMarkupBuilder

* cleanups

* removed deprecated writeToFile*

* Support column headers style generically in MarkupTableColumn

* Use DiffAssertions to check generated markup result in tests

* Introduce MarkupLanguage conversion in importMarkup. Currently support Markdown -> AsciiDoc.

* remove unnecessary newlines when importMarkup text is blank

* removed hardbreaks from AsciiDoc paragraph()

* fixed tests after removing hardbreaks

* better cell formatting : content trimming and newLines management

* fixed pipe escaping management in ConfluenceMarkup cell formatter (does not escape pipe in links in cells)
fixed corner cases in Regexp replacements (quoting)

* added OpenOption parameter in writeToFile()

* Fixed MarkupDocBuilderTests on windows by fixing line separator to LineSeparator.UNIX

* Adapted group id, versioning and root package to other swagger2markup projects

* introduced paragraph(text, hardbreaks), force line breaks on each line for Markdown and ConfluenceMarkup

* ImportMarkup, writeToFile and writeToFileWithoutExtension don't throw IOExceptions anymore, but RuntimeExceptions.

* Upgrade to Java8

* Fixed JavaDoc

* Fixed JavaDoc
Removed commons-collection by using Java8 Streams

* Updated readme

* Updated readme

* reintroduce literalTextLine(text)
rename listing -> listingBlock

* Support <> in cross-reference texts in AsciiDoc

* fixed sectionTitleWithAnchor and auto-generated anchor (and fixed tests)
fixed ConfluenceBuilder : missing replaceNewLinesWithWhiteSpace on title/anchor, removed extra newLine

* supports for blank value for text and textLine only to support adding simple spaces to document

* Released v1.0.0

* Updated readme

* Updated readme

* Updated readme

* Updated readme

* Updated readme

* Changed bold to ** and italic to __ so that special chars in the text are possible

* Updated version to 1.1.0-SNAPSHOT

* Release v1.0.0

* Updated bintray badge

* Updated docs

* Add support for page breaks

* Add page breaks to unit tests

* Updated version from 1.1.0 to 1.1.1-SNAPSHOT

* Released v1.1.1

* Updated README

* Improve code blocks in markdown (#28)

* Prepare release 1.1.2

* Update AbstractMarkupDocBuilder.java (#29)

Support relative file names both of "filename" and "./filename" while `writeToFileWithoutExtension`

* Issue #21: AsciidocBuilder should enable option to set pegdown timeout (#31)

* Upgraded gradle (#33)

* upgrade to gradle 5.6.3

* update dependencies versions

* Moved markup-document-builder files and folders into swagger2markup-builder/

* Fix merge problems from markup-document-builder

* correct expected file for instagram/overview.adoc

* fix paths to examples files in documentation files
2019-10-30 08:13:52 +01:00
Ali Ustek
75fa8f788c Moved docs to documentation module (#373) 2019-10-29 12:49:09 +01:00
Ali Ustek
7a86fdaba3 Updated version numbers and turn on strict conflict resolution (#371) 2019-10-29 12:48:43 +01:00
Ali Ustek
1566b22489 Convert project to be multi-module (#372) 2019-10-29 08:15:17 +01:00
Ali Ustek
ed026f3587 Upgraded to gradle 5.6.3 (#370) 2019-10-24 10:02:22 +02:00
Robert Winkler
6e8e4ce780 Updated READE 2019-06-27 13:02:46 +02:00
mona
60b7d90ad2 get label for operation.deprecated (#363) 2019-06-03 22:54:51 +02:00
guangp
da83465f19 add hostname in uri section of every operation, it is configurable. (#356)
* add hostname in uri section of every operation, it is configurable.

* modify java docs

* test hostname conf
2019-03-21 15:41:58 +01:00
alexmartinsrj
7ae0b64d8e Update labels_pt_BR.properties (#359)
translate of some untraslated words.
2019-03-21 15:41:24 +01:00
Sridhar Jonnalagadda
f8cbf7801d Issue #21: AsciidocBuilder should enable option to set pegdown timeout (#353) 2018-11-21 13:04:22 +01:00
Maciej Swiderski
7fbd49c5ea Issue #349 - Add support for generating example for request data based on media type (#350) 2018-11-05 10:43:03 +01:00
Valy Diarrassouba
8717e26f76 Allow to define freeform with additionalProperties: {} (#346) (#347) 2018-10-22 12:48:02 +02:00
aspekt23
483d6c3d17 Issue 291 support for title property in definitions (#348)
* Implemented preference for definition title if it is present

* Fixed failing test data
2018-10-22 12:43:09 +02:00
parrrot
03fb52fb8e Bugfix/issue336 (#345)
* added if branches for "header" parameter for examples and generated proper format

* modified expected test files to include new format of request header
2018-10-18 09:21:28 +02:00
MarosPataky
e574f0e65f Added support for minItems, maxItems property in parameters section o… (#341)
* Added support for minItems, maxItems property in parameters section of specification

* Added values for min/max items for all languages (for now, no translations are provided)

* Fixed issues with NPE and failing tests

* Added translations for min_items and max_items
2018-10-15 10:14:03 +02:00
MarosPataky
e9b04c712d Added support for enums with Integer type (#342)
* Added support for enums for Integer type, changed enums test data to reflect the change

* Fixed test failures that were caused by missing "format" part of integer type description
2018-10-15 10:13:24 +02:00
Martin Waßmann
b4c7c8860c Better generated examples for strings (#329)
* Generate examples based on string format

The following static examples are generated:
* byte: Ynl0ZQ== (base64 of byte)
* date: 1970-01-01
* date-time: 1970-01-01T00:00:00Z
* email: email@example.com
* password: secret
* uuid: f81d4fae-7dec-11d0-a765-00a0c91e6bf6

* Use first enum value as example

* Also generate string examples for path and query parameter

* Test example generation for custom string format
2018-08-06 12:50:07 +02:00
Bennet Schulz
815c161b7e fix typo in documentation (#330) 2018-08-06 10:31:18 +02:00
Łukasz Kolek
ecaaaeb049 fix: polish translation corrected from UTF-8 to encoded properites (#324) 2018-07-12 15:24:56 +02:00
Barry Ostroff
647846762d Generate examples for inline responses (#314)
* Handle untyped inlines - swagger parser no longer defaults untyped to object types
* Handle object inlines - generates a name based on method and response code
* Handle object inlines with titles - generates a name from the title
2018-05-01 21:35:43 +02:00
Michał Dul
655a15c722 Polish language translation (#311)
* Polish language translation

* language builder adjusted
2018-04-29 11:42:18 +02:00
Robert Winkler
6297b859dd Use old gitHubPages plugin 2018-04-27 13:42:29 +02:00
Robert Winkler
19f05c68f8 Prepare release v1.3.3 2018-04-27 12:59:23 +02:00
Robert Winkler
5a12bd9cce Added release notes for v1.3.3 2018-04-27 12:42:36 +02:00
Barry Ostroff
e22b374bdd Resolve issue #298 - Move to latest swagger parser (#308)
* Move to swagger-parser version 1.0.33

* Move to swagger-parser version 1.0.34

* Move to swagger-parser version 1.0.35

* Replace deprecated getSchema() method
2018-04-20 19:04:33 +02:00
Barry Ostroff
fe3749d499 Include required parameters in example request (#307)
* Include required parameters in example request

* Fix unit tests

* Add unit tests for swagger required parameters
2018-04-13 09:04:33 +02:00
Robert Winkler
85ef7f252d Updated to snapshot version. 2018-03-13 16:04:51 +01:00
Robert Winkler
f16b563a82 Prepare release v1.3.2 2017-12-11 09:20:18 +01:00
g00de
8e22dd817e make examples always start newline if there is other content before the example (#294) 2017-12-08 19:02:58 +01:00
Robert Winkler
569f3c02cd Fixed build script 2017-12-04 15:38:17 +01:00
Robert Winkler
e8c2099e4c Prepare release v1.3.2 2017-12-04 14:47:58 +01:00
ctytgat
1646fefd56 Fix crash on empty tables (#293)
* https://github.com/Swagger2Markup/swagger2markup-cli/issues/17

* https://github.com/Swagger2Markup/swagger2markup-cli/issues/17
add test case
2017-12-01 12:31:12 +01:00
bassettb
aad387802e Fix list parsing in properties file (#290)
Move up the code that enables list delimiters so that it comes before any list properties are parsed.
2017-11-15 08:33:07 +01:00
Frederik Hahne
034d0a2f50 replace deprecated gh pages plugin (#285) 2017-11-14 08:05:55 +01:00
Frederik Hahne
d2c78304c6 Description for api keys are no parsed and written (#281)
* Description for api keys are no parsed and written

close #259

* fix markdown converter tests

* fix asciidoc converter tests
2017-10-09 10:53:31 +02:00
Frederik Hahne
247857a843 Issue #162: adoc content in tables (#280)
* adoc content in tables

some dependency update and cleanup

close #162

* fix analysis remarks
2017-10-05 19:40:28 +02:00
brischniz
038ff3a40e ExternalDocs section will now be rendered in result document (#263)
* Typo fixed

* ExternalDocs section will now be rendered in result document
2017-07-17 09:13:41 +02:00
Magnus Larsson
6d8776332f Property refs are resolved as links and not as text (#265)
* Property refs are resolved as links and not as text

* Update static docs in tests to match change in code

* Remove unnecessary if check
2017-07-17 09:12:45 +02:00
Robert Winkler
4ea24b0297 Fixed typo in german language file 2017-07-11 09:01:41 +02:00
Robert Winkler
12570ecb00 Issue #254: The wildcard Mediatype */* is escaped now 2017-05-15 13:01:51 +02:00
Eugeniy Lykov
7b68aecbd7 Improve russian translation (#251)
* Improve russian translation

* Improve russian translation

Complete translation and correct errors.
2017-05-15 08:45:39 +02:00
Robert Winkler
7ce62a8a3d Updated version to 1.3.2-SNAPSHOT 2017-03-20 12:33:14 +01:00
Robert Winkler
d8c3cf725d Release 1.3.1 2017-03-20 12:28:44 +01:00
Robert Winkler
aecc531d84 Added gradle.properties to set file.encoding and sun.jnu.encoding to UTF-8 2017-03-17 09:25:30 +01:00
shardings
f107779542 Fix request path and query params' example support. (#247)
Fix request path and query params' example support.
2017-03-16 09:01:45 +01:00
shardings
70bf17011c Improve the zh_CN translation. (#246)
For human:
default_column: 默认列 -> 默认值
example_column: 例子 -> 样例
schema_column: 架构 -> 类型
overview: 概观 -> 概览
2017-03-14 16:40:01 +01:00
Robert Winkler
86ae19fe2a Update version to 1.3.1-SNAPSHOT 2017-02-20 08:39:59 +01:00
Robert Winkler
e8235c4c35 Updated README 2017-02-20 08:38:20 +01:00
Robert Winkler
63b5cd3bfb Release 1.3.0 2017-02-20 08:37:02 +01:00
Robert Winkler
12e851c127 Refactored Swagger2MarkupConfigBuilder 2017-02-03 09:33:49 +01:00
kruffin
20fa72b613 Multi-Valued Dynamic Content Folders (#240)
* Adds in the capability to have array valued properties. Mostly only affects extensions that may
need this. It is disabled by default and should work the same as it currently does. Array values
can be enabled by setting a separator character in the "swagger2markup.documentFolderSeparator"
configuration attribute.

* Modifications from code review:

* Altered the "documentFolderSeparator" name to "listDelimiter"
* Added an additional property to enable/disable the list delimiter "listDelimiterEnabled"
* Defaulted the "listDelimiter" to ','
* Updated logic that assumed the configuration was derived from AbstractConfiguration to explicitly check before casting
* Added a couple "withListDelimiter" methods to the builder

* Modifies the list delimiter parsing logic (how the delimiter is determined from properties) to be more
of a Java 8 style.
2017-02-03 09:06:49 +01:00
jbrugge
36bee8070a Fix position reference for parameters table. (#241) 2017-02-02 08:57:04 +01:00
fooinha
9a85612b8a * fix NPE for response headers with relative definitions 2017-01-21 10:34:08 +01:00
Robert Winkler
2bc18f7d90 Updated RELEASENOTES 2017-01-19 14:24:41 +01:00
Robert Winkler
6f6428543d The Number Formatter must use the Locale of the Swagger2MarkupConfig output language. 2017-01-19 14:17:17 +01:00
Robert Winkler
d03087c1b8 Fixed version in changelog 2017-01-19 14:00:39 +01:00
Robert Winkler
d2d47cf8ee Updated javslang from 2.0.4 to 2.0.5
Updated paleo-core from 0.10.1 to 0.10.2
Updated swagger-parser from v1.0.23 to v1.0.25
2017-01-19 13:59:23 +01:00
Robert Winkler
7a0f4490de Updated copyright statement 2017-01-19 11:30:50 +01:00
Cas Eliëns
d2b3c9472a Close #180. 2017-01-19 10:24:04 +01:00
Cas Eliëns
3a0b9a00a3 Improve generated examples for arrays 2017-01-19 10:24:04 +01:00
Cas Eliëns
d5cf4ad9e5 Add unit test for #180 2017-01-19 10:24:04 +01:00
Cas Eliëns
2899b2f263 Use shorter sorting syntax and update javadoc 2017-01-13 14:12:41 +01:00
Cas Eliëns
7475321e97 Add ISAAC to 'Companies who use Swagger2Markup' 2017-01-13 14:12:33 +01:00
Cas Eliëns
88a24d7bdd Add space between schema type and format 2017-01-09 12:19:41 +01:00
Robert Winkler
f798a51edc Release v1.2.0 2017-01-05 14:27:53 +01:00
Robert Winkler
81edab38f3 The notBlank validation of the type should tell which parameter is not valid. 2017-01-03 15:58:43 +01:00
Robert Winkler
039607a294 Updated version to 1.2.0-SNAPSHOT 2017-01-03 15:27:32 +01:00
Cas Eliëns
2f33522e6d Issue #214 Added support for page breaks (#226)
* Added support for page breaks
* Added documentation and config file support for page breaks and regex
2017-01-03 11:21:31 +01:00
Cas Eliëns
76c54a713a use raw JSON object instead of converting to string 2017-01-02 13:47:02 +01:00
Cas Eliëns
dcebed2d42 split reused code into methods 2017-01-02 13:47:02 +01:00
Cas Eliëns
dbf9afa8da Remove unused import 2017-01-02 13:47:02 +01:00
Cas Eliëns
f7f397b5f2 Improve printing for different ways of defining examples 2017-01-02 13:47:02 +01:00
Cas Eliëns
44f852ad42 Improve example printing for $ref'd examples 2017-01-02 13:47:02 +01:00
Cas Eliëns
e1be2f2130 Great Expectations 2017-01-02 13:47:02 +01:00
Cas Eliëns
8468607703 Improve example rendering for hardcoded examples 2017-01-02 13:47:02 +01:00
Cas Eliëns
f981318142 Example responses now display correctly 2017-01-02 13:47:02 +01:00
Cas Eliëns
e1d0d7b293 Add FIXME comment 2017-01-02 13:47:02 +01:00
Cas Eliëns
d118a0cf74 Further work on Swagger2Markup/swagger2markup#223 2017-01-02 13:47:02 +01:00
Cas Eliëns
7cb1095465 Begin work on Swagger2Markup/swagger2markup#223 2017-01-02 13:47:02 +01:00
Cas Eliëns
595b885b9a Close Swagger2Markup/swagger2markup#220 2016-12-20 14:07:27 +01:00
Cas Eliëns
b1c219bc1b Remove unused code, optimize imports, fix Codacy issues
* Begin working on Swagger2Markup/swagger2markup#215

* Begin looking for methods that need to be modified for Swagger2Markup/swagger2markup#215

* Begin working on Swagger2Markup/swagger2markup#215

* Begin looking for methods that need to be modified for Swagger2Markup/swagger2markup#215

* Work on implementing regex sorting

* Add regex ordering translations and unit test

* Improve Regex grouping

* Make regex sorting test more like a real-world example

* Remove unused imports

* Improve code style consistency

* Improve code style consistency

* Remove empty statement

* Resolve some Codacy issues

* Remove empty constructors

* Remove unused fields

* Merge nested IF statements

* Improve method scopes

* Remove unused classes

* Remove unused imports

* Remove fixed TODO comment

* Fix codacy issues

* Fix codacy issues (reverted from commit 43f27e7fc6)

* Improve code style consistency

* Resolve some Codacy issues

* Remove empty constructors

* Remove unused fields

* Merge nested IF statements

* Improve method scopes

* Remove unused classes

* Remove unused imports

* Remove fixed TODO comment

* Fix codacy issues
2016-12-19 16:04:17 +01:00
Cas Eliëns
852b2ac3b4 PR#218 Improve code style consistency
Improved code style consistency
2016-12-13 10:44:31 +01:00
Cas Eliëns
937cded2aa Issue #215: Path grouping via a RegEx pattern
* Begin working on Swagger2Markup/swagger2markup#215

* Begin looking for methods that need to be modified for Swagger2Markup/swagger2markup#215

* Begin working on Swagger2Markup/swagger2markup#215

* Begin looking for methods that need to be modified for Swagger2Markup/swagger2markup#215

* Work on implementing regex sorting

* Add regex ordering translations and unit test

* Improve Regex grouping

* Make regex sorting test more like a real-world example

* Remove unused imports
2016-12-13 09:58:12 +01:00
Robert Winkler
022d2453d2 Issee #216: Replace slash with system file separator in unit tests. 2016-12-09 09:17:55 +01:00
Robert Winkler
e5a187cc24 Updated version to 1.1.2-SNAPSHOT 2016-11-30 09:18:22 +01:00
Robert Winkler
83bb63321a Updated markup-document-builder from 1.0.0 to 1.1.0 2016-11-30 08:20:04 +01:00
Robert Winkler
cd5b5c9240 Refactored ParameterAdapter and created MarkupDocBuilderUtils. 2016-11-18 12:36:39 +01:00
Robert Winkler
2096ec0d5d Refactored ParameterAdapter and moved ParameterAdapter and PropertyAdapter into a new package. 2016-11-16 12:54:32 +01:00
Robert Winkler
25d4311237 Added a modularized Swagger spec test 2016-11-16 12:54:03 +01:00
Robert Winkler
7e07c2fc81 Fixed method name in DefinitionsDocument 2016-11-15 14:50:45 +01:00
Robert Winkler
5a8a618e6b Refactored document resolver and added tests. 2016-11-15 14:47:11 +01:00
Robert Winkler
f072fc99b9 Refactored Documents. Documents are also components now and can be composed of components. 2016-11-15 11:12:17 +01:00
Robert Winkler
54e881fc58 Fixed wrong import in SecuritySchemeComponent 2016-11-14 16:14:16 +01:00
Robert Winkler
cd6a3ed724 Refactored Components to be more functional. 2016-11-14 16:08:24 +01:00
Robert Winkler
5a00dde912 Refactored Components to be more functional. 2016-11-14 16:02:49 +01:00
Robert Winkler
876d7b2f7b Moved code into BodyParameterComponent 2016-11-11 14:21:43 +01:00
Robert Winkler
4b74ec0e54 Moved code into PathOperationComponent 2016-11-11 13:30:04 +01:00
Robert Winkler
a719e33332 Moved code into SecuritySchemeComponent 2016-11-11 10:29:51 +01:00
Robert Winkler
86a727f097 Refactored DocumentBuilder into components. 2016-11-10 15:48:03 +01:00
Robert Winkler
2670780076 Enhancement #206 Updated to markup-document-builder v1.1.0 which renders bold text as **text** and italic text as __text__. 2016-11-10 12:42:52 +01:00
Robert Winkler
ebf9912269 Bug #205: Fix ordering of operations when grouped by tags. 2016-11-10 12:41:26 +01:00
Robert Winkler
11549ab64e Bug #205: Fix ordering of operations when grouped by tags. 2016-11-10 10:43:12 +01:00
Robert Winkler
d128146952 Added a component API to split a document into components and improve component testability 2016-11-09 16:30:02 +01:00
Robert Winkler
686abd8842 Added a component API to split a document into components and improve component testability 2016-11-09 15:02:28 +01:00
Robert Winkler
551aeed835 Removed ListUtils and changed MapUtils.toKeySet to MapUtils.toSortedMap 2016-11-08 12:28:27 +01:00
Robert Winkler
5b1a1a2bcf Migrated some collections to Javaslang 2016-11-08 10:18:07 +01:00
Robert Winkler
09d2474a9a Added javaslang and paleo-core to improve Table rendering 2016-11-04 15:32:17 +01:00
Robert Winkler
5c00e5493c Removed ExternalLocation model from inlineSchema test. 2016-11-04 15:32:17 +01:00
Robert Winkler
c343af8f5a Updated Gradle to v3.1 2016-11-04 15:32:17 +01:00
yewton
4af7eb5b89 Add support for Japanese 2016-11-02 08:45:42 +01:00
Robert Winkler
aa9a340144 Added a config parameter which allows to prepend the basePath to all paths. 2016-11-01 14:42:46 +01:00
Robert Winkler
35ae68ceee Fixed german and spanish language files 2016-11-01 08:55:04 +01:00
Robert Winkler
560fb4ece6 Added language file for Portuguese (Brazilian) 2016-11-01 08:30:28 +01:00
Cleydson Júnior
8eb494cd5b Converting special characters to ASCII escape codes 2016-11-01 07:05:19 +01:00
Cleydson Júnior
0766336a56 Adding support for Brazilian Portuguese 2016-11-01 07:05:19 +01:00
TzeKai Lee
24352f4d1c Add format tests on request param in query and body 2016-10-28 09:07:56 +02:00
TzeKei Lee
adb0fee973 Added displaying format for string type and definitions only contains string or integer type. 2016-10-28 09:07:56 +02:00
Robert Winkler
13a7113aa7 Fixes #197 Converted ZH-language file from UTF-8 to latin1 using native2asciidoc 2016-10-25 15:25:27 +02:00
Robert Winkler
e882975726 Updated README 2016-10-18 15:27:06 +02:00
Robert Winkler
12209fe923 Updated version to 1.1.0 2016-10-18 15:14:05 +02:00
Robert Winkler
8a63744198 Updated releases notes 2016-10-18 15:11:52 +02:00
James Bassett
5871f0c9b0 Added support for exclusiveMin and exclusiveMax 2016-10-14 07:12:53 +02:00
James Bassett
908f524c64 Updated min/max value to format correctly based on the data type 2016-10-12 08:47:54 +02:00
Francisco José Bermejo Herrera
9fa0ee3def Add support for Spanish language 2016-10-03 13:46:12 +02:00
Robert Winkler
35e9450f74 Updated docker documentation 2016-09-23 10:29:46 +02:00
Robert Winkler
6033ea5a98 Updated docker documentation 2016-09-23 10:21:02 +02:00
Robert Winkler
6f24c3cb39 Merge remote-tracking branch 'origin/master' 2016-09-23 08:54:37 +02:00
Robert Winkler
e975e49d3e Added docker documentation 2016-09-23 08:54:18 +02:00
Robert Winkler
c5cfe10fa6 Merge pull request #187 from KristinaGen/master
update labels_ru
2016-09-14 09:55:56 +02:00
KristinaGen
7c988460f0 update labels_ru 2016-09-13 16:20:57 +02:00
Robert Winkler
21f1892de0 Added chinese language 2016-09-12 10:02:02 +02:00
Robert Winkler
b97344849d Merge pull request #186 from mingkaili/patch-1
labels_zh.properties
2016-09-12 09:49:43 +02:00
Mingkai Lee
935d48d4cc labels_zh.properties
Add chinese labels.properties. Add chinese language.
2016-09-12 10:26:16 +08:00
Robert Winkler
73ba233f9e Merge pull request #181 from iwannayoyo/Remove_empty_columns
eliminate empty columns in tables
2016-08-31 10:20:25 +02:00
Chris Hartman
ff955d392b eliminate empty columns in tables 2016-08-25 16:43:17 -04:00
Robert Winkler
19fde31f67 Merge pull request #177 from mhswisscom/Fix_without_reformat
recursive examples patch without reformatting
2016-08-25 13:49:45 +02:00
Marc Habegger
b3f368ac37 recursive examples patch without reformatting 2016-08-25 13:33:27 +02:00
Robert Winkler
c5efb401b4 Added releaseVersion to build.gradle and documentation.gradle scripts so that the AsciiDoc documentation always refers to the release version and not to the SNAPSHOT version. 2016-08-04 12:10:08 +02:00
Robert Winkler
f386e6ed91 Updated version to 1.0.2-SNAPSHOT 2016-08-04 10:28:30 +02:00
Robert Winkler
55b323c063 Merge pull request #171 from zerok/fix/emptycontact
Allow empty contact objects
2016-08-04 10:25:14 +02:00
Robert Winkler
6f286b52d8 Prepare release v1.0.1 2016-08-04 10:03:08 +02:00
Horst Gutmann
4850673b96 Allow empty contact objects
According to the spec the contact object can be empty (it doesn't have
any required properties). Previously, the markup generation failed in
that situation due to an empty paragraph being generated. This change
fixes that.
2016-08-04 10:00:33 +02:00
Robert Winkler
353af537ba Prepare release v1.0.1 2016-08-04 09:49:35 +02:00
Robert Winkler
2367d86eb7 Merge pull request #170 from zerok/fix/instagram-fenced-code-adoc
Fixes expected output of testSwagger2AsciiDocConversionInstagram
2016-08-03 10:11:43 +02:00
Horst Gutmann
1aec46a57c Fixes expected output of testSwagger2AsciiDocConversionInstagram
The fenced code block in the original specification was previously
converted to something resembling an inline code element, while
the new output now contains an actual code block.

This closes #168.
2016-08-03 09:38:33 +02:00
Robert Winkler
f650fb7b3e Fixed wrong expected test files after merging PR #149 and PR #156 2016-08-02 19:35:27 +02:00
Robert Winkler
568d6a6441 Failed tests shouldn't be ignored 2016-07-30 20:52:54 +02:00
Robert Winkler
630e86cd31 Merge pull request #167 from afdia/master
new property "pathSecuritySectionEnabled" (default: true)
2016-07-30 20:31:14 +02:00
Andreas
0e3e229434 + new property "pathSecuritySectionEnabled" (default: true)
The property decides whether to add the security section for every path
(introduced in pull request #63)
2016-07-30 12:18:12 +02:00
Hugo de Paix de Coeur
f41d1cbcb0 missing FR translations 2016-06-21 13:47:09 +02:00
Hugo de Paix de Coeur
20b653086d Merge pull request #156 from jfiala/master
validation constraints, german translations
2016-06-17 11:16:46 +02:00
Johannes Fiala
ae4cf35de4 validation constraints, german translations (#156) 2016-06-16 19:04:58 +02:00
Johannes Fiala
86fc9a9746 add expected results #160 2016-06-15 22:41:17 +02:00
Johannes Fiala
1b4626d9ca update test cases #160 2016-06-15 22:36:40 +02:00
Johannes Fiala
7528b34ba3 Merge branch 'master' of https://github.com/jfiala/swagger2markup 2016-06-15 22:35:23 +02:00
Johannes Fiala
ebecde1768 update test cases #160 2016-06-15 22:35:00 +02:00
Johannes Fiala
2301de6466 update test examples #160 2016-06-15 22:32:34 +02:00
Johannes Fiala
f7efad2480 Merge branch 'master' of https://github.com/jfiala/swagger2markup
Conflicts:
	src/test/resources/expected/asciidoc/validators/definitions.adoc
	src/test/resources/json/swagger_validators.json
2016-06-15 22:29:12 +02:00
Johannes Fiala
c23bd01495 add more cases to minimum/maximum tests 2016-06-15 22:28:42 +02:00
Johannes Fiala
7e5986237a Merge branch 'master' of https://github.com/jfiala/swagger2markup
Conflicts:
	src/test/resources/expected/asciidoc/validators/definitions.adoc
	src/test/resources/json/swagger_validators.json
2016-06-15 22:25:24 +02:00
Johannes Fiala
1bf26c95e3 Added simple json + test cases for validators #160´ 2016-06-15 22:19:56 +02:00
Johannes Fiala
3888e67d02 Added simple json + test cases for validators #160´ 2016-06-15 22:18:10 +02:00
Johannes Fiala
54e17321b6 Fixed check for description 2016-06-13 12:01:50 +02:00
Johannes Fiala
90f56cfe61 Merge branch 'master' of https://github.com/jfiala/swagger2markup 2016-06-13 11:56:21 +02:00
Johannes Fiala
44e33ad6f3 Fixed line-break issue if no description is present - should always
check for descriptionContent instead of description
2016-06-13 11:55:59 +02:00
Johannes Fiala
65d4e0c225 Merge branch 'master' of https://github.com/jfiala/swagger2markup 2016-06-12 18:53:59 +02:00
Johannes Fiala
d37a374d02 added example for min/max at order.quantity #160 2016-06-12 18:53:12 +02:00
Johannes Fiala
5bb5e5ff29 added new definition of swagger petstore #159 in separate file 2016-06-12 18:20:23 +02:00
Johannes Fiala
de1f84d2aa reseted to original swagger_petstore.yaml, added example for
minlength/maxlength/pattern
2016-06-12 18:12:55 +02:00
Johannes Fiala
aa35c0169c Update swagger_petstore.yaml to current version #159 2016-06-12 17:49:52 +02:00
Johannes Fiala
b53727842a Suggest adding eclipse plugin to support gradle eclipse #158 2016-06-12 17:17:56 +02:00
Johannes Fiala
f88e3d2ed4 added check if minlength equals maxlength 2016-06-12 17:15:07 +02:00
Johannes Fiala
eefda62d99 Added query if minlength equals maxlength #147 2016-06-12 17:08:56 +02:00
Johannes Fiala
592446f714 Removed quotes for Minlength/Maxlength #147 2016-06-12 17:05:45 +02:00
Johannes Fiala
3275a07325 German translations - fine tuning #157 2016-06-12 16:56:03 +02:00
Johannes Fiala
1c2b9eee26 validation constraints don't appear in generated docs #147 2016-06-12 16:50:25 +02:00
Hugo de Paix de Coeur
3a5533447b Merge pull request #149 from filip-owczarzak/Columns-Width-Too-Small
1st column in table extended width in order to avoid text wrapping
2016-06-01 14:59:50 +02:00
Filip Owczarzak
2fcd2d1a79 1st column in tables width set to 2 2016-06-01 13:49:15 +02:00
Robert Winkler
07d878be35 Added release Version to docs 2016-05-29 07:11:25 +02:00
Robert Winkler
7a75d7874b Added release Version to docs 2016-05-28 21:17:42 +02:00
Robert Winkler
99c3044218 Added release Version to docs 2016-05-28 20:49:46 +02:00
Robert Winkler
fec5fb54bb Added release Version to docs 2016-05-28 20:48:34 +02:00
Robert Winkler
031051f1f9 Added release Version to docs 2016-05-28 20:47:52 +02:00
Robert Winkler
d432c398cf Added release Version to docs 2016-05-28 20:35:07 +02:00
Robert Winkler
8eb44c26d2 Added release Version to docs 2016-05-28 20:25:23 +02:00
Robert Winkler
3a76a3e920 Added release Version to docs 2016-05-28 20:24:14 +02:00
Robert Winkler
52e80e7af6 Updated readme 2016-05-28 20:21:00 +02:00
Hugo de Paix de Coeur
1eac6a63d9 set development version to 1.0.1-SNAPSHOT 2016-05-26 16:21:42 +02:00
Hugo de Paix de Coeur
6e379042a0 #152 keep track of properties order in Composed models so that OrderBy.AS_IS works as expected 2016-05-26 13:22:37 +02:00
hdr
8367195315 fixes #150 create empty object when Swagger Parser fails to convert composed items
Added Instagram API conversion to tests next to PetStore
2016-05-26 11:23:26 +02:00
Hugo de Paix de Coeur
7de954958d Merge pull request #151 from johanhammar/master
Fix invalid XML in documentation
2016-05-26 08:24:39 +02:00
Johan Hammar
a161924a7f Fix invalid XML in documentation 2016-05-25 21:24:19 +02:00
hdr
9568f3a960 #148 Removed NPE in ExamplesUtil::exampleMapForProperties 2016-05-24 14:20:37 +02:00
Filip Owczarzak
fdb24fdf33 1st column in table extended width in order to avoid text wrapping 2016-05-24 10:28:12 +02:00
Robert Winkler
3c0f935e99 Merge remote-tracking branch 'origin/master' 2016-05-12 09:54:49 +02:00
Robert Winkler
826f4ff762 Updated images 2016-05-12 09:54:39 +02:00
Robert Winkler
ed926139b8 Updated readme 2016-05-04 21:05:59 +02:00
Robert Winkler
cb23bfe1a4 Updated Bintray badge 2016-05-02 13:22:04 +02:00
Robert Winkler
ab7d355fe4 Prepare release v1.0.0 2016-05-02 13:06:54 +02:00
Robert Winkler
87ccc182f1 Prepare release v1.0.0 2016-04-29 14:12:21 +02:00
Robert Winkler
ff21d7c985 Fixes #136: Moved default value of a property into the description column. 2016-04-19 13:09:03 +02:00
Robert Winkler
b69797ef51 Fixed levelOffset calculation when using paths grouped by TAGS 2016-04-19 10:52:38 +02:00
Robert Winkler
f1614fe81a Fixed levelOffset calculation when using paths grouped by TAGS 2016-04-19 10:38:54 +02:00
Robert Winkler
d5c9116dc7 Merge remote-tracking branch 'origin/master'
Conflicts:
	src/main/java/io/github/swagger2markup/spi/PathsDocumentExtension.java
2016-04-19 10:36:57 +02:00
Robert Winkler
5aaff59f71 Fixed levelOffset calculation when using paths grouped by TAGS 2016-04-19 10:30:57 +02:00
Robert Winkler
a20ed66400 Merge pull request #131 from ozanyildiz/master
Add Turkish language support
2016-04-15 12:24:53 +02:00
Ozan Yildiz
6312c2f3e0 add Turkish language support 2016-04-15 11:35:07 +03:00
Hugo de Paix de Coeur
2e2bd7d6c5 Enable inline schemas by default. No more depth level control. 2016-04-14 17:51:47 +02:00
Hugo de Paix de Coeur
dd7de8fe08 Added new DEFINITION_{BEFORE,AFTER} positions to DefinitionsDocumentExtension 2016-04-14 16:46:53 +02:00
Hugo de Paix de Coeur
934039bcd4 Renamed SecurityDocumentExtension positions DEFINITION -> SECURITY_SCHEME for clarity
Added new SECURITY_SCHEME_{BEFORE,AFTER} positions
2016-04-14 16:38:59 +02:00
Hugo de Paix de Coeur
98efe9543d #130 : Documentation for new PathsDocumentExtension positions 2016-04-14 15:52:24 +02:00
Hugo de Paix de Coeur
b68c0031a7 fix #130 : Supports for new PathsDocumentExtension positions (descriptions, responses, parameters, security) + OPERATION_{BEFORE,AFTER}
Fixed OPERATION_BEGIN hook call location
2016-04-14 15:32:54 +02:00
Hugo de Paix de Coeur
a587899976 Extension documentation : recommend to use different contentPaths for import files extension 2016-04-14 15:32:54 +02:00
Robert Winkler
4528f2aa0e Merge remote-tracking branch 'origin/master' 2016-04-14 12:37:35 +02:00
Robert Winkler
b2e6f498be Fixed credentials 2016-04-14 12:37:23 +02:00
Hugo de Paix de Coeur
d32179009d Created separate doc for extensions
Extensions documents enhancements
reverted to coderay until AsciiDoctor 1.5.5 (supports for highlightjs-langs attribute)
2016-04-14 12:04:17 +02:00
Hugo de Paix de Coeur
c815318972 missing language 2016-04-14 12:04:17 +02:00
Robert Winkler
7cbb52094d Changed documentation source-highlighter back to coderay, because groovy listings look strange with highlight.js 2016-04-13 14:25:12 +02:00
Hugo de Paix de Coeur
7c8dfb520f Dynamic file content extension detailed documentation 2016-04-13 14:05:01 +02:00
Hugo de Paix de Coeur
6395adddb6 Dynamic file content extension detailed documentation 2016-04-13 13:43:20 +02:00
Hugo de Paix de Coeur
01a63f895c always add space at the beginning and at the end of array/map < target type > for symmetry 2016-04-12 20:07:59 +02:00
Hugo de Paix de Coeur
5d2ba5b21e refactored PropertyUtils.getDefaultValue & ParameterUtils.getDefaultValue to return Objects.
default values are now displayed with literalText + Json.pretty
swaggerMarkupDescription now returns null when there's no description.
2016-04-12 19:16:03 +02:00
Hugo de Paix de Coeur
6e4c0c1498 refactored responses header display
fixed tests after column width update
fixed defaultString in swaggerMarkupDescription
2016-04-12 18:50:25 +02:00
Hugo de Paix de Coeur
dce6b4183a update column width using values sum = 20 for better granularity on col width 2016-04-12 18:50:25 +02:00
Hugo de Paix de Coeur
1bf36592ef advanced_usage documentation (cosmetic) 2016-04-12 18:50:25 +02:00
Robert Winkler
24d9218d14 Show stacktrace of TravisCI publishGhPages task 2016-04-12 16:07:09 +02:00
Robert Winkler
9ee6c96a3a Merge remote-tracking branch 'origin/master' 2016-04-12 15:57:10 +02:00
Robert Winkler
507307308d Fixed index.adoc 2016-04-12 15:57:03 +02:00
Hugo de Paix de Coeur
14d4268cc3 advanced_usage documentation (fixed index) 2016-04-12 15:56:24 +02:00
Hugo de Paix de Coeur
aade4453e1 advanced_usage documentation (fixed tests) 2016-04-12 15:51:19 +02:00
Robert Winkler
232a635c06 Merge remote-tracking branch 'origin/master' 2016-04-12 15:46:36 +02:00
Robert Winkler
545cf13584 Publish documentation on each commit 2016-04-12 15:46:26 +02:00
Hugo de Paix de Coeur
b7ef781fda advanced_usage documentation (cosmetic) 2016-04-12 15:06:35 +02:00
Hugo de Paix de Coeur
3f18a446af advanced_usage documentation (with examples) 2016-04-12 14:55:59 +02:00
Hugo de Paix de Coeur
391bb20de2 advanced_usage documentation (with all files) 2016-04-12 14:28:18 +02:00
Hugo de Paix de Coeur
aafac7821c advanced_usage documentation 2016-04-12 14:27:25 +02:00
Hugo de Paix de Coeur
103aef6cd6 issue template fix 2016-04-08 17:44:21 +02:00
Hugo de Paix de Coeur
6282459905 fixed #124 : fix inter-document cross-references in security schemes
Added inter-document cross-references tests in AsciiDoc and Markdown format
2016-04-08 17:39:52 +02:00
Robert Winkler
293132e6a4 Created an issue template 2016-04-08 16:59:18 +02:00
Hugo de Paix de Coeur
0e4b193d70 Use JSON schema title value to name inline schema intermediary objects, or, if not provided, generate a virtual name based on definition/property/parameter/response name
fixed column widths
fixed bug with <> and cross-references
added type to BasicType to clearly distinct type and name
refactored RefType to use referenced type name/uniqueName instead of a copy of them.
2016-04-08 15:44:38 +02:00
Robert Winkler
277e452a73 Changed gitter to slack integration 2016-04-08 14:40:13 +02:00
Hugo de Paix de Coeur
80e96933b0 missing expected files for inline_schema_flat_body test 2016-04-06 22:08:41 +02:00
Hugo de Paix de Coeur
1ab4f8ff6c fixed javadoc 2016-04-06 22:02:52 +02:00
Hugo de Paix de Coeur
9a67581ad9 fixed javadoc 2016-04-06 22:02:01 +02:00
Hugo de Paix de Coeur
9ef34dd853 fixed inlineSchema depth constant 1 -> configured depth level in definitions
fixed tests
2016-04-06 22:00:10 +02:00
Hugo de Paix de Coeur
b37c173e07 fixed inlineSchemas in collections (array and map, recursive collections, and object/collection mix) in parameters, responses and definitions
fixed missing support for withInlineSchemaDepth when withFlatBody enabled
fixed inline definitions unicity with depth > 1
2016-04-06 21:47:18 +02:00
Hugo de Paix de Coeur
105ac545b3 Moved Example column to description content 2016-04-06 19:16:17 +02:00
Hugo de Paix de Coeur
ae3f9aa353 Removed Required column and render required flag in NAME_COLUMN.
Removed header style on columns in tables.
Support for read-only property flags.
2016-04-06 18:15:09 +02:00
Hugo de Paix de Coeur
3e9fca8a0d SecurityDocument : WorkAround AsciiDoctor HTML conversion bug with + on the last paragraph line when using hardbreaks
SecurityDocument : Use italic for informations keys.
2016-04-06 14:27:04 +02:00
Hugo de Paix de Coeur
1a45054b5d fixed missing DOCUMENT_AFTER extension point call
fixed SecurityDocument DEFINITION_BEGIN->DEFINITION_END extension point call
2016-04-06 14:09:23 +02:00
Robert Winkler
be56290257 Updated documentation 2016-04-06 09:32:03 +02:00
Robert Winkler
64195e095b Updated documentation 2016-04-06 09:03:59 +02:00
Robert Winkler
5a33b3473e Merge remote-tracking branch 'origin/master' 2016-04-06 08:12:35 +02:00
Robert Winkler
df23dc09e8 Updated documentation 2016-04-06 08:12:07 +02:00
Robert Winkler
2a3ac1e6d0 Updated readme 2016-04-05 19:08:36 +02:00
Hugo de Paix de Coeur
bad8cde186 missing placeholder quoting 2016-04-05 16:08:07 +02:00
Hugo de Paix de Coeur
d9adcc2016 log normalized operation id to the console for external content, etc ... 2016-04-05 16:08:07 +02:00
Hugo de Paix de Coeur
7b59a069ef escape consume/produce in overview too (#28).
WorkAround AsciiDoctor HTML conversion bug with + on the last paragraph line.
Use italic for overview informations keys.
fixed termsOfService layout.
2016-04-05 16:08:07 +02:00
Robert Winkler
310a2e47b6 Updated documentation 2016-04-05 15:50:52 +02:00
Robert Winkler
954e302467 Updated documentation 2016-04-05 15:46:34 +02:00
Robert Winkler
abb77b7c5f Updated documentation 2016-04-05 15:36:13 +02:00
Robert Winkler
aaac78f985 Merge remote-tracking branch 'origin/master' 2016-04-05 15:05:53 +02:00
Robert Winkler
e959c9ed59 Updated documentation 2016-04-05 15:05:45 +02:00
Hugo de Paix de Coeur
1965110df9 typos 2016-04-05 15:04:39 +02:00
Hugo de Paix de Coeur
1300249555 cosmetic 2016-04-05 15:02:11 +02:00
Hugo de Paix de Coeur
05a4ee230c Remove hand-written definition/operation descriptions from code, to prepare extension (#108) 2016-04-05 14:53:41 +02:00
Robert Winkler
78411de398 Merge remote-tracking branch 'origin/master' 2016-04-05 14:52:49 +02:00
Robert Winkler
e697815c0c Updated documentation 2016-04-05 14:52:43 +02:00
Hugo de Paix de Coeur
fbd22779ee revert buildOperationTitle block from SIDEBAR to LITERAL style
fixed #28 : */* (consume/produce) not escaped
fixed tests
2016-04-05 14:25:01 +02:00
Robert Winkler
b13c57ea35 Merge remote-tracking branch 'origin/master' 2016-04-05 13:40:36 +02:00
Robert Winkler
0b38f2a91c Updated documentation 2016-04-05 13:40:30 +02:00
Robert Winkler
db36397e81 Fixed getRequiredURI and getURI in Swagger2MarkupProperties 2016-04-05 13:40:21 +02:00
Hugo de Paix de Coeur
066fd597da fix bad refactoring in URIUtils 2016-04-05 13:38:06 +02:00
Hugo de Paix de Coeur
e979d2b45b adapt to latest MDB modifications 2016-04-05 13:33:39 +02:00
Robert Winkler
4fa9f0d645 Updated documentation 2016-04-05 13:17:12 +02:00
Robert Winkler
fecf6c6161 Added a check to the static factory method fromPath to check if the input file does exist. 2016-04-05 11:12:46 +02:00
Robert Winkler
7eecba583d Added a static factory method in URIUtils to create a URI from a String representation of a URI or a Path. 2016-04-05 11:06:37 +02:00
Robert Winkler
9c6111da3e Removed checks to the static factory method fromPath to check if the input file does exist and is readable.
They are not working as expected.
2016-04-05 10:46:34 +02:00
Robert Winkler
f10882d14d Fixed checks to the static factory method fromPath to check if the input file does exist and is readable. 2016-04-05 10:25:39 +02:00
Robert Winkler
0ac9e13948 Fixed checks to the static factory method fromPath to check if the input file does exist and is readable. 2016-04-05 10:20:04 +02:00
Robert Winkler
fb3ef974a3 Added checks to the static factory method fromPath to check if the input file does exist and is readable. 2016-04-05 09:19:00 +02:00
Robert Winkler
65522e4569 Fixed static factory method fromUri so that it also excepts URIs without a scheme. 2016-04-05 08:30:59 +02:00
Hugo de Paix de Coeur
ae8961d43c fixed #44 : added a non-regression test 2016-04-04 20:14:52 +02:00
Robert Winkler
c131a8cad8 Merge pull request #123 from Swagger2Markup/features/polymorphism
fixed #22 : Add discriminator field to the output
2016-04-04 20:04:20 +02:00
Hugo de Paix de Coeur
7ad8ef8d18 fixed #22 : Add discriminator field to the output 2016-04-04 19:58:29 +02:00
Hugo de Paix de Coeur
539520903f enhanced maps test using integer with format int32 2016-04-04 17:55:53 +02:00
Hugo de Paix de Coeur
566300a598 fixed missing line breaks in overview document 2016-04-04 17:55:53 +02:00
Robert Winkler
b64bbee4b4 Merge pull request #122 from Swagger2Markup/features/enums
fixes #111 : Enum definition type values not rendered
2016-04-04 17:49:32 +02:00
Robert Winkler
8c005466c6 Updated documentation 2016-04-04 16:37:53 +02:00
Robert Winkler
d222e01466 Updated javadoc of toPath method in Swagger2MarkupConverter. 2016-04-04 16:26:17 +02:00
Hugo de Paix de Coeur
d692f616ba getTypeProperties documentation 2016-04-04 16:25:00 +02:00
Hugo de Paix de Coeur
656ebde58c fixes #111 : Enum definition type values not rendered
getAllProperties logic as been factored in ModelUtils
2016-04-04 16:16:41 +02:00
Robert Winkler
4973f9674a Added Gradle Plugin documentation 2016-04-04 13:55:52 +02:00
Robert Winkler
9fe3bf9ec0 Merge branch 'master' of https://github.com/Swagger2Markup/swagger2markup 2016-04-04 13:36:49 +02:00
Robert Winkler
074794830f Merge pull request #121 from Swagger2Markup/features/maps
fixes #113 : Support for maps (additionalProperties) in parameters, defs and responses
2016-04-04 13:36:17 +02:00
Hugo de Paix de Coeur
1f4fd9f115 cosmetic 2016-04-04 13:35:21 +02:00
Hugo de Paix de Coeur
82ac10c7a5 fixes #113 : Support for maps (additionalProperties) in parameters, definitions and responses 2016-04-04 13:31:56 +02:00
Robert Winkler
505b9047ba Updated javadoc of toPath 2016-04-04 13:04:05 +02:00
Robert Winkler
735123749e Added Gradle Plugin documentation 2016-04-04 12:18:22 +02:00
Robert Winkler
df3c8f51d5 Merge remote-tracking branch 'origin/master' 2016-04-04 12:15:16 +02:00
Robert Winkler
6de159fa7d Moved Swagger2MarkupProperties into another package. 2016-04-04 12:15:08 +02:00
Hugo de Paix de Coeur
119b190585 fixed content extensions positions documentation 2016-04-04 11:31:38 +02:00
Robert Winkler
14c0be59dd Updated documentation 2016-04-04 11:18:16 +02:00
Robert Winkler
fd2ae92663 Updated documentation 2016-04-04 11:16:29 +02:00
Robert Winkler
a57b16504f Added a check that the input file must not be a hidden file. 2016-04-04 10:49:01 +02:00
Robert Winkler
ee36c1b9f3 Added a toPath methods to the Swagger2MarkupConverter which converts the Swagger specification either into a folder or a file. 2016-04-04 10:42:25 +02:00
Robert Winkler
928ec8b325 Added a static factory method "fromURI" method to the Swagger2MarkupConverter 2016-04-04 10:31:43 +02:00
Robert Winkler
3d720f2c81 Merge branch 'master' of https://github.com/Swagger2Markup/swagger2markup 2016-04-04 08:11:03 +02:00
Robert Winkler
040c60a9ba Merged swagger-parser 1.0.18 2016-04-04 08:10:59 +02:00
Robert Winkler
2e874957fb Updated documentation 2016-04-02 20:16:40 +02:00
Robert Winkler
3ed94986ed Updated documentation 2016-04-02 20:09:21 +02:00
Robert Winkler
32f7561e26 Updated documentation 2016-04-02 20:02:07 +02:00
Robert Winkler
dbaaa195b5 Updated documentation 2016-04-02 19:56:11 +02:00
Robert Winkler
7f01e9beaa Updated documentation 2016-04-02 17:44:07 +02:00
Robert Winkler
2e95cf6b25 Updated documentation 2016-04-02 17:24:11 +02:00
Robert Winkler
23314507db Merge pull request #120 from Swagger2Markup/features/sparser-1.0.18
Features/sparser 1.0.18
2016-04-02 13:18:18 +02:00
Hugo de Paix de Coeur
cfbff5402c Reintroduce DOCUMENT_AFTER position for content extensions 2016-04-01 16:22:03 +02:00
Hugo de Paix de Coeur
6c6c625273 use released io.swagger:swagger-compat-spec-parser:1.0.18 2016-04-01 15:16:57 +02:00
Robert Winkler
a66560a255 Updated documentation 2016-04-01 14:59:27 +02:00
Robert Winkler
5ff5fc8f0f Updated documentation 2016-04-01 14:55:53 +02:00
Robert Winkler
f001b5bb7c Updated documentation 2016-04-01 14:53:56 +02:00
Hugo de Paix de Coeur
403b8fcfc7 Merge branch 'master' into features/sparser-1.0.18
# Conflicts:
#	build.gradle
2016-04-01 14:11:34 +02:00
Robert Winkler
456625ae4b Simplified loading of the default properties file. 2016-04-01 13:11:09 +02:00
Robert Winkler
5dd9163610 Merge remote-tracking branch 'origin/master' 2016-04-01 10:38:35 +02:00
Robert Winkler
3953b3328a Added commons-collections4:4.1 2016-04-01 10:38:28 +02:00
Robert Winkler
124be6c37a Added Codacy badge 2016-04-01 10:19:52 +02:00
Robert Winkler
6fc474ac09 Fixed JavaDoc 2016-04-01 10:00:57 +02:00
Robert Winkler
49ccad694e Fixed JavaDoc 2016-03-31 16:30:46 +02:00
Robert Winkler
370fa5eb8d Merge remote-tracking branch 'origin/master' 2016-03-31 16:25:12 +02:00
Robert Winkler
df61f140ca Upgrade to JDK8 2016-03-31 16:25:03 +02:00
Robert Winkler
b80b16d03f Updated readme 2016-03-24 20:08:24 +01:00
Robert Winkler
97c75c306f Updated readme 2016-03-24 20:04:21 +01:00
Robert Winkler
30258c7e75 Updated documentation. 2016-03-23 16:31:33 +01:00
Robert Winkler
e66feb5a27 Updated documentation. 2016-03-23 14:46:16 +01:00
Robert Winkler
972f2c2d6d Updated documentation. 2016-03-23 14:43:05 +01:00
Hugo de Paix de Coeur
fcf46c1588 small doc changes 2016-03-22 17:24:43 +01:00
Robert Winkler
cd38ed01a4 Updated documentation. 2016-03-22 16:38:20 +01:00
Robert Winkler
5f965e6378 Updated documentation. 2016-03-22 16:33:20 +01:00
Robert Winkler
d20bce81f0 Merge remote-tracking branch 'origin/master' 2016-03-21 16:44:52 +01:00
Robert Winkler
d9e2397f48 Updated documentation. 2016-03-21 16:43:42 +01:00
Robert Winkler
6fe35c34be Updated readme 2016-03-19 15:22:01 +01:00
Hugo de Paix de Coeur
05924c5813 Merge branch 'master' into features/sparser-1.0.18
# Conflicts:
#	build.gradle
2016-03-18 15:48:43 +01:00
Robert Winkler
b931d7f3af Fixes #116 Section titles of generated HTTP request/response have the same level 2016-03-18 15:39:03 +01:00
Robert Winkler
5b970eb2c8 Merge remote-tracking branch 'origin/master' 2016-03-18 15:06:24 +01:00
Robert Winkler
52b5bf2361 Renamed operationsGroupedBy to pathsGroupedBy to be backward compatible. 2016-03-18 15:06:17 +01:00
Hugo de Paix de Coeur
8eee21baf0 renamed intoFolder -> toFolder, asString -> toString for consistency 2016-03-18 13:20:36 +01:00
Robert Winkler
e99656704f Merge pull request #114 from ahus1/translation_to_german
translation of labels to German
2016-03-18 13:05:37 +01:00
Alexander Schwartz
235e5b7ddf translation of labels to German 2016-03-18 12:50:27 +01:00
Robert Winkler
69e7992f3e Updated markup-document-builder to 1.0.0-SNAPSHOT 2016-03-18 10:39:14 +01:00
Robert Winkler
29bfddc8d2 DiffUtils assertThatAllFilesAreEqual iterates over the expectedDirectory instead of the actualDirectory now. This allows to check only 2 files instead of always all 4 S2M documents. 2016-03-18 08:22:59 +01:00
Robert Winkler
3fc8a897a1 Removed mavenLocal() in build.gradle. 2016-03-18 08:12:41 +01:00
Hugo de Paix de Coeur
451e377cac inverted actual/expected in DiffUtils.assertThatAllFilesAreEqual for consistency with tests habits 2016-03-17 17:15:44 +01:00
Hugo de Paix de Coeur
6379b3ccf1 fixed #107 : Possibility to write the output into just one file instead of a folder 2016-03-17 17:10:53 +01:00
Hugo de Paix de Coeur
456f27c85b Merge branch 'master' into features/sparser-1.0.18 2016-03-17 15:38:06 +01:00
Hugo de Paix de Coeur
c739649f20 fixed typo bug in withSwaggerMarkupLanguage which was setting the bad markupLanguage variable 2016-03-17 15:37:37 +01:00
Hugo de Paix de Coeur
3dceb21bd5 Merge branch 'master' into features/sparser-1.0.18 2016-03-16 19:16:08 +01:00
Hugo de Paix de Coeur
23331930cc introduced .withSwaggerMarkupLanguage configuration to automatically convert Swagger file description into the target S2M language 2016-03-16 19:13:57 +01:00
Hugo de Paix de Coeur
da48f49a25 Merge branch 'master' into features/sparser-1.0.18 2016-03-16 16:32:36 +01:00
Hugo de Paix de Coeur
3775f26458 fixed refactoring bug in PathsDocumentBuilder::DefinitionDocumentResolverFromOperation 2016-03-16 16:30:20 +01:00
Robert Winkler
365d3278ff Added getRequiredMarkupLanguage method to Swagger2MarkupProperties 2016-03-16 16:09:01 +01:00
Robert Winkler
7cc9742530 Merge remote-tracking branch 'origin/master' 2016-03-16 15:51:01 +01:00
Robert Winkler
0648a9cbea Added two getPath methods to Swagger2MarkupProperties. 2016-03-16 15:50:48 +01:00
Hugo de Paix de Coeur
7766276abc Merge branch 'master' into features/sparser-1.0.18
# Conflicts:
#	build.gradle
2016-03-16 15:50:41 +01:00
Hugo de Paix de Coeur
19bc2dd0e2 moved generated test results to build/test for consistency with MDB 2016-03-16 15:37:37 +01:00
Robert Winkler
6126260aae Added a URIUtils class with a new convertUriWithoutSchemeToFileScheme method. 2016-03-16 15:15:30 +01:00
Robert Winkler
cdd0bc52e2 Added a getRequiredURI and updated the getURI method in Swagger2MarkupProperties 2016-03-16 14:07:24 +01:00
Hugo de Paix de Coeur
ccf3ee8e7d use new MDB .withHeaderColumn 2016-03-16 13:51:55 +01:00
Robert Winkler
54147bbddb Merge remote-tracking branch 'origin/master' 2016-03-16 12:42:33 +01:00
Robert Winkler
914fa2da0f Refactored Swagger2MarkupConfigBuilder to use Apache Commons configuration. 2016-03-16 12:42:27 +01:00
Hugo de Paix de Coeur
d41b14bbff added anchors for operations and definitions in !separated mode too
switched paths anchors to getId() instead of getTitle()
2016-03-16 11:39:37 +01:00
Robert Winkler
354d2167fb Added enum examples to swagger_petstore.yaml. 2016-03-16 08:52:09 +01:00
Hugo de Paix de Coeur
9eb7c671cd Merge branch 'master' into features/sparser-1.0.18 2016-03-15 18:14:48 +01:00
Hugo de Paix de Coeur
aee7708cd1 Use swagger-compat-spec-parser:1.0.18-SNAPSHOT 2016-03-15 18:07:20 +01:00
Robert Winkler
e3f946ecf8 Added missing javadoc to Swagger2MarkupConfig. 2016-03-15 15:51:08 +01:00
Robert Winkler
c25b6be1f3 Moved String constants PROPERTIES_PREFIX and EXTENSION_PREFIX into Swagger2MarkupConfig interfaces 2016-03-15 15:49:27 +01:00
Hugo de Paix de Coeur
eff69079a6 added Swagger2MarkupConfig, Swagger2MarkupExtensionRegistry documentation 2016-03-15 14:44:42 +01:00
Robert Winkler
8d8d4cd5d0 Added a method getExtensionsProperties to Swagger2MarkupConfig and withExtensionProperties to Swagger2MarkupConfigBuilder so that a user is able to configure its Swagger2Markup extension. 2016-03-15 13:42:36 +01:00
Hugo de Paix de Coeur
4bce1234af fixes package paths after massive package refactoring (2/2) 2016-03-15 12:12:44 +01:00
Hugo de Paix de Coeur
d892f0b39d fixes package paths after massive package refactoring 2016-03-15 11:23:52 +01:00
Robert Winkler
831e949d91 Uncommented tests which are not necessary anymore. 2016-03-15 11:04:53 +01:00
Robert Winkler
d48b9c217b The S2MConfig and S2MRegistry are interfaces now so that other users can develop their own implementations and don't have to use our default implementations. 2016-03-15 09:59:32 +01:00
Robert Winkler
124a66aaa9 Merge branch 'master' of https://github.com/Swagger2Markup/swagger2markup 2016-03-15 08:43:31 +01:00
Robert Winkler
08eb6841fc Refactor extension SPI to use the ServiceLoader by default 2016-03-15 08:43:26 +01:00
Hugo de Paix de Coeur
e74ac9fda5 fixes copy code to support last mdb commits 2016-03-14 19:28:07 +01:00
Robert Winkler
d4bbcc3acc Allow to use http proxy settings in unit tests. 2016-03-14 15:43:40 +01:00
Robert Winkler
9655e113c0 Fixed order of examples and security scheme definitions. 2016-03-14 15:43:20 +01:00
Robert Winkler
54c7682f00 Fixed compile issue in Swagger2MarkupConverter 2016-03-14 15:14:56 +01:00
Robert Winkler
7c8efa1060 Fixed failing Swagger2MarkupExtensionRegistryTest after moving the extensions into another repo. 2016-03-14 15:12:14 +01:00
Robert Winkler
0caf2d7a43 Merge remote-tracking branch 'origin/master' 2016-03-14 15:03:31 +01:00
Robert Winkler
533590656f Fixes #110 Move Extensions into swagger2markup-extensions repo 2016-03-14 15:03:19 +01:00
Robert Winkler
fe0fa8a9ce Moved classes from 'io.github.robwin.swagger2markup' to 'io.github.swagger2markup' 2016-03-14 15:01:32 +01:00
Robert Winkler
a85b695c80 Changed artifact group from group = 'io.github.robwin' to 'io.github.swagger2markup'.
Refactored gradle scripts.
2016-03-14 15:00:17 +01:00
Hugo de Paix de Coeur
251a6b7e73 fixes merge from master (missing some convertExample) 2016-03-14 12:10:31 +01:00
Hugo de Paix de Coeur
08b0d085db Merge branch 'master' into features/sparser-1.0.18
# Conflicts:
#	build.gradle
#	src/main/java/io/github/robwin/swagger2markup/Swagger2MarkupConfig.java
2016-03-14 11:43:04 +01:00
Hugo de Paix de Coeur
0b95f35a61 Removes formatting from RU localization 2016-03-14 11:28:23 +01:00
Robert Winkler
4073b7627d Fixes #60: Add support of Response Headers
The description of response headers was not rendered correctly.
2016-03-11 08:37:32 +01:00
Robert Winkler
2c2b599528 Fixed expected result files. 2016-03-10 16:14:31 +01:00
Robert Winkler
eb86d6f1d0 Moved buildDescriptionParagraph method ino MarkupDocumentBuilder so that it can be reused by all other builders. 2016-03-10 15:39:07 +01:00
Robert Winkler
2d74e441dc Replaced colon separator by a static final string. 2016-03-10 15:38:11 +01:00
Robert Winkler
8145dea0d5 Added gh-pages gradle-git plugin. 2016-03-10 15:37:38 +01:00
Robert Winkler
a4a217a223 Fixed security scheme title anchor. 2016-03-10 15:37:03 +01:00
Robert Winkler
cd023a99b5 Updated introduction. 2016-03-09 16:44:49 +01:00
Robert Winkler
a339e78135 Added initial AsciiDoc documentation for release v1.0.0. 2016-03-09 16:41:30 +01:00
Robert Winkler
1425414b4a Moved AsciiDoc and Markdown documents which are required by the test into "src/test/resources/docs". 2016-03-09 16:16:52 +01:00
Robert Winkler
a8e189408a Merge branch 'develop' of https://github.com/Swagger2Markup/swagger2markup into develop 2016-03-09 15:19:58 +01:00
Robert Winkler
fbb535d241 Removed new line from swagger_inlineSchema.yaml 2016-03-09 15:18:26 +01:00
Robert Winkler
7d6fc09c24 Fixed expected test results after adding support for HTTP headers in Responses 2016-03-09 13:58:06 +01:00
Robert Winkler
00f62124af Added missing JavaDoc to DynamicSecurityDocumentExtension
Added missing Enums in DynamicSecurityDocumentExtension::apply
2016-03-09 13:35:12 +01:00
Robert Winkler
138be996db Renamed MarkupDocumentBuilder::typeProperties to MarkupDocumentBuilder::buildPropertiesTable
Renamed DefinitionsDocumentBuilder::definition to DefinitionsDocumentBuilder::buildDefinition
Added a description paragraph to SecurityDocumentBuilder::buildSecuritySchemeDefinitionsSection
2016-03-09 13:34:26 +01:00
Robert Winkler
722b2b24b7 Added the name of the definition and the SecuritySchemeDefinition to the SecurityDocumentExtension.Context. 2016-03-09 13:04:53 +01:00
Robert Winkler
d90d68332f Updated version of Apache commons collection
Remove library dependencies which are already included in markup-document-builder
2016-03-09 12:39:04 +01:00
Robert Winkler
0470d984cc Updated version 2016-03-08 20:14:52 +01:00
Robert Winkler
c001452abf Renamed and refactored some methods in the document builder.
Fixed Javadoc.
2016-03-08 12:34:53 +01:00
Robert Winkler
b25378463c Renamed Position enums. 2016-03-08 12:32:25 +01:00
Robert Winkler
63d3a95529 Added global parameter and response to swagger_petstore to test #102 and #103 2016-03-08 11:10:14 +01:00
Robert Winkler
1c1eb106d6 Renamed and refactored some methods in the document builder. 2016-03-08 09:54:30 +01:00
Robert Winkler
916d2515b0 Renamed resource folder which contains the expected test results. 2016-03-08 09:53:08 +01:00
Robert Winkler
caff7db0d4 Merge branch 'master' of https://github.com/Swagger2Markup/swagger2markup into develop
Conflicts:
	src/main/resources/io/github/robwin/swagger2markup/lang/labels_ru.properties
2016-03-07 16:21:50 +01:00
Robert Winkler
85006b2c15 Merge pull request #104 from MeteorBoom/master
Russian propirties update
2016-03-07 16:11:51 +01:00
Maksim Myshkin
727c6c6467 Russian propirties update 2016-03-07 20:05:38 +05:00
Robert Winkler
12fc80c8b0 Fixes #101: Rename extensions. Content should be renamed to Document 2016-03-07 16:03:13 +01:00
Robert Winkler
97ae3df30d Refactored visibility of classes. 2016-03-07 15:58:43 +01:00
Robert Winkler
3189043b7f Refactored package structure into an API (root), a SPI (service provider interface) and internal classes which should not be used by a user directly. 2016-03-07 15:28:46 +01:00
Robert Winkler
9f01adfb25 Removed withLineSeparator from unit tests, because it fails on TravisCI. 2016-03-07 12:52:33 +01:00
Robert Winkler
5155e6510f Renamed MarkupDocument to MarkupDocumentBuilder which builds an MarkupDocument now. 2016-03-07 12:51:32 +01:00
Robert Winkler
37d99eb86f Renamed AbstractExtension::onUpdateGlobalContext to AbstractExtension::init 2016-03-07 12:50:40 +01:00
Robert Winkler
014e9354ce Merge pull request #99 from Swagger2Markup/features/schema-ext
moved definitions Schema implementation to SchemaExtension
2016-03-07 11:26:28 +01:00
Robert Winkler
c8ecab6d78 Fixed broken GeneralConverterTest 2016-03-07 11:20:18 +01:00
Robert Winkler
2e7e10aaae Merge branch 'develop' into features/schema-ext
Conflicts:
	src/test/java/io/github/robwin/swagger2markup/Swagger2MarkupConverterTest.java
2016-03-07 11:16:00 +01:00
Robert Winkler
9f197074ef The line separator which should be used can be configured now. 2016-03-07 11:10:28 +01:00
Robert Winkler
5b054761cf Added expected AsciiDoc and Markdown files. 2016-03-07 11:08:51 +01:00
Hugo de Paix de Coeur
be3ae6bd0d Merge branch 'develop' into features/schema-ext
# Conflicts:
#	src/main/java/io/github/robwin/swagger2markup/config/Swagger2MarkupConfig.java
2016-03-04 17:42:01 +01:00
Hugo de Paix de Coeur
71980aafeb moved definitions Schema implementation to SchemaExtension 2016-03-04 17:38:19 +01:00
Robert Winkler
d1c20ed325 Merge pull request #98 from atomfrede/master
add wescale as using company
2016-03-04 17:35:38 +01:00
Frederik Hahne
16f559cd70 add wescale as using company 2016-03-04 17:24:07 +01:00
Robert Winkler
d0dc6188cd Removed io.spring.gradle:dependency-management-plugin 2016-03-04 14:54:25 +01:00
Robert Winkler
e79f6c49a4 Moved testSwagger2MarkupConfigDefaultPathsWithoutFile from MarkdownConvertTest into GeneralConverterTest. 2016-03-04 13:32:37 +01:00
Robert Winkler
4ec11f8359 Separated AsciiDocConverterTest into three different files. 2016-03-04 13:30:03 +01:00
Robert Winkler
52c1780f79 AS_IS ordering of path operations does not work yet, because of https://github.com/swagger-api/swagger-core/issues/1696.
New default value is NATURAL.
2016-03-04 13:20:56 +01:00
Robert Winkler
c6becb9995 Merge remote-tracking branch 'origin/develop' into develop 2016-03-04 12:15:10 +01:00
Robert Winkler
194efab1f6 Added a DiffUtils class which can be used to assert that the content of the generated files are not different to the content of the expected files. 2016-03-04 12:14:37 +01:00
Hugo de Paix de Coeur
34af7a4899 Disabled inter-document cross-references when using withSeparatedOperations() without withInterDocumentCrossReferences(), for consistency with definitions cross-references. 2016-03-04 11:50:45 +01:00
Hugo de Paix de Coeur
2b6c699828 fixes configuration validators and doc 2016-03-04 11:40:39 +01:00
Robert Winkler
e376b972fe Merge pull request #97 from Swagger2Markup/master
Updated readme
2016-03-04 08:28:32 +01:00
Robert Winkler
445a04b9d6 Updated readme 2016-03-04 08:25:13 +01:00
Hugo de Paix de Coeur
4283b2489d Merge branch 'develop' into features/sparser-1.0.18 2016-03-03 18:05:06 +01:00
Hugo de Paix de Coeur
c6e21b9ed1 fixes configuration validators and doc 2016-03-03 18:04:15 +01:00
Hugo de Paix de Coeur
c61a94495f Merge branch 'develop' into features/sparser-1.0.18
# Conflicts:
#	src/main/java/io/github/robwin/swagger2markup/utils/ExamplesUtil.java
2016-03-03 17:49:53 +01:00
Robert Winkler
99049d156a Updated readme 2016-03-03 16:33:07 +01:00
Hugo de Paix de Coeur
f8d331fc8b fixes property examples pretty-printing when no examples provided 2016-03-03 15:42:25 +01:00
Hugo de Paix de Coeur
667a883fb0 labels_fr fix for headers_column 2016-03-03 15:26:40 +01:00
Robert Winkler
2bd1719637 Merge remote-tracking branch 'origin/develop' into develop 2016-03-03 15:22:06 +01:00
Robert Winkler
d9d62dec6b Removed testOldSwaggerSpec2AsciiDocConversion unit test. 2016-03-03 15:21:46 +01:00
Hugo de Paix de Coeur
f3fdd45019 Extend to basic properties/parameters types : Auto-generated examples are disabled by default. Swagger examples are always rendered. 2016-03-03 15:11:00 +01:00
Hugo de Paix de Coeur
ded1cd6b06 Cleanup and fixes examples pretty-printing 2016-03-03 15:11:00 +01:00
Robert Winkler
854dcf48b2 Added headers property to all language files. 2016-03-03 14:26:55 +01:00
Robert Winkler
0916fa38e2 Merge remote-tracking branch 'origin/develop' into develop 2016-03-03 14:14:12 +01:00
Robert Winkler
c590f5102c Added an Assertj DiffAssertions class which can be used to compare the generated AsciiDoc/Markdown files with files which contain the expected conten.
The DiffAssert generates a HTML report, if the files differ.
2016-03-03 14:14:02 +01:00
Robert Winkler
9bda5b7941 Removed unused, duplicated method normalizeName. 2016-03-03 14:12:19 +01:00
Robert Winkler
ebba92368a Updated asciidoctor plugins.
Added a diff library to compare the content of files.
2016-03-03 14:10:37 +01:00
Hugo de Paix de Coeur
3e5df92223 Merge branch 'develop' into features/sparser-1.0.18
# Conflicts:
#	src/main/java/io/github/robwin/swagger2markup/utils/ExamplesUtil.java
2016-03-03 14:04:43 +01:00
Hugo de Paix de Coeur
2d17071c8c Updated copyright headers 2016-03-03 11:58:50 +01:00
Robert Winkler
38d4bff7f4 Merge pull request #96 from Swagger2Markup/features/withGeneratedExamples
Auto-generated examples are disabled by default
2016-03-02 19:27:57 +01:00
Hugo de Paix de Coeur
fc5434cb3d Auto-generated examples are disabled by default. Swagger examples are always rendered. 2016-03-02 19:13:28 +01:00
Hugo de Paix de Coeur
3c0e545661 fixed ComposedModel definitions model bug when used with examples 2016-03-02 19:07:00 +01:00
Hugo de Paix de Coeur
c0f758ba9b Added some missing validation 2016-03-02 18:12:24 +01:00
Hugo de Paix de Coeur
e96dd94ee9 Support Swagger Parser 1.0.18 interfaces changes 2016-03-02 11:57:28 +01:00
Robert Winkler
8a913d075d Refactored the examplesSection method in PathsDocument to remove duplicated code. 2016-03-02 11:26:31 +01:00
Robert Winkler
bbaf3a05b3 Added a swagger_petstore.yaml and swagger_security.yaml and removed the outdated swagger.json 2016-03-02 11:25:50 +01:00
Robert Winkler
61c4f8861f Changed Asciidoctor toclevel from 2 to 3. 2016-03-02 11:24:25 +01:00
Hugo de Paix de Coeur
1e7c51a2cb Removed file prefixes from dynamic content extensions 2016-03-01 18:37:26 +01:00
Hugo de Paix de Coeur
21620917f7 Unknown security scheme localization 2016-03-01 18:05:47 +01:00
Hugo de Paix de Coeur
cc65055f3c Use OrderBy for all ordering configurations 2016-03-01 17:58:22 +01:00
Hugo de Paix de Coeur
71fab0ca94 Simplify SpringRestDocsExtension::operationFolderName, and documentation fixes 2016-03-01 16:10:06 +01:00
Hugo de Paix de Coeur
b272e812d0 Remove lower-casing in normalizeName 2016-03-01 15:56:17 +01:00
Hugo de Paix de Coeur
cb9092492f Removes formatting from localization
fixes FR locale
2016-03-01 14:44:23 +01:00
Robert Winkler
0a79020e59 Merge pull request #95 from glaforge/patch-1
Add Restlet as a user of Swagger2Markup
2016-03-01 11:02:45 +01:00
Guillaume Laforge
4e4fa960b6 Add Restlet as a user of Swagger2Markup 2016-03-01 10:12:33 +01:00
Robert Winkler
c28fddb4f6 Merge pull request #93 from Swagger2Markup/features/#91-examples-to-ext
fixes #91 : Move SpringRestDocs examples to extension
2016-03-01 08:57:11 +01:00
Hugo de Paix de Coeur
e36587f61a fix directories to lower case 2016-02-29 17:52:31 +01:00
Hugo de Paix de Coeur
40c53cf27b Merge remote-tracking branch 'origin/master' into features/#91-examples-to-ext
# Conflicts:
#	src/main/java/io/github/robwin/swagger2markup/builder/document/PathsDocument.java
#	src/main/java/io/github/robwin/swagger2markup/config/Swagger2MarkupConfig.java
#	src/test/java/io/github/robwin/swagger2markup/config/Swagger2MarkupConfigTest.java
#	src/test/resources/config/config.properties
2016-02-29 17:04:22 +01:00
Hugo de Paix de Coeur
09c78a1cee fixes #91 : Move SpringRestDocs examples to extension 2016-02-29 16:25:09 +01:00
Robert Winkler
b2d9e5ab73 Moved language property files into the package io.github.robwin.swagger2markup.
Renamed boolean config properties.  They end with *Enabled now.
2016-02-29 12:57:18 +01:00
Hugo de Paix de Coeur
a630c1a161 Merge pull request #90 from Kabhal/master
Added FR locale
2016-02-26 19:49:44 +01:00
Hugo de Paix de Coeur
1771330890 Added FR locale 2016-02-26 19:48:26 +01:00
Kabhal
02fed86851 Merge pull request #89 from Kabhal/master
fixed #72 : Render examples of response and schema objects
2016-02-26 18:52:46 +01:00
Hugo de Paix de Coeur
46ae248056 Merge branch 'erik/master'
# Conflicts:
#	src/main/java/io/github/robwin/swagger2markup/builder/document/DefinitionsDocument.java
#	src/main/java/io/github/robwin/swagger2markup/builder/document/PathsDocument.java
#	src/test/java/io/github/robwin/swagger2markup/Swagger2MarkupConverterTest.java
2016-02-26 18:29:02 +01:00
Robert Winkler
5730a3be09 Merge pull request #88 from Kabhal/master
fixed #46 : Support deprecated operations
2016-02-26 17:39:41 +01:00
Hugo de Paix de Coeur
462df0032e fixed #46 : Support deprecated operations 2016-02-26 16:30:45 +01:00
Robert Winkler
d058a99874 Renamed addfileExtension to addFileExtension 2016-02-26 16:29:24 +01:00
Robert Winkler
2399cc25ca Merge remote-tracking branch 'origin/master' 2016-02-26 13:27:05 +01:00
Robert Winkler
c7fe39bf21 Refactored Swagger2MarkupConverter builder. 2016-02-26 13:26:52 +01:00
Robert Winkler
a5bf4c64bb Updated readme 2016-02-26 12:48:14 +01:00
Robert Winkler
3fd97ea471 Merge pull request #87 from Kabhal/uri
Move remaining String directories to Path
2016-02-26 12:40:03 +01:00
Hugo de Paix de Coeur
3dae4dd155 Move remaining String directories to Path 2016-02-26 12:17:10 +01:00
Robert Winkler
a510740fa3 Introduced new Swagger2MarkupConverter.from factory methods for URL and Path instead of URI to make sure that URLs and Paths have the correct format. 2016-02-26 11:05:54 +01:00
Robert Winkler
91ba9e7fd3 Moved method registerExtension into the Swagger2MarkupExtensionRegistry.Builder to make the Swagger2MarkupExtensionRegistry immutable. 2016-02-25 20:49:41 +01:00
Robert Winkler
f3056d316f Removed method withConfig(Properties config) from Swagger2MarkupConverter.Builder 2016-02-25 20:48:36 +01:00
Robert Winkler
0e9f556994 Merge pull request #86 from Kabhal/uri
Support for URI for all content resources
2016-02-25 19:29:55 +01:00
Hugo de Paix de Coeur
b9727c9275 Switched all paths to URI (except DynamicExtensions because file listing is needed -> Path) 2016-02-25 19:20:59 +01:00
Hugo de Paix de Coeur
d649fb0d87 fixes tests 2016-02-25 14:11:30 +01:00
Hugo de Paix de Coeur
1aa8221931 fixed #83 : Pluggable extension support 2016-02-25 13:49:37 +01:00
Hugo de Paix de Coeur
cbb541f1a3 fixed #80 : External folder path consistency 2016-02-25 13:00:03 +01:00
Hugo de Paix de Coeur
8b215d7425 fixed #82 : Swagger2Markup configuration builder 2016-02-25 13:00:03 +01:00
Hugo de Paix de Coeur
52ef344ba4 fixed #79 : Support for dynamic extensions from files to operations. 2016-02-25 12:59:58 +01:00
Erik Håkansson
44eff18b3e Expanded example .json 2016-02-25 06:39:18 +01:00
Erik Håkansson
a0c8d47369 Added tests and fixed some issues 2016-02-24 15:24:34 +01:00
Erik Håkansson
d19a0020fd Updated to use latest markupdocument 2016-02-24 14:11:52 +01:00
Erik Håkansson
5494ad911e merge from upstream 2016-02-24 13:51:18 +01:00
Erik Håkansson
5ead0975c1 Updates to example handling to cover more scenarios 2016-02-24 13:41:53 +01:00
Robert Winkler
34cd890cd9 Fixed CharSet in Unit test "testSwagger2AsciiDocConversionWithRussianOutputLanguage" 2016-02-22 15:30:47 +01:00
Robert Winkler
329756d664 Merge pull request #78 from Kabhal/master
fixed #77 : Generated anchors should be prefixed with a configurable prefix
2016-02-19 16:57:49 +01:00
Hugo de Paix de Coeur
8ebc4f603f Missing custom anchor for security document 2016-02-19 16:55:17 +01:00
Hugo de Paix de Coeur
07bcdf220d Shorty parameter type 2016-02-19 16:39:13 +01:00
Hugo de Paix de Coeur
2f71a011c3 Use Markup-dependent specifiers on tables (AsciiDoc : header style on name column & vertically centered columns) 2016-02-19 16:23:43 +01:00
Hugo de Paix de Coeur
e6244fc3f8 fixed #77 : Generated anchors should be prefixed with a configurable prefix 2016-02-18 19:03:12 +01:00
Hugo de Paix de Coeur
9eb713cefb Generate title anchors only for unique titles (overview, paths, definitions, <all paths>, <all operations> and <all definitions>) 2016-02-18 17:13:16 +01:00
Robert Winkler
714c0aa8c9 Merge pull request #76 from Kabhal/master
Use new markup-document-builder *AsString replacements
2016-02-18 15:35:06 +01:00
Hugo de Paix de Coeur
91a0aeec9d Use new markup-document-builder *AsString replacements 2016-02-18 14:56:50 +01:00
Robert Winkler
a28c1d4efe Merge pull request #74 from Kabhal/master
fixed #73 : Optionally isolate body display from other parameters
2016-02-17 13:22:18 +01:00
Hugo de Paix de Coeur
a6af12ae06 Added configurable ordering for properties, parameters and responses 2016-02-16 15:47:22 +01:00
Hugo de Paix de Coeur
910b2ff187 cleanups 2016-02-16 14:48:16 +01:00
Hugo de Paix de Coeur
64adbfaab6 enhanced filename normalization 2016-02-15 20:41:54 +01:00
Hugo de Paix de Coeur
d60b8d4b83 Enhanced inline schema uniqueness (no more incremental ids) 2016-02-15 18:43:40 +01:00
Hugo de Paix de Coeur
684fc221b1 fixed #73 : Optionally isolate body display from other parameters 2016-02-15 18:11:26 +01:00
Erik Håkansson
cf96642db5 Reverted custom versioning 2016-02-15 13:19:22 +01:00
Erik Håkansson
ab6628b1ab Added option for auto-generating examples 2016-02-15 13:16:15 +01:00
Robert Winkler
06beab3865 Merge pull request #69 from Kabhal/master
fixed bug with hand-written description folders fallback
2016-02-12 18:20:20 +01:00
Hugo de Paix de Coeur
bd77f4400f fixed bug with hand-written description folders fallback 2016-02-12 18:08:07 +01:00
Robert Winkler
deebb2be9a Merge pull request #68 from Kabhal/master
refactor hand-written descriptions folder
2016-02-12 17:29:05 +01:00
Hugo de Paix de Coeur
22c6cab910 refactor hand-written descriptions folder : search in stable operation.getId() first, then in back-compatible operation.getSummary()
Fix title rendering (was in debug mode)
2016-02-12 17:24:20 +01:00
Robert Winkler
ea771c80d1 Merge pull request #67 from Kabhal/master
refactored path -> operation
2016-02-12 17:22:07 +01:00
Hugo de Paix de Coeur
861b97c4ff Refactor operation sorting and group by tags logic 2016-02-12 16:34:15 +01:00
Hugo de Paix de Coeur
b1ffe7cfc2 Decomposed method and path 2016-02-12 16:34:15 +01:00
Hugo de Paix de Coeur
852ea15dc2 Renamed path -> operation anywhere we work on an operation and not a path 2016-02-12 16:34:15 +01:00
Hugo de Paix de Coeur
45768a5bba Migrate to asciidoctorj:1.5.4 (testCompile) -> better support for inter-document cross-references with paths 2016-02-12 16:34:15 +01:00
Hugo de Paix de Coeur
76b5a83511 fix withInterDocumentCrossReferences to support null prefix 2016-02-12 16:34:15 +01:00
Robert Winkler
c0d1da781f Merge pull request #66 from Kabhal/master
Option to enable/disable inter-document cross-references
2016-02-11 15:41:17 +01:00
Hugo de Paix de Coeur
1a80a7a8eb missing documentation 2016-02-11 15:33:35 +01:00
Hugo de Paix de Coeur
cd66661026 Introduce withInterDocumentCrossReferences(prefix). By default inter-document cross-references are disabled (We assume all generated files will be included in a user .adoc file)
Fixed DefinitionsDocumentResolver*
2016-02-11 14:37:17 +01:00
Hugo de Paix de Coeur
b88e4eea56 cleanup the resolvers 2016-02-11 14:37:17 +01:00
Robert Winkler
f64a0d199d Added a test case which converts a Swagger file into an AsciiDoc String. 2016-02-11 14:05:13 +01:00
Robert Winkler
5f47f49cf4 Issue #65:
When you combine multiple AsciiDoc files in a index.adoc. The anchors to the definitions don't work anymore in the paths section, because they reference a definitions.adoc: <<definitions.adoc#_pet,Pet>>
AsciiDoctor converts this reference to a HTML anchor <a href="definitions.html#_pet">Pet</a>. But AsciiDoctor only generates an index.html and no definitions.html
The DefinitionDocumentResolver must return null, if separatedDefinitionsEnabled is not true. Otherwise we are not backward compatible.
2016-02-11 10:58:19 +01:00
Robert Winkler
7a0c8d81f6 Moved the securitySchemeSection above the examplesSection in the PathsDocument. 2016-02-11 10:02:19 +01:00
Robert Winkler
427efca6f8 Added security.adoc to index.adoc 2016-02-11 09:45:24 +01:00
Robert Winkler
54546185ab Added test for separated paths builder method. 2016-02-11 09:26:43 +01:00
Robert Winkler
493f045764 Merge pull request #63 from rostskadat/master
Adding a simple section for Swagger security definitions
2016-02-10 18:15:54 +01:00
N090536
fd79e98ed7 Merge remote-tracking branch 'origin/master'
Conflicts:
	src/main/java/io/github/robwin/swagger2markup/Swagger2MarkupConverter.java
	src/test/java/io/github/robwin/swagger2markup/Swagger2MarkupConverterTest.java
2016-02-10 16:23:05 +01:00
Robert Winkler
40bf5762bb Merge pull request #64 from Kabhal/idxref
Fixed tests (no way to compare output to definitions.<ext> as the gen…
2016-02-10 14:00:33 +01:00
Hugo de Paix de Coeur
c291991236 Fixed tests (no way to compare output to definitions.<ext> as the generation logic changed) : definitions.<ext> is now just a link list to separated files 2016-02-10 13:40:18 +01:00
Robert Winkler
7cb9b97bfb Updated swagger-compat-spec-parser from 1.0.16 to 1.0.17 2016-02-10 13:39:35 +01:00
Robert Winkler
eddbd9610e Updated RELEASENOTES 2016-02-10 13:32:14 +01:00
Robert Winkler
a66ebec28f Merge pull request #62 from Kabhal/idxref
fixed #61 Refactor separated documents logic to support inter-document xrefs
2016-02-10 13:25:51 +01:00
N090536
cdad18194e Fixing UTF8 string... 2016-02-10 13:11:56 +01:00
N090536
17f69b2bbc Adapted the unit test to account for the new security document 2016-02-10 13:04:04 +01:00
N090536
84176e5e27 Fixing english labels and sync the russian labels 2016-02-10 12:48:34 +01:00
N090536
67a3b924e8 Add the SecurityDocument class 2016-02-10 12:41:30 +01:00
N090536
84c86873fb Added a section for the securityDefinitionsObject.
As per the specification:
http://swagger.io/specification/#securityDefinitionsObject
2016-02-10 12:40:40 +01:00
Hugo de Paix de Coeur
2a486a2939 fixed #61 Refactor separated documents logic to support inter-document cross-references 2016-02-10 12:29:02 +01:00
Robert Winkler
0550128e1d Merge pull request #59 from johanhammar/master
Update Gradle wrapper to 2.10 and dependency-management-plugin to latest version.
2016-02-07 12:21:27 +01:00
Johan Hammar
ff867c9ba4 Update Gradle wrapper to 2.10 2016-02-07 12:04:16 +01:00
Johan Hammar
c5fada0a62 Upgrade dependency-management-plugin to latest version 2016-02-07 11:59:06 +01:00
Robert Winkler
7316ae0ce4 Merge pull request #58 from Kabhal/separatedBody
fixed #53 : support for tags, paths and methods ordering
2016-02-05 20:44:08 +01:00
Hugo de Paix de Coeur
c8919e9844 refactored orderBy system by generalizing ordering to all resources (tags, paths, definitions, path methods).
definitionsOrderBy and OrderBy are deprecated (set definitionsOrdering to Ordering.natural() for back-compatibility)
All orderings set to Ordering.natural() by default.
Support as-is ordering for all resources by setting config options to null.
2016-02-05 19:57:38 +01:00
Hugo de Paix de Coeur
4e340466de Merge remote-tracking branch 'upstream/master' into separatedBody 2016-02-05 18:02:37 +01:00
Hugo de Paix de Coeur
2fceda6f09 fixed #53 : support for tags, paths and methods ordering 2016-02-05 16:38:06 +01:00
Robert Winkler
2aa29fde8a Merge pull request #56 from Kabhal/multipaths
fixed #51 : Support for separated operations files
2016-02-05 00:41:23 +01:00
Hugo de Paix de Coeur
a76b7c545a Localized Response inline type prefix 2016-02-05 00:15:17 +01:00
Hugo de Paix de Coeur
8178bf1380 renamed withSeparatedOperations to withSeparatedPaths along with all related resources 2016-02-05 00:10:45 +01:00
Hugo de Paix de Coeur
63ca190a32 fixed #51 : Support for separated operations files 2016-02-04 18:51:22 +01:00
Hugo de Paix de Coeur
836d9fbae7 Migrate to markup-document-builder 0.1.6-SNAPSHOT 2016-02-04 17:34:10 +01:00
Hugo de Paix de Coeur
9df1c73641 fixed Markdown generation for inline schemas 2016-02-04 13:51:23 +01:00
Hugo de Paix de Coeur
1899efd209 Test cleanups 2016-02-04 13:51:23 +01:00
Hugo de Paix de Coeur
9d90766592 Workaround for https://github.com/swagger-api/swagger-parser/issues/177 2016-02-04 13:51:23 +01:00
Hugo de Paix de Coeur
bd9d3ee4c3 Cleanups 2016-02-04 13:51:23 +01:00
Robert Winkler
20fac6ab26 Fixed travis file 2016-02-04 13:22:25 +01:00
Robert Winkler
5be5a7d8e3 Fixed travis file 2016-02-04 13:11:02 +01:00
Robert Winkler
35f0192ecb Fixed Coveralls badge 2016-02-03 15:59:49 +01:00
Robert Winkler
69949d6257 Added artifactoryPublish task to TravisCI to publish SNAPSHOTS to OSS Artifactory 2016-02-03 15:56:00 +01:00
Robert Winkler
94ad45d2b0 Added Artifactory Gradle Plugin in order to deploy snapshots to oss.jfrog.org 2016-02-03 13:25:05 +01:00
Robert Winkler
c62f6085f7 Changed inlineSchemaDepthLevel from Integer to int
Changed default value of inlineSchemaDepthLevel from 0 to 1
2016-02-03 08:46:52 +01:00
Robert Winkler
2a300a2ef6 Merge pull request #55 from Kabhal/separatedBody
Enhancements
2016-02-02 21:01:08 +01:00
Hugo de Paix de Coeur
a77a0f281d Merge branch 'master' of github.com:Swagger2Markup/swagger2markup into separatedBody 2016-02-02 20:08:14 +01:00
Hugo de Paix de Coeur
d794cd989b Introduced columns width ratio in all tables to maximize description column width.
Refactored table generation.
MarkupDocBuilderUtils code should be replaced with markup-document-builder enhancements.
2016-02-02 20:04:33 +01:00
Hugo de Paix de Coeur
60c687f3f8 Introduced tableRow() to escape table contents 2016-02-02 18:46:07 +01:00
Hugo de Paix de Coeur
8da5d3a770 l10n : No Content
Cleaning
2016-02-02 18:04:52 +01:00
Hugo de Paix de Coeur
ead3e0bc22 Added .withInlineSchemaDepthLevel to converter configuration (default: 0 = disable feature)
Added inline schema support for global definitions.
Relayout inlineSchema feature : no mode distinct Definitions section in Paths, inline types are displayed right after each original type. This is for consistency with global definitions.
2016-02-02 11:45:22 +01:00
Robert Winkler
a0c1f20fc3 Added inline schema example Swagger YAML file 2016-02-02 10:36:29 +01:00
Robert Winkler
8e6586d4e4 Merge pull request #54 from Kabhal/separatedBody
Inline schemas support (issue #52)
2016-02-02 07:30:39 +01:00
Hugo de Paix de Coeur
b2f4229f70 Merge branch 'master' of github.com:Swagger2Markup/swagger2markup into separatedBody 2016-02-01 22:46:21 +01:00
Hugo de Paix de Coeur
2425074855 cleanup 2016-02-01 20:41:01 +01:00
Hugo de Paix de Coeur
7d53a8aedb Managed inline schemas in parameters and responses (depth level = 1)
Inline schemas in definitions are still to be managed.
2016-02-01 20:14:40 +01:00
Hugo de Paix de Coeur
a16617880f Factorized the display of type properties table 2016-02-01 17:38:06 +01:00
Hugo de Paix de Coeur
650431b8ce Support for response inline objects 2016-02-01 16:15:56 +01:00
Hugo de Paix de Coeur
a6654b65a9 Genericized the type system between models, parameters, properties, etc ... for further refactoring
*Utils display logic is removed from *Utils which are now just adapters from Swagger model to *Type.
 *Type now have the display logic.
2016-02-01 16:10:30 +01:00
Hugo de Paix de Coeur
4f15ea9ed7 Corrected warnings 2016-02-01 10:59:38 +01:00
Hugo de Paix de Coeur
aa34532b33 Factorized paths sections titles 2016-02-01 10:58:31 +01:00
Robert Winkler
3fe711a3ba Merge pull request #53 from Kabhal/fixedPathsNames
Base paths and fixed file names must not depend on translations
2016-01-29 14:19:04 +01:00
Hugo de Paix de Coeur
93e2175435 Base paths and fixed file names must not depend on translations 2016-01-29 14:00:20 +01:00
Robert Winkler
5c61006d11 Updated readme 2016-01-26 08:06:48 +01:00
Robert Winkler
6da74af830 Updated readme 2016-01-26 08:04:12 +01:00
Robert Winkler
93ba67c405 Updated swagger-parser from v1.0.13 to v1.0.16 2016-01-11 08:44:40 +01:00
Robert Winkler
04fed3d4d5 Prepare release v0.9.2 2016-01-05 14:35:12 +01:00
Robert Winkler
1ead6614ba Corrected russian labels file, because the files names of spring-restdocs are always english. 2016-01-05 14:31:11 +01:00
Robert Winkler
887e63464d Merge pull request #49 from MeteorBoom/master
Added output files language option
2016-01-04 16:47:33 +01:00
Maksim Myshkin
47e5d5e56e I have merged property files in one. ResourceBundle is now used. 2016-01-04 20:15:50 +05:00
Maksim Myshkin
c505c1e88e Added output files language option 2016-01-03 22:13:57 +05:00
Robert Winkler
6a8c04c031 Updated documentation 2015-11-24 08:27:15 +01:00
Robert Winkler
33f68a7f41 Updated documentation 2015-11-24 08:26:07 +01:00
Robert Winkler
c5af8676e5 Updated documentation 2015-11-24 08:20:22 +01:00
Robert Winkler
618898cb09 Updated documentation 2015-11-24 08:19:37 +01:00
Robert Winkler
36bdcc57d9 Added Swagger2MarkupConverter.fromString test case 2015-11-16 09:41:27 +01:00
Robert Winkler
eb418c07f5 Updated publishing gradle script 2015-11-12 14:37:50 +01:00
Robert Winkler
9a265fbbc3 Updated RELEASENOTES 2015-11-12 13:12:15 +01:00
Robert Winkler
cf32d6cf29 [New Feature] Added support to group the paths by tags or as-is
[New Feature] Added support to order the definitions by natural ordering or as-is
2015-11-12 13:10:33 +01:00
Robert Winkler
9d216e3dc2 [Bug] Fixed unit test issue with composed models 2015-11-09 15:49:35 +01:00
Robert Winkler
9d387b3e80 Merge remote-tracking branch 'origin/master' 2015-11-09 14:52:52 +01:00
Robert Winkler
1e6be2f26d Updated swagger-parser from v1.0.8 to v1.0.13
Support for global responses and parameters
2015-11-09 14:52:43 +01:00
Robert Winkler
e56f824cd2 Updated documentation 2015-10-01 08:40:44 +02:00
Robert Winkler
d38014f4b5 Updated documentation 2015-09-30 13:35:12 +02:00
Robert Winkler
b331062fa6 Updated documentation 2015-09-01 17:28:13 +02:00
Robert Winkler
88df748451 Merge pull request #35 from Relequestual/patch-1
Updated readme to better reflect alternatives listing
2015-09-01 17:19:44 +02:00
Ben Hutton
5384197bd1 Updated readme to better reflect alternatives listing
The list of alternative publishing libraries was missleading in the sense it lead me to believe that I could use this library to generate AsciiDoc or Markdown, which would work in all of the listed documentation hosting services / open source projects templates.
2015-09-01 14:53:22 +01:00
Robert Winkler
2b5d4b7fe9 Merge pull request #34 from johanhammar/urischeme
Do not render URI scheme if none of host, schemes or basePath are set
2015-08-29 01:32:59 +02:00
Johan Hammar
c15d074488 Do not render URI scheme if none of host, schemes or basePath are set 2015-08-28 22:18:49 +02:00
Robert Winkler
b0c3aa71b9 Merge pull request #32 from johanhammar/gradle25
Update the dependency-management-plugin to work with Gradle 2.5
2015-08-26 21:15:17 +02:00
Johan Hammar
32d85ffb55 Update the dependency-management-plugin to work with Gradle 2.5 2015-08-26 20:56:23 +02:00
Robert Winkler
59fcd61738 Updated documentation 2015-08-24 20:55:30 +02:00
Robert Winkler
7ce969882d Updated documentation 2015-08-24 20:54:39 +02:00
Robert Winkler
ee70cdb94f Update README.adoc 2015-08-24 20:52:32 +02:00
Robert Winkler
f21fce7730 * Enhancement #26 and #27: Added a pre-process hook to modify a Swagger Model before it is converted. 2015-08-24 20:44:46 +02:00
Robert Winkler
c426c7b341 Bugfix #29: Tags are rendered twice 2015-08-24 20:44:17 +02:00
Robert Winkler
1231d1e0c2 Merge pull request #27 from zmitrok/master
Added a hook to pre-process Swagger model before generating the marku…
2015-08-21 18:13:18 +02:00
zmitrok
66073aebb8 Added a hook to pre-process Swagger model before generating the markup. This approach heavily relies on the mutability of the Swagger class 2015-08-20 23:57:46 -07:00
Robert Winkler
882d9e5709 Merge pull request #23 from izeye/patch-1
Fix a broken link
2015-07-24 17:08:27 +02:00
izeye
ba9ec45d9e Fix a broken link 2015-07-24 21:07:36 +09:00
Robert Winkler
f2787a41ae Merge branch 'master' of https://github.com/Swagger2Markup/swagger2markup 2015-07-20 08:20:41 +02:00
Robert Winkler
1dc9a07cb9 Updated documentation 2015-07-14 08:33:46 +02:00
Robert Winkler
a34807e5c9 Updated Travis-CI Batch 2015-07-09 08:08:57 +02:00
Robert Winkler
85ef33a720 Updated documentation 2015-07-06 08:49:22 +02:00
Robert Winkler
3163c077a1 Updated documentation 2015-06-30 08:39:46 +02:00
Robert Winkler
fbb446875d Updated documentation 2015-06-30 08:38:54 +02:00
Robert Winkler
e8cdcabffe Updated documentation 2015-06-30 08:36:08 +02:00
Robert Winkler
832813d40a Updated documentation 2015-06-30 08:26:05 +02:00
Robert Winkler
e2f28bca7d Updated documentation 2015-06-29 15:29:06 +02:00
558 changed files with 65376 additions and 3062 deletions

82
.github/workflows/gradle-build.yml vendored Normal file
View File

@@ -0,0 +1,82 @@
# This workflow will build a Java project with Gradle
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle
name: Build
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
validation:
name: "Gradle wrapper validation"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2.3.5
- uses: gradle/wrapper-validation-action@v1.0.4
build:
name: "Build and publish"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2.3.5
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'temurin'
- name: Cache SonarCloud packages
uses: actions/cache@v2.1.6
if: env.SONAR_TOKEN != null && env.SONAR_TOKEN != ''
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Build
id: gradle
uses: eskatos/gradle-command-action@v1
with:
arguments: check
wrapper-cache-enabled: true
dependencies-cache-enabled: true
configuration-cache-enabled: true
- name: "Comment build scan url"
uses: actions/github-script@v5
if: github.event_name == 'pull_request' && failure()
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
github.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '❌ ${{ github.workflow }} failed: ${{ steps.gradle.outputs.build-scan-url }}'
})
- name: Publish Unit Test Results
uses: EnricoMi/publish-unit-test-result-action/composite@v1
if: always()
with:
files: '**/test-results/**/*.xml'
- name: Analyze with SonarCloud
continue-on-error: true
if: env.SONAR_TOKEN != null && env.SONAR_TOKEN != ''
uses: eskatos/gradle-command-action@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
arguments: sonarqube -Psonar.organization=swagger2markup
dependencies-cache-enabled: true
configuration-cache-enabled: true
- name: Publish to Sonatype
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
uses: eskatos/gradle-command-action@v1
env:
ORG_GRADLE_PROJECT_sonatypeUsername: ${{ secrets.SONATYPE_USER }}
ORG_GRADLE_PROJECT_sonatypePassword : ${{ secrets.SONATYPE_PASSWORD }}
with:
arguments: publishToSonatype
dependencies-cache-enabled: true
configuration-cache-enabled: true

6
.gitignore vendored
View File

@@ -2,3 +2,9 @@
*.iml
.gradle
build
/bin/
/.classpath
/.project
/.settings/
*.ipr
*.iws

View File

@@ -1,15 +0,0 @@
language: java
jdk:
- oraclejdk7
before_install:
- chmod +x gradlew
after_success:
- ./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:

5
ISSUE_TEMPLATE Normal file
View File

@@ -0,0 +1,5 @@
Thanks for raising a Swagger2Markup issue. Please provide a brief description of your problem along with the Swagger2Markup version you are using. If possible, please also consider putting together a complete Swagger specification that reproduces the issue. It's better if the Swagger specification is small and isolate the issue.
Swagger2Markup version:
Problem description:

View File

@@ -2,26 +2,71 @@
:author: Robert Winkler
:hardbreaks:
image:https://travis-ci.org/RobWin/swagger2markup.svg?branch=master["Build Status", link="https://travis-ci.org/RobWin/swagger2markup"] image:https://coveralls.io/repos/RobWin/swagger2markup/badge.svg["Coverage Status", link="https://coveralls.io/r/RobWin/swagger2markup"] image:https://api.bintray.com/packages/robwin/maven/swagger2markup/images/download.svg[link="https://bintray.com/robwin/maven/swagger2markup/_latestVersion"] image:http://img.shields.io/badge/license-ASF2-blue.svg["Apache License 2", link="http://www.apache.org/licenses/LICENSE-2.0.txt"] image:https://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"]
image:https://coveralls.io/repos/Swagger2Markup/swagger2markup/badge.svg["Coverage Status", link="https://coveralls.io/r/Swagger2Markup/swagger2markup"] image:https://api.codacy.com/project/badge/grade/498a6a39d7d84ff687546359f58ee18d["Codacy code quality", link="https://www.codacy.com/app/robwin/swagger2markup"] image:https://api.bintray.com/packages/swagger2markup/Maven/swagger2markup/images/download.svg[link="https://bintray.com/swagger2markup/Maven/swagger2markup/_latestVersion"] image:http://img.shields.io/badge/license-ASF2-blue.svg["Apache License 2", link="http://www.apache.org/licenses/LICENSE-2.0.txt"] image:https://img.shields.io/badge/Twitter-rbrtwnklr-blue.svg["Twitter", link="https://twitter.com/rbrtwnklr"] image:https://badges.gitter.im/Join%20Chat.svg[link="https://gitter.im/RobWin/swagger2markup?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge"]
== Overview
NOTE: Dear community,
unfortunately I can't maintain Swagger2Markup alone anymore. There are many interesting new topics:
1) Swagger v3 support
2) Fixing bugs
2) Merge Swagger2Markup repositories and create a new multi-module repository.
Any help is welcome.
Kind regards,
Robert
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.
NOTE: The Swagger Specification has been donated to to the https://openapis.org/[Open API Initiative (OAI)] and has been renamed to the https://github.com/OAI/OpenAPI-Specification[OpenAPI Specification].
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].
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].
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/tree/master/samples/java-jersey2[Swagger JAX-RS], https://github.com/springfox/springfox[springfox] or https://github.com/spring-projects/spring-restdocs[spring-restdocs]. See https://github.com/RobWin/swagger2markup#usage-guide[usage guide] below. If you are are Gradle or Maven user, you can also use the https://github.com/RobWin/swagger2markup-gradle-plugin[Swagger2Markup Gradle Plugin] or https://github.com/redowl/swagger2markup-maven-plugin[Swagger2markup Maven Plugin].
You can use Swagger2Markup to convert your 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].
http://asciidoctor.org/docs/asciidoc-writers-guide/[AsciiDoc] is preferable to Markdown as it has more features. AsciiDoc is a text document format for writing documentation, articles, books, ebooks, slideshows, web pages and blogs. AsciiDoc files can be converted to *HTML*, *PDF* and *EPUB*. AsciiDoc is much better suited for describing public APIs than *JavaDoc* or *Annotations*.
You can generate your HTML5, PDF and EPUB documentation via https://github.com/asciidoctor/asciidoctorj[asciidoctorj] or even better via the https://github.com/asciidoctor/asciidoctor-gradle-plugin[asciidoctor-gradle-plugin] or https://github.com/asciidoctor/asciidoctor-maven-plugin[asciidoctor-maven-plugin]. You can also use https://github.com/jbake-org/jbake[JBake], https://github.com/tomchristie/mkdocs[MkDocs], https://github.com/rtfd/readthedocs.org[ReadTheDocs] or https://github.com/tripit/slate[slate] to publish your AsciiDoc or Markdown documentation.
You can generate your HTML5, PDF and EPUB documentation via https://github.com/asciidoctor/asciidoctorj[asciidoctorj] or even better via the https://github.com/asciidoctor/asciidoctor-gradle-plugin[asciidoctor-gradle-plugin] or https://github.com/asciidoctor/asciidoctor-maven-plugin[asciidoctor-maven-plugin].
The project requires at least JDK 7.
The project requires at least JDK 8.
== Example
image::swagger2markup-documentation/src/docs/asciidoc/images/Swagger2Markup.PNG[]
image::swagger2markup-documentation/src/docs/asciidoc/images/Swagger2Markup_definitions.PNG[]
== Reference documentation
- http://swagger2markup.github.io/swagger2markup/1.3.3/[Reference Documentation]
- https://github.com/Swagger2Markup/swagger2markup/blob/master/RELEASENOTES.adoc[Release notes]
- https://github.com/Swagger2Markup/spring-swagger2markup-demo[Demo using Swagger2Markup, Spring Boot, Springfox and spring-restdocs]
The documentation can be found at http://swagger2markup.github.io/swagger2markup-docs/[Reference documentation]
== Contributing
=== Community contributions
Pull requests are welcome.
=== 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 youd 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.
== Companies who use Swagger2Markup
* Deutsche Telekom AG
* https://restlet.com/[Restlet] -- Restlet offers an API platform, covering the https://restlet.com/products/restlet-studio/[design], https://restlet.com/products/dhc/[test] and https://restlet.com/products/apispark/[operation] of Web APIs, and uses Swagger2Markup to generate appealing HTML documentation from API definitions.
* http://www.qaware.de/[QAware GmbH]
* http://www.appdirect.com/[AppDirect] -- The leading commerce platform for selling cloud services.
* http://www.wescale.com[wescale]
* http://taskassure.com[TaskAssure]
* https://www.isaac.nl[ISAAC]
* https://www.spreadshirt.de[Spreadshirt]
== License
@@ -31,4 +76,4 @@ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
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.
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.

View File

@@ -1,62 +1,169 @@
= Release Notes
== Version 0.1.0
* 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.
= Release Notes
== Version 0.1.0
* Initial version with support for AsciiDoc and Markdown
=== Version 0.1.1
* Signed jar files
=== Version 0.1.2
* Removed logback from compile dependency
=== Version 0.1.3
* Removed commons.io from compile dependency
=== Version 0.1.4
* Fixed SECTION_TITLE_LEVEL3 in Markdown enum
=== Version 0.1.5
* Added SECTION_TITLE_LEVEL4
== 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.
=== Version 0.9.3
* Updated swagger-parser from v1.0.13 to v1.0.16
* Enhancement #61: Refactor separated documents logic to support inter-document cross-references
* Enhancement #53: Support for tags, paths and methods ordering
* Enhancement #51: Support for separated operations files
* Enhancement #52: Markdown generation for inline schemas
== Version 1.0.0
* New configuration API
* New extension SPI
* Added new languages: turkish, german, france
* New security document
* Inline schema support
* New configuration options
* Support of deprecated path operations
=== Version 1.0.1
* Enhancement: Support to render validation constraints of properties
* Enhancement: Possibility to disable rendering of the security chapter below operations
== Version 1.1.0
* PR #177: Fixed rendering of recursive examples
* PR #186: Add support for Chinese language
* PR #190: Add support for Spanish language
* PR #192: Updated min/max value to format correctly based on the data type
* PR #193: Added support for exclusiveMin and exclusiveMax
* Changed bold to ** and italic to __ so that special chars in the text are possible
=== Version 1.1.1
* Issue #194: Added a config parameter which allows to prepend the basePath to all paths.
* Updated swagger-parser from v1.0.16 to v1.0.23
* Added javslang v2.0.4 as a dependency
* Added paleo-core v0.10.1 as a dependency
* Updated markup-document-builder from 1.0.0 to 1.1.0
* PR #201: Add support for Brazilian Portuguese language
* PR #202: Add support for Japanese language
* Issue #205: Fixed the option to influence resource ordering
* Issue #198: Chinese chinese language encoding
* Issue #207: Properties that start with an underscore are displayed correctly now
* Refactored Swagger2Markup to use a Component-Based design. A document can be composed of components and components can be composed of other components.
* Added a method to add page breaks.
== Version 1.1.2
* Improve code blocks in markdown
== Version 1.2.0
* Issue #214: Add page break locations
* Issue #223: Improve example rendering
* Issue #215: Add ability to group operations by RegEx
* Added new configuration options: pageBreakLocations, headerRegex
* Added new valid value for configuration headerRegex: REGEX
* Updated markup-document-builder from 1.1.0 to 1.1.1
== Version 1.3.0
* Updated javslang from 2.0.4 to 2.0.5
* Updated paleo-core from 0.10.1 to 0.10.2
* Updated swagger-parser from v1.0.23 to v1.0.25
* Decimal numbers are formatted into locale-specific strings
=== Version 1.3.1
* PR #247: Fix request path and query params example support.
=== Version 1.3.2
* PR #290: Fixed list parsing in properties file
* PR #293: Fixed crash on empty tables
* Updated markup-document-builder from 1.1.1 to 1.1.2
=== Version 1.3.3
* Updated swagger-parser from v1.0.25 to 1.0.35
* PR #294: Examples always start with a newline if there is other content in the same cell
* PR 307: Include required parameters in example request
=== Version 2.0.0
* Added openapi2markup to support OpenAPI v3
* Issue #409: Fixed JSON response example

View File

@@ -1,121 +1,121 @@
buildscript {
plugins {
id "org.sonarqube" version "2.7"
id "me.champeau.gradle.jmh" version "0.4.8"
id 'org.asciidoctor.convert' version '1.6.0'
id "org.ajoberstar.github-pages" version "1.7.2"
id "io.github.gradle-nexus.publish-plugin" version "1.1.0"
}
apply plugin: 'idea'
apply from: "${rootDir}/libraries.gradle"
ext {
releaseVersion = '1.3.3'
}
allprojects {
apply plugin: 'jacoco'
apply plugin: 'me.champeau.gradle.jmh'
version = '2.0.0-SNAPSHOT'
group 'io.github.swagger2markup'
description = 'swagger2markup Build'
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'org.asciidoctor:asciidoctor-gradle-plugin:1.5.2'
classpath 'org.asciidoctor:asciidoctorj-pdf:1.5.0-alpha.8'
classpath 'io.spring.gradle:dependency-management-plugin:0.5.1.RELEASE'
classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.0.1'
classpath 'org.asciidoctor:asciidoctorj:1.5.2'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.2'
}
}
description = 'swagger2markup Build'
version = '0.7.1'
group = 'io.github.robwin'
apply plugin: 'java'
apply plugin: 'maven-publish'
apply plugin: 'org.asciidoctor.convert'
apply plugin: 'jacoco'
apply plugin: 'com.github.kt3k.coveralls'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'com.jfrog.bintray'
apply from: 'gradle/publishing.gradle'
tasks.withType(JavaCompile) {
sourceCompatibility = "1.7"
targetCompatibility = "1.7"
options.deprecation = true
options.encoding = 'UTF-8'
options.compilerArgs << "-Xlint:unchecked"
}
repositories {
jcenter()
mavenCentral()
mavenLocal()
}
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 {
dependency "io.github.robwin:markup-document-builder:0.1.4"
dependency "io.swagger:swagger-compat-spec-parser:1.0.8"
dependency "commons-collections:commons-collections:3.2.1"
dependency "commons-io:commons-io:2.4"
dependency "junit:junit:4.11"
dependency "org.slf4j:slf4j-api:1.7.12"
dependency "ch.qos.logback:logback-classic:1.1.2"
dependency "org.assertj:assertj-core:2.0.0"
}
}
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
}
//artifactoryPublish.skip = true // apply to all projects except the root
ext {
generatedDocumentation = file('build/docs/asciidoc/generated')
}
asciidoctor {
dependsOn test
sources {
include 'index.adoc'
}
backends = ['html5', 'pdf']
attributes = [
doctype: 'book',
toc: 'left',
toclevels: '2',
numbered: '',
sectlinks: '',
sectanchors: '',
hardbreaks: '',
generated: generatedDocumentation
]
}
jacocoTestReport {
reports {
xml.enabled = true // coveralls plugin depends on xml format report
html.enabled = true
coreProjects = subprojects.findAll {
p -> !p.name.contains("documentation") && !p.name.endsWith("-bom")
}
}
tasks.coveralls {
dependsOn 'check'
configure(project.coreProjects) {
apply plugin: 'java'
apply plugin: 'java-library'
apply plugin: 'maven'
apply plugin: 'maven-publish'
apply from: "${rootDir}/publishing.gradle"
apply plugin: 'jacoco'
tasks.withType(JavaCompile) {
sourceCompatibility = "11"
targetCompatibility = "11"
options.deprecation = true
options.encoding = 'UTF-8'
options.compilerArgs += ["-Xlint:unchecked", "-parameters"]
}
tasks.withType(Javadoc){
options.encoding = 'UTF-8'
}
jmh {
duplicateClassesStrategy = 'warn'
}
configurations.all {
resolutionStrategy {
failOnVersionConflict()
}
}
}
tasks.asciidoctor {
dependsOn 'check'
nexusPublishing {
repositories {
sonatype()
}
}
task wrapper(type: Wrapper) {
gradleVersion = '2.4'
sonarqube {
properties {
property "sonar.host.url", "https://sonarcloud.io"
property "sonar.organization", "swagger2markup"
property "sonar.projectName", "swagger2markup"
property "sonar.projectKey", "Swagger2Markup_swagger2markup"
property "sonar.links.homepage", "https://github.com/Swagger2Markup/swagger2markup"
property "sonar.links.ci", "https://travis-ci.org/Swagger2Markup/swagger2markup"
property "sonar.links.scm", "https://github.com/Swagger2Markup/swagger2markup"
property "sonar.links.issue", "https://github.com/Swagger2Markup/swagger2markup/issues"
property "sonar.language", "java"
}
}
def allTestCoverageFile = "$buildDir/jacoco/allTestCoverage.exec"
task jacocoMergeTest(type: JacocoMerge) {
destinationFile = file(allTestCoverageFile)
executionData = project.fileTree(dir: '.', include: '**/build/jacoco/test.exec')
}
task jacocoMerge(dependsOn: ['jacocoMergeTest']) {
// used to run the other merge tasks
}
subprojects {
sonarqube {
properties {
property "sonar.jacoco.reportPaths", allTestCoverageFile
}
}
afterEvaluate {
// exclude subprojects that don't produce a jar file or by design.
if (!project.name.equals('swagger2markup-bom') && !project.name.equals('swagger2markup-documentation')) {
jar {
into("META-INF/maven/$project.group/$project.name") {
from {generatePomFileForMavenJavaPublication}
rename ".*", "pom.xml"
}
inputs.property('moduleName', moduleName)
manifest.attributes(
'Automatic-Module-Name': moduleName
)
}
}
}
}
tasks.check.dependsOn tasks.jacocoTestReport
test {
dependsOn(subprojects.test) // required by cobertura to aggregate report
}

2
gradle.properties Normal file
View File

@@ -0,0 +1,2 @@
systemProp.file.encoding=UTF-8
systemProp.sun.jnu.encoding=UTF-8

View File

@@ -1,100 +0,0 @@
import java.text.SimpleDateFormat
Date buildTimeAndDate = new Date()
ext {
buildDate = new SimpleDateFormat('yyyy-MM-dd').format(buildTimeAndDate)
buildTime = new SimpleDateFormat('HH:mm:ss.SSSZ').format(buildTimeAndDate)
}
def projectArtifactId = 'swagger2markup'
jar {
manifest {
attributes(
'Built-By': 'Robert Winkler',
'Created-By': System.properties['java.version'] + " (" + System.properties['java.vendor'] + " " + System.properties['java.vm.version'] + ")",
'Build-Date': project.buildDate,
'Build-Time': project.buildTime,
'Specification-Title': projectArtifactId,
'Specification-Version': project.version,
'Implementation-Title': projectArtifactId,
'Implementation-Version': project.version
)
}
}
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
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/RobWin/swagger2markup'
issueTrackerUrl = 'https://github.com/RobWin/swagger2markup/issues'
vcsUrl = 'https://github.com/RobWin/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/RobWin/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/RobWin/swagger2markup/blob/master/LICENSE.txt')
license.appendNode('distribution', 'repo')
root.appendNode('scm').appendNode('url', 'https://github.com/RobWin/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
}
}
}

Binary file not shown.

View File

@@ -1,6 +1,6 @@
#Mon Jun 08 08:20:09 CEST 2015
#Mon Oct 21 16:35:38 BST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.3-all.zip

110
gradlew vendored Normal file → Executable file
View File

@@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/usr/bin/env sh
##############################################################################
##
@@ -6,47 +6,6 @@
##
##############################################################################
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn ( ) {
echo "$*"
}
die ( ) {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
esac
# For Cygwin, ensure paths are in UNIX format before anything is touched.
if $cygwin ; then
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
fi
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
@@ -61,9 +20,49 @@ while [ -h "$PRG" ] ; do
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >&-
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >&-
cd "$SAVED" >/dev/null
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn () {
echo "$*"
}
die () {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
@@ -90,7 +89,7 @@ location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
@@ -114,6 +113,7 @@ fi
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
@@ -154,11 +154,19 @@ if $cygwin ; then
esac
fi
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
JVM_OPTS=("$@")
# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
APP_ARGS=$(save "$@")
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi
exec "$JAVACMD" "$@"

174
gradlew.bat vendored
View File

@@ -1,90 +1,84 @@
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windowz variants
if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
goto execute
:4NT_args
@rem Get arguments from the 4NT Shell from JP Software
set CMD_LINE_ARGS=%$
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windows variants
if not "%OS%" == "Windows_NT" goto win9xME_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

Binary file not shown.

Before

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 104 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 109 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 138 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 87 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

52
libraries.gradle Normal file
View File

@@ -0,0 +1,52 @@
// Allows centralized definition of the version of artifacts to
// use. In that respect it serves a role similar to <dependencyManagement> in Maven
ext {
implLibraries = [:]
testLibraries = [:]
dependencyOverrides = [:]
}
implLibraries = [
asciiDocJApi : "org.asciidoctor:asciidoctorj-api:2.2.0",
commonsBeanUtils : "commons-beanutils:commons-beanutils:1.9.4",
commonsCodec : "commons-codec:commons-codec:1.13",
commonsCollections4: "org.apache.commons:commons-collections4:4.4",
commonsConf2 : "org.apache.commons:commons-configuration2:2.6",
commonsLang3 : "org.apache.commons:commons-lang3:3.9",
commonsIO : "commons-io:commons-io:2.6",
commonsText : "org.apache.commons:commons-text:1.8",
guava : 'com.google.guava:guava:27.0.1-android',
jacksonDatabind : 'com.fasterxml.jackson.core:jackson-databind:2.9.10',
mark2Ascii : "nl.jworks.markdown_to_asciidoc:markdown_to_asciidoc:1.1",
paleo : "ch.netzwerg:paleo-core:0.14.0",
pegdown : "org.pegdown:pegdown:1.6.0",
slf4j : "org.slf4j:slf4j-api:1.7.28",
swaggerV2 : "io.swagger:swagger-parser:1.0.47",
swaggerV2Converter : "io.swagger.parser.v3:swagger-parser-v2-converter:2.0.15",
swaggerV3 : "io.swagger.parser.v3:swagger-parser:2.0.15",
vavr : "io.vavr:vavr:0.10.2"
]
testLibraries = [
asciiDocJ : "org.asciidoctor:asciidoctorj:2.2.0",
assertj : "org.assertj:assertj-core:3.13.2",
assertjDiff: "io.github.robwin:assertj-diff:0.1.1",
junit : "junit:junit:4.12",
logback : "ch.qos.logback:logback-classic:1.2.3",
mockito : "org.mockito:mockito-core:3.1.0"
]
dependencyOverrides = [
assertj : testLibraries.assertj,
commonsCodec : implLibraries.commonsCodec,
commonsIO : implLibraries.commonsIO,
commonsLang3 : implLibraries.commonsLang3,
findBugs : 'com.google.code.findbugs:jsr305:3.0.2',
guava : implLibraries.guava,
jaksonCore : 'com.github.fge:jackson-coreutils:1.8',
jacksonDatabind: implLibraries.jacksonDatabind,
jnrConstants : 'com.github.jnr:jnr-constants:0.9.12',
jnrEnxio : 'com.github.jnr:jnr-enxio:0.19',
jnrPosix : 'com.github.jnr:jnr-posix:3.0.49',
jodaTime : 'joda-time:joda-time:2.9.9',
slf4j : implLibraries.slf4j,
]

View File

@@ -0,0 +1,34 @@
ext.moduleName="io.github.swagger2markup.openapi2markup"
dependencies {
configurations.all {
resolutionStrategy.force dependencyOverrides.commonsCodec
resolutionStrategy.force dependencyOverrides.commonsIO
resolutionStrategy.force dependencyOverrides.commonsLang3
resolutionStrategy.force dependencyOverrides.jnrConstants
resolutionStrategy.force dependencyOverrides.jnrEnxio
resolutionStrategy.force dependencyOverrides.jnrPosix
resolutionStrategy.force dependencyOverrides.jodaTime
resolutionStrategy.force dependencyOverrides.slf4j
resolutionStrategy.force dependencyOverrides.jacksonDatabind
resolutionStrategy.force dependencyOverrides.guava
resolutionStrategy.force dependencyOverrides.findBugs
resolutionStrategy.force dependencyOverrides.jaksonCore
resolutionStrategy.force dependencyOverrides.assertj
}
// implementation implLibraries.swaggerV2Converter
compile project(':swagger2markup-asciidoc')
compile project(':swagger2markup-core')
implementation implLibraries.asciiDocJApi
implementation implLibraries.commonsText
implementation implLibraries.commonsBeanUtils
implementation implLibraries.slf4j
implementation implLibraries.swaggerV3
implementation implLibraries.commonsCollections4
implementation implLibraries.commonsConf2
implementation implLibraries.vavr
testImplementation testLibraries.assertj
testImplementation testLibraries.assertjDiff
testImplementation testLibraries.junit
testImplementation testLibraries.logback
}

View File

@@ -0,0 +1,378 @@
/*
* Copyright 2017 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.swagger2markup;
import io.github.swagger2markup.adoc.ast.impl.DocumentImpl;
import io.github.swagger2markup.config.OpenAPILabels;
import io.github.swagger2markup.config.builder.OpenAPI2MarkupConfigBuilder;
import io.github.swagger2markup.extension.OpenAPI2MarkupExtensionRegistry;
import io.github.swagger2markup.extension.builder.OpenAPI2MarkupExtensionRegistryBuilder;
import io.github.swagger2markup.internal.document.ComponentsDocument;
import io.github.swagger2markup.internal.document.OverviewDocument;
import io.github.swagger2markup.internal.document.PathsDocument;
import io.github.swagger2markup.internal.document.SecurityDocument;
import io.github.swagger2markup.utils.URIUtils;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.parser.OpenAPIV3Parser;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.Validate;
import org.asciidoctor.ast.Document;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
public class OpenAPI2MarkupConverter extends AbstractSchema2MarkupConverter<OpenAPI> {
private final OverviewDocument overviewDocument;
private final PathsDocument pathsDocument;
private final ComponentsDocument componentsDocument;
private final SecurityDocument securityDocument;
private final OpenAPIContext openAPIContext;
public OpenAPI2MarkupConverter(OpenAPIContext context) {
super(context);
this.openAPIContext = context;
this.overviewDocument = new OverviewDocument(context);
this.pathsDocument = new PathsDocument(context);
this.componentsDocument = new ComponentsDocument(context);
this.securityDocument = new SecurityDocument(context);
}
/**
* Creates a OpenAPI2MarkupConverter.Builder from a URI.
*
* @param swaggerUri the URI
* @return a OpenAPI2MarkupConverter
*/
public static Builder from(URI swaggerUri) {
Validate.notNull(swaggerUri, "swaggerUri must not be null");
String scheme = swaggerUri.getScheme();
if (scheme != null && swaggerUri.getScheme().startsWith("http")) {
try {
return from(swaggerUri.toURL());
} catch (MalformedURLException e) {
throw new RuntimeException("Failed to convert URI to URL", e);
}
} else if (scheme != null && swaggerUri.getScheme().startsWith("file")) {
return from(Paths.get(swaggerUri));
} else {
return from(URIUtils.convertUriWithoutSchemeToFileScheme(swaggerUri));
}
}
/**
* Creates a OpenAPI2MarkupConverter.Builder using a remote URL.
*
* @param swaggerURL the remote URL
* @return a OpenAPI2MarkupConverter
*/
public static Builder from(URL swaggerURL) {
Validate.notNull(swaggerURL, "swaggerURL must not be null");
return new Builder(swaggerURL);
}
/**
* Creates a OpenAPI2MarkupConverter.Builder using a local Path.
*
* @param swaggerPath the local Path
* @return a OpenAPI2MarkupConverter
*/
public static Builder from(Path swaggerPath) {
Validate.notNull(swaggerPath, "swaggerPath must not be null");
if (Files.notExists(swaggerPath)) {
throw new IllegalArgumentException(String.format("swaggerPath does not exist: %s", swaggerPath));
}
try {
if (Files.isHidden(swaggerPath)) {
throw new IllegalArgumentException("swaggerPath must not be a hidden file");
}
} catch (IOException e) {
throw new RuntimeException("Failed to check if swaggerPath is a hidden file", e);
}
return new Builder(swaggerPath);
}
/**
* Creates a OpenAPI2MarkupConverter.Builder from a given Swagger model.
*
* @param openAPI the Swagger source.
* @return a OpenAPI2MarkupConverter
*/
public static Builder from(OpenAPI openAPI) {
Validate.notNull(openAPI, "schema must not be null");
return new Builder(openAPI);
}
/**
* Creates a OpenAPI2MarkupConverter.Builder from a given Swagger YAML or JSON String.
*
* @param swaggerString the Swagger YAML or JSON String.
* @return a OpenAPI2MarkupConverter
*/
public static Builder from(String swaggerString) {
Validate.notEmpty(swaggerString, "swaggerString must not be null");
return from(new StringReader(swaggerString));
}
/**
* Creates a OpenAPI2MarkupConverter.Builder from a given Swagger YAML or JSON reader.
*
* @param schemaReader the schema YAML or JSON reader.
* @return a OpenAPI2MarkupConverter
*/
public static Builder from(Reader schemaReader) {
Validate.notNull(schemaReader, "swaggerReader must not be null");
OpenAPI openAPI;
try {
//TODO
openAPI = new OpenAPIV3Parser().read(IOUtils.toString(schemaReader));
} catch (IOException e) {
throw new RuntimeException("Swagger source can not be parsed", e);
}
if (openAPI == null)
throw new IllegalArgumentException("Swagger source is in a wrong format");
return new Builder(openAPI);
}
@Override
public void toFolder(Path outputDirectory) {
Validate.notNull(outputDirectory, "outputDirectory must not be null");
openAPIContext.setOutputPath(outputDirectory);
writeToFile(applyOverviewDocument(), outputDirectory.resolve(openAPIContext.config.getOverviewDocument()));
writeToFile(applyPathsDocument(), outputDirectory.resolve(openAPIContext.config.getPathsDocument()));
writeToFile(applyComponentsDocument(), outputDirectory.resolve(openAPIContext.config.getDefinitionsDocument()));
writeToFile(applySecurityDocument(), outputDirectory.resolve(openAPIContext.config.getSecurityDocument()));
}
@Override
public void toFile(Path outputFile) {
Validate.notNull(outputFile, "outputFile must not be null");
writeToFile(applyOverviewDocument(), outputFile);
writeToFile(applyPathsDocument(), outputFile);
writeToFile(applyComponentsDocument(), outputFile);
writeToFile(applySecurityDocument(), outputFile);
}
@Override
public void toFileWithoutExtension(Path outputFile) {
Validate.notNull(outputFile, "outputFile must not be null");
writeToFileWithoutExtension(applyOverviewDocument(), outputFile);
writeToFileWithoutExtension(applyPathsDocument(), outputFile);
writeToFileWithoutExtension(applyComponentsDocument(), outputFile);
writeToFileWithoutExtension(applySecurityDocument(), outputFile);
}
@Override
public String toString() {
return applyOverviewDocument().convert() +
applyPathsDocument().convert() +
applyComponentsDocument().convert() +
applySecurityDocument().convert();
}
private Document applyOverviewDocument() {
return overviewDocument.apply(
openAPIContext.createDocument(),
OverviewDocument.parameters(openAPIContext.getSchema()));
}
private Document applyPathsDocument() {
return pathsDocument.apply(
openAPIContext.createDocument(),
PathsDocument.parameters(openAPIContext.getSchema()));
}
private Document applyComponentsDocument() {
return componentsDocument.apply(
openAPIContext.createDocument(),
ComponentsDocument.parameters(openAPIContext.getSchema().getComponents()));
}
private Document applySecurityDocument() {
return securityDocument.apply(
openAPIContext.createDocument(),
SecurityDocument.parameters(openAPIContext.getSchema()));
}
private void writeToFile(Document document, Path path) {
MarkupLanguage markupLanguage = openAPIContext.config.getMarkupLanguage();
if (isMarkupLanguageSupported(markupLanguage)) {
String fileExtension = markupLanguage.getFileNameExtensions().get(0);
writeToFileWithoutExtension(document, path.resolveSibling(path.getFileName().toString() + fileExtension));
} else {
throw new RuntimeException("Given Markup language '"+markupLanguage+"' is not supported by "+getClass().getName());
}
}
private boolean isMarkupLanguageSupported(MarkupLanguage markupLanguage) {
return markupLanguage == MarkupLanguage.ASCIIDOC;
}
private void writeToFileWithoutExtension(Document document, Path file) {
if (file.getParent() != null) {
try {
Files.createDirectories(file.getParent());
} catch (IOException e) {
throw new RuntimeException("Failed create directory", e);
}
}
try (BufferedWriter writer = Files.newBufferedWriter(file, StandardCharsets.UTF_8)) {
writer.write(document.convert());
} catch (IOException e) {
throw new RuntimeException("Failed to write file", e);
}
if (logger.isInfoEnabled()) {
logger.info("Markup document written to: {}", file);
}
}
public static class OpenAPIContext extends Context<OpenAPI> {
private OpenSchema2MarkupConfig config;
private OpenAPI2MarkupExtensionRegistry extensionRegistry;
public OpenAPIContext(OpenSchema2MarkupConfig config,
OpenAPI2MarkupExtensionRegistry extensionRegistry,
OpenAPI schema, URI swaggerLocation, Labels labels) {
super(config, extensionRegistry, schema, swaggerLocation, labels);
this.config = config;
this.extensionRegistry = extensionRegistry;
}
@Override
public OpenSchema2MarkupConfig getConfig() {
return config;
}
@Override
public OpenAPI2MarkupExtensionRegistry getExtensionRegistry() {
return extensionRegistry;
}
public Document createDocument() {
return new DocumentImpl();
}
}
public static class Builder {
private final OpenAPI openAPI;
private final URI schemaLocation;
private OpenSchema2MarkupConfig config;
private OpenAPI2MarkupExtensionRegistry extensionRegistry;
/**
* Creates a Builder from a remote URL.
*
* @param schemaUrl the remote URL
*/
Builder(URL schemaUrl) {
try {
this.schemaLocation = schemaUrl.toURI();
} catch (URISyntaxException e) {
throw new IllegalArgumentException("swaggerURL is in a wrong format", e);
}
this.openAPI = readSchema(schemaUrl.toString());
}
/**
* Creates a Builder from a local Path.
*
* @param swaggerPath the local Path
*/
Builder(Path swaggerPath) {
this.schemaLocation = swaggerPath.toAbsolutePath().toUri();
this.openAPI = readSchema(swaggerPath.toString());
}
/**
* Creates a Builder using a given Swagger model.
*
* @param openAPI the Swagger source.
*/
Builder(OpenAPI openAPI) {
this.openAPI = openAPI;
this.schemaLocation = null;
}
/**
* Uses the SwaggerParser to read the Swagger source.
*
* @param schemaLocation the location of the Swagger source
* @return the Swagger model
*/
private OpenAPI readSchema(String schemaLocation) {
OpenAPI openAPI = new OpenAPIV3Parser().read(schemaLocation);
if (openAPI == null) {
throw new IllegalArgumentException("Failed to read the schema");
}
return openAPI;
}
public Builder withConfig(OpenSchema2MarkupConfig config) {
Validate.notNull(config, "config must not be null");
this.config = config;
return this;
}
public Builder withExtensionRegistry(OpenAPI2MarkupExtensionRegistry registry) {
Validate.notNull(registry, "registry must not be null");
this.extensionRegistry = registry;
return this;
}
public OpenAPI2MarkupConverter build() {
if (config == null)
config = new OpenAPI2MarkupConfigBuilder().build();
if (extensionRegistry == null)
extensionRegistry = new OpenAPI2MarkupExtensionRegistryBuilder().build();
OpenAPILabels openApiLabels = new OpenAPILabels(config);
OpenAPIContext context = new OpenAPIContext(config, extensionRegistry, openAPI, schemaLocation, openApiLabels);
initExtensions(context);
applySwaggerExtensions(context);
return new OpenAPI2MarkupConverter(context);
}
private void initExtensions(OpenAPIContext context) {
extensionRegistry.getSwaggerModelExtensions().forEach(extension -> extension.setGlobalContext(context));
extensionRegistry.getOverviewDocumentExtensions().forEach(extension -> extension.setGlobalContext(context));
extensionRegistry.getDefinitionsDocumentExtensions().forEach(extension -> extension.setGlobalContext(context));
extensionRegistry.getPathsDocumentExtensions().forEach(extension -> extension.setGlobalContext(context));
extensionRegistry.getSecurityDocumentExtensions().forEach(extension -> extension.setGlobalContext(context));
}
private void applySwaggerExtensions(OpenAPIContext context) {
extensionRegistry.getSwaggerModelExtensions().forEach(extension -> extension.apply(context.getSchema()));
}
}
}

View File

@@ -0,0 +1,36 @@
/*
* Copyright 2017 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.swagger2markup;
import org.apache.commons.configuration2.Configuration;
import java.util.Map;
import java.util.Properties;
public class OpenAPI2MarkupProperties extends Schema2MarkupProperties {
public OpenAPI2MarkupProperties(Properties properties) {
super(properties);
}
public OpenAPI2MarkupProperties(Map<String, String> map) {
super(map);
}
public OpenAPI2MarkupProperties(Configuration configuration) {
super(configuration);
}
}

View File

@@ -0,0 +1,7 @@
package io.github.swagger2markup;
import io.github.swagger2markup.config.builder.Schema2MarkupConfigBuilder;
public class OpenSchema2MarkupConfig extends Schema2MarkupConfigBuilder.DefaultSchema2MarkupConfig {
}

View File

@@ -0,0 +1,72 @@
package io.github.swagger2markup.config;
import io.github.swagger2markup.Labels;
import io.github.swagger2markup.OpenSchema2MarkupConfig;
import java.util.ResourceBundle;
public class OpenAPILabels extends Labels {
public static final String LABEL_CONTENT = "label_content";
public static final String LABEL_DEFAULT = "label_default";
public static final String LABEL_DEPRECATED = "label_deprecated";
public static final String LABEL_EXAMPLE = "label_example";
public static final String LABEL_EXAMPLES = "label_examples";
public static final String LABEL_EXCLUSIVE_MAXIMUM = "label_exclusive_maximum";
public static final String LABEL_EXCLUSIVE_MINIMUM = "label_exclusive_minimum";
public static final String LABEL_EXTERNAL_VALUE = "label_external_value";
public static final String LABEL_FORMAT = "label_format";
public static final String LABEL_MAXIMUM = "label_maximum";
public static final String LABEL_MAX_ITEMS = "label_max_items";
public static final String LABEL_MAX_LENGTH = "label_max_length";
public static final String LABEL_MAX_PROPERTIES = "label_max_properties";
public static final String LABEL_MINIMUM = "label_minimum";
public static final String LABEL_MIN_ITEMS = "label_min_items";
public static final String LABEL_MIN_LENGTH = "label_min_length";
public static final String LABEL_MIN_PROPERTIES = "label_min_properties";
public static final String LABEL_MULTIPLE_OF = "label_multiple_of";
public static final String LABEL_NO_LINKS = "label_no_links";
public static final String LABEL_NULLABLE = "label_nullable";
public static final String LABEL_OPERATION = "label_operation";
public static final String LABEL_OPTIONAL = "label_optional";
public static final String LABEL_PARAMETERS = "label_parameters";
public static final String LABEL_READ_ONLY = "label_read_only";
public static final String LABEL_REQUIRED = "label_required";
public static final String LABEL_SERVER = "label_server";
public static final String LABEL_TERMS_OF_SERVICE = "label_terms_of_service";
public static final String LABEL_TITLE = "label_title";
public static final String LABEL_TYPE = "label_type";
public static final String LABEL_UNIQUE_ITEMS = "label_unique_items";
public static final String LABEL_WRITE_ONLY = "label_write_only";
public static final String SECTION_TITLE_COMPONENTS = "section_title_components";
public static final String SECTION_TITLE_PARAMETERS = "section_title_parameters";
public static final String SECTION_TITLE_PATHS = "section_title_paths";
public static final String SECTION_TITLE_SCHEMAS = "section_title_schemas";
public static final String SECTION_TITLE_SECURITY = "section_title_security";
public static final String SECTION_TITLE_SERVERS = "section_title_servers";
public static final String SECTION_TITLE_OVERVIEW = "section_title_overview";
public static final String SECTION_TITLE_TAGS = "section_title_tags";
public static final String SECTION_TITLE_RESPONSES = "section_title_responses";
public static final String SECTION_TITLE_HEADERS = "section_title_headers";
public static final String SECTION_TITLE_LINKS = "section_title_links";
public static final String TABLE_HEADER_DEFAULT = "table_header_default";
public static final String TABLE_HEADER_DESCRIPTION = "table_header_description";
public static final String TABLE_HEADER_HTTP_CODE = "table_header_http_code";
public static final String TABLE_HEADER_LINKS = "table_header_links";
public static final String TABLE_HEADER_NAME = "table_header_name";
public static final String TABLE_HEADER_POSSIBLE_VALUES = "table_header_possible_values";
public static final String TABLE_HEADER_SCHEMA = "table_header_schema";
public static final String TABLE_HEADER_SCOPES = "table_header_scopes";
public static final String TABLE_HEADER_TYPE = "table_header_type";
public static final String TABLE_HEADER_VARIABLE = "table_header_variable";
public static final String TABLE_TITLE_HEADERS = "table_title_headers";
public static final String TABLE_TITLE_PARAMETERS = "table_title_parameters";
public static final String TABLE_TITLE_PROPERTIES = "table_title_properties";
public static final String TABLE_TITLE_RESPONSES = "table_title_responses";
public static final String TABLE_TITLE_SECURITY = "table_title_security";
public static final String TABLE_TITLE_SERVER_VARIABLES = "table_title_server_variables";
public OpenAPILabels(OpenSchema2MarkupConfig config) {
super(ResourceBundle.getBundle("io/github/swagger2markup/lang/labels", config.getLanguage().toLocale()));
}
}

View File

@@ -0,0 +1,38 @@
package io.github.swagger2markup.config.builder;
import io.github.swagger2markup.OpenAPI2MarkupProperties;
import io.github.swagger2markup.OpenSchema2MarkupConfig;
import org.apache.commons.configuration2.Configuration;
import org.apache.commons.configuration2.ConfigurationConverter;
import org.apache.commons.configuration2.MapConfiguration;
import org.apache.commons.configuration2.PropertiesConfiguration;
import java.util.Map;
import java.util.Properties;
public class OpenAPI2MarkupConfigBuilder extends Schema2MarkupConfigBuilder<OpenAPI2MarkupConfigBuilder, OpenSchema2MarkupConfig> {
public OpenAPI2MarkupConfigBuilder() {
this(new PropertiesConfiguration());
}
public OpenAPI2MarkupConfigBuilder(Properties properties) {
this(ConfigurationConverter.getConfiguration(properties));
}
public OpenAPI2MarkupConfigBuilder(Map<String, String> map) {
this(new MapConfiguration(map));
}
private OpenAPI2MarkupConfigBuilder(Configuration configuration) {
super(OpenAPI2MarkupConfigBuilder.class,
new OpenSchema2MarkupConfig(),
new OpenAPI2MarkupProperties(getCompositeConfiguration(configuration)), configuration);
}
@Override
public OpenSchema2MarkupConfig build() {
buildNaturalOrdering();
return config;
}
}

View File

@@ -0,0 +1,36 @@
/*
* Copyright 2017 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.swagger2markup.extension;
import io.github.swagger2markup.OpenAPI2MarkupConverter.OpenAPIContext;
/**
* An abstract OpenAPI extension which must be extended by an other OpenAPI extensions
*/
abstract class AbstractExtension implements Extension {
protected OpenAPIContext globalContext;
/**
* Global context lazy initialization
*
* @param globalContext Global context
*/
public void setGlobalContext(OpenAPIContext globalContext) {
this.globalContext = globalContext;
}
}

View File

@@ -0,0 +1,15 @@
package io.github.swagger2markup.extension;
import org.asciidoctor.ast.Document;
public class ContentContext {
private Document document;
public ContentContext(Document document) {
this.document = document;
}
public Document getDocument() {
return document;
}
}

View File

@@ -0,0 +1,94 @@
/*
* Copyright 2017 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.swagger2markup.extension;
import io.swagger.models.Model;
import org.apache.commons.lang3.Validate;
import org.asciidoctor.ast.Document;
import java.util.Optional;
/**
* DefinitionsDocumentExtension extension point can be used to extend the definitions document content.
*/
public abstract class DefinitionsDocumentExtension extends AbstractExtension {
public abstract void apply(Context context);
public enum Position {
DOCUMENT_BEFORE,
DOCUMENT_BEGIN,
DOCUMENT_END,
DOCUMENT_AFTER,
DEFINITION_BEFORE,
DEFINITION_BEGIN,
DEFINITION_END,
DEFINITION_AFTER
}
public static class Context extends ContentContext {
private Position position;
/**
* null if position == DOCUMENT_*
*/
private String definitionName;
/**
* null if position == DOCUMENT_*
*/
private Model model;
/**
* @param position the current position
* @param document document object
*/
public Context(Position position, Document document) {
super(document);
Validate.inclusiveBetween(Position.DOCUMENT_BEFORE, Position.DOCUMENT_AFTER, position);
this.position = position;
}
/**
* @param position the current position
* @param document document object
* @param definitionName the name of the current definition
* @param model the current Model of the definition
*/
public Context(Position position, Document document, String definitionName, Model model) {
super(document);
Validate.inclusiveBetween(Position.DEFINITION_BEFORE, Position.DEFINITION_AFTER, position);
Validate.notNull(definitionName);
Validate.notNull(model);
this.position = position;
this.definitionName = definitionName;
this.model = model;
}
public Position getPosition() {
return position;
}
public Optional<String> getDefinitionName() {
return Optional.ofNullable(definitionName);
}
public Optional<Model> getModel() {
return Optional.ofNullable(model);
}
}
}

View File

@@ -0,0 +1,33 @@
/*
* Copyright 2017 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.swagger2markup.extension;
import static io.github.swagger2markup.OpenAPI2MarkupConverter.OpenAPIContext;
/**
* Extension interface which must be implemented by an OpenAPI extension
*/
interface Extension {
/**
* Global context lazy initialization
*
* @param globalContext Global context
*/
void setGlobalContext(OpenAPIContext globalContext);
}

View File

@@ -0,0 +1,41 @@
/*
* Copyright 2017 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.swagger2markup.extension;
import io.github.swagger2markup.OpenSchema2MarkupConfig;
import io.github.swagger2markup.OpenAPI2MarkupConverter;
import io.github.swagger2markup.Labels;
import io.swagger.v3.oas.models.OpenAPI;
import io.vavr.Function2;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public abstract class MarkupComponent<D, T, R> implements Function2<D, T, R> {
protected Logger logger = LoggerFactory.getLogger(getClass());
protected OpenAPI2MarkupConverter.Context<OpenAPI> context;
protected Labels labels;
protected OpenSchema2MarkupConfig config;
protected OpenAPI2MarkupExtensionRegistry extensionRegistry;
public MarkupComponent(OpenAPI2MarkupConverter.OpenAPIContext context) {
this.context = context;
this.config = context.getConfig();
this.extensionRegistry = context.getExtensionRegistry();
this.labels = context.getLabels();
}
}

View File

@@ -0,0 +1,58 @@
/*
* Copyright 2017 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.swagger2markup.extension;
import java.util.List;
/**
* Extension points registry interface.
*/
public interface OpenAPI2MarkupExtensionRegistry extends Schema2MarkupExtensionRegistry {
/**
* OpenAPIModelExtension extension point can be used to preprocess the Swagger model.
*
* @return registered extensions extending OpenAPIModelExtension extension point
*/
List<OpenAPIModelExtension> getSwaggerModelExtensions();
/**
* OverviewDocumentExtension extension point can be used to extend the overview document content.
*
* @return registered extensions extending OverviewDocumentExtension extension point
*/
List<OverviewDocumentExtension> getOverviewDocumentExtensions();
/**
* DefinitionsDocumentExtension extension point can be used to extend the definitions document content.
*
* @return registered extensions extending DefinitionsDocumentExtension extension point
*/
List<DefinitionsDocumentExtension> getDefinitionsDocumentExtensions();
/**
* SecurityContentExtension extension point can be used to extend the security document content.
*
* @return registered extensions extending SecurityContentExtension extension point
*/
List<SecurityDocumentExtension> getSecurityDocumentExtensions();
/**
* PathsDocumentExtension extension point can be used to extend the paths document content.
*
* @return registered extensions extending PathsDocumentExtension extension point
*/
List<PathsDocumentExtension> getPathsDocumentExtensions();
}

View File

@@ -0,0 +1,28 @@
/*
* Copyright 2017 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.swagger2markup.extension;
import io.swagger.v3.oas.models.OpenAPI;
/**
* OpenAPIModelExtension extension point can be used to preprocess the Swagger model.
*/
public abstract class OpenAPIModelExtension extends AbstractExtension {
public abstract void apply(OpenAPI openAPI);
}

View File

@@ -0,0 +1,52 @@
/*
* Copyright 2017 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.swagger2markup.extension;
import org.asciidoctor.ast.Document;
/**
* OverviewDocumentExtension extension point can be used to extend the overview document content.
*/
public abstract class OverviewDocumentExtension extends AbstractExtension {
public abstract void apply(Context context);
public enum Position {
DOCUMENT_BEFORE,
DOCUMENT_AFTER,
DOCUMENT_BEGIN,
DOCUMENT_END
}
public static class Context extends ContentContext {
private Position position;
/**
* @param position the current position
* @param document document object
*/
public Context(Position position, Document document) {
super(document);
this.position = position;
}
public Position getPosition() {
return position;
}
}
}

View File

@@ -0,0 +1,101 @@
/*
* Copyright 2017 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.swagger2markup.extension;
import io.github.swagger2markup.model.PathOperation;
import org.apache.commons.lang3.Validate;
import org.asciidoctor.ast.Document;
import java.util.Optional;
/**
* PathsDocumentExtension extension point can be used to extend the paths document content.
*/
public abstract class PathsDocumentExtension extends AbstractExtension {
public abstract void apply(Context context);
public enum Position {
DOCUMENT_BEFORE,
DOCUMENT_BEGIN,
DOCUMENT_END,
DOCUMENT_AFTER,
OPERATION_BEFORE,
OPERATION_BEGIN,
OPERATION_END,
OPERATION_AFTER,
OPERATION_DESCRIPTION_BEFORE,
OPERATION_DESCRIPTION_BEGIN,
OPERATION_DESCRIPTION_END,
OPERATION_DESCRIPTION_AFTER,
OPERATION_PARAMETERS_BEFORE,
OPERATION_PARAMETERS_BEGIN,
OPERATION_PARAMETERS_END,
OPERATION_PARAMETERS_AFTER,
OPERATION_RESPONSES_BEFORE,
OPERATION_RESPONSES_BEGIN,
OPERATION_RESPONSES_END,
OPERATION_RESPONSES_AFTER,
OPERATION_SECURITY_BEFORE,
OPERATION_SECURITY_BEGIN,
OPERATION_SECURITY_END,
OPERATION_SECURITY_AFTER
}
public static class Context extends ContentContext {
private Position position;
/**
* null if position == DOCUMENT_*
*/
private PathOperation operation;
/**
* Context for positions DOCUMENT_*
*
* @param position the current position
* @param document document object
*/
public Context(Position position, Document document) {
super(document);
Validate.inclusiveBetween(Position.DOCUMENT_BEFORE, Position.DOCUMENT_AFTER, position);
this.position = position;
}
/**
* Context for all other positions
*
* @param position the current position
* @param document document object
* @param operation the current path operation
*/
public Context(Position position, Document document, PathOperation operation) {
super(document);
Validate.inclusiveBetween(Position.OPERATION_BEFORE, Position.OPERATION_SECURITY_AFTER, position);
Validate.notNull(operation);
this.position = position;
this.operation = operation;
}
public Position getPosition() {
return position;
}
public Optional<PathOperation> getOperation() {
return Optional.ofNullable(operation);
}
}
}

View File

@@ -0,0 +1,94 @@
/*
* Copyright 2017 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.swagger2markup.extension;
import io.swagger.models.auth.SecuritySchemeDefinition;
import org.apache.commons.lang3.Validate;
import org.asciidoctor.ast.Document;
import java.util.Optional;
/**
* SecurityContentExtension extension point can be used to extend the security document content.
*/
public abstract class SecurityDocumentExtension extends AbstractExtension {
public abstract void apply(Context context);
public enum Position {
DOCUMENT_BEFORE,
DOCUMENT_BEGIN,
DOCUMENT_END,
DOCUMENT_AFTER,
SECURITY_SCHEME_BEFORE,
SECURITY_SCHEME_BEGIN,
SECURITY_SCHEME_END,
SECURITY_SCHEME_AFTER
}
public static class Context extends ContentContext {
private Position position;
/**
* null if position == DOCUMENT_*
*/
private String securitySchemeName;
/**
* null if position == DOCUMENT_*
*/
private SecuritySchemeDefinition securityScheme;
/**
* @param position the current position
* @param document the MarkupDocBuilder
*/
public Context(Position position, Document document) {
super(document);
Validate.inclusiveBetween(Position.DOCUMENT_BEFORE, Position.DOCUMENT_AFTER, position);
this.position = position;
}
/**
* @param position the current position
* @param document the MarkupDocBuilder
* @param securitySchemeName the name of the current securityScheme
* @param securityScheme the current security scheme securityScheme
*/
public Context(Position position, Document document, String securitySchemeName, SecuritySchemeDefinition securityScheme) {
super(document);
Validate.inclusiveBetween(Position.SECURITY_SCHEME_BEFORE, Position.SECURITY_SCHEME_AFTER, position);
Validate.notNull(securitySchemeName);
Validate.notNull(securityScheme);
this.position = position;
this.securitySchemeName = securitySchemeName;
this.securityScheme = securityScheme;
}
public Position getPosition() {
return position;
}
public Optional<String> getSecuritySchemeName() {
return Optional.ofNullable(securitySchemeName);
}
public Optional<SecuritySchemeDefinition> getSecurityScheme() {
return Optional.ofNullable(securityScheme);
}
}
}

View File

@@ -0,0 +1,127 @@
/*
* Copyright 2017 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.swagger2markup.extension.builder;
import io.github.swagger2markup.extension.*;
import java.util.List;
import static java.util.ServiceLoader.load;
import static org.apache.commons.collections4.IteratorUtils.toList;
public class OpenAPI2MarkupExtensionRegistryBuilder {
private final Context context;
public OpenAPI2MarkupExtensionRegistryBuilder() {
List<OpenAPIModelExtension> openAPIModelExtensions = toList(load(OpenAPIModelExtension.class).iterator());
List<OverviewDocumentExtension> overviewDocumentExtensions = toList(load(OverviewDocumentExtension.class).iterator());
List<DefinitionsDocumentExtension> definitionsDocumentExtensions = toList(load(DefinitionsDocumentExtension.class).iterator());
List<PathsDocumentExtension> pathsDocumentExtensions = toList(load(PathsDocumentExtension.class).iterator());
List<SecurityDocumentExtension> securityDocumentExtensions = toList(load(SecurityDocumentExtension.class).iterator());
context = new Context(
openAPIModelExtensions,
overviewDocumentExtensions,
definitionsDocumentExtensions,
pathsDocumentExtensions,
securityDocumentExtensions);
}
public OpenAPI2MarkupExtensionRegistry build() {
return new DefaultOpenAPI2MarkupExtensionRegistry(context);
}
public OpenAPI2MarkupExtensionRegistryBuilder withSwaggerModelExtension(OpenAPIModelExtension extension) {
context.openAPIModelExtensions.add(extension);
return this;
}
public OpenAPI2MarkupExtensionRegistryBuilder withOverviewDocumentExtension(OverviewDocumentExtension extension) {
context.overviewDocumentExtensions.add(extension);
return this;
}
public OpenAPI2MarkupExtensionRegistryBuilder withDefinitionsDocumentExtension(DefinitionsDocumentExtension extension) {
context.definitionsDocumentExtensions.add(extension);
return this;
}
public OpenAPI2MarkupExtensionRegistryBuilder withPathsDocumentExtension(PathsDocumentExtension extension) {
context.pathsDocumentExtensions.add(extension);
return this;
}
public OpenAPI2MarkupExtensionRegistryBuilder withSecurityDocumentExtension(SecurityDocumentExtension extension) {
context.securityDocumentExtensions.add(extension);
return this;
}
static class DefaultOpenAPI2MarkupExtensionRegistry implements OpenAPI2MarkupExtensionRegistry {
private Context context;
DefaultOpenAPI2MarkupExtensionRegistry(Context context) {
this.context = context;
}
@Override
public List<OpenAPIModelExtension> getSwaggerModelExtensions() {
return context.openAPIModelExtensions;
}
@Override
public List<OverviewDocumentExtension> getOverviewDocumentExtensions() {
return context.overviewDocumentExtensions;
}
@Override
public List<DefinitionsDocumentExtension> getDefinitionsDocumentExtensions() {
return context.definitionsDocumentExtensions;
}
@Override
public List<SecurityDocumentExtension> getSecurityDocumentExtensions() {
return context.securityDocumentExtensions;
}
@Override
public List<PathsDocumentExtension> getPathsDocumentExtensions() {
return context.pathsDocumentExtensions;
}
}
private static class Context {
final List<OpenAPIModelExtension> openAPIModelExtensions;
final List<OverviewDocumentExtension> overviewDocumentExtensions;
final List<DefinitionsDocumentExtension> definitionsDocumentExtensions;
final List<PathsDocumentExtension> pathsDocumentExtensions;
final List<SecurityDocumentExtension> securityDocumentExtensions;
Context(List<OpenAPIModelExtension> openAPIModelExtensions,
List<OverviewDocumentExtension> overviewDocumentExtensions,
List<DefinitionsDocumentExtension> definitionsDocumentExtensions,
List<PathsDocumentExtension> pathsDocumentExtensions,
List<SecurityDocumentExtension> securityDocumentExtensions) {
this.openAPIModelExtensions = openAPIModelExtensions;
this.overviewDocumentExtensions = overviewDocumentExtensions;
this.definitionsDocumentExtensions = definitionsDocumentExtensions;
this.pathsDocumentExtensions = pathsDocumentExtensions;
this.securityDocumentExtensions = securityDocumentExtensions;
}
}
}

View File

@@ -0,0 +1,101 @@
/*
* Copyright 2017 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.swagger2markup.internal.component;
import io.github.swagger2markup.OpenAPI2MarkupConverter;
import io.github.swagger2markup.adoc.ast.impl.DescriptionListEntryImpl;
import io.github.swagger2markup.adoc.ast.impl.DescriptionListImpl;
import io.github.swagger2markup.adoc.ast.impl.ListItemImpl;
import io.github.swagger2markup.adoc.ast.impl.ParagraphBlockImpl;
import io.github.swagger2markup.extension.MarkupComponent;
import io.swagger.v3.oas.models.media.Encoding;
import org.apache.commons.lang3.StringUtils;
import org.asciidoctor.ast.StructuralNode;
import java.util.Collections;
import java.util.Map;
import static io.github.swagger2markup.adoc.converter.internal.Delimiters.LINE_SEPARATOR;
import static io.github.swagger2markup.config.OpenAPILabels.LABEL_EXAMPLES;
import static io.github.swagger2markup.internal.helper.OpenApiHelpers.italicUnconstrained;
public class EncodingComponent extends MarkupComponent<StructuralNode, EncodingComponent.Parameters, StructuralNode> {
private final HeadersComponent headersComponent;
public EncodingComponent(OpenAPI2MarkupConverter.OpenAPIContext context) {
super(context);
this.headersComponent = new HeadersComponent(context);
}
public static EncodingComponent.Parameters parameters(Map<String, Encoding> encodings) {
return new EncodingComponent.Parameters(encodings);
}
public StructuralNode apply(StructuralNode node, Map<String, Encoding> encodings) {
return apply(node, parameters(encodings));
}
@Override
public StructuralNode apply(StructuralNode node, EncodingComponent.Parameters parameters) {
Map<String, Encoding> encodings = parameters.encodings;
if (encodings == null || encodings.isEmpty()) return node;
DescriptionListImpl encodingList = new DescriptionListImpl(node);
encodingList.setTitle(labels.getLabel(LABEL_EXAMPLES));
encodings.forEach((name, encoding) -> {
DescriptionListEntryImpl encodingEntry = new DescriptionListEntryImpl(encodingList, Collections.singletonList(new ListItemImpl(encodingList, name)));
ListItemImpl tagDesc = new ListItemImpl(encodingEntry, "");
ParagraphBlockImpl encodingBlock = new ParagraphBlockImpl(tagDesc);
StringBuilder sb = new StringBuilder();
String contentType = encoding.getContentType();
if(StringUtils.isNotBlank(contentType)){
sb.append("Content-Type:").append(contentType).append(LINE_SEPARATOR);
}
if(encoding.getAllowReserved()){
sb.append(italicUnconstrained("Allow Reserved").toLowerCase()).append(LINE_SEPARATOR);
}
if(encoding.getExplode()){
sb.append(italicUnconstrained("Explode").toLowerCase()).append(LINE_SEPARATOR);
}
Encoding.StyleEnum style = encoding.getStyle();
if(style != null){
sb.append("style").append(style).append(LINE_SEPARATOR);
}
encodingBlock.setSource(sb.toString());
tagDesc.append(encodingBlock);
headersComponent.apply(tagDesc, encoding.getHeaders());
encodingEntry.setDescription(tagDesc);
encodingList.addEntry(encodingEntry);
});
node.append(encodingList);
return node;
}
public static class Parameters {
private final Map<String, Encoding> encodings;
public Parameters(Map<String, Encoding> encodings) {
this.encodings = encodings;
}
}
}

View File

@@ -0,0 +1,108 @@
/*
* Copyright 2017 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.swagger2markup.internal.component;
import io.github.swagger2markup.OpenAPI2MarkupConverter;
import io.github.swagger2markup.adoc.ast.impl.DescriptionListEntryImpl;
import io.github.swagger2markup.adoc.ast.impl.DescriptionListImpl;
import io.github.swagger2markup.adoc.ast.impl.ListItemImpl;
import io.github.swagger2markup.adoc.ast.impl.ParagraphBlockImpl;
import io.github.swagger2markup.extension.MarkupComponent;
import io.swagger.v3.oas.models.examples.Example;
import org.apache.commons.lang3.StringUtils;
import org.asciidoctor.ast.StructuralNode;
import java.util.Collections;
import java.util.Map;
import static io.github.swagger2markup.adoc.converter.internal.Delimiters.LINE_SEPARATOR;
import static io.github.swagger2markup.config.OpenAPILabels.LABEL_EXAMPLES;
import static io.github.swagger2markup.config.OpenAPILabels.LABEL_EXTERNAL_VALUE;
import static io.github.swagger2markup.internal.helper.OpenApiHelpers.appendDescription;
public class ExamplesComponent extends MarkupComponent<StructuralNode, ExamplesComponent.Parameters, StructuralNode> {
private final MediaTypeExampleComponent mediaTypeExampleComponent;
public ExamplesComponent(OpenAPI2MarkupConverter.OpenAPIContext context) {
super(context);
this.mediaTypeExampleComponent = new MediaTypeExampleComponent(context);
}
public static ExamplesComponent.Parameters parameters(Map<String, Example> examples) {
return new ExamplesComponent.Parameters(examples);
}
public StructuralNode apply(StructuralNode node, Map<String, Example> examples) {
return apply(node, parameters(examples));
}
@Override
public StructuralNode apply(StructuralNode node, ExamplesComponent.Parameters parameters) {
Map<String, Example> examples = parameters.examples;
if (examples == null || examples.isEmpty()) return node;
DescriptionListImpl examplesList = new DescriptionListImpl(node);
examplesList.setTitle(labels.getLabel(LABEL_EXAMPLES));
examples.forEach((name, example) -> {
DescriptionListEntryImpl exampleEntry = new DescriptionListEntryImpl(examplesList, Collections.singletonList(new ListItemImpl(examplesList, name)));
ListItemImpl tagDesc = new ListItemImpl(exampleEntry, "");
ParagraphBlockImpl exampleBlock = new ParagraphBlockImpl(tagDesc);
appendDescription(exampleBlock, example.getSummary());
appendDescription(exampleBlock, example.getDescription());
mediaTypeExampleComponent.apply(tagDesc, example.getValue());
ParagraphBlockImpl paragraphBlock = new ParagraphBlockImpl(tagDesc);
String source = "";
generateRefLink(source, example.getExternalValue(), labels.getLabel(LABEL_EXTERNAL_VALUE));
generateRefLink(source, example.get$ref(), "");
if(StringUtils.isNotBlank(source)){
paragraphBlock.setSource(source);
tagDesc.append(paragraphBlock);
}
exampleEntry.setDescription(tagDesc);
examplesList.addEntry(exampleEntry);
});
node.append(examplesList);
return node;
}
private String generateRefLink(String source, String ref, String alt) {
if (StringUtils.isNotBlank(ref)) {
if (StringUtils.isBlank(alt)) {
alt = ref.substring(ref.lastIndexOf('/') + 1);
}
String anchor = ref.replaceFirst("#", "").replaceAll("/", "_");
source += "<<" + anchor + "," + alt + ">>" + LINE_SEPARATOR;
}
return source;
}
public static class Parameters {
private final Map<String, Example> examples;
public Parameters(Map<String, Example> examples) {
this.examples = examples;
}
}
}

View File

@@ -0,0 +1,64 @@
/*
* Copyright 2017 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.swagger2markup.internal.component;
import io.github.swagger2markup.OpenAPI2MarkupConverter;
import io.github.swagger2markup.extension.MarkupComponent;
import io.github.swagger2markup.adoc.ast.impl.ParagraphBlockImpl;
import io.swagger.v3.oas.models.ExternalDocumentation;
import org.apache.commons.lang3.StringUtils;
import org.asciidoctor.ast.Block;
import org.asciidoctor.ast.StructuralNode;
public class ExternalDocumentationComponent extends MarkupComponent<StructuralNode, ExternalDocumentationComponent.Parameters, StructuralNode> {
public ExternalDocumentationComponent(OpenAPI2MarkupConverter.OpenAPIContext context) {
super(context);
}
public static Parameters parameters(ExternalDocumentation externalDocs) {
return new Parameters(externalDocs);
}
public StructuralNode apply(StructuralNode node, ExternalDocumentation externalDocs) {
return apply(node, parameters(externalDocs));
}
@Override
public StructuralNode apply(StructuralNode node, Parameters params) {
ExternalDocumentation externalDocs = params.externalDocs;
if (externalDocs == null) return node;
String url = externalDocs.getUrl();
if (StringUtils.isNotBlank(url)) {
Block paragraph = new ParagraphBlockImpl(node);
String desc = externalDocs.getDescription();
paragraph.setSource(url + (StringUtils.isNotBlank(desc) ? "[" + desc + "]" : ""));
node.append(paragraph);
}
return node;
}
public static class Parameters {
private final ExternalDocumentation externalDocs;
public Parameters(ExternalDocumentation externalDocs) {
this.externalDocs = externalDocs;
}
}
}

View File

@@ -0,0 +1,79 @@
/*
* Copyright 2017 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.swagger2markup.internal.component;
import io.github.swagger2markup.OpenAPI2MarkupConverter;
import io.github.swagger2markup.adoc.ast.impl.TableImpl;
import io.github.swagger2markup.extension.MarkupComponent;
import io.swagger.v3.oas.models.headers.Header;
import org.asciidoctor.ast.StructuralNode;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import static io.github.swagger2markup.config.OpenAPILabels.*;
import static io.github.swagger2markup.internal.helper.OpenApiHelpers.generateInnerDoc;
import static io.github.swagger2markup.internal.helper.OpenApiHelpers.getSchemaTypeAsString;
public class HeadersComponent extends MarkupComponent<StructuralNode, HeadersComponent.Parameters, StructuralNode> {
private final SchemaComponent schemaComponent;
public HeadersComponent(OpenAPI2MarkupConverter.OpenAPIContext context) {
super(context);
this.schemaComponent = new SchemaComponent(context);
}
public static HeadersComponent.Parameters parameters(Map<String, Header> headers) {
return new HeadersComponent.Parameters(headers);
}
public StructuralNode apply(StructuralNode node, Map<String, Header> headers) {
return apply(node, parameters(headers));
}
@Override
public StructuralNode apply(StructuralNode node, HeadersComponent.Parameters parameters) {
Map<String, Header> headers = parameters.headers;
if (null == headers || headers.isEmpty()) return node;
TableImpl responseHeadersTable = new TableImpl(node, new HashMap<>(), new ArrayList<>());
responseHeadersTable.setOption("header");
responseHeadersTable.setAttribute("caption", "", true);
responseHeadersTable.setAttribute("cols", ".^2a,.^14a,.^4a", true);
responseHeadersTable.setTitle(labels.getLabel(TABLE_TITLE_HEADERS));
responseHeadersTable.setHeaderRow(labels.getLabel(TABLE_HEADER_NAME), labels.getLabel(TABLE_HEADER_DESCRIPTION), labels.getLabel(TABLE_HEADER_SCHEMA));
headers.forEach((name, header) ->
responseHeadersTable.addRow(
generateInnerDoc(responseHeadersTable, name),
generateInnerDoc(responseHeadersTable, Optional.ofNullable(header.getDescription()).orElse("")),
generateInnerDoc(responseHeadersTable, getSchemaTypeAsString(header.getSchema()))
));
node.append(responseHeadersTable);
return node;
}
public static class Parameters {
private final Map<String, Header> headers;
public Parameters(Map<String, Header> headers) {
this.headers = headers;
}
}
}

View File

@@ -0,0 +1,82 @@
/*
* Copyright 2017 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.swagger2markup.internal.component;
import io.github.swagger2markup.OpenAPI2MarkupConverter;
import io.github.swagger2markup.adoc.ast.impl.DocumentImpl;
import io.github.swagger2markup.adoc.ast.impl.ParagraphBlockImpl;
import io.github.swagger2markup.extension.MarkupComponent;
import io.swagger.v3.oas.models.links.Link;
import org.asciidoctor.ast.Document;
import org.asciidoctor.ast.StructuralNode;
import java.util.Map;
import static io.github.swagger2markup.adoc.converter.internal.Delimiters.LINE_SEPARATOR;
import static io.github.swagger2markup.config.OpenAPILabels.*;
import static io.github.swagger2markup.internal.helper.OpenApiHelpers.italicUnconstrained;
public class LinkComponent extends MarkupComponent<StructuralNode, LinkComponent.Parameters, StructuralNode> {
public LinkComponent(OpenAPI2MarkupConverter.OpenAPIContext context) {
super(context);
}
public static LinkComponent.Parameters parameters(Map<String, Link> links) {
return new LinkComponent.Parameters(links);
}
public Document apply(StructuralNode parent, Map<String, Link> links) {
return apply(parent, parameters(links));
}
@Override
public Document apply(StructuralNode parent, LinkComponent.Parameters parameters) {
DocumentImpl linksDocument = new DocumentImpl(parent);
ParagraphBlockImpl linkParagraph = new ParagraphBlockImpl(linksDocument);
Map<String, Link> links = parameters.links;
if (null == links || links.isEmpty()) {
linkParagraph.setSource(labels.getLabel(LABEL_NO_LINKS));
} else {
StringBuilder sb = new StringBuilder();
links.forEach((name, link) -> {
sb.append(name).append(" +").append(LINE_SEPARATOR);
sb.append(italicUnconstrained(labels.getLabel(LABEL_OPERATION))).append(' ')
.append(italicUnconstrained(link.getOperationId())).append(" +").append(LINE_SEPARATOR);
Map<String, String> linkParameters = link.getParameters();
if (null != linkParameters && !linkParameters.isEmpty()) {
sb.append(italicUnconstrained(labels.getLabel(LABEL_PARAMETERS))).append(" {").append(" +").append(LINE_SEPARATOR);
linkParameters.forEach((param, value) ->
sb.append('"').append(param).append("\": \"").append(value).append('"').append(" +").append(LINE_SEPARATOR)
);
sb.append('}').append(" +").append(LINE_SEPARATOR);
}
});
linkParagraph.setSource(sb.toString());
}
linksDocument.append(linkParagraph);
return linksDocument;
}
public static class Parameters {
private final Map<String, Link> links;
public Parameters(Map<String, Link> links) {
this.links = links;
}
}
}

View File

@@ -0,0 +1,87 @@
/*
* Copyright 2017 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.swagger2markup.internal.component;
import io.github.swagger2markup.OpenAPI2MarkupConverter;
import io.github.swagger2markup.adoc.ast.impl.DescriptionListEntryImpl;
import io.github.swagger2markup.adoc.ast.impl.DescriptionListImpl;
import io.github.swagger2markup.adoc.ast.impl.ListItemImpl;
import io.github.swagger2markup.extension.MarkupComponent;
import io.swagger.v3.oas.models.media.Content;
import org.asciidoctor.ast.Document;
import org.asciidoctor.ast.StructuralNode;
import java.util.Collections;
import static io.github.swagger2markup.config.OpenAPILabels.LABEL_CONTENT;
public class MediaContentComponent extends MarkupComponent<StructuralNode, MediaContentComponent.Parameters, StructuralNode> {
private final MediaTypeExampleComponent mediaTypeExampleComponent;
private final ExamplesComponent examplesComponent;
private final SchemaComponent schemaComponent;
private final EncodingComponent encodingComponent;
public MediaContentComponent(OpenAPI2MarkupConverter.OpenAPIContext context) {
super(context);
this.mediaTypeExampleComponent = new MediaTypeExampleComponent(context);
this.examplesComponent = new ExamplesComponent(context);
this.schemaComponent = new SchemaComponent(context);
this.encodingComponent = new EncodingComponent(context);
}
public static MediaContentComponent.Parameters parameters(Content content) {
return new MediaContentComponent.Parameters(content);
}
public StructuralNode apply(StructuralNode node, Content content) {
return apply(node, parameters(content));
}
@Override
public StructuralNode apply(StructuralNode node, MediaContentComponent.Parameters parameters) {
Content content = parameters.content;
if (content == null || content.isEmpty()) return node;
DescriptionListImpl mediaContentList = new DescriptionListImpl(node);
mediaContentList.setTitle(labels.getLabel(LABEL_CONTENT));
content.forEach((type, mediaType) -> {
DescriptionListEntryImpl tagEntry = new DescriptionListEntryImpl(mediaContentList, Collections.singletonList(new ListItemImpl(mediaContentList, type)));
ListItemImpl tagDesc = new ListItemImpl(tagEntry, "");
Document tagDescDocument = schemaComponent.apply(mediaContentList, mediaType.getSchema());
mediaTypeExampleComponent.apply(tagDescDocument, mediaType.getExample());
examplesComponent.apply(tagDescDocument, mediaType.getExamples());
encodingComponent.apply(tagDescDocument, mediaType.getEncoding());
tagDesc.append(tagDescDocument);
tagEntry.setDescription(tagDesc);
mediaContentList.addEntry(tagEntry);
});
node.append(mediaContentList);
return node;
}
public static class Parameters {
private final Content content;
public Parameters(Content content) {
this.content = content;
}
}
}

View File

@@ -0,0 +1,64 @@
/*
* Copyright 2017 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.swagger2markup.internal.component;
import io.github.swagger2markup.OpenAPI2MarkupConverter;
import io.github.swagger2markup.adoc.ast.impl.ParagraphBlockImpl;
import io.github.swagger2markup.extension.MarkupComponent;
import org.apache.commons.lang3.StringUtils;
import org.asciidoctor.ast.StructuralNode;
import static io.github.swagger2markup.adoc.converter.internal.Delimiters.DELIMITER_BLOCK;
import static io.github.swagger2markup.adoc.converter.internal.Delimiters.LINE_SEPARATOR;
import static io.github.swagger2markup.config.OpenAPILabels.LABEL_EXAMPLE;
public class MediaTypeExampleComponent extends MarkupComponent<StructuralNode, MediaTypeExampleComponent.Parameters, StructuralNode> {
public MediaTypeExampleComponent(OpenAPI2MarkupConverter.OpenAPIContext context) {
super(context);
}
public static MediaTypeExampleComponent.Parameters parameters(Object example) {
return new MediaTypeExampleComponent.Parameters(example);
}
public StructuralNode apply(StructuralNode node, Object example) {
return apply(node, parameters(example));
}
@Override
public StructuralNode apply(StructuralNode node, MediaTypeExampleComponent.Parameters parameters) {
Object example = parameters.example;
if (example == null || StringUtils.isBlank(example.toString())) return node;
ParagraphBlockImpl sourceBlock = new ParagraphBlockImpl(node);
sourceBlock.setTitle(labels.getLabel(LABEL_EXAMPLE));
sourceBlock.setAttribute("style", "source", true);
sourceBlock.setSource(DELIMITER_BLOCK + LINE_SEPARATOR + example + LINE_SEPARATOR + DELIMITER_BLOCK);
node.append(sourceBlock);
return node;
}
public static class Parameters {
private final Object example;
public Parameters(Object example) {
this.example = example;
}
}
}

View File

@@ -0,0 +1,103 @@
/*
* Copyright 2017 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.swagger2markup.internal.component;
import io.github.swagger2markup.OpenAPI2MarkupConverter;
import io.github.swagger2markup.adoc.ast.impl.TableImpl;
import io.github.swagger2markup.extension.MarkupComponent;
import io.swagger.v3.oas.models.parameters.Parameter;
import org.asciidoctor.ast.Document;
import org.asciidoctor.ast.StructuralNode;
import org.asciidoctor.ast.Table;
import java.util.*;
import java.util.stream.Collectors;
import static io.github.swagger2markup.adoc.converter.internal.Delimiters.LINE_SEPARATOR;
import static io.github.swagger2markup.config.OpenAPILabels.*;
import static io.github.swagger2markup.internal.helper.OpenApiHelpers.*;
public class ParametersComponent extends MarkupComponent<StructuralNode, ParametersComponent.Parameters, StructuralNode> {
private final SchemaComponent schemaComponent;
public ParametersComponent(OpenAPI2MarkupConverter.OpenAPIContext context) {
super(context);
this.schemaComponent = new SchemaComponent(context);
}
public static ParametersComponent.Parameters parameters(Map<String, Parameter> parameters) {
return new ParametersComponent.Parameters(parameters);
}
public static ParametersComponent.Parameters parameters(List<Parameter> parameters) {
if(null == parameters) {
return new ParametersComponent.Parameters(new HashMap<>());
}
return new ParametersComponent.Parameters(parameters.stream().collect(Collectors.toMap(Parameter::getName, parameter -> parameter)));
}
public StructuralNode apply(StructuralNode parent, List<Parameter> params) {
return apply(parent, parameters(params));
}
public StructuralNode apply(StructuralNode parent, Map<String, Parameter> params) {
return apply(parent, parameters(params));
}
@Override
public StructuralNode apply(StructuralNode parent, ParametersComponent.Parameters componentParameters) {
Map<String, Parameter> parameters = componentParameters.parameters;
if (null == parameters || parameters.isEmpty()) return parent;
TableImpl pathParametersTable = new TableImpl(parent, new HashMap<>(), new ArrayList<>());
pathParametersTable.setOption("header");
pathParametersTable.setAttribute("caption", "", true);
pathParametersTable.setAttribute("cols", ".^2a,.^3a,.^10a,.^5a", true);
pathParametersTable.setTitle(labels.getLabel(TABLE_TITLE_PARAMETERS));
pathParametersTable.setHeaderRow(
labels.getLabel(TABLE_HEADER_TYPE),
labels.getLabel(TABLE_HEADER_NAME),
labels.getLabel(TABLE_HEADER_DESCRIPTION),
labels.getLabel(TABLE_HEADER_SCHEMA));
parameters.forEach((alt, parameter) ->
pathParametersTable.addRow(
generateInnerDoc(pathParametersTable, boldUnconstrained(parameter.getIn()), alt),
getParameterNameDocument(pathParametersTable, parameter),
generateInnerDoc(pathParametersTable, Optional.ofNullable(parameter.getDescription()).orElse("")),
generateInnerDoc(pathParametersTable, getSchemaTypeAsString(parameter.getSchema()))
));
parent.append(pathParametersTable);
return parent;
}
private Document getParameterNameDocument(Table table, Parameter parameter) {
String documentContent = boldUnconstrained(parameter.getName()) + " +" + LINE_SEPARATOR + requiredIndicator(parameter.getRequired(),
labels.getLabel(LABEL_REQUIRED), labels.getLabel(LABEL_OPTIONAL));
return generateInnerDoc(table, documentContent);
}
public static class Parameters {
private final Map<String, Parameter> parameters;
public Parameters(Map<String, Parameter> parameters) {
this.parameters = parameters;
}
}
}

View File

@@ -0,0 +1,89 @@
/*
* Copyright 2017 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.swagger2markup.internal.component;
import io.github.swagger2markup.OpenAPI2MarkupConverter;
import io.github.swagger2markup.adoc.ast.impl.TableImpl;
import io.github.swagger2markup.extension.MarkupComponent;
import io.swagger.v3.oas.models.media.Schema;
import org.asciidoctor.ast.StructuralNode;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static io.github.swagger2markup.adoc.converter.internal.Delimiters.LINE_SEPARATOR;
import static io.github.swagger2markup.config.OpenAPILabels.*;
import static io.github.swagger2markup.internal.helper.OpenApiHelpers.*;
public class PropertiesTableComponent extends MarkupComponent<StructuralNode, PropertiesTableComponent.Parameters, StructuralNode> {
private final SchemaComponent schemaComponent;
PropertiesTableComponent(OpenAPI2MarkupConverter.OpenAPIContext context) {
super(context);
this.schemaComponent = new SchemaComponent(context);
}
public static Parameters parameters(@SuppressWarnings("rawtypes") Map<String, Schema> properties, List<String> schemaRequired) {
return new Parameters(properties, schemaRequired);
}
public StructuralNode apply(StructuralNode parent, @SuppressWarnings("rawtypes") Map<String, Schema> properties, List<String> schemaRequired) {
return apply(parent, parameters(properties, schemaRequired));
}
public StructuralNode apply(StructuralNode parent, Parameters params) {
@SuppressWarnings("rawtypes") Map<String, Schema> properties = params.properties;
List<String> schemaRequired = params.schemaRequired;
if (null == properties || properties.isEmpty()) return parent;
List<String> finalSchemaRequired = (null == schemaRequired) ? new ArrayList<>() : schemaRequired;
TableImpl propertiesTable = new TableImpl(parent, new HashMap<>(), new ArrayList<>());
propertiesTable.setOption("header");
propertiesTable.setAttribute("caption", "", true);
propertiesTable.setAttribute("cols", ".^4a,.^16a,.^4a", true);
propertiesTable.setTitle(labels.getLabel(TABLE_TITLE_PROPERTIES));
propertiesTable.setHeaderRow(
labels.getLabel(TABLE_HEADER_NAME),
labels.getLabel(TABLE_HEADER_DESCRIPTION),
labels.getLabel(TABLE_HEADER_SCHEMA));
properties.forEach((name, schema) -> propertiesTable.addRow(
generateInnerDoc(propertiesTable, name + LINE_SEPARATOR + requiredIndicator(finalSchemaRequired.contains(name),
labels.getLabel(LABEL_REQUIRED), labels.getLabel(LABEL_OPTIONAL))),
schemaComponent.apply(propertiesTable, schema),
generateInnerDoc(propertiesTable, getSchemaTypeAsString(schema))
));
parent.append(propertiesTable);
return parent;
}
@SuppressWarnings("rawtypes")
public static class Parameters {
private final Map<String, Schema> properties;
private final List<String> schemaRequired;
public Parameters(Map<String, Schema> properties, List<String> schemaRequired) {
this.properties = properties;
this.schemaRequired = schemaRequired;
}
}
}

View File

@@ -0,0 +1,96 @@
/*
* Copyright 2017 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.swagger2markup.internal.component;
import io.github.swagger2markup.OpenAPI2MarkupConverter;
import io.github.swagger2markup.adoc.ast.impl.TableImpl;
import io.github.swagger2markup.extension.MarkupComponent;
import io.swagger.v3.oas.models.responses.ApiResponse;
import org.asciidoctor.ast.Document;
import org.asciidoctor.ast.StructuralNode;
import org.asciidoctor.ast.Table;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import static io.github.swagger2markup.config.OpenAPILabels.*;
import static io.github.swagger2markup.internal.helper.OpenApiHelpers.generateInnerDoc;
public class ResponseComponent extends MarkupComponent<StructuralNode, ResponseComponent.Parameters, StructuralNode> {
private final HeadersComponent headersComponent;
private final LinkComponent linkComponent;
private final MediaContentComponent mediaContentComponent;
public ResponseComponent(OpenAPI2MarkupConverter.OpenAPIContext context) {
super(context);
this.headersComponent = new HeadersComponent(context);
this.linkComponent = new LinkComponent(context);
this.mediaContentComponent = new MediaContentComponent(context);
}
public static Parameters parameters(Map<String, ApiResponse> apiResponses) {
return new Parameters(apiResponses);
}
public StructuralNode apply(StructuralNode serverSection, Map<String, ApiResponse> apiResponses) {
return apply(serverSection, parameters(apiResponses));
}
@Override
public StructuralNode apply(StructuralNode serverSection, Parameters params) {
Map<String, ApiResponse> apiResponses = params.apiResponses;
if (null == apiResponses || apiResponses.isEmpty()) return serverSection;
TableImpl pathResponsesTable = new TableImpl(serverSection, new HashMap<>(), new ArrayList<>());
pathResponsesTable.setOption("header");
pathResponsesTable.setAttribute("caption", "", true);
pathResponsesTable.setAttribute("cols", ".^2a,.^14a,.^4a", true);
pathResponsesTable.setTitle(labels.getLabel(TABLE_TITLE_RESPONSES));
pathResponsesTable.setHeaderRow(
labels.getLabel(TABLE_HEADER_HTTP_CODE),
labels.getLabel(TABLE_HEADER_DESCRIPTION),
labels.getLabel(TABLE_HEADER_LINKS));
apiResponses.forEach((httpCode, apiResponse) ->
pathResponsesTable.addRow(
generateInnerDoc(pathResponsesTable, httpCode),
getResponseDescriptionColumnDocument(pathResponsesTable, apiResponse),
linkComponent.apply(pathResponsesTable, apiResponse.getLinks())
));
serverSection.append(pathResponsesTable);
return serverSection;
}
private Document getResponseDescriptionColumnDocument(Table table, ApiResponse apiResponse) {
Document document = generateInnerDoc(table, Optional.ofNullable(apiResponse.getDescription()).orElse(""));
headersComponent.apply(document, apiResponse.getHeaders());
mediaContentComponent.apply(document, apiResponse.getContent());
return document;
}
public static class Parameters {
private final Map<String, ApiResponse> apiResponses;
public Parameters(Map<String, ApiResponse> apiResponses) {
this.apiResponses = apiResponses;
}
}
}

View File

@@ -0,0 +1,118 @@
/*
* Copyright 2017 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.swagger2markup.internal.component;
import io.github.swagger2markup.OpenAPI2MarkupConverter;
import io.github.swagger2markup.adoc.ast.impl.DocumentImpl;
import io.github.swagger2markup.adoc.ast.impl.ParagraphBlockImpl;
import io.github.swagger2markup.extension.MarkupComponent;
import io.github.swagger2markup.internal.helper.OpenApiHelpers;
import io.swagger.v3.oas.models.media.Schema;
import org.apache.commons.lang3.StringUtils;
import org.asciidoctor.ast.Document;
import org.asciidoctor.ast.StructuralNode;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static io.github.swagger2markup.adoc.converter.internal.Delimiters.LINE_SEPARATOR;
import static io.github.swagger2markup.config.OpenAPILabels.*;
import static io.github.swagger2markup.internal.helper.OpenApiHelpers.boldUnconstrained;
public class SchemaComponent extends MarkupComponent<StructuralNode, SchemaComponent.Parameters, StructuralNode> {
private final OpenAPI2MarkupConverter.OpenAPIContext context;
public SchemaComponent(OpenAPI2MarkupConverter.OpenAPIContext context) {
super(context);
this.context = context;
}
public static SchemaComponent.Parameters parameters(@SuppressWarnings("rawtypes") Schema schema) {
return new SchemaComponent.Parameters(schema);
}
public Document apply(StructuralNode parent, @SuppressWarnings("rawtypes") Schema schema) {
return apply(parent, parameters(schema));
}
@SuppressWarnings({"unchecked", "rawtypes"})
@Override
public Document apply(StructuralNode parent, SchemaComponent.Parameters parameters) {
Document schemaDocument = new DocumentImpl(parent);
Schema schema = parameters.schema;
if (null == schema) return schemaDocument;
OpenApiHelpers.appendDescription(schemaDocument, schema.getDescription());
Map<String, Boolean> schemasBooleanProperties = new HashMap<String, Boolean>() {{
put(labels.getLabel(LABEL_DEPRECATED), schema.getDeprecated());
put(labels.getLabel(LABEL_NULLABLE), schema.getNullable());
put(labels.getLabel(LABEL_READ_ONLY), schema.getReadOnly());
put(labels.getLabel(LABEL_WRITE_ONLY), schema.getWriteOnly());
put(labels.getLabel(LABEL_UNIQUE_ITEMS), schema.getUniqueItems());
put(labels.getLabel(LABEL_EXCLUSIVE_MAXIMUM), schema.getExclusiveMaximum());
put(labels.getLabel(LABEL_EXCLUSIVE_MINIMUM), schema.getExclusiveMinimum());
}};
Map<String, Object> schemasValueProperties = new HashMap<String, Object>() {{
put(labels.getLabel(LABEL_TITLE), schema.getTitle());
put(labels.getLabel(LABEL_DEFAULT), schema.getDefault());
put(labels.getLabel(LABEL_MAXIMUM), schema.getMaximum());
put(labels.getLabel(LABEL_MINIMUM), schema.getMinimum());
put(labels.getLabel(LABEL_MAX_LENGTH), schema.getMaxLength());
put(labels.getLabel(LABEL_MIN_LENGTH), schema.getMinLength());
put(labels.getLabel(LABEL_MAX_ITEMS), schema.getMaxItems());
put(labels.getLabel(LABEL_MIN_ITEMS), schema.getMinItems());
put(labels.getLabel(LABEL_MAX_PROPERTIES), schema.getMaxProperties());
put(labels.getLabel(LABEL_MIN_PROPERTIES), schema.getMinProperties());
put(labels.getLabel(LABEL_MULTIPLE_OF), schema.getMultipleOf());
}};
Stream<String> schemaBooleanStream = schemasBooleanProperties.entrySet().stream()
.filter(e -> null != e.getValue() && e.getValue())
.map(e -> OpenApiHelpers.italicUnconstrained(e.getKey().toLowerCase()));
Stream<String> schemaValueStream = schemasValueProperties.entrySet().stream()
.filter(e -> null != e.getValue() && StringUtils.isNotBlank(e.getValue().toString()))
.map(e -> boldUnconstrained(e.getKey()) + ": " + e.getValue());
ParagraphBlockImpl paragraphBlock = new ParagraphBlockImpl(schemaDocument);
String source = Stream.concat(schemaBooleanStream, schemaValueStream).collect(Collectors.joining(" +" + LINE_SEPARATOR));
paragraphBlock.setSource(source);
schemaDocument.append(paragraphBlock);
Map<String, Schema> properties = schema.getProperties();
if (null != properties && !properties.isEmpty()) {
PropertiesTableComponent propertiesTableComponent = new PropertiesTableComponent(context);
propertiesTableComponent.apply(schemaDocument, properties, schema.getRequired());
}
return schemaDocument;
}
@SuppressWarnings("rawtypes")
public static class Parameters {
private final Schema schema;
public Parameters(Schema schema) {
this.schema = schema;
}
}
}

View File

@@ -0,0 +1,86 @@
/*
* Copyright 2017 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.swagger2markup.internal.component;
import io.github.swagger2markup.OpenAPI2MarkupConverter;
import io.github.swagger2markup.adoc.ast.impl.TableImpl;
import io.github.swagger2markup.extension.MarkupComponent;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import org.asciidoctor.ast.StructuralNode;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import static io.github.swagger2markup.config.OpenAPILabels.*;
import static io.github.swagger2markup.internal.helper.OpenApiHelpers.*;
public class SecurityRequirementTableComponent extends MarkupComponent<StructuralNode, SecurityRequirementTableComponent.Parameters, StructuralNode> {
public SecurityRequirementTableComponent(OpenAPI2MarkupConverter.OpenAPIContext context) {
super(context);
}
public static SecurityRequirementTableComponent.Parameters parameters(List<SecurityRequirement> securityRequirements, boolean addTitle) {
return new SecurityRequirementTableComponent.Parameters(securityRequirements, addTitle);
}
public StructuralNode apply(StructuralNode document, List<SecurityRequirement> securityRequirements, boolean addTitle) {
return apply(document, parameters(securityRequirements, addTitle));
}
@Override
public StructuralNode apply(StructuralNode node, SecurityRequirementTableComponent.Parameters parameters) {
List<SecurityRequirement> securityRequirements = parameters.securityRequirements;
if (securityRequirements == null || securityRequirements.isEmpty()) return node;
TableImpl securityRequirementsTable = new TableImpl(node, new HashMap<>(), new ArrayList<>());
securityRequirementsTable.setOption("header");
securityRequirementsTable.setAttribute("caption", "", true);
securityRequirementsTable.setAttribute("cols", ".^3a,.^4a,.^13a", true);
if (parameters.addTitle) {
securityRequirementsTable.setTitle(labels.getLabel(TABLE_TITLE_SECURITY));
}
securityRequirementsTable.setHeaderRow(
labels.getLabel(TABLE_HEADER_TYPE),
labels.getLabel(TABLE_HEADER_NAME),
labels.getLabel(TABLE_HEADER_SCOPES));
securityRequirements.forEach(securityRequirement ->
securityRequirement.forEach((name, scopes) ->
securityRequirementsTable.addRow(
generateInnerDoc(securityRequirementsTable, boldUnconstrained(scopes.isEmpty() ? "apiKey" : "oauth2")),
generateInnerDoc(securityRequirementsTable, name),
generateInnerDoc(securityRequirementsTable, String.join(", ", scopes))
)
)
);
node.append(securityRequirementsTable);
return node;
}
public static class Parameters {
private final List<SecurityRequirement> securityRequirements;
private final boolean addTitle;
public Parameters(List<SecurityRequirement> securityRequirements, boolean addTitle) {
this.securityRequirements = securityRequirements;
this.addTitle = addTitle;
}
}
}

View File

@@ -0,0 +1,86 @@
/*
* Copyright 2017 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.swagger2markup.internal.component;
import io.github.swagger2markup.OpenAPI2MarkupConverter;
import io.github.swagger2markup.adoc.ast.impl.DescriptionListEntryImpl;
import io.github.swagger2markup.adoc.ast.impl.DescriptionListImpl;
import io.github.swagger2markup.adoc.ast.impl.ListItemImpl;
import io.github.swagger2markup.adoc.ast.impl.SectionImpl;
import io.github.swagger2markup.extension.MarkupComponent;
import io.swagger.v3.oas.models.tags.Tag;
import org.apache.commons.lang3.StringUtils;
import org.asciidoctor.ast.Document;
import org.asciidoctor.ast.Section;
import java.util.Collections;
import java.util.List;
import static io.github.swagger2markup.config.OpenAPILabels.SECTION_TITLE_TAGS;
public class TagsComponent extends MarkupComponent<Document, TagsComponent.Parameters, Document> {
private final ExternalDocumentationComponent externalDocumentationComponent;
public TagsComponent(OpenAPI2MarkupConverter.OpenAPIContext context) {
super(context);
this.externalDocumentationComponent = new ExternalDocumentationComponent(context);
}
public static TagsComponent.Parameters parameters(List<Tag> tags) {
return new TagsComponent.Parameters(tags);
}
public Document apply(Document document, List<Tag> tags) {
return apply(document, parameters(tags));
}
@Override
public Document apply(Document document, TagsComponent.Parameters parameters) {
List<Tag> openAPITags = parameters.tags;
if (null == openAPITags || openAPITags.isEmpty()) return document;
Section tagsSection = new SectionImpl(document);
tagsSection.setTitle(labels.getLabel(SECTION_TITLE_TAGS));
DescriptionListImpl tagsList = new DescriptionListImpl(tagsSection);
openAPITags.forEach(tag -> {
DescriptionListEntryImpl tagEntry = new DescriptionListEntryImpl(tagsList, Collections.singletonList(new ListItemImpl(tagsList, tag.getName())));
String description = tag.getDescription();
if(StringUtils.isNotBlank(description)){
ListItemImpl tagDesc = new ListItemImpl(tagEntry, "");
tagDesc.setSource(description);
externalDocumentationComponent.apply(tagDesc, tag.getExternalDocs());
tagEntry.setDescription(tagDesc);
}
tagsList.addEntry(tagEntry);
});
tagsSection.append(tagsList);
document.append(tagsSection);
return document;
}
public static class Parameters {
private final List<Tag> tags;
public Parameters(List<Tag> tags) {
this.tags = tags;
}
}
}

View File

@@ -0,0 +1,122 @@
package io.github.swagger2markup.internal.document;
import io.github.swagger2markup.OpenAPI2MarkupConverter;
import io.github.swagger2markup.adoc.ast.impl.SectionImpl;
import io.github.swagger2markup.extension.MarkupComponent;
import io.github.swagger2markup.internal.component.*;
import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.headers.Header;
import io.swagger.v3.oas.models.links.Link;
import io.swagger.v3.oas.models.media.Schema;
import io.swagger.v3.oas.models.parameters.Parameter;
import io.swagger.v3.oas.models.responses.ApiResponse;
import org.apache.commons.lang3.Validate;
import org.asciidoctor.ast.Document;
import org.asciidoctor.ast.Section;
import org.asciidoctor.ast.StructuralNode;
import java.util.Map;
import static io.github.swagger2markup.config.OpenAPILabels.*;
public class ComponentsDocument extends MarkupComponent<Document, ComponentsDocument.Parameters, Document> {
private final ParametersComponent parametersComponent;
private final ResponseComponent responseComponent;
private final HeadersComponent headersComponent;
private final SchemaComponent schemaComponent;
private final LinkComponent linkComponent;
public ComponentsDocument(OpenAPI2MarkupConverter.OpenAPIContext context) {
super(context);
this.parametersComponent = new ParametersComponent(context);
this.responseComponent = new ResponseComponent(context);
this.headersComponent = new HeadersComponent(context);
this.schemaComponent = new SchemaComponent(context);
this.linkComponent = new LinkComponent(context);
}
public static Parameters parameters(Components components) {
return new Parameters(components);
}
@Override
public Document apply(Document document, ComponentsDocument.Parameters parameters) {
appendComponentsSection(document, parameters.components);
return document;
}
public static class Parameters {
private final Components components;
public Parameters(Components components) {
this.components = Validate.notNull(components, "Schema must not be null");
}
}
private void appendComponentsSection(Document document, Components components) {
if (null == components) return;
Section componentsSection = new SectionImpl(document);
componentsSection.setTitle(labels.getLabel(SECTION_TITLE_COMPONENTS));
String componentSectionId = "_components";
componentsSection.setId(componentSectionId);
appendComponentsSchemasSection(componentsSection, componentSectionId, components.getSchemas());
Map<String, Parameter> parameters = components.getParameters();
if (null != parameters && !parameters.isEmpty()) {
appendSubSection(componentsSection, componentSectionId, parametersComponent, SECTION_TITLE_PARAMETERS,
new ParametersComponent.Parameters(parameters));
}
Map<String, ApiResponse> responses = components.getResponses();
if (null != responses && !responses.isEmpty()) {
appendSubSection(componentsSection, componentSectionId, responseComponent, SECTION_TITLE_RESPONSES,
new ResponseComponent.Parameters(responses));
}
Map<String, Header> headers = components.getHeaders();
if (null != headers && !headers.isEmpty()) {
appendSubSection(componentsSection, componentSectionId, headersComponent, SECTION_TITLE_HEADERS,
new HeadersComponent.Parameters(headers));
}
Map<String, Link> links = components.getLinks();
if (null != links && !links.isEmpty()) {
appendSubSection(componentsSection, componentSectionId, linkComponent, SECTION_TITLE_LINKS,
new LinkComponent.Parameters(links));
}
document.append(componentsSection);
}
private void appendComponentsSchemasSection(
Section componentsSection, String componentSectionId,
@SuppressWarnings("rawtypes") Map<String, Schema> schemas) {
if (null == schemas || schemas.isEmpty()) return;
SectionImpl schemasSection = new SectionImpl(componentsSection);
String schemasSectionId = componentSectionId + "_schemas";
schemasSection.setTitle(labels.getLabel(SECTION_TITLE_SCHEMAS));
schemasSection.setId(schemasSectionId);
schemas.forEach((name, schema) -> {
String schemaDocumentId = schemasSectionId + "_" + name;
Document schemaDocument = schemaComponent.apply(schemasSection, schema);
schemaDocument.setTitle(name);
schemaDocument.setId(schemaDocumentId);
schemasSection.append(schemaDocument);
});
componentsSection.append(schemasSection);
}
private <T> void appendSubSection(Section componentsSection, String componentSectionId,
MarkupComponent<StructuralNode, T, StructuralNode> markupComponent,
String sectionLabel, T parameters) {
SectionImpl parametersSection = new SectionImpl(componentsSection);
String parametersSectionId = componentSectionId + "_parameters";
parametersSection.setTitle(labels.getLabel(sectionLabel));
parametersSection.setId(parametersSectionId);
markupComponent.apply(parametersSection, parameters);
componentsSection.append(parametersSection);
}
}

View File

@@ -0,0 +1,138 @@
package io.github.swagger2markup.internal.document;
import io.github.swagger2markup.OpenAPI2MarkupConverter;
import io.github.swagger2markup.adoc.ast.impl.BlockImpl;
import io.github.swagger2markup.adoc.ast.impl.DocumentImpl;
import io.github.swagger2markup.adoc.ast.impl.ParagraphBlockImpl;
import io.github.swagger2markup.adoc.ast.impl.SectionImpl;
import io.github.swagger2markup.extension.MarkupComponent;
import io.github.swagger2markup.extension.OverviewDocumentExtension;
import io.github.swagger2markup.internal.component.ExternalDocumentationComponent;
import io.github.swagger2markup.internal.component.TagsComponent;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate;
import org.asciidoctor.ast.Block;
import org.asciidoctor.ast.Document;
import org.asciidoctor.ast.Section;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Optional;
import static io.github.swagger2markup.config.OpenAPILabels.LABEL_TERMS_OF_SERVICE;
import static io.github.swagger2markup.config.OpenAPILabels.SECTION_TITLE_OVERVIEW;
import static io.github.swagger2markup.extension.OverviewDocumentExtension.Context;
import static io.github.swagger2markup.internal.helper.OpenApiHelpers.appendDescription;
public class OverviewDocument extends MarkupComponent<Document, OverviewDocument.Parameters, Document> {
private final TagsComponent tagsComponent;
private final ExternalDocumentationComponent externalDocumentationComponent;
public OverviewDocument(OpenAPI2MarkupConverter.OpenAPIContext context) {
super(context);
tagsComponent = new TagsComponent(context);
this.externalDocumentationComponent = new ExternalDocumentationComponent(context);
}
public static OverviewDocument.Parameters parameters(OpenAPI schema) {
return new OverviewDocument.Parameters(schema);
}
@Override
public Document apply(Document document, Parameters parameters) {
Info apiInfo = parameters.openAPI.getInfo();
document.setAttribute("openapi", parameters.openAPI.getOpenapi(), true);
addDocumentTitle(document, apiInfo);
addAuthorInfo(document, apiInfo);
addVersionInfo(document, apiInfo);
applyOverviewDocumentExtension(new Context(OverviewDocumentExtension.Position.DOCUMENT_BEFORE, document));
Document subDocument = new DocumentImpl(document);
Section overviewDoc = new SectionImpl(subDocument, "section", new HashMap<>(), new ArrayList<>(),
null, new ArrayList<>(), 1, "", new ArrayList<>(),
null, null, "", "", false, false);
applyOverviewDocumentExtension(new Context(OverviewDocumentExtension.Position.DOCUMENT_BEGIN, subDocument));
overviewDoc.setTitle(labels.getLabel(SECTION_TITLE_OVERVIEW));
appendDescription(overviewDoc, apiInfo.getDescription());
appendTermsOfServiceInfo(overviewDoc, apiInfo);
appendLicenseInfo(overviewDoc, apiInfo);
subDocument.append(overviewDoc);
applyOverviewDocumentExtension(new Context(OverviewDocumentExtension.Position.DOCUMENT_END, subDocument));
document.append(subDocument);
externalDocumentationComponent.apply(document, parameters.openAPI.getExternalDocs());
tagsComponent.apply(document, parameters.openAPI.getTags());
applyOverviewDocumentExtension(new Context(OverviewDocumentExtension.Position.DOCUMENT_AFTER, document));
return document;
}
private void applyOverviewDocumentExtension(Context context) {
extensionRegistry.getOverviewDocumentExtensions().forEach(extension -> extension.apply(context));
}
private void addDocumentTitle(Document rootDocument, Info apiInfo) {
String title = apiInfo.getTitle();
if (StringUtils.isNotBlank(title)) {
rootDocument.setTitle(title);
}
}
private void addVersionInfo(Document rootDocument, Info info) {
String version = info.getVersion();
if (StringUtils.isNotBlank(version)) {
rootDocument.setAttribute("revnumber", version, true);
}
}
private void addAuthorInfo(Document rootDocument, Info info) {
Contact contact = info.getContact();
if (null != contact) {
String author = Optional.ofNullable(contact.getName()).orElse("");
String email = contact.getEmail();
if (StringUtils.isNotBlank(email)) {
rootDocument.setAttribute("email", email, true);
}
rootDocument.setAttribute("author", author, true);
rootDocument.setAttribute("authorcount", 1L, true);
}
}
private void appendLicenseInfo(Section overviewDoc, Info info) {
License license = info.getLicense();
if (null != license) {
StringBuilder sb = new StringBuilder();
if (StringUtils.isNotBlank(license.getUrl())) {
sb.append(license.getUrl()).append("[");
}
sb.append(license.getName());
if (StringUtils.isNotBlank(license.getUrl())) {
sb.append("]");
}
BlockImpl paragraph = new ParagraphBlockImpl(overviewDoc);
paragraph.setSource(sb.toString());
overviewDoc.append(paragraph);
}
}
private void appendTermsOfServiceInfo(Section overviewDoc, Info info) {
String termsOfService = info.getTermsOfService();
if (StringUtils.isNotBlank(termsOfService)) {
Block paragraph = new ParagraphBlockImpl(overviewDoc);
paragraph.setSource(termsOfService + "[" + labels.getLabel(LABEL_TERMS_OF_SERVICE) + "]");
overviewDoc.append(paragraph);
}
}
public static class Parameters {
private final OpenAPI openAPI;
public Parameters(OpenAPI openAPI) {
this.openAPI = Validate.notNull(openAPI, "Schema must not be null");
}
}
}

View File

@@ -0,0 +1,116 @@
package io.github.swagger2markup.internal.document;
import io.github.swagger2markup.OpenAPI2MarkupConverter;
import io.github.swagger2markup.adoc.ast.impl.SectionImpl;
import io.github.swagger2markup.adoc.ast.impl.TableImpl;
import io.github.swagger2markup.extension.MarkupComponent;
import io.github.swagger2markup.internal.component.ExternalDocumentationComponent;
import io.github.swagger2markup.internal.component.ParametersComponent;
import io.github.swagger2markup.internal.component.ResponseComponent;
import io.github.swagger2markup.internal.component.SecurityRequirementTableComponent;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.Paths;
import io.swagger.v3.oas.models.servers.Server;
import io.swagger.v3.oas.models.servers.ServerVariables;
import org.apache.commons.lang3.Validate;
import org.asciidoctor.ast.Document;
import org.asciidoctor.ast.Section;
import org.asciidoctor.ast.StructuralNode;
import java.util.*;
import static io.github.swagger2markup.config.OpenAPILabels.*;
import static io.github.swagger2markup.internal.helper.OpenApiHelpers.*;
public class PathsDocument extends MarkupComponent<Document, PathsDocument.Parameters, Document> {
private final ParametersComponent parametersComponent;
private final ExternalDocumentationComponent externalDocumentationComponent;
private final ResponseComponent responseComponent;
private final SecurityRequirementTableComponent securityRequirementTableComponent;
public PathsDocument(OpenAPI2MarkupConverter.OpenAPIContext context) {
super(context);
this.parametersComponent = new ParametersComponent(context);
this.externalDocumentationComponent = new ExternalDocumentationComponent(context);
this.responseComponent = new ResponseComponent(context);
this.securityRequirementTableComponent = new SecurityRequirementTableComponent(context);
}
public static Parameters parameters(OpenAPI schema) {
return new Parameters(schema);
}
@Override
public Document apply(Document document, Parameters parameters) {
Paths apiPaths = parameters.schema.getPaths();
if (null == apiPaths || apiPaths.isEmpty()) return document;
SectionImpl allPathsSection = new SectionImpl(document);
allPathsSection.setTitle(labels.getLabel(SECTION_TITLE_PATHS));
apiPaths.forEach((name, pathItem) ->
pathItem.readOperationsMap().forEach(((httpMethod, operation) -> {
SectionImpl operationSection = new SectionImpl(allPathsSection);
String summary = Optional.ofNullable(operation.getSummary()).orElse("");
operationSection.setTitle((italicUnconstrained(httpMethod.name().toUpperCase()) + " " + monospaced(name) + " " + summary).trim());
appendDescription(operationSection, operation.getDescription());
externalDocumentationComponent.apply(operationSection, operation.getExternalDocs());
parametersComponent.apply(operationSection, operation.getParameters());
responseComponent.apply(operationSection, operation.getResponses());
appendServersSection(operationSection, operation.getServers());
securityRequirementTableComponent.apply(operationSection, operation.getSecurity(), false);
allPathsSection.append(operationSection);
})));
document.append(allPathsSection);
return document;
}
private void appendServersSection(StructuralNode node, List<Server> servers) {
if (null == servers || servers.isEmpty()) return;
Section serversSection = new SectionImpl(node);
serversSection.setTitle(labels.getLabel(SECTION_TITLE_SERVERS));
servers.forEach(server -> {
Section serverSection = new SectionImpl(serversSection);
serverSection.setTitle(italicUnconstrained(labels.getLabel(LABEL_SERVER)) + ": " + server.getUrl());
appendDescription(serverSection, server.getDescription());
ServerVariables variables = server.getVariables();
appendVariables(serverSection, variables);
serversSection.append(serverSection);
});
node.append(serversSection);
}
private void appendVariables(Section serverSection, ServerVariables variables) {
if (null == variables || variables.isEmpty()) return;
TableImpl serverVariables = new TableImpl(serverSection, new HashMap<String, Object>() {{
put("header-option", "");
put("cols", ".^2a,.^9a,.^3a,.^4a");
}}, new ArrayList<>());
serverVariables.setTitle(labels.getLabel(TABLE_TITLE_SERVER_VARIABLES));
serverVariables.setHeaderRow(labels.getLabel(TABLE_HEADER_VARIABLE), labels.getLabel(TABLE_HEADER_DESCRIPTION),
labels.getLabel(TABLE_HEADER_POSSIBLE_VALUES), labels.getLabel(TABLE_HEADER_DEFAULT)
);
variables.forEach((name, variable) -> {
String possibleValues = String.join(", ", Optional.ofNullable(variable.getEnum()).orElse(Collections.singletonList("Any")));
serverVariables.addRow(name, Optional.ofNullable(variable.getDescription()).orElse(""), possibleValues, variable.getDefault());
});
serverSection.append(serverVariables);
}
public static class Parameters {
private final OpenAPI schema;
public Parameters(OpenAPI schema) {
this.schema = Validate.notNull(schema, "Schema must not be null");
}
}
}

View File

@@ -0,0 +1,49 @@
package io.github.swagger2markup.internal.document;
import io.github.swagger2markup.OpenAPI2MarkupConverter;
import io.github.swagger2markup.adoc.ast.impl.SectionImpl;
import io.github.swagger2markup.extension.MarkupComponent;
import io.github.swagger2markup.internal.component.SecurityRequirementTableComponent;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import org.apache.commons.lang3.Validate;
import org.asciidoctor.ast.Document;
import org.asciidoctor.ast.Section;
import java.util.List;
import static io.github.swagger2markup.config.OpenAPILabels.SECTION_TITLE_SECURITY;
public class SecurityDocument extends MarkupComponent<Document, SecurityDocument.Parameters, Document> {
private final SecurityRequirementTableComponent securityRequirementTableComponent;
public SecurityDocument(OpenAPI2MarkupConverter.OpenAPIContext context) {
super(context);
this.securityRequirementTableComponent = new SecurityRequirementTableComponent(context);
}
public static Parameters parameters(OpenAPI schema) {
return new Parameters(schema);
}
@Override
public Document apply(Document document, SecurityDocument.Parameters parameters) {
List<SecurityRequirement> securityRequirements = parameters.schema.getSecurity();
if (null == securityRequirements || securityRequirements.isEmpty()) return document;
Section securityRequirementsSection = new SectionImpl(document);
securityRequirementsSection.setTitle(labels.getLabel(SECTION_TITLE_SECURITY));
securityRequirementTableComponent.apply(securityRequirementsSection, securityRequirements, false);
document.append(securityRequirementsSection);
return document;
}
public static class Parameters {
private final OpenAPI schema;
public Parameters(OpenAPI schema) {
this.schema = Validate.notNull(schema, "Schema must not be null");
}
}
}

View File

@@ -0,0 +1,115 @@
package io.github.swagger2markup.internal.helper;
import io.github.swagger2markup.adoc.ast.impl.DocumentImpl;
import io.github.swagger2markup.adoc.ast.impl.ParagraphBlockImpl;
import io.swagger.v3.oas.models.media.ArraySchema;
import io.swagger.v3.oas.models.media.Schema;
import org.apache.commons.lang3.StringUtils;
import org.asciidoctor.ast.Block;
import org.asciidoctor.ast.Document;
import org.asciidoctor.ast.StructuralNode;
import org.asciidoctor.ast.Table;
import java.util.List;
import static io.github.swagger2markup.adoc.converter.internal.Delimiters.LINE_SEPARATOR;
public class OpenApiHelpers {
public static void appendDescription(StructuralNode node, String description) {
if (StringUtils.isNotBlank(description)) {
Block paragraph = new ParagraphBlockImpl(node);
paragraph.setSource(description);
node.append(paragraph);
}
}
public static Document generateInnerDoc(Table table, String documentContent) {
return generateInnerDoc(table, documentContent, "");
}
public static Document generateInnerDoc(Table table, String documentContent, String id) {
Document innerDoc = new DocumentImpl(table);
if (StringUtils.isNotBlank(id)) {
innerDoc.setId(id);
}
Block paragraph = new ParagraphBlockImpl(innerDoc);
paragraph.setSource(documentContent);
innerDoc.append(paragraph);
return innerDoc;
}
public static String requiredIndicator(boolean isRequired, String labelRequired, String labelOptional) {
return italicUnconstrained(isRequired ? labelRequired : labelOptional).toLowerCase();
}
public static String superScript(String str) {
return "^" + str + "^";
}
public static String subScript(String str) {
return "~" + str + "~";
}
public static String italicUnconstrained(String str) {
return "__" + str + "__";
}
public static String boldUnconstrained(String str) {
return "**" + str + "**";
}
public static String monospaced(String str) {
return "`" + str + "`";
}
public static String getSchemaTypeAsString(Schema schema) {
StringBuilder stringBuilder = new StringBuilder();
if (schema instanceof ArraySchema) {
stringBuilder.append("< ");
Schema<?> items = ((ArraySchema) schema).getItems();
stringBuilder.append(getSchemaType(items));
stringBuilder.append(" > ");
stringBuilder.append(schema.getType());
} else {
List enumList = schema.getEnum();
if (enumList != null) {
stringBuilder.append("enum (");
for (Object value : enumList) {
stringBuilder.append(value.toString());
stringBuilder.append(",");
}
stringBuilder.deleteCharAt(stringBuilder.length() - 1);
stringBuilder.append(')');
} else {
stringBuilder.append(getSchemaType(schema));
String format = schema.getFormat();
if (format != null) {
stringBuilder.append(' ');
stringBuilder.append('(');
stringBuilder.append(format);
stringBuilder.append(')');
}
}
}
return stringBuilder.toString();
}
private static String getSchemaType(Schema<?> schema) {
String type = schema.getType();
if (StringUtils.isNotEmpty(type)) {
return type;
} else {
return generateRefLink(schema.get$ref());
}
}
private static String generateRefLink(String ref) {
if (StringUtils.isNotBlank(ref)) {
String anchor = ref.toLowerCase().replaceFirst("#", "").replaceAll("/", "_");
return "<<" + anchor + ">>" + LINE_SEPARATOR;
}
return "";
}
}

View File

@@ -0,0 +1,43 @@
swagger2markup.markupLanguage=ASCIIDOC
swagger2markup.swaggerMarkupLanguage=ASCIIDOC
swagger2markup.hostnameEnabled=false
swagger2markup.basePathPrefixEnabled=false
swagger2markup.operationExtensionsEnabled=false
swagger2markup.definitionExtensionsEnabled=false
swagger2markup.separatedDefinitionsEnabled=false
swagger2markup.separatedOperationsEnabled=false
swagger2markup.pathsGroupedBy=AS_IS
swagger2markup.outputLanguage=EN
swagger2markup.inlineSchemaEnabled=true
swagger2markup.interDocumentCrossReferencesEnabled=false
swagger2markup.flatBodyEnabled=false
swagger2markup.pathSecuritySectionEnabled=true
swagger2markup.overviewDocument=overview
swagger2markup.pathsDocument=paths
swagger2markup.definitionsDocument=definitions
swagger2markup.securityDocument=security
swagger2markup.separatedOperationsFolder=operations
swagger2markup.separatedDefinitionsFolder=definitions
swagger2markup.tagOrderBy=NATURAL
swagger2markup.operationOrderBy=NATURAL
swagger2markup.definitionOrderBy=NATURAL
swagger2markup.parameterOrderBy=NATURAL
swagger2markup.propertyOrderBy=NATURAL
swagger2markup.responseOrderBy=NATURAL
swagger2markup.listDelimiterEnabled=false
swagger2markup.listDelimiter=,
swagger2markup.asciidoc.pegdown.timeoutMillis=2000
swagger2markup.generatedExamplesEnabled=false
# basic, curl, invoke-webrequest
swagger2markup.requestExamplesFormat=basic
# default, bash, powershell, etc.
swagger2markup.requestExamplesSourceFormat=default
# hide, inherit or hostname
swagger2markup.requestExamplesHost=hide
# hide, inherit or schema (e.g. https, https, etc.)
swagger2markup.requestExamplesSchema=hide
swagger2markup.requestExamplesHideBasePath=true
swagger2markup.requestExamplesIncludeAllQueryParams=false
# single, commaSeparated, multiple, multiple[]
swagger2markup.requestExamplesQueryArrayStyle=single

View File

@@ -0,0 +1,58 @@
label_content=Content
label_default=Default
label_deprecated=Deprecated
label_example=Example
label_examples=Examples
label_exclusive_maximum=Exclusive Maximum
label_exclusive_minimum=Exclusive Minimum
label_external_value=External Value
label_format=Format
label_maximum=Maximum
label_max_items=Maximum Items
label_max_length=Maximum Length
label_max_properties=Maximum Properties
label_minimum=Minimum
label_min_items=Minimum Items
label_min_length=Minimum Length
label_min_properties=Minimum Properties
label_multiple_of=Multiple Of
label_no_links=No Links
label_nullable=Nullable
label_operation=Operation
label_optional=Optional
label_parameters=Parameters
label_read_only=Read Only
label_required=Required
label_server=Server
label_terms_of_service=Terms Of Service
label_title=Title
label_type=Type
label_unique_items=Unique Items
label_write_only=Write Only
section_title_components=Components
section_title_parameters=Parameters
section_title_paths=Paths
section_title_schemas=Schemas
section_title_security=Security
section_title_servers=Servers
section_title_overview=Overview
section_title_tags=Tags
section_title_responses=Responses
section_title_headers=Headers
section_title_links=Links
table_header_default=Default
table_header_description=Description
table_header_http_code=Code
table_header_links=Links
table_header_name=Name
table_header_possible_values=Possible Values
table_header_schema=Schema
table_header_scopes=Scopes
table_header_type=Type
table_header_variable=Variable
table_title_headers=Headers
table_title_parameters=Parameters
table_title_properties=Properties
table_title_responses=Responses
table_title_security=Security
table_title_server_variables=Server Variables

View File

@@ -0,0 +1,74 @@
/*
* Copyright 2017 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.swagger2markup;
import io.github.swagger2markup.assertions.DiffUtils;
import org.apache.commons.io.FileUtils;
import org.assertj.core.api.Assertions;
import org.junit.Before;
import org.junit.Test;
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThat;
public class AsciidocConverterTest {
private static final String[] EXPECTED_FILES = new String[]{"definitions.adoc", "overview.adoc", "paths.adoc", "security.adoc"};
private List<String> expectedFiles;
@Before
public void setUp() {
expectedFiles = new ArrayList<>(asList(EXPECTED_FILES));
}
@Test
public void testToString() throws URISyntaxException {
//Given
Path file = Paths.get(AsciidocConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI());
//When
String asciiDocAsString = OpenAPI2MarkupConverter.from(file).build()
.toString();
//Then
Assertions.assertThat(asciiDocAsString).isNotEmpty();
System.out.println(asciiDocAsString);
}
@Test
public void testToFolder() throws URISyntaxException {
//Given
Path file = Paths.get(AsciidocConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI());
Path outputDirectory = Paths.get("build/test/asciidoc/to_folder");
FileUtils.deleteQuietly(outputDirectory.toFile());
//When
OpenAPI2MarkupConverter.from(file).build()
.toFolder(outputDirectory);
//Then
String[] files = outputDirectory.toFile().list();
assertThat(files).hasSize(4).containsAll(expectedFiles);
Path expectedFilesDirectory = Paths.get(AsciidocConverterTest.class.getResource("/expected/asciidoc/to_folder").toURI());
DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testToFolder.html");
}
}

View File

@@ -0,0 +1,49 @@
package io.github.swagger2markup;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.parser.OpenAPIV3Parser;
import io.swagger.v3.parser.core.models.ParseOptions;
import io.swagger.v3.parser.core.models.SwaggerParseResult;
import org.apache.commons.io.IOUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Paths;
import java.util.Arrays;
import static org.junit.Assert.assertNotNull;
@RunWith(Parameterized.class)
public class OpenApi2AsciiDocTest {
final private String openApiFile;
final private String expectedAsciiDoc;
public OpenApi2AsciiDocTest(String openApiFile, String expectedAsciiDoc) throws IOException {
this.openApiFile = "./src/test/resources/open_api/" + openApiFile;
this.expectedAsciiDoc = IOUtils.toString(getClass().getResourceAsStream("/asciidoc/" + expectedAsciiDoc), StandardCharsets.UTF_8);
}
@Parameterized.Parameters(name = "Run {index}: open api={0}, asciidoc={1}")
public static Iterable<Object[]> data() {
return Arrays.asList(new Object[][]{
{"simple.yaml", "simple.adoc"},
{"petstore.yaml", "petstore.adoc"}
});
}
@Test
public void converts_open_api_v3_to_asciidoc() {
ParseOptions options = new ParseOptions();
options.setResolve(true);
SwaggerParseResult result = new OpenAPIV3Parser().readLocation(openApiFile, null, options);
OpenAPI swagger = result.getOpenAPI();
assertNotNull(swagger);
OpenAPI2MarkupConverter converter = OpenAPI2MarkupConverter.from(swagger).build();
converter.toFolder(Paths.get("build/test/asciidoc"));
}
}

View File

@@ -0,0 +1,55 @@
/*
*
* Copyright 2017 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.swagger2markup.assertions;
import io.github.robwin.diff.DiffAssertions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
public class DiffUtils {
private static final Logger LOGGER = LoggerFactory.getLogger(DiffUtils.class);
public static void assertThatAllFilesAreEqual(Path expectedDirectory, Path actualDirectory, String reportName) {
Path reportPath = Paths.get("build/diff-report/", reportName);
try {
try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(expectedDirectory)) {
for (Path expectedFile : directoryStream) {
Path actualFile = actualDirectory.resolve(expectedFile.getFileName());
LOGGER.info("Diffing file '{}' with '{}'", actualFile, expectedFile);
DiffAssertions.assertThat(actualFile).isEqualTo(expectedFile, reportPath);
}
}
} catch (IOException e) {
throw new RuntimeException("Failed to assert that all files are equal", e);
}
}
public static void assertThatFileIsEqual(Path expectedFile, Path actualFile, String reportName) {
Path reportPath = Paths.get("build/diff-report/", reportName);
LOGGER.info("Diffing file '{}' with '{}'", actualFile, expectedFile);
DiffAssertions.assertThat(actualFile).isEqualTo(expectedFile, reportPath);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,276 @@
= Simple Inventory API
<you@your-company.com>
v1.0.0
:revnumber: 1.0.0
:openapi: 3.0.0
:authorcount: 1
:email: you@your-company.com
== Overview
This is a simple API
http://www.apache.org/licenses/LICENSE-2.0.html[Apache 2.0]
== Tags
admins::
Secured Admin-only calls
developers::
Operations available to regular developers
== Servers
=== __Server__: /
== Paths
=== __GET__ `/inventory` searches inventory
By passing in the appropriate options, you can search for
available inventory in the system
.Parameters
[%header,caption=,cols=".^2a,.^3a,.^10a,.^5a"]
|===
<.<|Type
<.<|Name
<.<|Description
<.<|Schema
<.<|**query**
<.<|**searchString** +
__optional__
<.<|pass an optional search string for looking up inventory
<.<|type: string
<.<|**query**
<.<|**limit** +
__optional__
<.<|maximum number of records to return
<.<|minimum: 0 +
type: integer +
maximum: 50 +
format: int32
<.<|**query**
<.<|**skip** +
__optional__
<.<|number of records to skip for pagination
<.<|minimum: 0 +
type: integer +
format: int32
|===
.Responses
[%header,caption=,cols=".^2a,.^14a,.^4a"]
|===
<.<|Code
<.<|Description
<.<|Links
<.<|200
<.<|search results matching criteria
.Content
application/json::
+
type: array
<.<|No Links
<.<|400
<.<|bad input parameter
<.<|No Links
|===
=== __POST__ `/inventory` adds an inventory item
Adds an item to the system
.Responses
[%header,caption=,cols=".^2a,.^14a,.^4a"]
|===
<.<|Code
<.<|Description
<.<|Links
<.<|201
<.<|item created
<.<|No Links
<.<|400
<.<|invalid input, object invalid
<.<|No Links
<.<|409
<.<|an existing item already exists
<.<|No Links
|===
[[_components]]
== Components
[[_components_schemas]]
=== Schemas
[[_components_schemas_inventoryitem]]
==== InventoryItem
type: object
.Properties
[%header,caption=,cols=".^4a,.^16a"]
|===
<.<|Name
<.<|Schema
<.<|id
__required__
<.<|type: string +
format: uuid
<.<|name
__required__
<.<|type: string
<.<|releaseDate
__required__
<.<|type: string +
format: date-time
<.<|manufacturer
__required__
<.<|<<_components_schemas_Manufacturer,Manufacturer>>
|===
[[_components_schemas_manufacturer]]
==== Manufacturer
type: object
.Properties
[%header,caption=,cols=".^4a,.^16a"]
|===
<.<|Name
<.<|Schema
<.<|name
__required__
<.<|type: string
<.<|homePage
__optional__
<.<|type: string +
format: url
<.<|phone
__optional__
<.<|type: string
|===

View File

@@ -0,0 +1,351 @@
[[_components]]
== Components
[[_components_schemas]]
=== Schemas
[[_components_schemas_user]]
==== User
.Properties
[%header,caption=,cols=".^4a,.^16a,.^4a"]
|===
<.<|Name
<.<|Description
<.<|Schema
<.<|id
__optional__
<.<|
<.<|integer (int64)
<.<|username
__optional__
<.<|
<.<|string
<.<|firstName
__optional__
<.<|
<.<|string
<.<|lastName
__optional__
<.<|
<.<|string
<.<|email
__optional__
<.<|
<.<|string
<.<|password
__optional__
<.<|
<.<|string
<.<|phone
__optional__
<.<|
<.<|string
<.<|userStatus
__optional__
<.<|User Status
<.<|integer (int32)
|===
[[_components_schemas_category]]
==== Category
.Properties
[%header,caption=,cols=".^4a,.^16a,.^4a"]
|===
<.<|Name
<.<|Description
<.<|Schema
<.<|id
__optional__
<.<|
<.<|integer (int64)
<.<|name
__optional__
<.<|The name of the category
**Maximum Length**: 255 +
**Minimum Length**: 0 +
**Default**: DefaultCategory
<.<|string
|===
[[_components_schemas_pet]]
==== Pet
.Properties
[%header,caption=,cols=".^4a,.^16a,.^4a"]
|===
<.<|Name
<.<|Description
<.<|Schema
<.<|id
__optional__
<.<|
<.<|integer (int64)
<.<|category
__optional__
<.<|
<.<|<<_components_schemas_category>>
<.<|name
__required__
<.<|
<.<|string
<.<|photoUrls
__required__
<.<|
<.<|< string > array
<.<|tags
__optional__
<.<|
<.<|< <<_components_schemas_tag>>
> array
<.<|status
__optional__
<.<|pet status in the store,
<.<|enum (Dead,Alive)
|===
[[_components_schemas_tag]]
==== Tag
.Properties
[%header,caption=,cols=".^4a,.^16a,.^4a"]
|===
<.<|Name
<.<|Description
<.<|Schema
<.<|id
__optional__
<.<|
<.<|integer (int64)
<.<|name
__optional__
<.<|
<.<|string
|===
[[_components_schemas_order]]
==== Order
.Properties
[%header,caption=,cols=".^4a,.^16a,.^4a"]
|===
<.<|Name
<.<|Description
<.<|Schema
<.<|id
__optional__
<.<|
<.<|integer (int64)
<.<|petId
__optional__
<.<|
<.<|integer (int64)
<.<|quantity
__optional__
<.<|**Maximum**: 10000 +
**Minimum**: 0 +
**Default**: 0
<.<|integer (int32)
<.<|shipDate
__optional__
<.<|
<.<|string (date-time)
<.<|status
__optional__
<.<|Order Status
<.<|enum (Ordered,Cancelled)
<.<|complete
__optional__
<.<|
<.<|boolean
|===
[[_components_parameters]]
=== Responses
.Responses
[%header,caption=,cols=".^2a,.^14a,.^4a"]
|===
<.<|Code
<.<|Description
<.<|Links
<.<|InvalidId
<.<|Invalid ID supplied
<.<|No Links
|===

View File

@@ -0,0 +1,30 @@
= Swagger Petstore
apiteam@swagger.io
v1.0.0
:revnumber: 1.0.0
:openapi: 3.0.0
:author: apiteam@swagger.io
:authorcount: 1
== Overview
This is a sample server Petstore server.
[Learn about Swagger](http://swagger.io) 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
http://helloreverb.com/terms/[Terms Of Service]
http://www.apache.org/licenses/LICENSE-2.0.html[Apache 2.0]
http://swagger.io[Find out more about Swagger]
== Tags
pet::
Pet resource
store::
Store resource
user::
User resource

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true">
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<logger name="io.github.swagger2markup" level="DEBUG"/>
<root level="INFO">
<appender-ref ref="CONSOLE" />
</root>
</configuration>

View File

@@ -0,0 +1,732 @@
openapi: 3.0.0
servers:
- url: 'http://localhost:8000/v2/api'
info:
description: >-
This is a sample server Petstore server. You can find out more about
Swagger at http://swagger.io or on
irc.freenode.net, #swagger. For this sample, you can use the api key
"special-key" to test the authorization filters
version: 1.0.0
title: Swagger Petstore
termsOfService: 'http://swagger.io/terms/'
contact:
name: apiteam@swagger.io
license:
name: Apache 2.0
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
externalDocs:
description: Find more info here
url: 'https://swagger.io'
tags:
- name: pet
description: Pet Operations
externalDocs:
url: 'http://swagger.io'
- name: user
description: All about the Users
paths:
/pet/add:
post:
tags:
- pet
summary: Add a new pet to the store
description: ''
operationId: createPet
responses:
'200':
description: This is a sample
content:
text/plain:
schema:
type: string
example: 'whoa!'
'405':
description: Invalid input
security:
- petstore_auth:
- 'write:pets'
- 'read:pets'
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
description: Pet object that needs to be added to the store
/pet:
post:
tags:
- pet
summary: Add a new pet to the store
description: ''
operationId: addPet
responses:
'405':
description: Invalid input
security:
- petstore_auth:
- 'write:pets'
- 'read:pets'
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
application/xml:
schema:
$ref: '#/components/schemas/Pet'
description: Pet object that needs to be added to the store
put:
tags:
- pet
summary: Update an existing pet
description: ''
operationId: updatePet
responses:
'400':
description: Invalid ID supplied
'404':
description: Pet not found
'405':
description: Validation exception
security:
- petstore_auth:
- 'write:pets'
- 'read:pets'
requestBody:
$ref: '#/components/requestBodies/Pet'
/pet/findByStatus:
get:
tags:
- pet
summary: Finds Pets by status
description: Multiple status values can be provided with comma seperated strings
operationId: findPetsByStatus
parameters:
- name: status
in: query
description: Status values that need to be considered for filter
required: false
style: pipeDelimited
schema:
type: array
items:
type: string
default: available
responses:
'200':
description: successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/PetArray'
application/xml:
schema:
$ref: '#/components/schemas/PetArray'
'400':
description: Invalid status value
security:
- petstore_auth:
- 'write:pets'
- 'read:pets'
/pet/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
parameters:
- name: tags
in: query
description: Tags to filter by
required: false
explode: true
schema:
type: array
items:
type: string
responses:
'200':
description: successful operation
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Pet'
application/xml:
schema:
type: array
items:
$ref: '#/components/schemas/Pet'
'400':
description: Invalid tag value
security:
- petstore_auth:
- 'write:pets'
- 'read:pets'
'/pet/{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
parameters:
- name: petId
in: path
description: ID of pet that needs to be fetched
required: true
schema:
type: integer
format: int64
responses:
'200':
description: successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
application/xml:
schema:
$ref: '#/components/schemas/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
parameters:
- name: petId
in: path
description: ID of pet that needs to be updated
required: true
schema:
type: string
responses:
'405':
description: Invalid input
security:
- petstore_auth:
- 'write:pets'
- 'read:pets'
requestBody:
content:
application/x-www-form-urlencoded:
schema:
type: object
properties:
name:
description: Updated name of the pet
type: string
status:
description: Updated status of the pet
type: string
delete:
tags:
- pet
summary: Deletes a pet
description: ''
operationId: deletePet
parameters:
- name: api_key
in: header
description: ''
required: false
schema:
type: string
- name: petId
in: path
description: Pet id to delete
required: true
schema:
type: integer
format: int64
responses:
'400':
description: Invalid pet value
security:
- petstore_auth:
- 'write:pets'
- 'read:pets'
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
description: Pet extra params that needs to be deleted
'/pet/{petId}/uploadImage':
post:
tags:
- pet
summary: uploads an image
description: ''
operationId: uploadFile
parameters:
- name: petId
in: path
description: ID of pet to update
required: true
schema:
type: integer
format: int64
responses:
'200':
description: successful operation
content:
application/json:
schema:
$ref: "#/components/schemas/ApiResponse"
security:
- petstore_auth:
- 'write:pets'
- 'read:pets'
requestBody:
content:
multipart/form-data:
schema:
type: object
properties:
additionalMetadata:
description: Additional data to pass to server
type: string
file:
description: file to upload
type: string
format: binary
/store/inventory:
get:
tags:
- store
summary: Returns pet inventories by status
description: Returns a map of status codes to quantities
operationId: get inventory+1
responses:
'200':
description: successful operation
content:
application/json:
schema:
type: object
additionalProperties:
type: integer
format: int32
application/xml:
schema:
type: object
additionalProperties:
type: integer
format: int32
security:
- api_key: []
/store/order:
post:
tags:
- store
summary: Place an order for a pet
description: ''
operationId: placeOrder
responses:
'200':
description: successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/Order'
application/xml:
schema:
$ref: '#/components/schemas/Order'
'400':
description: Invalid Order
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Order'
description: order placed for purchasing the pet
'/store/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
parameters:
- name: orderId
in: path
description: ID of pet that needs to be fetched
required: true
schema:
type: string
responses:
'200':
description: successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/Order'
application/xml:
schema:
$ref: '#/components/schemas/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
parameters:
- name: orderId
in: path
description: ID of the order that needs to be deleted
required: true
schema:
type: string
responses:
'400':
description: Invalid ID supplied
'404':
description: Order not found
/user:
post:
tags:
- user
summary: Create user
description: This can only be done by the logged in user.
operationId: createUser
responses:
200:
content:
'application/json':
schema:
type: object
properties:
id:
# default is text/plain
type: string
format: text
examples:
foo:
value: {"foo": "bar"}
bar:
summary: A bar example
value: {"bar": "baz"}
default:
description: successful operation
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/User'
description: Created user object
/user/createWithArray:
post:
tags:
- user
summary: Creates list of users with given input array
description: ''
operationId: createUsersWithArrayInput
responses:
default:
description: successful operation
requestBody:
$ref: '#/components/requestBodies/UserArray'
/user/createWithList:
post:
tags:
- user
summary: Creates list of users with given input array
description: ''
operationId: createUsersWithListInput
responses:
default:
description: successful operation
requestBody:
$ref: '#/components/requestBodies/UserArray'
/user/login:
get:
tags:
- user
security:
- https
summary: Logs user into the system
description: ''
operationId: loginUser
parameters:
- name: username
in: query
description: The user name for login
required: false
schema:
type: string
- name: password
in: query
description: The password for login in clear text
required: false
schema:
type: string
responses:
'200':
description: successful operation
content:
application/json:
schema:
type: string
application/xml:
schema:
type: string
'400':
description: Invalid username/password supplied
/user/logout:
get:
tags:
- user
security:
- https
summary: Logs out current logged in user session
description: ''
operationId: logoutUser
responses:
default:
description: successful operation
'/user/{username}':
get:
tags:
- user
summary: Get user by user name
description: ''
operationId: getUserByName
parameters:
- name: username
in: path
description: 'The name that needs to be fetched. Use user1 for testing.'
required: true
schema:
type: string
responses:
'200':
description: successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/User'
application/xml:
schema:
$ref: '#/components/schemas/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
parameters:
- name: username
in: path
description: name that need to be deleted
required: true
schema:
type: string
responses:
'400':
description: Invalid user supplied
'404':
description: User not found
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/User'
description: Updated user object
delete:
tags:
- user
summary: Delete user
description: This can only be done by the logged in user.
operationId: deleteUser
parameters:
- name: username
in: path
description: The name that needs to be deleted
required: true
schema:
type: string
responses:
'400':
description: Invalid username supplied
'404':
description: User not found
security:
- foo:
- bar
- baz
a:
- b
- c
components:
parameters:
sharedSkip:
name: skip
in: query
description: Results to skip
required: false
schema:
type: integer
format: int32
responses:
veryBad:
description: failed
requestBodies:
UserArray:
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/User'
description: List of user object
Pet:
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
application/xml:
schema:
$ref: '#/components/schemas/Pet'
description: Pet object that needs to be added to the store
securitySchemes:
api_key:
type: apiKey
name: api_key
in: header
petstore_auth:
type: oauth2
flows:
implicit:
authorizationUrl: 'http://petstore.swagger.io/api/oauth/dialog'
scopes:
'write:pets': modify pets in your account
'read:pets': read your pets
schemas:
User:
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
xml:
name: User
Category:
properties:
id:
type: integer
format: int64
name:
type: string
xml:
name: Category
Pet:
required:
- name
- photoUrls
properties:
id:
type: integer
format: int64
category:
$ref: '#/components/schemas/Category'
name:
type: string
example: doggie
photoUrls:
type: array
xml:
name: photoUrl
wrapped: true
items:
type: string
tags:
type: array
xml:
name: tag
wrapped: true
items:
$ref: '#/components/schemas/Tag'
status:
type: string
description: pet status in the store
xml:
name: Pet
Tag:
properties:
id:
type: integer
format: int64
name:
type: string
xml:
name: Tag
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
xml:
name: Order
PetArray:
type: array
items:
$ref: '#/components/schemas/Pet'

View File

@@ -0,0 +1,115 @@
openapi: 3.0.0
info:
description: This is a simple API
version: "1.0.0"
title: Simple Inventory API
contact:
email: you@your-company.com
license:
name: Apache 2.0
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
tags:
- name: admins
description: Secured Admin-only calls
- name: developers
description: Operations available to regular developers
paths:
/inventory:
get:
tags:
- developers
summary: searches inventory
operationId: searchInventory
description: |
By passing in the appropriate options, you can search for
available inventory in the system
parameters:
- in: query
name: searchString
description: pass an optional search string for looking up inventory
required: false
schema:
type: string
- in: query
name: skip
description: number of records to skip for pagination
schema:
type: integer
format: int32
minimum: 0
- in: query
name: limit
description: maximum number of records to return
schema:
type: integer
format: int32
minimum: 0
maximum: 50
responses:
'200':
description: search results matching criteria
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/InventoryItem'
'400':
description: bad input parameter
post:
tags:
- admins
summary: adds an inventory item
operationId: addInventory
description: Adds an item to the system
responses:
'201':
description: item created
'400':
description: 'invalid input, object invalid'
'409':
description: an existing item already exists
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/InventoryItem'
description: Inventory item to add
components:
schemas:
InventoryItem:
type: object
required:
- id
- name
- manufacturer
- releaseDate
properties:
id:
type: string
format: uuid
example: d290f1ee-6c54-4b01-90e6-d701748f0851
name:
type: string
example: Widget Adapter
releaseDate:
type: string
format: date-time
example: '2016-08-29T09:12:33.001Z'
manufacturer:
$ref: '#/components/schemas/Manufacturer'
Manufacturer:
required:
- name
properties:
name:
type: string
example: ACME Corporation
homePage:
type: string
format: url
example: 'https://www.acme-corp.com'
phone:
type: string
example: 408-867-5309
type: object

View File

@@ -0,0 +1,693 @@
openapi: 3.0.0
info:
description: >
This is a sample server Petstore server.
[Learn about Swagger](http://swagger.io) 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
title: Swagger Petstore
termsOfService: http://helloreverb.com/terms/
contact:
name: apiteam@swagger.io
license:
name: Apache 2.0
url: http://www.apache.org/licenses/LICENSE-2.0.html
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
requestBody:
$ref: "#/components/requestBodies/Pet"
responses:
"405":
description: Invalid input
security:
- petstore_auth:
- write_pets
- read_pets
put:
tags:
- pet
summary: Update an existing pet
description: ""
operationId: updatePet
requestBody:
$ref: "#/components/requestBodies/Pet"
responses:
"400":
$ref: "#/components/responses/InvalidId"
"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
parameters:
- in: query
name: status
description: Status values that need to be considered for filter
required: false
explode: true
schema:
type: array
items:
type: string
responses:
"200":
description: successful operation
headers:
X-Rate-Limit-Limit:
description: The number of allowed requests in the current period
schema:
type: integer
X-Rate-Limit-Remaining:
description: The number of remaining requests in the current period
schema:
type: integer
X-Rate-Limit-Reset:
description: The number of seconds left in the current period
schema:
type: integer
content:
application/json:
schema:
type: array
items:
$ref: "#/components/schemas/Pet"
application/xml:
schema:
type: array
items:
$ref: "#/components/schemas/Pet"
"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
parameters:
- in: query
name: tags
description: Tags to filter by
required: false
example: adorable
explode: true
schema:
type: array
items:
type: string
responses:
"200":
description: successful operation
headers:
X-Rate-Limit-Limit:
description: The number of allowed requests in the current period
schema:
type: integer
X-Rate-Limit-Remaining:
description: The number of remaining requests in the current period
schema:
type: integer
X-Rate-Limit-Reset:
description: The number of seconds left in the current period
schema:
type: integer
content:
application/json:
schema:
type: array
items:
$ref: "#/components/schemas/Pet"
application/xml:
schema:
type: array
items:
$ref: "#/components/schemas/Pet"
"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
parameters:
- in: path
name: petId
description: ID of pet that needs to be fetched
required: true
example: 30
schema:
type: integer
format: int64
responses:
"200":
description: successful operation
headers:
X-Rate-Limit-Limit:
description: The number of allowed requests in the current period
schema:
type: integer
X-Rate-Limit-Remaining:
description: The number of remaining requests in the current period
schema:
type: integer
X-Rate-Limit-Reset:
description: The number of seconds left in the current period
schema:
type: integer
content:
application/json:
schema:
$ref: "#/components/schemas/Pet"
application/xml:
schema:
$ref: "#/components/schemas/Pet"
"400":
$ref: "#/components/responses/InvalidId"
"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
parameters:
- in: path
name: petId
description: ID of pet that needs to be updated
required: true
schema:
type: string
requestBody:
content:
application/x-www-form-urlencoded:
schema:
type: object
properties:
name:
description: Updated name of the pet
type: string
status:
description: Updated status of the pet
type: string
required:
- name
- status
responses:
"405":
description: Invalid input
security:
- petstore_auth:
- write_pets
- read_pets
delete:
tags:
- pet
summary: Deletes a pet
description: ""
operationId: deletePet
parameters:
- in: header
name: api_key
description: ""
required: true
schema:
type: string
- in: path
name: petId
description: Pet id to delete
required: true
schema:
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
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/Order"
description: order placed for purchasing the pet
responses:
"200":
description: successful operation
headers:
X-Rate-Limit-Limit:
description: The number of allowed requests in the current period
schema:
type: integer
X-Rate-Limit-Remaining:
description: The number of remaining requests in the current period
schema:
type: integer
X-Rate-Limit-Reset:
description: The number of seconds left in the current period
schema:
type: integer
content:
application/json:
schema:
$ref: "#/components/schemas/Order"
application/xml:
schema:
$ref: "#/components/schemas/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
parameters:
- in: path
name: orderId
description: ID of pet that needs to be fetched
required: true
schema:
type: string
responses:
"200":
description: successful operation
headers:
X-Rate-Limit-Limit:
description: The number of allowed requests in the current period
schema:
type: integer
X-Rate-Limit-Remaining:
description: The number of remaining requests in the current period
schema:
type: integer
X-Rate-Limit-Reset:
description: The number of seconds left in the current period
schema:
type: integer
content:
application/json:
schema:
$ref: "#/components/schemas/Order"
application/xml:
schema:
$ref: "#/components/schemas/Order"
"400":
$ref: "#/components/responses/InvalidId"
"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
parameters:
- in: path
name: orderId
description: ID of the order that needs to be deleted
required: true
schema:
type: string
responses:
"400":
$ref: "#/components/responses/InvalidId"
"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
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/User"
description: Created user object
responses:
default:
description: successful operation
/users/createWithArray:
post:
tags:
- user
summary: Creates list of users with given input array
description: ""
operationId: createUsersWithArrayInput
requestBody:
$ref: "#/components/requestBodies/UserArray"
responses:
default:
description: successful operation
/users/createWithList:
post:
tags:
- user
summary: Creates list of users with given input array
description: ""
operationId: createUsersWithListInput
requestBody:
$ref: "#/components/requestBodies/UserArray"
responses:
default:
description: successful operation
/users/login:
get:
tags:
- user
summary: Logs user into the system
description: ""
operationId: loginUser
parameters:
- in: query
name: username
description: The user name for login
required: false
schema:
type: string
- in: query
name: password
description: The password for login in clear text
required: false
schema:
type: string
responses:
"200":
description: successful operation
headers:
X-Rate-Limit-Limit:
description: The number of allowed requests in the current period
schema:
type: integer
X-Rate-Limit-Remaining:
description: The number of remaining requests in the current period
schema:
type: integer
X-Rate-Limit-Reset:
description: The number of seconds left in the current period
schema:
type: integer
content:
application/json:
schema:
type: string
application/xml:
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
responses:
default:
description: successful operation
"/users/{username}":
get:
tags:
- user
summary: Get user by user name
description: ""
operationId: getUserByName
parameters:
- in: path
name: username
description: The name that needs to be fetched. Use user1 for testing.
required: true
schema:
type: string
responses:
"200":
description: successful operation
headers:
X-Rate-Limit-Limit:
description: The number of allowed requests in the current period
schema:
type: integer
X-Rate-Limit-Remaining:
description: The number of remaining requests in the current period
schema:
type: integer
X-Rate-Limit-Reset:
description: The number of seconds left in the current period
schema:
type: integer
content:
application/json:
schema:
$ref: "#/components/schemas/User"
application/xml:
schema:
$ref: "#/components/schemas/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
parameters:
- in: path
name: username
description: name that need to be deleted
required: true
schema:
type: string
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/User"
description: Updated user object
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
parameters:
- in: path
name: username
description: The name that needs to be deleted
required: true
schema:
type: string
responses:
"400":
description: Invalid username supplied
"404":
description: User not found
externalDocs:
description: Find out more about Swagger
url: http://swagger.io
servers:
- url: http://petstore.swagger.io/v2
components:
responses:
InvalidId:
description: Invalid ID supplied
requestBodies:
UserArray:
content:
application/json:
schema:
type: array
items:
$ref: "#/components/schemas/User"
description: List of user object
Pet:
content:
application/json:
schema:
$ref: "#/components/schemas/Pet"
application/xml:
schema:
$ref: "#/components/schemas/Pet"
description: Pet object that needs to be added to the store
securitySchemes:
api_key:
type: apiKey
name: api_key
in: header
description: This is another description
petstore_auth:
type: oauth2
description: This is a standard oauth flow
flows:
implicit:
authorizationUrl: http://petstore.swagger.io/api/oauth/dialog
scopes:
write_pets: modify pets in your account
read_pets: read your pets
schemas:
User:
type: object
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
Category:
type: object
properties:
id:
type: integer
format: int64
name:
type: string
description: The name of the category
minLength: 0
maxLength: 255
pattern: "[A-Za-zäöüÄÖÜß]{0,255}"
default: DefaultCategory
example: FoobarCategory
Pet:
type: object
required:
- name
- photoUrls
properties:
id:
type: integer
format: int64
category:
$ref: "#/components/schemas/Category"
name:
type: string
example: doggie
photoUrls:
type: array
items:
type: string
tags:
type: array
items:
$ref: "#/components/schemas/Tag"
status:
type: string
description: pet status in the store,
enum:
- Dead
- Alive
Tag:
type: object
properties:
id:
type: integer
format: int64
name:
type: string
Order:
type: object
properties:
id:
type: integer
format: int64
petId:
type: integer
format: int64
quantity:
type: integer
format: int32
minimum: 0
maximum: 10000
default: 0
example: 10
shipDate:
type: string
format: date-time
status:
type: string
description: Order Status
enum:
- Ordered
- Cancelled
complete:
type: boolean

87
publishing.gradle Normal file
View File

@@ -0,0 +1,87 @@
import java.text.SimpleDateFormat
Date buildTimeAndDate = new Date()
ext {
buildDate = new SimpleDateFormat('yyyy-MM-dd').format(buildTimeAndDate)
buildTime = new SimpleDateFormat('HH:mm:ss.SSSZ').format(buildTimeAndDate)
licenseUrl = 'https://github.com/Swagger2Markup/swagger2markup/blob/master/LICENSE.txt'
scmUrl = 'https://github.com/Swagger2Markup/swagger2markup.git'
}
def projectArtifactId = 'swagger2markup'
def projectUrl = 'https://github.com/Swagger2Markup/swagger2markup'
def licenseUrl = 'https://github.com/Swagger2Markup/swagger2markup/blob/master/LICENSE.txt'
def scmUrl = 'https://github.com/Swagger2Markup/swagger2markup.git'
def issuesUrl = 'https://github.com/Swagger2Markup/swagger2markup/issues'
jar {
manifest {
attributes(
'Built-By': 'Robert Winkler',
'Created-By': System.properties['java.version'] + " (" + System.properties['java.vendor'] + " " + System.properties['java.vm.version'] + ")",
'Build-Date': project.buildDate,
'Build-Time': project.buildTime,
'Specification-Title': projectArtifactId,
'Specification-Version': project.version,
'Implementation-Title': projectArtifactId,
'Implementation-Version': project.version
)
}
}
task sourcesJar(type: Jar) {
from sourceSets.main.allJava
archiveClassifier = 'sources'
}
task javadocJar(type: Jar) {
from javadoc
archiveClassifier = 'javadoc'
}
artifacts {
archives sourcesJar
archives javadocJar
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
pom.withXml {
def devs = ['RobWin': 'Robert Winkler',
'austek': 'Ali Ustek']
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', projectArtifactId)
root.appendNode('packaging', 'jar')
root.appendNode('url', projectUrl)
root.appendNode('description', project.description)
def license = root.appendNode('licenses').appendNode('license')
license.appendNode('name', 'Apache-2.0')
license.appendNode('url', licenseUrl)
license.appendNode('distribution', 'repo')
root.appendNode('scm').appendNode('url', scmUrl)
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
}
}
}

View File

@@ -1 +1,10 @@
rootProject.name = 'swagger2markup'
rootProject.name = 'swagger2markup'
include 'swagger2markup-asciidoc'
include 'swagger2markup-bom'
include 'swagger2markup-builder'
include 'swagger2markup-documentation'
include 'swagger2markup'
include 'swagger2markup-core'
include 'openapi2markup'

View File

@@ -1,5 +0,0 @@
This is a hand-written description.
AsciiDoc is better suited for descriptions than:
* JavaDoc
* Annotations

View File

@@ -1 +0,0 @@
This is a hand-written description. AsciiDoc is better suited for descriptions than *JavaDoc* and *Annotations*

View File

@@ -1 +0,0 @@
This is a hand-written description. AsciiDoc is better suited for descriptions than *JavaDoc* and *Annotations*

View File

@@ -1,2 +0,0 @@
This is a hand-written description.
AsciiDoc is better suited for descriptions than *JavaDoc* and *Annotations*

View File

@@ -1,5 +0,0 @@
This is a hand-written description.
AsciiDoc is better suited for descriptions than:
* JavaDoc
* Annotations

View File

@@ -1,5 +0,0 @@
This is a hand-written description.
AsciiDoc is better suited for descriptions than:
* JavaDoc
* Annotations

View File

@@ -1 +0,0 @@
This is a hand-written description. AsciiDoc is better suited for descriptions than *JavaDoc* and *Annotations*

View File

@@ -1 +0,0 @@
This is a hand-written description. AsciiDoc is better suited for descriptions than *JavaDoc* and *Annotations*

View File

@@ -1 +0,0 @@
This is a hand-written description. AsciiDoc is better suited for descriptions than *JavaDoc* and *Annotations*

View File

@@ -1,5 +0,0 @@
This is a hand-written description.
It is better suited for adding descriptions than:
* JavaDoc
* Annotations

View File

@@ -1,251 +0,0 @@
/*
*
* Copyright 2015 Robert Winkler
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*
*/
package io.github.robwin.swagger2markup;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.robwin.markup.builder.MarkupLanguage;
import io.github.robwin.swagger2markup.builder.document.DefinitionsDocument;
import io.github.robwin.swagger2markup.builder.document.OverviewDocument;
import io.github.robwin.swagger2markup.builder.document.PathsDocument;
import io.swagger.models.Swagger;
import io.swagger.parser.SwaggerParser;
import io.swagger.util.Json;
import io.swagger.util.Yaml;
import org.apache.commons.lang3.Validate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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 Swagger swagger;
private final MarkupLanguage markupLanguage;
private final String examplesFolderPath;
private final String schemasFolderPath;
private final String descriptionsFolderPath;
private final boolean separatedDefinitions;
private static final String OVERVIEW_DOCUMENT = "overview";
private static final String PATHS_DOCUMENT = "paths";
private static final String DEFINITIONS_DOCUMENT = "definitions";
/**
* @param markupLanguage the markup language which is used to generate the files
* @param swagger the Swagger object
* @param examplesFolderPath the folderPath where examples are stored
* @param schemasFolderPath the folderPath where (XML, JSON)-Schema files are stored
* @param descriptionsFolderPath the folderPath where descriptions are stored
* @param separatedDefinitions create separate definition files for each model definition.
*/
Swagger2MarkupConverter(MarkupLanguage markupLanguage, Swagger swagger, String examplesFolderPath, String schemasFolderPath, String descriptionsFolderPath, boolean separatedDefinitions){
this.markupLanguage = markupLanguage;
this.swagger = swagger;
this.examplesFolderPath = examplesFolderPath;
this.schemasFolderPath = schemasFolderPath;
this.descriptionsFolderPath = descriptionsFolderPath;
this.separatedDefinitions = separatedDefinitions;
}
/**
* 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 swagger the Swagger YAML or JSON String.
* @return a Swagger2MarkupConverter
* @throws java.io.IOException if String can not be parsed
*/
public static Builder fromString(String swagger) throws IOException {
Validate.notEmpty(swagger, "swagger must not be null!");
ObjectMapper mapper;
if(swagger.trim().startsWith("{")) {
mapper = Json.mapper();
}else {
mapper = Yaml.mapper();
}
JsonNode rootNode = mapper.readTree(swagger);
// must have swagger node set
JsonNode swaggerNode = rootNode.get("swagger");
if(swaggerNode == null)
throw new IllegalArgumentException("Swagger String is in the wrong format");
return new Builder(mapper.convertValue(rootNode, Swagger.class));
}
/**
* Builds the document with the given markup language and stores
* the files in the given folder.
*
* @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(swagger, markupLanguage).build().writeToFile(directory, OVERVIEW_DOCUMENT, StandardCharsets.UTF_8);
new PathsDocument(swagger, markupLanguage, examplesFolderPath, descriptionsFolderPath).build().writeToFile(directory, PATHS_DOCUMENT, StandardCharsets.UTF_8);
new DefinitionsDocument(swagger, markupLanguage, schemasFolderPath, descriptionsFolderPath, separatedDefinitions, directory).build().writeToFile(directory, DEFINITIONS_DOCUMENT, StandardCharsets.UTF_8);
}
/**
* Returns all documents as a String
* @return a the document as a String
*/
private String buildDocuments() throws IOException {
return new OverviewDocument(swagger, markupLanguage).build().toString().concat(
new PathsDocument(swagger, markupLanguage, examplesFolderPath, schemasFolderPath).build().toString()
.concat(new DefinitionsDocument(swagger, markupLanguage, schemasFolderPath, schemasFolderPath, false, null).build().toString()));
}
public static class Builder{
private final Swagger swagger;
private String examplesFolderPath;
private String schemasFolderPath;
private String descriptionsFolderPath;
private boolean separatedDefinitions;
private MarkupLanguage markupLanguage = MarkupLanguage.ASCIIDOC;
/**
* 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(markupLanguage, swagger, examplesFolderPath, schemasFolderPath, descriptionsFolderPath, separatedDefinitions);
}
/**
* 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;
}
}
}

View File

@@ -1,310 +0,0 @@
/*
*
* 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.swagger.models.ComposedModel;
import io.swagger.models.Model;
import io.swagger.models.RefModel;
import io.swagger.models.Swagger;
import io.swagger.models.properties.Property;
import io.github.robwin.markup.builder.MarkupLanguage;
import io.github.robwin.swagger2markup.utils.PropertyUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.*;
/**
* @author Robert Winkler
*/
public class DefinitionsDocument extends MarkupDocument {
private static final String DEFINITIONS = "Definitions";
private static final List<String> IGNORED_DEFINITIONS = Collections.singletonList("Void");
private static final String JSON_SCHEMA = "JSON Schema";
private static final String XML_SCHEMA = "XML Schema";
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;
public DefinitionsDocument(Swagger swagger, MarkupLanguage markupLanguage, String schemasFolderPath, String descriptionsFolderPath, boolean separatedDefinitionsEnabled, String outputDirectory){
super(swagger, markupLanguage);
if(StringUtils.isNotBlank(schemasFolderPath)){
this.schemasEnabled = true;
this.schemasFolderPath = schemasFolderPath;
}
if(StringUtils.isNotBlank(descriptionsFolderPath)){
this.handWrittenDescriptionsEnabled = true;
this.descriptionsFolderPath = descriptionsFolderPath + "/" + DEFINITIONS.toLowerCase();
}
if(schemasEnabled){
if (logger.isDebugEnabled()) {
logger.debug("Include schemas is enabled.");
}
}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 = separatedDefinitionsEnabled;
if(this.separatedDefinitionsEnabled){
if (logger.isDebugEnabled()) {
logger.debug("Create separated definition files is enabled.");
}
Validate.notEmpty(outputDirectory, "Output directory is required for separated definition files!");
}else{
if (logger.isDebugEnabled()) {
logger.debug("Create separated definition files is disabled.");
}
}
this.outputDirectory = outputDirectory;
}
@Override
public MarkupDocument build() throws IOException {
definitions(swagger.getDefinitions(), 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) throws IOException {
if(MapUtils.isNotEmpty(definitions)){
docBuilder.sectionTitleLevel1(DEFINITIONS);
for(Map.Entry<String, Model> definitionsEntry : definitions.entrySet()){
String definitionName = definitionsEntry.getKey();
if(StringUtils.isNotBlank(definitionName)) {
if (checkThatDefinitionIsNotInIgnoreList(definitionName)) {
definition(definitions, definitionName, definitionsEntry.getValue(), docBuilder);
definitionSchema(definitionName, docBuilder);
if (separatedDefinitionsEnabled) {
MarkupDocBuilder defDocBuilder = MarkupDocBuilders.documentBuilder(markupLanguage);
definition(definitions, definitionName, definitionsEntry.getValue(), defDocBuilder);
definitionSchema(definitionName, defDocBuilder);
defDocBuilder.writeToFile(outputDirectory, definitionName.toLowerCase(), StandardCharsets.UTF_8);
if (logger.isInfoEnabled()) {
logger.info("Separate definition file produced: {}", definitionName);
}
}
if (logger.isInfoEnabled()) {
logger.info("Definition processed: {}", definitionName);
}
}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) throws IOException {
docBuilder.sectionTitleLevel2(definitionName);
descriptionSection(definitionName, model, docBuilder);
propertiesSection(definitions, definitionName, model, docBuilder);
}
private void propertiesSection(Map<String, Model> definitions, String definitionName, Model model, MarkupDocBuilder docBuilder) throws IOException {
Map<String, Property> properties = getAllProperties(definitions, model);
List<String> headerAndContent = new ArrayList<>();
List<String> header = Arrays.asList(NAME_COLUMN, DESCRIPTION_COLUMN, REQUIRED_COLUMN, SCHEMA_COLUMN, DEFAULT_COLUMN);
headerAndContent.add(StringUtils.join(header, DELIMITER));
if(MapUtils.isNotEmpty(properties)){
for (Map.Entry<String, Property> propertyEntry : properties.entrySet()) {
Property property = propertyEntry.getValue();
String propertyName = propertyEntry.getKey();
List<String> content = Arrays.asList(
propertyName,
propertyDescription(definitionName, propertyName, property),
Boolean.toString(property.getRequired()),
PropertyUtils.getType(property, markupLanguage),
PropertyUtils.getDefaultValue(property));
headerAndContent.add(StringUtils.join(content, DELIMITER));
}
docBuilder.tableWithHeaderRow(headerAndContent);
}
}
private Map<String, Property> getAllProperties(Map<String, Model> definitions, Model model) {
if(model instanceof RefModel) {
final String ref = model.getReference();
return definitions.containsKey(ref)
? getAllProperties(definitions, definitions.get(model.getReference()))
: null;
}
if(model instanceof ComposedModel) {
ComposedModel composedModel = (ComposedModel)model;
ImmutableMap.Builder<String, Property> allProperties = ImmutableMap.builder();
if(composedModel.getAllOf() != null) {
for(Model innerModel : composedModel.getAllOf()) {
Map<String, Property> innerProperties = getAllProperties(definitions, innerModel);
if(innerProperties != null) {
allProperties.putAll(innerProperties);
}
}
}
return allProperties.build();
}
else {
return model.getProperties();
}
}
private void descriptionSection(String definitionName, Model model, MarkupDocBuilder docBuilder) throws IOException {
if(handWrittenDescriptionsEnabled){
String description = handWrittenPathDescription(definitionName.toLowerCase(), DESCRIPTION_FILE_NAME);
if(StringUtils.isNotBlank(description)){
docBuilder.paragraph(description);
}else{
if (logger.isInfoEnabled()) {
logger.info("Hand-written description cannot be read. Trying to use description from Swagger source.");
}
modelDescription(model, docBuilder);
}
}
else{
modelDescription(model, docBuilder);
}
}
private void modelDescription(Model model, MarkupDocBuilder docBuilder) {
String description = model.getDescription();
if (StringUtils.isNotBlank(description)) {
docBuilder.paragraph(description);
}
}
private String propertyDescription(String definitionName, String propertyName, Property property) throws IOException {
String description;
if(handWrittenDescriptionsEnabled){
description = handWrittenPathDescription(definitionName.toLowerCase() + "/" + propertyName.toLowerCase(), DESCRIPTION_FILE_NAME);
if(StringUtils.isBlank(description)) {
if (logger.isInfoEnabled()) {
logger.info("Hand-written description file cannot be read. Trying to use description from Swagger source.");
}
description = StringUtils.defaultString(property.getDescription());
}
}
else{
description = StringUtils.defaultString(property.getDescription());
}
return description;
}
/**
* Reads a hand-written description
*
* @param descriptionFolder the name of the folder where the description file resides
* @param descriptionFileName the name of the description file
* @return the content of the file
* @throws IOException
*/
private String handWrittenPathDescription(String descriptionFolder, String descriptionFileName) throws IOException {
for (String fileNameExtension : markupLanguage.getFileNameExtensions()) {
java.nio.file.Path path = Paths.get(descriptionsFolderPath, descriptionFolder, descriptionFileName + fileNameExtension);
if (Files.isReadable(path)) {
if (logger.isInfoEnabled()) {
logger.info("Description file processed: {}", path);
}
return FileUtils.readFileToString(path.toFile(), StandardCharsets.UTF_8).trim();
} else {
if (logger.isDebugEnabled()) {
logger.debug("Description file is not readable: {}", path);
}
}
}
if (logger.isWarnEnabled()) {
logger.info("No description file found with correct file name extension in folder: {}", Paths.get(descriptionsFolderPath, descriptionFolder));
}
return null;
}
private void definitionSchema(String definitionName, MarkupDocBuilder docBuilder) throws IOException {
if(schemasEnabled) {
if (StringUtils.isNotBlank(definitionName)) {
schema(JSON_SCHEMA, schemasFolderPath, definitionName + JSON_SCHEMA_EXTENSION, JSON, docBuilder);
schema(XML_SCHEMA, schemasFolderPath, definitionName + XML_SCHEMA_EXTENSION, XML, docBuilder);
}
}
}
private void schema(String title, String schemasFolderPath, String schemaName, String language, MarkupDocBuilder docBuilder) throws IOException {
java.nio.file.Path path = Paths.get(schemasFolderPath, schemaName);
if (Files.isReadable(path)) {
docBuilder.sectionTitleLevel3(title);
docBuilder.source(FileUtils.readFileToString(path.toFile(), StandardCharsets.UTF_8).trim(), language);
if (logger.isInfoEnabled()) {
logger.info("Schema file processed: {}", path);
}
} else {
if (logger.isDebugEnabled()) {
logger.debug("Schema file is not readable: {}", path);
}
}
}
}

View File

@@ -1,83 +0,0 @@
/*
*
* 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.swagger.models.Swagger;
import io.github.robwin.markup.builder.MarkupDocBuilder;
import io.github.robwin.markup.builder.MarkupDocBuilders;
import io.github.robwin.markup.builder.MarkupLanguage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.nio.charset.Charset;
/**
* @author Robert Winkler
*/
public abstract class MarkupDocument {
protected static final String DELIMITER = "|";
protected static final String DEFAULT_COLUMN = "Default";
protected static final String REQUIRED_COLUMN = "Required";
protected static final String SCHEMA_COLUMN = "Schema";
protected static final String NAME_COLUMN = "Name";
protected static final String DESCRIPTION_COLUMN = "Description";
protected static final String DESCRIPTION = DESCRIPTION_COLUMN;
protected static final String PRODUCES = "Produces";
protected static final String CONSUMES = "Consumes";
protected static final String TAGS = "Tags";
protected Logger logger = LoggerFactory.getLogger(getClass());
protected Swagger swagger;
protected MarkupLanguage markupLanguage;
protected MarkupDocBuilder markupDocBuilder;
MarkupDocument(Swagger swagger, MarkupLanguage markupLanguage){
this.swagger = swagger;
this.markupLanguage = markupLanguage;
this.markupDocBuilder = MarkupDocBuilders.documentBuilder(markupLanguage);
}
/**
* 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);
}
}

View File

@@ -1,153 +0,0 @@
/*
*
* 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.swagger.models.*;
import io.github.robwin.markup.builder.MarkupLanguage;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class OverviewDocument extends MarkupDocument {
private static final String OVERVIEW = "Overview";
private static final String CURRENT_VERSION = "Version information";
private static final String VERSION = "Version: ";
private static final String CONTACT_INFORMATION = "Contact information";
private static final String CONTACT_NAME = "Contact: ";
private static final String CONTACT_EMAIL = "Contact Email: ";
private static final String LICENSE_INFORMATION = "License information";
private static final String LICENSE = "License: ";
private static final String LICENSE_URL = "License URL: ";
private static final String TERMS_OF_SERVICE = "Terms of service: ";
private static final String URI_SCHEME = "URI scheme";
private static final String HOST = "Host: ";
private static final String BASE_PATH = "BasePath: ";
private static final String SCHEMES = "Schemes: ";
public OverviewDocument(Swagger swagger, MarkupLanguage markupLanguage){
super(swagger, markupLanguage);
}
/**
* Builds the MarkupDocument.
*
* @return the built MarkupDocument
* @throws java.io.IOException if the files to include are not readable
*/
@Override
public MarkupDocument build() throws IOException {
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(StringUtils.isNotBlank(info.getDescription())){
this.markupDocBuilder.textLine(info.getDescription());
this.markupDocBuilder.newLine();
}
if(StringUtils.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(StringUtils.isNotBlank(contact.getName())){
this.markupDocBuilder.textLine(CONTACT_NAME + contact.getName());
}
if(StringUtils.isNotBlank(contact.getEmail())){
this.markupDocBuilder.textLine(CONTACT_EMAIL + contact.getEmail());
}
this.markupDocBuilder.newLine();
}
License license = info.getLicense();
if(license != null && (StringUtils.isNotBlank(license.getName()) || StringUtils.isNotBlank(license.getUrl()))) {
this.markupDocBuilder.sectionTitleLevel2(LICENSE_INFORMATION);
if (StringUtils.isNotBlank(license.getName())) {
this.markupDocBuilder.textLine(LICENSE + license.getName());
}
if (StringUtils.isNotBlank(license.getUrl())) {
this.markupDocBuilder.textLine(LICENSE_URL + license.getUrl());
}
this.markupDocBuilder.newLine();
}
if(StringUtils.isNotBlank(info.getTermsOfService())){
this.markupDocBuilder.textLine(TERMS_OF_SERVICE + info.getTermsOfService());
this.markupDocBuilder.newLine();
}
this.markupDocBuilder.sectionTitleLevel2(URI_SCHEME);
if(StringUtils.isNotBlank(swagger.getHost())){
this.markupDocBuilder.textLine(HOST + swagger.getHost());
}
if(StringUtils.isNotBlank(swagger.getBasePath())){
this.markupDocBuilder.textLine(BASE_PATH + swagger.getBasePath());
}
if(CollectionUtils.isNotEmpty(swagger.getSchemes())){
List<String> schemes = new ArrayList<>();
for(Scheme scheme : swagger.getSchemes()){
schemes.add(scheme.toString());
}
this.markupDocBuilder.textLine(SCHEMES + StringUtils.join(schemes, ", "));
}
this.markupDocBuilder.newLine();
if(CollectionUtils.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(StringUtils.isNoneBlank(description)){
tags.add(name + ": " + description);
}
tags.add(name);
}
this.markupDocBuilder.unorderedList(tags);
this.markupDocBuilder.newLine();
}
if(CollectionUtils.isNotEmpty(swagger.getConsumes())){
this.markupDocBuilder.sectionTitleLevel2(CONSUMES);
this.markupDocBuilder.unorderedList(swagger.getConsumes());
this.markupDocBuilder.newLine();
}
if(CollectionUtils.isNotEmpty(swagger.getProduces())){
this.markupDocBuilder.sectionTitleLevel2(PRODUCES);
this.markupDocBuilder.unorderedList(swagger.getProduces());
this.markupDocBuilder.newLine();
}
}
}

View File

@@ -1,381 +0,0 @@
/*
*
* 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.swagger.models.Operation;
import io.swagger.models.Path;
import io.swagger.models.Response;
import io.swagger.models.Swagger;
import io.swagger.models.parameters.Parameter;
import io.swagger.models.properties.Property;
import io.github.robwin.markup.builder.MarkupLanguage;
import io.github.robwin.swagger2markup.utils.ParameterUtils;
import io.github.robwin.swagger2markup.utils.PropertyUtils;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.text.WordUtils;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
/**
* @author Robert Winkler
*/
public class PathsDocument extends MarkupDocument {
private static final String PATHS = "Paths";
private static final String PARAMETERS = "Parameters";
private static final String RESPONSES = "Responses";
private static final String EXAMPLE_CURL = "Example CURL request";
private static final String EXAMPLE_REQUEST = "Example HTTP request";
private static final String EXAMPLE_RESPONSE = "Example HTTP response";
private static final String TYPE_COLUMN = "Type";
private static final String HTTP_CODE_COLUMN = "HTTP Code";
private static final String REQUEST_EXAMPLE_FILE_NAME = "http-request";
private static final String RESPONSE_EXAMPLE_FILE_NAME = "http-response";
private static final String CURL_EXAMPLE_FILE_NAME = "curl-request";
private static final String DESCRIPTION_FILE_NAME = "description";
private static final String PARAMETER = "Parameter";
private boolean examplesEnabled;
private String examplesFolderPath;
private boolean handWrittenDescriptionsEnabled;
private String descriptionsFolderPath;
public PathsDocument(Swagger swagger, MarkupLanguage markupLanguage, String examplesFolderPath, String descriptionsFolderPath){
super(swagger, markupLanguage);
if(StringUtils.isNotBlank(examplesFolderPath)){
this.examplesEnabled = true;
this.examplesFolderPath = examplesFolderPath;
}
if(StringUtils.isNotBlank(descriptionsFolderPath)){
this.handWrittenDescriptionsEnabled = true;
this.descriptionsFolderPath = descriptionsFolderPath + "/" + PATHS.toLowerCase();
}
if(examplesEnabled){
if (logger.isDebugEnabled()) {
logger.debug("Include examples is enabled.");
}
}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.");
}
}
}
@Override
public MarkupDocument build() throws IOException {
paths();
return this;
}
/**
* Builds all paths of the Swagger model
*/
private void paths() throws IOException {
Map<String, Path> paths = swagger.getPaths();
if(MapUtils.isNotEmpty(paths)) {
this.markupDocBuilder.sectionTitleLevel1(PATHS);
for (Map.Entry<String, Path> entry : paths.entrySet()) {
Path path = entry.getValue();
if(path != null) {
path("GET", entry.getKey(), path.getGet());
path("PUT", entry.getKey(), path.getPut());
path("DELETE", entry.getKey(), path.getDelete());
path("POST", entry.getKey(), path.getPost());
path("PATCH", entry.getKey(), path.getPatch());
}
}
}
}
/**
* Builds a path
*
* @param httpMethod the HTTP method of the path
* @param resourcePath the URL of the path
* @param operation the Swagger Operation
*/
private void path(String httpMethod, String resourcePath, Operation operation) throws IOException {
if(operation != null){
pathTitle(httpMethod, resourcePath, operation);
descriptionSection(operation);
parametersSection(operation);
responsesSection(operation);
consumesSection(operation);
producesSection(operation);
tagsSection(operation);
examplesSection(operation);
}
}
private void pathTitle(String httpMethod, String resourcePath, Operation operation) {
String summary = operation.getSummary();
String title;
if(StringUtils.isNotBlank(summary)) {
title = summary;
this.markupDocBuilder.sectionTitleLevel2(title);
this.markupDocBuilder.listing(httpMethod + " " + resourcePath);
}else{
title = httpMethod + " " + resourcePath;
this.markupDocBuilder.sectionTitleLevel2(title);
}
if (logger.isInfoEnabled()) {
logger.info("Path processed: {}", title);
}
}
private void descriptionSection(Operation operation) throws IOException {
if(handWrittenDescriptionsEnabled){
String summary = operation.getSummary();
if(StringUtils.isNotBlank(summary)) {
String operationFolder = summary.replace(".", "").replace(" ", "_").toLowerCase();
String description = handWrittenPathDescription(operationFolder, DESCRIPTION_FILE_NAME);
if(StringUtils.isNotBlank(description)){
this.markupDocBuilder.sectionTitleLevel3(DESCRIPTION);
this.markupDocBuilder.paragraph(description);
}else{
if (logger.isInfoEnabled()) {
logger.info("Hand-written description cannot be read. Trying to use description from Swagger source.");
}
pathDescription(operation);
}
}else{
if (logger.isInfoEnabled()) {
logger.info("Hand-written description cannot be read, because summary of operation is empty. Trying to use description from Swagger source.");
}
pathDescription(operation);
}
}else {
pathDescription(operation);
}
}
private void pathDescription(Operation operation) {
String description = operation.getDescription();
if (StringUtils.isNotBlank(description)) {
this.markupDocBuilder.sectionTitleLevel3(DESCRIPTION);
this.markupDocBuilder.paragraph(description);
}
}
private void parametersSection(Operation operation) throws IOException {
List<Parameter> parameters = operation.getParameters();
if(CollectionUtils.isNotEmpty(parameters)){
List<String> headerAndContent = new ArrayList<>();
// Table header row
List<String> header = Arrays.asList(TYPE_COLUMN, NAME_COLUMN, DESCRIPTION_COLUMN, REQUIRED_COLUMN, SCHEMA_COLUMN, DEFAULT_COLUMN);
headerAndContent.add(StringUtils.join(header, DELIMITER));
for(Parameter parameter : parameters){
String type = ParameterUtils.getType(parameter, markupLanguage);
String parameterType = WordUtils.capitalize(parameter.getIn() + PARAMETER);
// Table content row
List<String> content = Arrays.asList(
parameterType,
parameter.getName(),
parameterDescription(operation, parameter),
Boolean.toString(parameter.getRequired()), type,
ParameterUtils.getDefaultValue(parameter));
headerAndContent.add(StringUtils.join(content, DELIMITER));
}
this.markupDocBuilder.sectionTitleLevel3(PARAMETERS);
this.markupDocBuilder.tableWithHeaderRow(headerAndContent);
}
}
private String parameterDescription(Operation operation, Parameter parameter) throws IOException {
String description;
if(handWrittenDescriptionsEnabled){
String summary = operation.getSummary();
String operationFolder = summary.replace(".", "").replace(" ", "_").toLowerCase();
String parameterName = parameter.getName();
if(StringUtils.isNotBlank(operationFolder) && StringUtils.isNotBlank(parameterName)) {
description = handWrittenPathDescription(operationFolder + "/" + parameterName, DESCRIPTION_FILE_NAME);
if(StringUtils.isBlank(description)) {
if (logger.isInfoEnabled()) {
logger.info("Hand-written description file cannot be read. Trying to use description from Swagger source.");
}
description = StringUtils.defaultString(parameter.getDescription());
}
}else{
if (logger.isInfoEnabled()) {
logger.info("Hand-written description file cannot be read, because summary of operation or name of parameter is empty. Trying to use description from Swagger source.");
}
description = StringUtils.defaultString(parameter.getDescription());
}
}else {
description = StringUtils.defaultString(parameter.getDescription());
}
return description;
}
private void consumesSection(Operation operation) {
List<String> consumes = operation.getConsumes();
if(CollectionUtils.isNotEmpty(consumes)){
this.markupDocBuilder.sectionTitleLevel3(CONSUMES);
this.markupDocBuilder.unorderedList(consumes);
}
}
private void producesSection(Operation operation) {
List<String> produces = operation.getProduces();
if(CollectionUtils.isNotEmpty(produces)){
this.markupDocBuilder.sectionTitleLevel3(PRODUCES);
this.markupDocBuilder.unorderedList(produces);
}
}
private void tagsSection(Operation operation) {
List<String> tags = operation.getTags();
if(CollectionUtils.isNotEmpty(tags)){
this.markupDocBuilder.sectionTitleLevel3(TAGS);
this.markupDocBuilder.unorderedList(tags);
}
}
/**
* Builds the example section of a Swagger Operation
*
* @param operation the Swagger Operation
* @throws IOException if the example file is not readable
*/
private void examplesSection(Operation operation) throws IOException {
if(examplesEnabled){
String summary = operation.getSummary();
if(StringUtils.isNotBlank(summary)) {
String exampleFolder = summary.replace(".", "").replace(" ", "_").toLowerCase();
String curlExample = example(exampleFolder, CURL_EXAMPLE_FILE_NAME);
if(StringUtils.isNotBlank(curlExample)){
this.markupDocBuilder.sectionTitleLevel3(EXAMPLE_CURL);
this.markupDocBuilder.paragraph(curlExample);
}
String requestExample = example(exampleFolder, REQUEST_EXAMPLE_FILE_NAME);
if(StringUtils.isNotBlank(requestExample)){
this.markupDocBuilder.sectionTitleLevel3(EXAMPLE_REQUEST);
this.markupDocBuilder.paragraph(requestExample);
}
String responseExample = example(exampleFolder, RESPONSE_EXAMPLE_FILE_NAME);
if(StringUtils.isNotBlank(responseExample)){
this.markupDocBuilder.sectionTitleLevel3(EXAMPLE_RESPONSE);
this.markupDocBuilder.paragraph(responseExample);
}
}else{
if (logger.isWarnEnabled()) {
logger.warn("Example file cannot be read, because summary of operation is empty.");
}
}
}
}
/**
* 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
* @throws IOException
*/
private String example(String exampleFolder, String exampleFileName) throws IOException {
for (String fileNameExtension : markupLanguage.getFileNameExtensions()) {
java.nio.file.Path path = Paths.get(examplesFolderPath, exampleFolder, exampleFileName + fileNameExtension);
if (Files.isReadable(path)) {
if (logger.isInfoEnabled()) {
logger.info("Example file processed: {}", path);
}
return FileUtils.readFileToString(path.toFile(), StandardCharsets.UTF_8).trim();
} else {
if (logger.isDebugEnabled()) {
logger.debug("Example file is not readable: {}", path);
}
}
}
if (logger.isWarnEnabled()) {
logger.info("No example file found with correct file name extension in folder: {}", Paths.get(examplesFolderPath, exampleFolder));
}
return null;
}
/**
* Reads a hand-written description
*
* @param descriptionFolder the name of the folder where the description file resides
* @param descriptionFileName the name of the description file
* @return the content of the file
* @throws IOException
*/
private String handWrittenPathDescription(String descriptionFolder, String descriptionFileName) throws IOException {
for (String fileNameExtension : markupLanguage.getFileNameExtensions()) {
java.nio.file.Path path = Paths.get(descriptionsFolderPath, descriptionFolder, descriptionFileName + fileNameExtension);
if (Files.isReadable(path)) {
if (logger.isInfoEnabled()) {
logger.info("Description file processed: {}", path);
}
return FileUtils.readFileToString(path.toFile(), StandardCharsets.UTF_8).trim();
} else {
if (logger.isDebugEnabled()) {
logger.debug("Description file is not readable: {}", path);
}
}
}
if (logger.isWarnEnabled()) {
logger.info("No description file found with correct file name extension in folder: {}", Paths.get(descriptionsFolderPath, descriptionFolder));
}
return null;
}
private void responsesSection(Operation operation) {
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");
}
}
this.markupDocBuilder.sectionTitleLevel3(RESPONSES);
this.markupDocBuilder.tableWithHeaderRow(csvContent);
}
}
}

View File

@@ -1,45 +0,0 @@
/*
*
* 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 {
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";
}
}

View File

@@ -1,92 +0,0 @@
/*
*
* 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.Model;
import io.swagger.models.parameters.AbstractSerializableParameter;
import io.swagger.models.parameters.BodyParameter;
import io.swagger.models.parameters.Parameter;
import io.swagger.models.parameters.RefParameter;
import io.github.robwin.markup.builder.MarkupLanguage;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate;
import java.util.List;
public final class ParameterUtils {
public static String getType(Parameter parameter, MarkupLanguage markupLanguage){
Validate.notNull(parameter, "property must not be null!");
String type = "NOT FOUND";
if(parameter instanceof BodyParameter){
BodyParameter bodyParameter = (BodyParameter)parameter;
Model model = bodyParameter.getSchema();
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" + " (" + StringUtils.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 StringUtils.defaultString(type);
}
private static String getTypeWithFormat(String typeWithoutFormat, String format) {
String type;
if(StringUtils.isNotBlank(format)){
type = StringUtils.defaultString(typeWithoutFormat) + " (" + format + ")";
}else{
type = StringUtils.defaultString(typeWithoutFormat);
}
return type;
}
public static String getDefaultValue(Parameter parameter){
Validate.notNull(parameter, "property must not be null!");
String defaultValue = "";
if(parameter instanceof AbstractSerializableParameter){
AbstractSerializableParameter serializableParameter = (AbstractSerializableParameter)parameter;
defaultValue = serializableParameter.getDefaultValue();
}
return StringUtils.defaultString(defaultValue);
}
}

View File

@@ -1,93 +0,0 @@
/*
*
* 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.properties.*;
import io.github.robwin.markup.builder.MarkupLanguage;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate;
import java.util.List;
import java.util.Objects;
public final class PropertyUtils {
public static String getType(Property property, MarkupLanguage markupLanguage){
Validate.notNull(property, "property must not be null!");
String type;
if(property instanceof RefProperty){
RefProperty refProperty = (RefProperty)property;
switch (markupLanguage){
case ASCIIDOC: return "<<" + refProperty.getSimpleRef() + ">>";
default: return refProperty.getSimpleRef();
}
}else if(property instanceof ArrayProperty){
ArrayProperty arrayProperty = (ArrayProperty)property;
Property items = arrayProperty.getItems();
type = getType(items, markupLanguage) + " " + arrayProperty.getType();
}else if(property instanceof StringProperty){
StringProperty stringProperty = (StringProperty)property;
List<String> enums = stringProperty.getEnum();
if(CollectionUtils.isNotEmpty(enums)){
type = "enum" + " (" + StringUtils.join(enums, ", ") + ")";
}else{
type = property.getType();
}
}
else{
if(StringUtils.isNotBlank(property.getFormat())){
type = StringUtils.defaultString(property.getType()) + " (" + property.getFormat() + ")";
}else{
type = property.getType();
}
}
return StringUtils.defaultString(type);
}
public static String getDefaultValue(Property property){
Validate.notNull(property, "property must not be null!");
String defaultValue = "";
if(property instanceof BooleanProperty){
BooleanProperty booleanProperty = (BooleanProperty)property;
defaultValue = Objects.toString(booleanProperty.getDefault(), "");
}else if(property instanceof StringProperty){
StringProperty stringProperty = (StringProperty)property;
defaultValue = Objects.toString(stringProperty.getDefault(), "");
}else if(property instanceof DoubleProperty){
DoubleProperty doubleProperty = (DoubleProperty)property;
defaultValue = Objects.toString(doubleProperty.getDefault(), "");
}else if(property instanceof FloatProperty){
FloatProperty floatProperty = (FloatProperty)property;
defaultValue = Objects.toString(floatProperty.getDefault(), "");
}else if(property instanceof IntegerProperty){
IntegerProperty integerProperty = (IntegerProperty)property;
defaultValue = Objects.toString(integerProperty.getDefault(), "");
}
else if(property instanceof LongProperty){
LongProperty longProperty = (LongProperty)property;
defaultValue = Objects.toString(longProperty.getDefault(), "");
}
else if(property instanceof UUIDProperty){
UUIDProperty uuidProperty = (UUIDProperty)property;
defaultValue = Objects.toString(uuidProperty.getDefault(), "");
}
return defaultValue;
}
}

View File

@@ -1,278 +0,0 @@
/*
*
* 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.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.BDDAssertions.assertThat;
public class Swagger2MarkupConverterTest {
@Test
public void testSwagger2AsciiDocConversion() throws IOException {
//Given
File file = new File(Swagger2MarkupConverterTest.class.getResource("/json/swagger.json").getFile());
File outputDirectory = new File("build/docs/asciidoc/generated");
FileUtils.deleteQuietly(outputDirectory);
//When
Swagger2MarkupConverter.from(file.getAbsolutePath()).build()
.intoFolder(outputDirectory.getAbsolutePath());
//Then
String[] directories = outputDirectory.list();
assertThat(directories).hasSize(3).containsAll(asList("definitions.adoc", "overview.adoc", "paths.adoc"));
}
@Test
public void testOldSwaggerSpec2AsciiDocConversion() throws IOException {
//Given
File file = new File(Swagger2MarkupConverterTest.class.getResource("/json/swagger_12.json").getFile());
File outputDirectory = new File("build/docs/asciidoc/generated");
FileUtils.deleteQuietly(outputDirectory);
//When
Swagger2MarkupConverter.from(file.getAbsolutePath()).build()
.intoFolder(outputDirectory.getAbsolutePath());
//Then
String[] directories = outputDirectory.list();
assertThat(directories).hasSize(3).containsAll(asList("definitions.adoc", "overview.adoc", "paths.adoc"));
}
@Test
public void testSwagger2AsciiDocConversionWithDescriptionsAndExamples() throws IOException {
//Given
File file = new File(Swagger2MarkupConverterTest.class.getResource("/json/swagger.json").getFile());
File outputDirectory = new File("build/docs/asciidoc/generated");
FileUtils.deleteQuietly(outputDirectory);
//When
Swagger2MarkupConverter.from(file.getAbsolutePath()).withDescriptions("src/docs/asciidoc")
.withExamples("src/docs/asciidoc/paths").build()
.intoFolder(outputDirectory.getAbsolutePath());
//Then
String[] directories = outputDirectory.list();
assertThat(directories).hasSize(3).containsAll(asList("definitions.adoc", "overview.adoc", "paths.adoc"));
}
@Test
public void testSwagger2MarkdownConversion() throws IOException {
//Given
File file = new File(Swagger2MarkupConverterTest.class.getResource("/json/swagger.json").getFile());
File outputDirectory = new File("build/docs/markdown/generated");
FileUtils.deleteQuietly(outputDirectory);
//When
Swagger2MarkupConverter.from(file.getAbsolutePath()).
withMarkupLanguage(MarkupLanguage.MARKDOWN).build()
.intoFolder(outputDirectory.getAbsolutePath());
//Then
String[] directories = outputDirectory.list();
assertThat(directories).hasSize(3).containsAll(asList("definitions.md", "overview.md", "paths.md"));
}
@Test
public void testSwagger2MarkdownConversionWithDescriptions() throws IOException {
//Given
File file = new File(Swagger2MarkupConverterTest.class.getResource("/json/swagger.json").getFile());
File outputDirectory = new File("build/docs/markdown/generated");
FileUtils.deleteQuietly(outputDirectory);
//When
Swagger2MarkupConverter.from(file.getAbsolutePath()).withDescriptions("src/docs/markdown").
withMarkupLanguage(MarkupLanguage.MARKDOWN).build()
.intoFolder(outputDirectory.getAbsolutePath());
//Then
String[] directories = outputDirectory.list();
assertThat(directories).hasSize(3).containsAll(asList("definitions.md", "overview.md", "paths.md"));
}
@Test
public void testSwagger2AsciiDocConversionWithSeparatedDefinitions() throws IOException {
//Given
File file = new File(Swagger2MarkupConverterTest.class.getResource("/json/swagger.json").getFile());
File outputDirectory = new File("build/docs/asciidoc/generated");
FileUtils.deleteQuietly(outputDirectory);
//When
Swagger2MarkupConverter.from(file.getAbsolutePath()).withSeparatedDefinitions().build()
.intoFolder(outputDirectory.getAbsolutePath());
//Then
String[] directories = outputDirectory.list();
assertThat(directories).hasSize(9).containsAll(
asList("definitions.adoc", "overview.adoc", "paths.adoc", "identified.adoc",
"user.adoc", "category.adoc", "pet.adoc", "tag.adoc", "order.adoc"));
assertThat(new String(Files.readAllBytes(Paths.get(outputDirectory + File.separator + "definitions.adoc"))))
.contains(new String(Files.readAllBytes(Paths.get(outputDirectory + File.separator + "user.adoc"))));
}
@Test
public void testSwagger2MarkdownConversionWithSeparatedDefinitions() throws IOException {
//Given
File file = new File(Swagger2MarkupConverterTest.class.getResource("/json/swagger.json").getFile());
File outputDirectory = new File("build/docs/asciidoc/generated");
FileUtils.deleteQuietly(outputDirectory);
//When
Swagger2MarkupConverter.from(file.getAbsolutePath()).withSeparatedDefinitions().
withMarkupLanguage(MarkupLanguage.MARKDOWN).build()
.intoFolder(outputDirectory.getAbsolutePath());
//Then
String[] directories = outputDirectory.list();
assertThat(directories).hasSize(9).containsAll(
asList("definitions.md", "overview.md", "paths.md", "identified.md",
"user.md", "category.md", "pet.md", "tag.md", "order.md"));
assertThat(new String(Files.readAllBytes(Paths.get(outputDirectory + File.separator + "definitions.md"))))
.contains(new String(Files.readAllBytes(Paths.get(outputDirectory + File.separator + "user.md"))));
}
@Test
public void testSwagger2MarkdownConversionHandlesComposition() throws IOException {
//Given
File file = new File(Swagger2MarkupConverterTest.class.getResource("/json/swagger.json").getFile());
File outputDirectory = new File("build/docs/asciidoc/generated");
FileUtils.deleteQuietly(outputDirectory);
//When
Swagger2MarkupConverter.from(file.getAbsolutePath()).withSeparatedDefinitions().
withMarkupLanguage(MarkupLanguage.MARKDOWN).build()
.intoFolder(outputDirectory.getAbsolutePath());
// Then
String[] directories = outputDirectory.list();
assertThat(directories).hasSize(9).containsAll(
asList("definitions.md", "overview.md", "paths.md", "identified.md",
"user.md", "category.md", "pet.md", "tag.md", "order.md"));
verifyMarkdownContainsFieldsInTables(
outputDirectory + File.separator + "definitions.md",
ImmutableMap.<String, Set<String>>builder()
.put("Identified", ImmutableSet.of("id"))
.put("User", ImmutableSet.of("id", "username", "firstName",
"lastName", "email", "password", "phone", "userStatus"))
.build());
verifyMarkdownContainsFieldsInTables(
outputDirectory + File.separator + "user.md",
ImmutableMap.<String, Set<String>>builder()
.put("User", ImmutableSet.of("id", "username", "firstName",
"lastName", "email", "password", "phone", "userStatus"))
.build()
);
}
/**
* Given a markdown document to search, this checks to see if the specified tables
* have all of the expected fields listed.
*
* @param doc path of markdown document to inspect
* @param fieldsByTable map of table name (header) to field names expected
* to be found in that table.
* @throws IOException if the markdown document could not be read
*/
private static void verifyMarkdownContainsFieldsInTables(String doc, Map<String, Set<String>> fieldsByTable) throws IOException {
final List<String> lines = Files.readAllLines(Paths.get(doc), Charset.defaultCharset());
final Map<String, Set<String>> fieldsLeftByTable = Maps.newHashMap();
for(Map.Entry<String, Set<String>> entry : fieldsByTable.entrySet()) {
fieldsLeftByTable.put(entry.getKey(), Sets.newHashSet(entry.getValue()));
}
String inTable = null;
for(String line : lines) {
// If we've found every field we care about, quit early
if(fieldsLeftByTable.isEmpty()) {
return;
}
// Transition to a new table if we encounter a header
final String currentHeader = getTableHeader(line);
if(inTable == null || currentHeader != null) {
inTable = currentHeader;
}
// If we're in a table that we care about, inspect this potential table row
if (inTable != null && fieldsLeftByTable.containsKey(inTable)){
// If we're still in a table, read the row and check for the field name
// NOTE: If there was at least one pipe, then there's at least 2 fields
String[] parts = line.split("\\|");
if(parts.length > 1) {
final String fieldName = parts[1];
final Set<String> fieldsLeft = fieldsLeftByTable.get(inTable);
// Mark the field as found and if this table has no more fields to find,
// remove it from the "fieldsLeftByTable" map to mark the table as done
if(fieldsLeft.remove(fieldName) && fieldsLeft.isEmpty()) {
fieldsLeftByTable.remove(inTable);
}
}
}
}
// After reading the file, if there were still types, fail
if(!fieldsLeftByTable.isEmpty()) {
fail(String.format("Markdown file '%s' did not contain expected fields (by table): %s",
doc, fieldsLeftByTable));
}
}
private static String getTableHeader(String line) {
return line.startsWith("###")
? line.replace("###", "").trim()
: null;
}
/*
@Test
public void testSwagger2HtmlConversion() throws IOException {
File file = new File(Swagger2MarkupConverterTest.class.getResource("/json/swagger.json").getFile());
String asciiDoc = Swagger2MarkupConverter.from(file.getAbsolutePath()).build().asString();
String path = "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);
}
}
*/
}

View File

@@ -1,861 +0,0 @@
{
"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"
],
"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": {
"tags": [
"pet"
],
"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": {
"description": "successful operation",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/Pet"
}
}
},
"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": {
"description": "successful operation",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/Pet"
}
}
},
"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": [
{
"in": "path",
"name": "petId",
"description": "ID of pet that needs to be fetched",
"required": true,
"type": "integer",
"format": "int64"
}
],
"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"
}
}
},
"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"
}
}
}
]
},
"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"
}
}
}
}
}

View File

@@ -1,54 +0,0 @@
{
"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" ]
} ]
} ]
}

View File

@@ -0,0 +1,25 @@
ext.moduleName="io.github.swagger2markup.asciidoc"
dependencies {
configurations.all {
// resolutionStrategy.force dependencyOverrides.commonsCodec
// resolutionStrategy.force dependencyOverrides.commonsIO
// resolutionStrategy.force dependencyOverrides.commonsLang3
resolutionStrategy.force dependencyOverrides.jnrConstants
resolutionStrategy.force dependencyOverrides.jnrEnxio
resolutionStrategy.force dependencyOverrides.jnrPosix
// resolutionStrategy.force dependencyOverrides.jodaTime
resolutionStrategy.force dependencyOverrides.slf4j
// resolutionStrategy.force dependencyOverrides.jacksonDatabind
// resolutionStrategy.force dependencyOverrides.guava
// resolutionStrategy.force dependencyOverrides.findBugs
// resolutionStrategy.force dependencyOverrides.jaksonCore
}
implementation implLibraries.asciiDocJApi
implementation implLibraries.commonsText
implementation implLibraries.slf4j
testImplementation implLibraries.commonsIO
testImplementation testLibraries.asciiDocJ
testImplementation testLibraries.junit
testImplementation testLibraries.logback
}

View File

@@ -0,0 +1,887 @@
package io.github.swagger2markup.adoc;
import io.github.swagger2markup.adoc.converter.internal.*;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.text.StringEscapeUtils;
import org.asciidoctor.ast.List;
import org.asciidoctor.ast.*;
import org.asciidoctor.converter.ConverterFor;
import org.asciidoctor.converter.StringConverter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.LongStream;
import java.util.stream.Stream;
import static io.github.swagger2markup.adoc.converter.internal.Delimiters.*;
@ConverterFor(AsciidocConverter.NAME)
public class AsciidocConverter extends StringConverter {
private Logger logger = LoggerFactory.getLogger(getClass());
public static final String NAME = "adoc";
private final Pattern emptyLineOrStartWith = Pattern.compile("(?m)^\\s*(?:\\r?\\n)|(?m)^\\s+");
private final Pattern coListItemIdPattern = Pattern.compile(".*-(\\d+)");
private final Pattern tableColumnsStylePattern = Pattern.compile("((\\d+)\\*)?([<^>])?(\\.[<^>])?(\\d+)?([adehlmsv])?");
private static final java.util.List<String> attributeToExclude = Arrays.asList(
"localtime",
"filetype",
"asciidoctor-version",
"doctime",
"localyear",
"docdate",
"localdate",
"localdatetime",
"docdatetime",
"backend",
"basebackend",
"doctitle",
"docyear"
);
private static final String[] supportedUrlSchemes = new String[]{
"http",
"https",
"ftp",
"irc",
"mailto"
};
public AsciidocConverter(String backend, Map<String, Object> opts) {
super(backend, opts);
}
/**
* Converts an {@link ContentNode} using the specified transform along
* with additional options. If a transform is not specified, implementations
* typically derive one from the {@link ContentNode#getNodeName()} property.
*
* <p>Implementations are free to decide how to carry out the conversion. In
* the case of the built-in converters, the tranform value is used to
* dispatch to a handler method. The TemplateConverter uses the value of
* the transform to select a template to render.
*
* @param node The concrete instance of FlowNode to convert
* @param transform An optional String transform that hints at which transformation
* should be applied to this node. If a transform is not specified,
* the transform is typically derived from the value of the
* node's node_name property. (optional, default: null)
* @param opts An optional map of options that provide additional hints about
* how to convert the node. (optional, default: empty map)
* @return the converted result
*/
@Override
public String convert(ContentNode node, String transform, Map<Object, Object> opts) {
if (null == transform) {
transform = node.getNodeName();
}
switch (transform) {
case "inline_quoted":
return convertInlineQuoted((PhraseNode) node);
case "paragraph":
return convertParagraph((StructuralNode) node);
case "inline_anchor":
return convertInlineAnchor((PhraseNode) node);
case "section":
return convertSection((Section) node);
case "listing":
return convertListing((Block) node);
case "literal":
return convertLiteral((StructuralNode) node);
case "ulist":
return convertUList((List) node);
case "olist":
return convertOList((List) node);
case "dlist":
return convertDescriptionList((DescriptionList) node);
case "admonition":
return convertAdmonition((Block) node);
case "colist":
return convertCoList((List) node);
case "embedded":
case "document":
return convertEmbedded((Document) node);
case "example":
return convertExample((Block) node);
case "floating_title":
return convertFloatingTitle((StructuralNode) node);
case "image":
return convertImage((StructuralNode) node);
case "inline_break":
return convertInlineBreak(node);
case "inline_button":
return convertInlineButton(node);
case "inline_callout":
return convertInlineCallout(node);
case "inline_footnote":
return convertInlineFootnote(node);
case "inline_image":
return convertInlineImage((PhraseNode) node);
case "inline_indexterm":
return convertInlineIndexTerm(node);
case "inline_kbd":
return convertInlineKbd(node);
case "inline_menu":
return convertInlineMenu(node);
case "open":
return convertOpen((StructuralNode) node);
case "page_break":
return convertPageBreak(node);
case "preamble":
return convertPreamble((StructuralNode) node);
case "quote":
return convertQuote((StructuralNode) node);
case "sidebar":
return convertSidebar((StructuralNode) node);
case "stem":
return convertStem(node);
case "table":
return convertTable((Table) node);
case "thematic_break":
return convertThematicBreak(node);
case "verse":
return convertVerse((StructuralNode) node);
case "video":
return convertVideo(node);
case "toc":
return convertToc(node);
case "pass":
return convertPass(node);
case "audio":
return convertAudio(node);
// didn't exist on html converter
case "list":
return convertList((List) node);
case "list_item":
return convertListItem((ListItem) node);
default:
logger.debug("Don't know how to convert transform: [" + transform + "] Node: " + node);
return null;
}
}
String convertEmbedded(Document node) {
logger.debug("convertEmbedded");
StringBuilder sb = new StringBuilder();
appendId(node, sb);
if (StringUtils.isNotBlank(node.getDoctitle())) {
sb.append(repeat(node.getLevel() + 1,DOCUMENT_TITLE)).append(' ').append(StringEscapeUtils.unescapeHtml4(node.getDoctitle())).append(LINE_SEPARATOR);
}
Map<String, Object> attributes = node.getAttributes();
appendAuthors(sb, attributes);
appendRevisionDetails(sb, attributes);
appendDocumentAttributes(sb, attributes);
appendTrailingNewLine(sb);
appendChildBlocks(node, sb);
return sb.toString();
}
private void appendAuthors(StringBuilder sb, Map<String, Object> attributes) {
Long authorCount = (Long) attributes.getOrDefault("authorcount", 0L);
if (authorCount == 1) {
String author = getAuthorDetail(attributes, "author", "email");
if (StringUtils.isNotBlank(author)) {
sb.append(author).append(LINE_SEPARATOR);
}
} else if (authorCount > 1) {
String authors = LongStream.rangeClosed(1, authorCount)
.mapToObj(i -> getAuthorDetail(attributes, "author_" + i, "email_" + i))
.collect(Collectors.joining("; "));
if (StringUtils.isNotBlank(authors)) {
sb.append(authors).append(LINE_SEPARATOR);
}
}
}
private void appendDocumentAttributes(StringBuilder sb, Map<String, Object> attributes) {
attributes.forEach((k, v) -> {
if (!attributeToExclude.contains(k) && v != null && !v.toString().isEmpty())
sb.append(COLON).append(k).append(COLON).append(" ").append(v).append(LINE_SEPARATOR);
});
}
private void appendRevisionDetails(StringBuilder sb, Map<String, Object> attributes) {
String revDetails = Stream.of(attributes.get("revnumber"), attributes.get("revdate")).filter(Objects::nonNull)
.filter(o -> !o.toString().isEmpty()).map(Object::toString)
.collect(Collectors.joining(", "));
if (!revDetails.isEmpty()) {
sb.append("v").append(revDetails).append(LINE_SEPARATOR);
}
}
private String getAuthorDetail(Map<String, Object> attributes, String authorKey, String emailKey) {
String author = attributes.getOrDefault(authorKey, "").toString();
String email = attributes.getOrDefault(emailKey, "").toString();
if (StringUtils.isNotBlank(email)) {
email = " <" + email + ">";
}
return (author + email).trim();
}
private String convertInlineAnchor(PhraseNode node) {
logger.debug("convertInlineAnchor");
String type = node.getType();
switch (type) {
case "xref": {
String attrs;
String text;
String path = Optional.ofNullable(node.getAttributes().get("path")).orElse("").toString();
if (StringUtils.isNotBlank(path)) {
ArrayList<String> list = new ArrayList<>();
if (StringUtils.isNotBlank(node.getRole())) {
list.add(" class=\"#{node.role}\"");
}
append_link_constraint_attrs(node, list);
attrs = String.join(" ", list);
text = StringUtils.isNotBlank(node.getText()) ? node.getText() : path;
} else {
attrs = StringUtils.isNotBlank(node.getRole()) ? " class=\"" + node.getRole() + "\"" : "";
text = node.getText();
if (StringUtils.isNotBlank(text)) {
text = node.getAttributes().get("refid").toString();
}
}
return node.getTarget() + ATTRIBUTES_BEGIN + text + (StringUtils.isNotBlank(attrs) ? "," + attrs : "") + ATTRIBUTES_END;
}
case "ref":
return node.getId();
case "link": {
ArrayList<String> attrs = new ArrayList<>();
String target = node.getTarget();
String includePrefix = !StringUtils.startsWithAny(target, supportedUrlSchemes) ? "include::" : "";
String text = node.getText();
if (!target.equals(text)) {
attrs.add(text);
}
if (StringUtils.isNotBlank(node.getId())) {
attrs.add("id=\"" + node.getId() + "\"");
}
String role = node.getRole();
if (StringUtils.isNotBlank(role) && !role.equals("bare")) {
attrs.add("role=\"" + role + "\"");
}
String title = node.getAttribute("title", "").toString();
if (StringUtils.isNotBlank(title)) {
attrs.add("title=\"" + title + "\"");
}
return includePrefix + target + ATTRIBUTES_BEGIN + String.join(",", attrs) + ATTRIBUTES_END;
}
case "bibref":
return node.getId() + ATTRIBUTES_BEGIN + (StringUtils.isNotBlank(node.getReftext()) ? node.getReftext() : node.getId()) + ATTRIBUTES_END;
default:
logger.warn("unknown anchor type: " + node.getType());
return null;
}
}
private String convertAdmonition(Block node) {
logger.debug("convertAdmonition");
StringBuilder sb = new StringBuilder();
java.util.List<StructuralNode> blocks = node.getBlocks();
if (blocks.isEmpty()) {
sb.append(node.getStyle()).append(": ").append(node.getSource());
} else {
appendTitle(node, sb);
sb.append(ATTRIBUTES_BEGIN).append(node.getStyle()).append(ATTRIBUTES_END)
.append(LINE_SEPARATOR).append(DELIMITER_EXAMPLE).append(LINE_SEPARATOR);
appendChildBlocks(node, sb);
sb.append(DELIMITER_EXAMPLE).append(LINE_SEPARATOR);
}
return sb.toString();
}
private String convertInlineQuoted(PhraseNode node) {
logger.debug("convertInlineQuoted");
StringBuilder sb = new StringBuilder();
String marker = "";
switch (node.getType()) {
case "monospaced":
marker = "`";
break;
case "emphasis":
marker = "_";
break;
case "strong":
marker = "*";
break;
case "superscript":
marker = "^";
break;
case "subscript":
marker = "~";
break;
case "double":
case "single":
case "mark":
case "asciimath":
case "latexmath":
marker = "";
break;
}
sb.append(marker).append(node.getText()).append(marker);
return sb.toString();
}
private String convertFloatingTitle(StructuralNode node) {
logger.debug("convertFloatingTitle");
return ATTRIBUTES_BEGIN + "discrete" + ATTRIBUTES_END + LINE_SEPARATOR +
repeat(node.getLevel() + 1, TITLE) + ' ' + node.getTitle() + LINE_SEPARATOR;
}
private String convertExample(Block node) {
logger.debug("convertExample");
StringBuilder sb = new StringBuilder();
appendTitle(node, sb);
sb.append(DELIMITER_EXAMPLE).append(LINE_SEPARATOR);
appendChildBlocks(node, sb);
sb.append(DELIMITER_EXAMPLE).append(LINE_SEPARATOR);
return sb.toString();
}
private String convertInlineButton(ContentNode node) {
logger.debug("convertInlineButton: name" + node.getNodeName());
return "convertInlineButton";
}
private String convertInlineCallout(ContentNode node) {
logger.debug("convertInlineCallout: name" + node.getNodeName());
return "convertInlineCallout";
}
private String convertInlineBreak(ContentNode node) {
logger.debug("convertInlineBreak: name" + node.getNodeName());
return "convertInlineBreak";
}
private String convertInlineFootnote(ContentNode node) {
logger.debug("convertInlineFootnote: name" + node.getNodeName());
return "convertInlineFootnote";
}
private String convertInlineImage(PhraseNode node) {
logger.debug("convertInlineImage");
if (node.getType().equals("icon")) {
return (new IconNode(node)).toAsciiDocContent();
} else {
return (new BlockImageNode(node)).toAsciiDocContent();
}
}
private String convertInlineIndexTerm(ContentNode node) {
logger.debug("convertInlineIndexTerm: name" + node.getNodeName());
return "convertInlineIndexTerm";
}
private String convertInlineKbd(ContentNode node) {
logger.debug("convertInlineKbd: name" + node.getNodeName());
return "convertInlineKbd";
}
private String convertInlineMenu(ContentNode node) {
logger.debug("convertInlineMenu: name" + node.getNodeName());
return "convertInlineMenu";
}
private String convertOpen(StructuralNode node) {
logger.debug("convertOpen");
StringBuilder sb = new StringBuilder();
switch (node.getStyle()) {
case "abstract":
sb.append(ATTRIBUTES_BEGIN).append("abstract").append(ATTRIBUTES_END).append(LINE_SEPARATOR);
break;
case "open":
sb.append(DELIMITER_OPEN_BLOCK).append(LINE_SEPARATOR);
}
sb.append(Optional.ofNullable(((Block) node).getSource()).orElse(""));
appendChildBlocks(node, sb);
if ("open".equals(node.getStyle())) {
sb.append(DELIMITER_OPEN_BLOCK).append(LINE_SEPARATOR);
}
return sb.toString();
}
private String convertPageBreak(ContentNode node) {
logger.debug("convertPageBreak: name" + node.getNodeName());
return DELIMITER_PAGE_BREAK + LINE_SEPARATOR;
}
private String convertQuote(StructuralNode node) {
logger.debug("convertQuote");
StringBuilder sb = new StringBuilder();
appendTitle(node, sb);
sb.append(ATTRIBUTES_BEGIN);
java.util.List<String> attrs = new ArrayList<>();
if (StringUtils.isNotBlank(node.getStyle())) {
attrs.add("quote");
}
appendAttributeTo(node, attrs, "attribution");
appendAttributeTo(node, attrs, "citetitle");
sb.append(String.join(",", attrs)).append(ATTRIBUTES_END).append(LINE_SEPARATOR);
java.util.List<StructuralNode> blocks = node.getBlocks();
if (!blocks.isEmpty()) {
sb.append("____").append(LINE_SEPARATOR);
appendChildBlocks(node, sb);
sb.append("____").append(LINE_SEPARATOR);
} else {
sb.append(((Block) node).getSource());
}
return sb.toString();
}
private String convertSidebar(StructuralNode node) {
logger.debug("convertSidebar");
StringBuilder sb = new StringBuilder();
appendTitle(node, sb);
appendChildBlocks(node, sb);
return sb.toString();
}
private String convertStem(ContentNode node) {
logger.debug("convertStem: name" + node.getNodeName());
return "convertStem";
}
private String convertThematicBreak(ContentNode node) {
logger.debug("convertThematicBreak: name" + node.getNodeName());
return DELIMITER_THEMATIC_BREAK + LINE_SEPARATOR;
}
private String convertVerse(StructuralNode node) {
logger.debug("convertVerse");
StringBuilder sb = new StringBuilder();
appendTitle(node, sb);
sb.append(ATTRIBUTES_BEGIN);
java.util.List<String> attrs = new ArrayList<>();
if (StringUtils.isNotBlank(node.getStyle())) {
attrs.add("verse");
}
appendAttributeTo(node, attrs, "attribution");
appendAttributeTo(node, attrs, "citetitle");
sb.append(String.join(",", attrs)).append(ATTRIBUTES_END).append(LINE_SEPARATOR);
String source = ((Block) node).getSource();
boolean matches = emptyLineOrStartWith.matcher(source).find();
if (matches) {
sb.append(DELIMITER_VERSE).append(LINE_SEPARATOR);
}
sb.append(source);
if (matches) {
sb.append(LINE_SEPARATOR).append(DELIMITER_VERSE);
}
appendTrailingNewLine(sb);
return sb.toString();
}
private String convertVideo(ContentNode node) {
logger.debug("convertVideo: name" + node.getNodeName());
return "convertVideo";
}
private String convertToc(ContentNode node) {
logger.debug("convertToc: name" + node.getNodeName());
return "convertToc";
}
private String convertPass(ContentNode node) {
logger.debug("convertPass: name" + node.getNodeName());
return "convertPass";
}
private String convertAudio(ContentNode node) {
logger.debug("convertAudio: name" + node.getNodeName());
return "convertAudio";
}
private String convertCell(Cell node) {
logger.debug("convertCell");
StringBuilder sb = new StringBuilder();
String source = node.getSource();
if (StringUtils.isNotBlank(source)) {
sb.append(source);
}
Document innerDocument = node.getInnerDocument();
if (null != innerDocument) {
appendChildBlocks(innerDocument, sb, false);
}
return sb.toString().replaceAll(LINE_SEPARATOR + LINE_SEPARATOR + "+", LINE_SEPARATOR + LINE_SEPARATOR);
}
private String convertRow(Row node, java.util.List<TableCellStyle> columnStyles, String delimiterTableCell) {
logger.debug("convertRow");
StringBuilder sb = new StringBuilder();
node.getCells().forEach(cell -> {
boolean addNewLine = false;
int colspan = cell.getColspan();
if (colspan != 0) {
addNewLine = true;
sb.append(colspan).append('+');
}
int rowspan = cell.getRowspan();
if (rowspan != 0) {
addNewLine = true;
sb.append('.').append(rowspan).append('+');
}
int index = cell.getColumn().getColumnNumber() - 1;
TableCellStyle tableCellStyle = (columnStyles.size() > index) ? columnStyles.get(index) : null;
boolean hAlignmentAdded = false;
TableCellHorizontalAlignment hAlignment = TableCellHorizontalAlignment.fromName(cell.getHorizontalAlignment().name());
if ((null != hAlignment) && (null == tableCellStyle || hAlignment != tableCellStyle.horizontalAlignment)) {
hAlignmentAdded = true;
addNewLine = true;
sb.append(hAlignment.getDelimiter());
}
TableCellVerticalAlignment vAlignment = TableCellVerticalAlignment.fromName(cell.getVerticalAlignment().name());
if ((null != vAlignment) && (null == tableCellStyle || hAlignmentAdded || vAlignment != tableCellStyle.verticalAlignment)) {
addNewLine = true;
sb.append(vAlignment.getDelimiter());
}
Style style = Style.fromName(cell.getAttribute("style", "").toString());
if (null != style && (null == tableCellStyle || style != tableCellStyle.style)) {
addNewLine = true;
sb.append(style.getShortHand());
}
sb.append(delimiterTableCell).append(convertCell(cell));
if (addNewLine) {
sb.append(LINE_SEPARATOR);
} else {
sb.append(' ');
}
});
return sb.toString();
}
private String convertTable(Table node) {
logger.debug("convertTable");
java.util.List<TableCellStyle> columnStyles = new ArrayList<>();
for (String col : node.getAttribute("cols", "").toString().split(",")) {
Matcher matcher = tableColumnsStylePattern.matcher(col);
if (matcher.find()) {
int multiplier = 1;
String multiplierGroup = matcher.group(2);
if (null != multiplierGroup) {
try {
multiplier = Integer.parseInt(multiplierGroup);
} catch (NumberFormatException ignored) {
}
}
int width = 0;
try {
width = Integer.parseInt(matcher.group(5));
} catch (NumberFormatException ignored) {
}
TableCellStyle tableCellStyle = new TableCellStyle(
TableCellHorizontalAlignment.fromString(matcher.group(3)),
TableCellVerticalAlignment.fromString(matcher.group(4)),
Style.fromString(matcher.group(6)),
width
);
for (int i = 0; i < multiplier; i++) {
columnStyles.add(tableCellStyle);
}
}
}
StringBuilder sb = new StringBuilder();
appendTitle(node, sb);
sb.append(new TableNode(node).toAsciiDocContent());
boolean innerTable = isInnerTable(node);
String tableDelimiter = innerTable ? DELIMITER_INNER_TABLE : DELIMITER_TABLE;
String cellDelimiter = innerTable ? DELIMITER_INNER_TABLE_CELL : DELIMITER_TABLE_CELL;
sb.append(tableDelimiter).append(LINE_SEPARATOR);
appendRows(node.getHeader(), sb, columnStyles, cellDelimiter);
appendRows(node.getBody(), sb, columnStyles, cellDelimiter);
appendRows(node.getFooter(), sb, columnStyles, cellDelimiter);
sb.append(tableDelimiter).append(LINE_SEPARATOR);
return sb.toString();
}
private boolean isInnerTable(ContentNode node) {
if(null != node) {
ContentNode parent = node.getParent();
if (null != parent) {
return parent instanceof Table || isInnerTable(parent);
}
}
return false;
}
private void appendRows(java.util.List<Row> rows, StringBuilder sb, java.util.List<TableCellStyle> columnStyles, String delimiterTableCell) {
rows.forEach(row -> sb.append(convertRow(row, columnStyles, delimiterTableCell)).append(LINE_SEPARATOR));
}
private String convertDescriptionList(DescriptionList node) {
logger.debug("convertDescriptionList");
StringBuilder sb = new StringBuilder();
appendTitle(node, sb);
String style = Optional.ofNullable(node.getStyle()).orElse("");
switch (style) {
case STYLE_HORIZONTAL:
sb.append(ATTRIBUTES_BEGIN).append(STYLE_HORIZONTAL).append(ATTRIBUTES_END).append(LINE_SEPARATOR);
node.getItems().forEach(item -> sb.append(convertDescriptionListEntry(item, node.getLevel(), false)));
break;
case STYLE_Q_AND_A:
sb.append(ATTRIBUTES_BEGIN).append(STYLE_Q_AND_A).append(ATTRIBUTES_END).append(LINE_SEPARATOR);
default:
node.getItems().forEach(item -> sb.append(convertDescriptionListEntry(item, node.getLevel(), true)));
break;
}
appendTrailingNewLine(sb);
return sb.toString();
}
private String convertDescriptionListEntry(DescriptionListEntry node, int level, Boolean descriptionOnNewLine) {
logger.debug("convertDescriptionListEntry");
StringBuilder sb = new StringBuilder();
String delimiter = repeat(level + 1, MARKER_D_LIST_ITEM);
String entryTerms = node.getTerms().stream()
.map(term -> Optional.ofNullable(term.getSource()).orElse(""))
.collect(Collectors.joining(delimiter + LINE_SEPARATOR, "", delimiter));
sb.append(entryTerms);
ListItem description = node.getDescription();
if (null != description) {
if (descriptionOnNewLine) {
sb.append(LINE_SEPARATOR);
}
String desc = Optional.ofNullable(description.getSource()).orElse("");
if (StringUtils.isNotBlank(desc)) {
sb.append(desc).append(LINE_SEPARATOR);
}
appendChildBlocks(description, sb);
}
return sb.toString();
}
private String convertListing(Block node) {
logger.debug("convertListing");
StringBuilder sb = new StringBuilder();
appendTitle(node, sb);
if (STYLE_SOURCE.equals(node.getStyle())) {
sb.append(new SourceNode(node).toAsciiDocContent());
} else {
sb.append(new BlockListingNode(node).toAsciiDocContent());
}
return sb.toString();
}
private String convertUList(List node) {
logger.debug("convertUList");
StringBuilder sb = new StringBuilder();
appendStyle(node, sb);
appendTitle(node, sb);
appendChildBlocks(node, sb);
appendTrailingNewLine(sb);
return sb.toString();
}
private String convertOList(List node) {
logger.debug("convertOList");
StringBuilder sb = new StringBuilder();
java.util.List<String> attrs = new ArrayList<>();
String start = node.getAttribute("start", "").toString();
if (StringUtils.isNotBlank(start)) {
attrs.add("start=" + start);
}
if (node.isOption("reversed")) {
attrs.add("%reversed");
}
if (!attrs.isEmpty()) {
sb.append(ATTRIBUTES_BEGIN).append(String.join(",", attrs)).append(ATTRIBUTES_END).append(LINE_SEPARATOR);
}
appendTitle(node, sb);
appendChildBlocks(node, sb);
appendTrailingNewLine(sb);
return sb.toString();
}
private String convertCoList(List node) {
logger.debug("convertCoList");
StringBuilder result = new StringBuilder();
appendChildBlocks(node, result);
return result.toString();
}
private String convertListItem(ListItem node) {
logger.debug("convertListItem");
StringBuilder sb = new StringBuilder();
String marker = Optional.ofNullable(node.getMarker()).orElse(repeat(node.getLevel(), MARKER_LIST_ITEM));
String coids = node.getAttribute("coids", "").toString();
Matcher matcher = coListItemIdPattern.matcher(coids);
if (matcher.find()) {
marker = marker.replaceAll("\\d+", matcher.group(1));
}
sb.append(marker).append(" ");
if (node.hasAttribute("checkbox")) {
sb.append('[');
if (node.hasAttribute("checked")) {
sb.append('x');
} else {
sb.append(' ');
}
sb.append(']').append(' ');
}
sb.append(Optional.ofNullable(node.getSource()).orElse(""));
appendTrailingNewLine(sb);
appendChildBlocks(node, sb);
return sb.toString();
}
private String convertList(List node) {
logger.debug("convertList");
return node.getContent().toString();
}
private String convertPreamble(StructuralNode node) {
logger.debug("convertPreamble");
return node.getContent().toString();
}
private String convertImage(StructuralNode node) {
logger.debug("convertImage");
StringBuilder sb = new StringBuilder();
appendTitle(node, sb);
appendRoles(node, sb);
sb.append(new BlockImageNode(node).toAsciiDocContent());
return sb.toString();
}
private String convertLiteral(StructuralNode node) {
logger.debug("convertLiteral");
return ATTRIBUTES_BEGIN + node.getContext() + ATTRIBUTES_END + LINE_SEPARATOR +
StringEscapeUtils.unescapeHtml4(node.getContent().toString()) + LINE_SEPARATOR;
}
private String convertParagraph(StructuralNode node) {
logger.debug("convertParagraph");
StringBuilder sb = new StringBuilder();
appendTitle(node, sb);
sb.append(new ParagraphAttributes(node).toAsciiDocContent());
appendSource((Block) node, sb);
appendTrailingNewLine(sb);
return sb.toString();
}
private String convertSection(Section node) {
logger.debug("convertSection");
StringBuilder sb = new StringBuilder();
appendId(node, sb);
sb.append(new DelimitedBlockNode(node).toAsciiDocContent()).append(StringUtils.repeat(TITLE, node.getLevel() + 1))
.append(" ").append(StringEscapeUtils.unescapeHtml4(node.getTitle())).append(LINE_SEPARATOR);
appendChildBlocks(node, sb);
appendTrailingNewLine(sb);
return sb.toString();
}
private void append_link_constraint_attrs(ContentNode node, java.util.List<String> attrs) {
String rel = node.getAttribute("nofollow-option").toString();
String window = node.getAttributes().get("window").toString();
if (StringUtils.isNotBlank(window)) {
attrs.add("target = \"#{window}\"");
if (window.equals("_blank") || (node.getAttributes().containsKey("option-noopener"))) {
if (StringUtils.isNotBlank(rel)) {
attrs.add("rel = \"" + rel + "noopener\"");
} else {
attrs.add(" rel=\"noopener\"");
}
}
} else if (StringUtils.isNotBlank(rel)) {
attrs.add("rel = " + rel + "\"");
}
}
private String repeat(int count, String with) {
return new String(new char[count]).replace("\0", with);
}
private void appendChildBlocks(StructuralNode parentNode, StringBuilder sb) {
appendChildBlocks(parentNode, sb, true);
}
private void appendChildBlocks(StructuralNode parentNode, StringBuilder sb, boolean addTrailingLineSeparator) {
final boolean isParentAListItem = parentNode instanceof ListItem || parentNode instanceof DescriptionListEntry;
parentNode.getBlocks().forEach(childNode -> {
String childNodeValue = childNode.convert();
if (StringUtils.isNotBlank(childNodeValue)) {
if (isParentAListItem && (sb.toString().contains("+" + LINE_SEPARATOR) || !(childNode instanceof List || childNode instanceof DescriptionList))) {
sb.append('+').append(LINE_SEPARATOR);
}
sb.append(childNodeValue);
if (addTrailingLineSeparator && !StringUtils.endsWith(childNodeValue, LINE_SEPARATOR)) {
sb.append(LINE_SEPARATOR);
}
}
});
}
private void appendTrailingNewLine(StringBuilder sb) {
if (!sb.toString().endsWith(LINE_SEPARATOR + LINE_SEPARATOR)) {
sb.append(LINE_SEPARATOR);
}
}
private void appendId(StructuralNode node, StringBuilder sb) {
String id = node.getId();
if (StringUtils.isNotBlank(id)) {
sb.append("[[").append(id).append("]]").append(LINE_SEPARATOR);
}
}
private void appendSource(Block node, StringBuilder sb) {
String source = node.getSource();
if (StringUtils.isNotBlank(source)) {
sb.append(source).append(LINE_SEPARATOR);
}
}
private void appendTitle(StructuralNode node, StringBuilder sb) {
String title = node.getTitle();
if (StringUtils.isNotBlank(title)) {
sb.append(".").append(StringEscapeUtils.unescapeHtml4(title)).append(LINE_SEPARATOR);
}
}
private void appendStyle(StructuralNode node, StringBuilder sb) {
String style = node.getStyle();
if (StringUtils.isNotBlank(style)) {
sb.append(ATTRIBUTES_BEGIN).append(style).append(ATTRIBUTES_END).append(LINE_SEPARATOR);
}
}
private void appendRoles(StructuralNode node, StringBuilder sb) {
java.util.List<String> roles = node.getRoles();
if (!roles.isEmpty()) {
sb.append(ATTRIBUTES_BEGIN).append(".").append(String.join(".", roles))
.append(ATTRIBUTES_END).append(LINE_SEPARATOR);
}
}
private void appendAttributeTo(StructuralNode node, java.util.List<String> attrs, String name) {
String attribution = node.getAttribute(name, "").toString();
if (StringUtils.isNotBlank(attribution)) {
attrs.add(attribution);
}
}
}

Some files were not shown because too many files have changed in this diff Show More