Compare commits
2 Commits
1.3.x
...
feature/sw
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
85c5b7aa97 | ||
|
|
662cc3f40f |
82
.github/workflows/gradle-build.yml
vendored
@@ -1,82 +0,0 @@
|
||||
# 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: [ 1.3.x ]
|
||||
pull_request:
|
||||
branches: [ 1.3.x ]
|
||||
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/1.3.x' }}
|
||||
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
|
||||
3
.gitignore
vendored
@@ -3,6 +3,3 @@
|
||||
.gradle
|
||||
build
|
||||
/bin/
|
||||
/.classpath
|
||||
/.project
|
||||
/.settings/
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
language: java
|
||||
jdk:
|
||||
- openjdk8
|
||||
- oraclejdk8
|
||||
before_install:
|
||||
- chmod +x gradlew
|
||||
after_success:
|
||||
|
||||
19
README.adoc
@@ -7,17 +7,6 @@ image:https://travis-ci.org/Swagger2Markup/swagger2markup.svg?branch=master["Bui
|
||||
|
||||
== 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].
|
||||
|
||||
@@ -33,12 +22,12 @@ The project requires at least JDK 8.
|
||||
|
||||
== Example
|
||||
|
||||
image::swagger2markup-documentation/src/docs/asciidoc/images/Swagger2Markup.PNG[]
|
||||
image::src/docs/asciidoc/images/Swagger2Markup.PNG[]
|
||||
|
||||
image::swagger2markup-documentation/src/docs/asciidoc/images/Swagger2Markup_definitions.PNG[]
|
||||
image::src/docs/asciidoc/images/Swagger2Markup_definitions.PNG[]
|
||||
|
||||
== Reference documentation
|
||||
- http://swagger2markup.github.io/swagger2markup/1.3.4/[Reference Documentation]
|
||||
- http://swagger2markup.github.io/swagger2markup/1.0.0/[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]
|
||||
|
||||
@@ -65,8 +54,6 @@ If you’d like an enhancement to be made to Swagger2Markup, pull requests are m
|
||||
* 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
|
||||
|
||||
|
||||
@@ -3,21 +3,6 @@
|
||||
== 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.
|
||||
|
||||
@@ -93,9 +78,9 @@
|
||||
|
||||
=== 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 #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
|
||||
@@ -106,67 +91,3 @@
|
||||
* 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 1.3.4
|
||||
* Moved from bintray to Sonatype
|
||||
* Introduced Github actions
|
||||
* Certain bug fixes
|
||||
* Added support for MIME types with structured syntax suffixes (#410)
|
||||
|
||||
|
||||
|
||||
150
build.gradle
@@ -1,117 +1,67 @@
|
||||
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.4'
|
||||
}
|
||||
|
||||
allprojects {
|
||||
apply plugin: 'jacoco'
|
||||
apply plugin: 'me.champeau.gradle.jmh'
|
||||
|
||||
version = '1.3.4'
|
||||
group 'io.github.swagger2markup'
|
||||
description = 'swagger2markup Build'
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
//artifactoryPublish.skip = true // apply to all projects except the root
|
||||
|
||||
ext {
|
||||
coreProjects = subprojects.findAll {
|
||||
p -> !p.name.endsWith("-bom")
|
||||
dependencies {
|
||||
classpath 'org.asciidoctor:asciidoctor-gradle-plugin:1.5.3'
|
||||
classpath 'org.asciidoctor:asciidoctorj-pdf:1.5.0-alpha.10.1'
|
||||
classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.0.1'
|
||||
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6'
|
||||
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.0.0"
|
||||
classpath "org.ajoberstar:gradle-git:1.3.2"
|
||||
}
|
||||
}
|
||||
description = 'swagger2markup Build'
|
||||
version = '1.0.1-SNAPSHOT'
|
||||
group = 'io.github.swagger2markup'
|
||||
|
||||
configure(project.coreProjects) {
|
||||
apply plugin: 'signing'
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'maven'
|
||||
apply plugin: 'maven-publish'
|
||||
apply from: "${rootDir}/publishing.gradle"
|
||||
apply plugin: 'jacoco'
|
||||
apply plugin: 'java'
|
||||
apply from: 'gradle/publishing.gradle'
|
||||
apply from: 'gradle/coverage.gradle'
|
||||
apply from: 'gradle/documentation.gradle'
|
||||
|
||||
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.withType(JavaCompile) {
|
||||
sourceCompatibility = "1.8"
|
||||
targetCompatibility = "1.8"
|
||||
options.deprecation = true
|
||||
options.encoding = 'UTF-8'
|
||||
options.compilerArgs << "-Xlint:unchecked"
|
||||
}
|
||||
|
||||
nexusPublishing {
|
||||
repositories {
|
||||
sonatype()
|
||||
repositories {
|
||||
maven {
|
||||
url "https://oss.jfrog.org/artifactory/oss-snapshot-local"
|
||||
}
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
mavenLocal()
|
||||
}
|
||||
|
||||
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"
|
||||
}
|
||||
dependencies {
|
||||
compile 'io.github.swagger2markup:markup-document-builder:1.0.0'
|
||||
compile 'io.swagger:swagger-compat-spec-parser:1.0.21-SNAPSHOT'
|
||||
compile 'org.apache.commons:commons-configuration2:2.0'
|
||||
compile 'commons-beanutils:commons-beanutils:1.9.2'
|
||||
compile 'org.apache.commons:commons-collections4:4.1'
|
||||
testCompile 'junit:junit:4.11'
|
||||
testCompile 'org.asciidoctor:asciidoctorj:1.5.4'
|
||||
testCompile 'ch.qos.logback:logback-classic:1.1.2'
|
||||
testCompile 'org.assertj:assertj-core:3.4.0'
|
||||
testCompile 'io.github.robwin:assertj-diff:0.1.1'
|
||||
}
|
||||
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 {
|
||||
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
|
||||
if (System.properties['http.proxyHost']) {
|
||||
systemProperty 'http.proxyHost', System.properties['http.proxyHost']
|
||||
systemProperty 'http.proxyPort', System.properties['http.proxyPort']
|
||||
systemProperty 'http.nonProxyHosts', System.properties['http.nonProxyHosts']
|
||||
}
|
||||
systemProperty 'file.encoding', 'UTF-8'
|
||||
ignoreFailures = true
|
||||
}
|
||||
|
||||
|
||||
task wrapper(type: Wrapper) {
|
||||
gradleVersion = '2.12'
|
||||
}
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
systemProp.file.encoding=UTF-8
|
||||
systemProp.sun.jnu.encoding=UTF-8
|
||||
13
gradle/coverage.gradle
Normal file
@@ -0,0 +1,13 @@
|
||||
apply plugin: 'jacoco'
|
||||
apply plugin: 'com.github.kt3k.coveralls'
|
||||
|
||||
jacocoTestReport {
|
||||
reports {
|
||||
xml.enabled = true // coveralls plugin depends on xml format report
|
||||
html.enabled = true
|
||||
}
|
||||
}
|
||||
|
||||
tasks.coveralls {
|
||||
dependsOn 'check'
|
||||
}
|
||||
34
gradle/documentation.gradle
Normal file
@@ -0,0 +1,34 @@
|
||||
apply plugin: 'org.asciidoctor.convert'
|
||||
apply plugin: 'org.ajoberstar.github-pages'
|
||||
|
||||
asciidoctor {
|
||||
sources {
|
||||
include 'index.adoc'
|
||||
}
|
||||
backends = ['html5', 'pdf']
|
||||
attributes = [
|
||||
doctype: 'book',
|
||||
toc: 'left',
|
||||
toclevels: '3',
|
||||
numbered: '',
|
||||
sectlinks: '',
|
||||
sectanchors: '',
|
||||
hardbreaks: '',
|
||||
]
|
||||
}
|
||||
|
||||
publishGhPages.dependsOn asciidoctor
|
||||
|
||||
githubPages {
|
||||
repoUri = 'https://github.com/Swagger2Markup/swagger2markup.git'
|
||||
|
||||
credentials {
|
||||
username = project.hasProperty('githubUser') ? project.githubUser : System.getenv('GITHUB_USER')
|
||||
password = project.hasProperty('githubPassword') ? project.githubPassword : System.getenv('GITHUB_PASSWORD')
|
||||
}
|
||||
|
||||
pages {
|
||||
from file(asciidoctor.outputDir.path + '/html5')
|
||||
into project.version
|
||||
}
|
||||
}
|
||||
151
gradle/publishing.gradle
Normal file
@@ -0,0 +1,151 @@
|
||||
import java.text.SimpleDateFormat
|
||||
|
||||
apply plugin: 'maven-publish'
|
||||
apply plugin: 'com.jfrog.bintray'
|
||||
apply plugin: "com.jfrog.artifactory"
|
||||
|
||||
Date buildTimeAndDate = new Date()
|
||||
ext {
|
||||
buildDate = new SimpleDateFormat('yyyy-MM-dd').format(buildTimeAndDate)
|
||||
buildTime = new SimpleDateFormat('HH:mm:ss.SSSZ').format(buildTimeAndDate)
|
||||
projectUrl = 'https://github.com/Swagger2Markup/swagger2markup'
|
||||
licenseUrl = 'https://github.com/Swagger2Markup/swagger2markup/blob/master/LICENSE.txt'
|
||||
scmUrl = 'https://github.com/Swagger2Markup/swagger2markup.git'
|
||||
issuesUrl = 'https://github.com/Swagger2Markup/swagger2markup/issues'
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
jar {
|
||||
manifest {
|
||||
attributes(
|
||||
'Created-By': System.properties['java.version'] + " (" + System.properties['java.vendor'] + " " + System.properties['java.vm.version'] + ")",
|
||||
'Built-With': "gradle-${project.getGradle().getGradleVersion()}, groovy-${GroovySystem.getVersion()}",
|
||||
'Build-Time': "${new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")}",
|
||||
'Specification-Title': "${project.name}",
|
||||
'Specification-Version': project.version.toString(),
|
||||
'Implementation-Title': "${project.name}",
|
||||
'Implementation-Version': project.version.toString()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
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 = ''
|
||||
|
||||
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', project.name)
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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'
|
||||
userOrg = 'swagger2markup'
|
||||
websiteUrl = projectUrl
|
||||
issueTrackerUrl = issuesUrl
|
||||
vcsUrl = scmUrl
|
||||
desc = rootProject.description
|
||||
licenses = ['Apache-2.0']
|
||||
version {
|
||||
vcsTag = rootProject.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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
artifactory {
|
||||
contextUrl = 'https://oss.jfrog.org'
|
||||
resolve {
|
||||
repository {
|
||||
repoKey = 'libs-release'
|
||||
}
|
||||
}
|
||||
publish {
|
||||
repository {
|
||||
repoKey = 'oss-snapshot-local' //The Artifactory repository key to publish to
|
||||
//when using oss.jfrog.org the credentials are from Bintray. For local build we expect them to be found in
|
||||
//~/.gradle/gradle.properties, otherwise to be set in the build server
|
||||
username = project.hasProperty('bintrayUsername') ? project.bintrayUsername : System.getenv('BINTRAY_USER')
|
||||
password = project.hasProperty('bintrayApiKey') ? project.bintrayApiKey : System.getenv('BINTRAY_KEY')
|
||||
}
|
||||
defaults {
|
||||
publications('mavenJava')
|
||||
}
|
||||
}
|
||||
if (System.properties['https.proxyHost']) {
|
||||
clientConfig.proxy.host = System.properties['https.proxyHost']
|
||||
clientConfig.proxy.port = System.properties['https.proxyPort'].toInteger()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
tasks.artifactoryPublish {
|
||||
dependsOn 'check'
|
||||
}
|
||||
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
4
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,6 +1,6 @@
|
||||
#Mon Oct 21 16:35:38 BST 2019
|
||||
#Thu Mar 31 16:29:35 CEST 2016
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.3-all.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.12-all.zip
|
||||
|
||||
100
gradlew
vendored
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env sh
|
||||
#!/usr/bin/env bash
|
||||
|
||||
##############################################################################
|
||||
##
|
||||
@@ -6,6 +6,42 @@
|
||||
##
|
||||
##############################################################################
|
||||
|
||||
# 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
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
# Resolve links: $0 may be a link
|
||||
PRG="$0"
|
||||
@@ -24,46 +60,6 @@ cd "`dirname \"$PRG\"`/" >/dev/null
|
||||
APP_HOME="`pwd -P`"
|
||||
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
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
@@ -89,7 +85,7 @@ location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
||||
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
|
||||
MAX_FD_LIMIT=`ulimit -H -n`
|
||||
if [ $? -eq 0 ] ; then
|
||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||
@@ -154,19 +150,11 @@ if $cygwin ; then
|
||||
esac
|
||||
fi
|
||||
|
||||
# Escape application args
|
||||
save () {
|
||||
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
||||
echo " "
|
||||
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
|
||||
function splitJvmOpts() {
|
||||
JVM_OPTS=("$@")
|
||||
}
|
||||
APP_ARGS=$(save "$@")
|
||||
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
|
||||
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
|
||||
|
||||
# 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" "$@"
|
||||
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
|
||||
|
||||
14
gradlew.bat
vendored
@@ -8,14 +8,14 @@
|
||||
@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 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
|
||||
|
||||
@@ -46,9 +46,10 @@ echo location of your Java installation.
|
||||
goto fail
|
||||
|
||||
:init
|
||||
@rem Get command-line arguments, handling Windows variants
|
||||
@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.
|
||||
@@ -59,6 +60,11 @@ set _SKIP=2
|
||||
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
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
// 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,
|
||||
]
|
||||
@@ -1,91 +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)
|
||||
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
|
||||
}
|
||||
|
||||
signing {
|
||||
sign publishing.publications
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1 @@
|
||||
rootProject.name = 'swagger2markup'
|
||||
|
||||
include 'swagger2markup-asciidoc'
|
||||
include 'swagger2markup-bom'
|
||||
include 'swagger2markup-builder'
|
||||
include 'swagger2markup-documentation'
|
||||
include 'swagger2markup'
|
||||
include 'swagger2markup-core'
|
||||
|
||||
rootProject.name = 'swagger2markup'
|
||||
@@ -16,7 +16,7 @@ You can show the help:
|
||||
|
||||
[source, subs="attributes"]
|
||||
----
|
||||
java -jar swagger2markup-cli-{release-version}.jar help convert
|
||||
java -jar swagger2markup-cli-{project-version}.jar help convert
|
||||
----
|
||||
|
||||
Output:
|
||||
@@ -57,7 +57,7 @@ You can convert a Swagger file into a folder as follows:
|
||||
|
||||
[source, subs="attributes"]
|
||||
----
|
||||
java -jar swagger2markup-cli-{release-version}.jar convert -i /path/to/swagger_petstore.yaml -d /tmp/asiidoc
|
||||
java -jar swagger2markup-cli-1.0.0-SNAPSHOT.jar convert -i /path/to/swagger_petstore.yaml -d /tmp/asiidoc
|
||||
----
|
||||
|
||||
It generates the Markup documents into the `/tmp/asiidoc` folder.
|
||||
@@ -68,7 +68,7 @@ You can convert a local Swagger file into a file as follows:
|
||||
|
||||
[source, subs="attributes"]
|
||||
----
|
||||
java -jar swagger2markup-cli-{release-version}.jar convert -i /path/to/swagger_petstore.yaml -f /tmp/asiidoc/swagger
|
||||
java -jar swagger2markup-cli-1.0.0-SNAPSHOT.jar convert -i /path/to/swagger_petstore.yaml -f /tmp/asiidoc/swagger
|
||||
----
|
||||
|
||||
NOTE: The input file must not have a file extension
|
||||
@@ -81,7 +81,7 @@ You can convert a remote Swagger specification which must be accessible via HTTP
|
||||
|
||||
[source, subs="attributes"]
|
||||
----
|
||||
java -jar swagger2markup-cli-{release-version}.jar convert -i "http://petstore.swagger.io/v2/swagger.json" -d /tmp
|
||||
java -jar swagger2markup-cli-1.0.0-SNAPSHOT.jar convert -i "http://petstore.swagger.io/v2/swagger.json" -d /tmp
|
||||
----
|
||||
|
||||
=== Configuration
|
||||
@@ -98,6 +98,6 @@ Invoke the CLI as follows:
|
||||
|
||||
[source, subs="attributes"]
|
||||
----
|
||||
java -jar swagger2markup-cli-{release-version}.jar convert -i /path/to/swagger_petstore.yaml -o /tmp -c /path/to/config.properties
|
||||
java -jar swagger2markup-cli-1.0.0-SNAPSHOT.jar convert -i /path/to/swagger_petstore.yaml -o /tmp -c /path/to/config.properties
|
||||
----
|
||||
|
||||
@@ -22,7 +22,7 @@ To create a custom extension, you have to create a class (e.g. `io.myname.MyExte
|
||||
|
||||
[source,java,indent=0]
|
||||
----
|
||||
include::{coreProjectDir}/src/test/java/io/github/swagger2markup/builder/MyExtension.java[tags=MyExtension]
|
||||
include::../../test/java/io/github/swagger2markup/builder/MyExtension.java[tags=MyExtension]
|
||||
----
|
||||
1. You can retrieve extension properties from the config to configure the extension.
|
||||
2. You can retrieve a `MarkupDocBuilder` from the `Context`.
|
||||
@@ -47,7 +47,7 @@ To register your extension manually, you have to use the `Swagger2MarkupExtensio
|
||||
|
||||
[source,java,indent=0]
|
||||
----
|
||||
include::{coreProjectDir}/src/test/java/io/github/swagger2markup/DocumentationTest.java[tags=swagger2MarkupExtensionRegistryBuilder]
|
||||
include::../../test/java/io/github/swagger2markup/DocumentationTest.java[tags=swagger2MarkupExtensionRegistryBuilder]
|
||||
----
|
||||
1. Create a ``Swagger2MarkupExtensionRegistryBuilder`` using the default constructor
|
||||
2. Register your custom extension
|
||||
@@ -142,7 +142,7 @@ Example:
|
||||
|
||||
[source,java,indent=0]
|
||||
----
|
||||
include::{coreProjectDir}/src/test/java/io/github/swagger2markup/builder/MySwaggerModelExtension.java[tags=MySwaggerModelExtension]
|
||||
include::../../test/java/io/github/swagger2markup/builder/MySwaggerModelExtension.java[tags=MySwaggerModelExtension]
|
||||
----
|
||||
1. You can change any Swagger model property
|
||||
2. You could even remove elements from the Swagger model
|
||||
@@ -19,7 +19,7 @@ repositories {
|
||||
jCenter()
|
||||
}
|
||||
|
||||
compile "io.github.swagger2markup:swagger2markup:{release-version}"
|
||||
compile "io.github.swagger2markup:swagger2markup:{project-version}"
|
||||
----
|
||||
|
||||
==== Snapshot
|
||||
@@ -50,7 +50,7 @@ repositories {
|
||||
<dependency>
|
||||
<groupId>io.github.swagger2markup</groupId>
|
||||
<artifactId>swagger2markup</artifactId>
|
||||
<version>{release-version}</version>
|
||||
<version>{project-version}</version>
|
||||
</dependency>
|
||||
----
|
||||
|
||||
@@ -18,7 +18,7 @@ buildscript {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath 'io.github.swagger2markup:swagger2markup-gradle-plugin:{release-version}'
|
||||
classpath 'io.github.swagger2markup:swagger2markup-gradle-plugin:{project-version}'
|
||||
}
|
||||
}
|
||||
|
||||
|
Before Width: | Height: | Size: 130 KiB After Width: | Height: | Size: 130 KiB |
|
Before Width: | Height: | Size: 116 KiB After Width: | Height: | Size: 116 KiB |
|
Before Width: | Height: | Size: 133 KiB After Width: | Height: | Size: 133 KiB |
|
Before Width: | Height: | Size: 46 KiB After Width: | Height: | Size: 46 KiB |
|
Before Width: | Height: | Size: 38 KiB After Width: | Height: | Size: 38 KiB |
|
Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 35 KiB |
@@ -5,7 +5,7 @@ Robert Winkler
|
||||
:source-highlighter: coderay
|
||||
:numbered:
|
||||
:hardbreaks:
|
||||
:revnumber: {release-version}
|
||||
:revnumber: {project-version}
|
||||
:revdate: {localdate}
|
||||
:icons: font
|
||||
:pagenums:
|
||||
@@ -26,8 +26,6 @@ include::maven_plugin.adoc[]
|
||||
|
||||
include::command_line_interface.adoc[]
|
||||
|
||||
include::docker.adoc[]
|
||||
|
||||
include::demo.adoc[]
|
||||
|
||||
include::contributing.adoc[]
|
||||
@@ -6,7 +6,7 @@ NOTE: The Swagger Specification has been donated to to the https://openapis.org/
|
||||
|
||||
Swagger2Markup converts a Swagger JSON or YAML specification into either **AsciiDoc**, **GitHub Flavored Markdown** or *Atlassian Confluence Wiki* documents which can be combined with hand-written Markup documentation. The Swagger source file can be located locally or remotely via HTTP. Internally Swagger2Markup uses the __official__ https://github.com/swagger-api/swagger-parser[swagger-parser] and https://github.com/Swagger2Markup/markup-document-builder[markup-document-builder].
|
||||
|
||||
You can use Swagger2Markup to convert your contract-first Swagger YAML file into Markup. 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 a Gradle or Maven user, you can also use the https://github.com/Swagger2Markup/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 Markup. As an alternative, you can choose the code-first approach and use Swagger2Markup together with https://github.com/swagger-api/swagger-core/wiki/Swagger-Core-JAX-RS-Project-Setup-1.5.X[Swagger JAX-RS], https://github.com/springfox/springfox[Springfox] or https://github.com/spring-projects/spring-restdocs[spring-restdocs]. If you are are Gradle or Maven user, you can also use the https://github.com/Swagger2Markup/swagger2markup-gradle-plugin[Swagger2Markup Gradle Plugin] or https://github.com/redowl/swagger2markup-maven-plugin[Swagger2markup Maven Plugin].
|
||||
|
||||
NOTE: The project requires at least JDK 8.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
== License
|
||||
|
||||
Copyright 2017 Robert Winkler
|
||||
Copyright 2016 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
|
||||
|
||||
@@ -31,7 +31,7 @@ Add the following snippet to your Maven POM file:
|
||||
<plugin>
|
||||
<groupId>io.github.swagger2markup</groupId>
|
||||
<artifactId>swagger2markup-maven-plugin</artifactId>
|
||||
<version>{release-version}</version>
|
||||
<version>{project-version}</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
@@ -45,14 +45,14 @@ The plugin adds a new task goal `swagger2markup:convertSwagger2markup`. You can
|
||||
|
||||
You can customize the task by configuring a Map of <<Swagger2Markup properties>>.
|
||||
|
||||
[source,xml, subs="specialcharacters,attributes"]
|
||||
[source,xml]
|
||||
----
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>io.github.swagger2markup</groupId>
|
||||
<artifactId>swagger2markup-maven-plugin</artifactId>
|
||||
<version>{release-version}</version>
|
||||
<version>{project-version}</version>
|
||||
<configuration>
|
||||
<swaggerInput>${project.basedir}/src/docs/swagger/swagger_petstore.yaml</swaggerInput>
|
||||
<outputDir>${project.build.directory}/asciidoc</outputDir>
|
||||
@@ -7,14 +7,14 @@ Swagger2Markup converts a Swagger JSON or YAML specification into either **Ascii
|
||||
|
||||
==== Conversion of a local Swagger file
|
||||
|
||||
The entry point of the Swagger2Markup API is the ``Swagger2MarkupConverter`` class. This class provides static factory methods to create a `Swagger2MarkupConverter.Builder`.
|
||||
The entry point of the Swagger2Markup API is the ``Swagger2MarkupConverter`` class. This class provides static factory methods to create a `Swagger2MarkupConverter.Builder`.
|
||||
|
||||
[source,java,indent=0]
|
||||
----
|
||||
include::{coreProjectDir}/src/test/java/io/github/swagger2markup/DocumentationTest.java[tags=localSwaggerSpec]
|
||||
include::../../test/java/io/github/swagger2markup/DocumentationTest.java[tags=localSwaggerSpec]
|
||||
----
|
||||
|
||||
1. Create a ``Swagger2MarkupConverter.Builder`` by specifying the Path to the local file
|
||||
1. Create a ``Swagger2MarkupConverter.Builder`` by specifying the Path to the local file
|
||||
2. Build an instance of the ``Swagger2MarkupConverter``
|
||||
3. Invoke ``toFolder`` by specifying the output directory
|
||||
|
||||
@@ -26,7 +26,7 @@ You can convert a remote Swagger specification which must be accessible via HTTP
|
||||
|
||||
[source,java,indent=0]
|
||||
----
|
||||
include::{coreProjectDir}/src/test/java/io/github/swagger2markup/DocumentationTest.java[tags=remoteSwaggerSpec]
|
||||
include::../../test/java/io/github/swagger2markup/DocumentationTest.java[tags=remoteSwaggerSpec]
|
||||
----
|
||||
|
||||
1. Create a ``Swagger2MarkupConverter.Builder`` by specifying the URL to the remote file
|
||||
@@ -40,7 +40,7 @@ You can convert the Swagger specification into a file.
|
||||
|
||||
[source,java,indent=0]
|
||||
----
|
||||
include::{coreProjectDir}/src/test/java/io/github/swagger2markup/DocumentationTest.java[tags=convertIntoOneFile]
|
||||
include::../../test/java/io/github/swagger2markup/DocumentationTest.java[tags=convertIntoOneFile]
|
||||
----
|
||||
|
||||
==== Conversion to a String
|
||||
@@ -50,7 +50,7 @@ You can convert the Swagger specification to a String.
|
||||
|
||||
[source,java,indent=0]
|
||||
----
|
||||
include::{coreProjectDir}/src/test/java/io/github/swagger2markup/DocumentationTest.java[tags=convertIntoString]
|
||||
include::../../test/java/io/github/swagger2markup/DocumentationTest.java[tags=convertIntoString]
|
||||
----
|
||||
|
||||
=== Configuration
|
||||
@@ -69,7 +69,7 @@ You can configure the Swagger2MarkupConverter by using the `Swagger2MarkupConfig
|
||||
|
||||
[source,java,indent=0]
|
||||
----
|
||||
include::{coreProjectDir}/src/test/java/io/github/swagger2markup/DocumentationTest.java[tags=swagger2MarkupConfigBuilder]
|
||||
include::../../test/java/io/github/swagger2markup/DocumentationTest.java[tags=swagger2MarkupConfigBuilder]
|
||||
----
|
||||
|
||||
1. Create a `Swagger2MarkupConfigBuilder` using the default constructor.
|
||||
@@ -85,7 +85,7 @@ You can also create a `Swagger2MarkupConfig` from a Properties file, a `Map` or
|
||||
|
||||
[source,java,indent=0]
|
||||
----
|
||||
include::{coreProjectDir}/src/test/java/io/github/swagger2markup/DocumentationTest.java[tags=swagger2MarkupConfigFromProperties]
|
||||
include::../../test/java/io/github/swagger2markup/DocumentationTest.java[tags=swagger2MarkupConfigFromProperties]
|
||||
----
|
||||
1. Load a `Properties` file from the classpath or local filesystem.
|
||||
2. Create a `Swagger2MarkupConfigBuilder` using the proper constructor.
|
||||
@@ -94,7 +94,7 @@ include::{coreProjectDir}/src/test/java/io/github/swagger2markup/DocumentationTe
|
||||
|
||||
[source,java,indent=0]
|
||||
----
|
||||
include::{coreProjectDir}/src/test/java/io/github/swagger2markup/DocumentationTest.java[tags=swagger2MarkupConfigFromMap]
|
||||
include::../../test/java/io/github/swagger2markup/DocumentationTest.java[tags=swagger2MarkupConfigFromMap]
|
||||
----
|
||||
|
||||
1. Create a `Map` and configure the `Swagger2MarkupProperties`.
|
||||
@@ -113,7 +113,7 @@ Configuration parameters may be loaded from the following sources using Apache C
|
||||
|
||||
[source,java,indent=0]
|
||||
----
|
||||
include::{coreProjectDir}/src/test/java/io/github/swagger2markup/DocumentationTest.java[tags=swagger2MarkupConfigFromCommonsConfiguration]
|
||||
include::../../test/java/io/github/swagger2markup/DocumentationTest.java[tags=swagger2MarkupConfigFromCommonsConfiguration]
|
||||
----
|
||||
|
||||
1. Create an Apache Commons `Configuration` object using the proper ConfigurationBuilder.
|
||||
@@ -136,14 +136,12 @@ The following tables list all available properties of Swagger2Markup:
|
||||
|Name | Description | Possible Values | Default
|
||||
|swagger2markup.markupLanguage| Specifies the markup language which should be used to generate the files. | ASCIIDOC, MARKDOWN, CONFLUENCE_MARKUP | ASCIIDOC
|
||||
|swagger2markup.swaggerMarkupLanguage| Specifies the markup language used in Swagger descriptions. | ASCIIDOC, MARKDOWN, CONFLUENCE_MARKUP | MARKDOWN
|
||||
|swagger2markup.pathsGroupedBy| Specifies how the paths should be grouped | AS_IS, TAGS, REGEX | AS_IS
|
||||
|swagger2markup.pathsGroupedBy| Specifies how the paths should be grouped | AS_IS, TAGS | AS_IS
|
||||
|swagger2markup.outputLanguage| Specifies the language of the labels | EN, DE, FR, RU | EN
|
||||
|swagger2markup.lineSeparator| Specifies the line separator which should be used | UNIX, WINDOWS, MAC | <System-dependent>
|
||||
|swagger2markup.generatedExamplesEnabled| Specifies if HTTP request and response examples should be generated | true, false | false
|
||||
|swagger2markup.flatBodyEnabled| Optionally isolate the body parameter, if any, from other parameters | true, false | false
|
||||
|swagger2markup.pathSecuritySectionEnabled| Optionally disable the security section for path sections | true, false | true
|
||||
|swagger2markup.anchorPrefix| Optionally prefix all anchors for uniqueness if you want to include generated documents into a global documentation | Any String |
|
||||
|swagger2markup.basePathPrefixEnabled| Prepend the basePath to all paths | true, false | false
|
||||
|swagger2markup.headerRegex | Regular expression to use when grouping by RegEx | Any valid RegEx pattern with at least one capture group |
|
||||
|swagger2markup.anchorPrefix| Optionally prefix all anchors for uniqueness if you want to include generated documents into a global documentation | Any String |
|
||||
|===
|
||||
|
||||
[options="header"]
|
||||
@@ -183,7 +181,7 @@ The following tables list all available properties of Swagger2Markup:
|
||||
|===
|
||||
|Name | Description | Possible Values | Default
|
||||
|swagger2markup.interDocumentCrossReferencesEnabled| Enable use of inter-document cross-references when needed | true, false | false
|
||||
|swagger2markup.interDocumentCrossReferencesPrefix| Specifies a prefix for all inter-document cross-references for advanced usage | Any String |
|
||||
|swagger2markup.interDocumentCrossReferencesPrefix| Specifies a prefix for all inter-document cross-references for advanced usage | Any String |
|
||||
|===
|
||||
|
||||
[options="header"]
|
||||
@@ -193,66 +191,6 @@ The following tables list all available properties of Swagger2Markup:
|
||||
|swagger2markup.inlineSchemaEnabled| Enable inline object schema support | true, false | true
|
||||
|===
|
||||
|
||||
[options="header"]
|
||||
.Properties which configure page breaking
|
||||
|===
|
||||
|Name | Description | Possible Values | Default
|
||||
|swagger2markup.pageBreakLocations | Specifies where page breaks should be inserted. | BEFORE_OPERATION, BEFORE_OPERATION_DESCRIPTION, BEFORE_OPERATION_PARAMETERS, BEFORE_OPERATION_RESPONSES, BEFORE_OPERATION_CONSUMES, BEFORE_OPERATION_PRODUCES, BEFORE_OPERATION_EXAMPLE_REQUEST, BEFORE_OPERATION_EXAMPLE_RESPONSE, BEFORE_DEFINITION, AFTER_OPERATION, AFTER_OPERATION_DESCRIPTION, AFTER_OPERATION_PARAMETERS, AFTER_OPERATION_RESPONSES, AFTER_OPERATION_CONSUMES, AFTER_OPERATION_PRODUCES, AFTER_OPERATION_EXAMPLE_REQUEST, AFTER_OPERATION_EXAMPLE_RESPONSE, AFTER_DEFINITION | empty
|
||||
|===
|
||||
|
||||
|
||||
[options="header"]
|
||||
.Properties which configure examples generation
|
||||
|===
|
||||
|Name |Description |Possible Values |Default
|
||||
|
||||
|swagger2markup.generatedExamplesEnabled
|
||||
| Specifies if HTTP request and response examples should be generated
|
||||
| true, false
|
||||
| false
|
||||
|
||||
|swagger2markup.requestExamplesFormat
|
||||
| Specifies if `Request path` contents in `Example HTTP request` section should contain popular example utility
|
||||
invocation, e.g. `curl`
|
||||
a|
|
||||
* `basic` — example will have only endpoint and query params
|
||||
* `curl` — example with `curl` utility
|
||||
* `invoke-webrequest` — example with `Invoke-WebRequest` command of `powershell`
|
||||
| basic
|
||||
|
||||
|swagger2markup.requestExamplesSourceFormat
|
||||
|`Request path` source block code style format
|
||||
| `default` or any suppordet by asciidoc
|
||||
| none for `basic`, `bash` for `curl` and `powershell` for `WebRequest`
|
||||
|
||||
|swagger2markup.requestExamplesIncludeAllQueryParams
|
||||
|Specifies if `Request path` should contain required and optional params (if true) or only required (if false)
|
||||
|true, false
|
||||
|false
|
||||
|
||||
|swagger2markup.requestExamplesHost
|
||||
|Should we hide, inherit or override hostname (e.g. with google.com) from yml file
|
||||
|`hide`, `inherit` or string with hostname to be used in request example
|
||||
| hide
|
||||
|
||||
|swagger2markup.requestExamplesSchema
|
||||
|Should we hide, inherit or override schema (http, https name it) from yml file
|
||||
|`hide`, `inherit` or string with schema name to be used in request example
|
||||
| hide
|
||||
|
||||
|swagger2markup.requestExamplesHideBasePath
|
||||
|Should we hide or show base path in example request endpoint address
|
||||
|true, false
|
||||
|true
|
||||
|
||||
|swagger2markup.requestExamplesQueryArrayStyle
|
||||
|How we should output array query params
|
||||
|`single` — single time (similar to basic types), `commaSeparated` — single time with multiple comma separated values, `multiple` times with same param name and different values, `multiple[]` times with array brackets as param name suffix.
|
||||
|single
|
||||
|
||||
|
||||
|===
|
||||
|
||||
=== Logging
|
||||
|
||||
Swagger2Markup uses http://www.slf4j.org/[SLF4J] for all internal logging, but leaves the underlying log implementation open. To change the log level, you have the set the log level of the `io.github.swagger2markup` package.
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 Robert Winkler
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,11 +15,7 @@
|
||||
*/
|
||||
package io.github.swagger2markup;
|
||||
|
||||
/**
|
||||
* GroupBy enum for ordering
|
||||
*/
|
||||
public enum GroupBy {
|
||||
AS_IS,
|
||||
TAGS,
|
||||
REGEX
|
||||
TAGS
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 Robert Winkler
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -22,16 +22,11 @@ import java.util.Locale;
|
||||
* @author Maksim Myshkin
|
||||
*/
|
||||
public enum Language {
|
||||
EN(Locale.ENGLISH),
|
||||
EN(new Locale("en")),
|
||||
RU(new Locale("ru")),
|
||||
FR(Locale.FRENCH),
|
||||
DE(Locale.GERMAN),
|
||||
TR(new Locale("tr")),
|
||||
ZH(Locale.CHINESE),
|
||||
ES(new Locale("es")),
|
||||
BR(new Locale("pt", "BR")),
|
||||
JA(Locale.JAPANESE),
|
||||
PL(new Locale("pl"));
|
||||
FR(new Locale("fr")),
|
||||
DE(new Locale("de")),
|
||||
TR(new Locale("tr"));
|
||||
|
||||
private final Locale lang;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 Robert Winkler
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
206
src/main/java/io/github/swagger2markup/Swagger2MarkupConfig.java
Normal file
@@ -0,0 +1,206 @@
|
||||
/*
|
||||
* Copyright 2016 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.markup.builder.LineSeparator;
|
||||
import io.github.swagger2markup.markup.builder.MarkupLanguage;
|
||||
import io.github.swagger2markup.model.PathOperation;
|
||||
import io.swagger.models.parameters.Parameter;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
/**
|
||||
* Swagger2Markup configuration interface.
|
||||
*/
|
||||
public interface Swagger2MarkupConfig {
|
||||
|
||||
/**
|
||||
* Specifies the markup language which should be used to generate the files.
|
||||
*/
|
||||
MarkupLanguage getMarkupLanguage();
|
||||
|
||||
/**
|
||||
* Specifies the markup language used in Swagger descriptions.<br>
|
||||
* By default, {@link io.github.swagger2markup.markup.builder.MarkupLanguage#MARKDOWN} is assumed.
|
||||
*/
|
||||
MarkupLanguage getSwaggerMarkupLanguage();
|
||||
|
||||
/**
|
||||
* Include generated examples into the documents.
|
||||
*/
|
||||
boolean isGeneratedExamplesEnabled();
|
||||
|
||||
/**
|
||||
* In addition to the Definitions file, also create separate definition files for each model definition.
|
||||
*/
|
||||
boolean isSeparatedDefinitionsEnabled();
|
||||
|
||||
/**
|
||||
* In addition to the Paths file, also create separate operation files for each operation.
|
||||
*/
|
||||
boolean isSeparatedOperationsEnabled();
|
||||
|
||||
/**
|
||||
* Specifies if the operations should be grouped by tags or stay as-is.
|
||||
*/
|
||||
GroupBy getPathsGroupedBy();
|
||||
|
||||
/**
|
||||
* Specifies labels language of output files.
|
||||
*/
|
||||
Language getOutputLanguage();
|
||||
|
||||
/**
|
||||
* Specifies if inline schemas are detailed
|
||||
*/
|
||||
boolean isInlineSchemaEnabled();
|
||||
|
||||
/**
|
||||
* Specifies tag ordering.
|
||||
*/
|
||||
OrderBy getTagOrderBy();
|
||||
|
||||
/**
|
||||
* Specifies a custom comparator function to order tags.
|
||||
*/
|
||||
Comparator<String> getTagOrdering();
|
||||
|
||||
/**
|
||||
* Specifies operation ordering.
|
||||
*/
|
||||
OrderBy getOperationOrderBy();
|
||||
|
||||
/**
|
||||
* Specifies a custom comparator function to order operations.
|
||||
*/
|
||||
Comparator<PathOperation> getOperationOrdering();
|
||||
|
||||
/**
|
||||
* Specifies definition ordering.
|
||||
*/
|
||||
OrderBy getDefinitionOrderBy();
|
||||
|
||||
/**
|
||||
* Specifies a custom comparator function to order definitions.
|
||||
*/
|
||||
Comparator<String> getDefinitionOrdering();
|
||||
|
||||
/**
|
||||
* Specifies parameter ordering.
|
||||
*/
|
||||
OrderBy getParameterOrderBy();
|
||||
|
||||
/**
|
||||
* Specifies a custom comparator function to order parameters.
|
||||
*/
|
||||
Comparator<Parameter> getParameterOrdering();
|
||||
|
||||
/**
|
||||
* Specifies property ordering.
|
||||
*/
|
||||
OrderBy getPropertyOrderBy();
|
||||
|
||||
/**
|
||||
* Specifies a custom comparator function to order properties.
|
||||
*/
|
||||
Comparator<String> getPropertyOrdering();
|
||||
|
||||
/**
|
||||
* Specifies response ordering.
|
||||
*/
|
||||
OrderBy getResponseOrderBy();
|
||||
|
||||
/**
|
||||
* Specifies a custom comparator function to order responses.
|
||||
*/
|
||||
Comparator<String> getResponseOrdering();
|
||||
|
||||
/**
|
||||
* Enable use of inter-document cross-references when needed.
|
||||
*/
|
||||
boolean isInterDocumentCrossReferencesEnabled();
|
||||
|
||||
/**
|
||||
* Inter-document cross-references optional prefix.
|
||||
*/
|
||||
String getInterDocumentCrossReferencesPrefix();
|
||||
|
||||
/**
|
||||
* Optionally isolate the body parameter, if any, from other parameters.
|
||||
*/
|
||||
boolean isFlatBodyEnabled();
|
||||
|
||||
/**
|
||||
* Optionally prefix all anchors for uniqueness.
|
||||
*/
|
||||
String getAnchorPrefix();
|
||||
|
||||
/**
|
||||
* Overview document name (without extension).
|
||||
*
|
||||
* @return the overview document name (without extension)
|
||||
*/
|
||||
String getOverviewDocument();
|
||||
|
||||
/**
|
||||
* Paths document name (without extension).
|
||||
*
|
||||
* @return the paths document name (without extension)
|
||||
*/
|
||||
String getPathsDocument();
|
||||
|
||||
/**
|
||||
* Definitions document name (without extension).
|
||||
*
|
||||
* @return the definitions document name (without extension)
|
||||
*/
|
||||
String getDefinitionsDocument();
|
||||
|
||||
/**
|
||||
* Security document name (without extension).
|
||||
*
|
||||
* @return the security document name (without extension)
|
||||
*/
|
||||
String getSecurityDocument();
|
||||
|
||||
/**
|
||||
* Separated operations sub-folder name.
|
||||
*
|
||||
* @return the operations sub-folder name
|
||||
*/
|
||||
String getSeparatedOperationsFolder();
|
||||
|
||||
/**
|
||||
* Separated definitions sub-folder name.
|
||||
*
|
||||
* @return the definitions sub-folder name
|
||||
*/
|
||||
String getSeparatedDefinitionsFolder();
|
||||
|
||||
/**
|
||||
* Specifies the line separator which should be used.
|
||||
*
|
||||
* @return the line separator
|
||||
*/
|
||||
LineSeparator getLineSeparator();
|
||||
|
||||
/**
|
||||
* Returns properties for extensions.
|
||||
*
|
||||
* @return the extension properties
|
||||
*/
|
||||
Swagger2MarkupProperties getExtensionsProperties();
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 Robert Winkler
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,15 +17,11 @@ package io.github.swagger2markup;
|
||||
|
||||
import io.github.swagger2markup.builder.Swagger2MarkupConfigBuilder;
|
||||
import io.github.swagger2markup.builder.Swagger2MarkupExtensionRegistryBuilder;
|
||||
import io.github.swagger2markup.internal.document.DefinitionsDocument;
|
||||
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.markup.builder.LineSeparator;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilders;
|
||||
import io.github.swagger2markup.markup.builder.MarkupLanguage;
|
||||
import io.github.swagger2markup.spi.Swagger2MarkupExtensionRegistry;
|
||||
import io.github.swagger2markup.internal.document.builder.DefinitionsDocumentBuilder;
|
||||
import io.github.swagger2markup.internal.document.builder.OverviewDocumentBuilder;
|
||||
import io.github.swagger2markup.internal.document.builder.PathsDocumentBuilder;
|
||||
import io.github.swagger2markup.internal.document.builder.SecurityDocumentBuilder;
|
||||
import io.github.swagger2markup.spi.*;
|
||||
import io.github.swagger2markup.utils.URIUtils;
|
||||
import io.swagger.models.Swagger;
|
||||
import io.swagger.parser.SwaggerParser;
|
||||
@@ -49,20 +45,24 @@ import java.nio.file.StandardOpenOption;
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public class Swagger2MarkupConverter extends AbstractSchema2MarkupConverter<Swagger> {
|
||||
private final OverviewDocument overviewDocument;
|
||||
private final PathsDocument pathsDocument;
|
||||
private final DefinitionsDocument definitionsDocument;
|
||||
private final SecurityDocument securityDocument;
|
||||
private final SwaggerContext swaggerContext;
|
||||
public class Swagger2MarkupConverter {
|
||||
|
||||
public Swagger2MarkupConverter(SwaggerContext swaggerContext) {
|
||||
super(swaggerContext);
|
||||
this.swaggerContext = swaggerContext;
|
||||
this.overviewDocument = new OverviewDocument(swaggerContext);
|
||||
this.pathsDocument = new PathsDocument(swaggerContext);
|
||||
this.definitionsDocument = new DefinitionsDocument(swaggerContext);
|
||||
this.securityDocument = new SecurityDocument(swaggerContext);
|
||||
private Context context;
|
||||
|
||||
private Swagger2MarkupExtensionRegistry extensionRegistry;
|
||||
|
||||
public Swagger2MarkupConverter(Context globalContext, Swagger2MarkupExtensionRegistry extensionRegistry) {
|
||||
this.context = globalContext;
|
||||
this.extensionRegistry = extensionRegistry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the global Context
|
||||
*
|
||||
* @return the global Context
|
||||
*/
|
||||
Context getContext(){
|
||||
return context;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,15 +74,17 @@ public class Swagger2MarkupConverter extends AbstractSchema2MarkupConverter<Swag
|
||||
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")) {
|
||||
if(scheme != null && swaggerUri.getScheme().startsWith("http")){
|
||||
try {
|
||||
return from(swaggerUri.toURL());
|
||||
} catch (MalformedURLException e) {
|
||||
}
|
||||
catch (MalformedURLException e) {
|
||||
throw new RuntimeException("Failed to convert URI to URL", e);
|
||||
}
|
||||
} else if (scheme != null && swaggerUri.getScheme().startsWith("file")) {
|
||||
} else if(scheme != null && swaggerUri.getScheme().startsWith("file")){
|
||||
return from(Paths.get(swaggerUri));
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return from(URIUtils.convertUriWithoutSchemeToFileScheme(swaggerUri));
|
||||
}
|
||||
}
|
||||
@@ -93,7 +95,7 @@ public class Swagger2MarkupConverter extends AbstractSchema2MarkupConverter<Swag
|
||||
* @param swaggerURL the remote URL
|
||||
* @return a Swagger2MarkupConverter
|
||||
*/
|
||||
public static Builder from(URL swaggerURL) {
|
||||
public static Builder from(URL swaggerURL){
|
||||
Validate.notNull(swaggerURL, "swaggerURL must not be null");
|
||||
return new Builder(swaggerURL);
|
||||
}
|
||||
@@ -106,11 +108,11 @@ public class Swagger2MarkupConverter extends AbstractSchema2MarkupConverter<Swag
|
||||
*/
|
||||
public static Builder from(Path swaggerPath) {
|
||||
Validate.notNull(swaggerPath, "swaggerPath must not be null");
|
||||
if (Files.notExists(swaggerPath)) {
|
||||
if(Files.notExists(swaggerPath)){
|
||||
throw new IllegalArgumentException(String.format("swaggerPath does not exist: %s", swaggerPath));
|
||||
}
|
||||
try {
|
||||
if (Files.isHidden(swaggerPath)) {
|
||||
if(Files.isHidden(swaggerPath)){
|
||||
throw new IllegalArgumentException("swaggerPath must not be a hidden file");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
@@ -161,57 +163,18 @@ public class Swagger2MarkupConverter extends AbstractSchema2MarkupConverter<Swag
|
||||
return new Builder(swagger);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the global Context
|
||||
*
|
||||
* @return the global Context
|
||||
*/
|
||||
public SwaggerContext getContext() {
|
||||
return swaggerContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the Swagger specification into the given {@code outputDirectory}.
|
||||
*
|
||||
* @param outputDirectory the output directory path
|
||||
*/
|
||||
public void toFolder(Path outputDirectory) {
|
||||
public void toFolder(Path outputDirectory){
|
||||
Validate.notNull(outputDirectory, "outputDirectory must not be null");
|
||||
|
||||
swaggerContext.setOutputPath(outputDirectory);
|
||||
|
||||
applyOverviewDocument()
|
||||
.writeToFile(outputDirectory.resolve(swaggerContext.config.getOverviewDocument()), StandardCharsets.UTF_8);
|
||||
applyPathsDocument()
|
||||
.writeToFile(outputDirectory.resolve(swaggerContext.config.getPathsDocument()), StandardCharsets.UTF_8);
|
||||
applyDefinitionsDocument()
|
||||
.writeToFile(outputDirectory.resolve(swaggerContext.config.getDefinitionsDocument()), StandardCharsets.UTF_8);
|
||||
applySecurityDocument()
|
||||
.writeToFile(outputDirectory.resolve(swaggerContext.config.getSecurityDocument()), StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
private MarkupDocBuilder applyOverviewDocument() {
|
||||
return overviewDocument.apply(
|
||||
swaggerContext.createMarkupDocBuilder(),
|
||||
OverviewDocument.parameters(swaggerContext.getSchema()));
|
||||
}
|
||||
|
||||
private MarkupDocBuilder applyPathsDocument() {
|
||||
return pathsDocument.apply(
|
||||
swaggerContext.createMarkupDocBuilder(),
|
||||
PathsDocument.parameters(swaggerContext.getSchema().getPaths()));
|
||||
}
|
||||
|
||||
private MarkupDocBuilder applyDefinitionsDocument() {
|
||||
return definitionsDocument.apply(
|
||||
swaggerContext.createMarkupDocBuilder(),
|
||||
DefinitionsDocument.parameters(swaggerContext.getSchema().getDefinitions()));
|
||||
}
|
||||
|
||||
private MarkupDocBuilder applySecurityDocument() {
|
||||
return securityDocument.apply(
|
||||
swaggerContext.createMarkupDocBuilder(),
|
||||
SecurityDocument.parameters(swaggerContext.getSchema().getSecurityDefinitions()));
|
||||
|
||||
new OverviewDocumentBuilder(context, extensionRegistry, outputDirectory).build().writeToFile(outputDirectory.resolve(context.config.getOverviewDocument()), StandardCharsets.UTF_8);
|
||||
new PathsDocumentBuilder(context, extensionRegistry, outputDirectory).build().writeToFile(outputDirectory.resolve(context.config.getPathsDocument()), StandardCharsets.UTF_8);
|
||||
new DefinitionsDocumentBuilder(context, extensionRegistry, outputDirectory).build().writeToFile(outputDirectory.resolve(context.config.getDefinitionsDocument()), StandardCharsets.UTF_8);
|
||||
new SecurityDocumentBuilder(context, extensionRegistry, outputDirectory).build().writeToFile(outputDirectory.resolve(context.config.getSecurityDocument()), StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -239,10 +202,10 @@ public class Swagger2MarkupConverter extends AbstractSchema2MarkupConverter<Swag
|
||||
public void toFile(Path outputFile) {
|
||||
Validate.notNull(outputFile, "outputFile must not be null");
|
||||
|
||||
applyOverviewDocument().writeToFile(outputFile, StandardCharsets.UTF_8);
|
||||
applyPathsDocument().writeToFile(outputFile, StandardCharsets.UTF_8, StandardOpenOption.APPEND);
|
||||
applyDefinitionsDocument().writeToFile(outputFile, StandardCharsets.UTF_8, StandardOpenOption.APPEND);
|
||||
applySecurityDocument().writeToFile(outputFile, StandardCharsets.UTF_8, StandardOpenOption.APPEND);
|
||||
new OverviewDocumentBuilder(context,extensionRegistry, null).build().writeToFile(outputFile, StandardCharsets.UTF_8);
|
||||
new PathsDocumentBuilder(context, extensionRegistry, null).build().writeToFile(outputFile, StandardCharsets.UTF_8, StandardOpenOption.APPEND);
|
||||
new DefinitionsDocumentBuilder(context, extensionRegistry, null).build().writeToFile(outputFile, StandardCharsets.UTF_8, StandardOpenOption.APPEND);
|
||||
new SecurityDocumentBuilder(context, extensionRegistry, null).build().writeToFile(outputFile, StandardCharsets.UTF_8, StandardOpenOption.APPEND);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -250,13 +213,13 @@ public class Swagger2MarkupConverter extends AbstractSchema2MarkupConverter<Swag
|
||||
*
|
||||
* @param outputFile the output file
|
||||
*/
|
||||
public void toFileWithoutExtension(Path outputFile) {
|
||||
public void toFileWithoutExtension(Path outputFile){
|
||||
Validate.notNull(outputFile, "outputFile must not be null");
|
||||
|
||||
applyOverviewDocument().writeToFileWithoutExtension(outputFile, StandardCharsets.UTF_8);
|
||||
applyPathsDocument().writeToFileWithoutExtension(outputFile, StandardCharsets.UTF_8, StandardOpenOption.APPEND);
|
||||
applyDefinitionsDocument().writeToFileWithoutExtension(outputFile, StandardCharsets.UTF_8, StandardOpenOption.APPEND);
|
||||
applySecurityDocument().writeToFileWithoutExtension(outputFile, StandardCharsets.UTF_8, StandardOpenOption.APPEND);
|
||||
new OverviewDocumentBuilder(context, extensionRegistry, null).build().writeToFileWithoutExtension(outputFile, StandardCharsets.UTF_8);
|
||||
new PathsDocumentBuilder(context, extensionRegistry, null).build().writeToFileWithoutExtension(outputFile, StandardCharsets.UTF_8, StandardOpenOption.APPEND);
|
||||
new DefinitionsDocumentBuilder(context, extensionRegistry, null).build().writeToFileWithoutExtension(outputFile, StandardCharsets.UTF_8, StandardOpenOption.APPEND);
|
||||
new SecurityDocumentBuilder(context, extensionRegistry, null).build().writeToFileWithoutExtension(outputFile, StandardCharsets.UTF_8, StandardOpenOption.APPEND);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -267,10 +230,10 @@ public class Swagger2MarkupConverter extends AbstractSchema2MarkupConverter<Swag
|
||||
public String toString() {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(applyOverviewDocument().toString());
|
||||
sb.append(applyPathsDocument().toString());
|
||||
sb.append(applyDefinitionsDocument().toString());
|
||||
sb.append(applySecurityDocument().toString());
|
||||
sb.append(new OverviewDocumentBuilder(context,extensionRegistry, null).build().toString());
|
||||
sb.append(new PathsDocumentBuilder(context, extensionRegistry, null).build().toString());
|
||||
sb.append(new DefinitionsDocumentBuilder(context, extensionRegistry, null).build().toString());
|
||||
sb.append(new SecurityDocumentBuilder(context, extensionRegistry, null).build().toString());
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@@ -320,7 +283,7 @@ public class Swagger2MarkupConverter extends AbstractSchema2MarkupConverter<Swag
|
||||
* @param swaggerLocation the location of the Swagger source
|
||||
* @return the Swagger model
|
||||
*/
|
||||
private Swagger readSwagger(String swaggerLocation) {
|
||||
private Swagger readSwagger(String swaggerLocation){
|
||||
Swagger swagger = new SwaggerParser().read(swaggerLocation);
|
||||
if (swagger == null) {
|
||||
throw new IllegalArgumentException("Failed to read the Swagger source");
|
||||
@@ -346,62 +309,61 @@ public class Swagger2MarkupConverter extends AbstractSchema2MarkupConverter<Swag
|
||||
|
||||
if (extensionRegistry == null)
|
||||
extensionRegistry = new Swagger2MarkupExtensionRegistryBuilder().build();
|
||||
SwaggerLabels swaggerLabels = new SwaggerLabels(config);
|
||||
SwaggerContext context = new SwaggerContext(config, extensionRegistry, swagger, swaggerLocation, swaggerLabels);
|
||||
|
||||
Context context = new Context(config, swagger, swaggerLocation);
|
||||
|
||||
initExtensions(context);
|
||||
|
||||
applySwaggerExtensions(context);
|
||||
|
||||
return new Swagger2MarkupConverter(context);
|
||||
return new Swagger2MarkupConverter(context, extensionRegistry);
|
||||
}
|
||||
|
||||
private void initExtensions(SwaggerContext 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 initExtensions(Context context) {
|
||||
for (SwaggerModelExtension extension : extensionRegistry.getSwaggerModelExtensions())
|
||||
extension.setGlobalContext(context);
|
||||
|
||||
for (OverviewDocumentExtension extension : extensionRegistry.getOverviewDocumentExtensions())
|
||||
extension.setGlobalContext(context);
|
||||
|
||||
for (DefinitionsDocumentExtension extension : extensionRegistry.getDefinitionsDocumentExtensions())
|
||||
extension.setGlobalContext(context);
|
||||
|
||||
for (PathsDocumentExtension extension : extensionRegistry.getPathsDocumentExtensions())
|
||||
extension.setGlobalContext(context);
|
||||
|
||||
for (SecurityDocumentExtension extension : extensionRegistry.getSecurityDocumentExtensions())
|
||||
extension.setGlobalContext(context);
|
||||
}
|
||||
|
||||
private void applySwaggerExtensions(SwaggerContext context) {
|
||||
extensionRegistry.getSwaggerModelExtensions().forEach(extension -> extension.apply(context.getSchema()));
|
||||
private void applySwaggerExtensions(Context context) {
|
||||
for (SwaggerModelExtension swaggerModelExtension : extensionRegistry.getSwaggerModelExtensions()) {
|
||||
swaggerModelExtension.apply(context.getSwagger());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class SwaggerContext extends Context<Swagger> {
|
||||
public static class Context {
|
||||
private Swagger2MarkupConfig config;
|
||||
private Swagger2MarkupExtensionRegistry extensionRegistry;
|
||||
private Swagger swagger;
|
||||
private URI swaggerLocation;
|
||||
|
||||
public SwaggerContext(Swagger2MarkupConfig config,
|
||||
Swagger2MarkupExtensionRegistry extensionRegistry,
|
||||
Swagger schema, URI swaggerLocation, Labels labels) {
|
||||
super(config, extensionRegistry, schema, swaggerLocation, labels);
|
||||
Context(Swagger2MarkupConfig config, Swagger swagger, URI swaggerLocation) {
|
||||
this.config = config;
|
||||
this.extensionRegistry = extensionRegistry;
|
||||
this.swagger = swagger;
|
||||
this.swaggerLocation = swaggerLocation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Swagger2MarkupConfig getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Swagger2MarkupExtensionRegistry getExtensionRegistry() {
|
||||
return extensionRegistry;
|
||||
public Swagger getSwagger() {
|
||||
return swagger;
|
||||
}
|
||||
|
||||
public MarkupDocBuilder createMarkupDocBuilder() {
|
||||
MarkupLanguage markupLanguage = null;
|
||||
if (config.getMarkupLanguage() != null) {
|
||||
markupLanguage = MarkupLanguage.valueOf(config.getMarkupLanguage().name());
|
||||
}
|
||||
LineSeparator lineSeparator = null;
|
||||
if (config.getLineSeparator() != null) {
|
||||
lineSeparator = LineSeparator.valueOf(config.getLineSeparator().name());
|
||||
}
|
||||
return MarkupDocBuilders.documentBuilder(markupLanguage, lineSeparator,
|
||||
config.getAsciidocPegdownTimeoutMillis()).withAnchorPrefix(config.getAnchorPrefix());
|
||||
public URI getSwaggerLocation() {
|
||||
return swaggerLocation;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 Robert Winkler
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,47 +13,42 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.github.swagger2markup.spi;
|
||||
package io.github.swagger2markup;
|
||||
|
||||
import io.github.swagger2markup.extension.Schema2MarkupExtensionRegistry;
|
||||
import io.github.swagger2markup.spi.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Extension points registry interface.
|
||||
*/
|
||||
public interface Swagger2MarkupExtensionRegistry extends Schema2MarkupExtensionRegistry {
|
||||
public interface Swagger2MarkupExtensionRegistry {
|
||||
/**
|
||||
* SwaggerModelExtension extension point can be used to preprocess the Swagger model.
|
||||
*
|
||||
* @return registered extensions extending SwaggerModelExtension extension point
|
||||
*/
|
||||
List<SwaggerModelExtension> 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();
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 Robert Winkler
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,51 +15,40 @@
|
||||
*/
|
||||
package io.github.swagger2markup;
|
||||
|
||||
import io.github.swagger2markup.markup.builder.MarkupLanguage;
|
||||
import io.github.swagger2markup.utils.URIUtils;
|
||||
import org.apache.commons.collections4.IteratorUtils;
|
||||
import org.apache.commons.configuration2.Configuration;
|
||||
import org.apache.commons.configuration2.ConfigurationConverter;
|
||||
import org.apache.commons.configuration2.MapConfiguration;
|
||||
import org.apache.commons.configuration2.ex.ConversionException;
|
||||
|
||||
import java.net.URI;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.*;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Properties;
|
||||
|
||||
public class Schema2MarkupProperties {
|
||||
public class Swagger2MarkupProperties {
|
||||
|
||||
/**
|
||||
* Prefix for Swagger2Markup properties
|
||||
*/
|
||||
public static final String PROPERTIES_PREFIX = "swagger2markup";
|
||||
|
||||
public static final String REQUEST_EXAMPLES_FORMAT = PROPERTIES_PREFIX + ".requestExamplesFormat";
|
||||
public static final String REQUEST_EXAMPLES_SOURCE_FORMAT = PROPERTIES_PREFIX + ".requestExamplesSourceFormat";
|
||||
public static final String REQUEST_EXAMPLES_HOST = PROPERTIES_PREFIX + ".requestExamplesHost";
|
||||
public static final String REQUEST_EXAMPLES_SCHEMA = PROPERTIES_PREFIX + ".requestExamplesSchema";
|
||||
public static final String REQUEST_EXAMPLES_HIDE_BASE_PATH = PROPERTIES_PREFIX + ".requestExamplesHideBasePath";
|
||||
public static final String REQUEST_EXAMPLES_QUERY_ARRAY_STYLE = PROPERTIES_PREFIX +".requestExamplesQueryArrayStyle";
|
||||
public static final String REQUEST_EXAMPLES_INCLUDE_ALL_QUERY_PARAMS = PROPERTIES_PREFIX + ".requestExamplesIncludeAllQueryParams";
|
||||
public static final String MARKUP_LANGUAGE = PROPERTIES_PREFIX + ".markupLanguage";
|
||||
public static final String SWAGGER_MARKUP_LANGUAGE = PROPERTIES_PREFIX + ".swaggerMarkupLanguage";
|
||||
public static final String GENERATED_EXAMPLES_ENABLED = PROPERTIES_PREFIX + ".generatedExamplesEnabled";
|
||||
public static final String HOSTNAME_ENABLED = PROPERTIES_PREFIX + ".hostnameEnabled";
|
||||
public static final String BASE_PATH_PREFIX_ENABLED = PROPERTIES_PREFIX + ".basePathPrefixEnabled";
|
||||
public static final String SEPARATED_DEFINITIONS_ENABLED = PROPERTIES_PREFIX + ".separatedDefinitionsEnabled";
|
||||
public static final String SEPARATED_OPERATIONS_ENABLED = PROPERTIES_PREFIX + ".separatedOperationsEnabled";
|
||||
public static final String PATHS_GROUPED_BY = PROPERTIES_PREFIX + ".pathsGroupedBy";
|
||||
public static final String HEADER_REGEX = PROPERTIES_PREFIX + ".headerRegex";
|
||||
public static final String OUTPUT_LANGUAGE = PROPERTIES_PREFIX + ".outputLanguage";
|
||||
public static final String INLINE_SCHEMA_ENABLED = PROPERTIES_PREFIX + ".inlineSchemaEnabled";
|
||||
public static final String INTER_DOCUMENT_CROSS_REFERENCES_ENABLED = PROPERTIES_PREFIX + ".interDocumentCrossReferencesEnabled";
|
||||
public static final String INTER_DOCUMENT_CROSS_REFERENCES_PREFIX = PROPERTIES_PREFIX + ".interDocumentCrossReferencesPrefix";
|
||||
public static final String FLAT_BODY_ENABLED = PROPERTIES_PREFIX + ".flatBodyEnabled";
|
||||
public static final String PATH_SECURITY_SECTION_ENABLED = PROPERTIES_PREFIX + ".pathSecuritySectionEnabled";
|
||||
public static final String ANCHOR_PREFIX = PROPERTIES_PREFIX + ".anchorPrefix";
|
||||
public static final String LIST_DELIMITER = PROPERTIES_PREFIX + ".listDelimiter";
|
||||
public static final String LIST_DELIMITER_ENABLED = PROPERTIES_PREFIX + ".listDelimiterEnabled";
|
||||
public static final String OVERVIEW_DOCUMENT = PROPERTIES_PREFIX + ".overviewDocument";
|
||||
public static final String PATHS_DOCUMENT = PROPERTIES_PREFIX + ".pathsDocument";
|
||||
public static final String DEFINITIONS_DOCUMENT = PROPERTIES_PREFIX + ".definitionsDocument";
|
||||
@@ -73,8 +62,6 @@ public class Schema2MarkupProperties {
|
||||
public static final String PROPERTY_ORDER_BY = PROPERTIES_PREFIX + ".propertyOrderBy";
|
||||
public static final String RESPONSE_ORDER_BY = PROPERTIES_PREFIX + ".responseOrderBy";
|
||||
public static final String LINE_SEPARATOR = PROPERTIES_PREFIX + ".lineSeparator";
|
||||
public static final String PAGE_BREAK_LOCATIONS = PROPERTIES_PREFIX + ".pageBreakLocations";
|
||||
public static final String ASCIIDOC_PEGDOWN_TIMEOUT = PROPERTIES_PREFIX + ".asciidoc.pegdown.timeoutMillis";
|
||||
|
||||
/**
|
||||
* Prefix for Swagger2Markup extension properties
|
||||
@@ -83,76 +70,71 @@ public class Schema2MarkupProperties {
|
||||
|
||||
private final Configuration configuration;
|
||||
|
||||
public Schema2MarkupProperties(Properties properties) {
|
||||
public Swagger2MarkupProperties(Properties properties) {
|
||||
this(ConfigurationConverter.getConfiguration(properties));
|
||||
}
|
||||
|
||||
public Schema2MarkupProperties(Map<String, String> map) {
|
||||
public Swagger2MarkupProperties(Map<String, String> map) {
|
||||
this(new MapConfiguration(map));
|
||||
}
|
||||
|
||||
public Schema2MarkupProperties(Configuration configuration) {
|
||||
public Swagger2MarkupProperties(Configuration configuration){
|
||||
this.configuration = configuration;
|
||||
}
|
||||
|
||||
public Configuration getConfiguration() {
|
||||
return configuration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an optional String property value associated with the given key.
|
||||
*
|
||||
* @param key the property name to resolve
|
||||
*
|
||||
* @return The string property
|
||||
*/
|
||||
public Optional<String> getString(String key) {
|
||||
public Optional<String> getString(String key){
|
||||
return Optional.ofNullable(configuration.getString(key));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the String property value associated with the given key, or
|
||||
* {@code defaultValue} if the key cannot be resolved.
|
||||
*
|
||||
* @param key the property name to resolve
|
||||
* @param key the property name to resolve
|
||||
* @param defaultValue the default value to return if no value is found
|
||||
*
|
||||
* @return The string property
|
||||
*/
|
||||
public String getString(String key, String defaultValue) {
|
||||
public String getString(String key, String defaultValue){
|
||||
return configuration.getString(key, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the int property value associated with the given key, or
|
||||
* {@code defaultValue} if the key cannot be resolved.
|
||||
*
|
||||
* @param key the property name to resolve
|
||||
* @param key the property name to resolve
|
||||
* @param defaultValue the default value to return if no value is found
|
||||
*
|
||||
* @return The int property
|
||||
*/
|
||||
public int getInt(String key, int defaultValue) {
|
||||
public int getInt(String key, int defaultValue){
|
||||
return configuration.getInt(key, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an optional Integer property value associated with the given key.
|
||||
*
|
||||
* @param key the property name to resolve
|
||||
*
|
||||
* @return An optional Integer property
|
||||
*/
|
||||
public Optional<Integer> getInteger(String key) {
|
||||
public Optional<Integer> getInteger(String key){
|
||||
return Optional.ofNullable(configuration.getInteger(key, null));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the int property value associated with the given key (never {@code null}).
|
||||
*
|
||||
* @param key the property name to resolve
|
||||
* @return The int property
|
||||
* @throws IllegalStateException if the key cannot be
|
||||
*
|
||||
* @return The int property
|
||||
*/
|
||||
public int getRequiredInt(String key) {
|
||||
public int getRequiredInt(String key){
|
||||
Optional<Integer> value = getInteger(key);
|
||||
if (value.isPresent()) {
|
||||
if(value.isPresent()){
|
||||
return value.get();
|
||||
}
|
||||
throw new IllegalStateException(String.format("required key [%s] not found", key));
|
||||
@@ -160,16 +142,15 @@ public class Schema2MarkupProperties {
|
||||
|
||||
/**
|
||||
* Return the boolean property value associated with the given key (never {@code null}).
|
||||
*
|
||||
* @param key the property name to resolve
|
||||
* @return The boolean property
|
||||
* @throws IllegalStateException if the key cannot be resolved
|
||||
*
|
||||
* @return The boolean property
|
||||
*/
|
||||
public boolean getRequiredBoolean(String key) {
|
||||
public boolean getRequiredBoolean(String key){
|
||||
Boolean value = configuration.getBoolean(key, null);
|
||||
if (value != null) {
|
||||
if(value != null){
|
||||
return value;
|
||||
} else {
|
||||
}else{
|
||||
throw new IllegalStateException(String.format("required key [%s] not found", key));
|
||||
}
|
||||
}
|
||||
@@ -177,40 +158,43 @@ public class Schema2MarkupProperties {
|
||||
/**
|
||||
* Return the boolean property value associated with the given key, or
|
||||
* {@code defaultValue} if the key cannot be resolved.
|
||||
*
|
||||
* @param key the property name to resolve
|
||||
* @param key the property name to resolve
|
||||
* @param defaultValue the default value to return if no value is found
|
||||
*
|
||||
* @return The boolean property
|
||||
*/
|
||||
public boolean getBoolean(String key, boolean defaultValue) {
|
||||
public boolean getBoolean(String key, boolean defaultValue){
|
||||
return configuration.getBoolean(key, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the URI property value associated with the given key, or
|
||||
* {@code defaultValue} if the key cannot be resolved.
|
||||
*
|
||||
* @param key the property name to resolve
|
||||
* @return The URI property
|
||||
* @throws IllegalStateException if the value cannot be mapped to the enum
|
||||
*
|
||||
* @return The URI property
|
||||
*/
|
||||
public Optional<URI> getURI(String key) {
|
||||
public Optional<URI> getURI(String key){
|
||||
Optional<String> property = getString(key);
|
||||
return property.map(URIUtils::create);
|
||||
if(property.isPresent()){
|
||||
return Optional.of(URIUtils.create(property.get()));
|
||||
}else{
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the URI property value associated with the given key (never {@code null}).
|
||||
*
|
||||
* @param key the property name to resolve
|
||||
* @return The URI property
|
||||
* @throws IllegalStateException if the key cannot be resolved
|
||||
*
|
||||
* @return The URI property
|
||||
*/
|
||||
public URI getRequiredURI(String key) {
|
||||
public URI getRequiredURI(String key){
|
||||
Optional<String> property = getString(key);
|
||||
if (property.isPresent()) {
|
||||
if(property.isPresent()){
|
||||
return URIUtils.create(property.get());
|
||||
} else {
|
||||
}else{
|
||||
throw new IllegalStateException(String.format("required key [%s] not found", key));
|
||||
}
|
||||
}
|
||||
@@ -218,126 +202,107 @@ public class Schema2MarkupProperties {
|
||||
/**
|
||||
* Return the Path property value associated with the given key, or
|
||||
* {@code defaultValue} if the key cannot be resolved.
|
||||
*
|
||||
* @param key the property name to resolve
|
||||
* @return The Path property
|
||||
* @throws IllegalStateException if the value cannot be mapped to the enum
|
||||
*/
|
||||
public Optional<Path> getPath(String key) {
|
||||
Optional<String> property = getString(key);
|
||||
return property.map(s -> Paths.get(s));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of Path property values associated with the given key,
|
||||
* or {@code defaultValue} if the key cannot be resolved.
|
||||
*
|
||||
* @param key the property name to resolve
|
||||
* @return The list of Path properties
|
||||
* @throws IllegalStateException if the value cannot be mapped to an array of strings
|
||||
* @return The Path property
|
||||
*/
|
||||
public List<Path> getPathList(String key) {
|
||||
List<Path> pathList = new ArrayList<>();
|
||||
|
||||
try {
|
||||
String[] stringList = configuration.getStringArray(key);
|
||||
|
||||
for (String pathStr : stringList) {
|
||||
pathList.add(Paths.get(pathStr));
|
||||
}
|
||||
} catch (ConversionException ce) {
|
||||
throw new IllegalStateException(String.format("requested key [%s] is not convertable to an array", key));
|
||||
public Optional<Path> getPath(String key){
|
||||
Optional<String> property = getString(key);
|
||||
if(property.isPresent()){
|
||||
return Optional.of(Paths.get(property.get()));
|
||||
}else{
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
return pathList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the Path property value associated with the given key (never {@code null}).
|
||||
*
|
||||
* @param key the property name to resolve
|
||||
* @return The Path property
|
||||
* @throws IllegalStateException if the key cannot be resolved
|
||||
*
|
||||
* @return The Path property
|
||||
*/
|
||||
public Path getRequiredPath(String key) {
|
||||
public Path getRequiredPath(String key){
|
||||
Optional<String> property = getString(key);
|
||||
if (property.isPresent()) {
|
||||
if(property.isPresent()){
|
||||
return Paths.get(property.get());
|
||||
} else {
|
||||
}else{
|
||||
throw new IllegalStateException(String.format("required key [%s] not found", key));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the OutputLanguage property value associated with the given key, or
|
||||
* Return the MarkupLanguage property value associated with the given key, or
|
||||
* {@code defaultValue} if the key cannot be resolved.
|
||||
*
|
||||
* @param key the property name to resolve
|
||||
* @return The OutputLanguage property
|
||||
*
|
||||
* @return The MarkupLanguage property
|
||||
*/
|
||||
public Optional<MarkupLanguage> getMarkupLanguage(String key) {
|
||||
public Optional<MarkupLanguage> getMarkupLanguage(String key){
|
||||
Optional<String> property = getString(key);
|
||||
return property.map(MarkupLanguage::valueOf);
|
||||
if(property.isPresent()){
|
||||
return Optional.of(MarkupLanguage.valueOf(property.get()));
|
||||
}else{
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the OutputLanguage property value associated with the given key (never {@code null}).
|
||||
*
|
||||
* @param key the property name to resolve
|
||||
* @return The OutputLanguage property
|
||||
* Return the MarkupLanguage property value associated with the given key (never {@code null}).
|
||||
* @throws IllegalStateException if the key cannot be resolved
|
||||
*
|
||||
* @return The MarkupLanguage property
|
||||
*/
|
||||
public MarkupLanguage getRequiredMarkupLanguage(String key) {
|
||||
public MarkupLanguage getRequiredMarkupLanguage(String key){
|
||||
return MarkupLanguage.valueOf(configuration.getString(key));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the Language property value associated with the given key, or
|
||||
* {@code defaultValue} if the key cannot be resolved.
|
||||
*
|
||||
* @param key the property name to resolve
|
||||
*
|
||||
* @return The Language property
|
||||
*/
|
||||
public Language getLanguage(String key) {
|
||||
public Language getLanguage(String key){
|
||||
return Language.valueOf(configuration.getString(key));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the GroupBy property value associated with the given key, or
|
||||
* {@code defaultValue} if the key cannot be resolved.
|
||||
*
|
||||
* @param key the property name to resolve
|
||||
* @return The GroupBy property
|
||||
* @throws IllegalStateException if the value cannot be mapped to the enum
|
||||
*
|
||||
* @return The GroupBy property
|
||||
*/
|
||||
public GroupBy getGroupBy(String key) {
|
||||
public GroupBy getGroupBy(String key){
|
||||
return GroupBy.valueOf(configuration.getString(key));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the OrderBy property value associated with the given key, or
|
||||
* {@code defaultValue} if the key cannot be resolved.
|
||||
*
|
||||
* @param key the property name to resolve
|
||||
* @return The OrderBy property
|
||||
* @throws IllegalStateException if the value cannot be mapped to the enum
|
||||
*
|
||||
* @return The OrderBy property
|
||||
*/
|
||||
public OrderBy getOrderBy(String key) {
|
||||
public OrderBy getOrderBy(String key){
|
||||
return OrderBy.valueOf(configuration.getString(key));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the String property value associated with the given key (never {@code null}).
|
||||
*
|
||||
* @param key the property name to resolve
|
||||
* @return The String property
|
||||
* @throws IllegalStateException if the key cannot be resolved
|
||||
*
|
||||
* @return The String property
|
||||
*/
|
||||
public String getRequiredString(String key) throws IllegalStateException {
|
||||
public String getRequiredString(String key) throws IllegalStateException{
|
||||
Optional<String> property = getString(key);
|
||||
if (property.isPresent()) {
|
||||
if(property.isPresent()){
|
||||
return property.get();
|
||||
} else {
|
||||
}else{
|
||||
throw new IllegalStateException(String.format("required key [%s] not found", key));
|
||||
}
|
||||
}
|
||||
@@ -347,7 +312,7 @@ public class Schema2MarkupProperties {
|
||||
*
|
||||
* @return the list of keys.
|
||||
*/
|
||||
public List<String> getKeys() {
|
||||
public List<String> getKeys(){
|
||||
return IteratorUtils.toList(configuration.getKeys());
|
||||
}
|
||||
|
||||
@@ -364,21 +329,10 @@ public class Schema2MarkupProperties {
|
||||
* interpreted - depends on a concrete implementation.
|
||||
*
|
||||
* @param prefix The prefix to test against.
|
||||
*
|
||||
* @return the list of keys.
|
||||
*/
|
||||
public List<String> getKeys(String prefix) {
|
||||
public List<String> getKeys(String prefix){
|
||||
return IteratorUtils.toList(configuration.getKeys(prefix));
|
||||
}
|
||||
|
||||
public List<PageBreakLocations> getPageBreakLocations(String key) {
|
||||
List<PageBreakLocations> result = configuration.getList(PageBreakLocations.class, key);
|
||||
if (result == null) result = new ArrayList<>();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public Optional<Pattern> getHeaderPattern(String key) {
|
||||
Optional<String> property = getString(key);
|
||||
return property.map(Pattern::compile);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,690 @@
|
||||
/*
|
||||
* Copyright 2016 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.builder;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Ordering;
|
||||
import io.github.swagger2markup.*;
|
||||
import io.github.swagger2markup.markup.builder.LineSeparator;
|
||||
import io.github.swagger2markup.markup.builder.MarkupLanguage;
|
||||
import io.github.swagger2markup.model.PathOperation;
|
||||
import io.swagger.models.HttpMethod;
|
||||
import io.swagger.models.parameters.Parameter;
|
||||
import org.apache.commons.configuration2.*;
|
||||
import org.apache.commons.configuration2.builder.fluent.Configurations;
|
||||
import org.apache.commons.configuration2.ex.ConfigurationException;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Properties;
|
||||
|
||||
import static io.github.swagger2markup.Swagger2MarkupProperties.*;
|
||||
|
||||
public class Swagger2MarkupConfigBuilder {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(Swagger2MarkupConfigBuilder.class);
|
||||
|
||||
private static final String PROPERTIES_DEFAULT = "io/github/swagger2markup/config/default.properties";
|
||||
|
||||
static final Ordering<PathOperation> OPERATION_METHOD_NATURAL_ORDERING = Ordering
|
||||
.explicit(HttpMethod.POST, HttpMethod.GET, HttpMethod.PUT, HttpMethod.DELETE, HttpMethod.PATCH, HttpMethod.HEAD, HttpMethod.OPTIONS)
|
||||
.onResultOf(new Function<PathOperation, HttpMethod>() {
|
||||
public HttpMethod apply(PathOperation operation) {
|
||||
return operation.getMethod();
|
||||
}
|
||||
});
|
||||
|
||||
static final Ordering<PathOperation> OPERATION_PATH_NATURAL_ORDERING = Ordering
|
||||
.natural()
|
||||
.onResultOf(new Function<PathOperation, String>() {
|
||||
public String apply(PathOperation operation) {
|
||||
return operation.getPath();
|
||||
}
|
||||
});
|
||||
|
||||
static final Ordering<Parameter> PARAMETER_IN_NATURAL_ORDERING = Ordering
|
||||
.explicit("header", "path", "query", "formData", "body")
|
||||
.onResultOf(new Function<Parameter, String>() {
|
||||
public String apply(Parameter parameter) {
|
||||
return parameter.getIn();
|
||||
}
|
||||
});
|
||||
|
||||
static final Ordering<Parameter> PARAMETER_NAME_NATURAL_ORDERING = Ordering
|
||||
.natural()
|
||||
.onResultOf(new Function<Parameter, String>() {
|
||||
public String apply(Parameter parameter) {
|
||||
return parameter.getName();
|
||||
}
|
||||
});
|
||||
|
||||
DefaultSwagger2MarkupConfig config = new DefaultSwagger2MarkupConfig();
|
||||
|
||||
public Swagger2MarkupConfigBuilder() {
|
||||
this(new PropertiesConfiguration());
|
||||
}
|
||||
|
||||
public Swagger2MarkupConfigBuilder(Properties properties) {
|
||||
this(ConfigurationConverter.getConfiguration(properties));
|
||||
}
|
||||
|
||||
public Swagger2MarkupConfigBuilder(Map<String, String> map) {
|
||||
this(new MapConfiguration(map));
|
||||
}
|
||||
|
||||
public Swagger2MarkupConfigBuilder(Configuration configuration) {
|
||||
CompositeConfiguration compositeConfiguration = new CompositeConfiguration();
|
||||
compositeConfiguration.addConfiguration(new SystemConfiguration());
|
||||
compositeConfiguration.addConfiguration(configuration);
|
||||
compositeConfiguration.addConfiguration(getDefaultConfiguration());
|
||||
|
||||
Swagger2MarkupProperties swagger2MarkupProperties = new Swagger2MarkupProperties(compositeConfiguration);
|
||||
|
||||
config.markupLanguage = swagger2MarkupProperties.getRequiredMarkupLanguage(MARKUP_LANGUAGE);
|
||||
config.swaggerMarkupLanguage = swagger2MarkupProperties.getRequiredMarkupLanguage(SWAGGER_MARKUP_LANGUAGE);
|
||||
config.generatedExamplesEnabled = swagger2MarkupProperties.getRequiredBoolean(GENERATED_EXAMPLES_ENABLED);
|
||||
config.separatedDefinitionsEnabled = swagger2MarkupProperties.getRequiredBoolean(SEPARATED_DEFINITIONS_ENABLED);
|
||||
config.separatedOperationsEnabled = swagger2MarkupProperties.getRequiredBoolean(SEPARATED_OPERATIONS_ENABLED);
|
||||
config.pathsGroupedBy = swagger2MarkupProperties.getGroupBy(PATHS_GROUPED_BY);
|
||||
config.outputLanguage = swagger2MarkupProperties.getLanguage(OUTPUT_LANGUAGE);
|
||||
config.inlineSchemaEnabled = swagger2MarkupProperties.getRequiredBoolean(INLINE_SCHEMA_ENABLED);
|
||||
config.interDocumentCrossReferencesEnabled = swagger2MarkupProperties.getRequiredBoolean(INTER_DOCUMENT_CROSS_REFERENCES_ENABLED);
|
||||
config.interDocumentCrossReferencesPrefix = swagger2MarkupProperties.getString(INTER_DOCUMENT_CROSS_REFERENCES_PREFIX, null);
|
||||
config.flatBodyEnabled = swagger2MarkupProperties.getRequiredBoolean(FLAT_BODY_ENABLED);
|
||||
config.anchorPrefix = swagger2MarkupProperties.getString(ANCHOR_PREFIX, null);
|
||||
config.overviewDocument = swagger2MarkupProperties.getRequiredString(OVERVIEW_DOCUMENT);
|
||||
config.pathsDocument = swagger2MarkupProperties.getRequiredString(PATHS_DOCUMENT);
|
||||
config.definitionsDocument = swagger2MarkupProperties.getRequiredString(DEFINITIONS_DOCUMENT);
|
||||
config.securityDocument = swagger2MarkupProperties.getRequiredString(SECURITY_DOCUMENT);
|
||||
config.separatedOperationsFolder = swagger2MarkupProperties.getRequiredString(SEPARATED_OPERATIONS_FOLDER);
|
||||
config.separatedDefinitionsFolder = swagger2MarkupProperties.getRequiredString(SEPARATED_DEFINITIONS_FOLDER);
|
||||
config.tagOrderBy = swagger2MarkupProperties.getOrderBy(TAG_ORDER_BY);
|
||||
config.operationOrderBy = swagger2MarkupProperties.getOrderBy(OPERATION_ORDER_BY);
|
||||
config.definitionOrderBy = swagger2MarkupProperties.getOrderBy(DEFINITION_ORDER_BY);
|
||||
config.parameterOrderBy = swagger2MarkupProperties.getOrderBy(PARAMETER_ORDER_BY);
|
||||
config.propertyOrderBy = swagger2MarkupProperties.getOrderBy(PROPERTY_ORDER_BY);
|
||||
config.responseOrderBy = swagger2MarkupProperties.getOrderBy(RESPONSE_ORDER_BY);
|
||||
Optional<String> lineSeparator = swagger2MarkupProperties.getString(LINE_SEPARATOR);
|
||||
if(lineSeparator.isPresent() && StringUtils.isNoneBlank(lineSeparator.get())){
|
||||
config.lineSeparator = LineSeparator.valueOf(lineSeparator.get());
|
||||
}
|
||||
|
||||
Configuration swagger2markupConfiguration = compositeConfiguration.subset(PROPERTIES_PREFIX);
|
||||
Configuration extensionsConfiguration = swagger2markupConfiguration.subset(EXTENSION_PREFIX);
|
||||
config.extensionsProperties = new Swagger2MarkupProperties(extensionsConfiguration);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the default properties from the classpath.
|
||||
*
|
||||
* @return the default properties
|
||||
*/
|
||||
private Configuration getDefaultConfiguration() {
|
||||
Configurations configs = new Configurations();
|
||||
try {
|
||||
return configs.properties(PROPERTIES_DEFAULT);
|
||||
} catch (ConfigurationException e) {
|
||||
throw new RuntimeException(String.format("Can't load default properties '%s'", PROPERTIES_DEFAULT), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the Swagger2MarkupConfig.
|
||||
*
|
||||
* @return the Swagger2MarkupConfig
|
||||
*/
|
||||
public Swagger2MarkupConfig build() {
|
||||
buildNaturalOrdering();
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
private void buildNaturalOrdering() {
|
||||
if (config.tagOrderBy == OrderBy.NATURAL)
|
||||
config.tagOrdering = Ordering.natural();
|
||||
if (config.operationOrderBy == OrderBy.NATURAL)
|
||||
config.operationOrdering = OPERATION_PATH_NATURAL_ORDERING.compound(OPERATION_METHOD_NATURAL_ORDERING);
|
||||
if (config.definitionOrderBy == OrderBy.NATURAL)
|
||||
config.definitionOrdering = Ordering.natural();
|
||||
if (config.parameterOrderBy == OrderBy.NATURAL)
|
||||
config.parameterOrdering = PARAMETER_IN_NATURAL_ORDERING.compound(PARAMETER_NAME_NATURAL_ORDERING);
|
||||
if (config.propertyOrderBy == OrderBy.NATURAL)
|
||||
config.propertyOrdering = Ordering.natural();
|
||||
if (config.responseOrderBy == OrderBy.NATURAL)
|
||||
config.responseOrdering = Ordering.natural();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 this builder
|
||||
*/
|
||||
public Swagger2MarkupConfigBuilder withMarkupLanguage(MarkupLanguage markupLanguage) {
|
||||
Validate.notNull(markupLanguage, "%s must not be null", "markupLanguage");
|
||||
config.markupLanguage = markupLanguage;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies the markup language used in Swagger descriptions.
|
||||
*
|
||||
* @param swaggerMarkupLanguage the markup language used in Swagger descriptions
|
||||
* @return this builder
|
||||
*/
|
||||
public Swagger2MarkupConfigBuilder withSwaggerMarkupLanguage(MarkupLanguage swaggerMarkupLanguage) {
|
||||
Validate.notNull(swaggerMarkupLanguage, "%s must not be null", "swaggerMarkupLanguage");
|
||||
config.swaggerMarkupLanguage = swaggerMarkupLanguage;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Include generated examples into the documents.
|
||||
*
|
||||
* @return this builder
|
||||
*/
|
||||
public Swagger2MarkupConfigBuilder withGeneratedExamples() {
|
||||
config.generatedExamplesEnabled = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* In addition to the Definitions file, also create separate definition files for each model definition.
|
||||
*
|
||||
* @return this builder
|
||||
*/
|
||||
public Swagger2MarkupConfigBuilder withSeparatedDefinitions() {
|
||||
config.separatedDefinitionsEnabled = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* In addition to the Paths file, also create separate operation files for each operation.
|
||||
*
|
||||
* @return this builder
|
||||
*/
|
||||
public Swagger2MarkupConfigBuilder withSeparatedOperations() {
|
||||
config.separatedOperationsEnabled = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Specifies if the paths should be grouped by tags or stay as-is.
|
||||
*
|
||||
* @param pathsGroupedBy the GroupBy enum
|
||||
* @return this builder
|
||||
*/
|
||||
public Swagger2MarkupConfigBuilder withPathsGroupedBy(GroupBy pathsGroupedBy) {
|
||||
Validate.notNull(pathsGroupedBy, "%s must not be null", "pathsGroupedBy");
|
||||
config.pathsGroupedBy = pathsGroupedBy;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies labels language of output files.
|
||||
*
|
||||
* @param language the enum
|
||||
* @return this builder
|
||||
*/
|
||||
public Swagger2MarkupConfigBuilder withOutputLanguage(Language language) {
|
||||
Validate.notNull(language, "%s must not be null", "language");
|
||||
config.outputLanguage = language;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable inline schema support.
|
||||
*
|
||||
* @return this builder
|
||||
*/
|
||||
public Swagger2MarkupConfigBuilder withoutInlineSchema() {
|
||||
config.inlineSchemaEnabled = false;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies tag ordering.<br>
|
||||
* By default tag ordering == {@link io.github.swagger2markup.OrderBy#NATURAL}.<br>
|
||||
* Use {@link #withTagOrdering(Comparator)} to set a custom ordering.
|
||||
*
|
||||
* @param orderBy tag ordering
|
||||
* @return this builder
|
||||
*/
|
||||
public Swagger2MarkupConfigBuilder withTagOrdering(OrderBy orderBy) {
|
||||
Validate.notNull(orderBy, "%s must not be null", "orderBy");
|
||||
Validate.isTrue(orderBy != OrderBy.CUSTOM, "You must provide a custom comparator if orderBy == OrderBy.CUSTOM");
|
||||
config.tagOrderBy = orderBy;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies a custom comparator function to order tags.
|
||||
*
|
||||
* @param tagOrdering tag ordering
|
||||
* @return this builder
|
||||
*/
|
||||
public Swagger2MarkupConfigBuilder withTagOrdering(Comparator<String> tagOrdering) {
|
||||
Validate.notNull(tagOrdering, "%s must not be null", "tagOrdering");
|
||||
config.tagOrderBy = OrderBy.CUSTOM;
|
||||
config.tagOrdering = tagOrdering;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies operation ordering.<br>
|
||||
* By default operation ordering == {@link io.github.swagger2markup.OrderBy#AS_IS}.<br>
|
||||
* Use {@link #withOperationOrdering(Comparator)} to set a custom ordering.
|
||||
*
|
||||
* @param orderBy operation ordering
|
||||
* @return this builder
|
||||
*/
|
||||
public Swagger2MarkupConfigBuilder withOperationOrdering(OrderBy orderBy) {
|
||||
Validate.notNull(orderBy, "%s must not be null", "orderBy");
|
||||
Validate.isTrue(orderBy != OrderBy.CUSTOM, "You must provide a custom comparator if orderBy == OrderBy.CUSTOM");
|
||||
config.operationOrderBy = orderBy;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies a custom comparator function to order operations.
|
||||
*
|
||||
* @param operationOrdering operation ordering
|
||||
* @return this builder
|
||||
*/
|
||||
public Swagger2MarkupConfigBuilder withOperationOrdering(Comparator<PathOperation> operationOrdering) {
|
||||
Validate.notNull(operationOrdering, "%s must not be null", "operationOrdering");
|
||||
config.operationOrderBy = OrderBy.CUSTOM;
|
||||
config.operationOrdering = operationOrdering;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies definition ordering.<br>
|
||||
* By default definition ordering == {@link io.github.swagger2markup.OrderBy#NATURAL}.<br>
|
||||
* Use {@link #withDefinitionOrdering(Comparator)} to set a custom ordering.
|
||||
*
|
||||
* @param orderBy definition ordering
|
||||
* @return this builder
|
||||
*/
|
||||
public Swagger2MarkupConfigBuilder withDefinitionOrdering(OrderBy orderBy) {
|
||||
Validate.notNull(orderBy, "%s must not be null", "orderBy");
|
||||
Validate.isTrue(orderBy != OrderBy.CUSTOM, "You must provide a custom comparator if orderBy == OrderBy.CUSTOM");
|
||||
config.definitionOrderBy = orderBy;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies a custom comparator function to order definitions.
|
||||
*
|
||||
* @param definitionOrdering definition ordering
|
||||
* @return this builder
|
||||
*/
|
||||
public Swagger2MarkupConfigBuilder withDefinitionOrdering(Comparator<String> definitionOrdering) {
|
||||
Validate.notNull(definitionOrdering, "%s must not be null", "definitionOrdering");
|
||||
config.definitionOrderBy = OrderBy.CUSTOM;
|
||||
config.definitionOrdering = definitionOrdering;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies parameter ordering.<br>
|
||||
* By default parameter ordering == {@link OrderBy#NATURAL}.<br>
|
||||
* Use {@link #withParameterOrdering(Comparator)} to set a custom ordering.
|
||||
*
|
||||
* @param orderBy parameter ordering
|
||||
* @return this builder
|
||||
*/
|
||||
public Swagger2MarkupConfigBuilder withParameterOrdering(OrderBy orderBy) {
|
||||
Validate.notNull(orderBy, "%s must not be null", "orderBy");
|
||||
Validate.isTrue(orderBy != OrderBy.CUSTOM, "You must provide a custom comparator if orderBy == OrderBy.CUSTOM");
|
||||
config.parameterOrderBy = orderBy;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies a custom comparator function to order parameters.
|
||||
*
|
||||
* @param parameterOrdering parameter ordering
|
||||
* @return this builder
|
||||
*/
|
||||
public Swagger2MarkupConfigBuilder withParameterOrdering(Comparator<Parameter> parameterOrdering) {
|
||||
Validate.notNull(parameterOrdering, "%s must not be null", "parameterOrdering");
|
||||
|
||||
config.parameterOrderBy = OrderBy.CUSTOM;
|
||||
config.parameterOrdering = parameterOrdering;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies property ordering.<br>
|
||||
* By default property ordering == {@link io.github.swagger2markup.OrderBy#NATURAL}.<br>
|
||||
* Use {@link #withPropertyOrdering(Comparator)} to set a custom ordering.
|
||||
*
|
||||
* @param orderBy property ordering
|
||||
* @return this builder
|
||||
*/
|
||||
public Swagger2MarkupConfigBuilder withPropertyOrdering(OrderBy orderBy) {
|
||||
Validate.notNull(orderBy, "%s must not be null", "orderBy");
|
||||
Validate.isTrue(orderBy != OrderBy.CUSTOM, "You must provide a custom comparator if orderBy == OrderBy.CUSTOM");
|
||||
config.propertyOrderBy = orderBy;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies a custom comparator function to order properties.
|
||||
*
|
||||
* @param propertyOrdering property ordering
|
||||
* @return this builder
|
||||
*/
|
||||
public Swagger2MarkupConfigBuilder withPropertyOrdering(Comparator<String> propertyOrdering) {
|
||||
Validate.notNull(propertyOrdering, "%s must not be null", "propertyOrdering");
|
||||
|
||||
config.propertyOrderBy = OrderBy.CUSTOM;
|
||||
config.propertyOrdering = propertyOrdering;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies response ordering.<br>
|
||||
* By default response ordering == {@link io.github.swagger2markup.OrderBy#NATURAL}.<br>
|
||||
* Use {@link #withResponseOrdering(Comparator)} to set a custom ordering.
|
||||
*
|
||||
* @param orderBy response ordering
|
||||
* @return this builder
|
||||
*/
|
||||
public Swagger2MarkupConfigBuilder withResponseOrdering(OrderBy orderBy) {
|
||||
Validate.notNull(orderBy, "%s must not be null", "orderBy");
|
||||
Validate.isTrue(orderBy != OrderBy.CUSTOM, "You must provide a custom comparator if orderBy == OrderBy.CUSTOM");
|
||||
config.responseOrderBy = orderBy;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies a custom comparator function to order responses.
|
||||
*
|
||||
* @param responseOrdering response ordering
|
||||
* @return this builder
|
||||
*/
|
||||
public Swagger2MarkupConfigBuilder withResponseOrdering(Comparator<String> responseOrdering) {
|
||||
Validate.notNull(responseOrdering, "%s must not be null", "responseOrdering");
|
||||
|
||||
config.responseOrderBy = OrderBy.CUSTOM;
|
||||
config.responseOrdering = responseOrdering;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable use of inter-document cross-references when needed.
|
||||
*
|
||||
* @param prefix Prefix to document in all inter-document cross-references.
|
||||
* @return this builder
|
||||
*/
|
||||
public Swagger2MarkupConfigBuilder withInterDocumentCrossReferences(String prefix) {
|
||||
Validate.notNull(prefix, "%s must not be null", "prefix");
|
||||
config.interDocumentCrossReferencesEnabled = true;
|
||||
config.interDocumentCrossReferencesPrefix = prefix;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable use of inter-document cross-references when needed.
|
||||
*
|
||||
* @return this builder
|
||||
*/
|
||||
public Swagger2MarkupConfigBuilder withInterDocumentCrossReferences() {
|
||||
config.interDocumentCrossReferencesEnabled = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Optionally isolate the body parameter, if any, from other parameters.
|
||||
*
|
||||
* @return this builder
|
||||
*/
|
||||
public Swagger2MarkupConfigBuilder withFlatBody() {
|
||||
config.flatBodyEnabled = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Optionally prefix all anchors for uniqueness.
|
||||
*
|
||||
* @param anchorPrefix anchor prefix.
|
||||
* @return this builder
|
||||
*/
|
||||
public Swagger2MarkupConfigBuilder withAnchorPrefix(String anchorPrefix) {
|
||||
Validate.notNull(anchorPrefix, "%s must no be null", "anchorPrefix");
|
||||
config.anchorPrefix = anchorPrefix;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies the line separator which should be used.
|
||||
*
|
||||
* @param lineSeparator the lineSeparator
|
||||
* @return this builder
|
||||
*/
|
||||
public Swagger2MarkupConfigBuilder withLineSeparator(LineSeparator lineSeparator) {
|
||||
Validate.notNull(lineSeparator, "%s must no be null", "lineSeparator");
|
||||
config.lineSeparator = lineSeparator;
|
||||
return this;
|
||||
}
|
||||
|
||||
static class DefaultSwagger2MarkupConfig implements Swagger2MarkupConfig{
|
||||
|
||||
private MarkupLanguage markupLanguage;
|
||||
private MarkupLanguage swaggerMarkupLanguage;
|
||||
private boolean generatedExamplesEnabled;
|
||||
private boolean separatedDefinitionsEnabled;
|
||||
private boolean separatedOperationsEnabled;
|
||||
private GroupBy pathsGroupedBy;
|
||||
private Language outputLanguage;
|
||||
private boolean inlineSchemaEnabled;
|
||||
private OrderBy tagOrderBy;
|
||||
private Comparator<String> tagOrdering;
|
||||
private OrderBy operationOrderBy;
|
||||
private Comparator<PathOperation> operationOrdering;
|
||||
private OrderBy definitionOrderBy;
|
||||
private Comparator<String> definitionOrdering;
|
||||
private OrderBy parameterOrderBy;
|
||||
private Comparator<Parameter> parameterOrdering;
|
||||
private OrderBy propertyOrderBy;
|
||||
private Comparator<String> propertyOrdering;
|
||||
private OrderBy responseOrderBy;
|
||||
private Comparator<String> responseOrdering;
|
||||
private boolean interDocumentCrossReferencesEnabled;
|
||||
private String interDocumentCrossReferencesPrefix;
|
||||
private boolean flatBodyEnabled;
|
||||
private String anchorPrefix;
|
||||
private LineSeparator lineSeparator;
|
||||
|
||||
private String overviewDocument;
|
||||
private String pathsDocument;
|
||||
private String definitionsDocument;
|
||||
private String securityDocument;
|
||||
private String separatedOperationsFolder;
|
||||
private String separatedDefinitionsFolder;
|
||||
|
||||
private Swagger2MarkupProperties extensionsProperties;
|
||||
|
||||
@Override
|
||||
public MarkupLanguage getMarkupLanguage() {
|
||||
return markupLanguage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupLanguage getSwaggerMarkupLanguage() {
|
||||
return swaggerMarkupLanguage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGeneratedExamplesEnabled() {
|
||||
return generatedExamplesEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSeparatedDefinitionsEnabled() {
|
||||
return separatedDefinitionsEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSeparatedOperationsEnabled() {
|
||||
return separatedOperationsEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GroupBy getPathsGroupedBy() {
|
||||
return pathsGroupedBy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Language getOutputLanguage() {
|
||||
return outputLanguage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInlineSchemaEnabled() {
|
||||
return inlineSchemaEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderBy getTagOrderBy() {
|
||||
return tagOrderBy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Comparator<String> getTagOrdering() {
|
||||
return tagOrdering;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderBy getOperationOrderBy() {
|
||||
return operationOrderBy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Comparator<PathOperation> getOperationOrdering() {
|
||||
return operationOrdering;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderBy getDefinitionOrderBy() {
|
||||
return definitionOrderBy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Comparator<String> getDefinitionOrdering() {
|
||||
return definitionOrdering;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderBy getParameterOrderBy() {
|
||||
return parameterOrderBy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Comparator<Parameter> getParameterOrdering() {
|
||||
return parameterOrdering;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderBy getPropertyOrderBy() {
|
||||
return propertyOrderBy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Comparator<String> getPropertyOrdering() {
|
||||
return propertyOrdering;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderBy getResponseOrderBy() {
|
||||
return responseOrderBy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Comparator<String> getResponseOrdering() {
|
||||
return responseOrdering;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInterDocumentCrossReferencesEnabled() {
|
||||
return interDocumentCrossReferencesEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInterDocumentCrossReferencesPrefix() {
|
||||
return interDocumentCrossReferencesPrefix;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFlatBodyEnabled() {
|
||||
return flatBodyEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAnchorPrefix() {
|
||||
return anchorPrefix;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOverviewDocument() {
|
||||
return overviewDocument;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPathsDocument() {
|
||||
return pathsDocument;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefinitionsDocument() {
|
||||
return definitionsDocument;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSecurityDocument() {
|
||||
return securityDocument;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSeparatedOperationsFolder() {
|
||||
return separatedOperationsFolder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSeparatedDefinitionsFolder() {
|
||||
return separatedDefinitionsFolder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LineSeparator getLineSeparator() {
|
||||
return lineSeparator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Swagger2MarkupProperties getExtensionsProperties() {
|
||||
return extensionsProperties;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 Robert Winkler
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package io.github.swagger2markup.builder;
|
||||
|
||||
import io.github.swagger2markup.Swagger2MarkupExtensionRegistry;
|
||||
import io.github.swagger2markup.spi.*;
|
||||
|
||||
import java.util.List;
|
||||
@@ -70,7 +71,7 @@ public class Swagger2MarkupExtensionRegistryBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
static class DefaultSwagger2MarkupExtensionRegistry implements Swagger2MarkupExtensionRegistry {
|
||||
static class DefaultSwagger2MarkupExtensionRegistry implements Swagger2MarkupExtensionRegistry{
|
||||
|
||||
private Context context;
|
||||
|
||||
@@ -79,44 +80,44 @@ public class Swagger2MarkupExtensionRegistryBuilder {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SwaggerModelExtension> getSwaggerModelExtensions() {
|
||||
public List<SwaggerModelExtension> getSwaggerModelExtensions(){
|
||||
return context.swaggerModelExtensions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OverviewDocumentExtension> getOverviewDocumentExtensions() {
|
||||
public List<OverviewDocumentExtension> getOverviewDocumentExtensions(){
|
||||
return context.overviewDocumentExtensions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DefinitionsDocumentExtension> getDefinitionsDocumentExtensions() {
|
||||
public List<DefinitionsDocumentExtension> getDefinitionsDocumentExtensions(){
|
||||
return context.definitionsDocumentExtensions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SecurityDocumentExtension> getSecurityDocumentExtensions() {
|
||||
public List<SecurityDocumentExtension> getSecurityDocumentExtensions(){
|
||||
return context.securityDocumentExtensions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PathsDocumentExtension> getPathsDocumentExtensions() {
|
||||
public List<PathsDocumentExtension> getPathsDocumentExtensions(){
|
||||
return context.pathsDocumentExtensions;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class Context {
|
||||
final List<SwaggerModelExtension> swaggerModelExtensions;
|
||||
final List<OverviewDocumentExtension> overviewDocumentExtensions;
|
||||
final List<DefinitionsDocumentExtension> definitionsDocumentExtensions;
|
||||
final List<PathsDocumentExtension> pathsDocumentExtensions;
|
||||
final List<SecurityDocumentExtension> securityDocumentExtensions;
|
||||
public final List<SwaggerModelExtension> swaggerModelExtensions;
|
||||
public final List<OverviewDocumentExtension> overviewDocumentExtensions;
|
||||
public final List<DefinitionsDocumentExtension> definitionsDocumentExtensions;
|
||||
public final List<PathsDocumentExtension> pathsDocumentExtensions;
|
||||
public final List<SecurityDocumentExtension> securityDocumentExtensions;
|
||||
|
||||
Context(List<SwaggerModelExtension> swaggerModelExtensions,
|
||||
List<OverviewDocumentExtension> overviewDocumentExtensions,
|
||||
List<DefinitionsDocumentExtension> definitionsDocumentExtensions,
|
||||
List<PathsDocumentExtension> pathsDocumentExtensions,
|
||||
List<SecurityDocumentExtension> securityDocumentExtensions) {
|
||||
public Context(List<SwaggerModelExtension> swaggerModelExtensions,
|
||||
List<OverviewDocumentExtension> overviewDocumentExtensions,
|
||||
List<DefinitionsDocumentExtension> definitionsDocumentExtensions,
|
||||
List<PathsDocumentExtension> pathsDocumentExtensions,
|
||||
List<SecurityDocumentExtension> securityDocumentExtensions){
|
||||
this.swaggerModelExtensions = swaggerModelExtensions;
|
||||
this.overviewDocumentExtensions = overviewDocumentExtensions;
|
||||
this.definitionsDocumentExtensions = definitionsDocumentExtensions;
|
||||
@@ -124,4 +125,4 @@ public class Swagger2MarkupExtensionRegistryBuilder {
|
||||
this.securityDocumentExtensions = securityDocumentExtensions;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 2016 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.document;
|
||||
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.OpenOption;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class MarkupDocument {
|
||||
|
||||
private MarkupDocBuilder markupDocBuilder;
|
||||
|
||||
public MarkupDocument(MarkupDocBuilder markupDocBuilder) {
|
||||
this.markupDocBuilder = markupDocBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of the document.
|
||||
*/
|
||||
public String toString() {
|
||||
return markupDocBuilder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the content of the builder to a file.<br>
|
||||
* An extension identifying the markup language will be automatically added to file name.
|
||||
*
|
||||
* @param file the generated file
|
||||
* @param charset the the charset to use for encoding
|
||||
* @param options the file open options
|
||||
*/
|
||||
public void writeToFile(Path file, Charset charset, OpenOption... options) {
|
||||
markupDocBuilder.writeToFile(file, charset, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the content of the builder to a file.
|
||||
*
|
||||
* @param file the generated file
|
||||
* @param charset the the charset to use for encoding
|
||||
* @param options the file open options
|
||||
*/
|
||||
public void writeToFileWithoutExtension(Path file, Charset charset, OpenOption... options) {
|
||||
markupDocBuilder.writeToFileWithoutExtension(file, charset, options);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,336 @@
|
||||
/*
|
||||
* Copyright 2016 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.document.builder;
|
||||
|
||||
import io.github.swagger2markup.Swagger2MarkupConverter;
|
||||
import io.github.swagger2markup.Swagger2MarkupExtensionRegistry;
|
||||
import io.github.swagger2markup.internal.document.MarkupDocument;
|
||||
import io.github.swagger2markup.internal.type.ObjectType;
|
||||
import io.github.swagger2markup.internal.type.ObjectTypePolymorphism;
|
||||
import io.github.swagger2markup.internal.type.Type;
|
||||
import io.github.swagger2markup.internal.utils.ModelUtils;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import io.github.swagger2markup.spi.DefinitionsDocumentExtension;
|
||||
import io.swagger.models.Model;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
|
||||
import static io.github.swagger2markup.internal.utils.MapUtils.toKeySet;
|
||||
import static io.github.swagger2markup.spi.DefinitionsDocumentExtension.Context;
|
||||
import static io.github.swagger2markup.spi.DefinitionsDocumentExtension.Position;
|
||||
import static io.github.swagger2markup.utils.IOUtils.normalizeName;
|
||||
import static org.apache.commons.lang3.StringUtils.defaultString;
|
||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public class DefinitionsDocumentBuilder extends MarkupDocumentBuilder {
|
||||
|
||||
/* Discriminator is only displayed for inheriting definitions */
|
||||
private static final boolean ALWAYS_DISPLAY_DISCRIMINATOR = false;
|
||||
|
||||
private static final String DEFINITIONS_ANCHOR = "definitions";
|
||||
private final String DEFINITIONS;
|
||||
private final String DISCRIMINATOR_COLUMN;
|
||||
private final String POLYMORPHISM_COLUMN;
|
||||
private final Map<ObjectTypePolymorphism.Nature, String> POLYMORPHISM_NATURE;
|
||||
private final String TYPE_COLUMN;
|
||||
private static final List<String> IGNORED_DEFINITIONS = Collections.singletonList("Void");
|
||||
|
||||
public DefinitionsDocumentBuilder(Swagger2MarkupConverter.Context context, Swagger2MarkupExtensionRegistry extensionRegistry, Path outputPath) {
|
||||
super(context, extensionRegistry, outputPath);
|
||||
|
||||
ResourceBundle labels = ResourceBundle.getBundle("io/github/swagger2markup/lang/labels", config.getOutputLanguage().toLocale());
|
||||
DEFINITIONS = labels.getString("definitions");
|
||||
POLYMORPHISM_COLUMN = labels.getString("polymorphism.column");
|
||||
DISCRIMINATOR_COLUMN = labels.getString("polymorphism.discriminator");
|
||||
POLYMORPHISM_NATURE = new HashMap<ObjectTypePolymorphism.Nature, String>() {{
|
||||
put(ObjectTypePolymorphism.Nature.COMPOSITION, labels.getString("polymorphism.nature.COMPOSITION"));
|
||||
put(ObjectTypePolymorphism.Nature.INHERITANCE, labels.getString("polymorphism.nature.INHERITANCE"));
|
||||
}};
|
||||
TYPE_COLUMN = labels.getString("type_column");
|
||||
|
||||
if (config.isSeparatedDefinitionsEnabled()) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Create separated definition files is enabled.");
|
||||
}
|
||||
Validate.notNull(outputPath, "Output directory is required for separated definition files!");
|
||||
} else {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Create separated definition files is disabled.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the definitions MarkupDocument.
|
||||
*
|
||||
* @return the definitions MarkupDocument
|
||||
*/
|
||||
@Override
|
||||
public MarkupDocument build() {
|
||||
if (MapUtils.isNotEmpty(globalContext.getSwagger().getDefinitions())) {
|
||||
applyDefinitionsDocumentExtension(new Context(Position.DOCUMENT_BEFORE, this.markupDocBuilder));
|
||||
buildDefinitionsTitle(DEFINITIONS);
|
||||
applyDefinitionsDocumentExtension(new Context(Position.DOCUMENT_BEGIN, this.markupDocBuilder));
|
||||
buildDefinitionsSection();
|
||||
applyDefinitionsDocumentExtension(new Context(Position.DOCUMENT_END, this.markupDocBuilder));
|
||||
applyDefinitionsDocumentExtension(new Context(Position.DOCUMENT_AFTER, this.markupDocBuilder));
|
||||
}
|
||||
return new MarkupDocument(markupDocBuilder);
|
||||
}
|
||||
|
||||
private void buildDefinitionsSection() {
|
||||
Set<String> definitionNames = toKeySet(globalContext.getSwagger().getDefinitions(), config.getDefinitionOrdering());
|
||||
for (String definitionName : definitionNames) {
|
||||
Model model = globalContext.getSwagger().getDefinitions().get(definitionName);
|
||||
if (isNotBlank(definitionName)) {
|
||||
if (checkThatDefinitionIsNotInIgnoreList(definitionName)) {
|
||||
buildDefinition(definitionName, model);
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Definition processed : '{}'", definitionName);
|
||||
}
|
||||
} else {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Definition was ignored : '{}'", definitionName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void buildDefinitionsTitle(String title) {
|
||||
this.markupDocBuilder.sectionTitleWithAnchorLevel1(title, DEFINITIONS_ANCHOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply extension context to all DefinitionsContentExtension
|
||||
*
|
||||
* @param context context
|
||||
*/
|
||||
private void applyDefinitionsDocumentExtension(Context context) {
|
||||
for (DefinitionsDocumentExtension extension : extensionRegistry.getDefinitionsDocumentExtensions()) {
|
||||
extension.apply(context);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the definition filename depending on the generation mode
|
||||
*
|
||||
* @param definitionName definition name
|
||||
* @return definition filename
|
||||
*/
|
||||
private String resolveDefinitionDocument(String definitionName) {
|
||||
if (config.isSeparatedDefinitionsEnabled())
|
||||
return new File(config.getSeparatedDefinitionsFolder(), markupDocBuilder.addFileExtension(normalizeName(definitionName))).getPath();
|
||||
else
|
||||
return markupDocBuilder.addFileExtension(config.getDefinitionsDocument());
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate definition files depending on the generation mode
|
||||
*
|
||||
* @param definitionName definition name to process
|
||||
* @param model definition model to process
|
||||
*/
|
||||
private void buildDefinition(String definitionName, Model model) {
|
||||
|
||||
if (config.isSeparatedDefinitionsEnabled()) {
|
||||
MarkupDocBuilder defDocBuilder = copyMarkupDocBuilder();
|
||||
buildDefinition(definitionName, model, defDocBuilder);
|
||||
Path definitionFile = outputPath.resolve(resolveDefinitionDocument(definitionName));
|
||||
defDocBuilder.writeToFileWithoutExtension(definitionFile, StandardCharsets.UTF_8);
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Separate definition file produced : '{}'", definitionFile);
|
||||
}
|
||||
|
||||
definitionRef(definitionName, this.markupDocBuilder);
|
||||
|
||||
} else {
|
||||
buildDefinition(definitionName, model, this.markupDocBuilder);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 buildDefinition(String definitionName, Model model, MarkupDocBuilder docBuilder) {
|
||||
applyDefinitionsDocumentExtension(new Context(Position.DEFINITION_BEFORE, docBuilder, definitionName, model));
|
||||
buildDefinitionTitle(definitionName, definitionName, docBuilder);
|
||||
applyDefinitionsDocumentExtension(new Context(Position.DEFINITION_BEGIN, docBuilder, definitionName, model));
|
||||
buildDescriptionParagraph(model, docBuilder);
|
||||
inlineDefinitions(typeSection(definitionName, model, docBuilder), definitionName, docBuilder);
|
||||
applyDefinitionsDocumentExtension(new Context(Position.DEFINITION_END, docBuilder, definitionName, model));
|
||||
applyDefinitionsDocumentExtension(new Context(Position.DEFINITION_AFTER, docBuilder, definitionName, model));
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a cross-reference to a separated definition file.
|
||||
*
|
||||
* @param definitionName definition name to target
|
||||
* @param docBuilder the docbuilder do use for output
|
||||
*/
|
||||
private void definitionRef(String definitionName, MarkupDocBuilder docBuilder) {
|
||||
buildDefinitionTitle(copyMarkupDocBuilder().crossReference(new DefinitionDocumentResolverDefault().apply(definitionName), definitionName, definitionName).toString(), "ref-" + definitionName, docBuilder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds definition title
|
||||
*
|
||||
* @param title definition title
|
||||
* @param anchor optional anchor (null => auto-generate from title)
|
||||
* @param docBuilder the docbuilder do use for output
|
||||
*/
|
||||
private void buildDefinitionTitle(String title, String anchor, MarkupDocBuilder docBuilder) {
|
||||
docBuilder.sectionTitleWithAnchorLevel2(title, anchor);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Builds the type informations of a definition
|
||||
*
|
||||
* @param definitionName name of the definition to display
|
||||
* @param model model of the definition to display
|
||||
* @param docBuilder the docbuilder do use for output
|
||||
* @return a list of inlined types.
|
||||
*/
|
||||
private List<ObjectType> typeSection(String definitionName, Model model, MarkupDocBuilder docBuilder) {
|
||||
List<ObjectType> inlineDefinitions = new ArrayList<>();
|
||||
Type modelType = ModelUtils.resolveRefType(ModelUtils.getType(model, globalContext.getSwagger().getDefinitions(), new DefinitionDocumentResolverFromDefinition()));
|
||||
|
||||
if (!(modelType instanceof ObjectType)) {
|
||||
modelType = createInlineType(modelType, definitionName, definitionName + " " + "inline", inlineDefinitions);
|
||||
}
|
||||
|
||||
if (modelType instanceof ObjectType) {
|
||||
ObjectType objectType = (ObjectType) modelType;
|
||||
MarkupDocBuilder typeInfos = copyMarkupDocBuilder();
|
||||
switch (objectType.getPolymorphism().getNature()) {
|
||||
case COMPOSITION:
|
||||
typeInfos.italicText(POLYMORPHISM_COLUMN).textLine(COLON + POLYMORPHISM_NATURE.get(objectType.getPolymorphism().getNature()));
|
||||
break;
|
||||
case INHERITANCE:
|
||||
typeInfos.italicText(POLYMORPHISM_COLUMN).textLine(COLON + POLYMORPHISM_NATURE.get(objectType.getPolymorphism().getNature()));
|
||||
typeInfos.italicText(DISCRIMINATOR_COLUMN).textLine(COLON + objectType.getPolymorphism().getDiscriminator());
|
||||
break;
|
||||
case NONE:
|
||||
if (ALWAYS_DISPLAY_DISCRIMINATOR) {
|
||||
if (StringUtils.isNotBlank(objectType.getPolymorphism().getDiscriminator()))
|
||||
typeInfos.italicText(DISCRIMINATOR_COLUMN).textLine(COLON + objectType.getPolymorphism().getDiscriminator());
|
||||
}
|
||||
|
||||
default: break;
|
||||
}
|
||||
|
||||
String typeInfosString = typeInfos.toString();
|
||||
if (StringUtils.isNotBlank(typeInfosString))
|
||||
docBuilder.paragraph(typeInfosString, true);
|
||||
|
||||
inlineDefinitions.addAll(buildPropertiesTable(((ObjectType) modelType).getProperties(), definitionName, new DefinitionDocumentResolverFromDefinition(), docBuilder));
|
||||
} else if (modelType != null) {
|
||||
MarkupDocBuilder typeInfos = copyMarkupDocBuilder();
|
||||
typeInfos.italicText(TYPE_COLUMN).textLine(COLON + modelType.displaySchema(docBuilder));
|
||||
|
||||
docBuilder.paragraph(typeInfos.toString());
|
||||
}
|
||||
|
||||
return inlineDefinitions;
|
||||
}
|
||||
|
||||
private void buildDescriptionParagraph(Model model, MarkupDocBuilder docBuilder) {
|
||||
modelDescription(model, docBuilder);
|
||||
}
|
||||
|
||||
private void modelDescription(Model model, MarkupDocBuilder docBuilder) {
|
||||
String description = model.getDescription();
|
||||
if (isNotBlank(description)) {
|
||||
buildDescriptionParagraph(description, docBuilder);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the title of an inline schema.
|
||||
* Inline definitions should never been referenced in TOC because they have no real existence, so they are just text.
|
||||
*
|
||||
* @param title inline schema title
|
||||
* @param anchor inline schema anchor
|
||||
* @param docBuilder the docbuilder do use for output
|
||||
*/
|
||||
private void addInlineDefinitionTitle(String title, String anchor, MarkupDocBuilder docBuilder) {
|
||||
docBuilder.anchor(anchor, null);
|
||||
docBuilder.newLine();
|
||||
docBuilder.boldTextLine(title);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds inline schema definitions
|
||||
*
|
||||
* @param definitions all inline definitions to display
|
||||
* @param uniquePrefix unique prefix to prepend to inline object names to enforce unicity
|
||||
* @param docBuilder the docbuilder do use for output
|
||||
*/
|
||||
private void inlineDefinitions(List<ObjectType> definitions, String uniquePrefix, MarkupDocBuilder docBuilder) {
|
||||
if (CollectionUtils.isNotEmpty(definitions)) {
|
||||
for (ObjectType definition : definitions) {
|
||||
addInlineDefinitionTitle(definition.getName(), definition.getUniqueName(), docBuilder);
|
||||
List<ObjectType> localDefinitions = buildPropertiesTable(definition.getProperties(), uniquePrefix, new DefinitionDocumentResolverFromDefinition(), docBuilder);
|
||||
for (ObjectType localDefinition : localDefinitions)
|
||||
inlineDefinitions(Collections.singletonList(localDefinition), localDefinition.getUniqueName(), docBuilder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides definition document resolver functor for inter-document cross-references from definitions files.
|
||||
* This implementation simplify the path between two definitions because all definitions are in the same path.
|
||||
*/
|
||||
class DefinitionDocumentResolverFromDefinition extends DefinitionDocumentResolverDefault {
|
||||
|
||||
public DefinitionDocumentResolverFromDefinition() {
|
||||
}
|
||||
|
||||
public String apply(String definitionName) {
|
||||
String defaultResolver = super.apply(definitionName);
|
||||
|
||||
if (defaultResolver != null && config.isSeparatedDefinitionsEnabled())
|
||||
return defaultString(config.getInterDocumentCrossReferencesPrefix()) + markupDocBuilder.addFileExtension(normalizeName(definitionName));
|
||||
else
|
||||
return defaultResolver;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,282 @@
|
||||
/*
|
||||
* Copyright 2016 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.document.builder;
|
||||
|
||||
import io.github.swagger2markup.Swagger2MarkupConfig;
|
||||
import io.github.swagger2markup.Swagger2MarkupConverter;
|
||||
import io.github.swagger2markup.Swagger2MarkupExtensionRegistry;
|
||||
import io.github.swagger2markup.internal.document.MarkupDocument;
|
||||
import io.github.swagger2markup.internal.type.*;
|
||||
import io.github.swagger2markup.internal.utils.PropertyUtils;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilders;
|
||||
import io.github.swagger2markup.markup.builder.MarkupLanguage;
|
||||
import io.github.swagger2markup.markup.builder.MarkupTableColumn;
|
||||
import io.github.swagger2markup.utils.IOUtils;
|
||||
import io.swagger.models.properties.Property;
|
||||
import io.swagger.util.Json;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
|
||||
import static io.github.swagger2markup.internal.utils.MapUtils.toKeySet;
|
||||
import static org.apache.commons.lang3.StringUtils.defaultString;
|
||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public abstract class MarkupDocumentBuilder {
|
||||
|
||||
protected static final String COLON = " : ";
|
||||
|
||||
protected final String DEFAULT_COLUMN;
|
||||
protected final String EXAMPLE_COLUMN;
|
||||
protected final String SCHEMA_COLUMN;
|
||||
protected final String NAME_COLUMN;
|
||||
protected final String DESCRIPTION_COLUMN;
|
||||
protected final String SCOPES_COLUMN;
|
||||
protected final String DESCRIPTION;
|
||||
protected final String PRODUCES;
|
||||
protected final String CONSUMES;
|
||||
protected final String TAGS;
|
||||
protected final String NO_CONTENT;
|
||||
protected final String FLAGS_COLUMN;
|
||||
protected final String FLAGS_REQUIRED;
|
||||
protected final String FLAGS_OPTIONAL;
|
||||
protected final String FLAGS_READ_ONLY;
|
||||
|
||||
|
||||
protected Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
protected Swagger2MarkupConverter.Context globalContext;
|
||||
protected Swagger2MarkupExtensionRegistry extensionRegistry;
|
||||
protected Swagger2MarkupConfig config;
|
||||
protected MarkupDocBuilder markupDocBuilder;
|
||||
protected Path outputPath;
|
||||
|
||||
MarkupDocumentBuilder(Swagger2MarkupConverter.Context globalContext, Swagger2MarkupExtensionRegistry extensionRegistry, Path outputPath) {
|
||||
this.globalContext = globalContext;
|
||||
this.extensionRegistry = extensionRegistry;
|
||||
this.config = globalContext.getConfig();
|
||||
this.outputPath = outputPath;
|
||||
|
||||
this.markupDocBuilder = MarkupDocBuilders.documentBuilder(config.getMarkupLanguage(), config.getLineSeparator()).withAnchorPrefix(config.getAnchorPrefix());
|
||||
|
||||
ResourceBundle labels = ResourceBundle.getBundle("io/github/swagger2markup/lang/labels", config.getOutputLanguage().toLocale());
|
||||
DEFAULT_COLUMN = labels.getString("default_column");
|
||||
EXAMPLE_COLUMN = labels.getString("example_column");
|
||||
FLAGS_COLUMN = labels.getString("flags.column");
|
||||
FLAGS_REQUIRED = labels.getString("flags.required");
|
||||
FLAGS_OPTIONAL = labels.getString("flags.optional");
|
||||
FLAGS_READ_ONLY = labels.getString("flags.read_only");
|
||||
SCHEMA_COLUMN = labels.getString("schema_column");
|
||||
NAME_COLUMN = labels.getString("name_column");
|
||||
DESCRIPTION_COLUMN = labels.getString("description_column");
|
||||
SCOPES_COLUMN = labels.getString("scopes_column");
|
||||
DESCRIPTION = DESCRIPTION_COLUMN;
|
||||
PRODUCES = labels.getString("produces");
|
||||
CONSUMES = labels.getString("consumes");
|
||||
TAGS = labels.getString("tags");
|
||||
NO_CONTENT = labels.getString("no_content");
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 RefType to a new inlined type named with {@code name} and {@code uniqueName}.<br>
|
||||
* The returned RefType point to the new inlined type which is added to the {@code inlineDefinitions} collection.<br>
|
||||
* The function is recursive and support collections (ArrayType and MapType).<br>
|
||||
* The function is transparent : {@code type} is returned as-is if type is not inlinable or if !config.isInlineSchemaEnabled().<br>
|
||||
*
|
||||
* @param type type to inline
|
||||
* @param name name of the created inline ObjectType
|
||||
* @param uniqueName unique name of the created inline ObjectType
|
||||
* @param inlineDefinitions a non null collection of inline ObjectType
|
||||
* @return the type referencing the newly created inline ObjectType. Can be a RefType, an ArrayType or a MapType
|
||||
*/
|
||||
protected Type createInlineType(Type type, String name, String uniqueName, List<ObjectType> inlineDefinitions) {
|
||||
if (!config.isInlineSchemaEnabled())
|
||||
return type;
|
||||
|
||||
if (type instanceof ObjectType) {
|
||||
return createInlineObjectType(type, name, uniqueName, inlineDefinitions);
|
||||
} else if (type instanceof ArrayType) {
|
||||
ArrayType arrayType = (ArrayType)type;
|
||||
arrayType.setOfType(createInlineType(arrayType.getOfType(), name, uniqueName, inlineDefinitions));
|
||||
|
||||
return arrayType;
|
||||
} else if (type instanceof MapType) {
|
||||
MapType mapType = (MapType)type;
|
||||
if (mapType.getValueType() instanceof ObjectType)
|
||||
mapType.setValueType(createInlineType(mapType.getValueType(), name, uniqueName, inlineDefinitions));
|
||||
|
||||
return mapType;
|
||||
} else {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
||||
protected Type createInlineObjectType(Type type, String name, String uniqueName, List<ObjectType> inlineDefinitions) {
|
||||
if (type instanceof ObjectType) {
|
||||
ObjectType objectType = (ObjectType)type;
|
||||
if (MapUtils.isNotEmpty(objectType.getProperties())) {
|
||||
if (objectType.getName() == null) {
|
||||
objectType.setName(name);
|
||||
objectType.setUniqueName(uniqueName);
|
||||
}
|
||||
inlineDefinitions.add(objectType);
|
||||
return new RefType(objectType);
|
||||
} else
|
||||
return type;
|
||||
} else
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a generic property table
|
||||
*
|
||||
* @param properties properties to display
|
||||
* @param uniquePrefix unique prefix to prepend to inline object names to enforce unicity
|
||||
* @param definitionDocumentResolver definition document resolver to apply to property type cross-reference
|
||||
* @param docBuilder the docbuilder do use for output
|
||||
* @return a list of inline schemas referenced by some properties, for later display
|
||||
*/
|
||||
protected List<ObjectType> buildPropertiesTable(Map<String, Property> properties, String uniquePrefix, DefinitionDocumentResolver definitionDocumentResolver, MarkupDocBuilder docBuilder) {
|
||||
List<ObjectType> inlineDefinitions = new ArrayList<>();
|
||||
List<List<String>> cells = new ArrayList<>();
|
||||
List<MarkupTableColumn> cols = Arrays.asList(
|
||||
new MarkupTableColumn(NAME_COLUMN).withWidthRatio(3).withHeaderColumn(false).withMarkupSpecifiers(MarkupLanguage.ASCIIDOC, ".^3"),
|
||||
new MarkupTableColumn(DESCRIPTION_COLUMN).withWidthRatio(11).withMarkupSpecifiers(MarkupLanguage.ASCIIDOC, ".^11"),
|
||||
new MarkupTableColumn(SCHEMA_COLUMN).withWidthRatio(4).withMarkupSpecifiers(MarkupLanguage.ASCIIDOC, ".^4"));
|
||||
if (MapUtils.isNotEmpty(properties)) {
|
||||
Set<String> propertyNames = toKeySet(properties, config.getPropertyOrdering());
|
||||
for (String propertyName : propertyNames) {
|
||||
Property property = properties.get(propertyName);
|
||||
Type propertyType = PropertyUtils.getType(property, definitionDocumentResolver);
|
||||
|
||||
propertyType = createInlineType(propertyType, propertyName, uniquePrefix + " " + propertyName, inlineDefinitions);
|
||||
|
||||
Object example = PropertyUtils.getExample(config.isGeneratedExamplesEnabled(), property, markupDocBuilder);
|
||||
|
||||
Object defaultValue = PropertyUtils.getDefaultValue(property);
|
||||
|
||||
MarkupDocBuilder propertyNameContent = copyMarkupDocBuilder();
|
||||
propertyNameContent.boldTextLine(propertyName, true);
|
||||
if (BooleanUtils.isTrue(property.getRequired()))
|
||||
propertyNameContent.italicText(FLAGS_REQUIRED.toLowerCase());
|
||||
else
|
||||
propertyNameContent.italicText(FLAGS_OPTIONAL.toLowerCase());
|
||||
if (BooleanUtils.isTrue(property.getReadOnly())) {
|
||||
propertyNameContent.newLine(true);
|
||||
propertyNameContent.italicText(FLAGS_READ_ONLY.toLowerCase());
|
||||
}
|
||||
|
||||
MarkupDocBuilder descriptionContent = copyMarkupDocBuilder();
|
||||
String description = defaultString(swaggerMarkupDescription(property.getDescription()));
|
||||
if (isNotBlank(description))
|
||||
descriptionContent.text(description);
|
||||
if(defaultValue != null){
|
||||
if (isNotBlank(description))
|
||||
descriptionContent.newLine(true);
|
||||
descriptionContent.boldText(DEFAULT_COLUMN).text(COLON).literalText(Json.pretty(defaultValue));
|
||||
}
|
||||
if (example != null) {
|
||||
if (isNotBlank(description) || defaultValue != null)
|
||||
descriptionContent.newLine(true);
|
||||
descriptionContent.boldText(EXAMPLE_COLUMN).text(COLON).literalText(Json.pretty(example));
|
||||
}
|
||||
|
||||
List<String> content = Arrays.asList(
|
||||
propertyNameContent.toString(),
|
||||
descriptionContent.toString(),
|
||||
propertyType.displaySchema(docBuilder)
|
||||
);
|
||||
cells.add(content);
|
||||
}
|
||||
docBuilder.tableWithColumnSpecs(cols, cells);
|
||||
} else {
|
||||
docBuilder.textLine(NO_CONTENT);
|
||||
}
|
||||
|
||||
return inlineDefinitions;
|
||||
}
|
||||
|
||||
protected MarkupDocBuilder copyMarkupDocBuilder() {
|
||||
return markupDocBuilder.copy(false);
|
||||
}
|
||||
|
||||
protected String boldText(String text) {
|
||||
return copyMarkupDocBuilder().boldText(text).toString();
|
||||
}
|
||||
|
||||
protected String italicText(String text) {
|
||||
return copyMarkupDocBuilder().italicText(text).toString();
|
||||
}
|
||||
|
||||
protected String literalText(String text) {
|
||||
return copyMarkupDocBuilder().literalText(text).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns converted markup text from Swagger.
|
||||
*
|
||||
* @param markupText text to convert, or null
|
||||
* @return converted markup text, or null if {@code markupText} == null
|
||||
*/
|
||||
protected String swaggerMarkupDescription(String markupText) {
|
||||
if (markupText == null)
|
||||
return null;
|
||||
return copyMarkupDocBuilder().importMarkup(new StringReader(markupText), globalContext.getConfig().getSwaggerMarkupLanguage()).toString().trim();
|
||||
}
|
||||
|
||||
protected void buildDescriptionParagraph(String description, MarkupDocBuilder docBuilder) {
|
||||
if (isNotBlank(description)) {
|
||||
docBuilder.paragraph(swaggerMarkupDescription(description));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Default {@code DefinitionDocumentResolver} functor
|
||||
*/
|
||||
class DefinitionDocumentResolverDefault implements DefinitionDocumentResolver {
|
||||
|
||||
public DefinitionDocumentResolverDefault() {
|
||||
}
|
||||
|
||||
public String apply(String definitionName) {
|
||||
if (!config.isInterDocumentCrossReferencesEnabled() || outputPath == null)
|
||||
return null;
|
||||
else if (config.isSeparatedDefinitionsEnabled())
|
||||
return defaultString(config.getInterDocumentCrossReferencesPrefix()) + new File(config.getSeparatedDefinitionsFolder(), markupDocBuilder.addFileExtension(IOUtils.normalizeName(definitionName))).getPath();
|
||||
else
|
||||
return defaultString(config.getInterDocumentCrossReferencesPrefix()) + markupDocBuilder.addFileExtension(config.getDefinitionsDocument());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,224 @@
|
||||
/*
|
||||
* Copyright 2016 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.document.builder;
|
||||
|
||||
import io.github.swagger2markup.Swagger2MarkupConverter;
|
||||
import io.github.swagger2markup.Swagger2MarkupExtensionRegistry;
|
||||
import io.github.swagger2markup.internal.document.MarkupDocument;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import io.github.swagger2markup.spi.OverviewDocumentExtension;
|
||||
import io.swagger.models.*;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import static io.github.swagger2markup.spi.OverviewDocumentExtension.Context;
|
||||
import static io.github.swagger2markup.spi.OverviewDocumentExtension.Position;
|
||||
import static org.apache.commons.collections4.CollectionUtils.isNotEmpty;
|
||||
import static org.apache.commons.lang3.StringUtils.*;
|
||||
|
||||
public class OverviewDocumentBuilder extends MarkupDocumentBuilder {
|
||||
|
||||
private static final String OVERVIEW_ANCHOR = "overview";
|
||||
private final String OVERVIEW;
|
||||
private final String CURRENT_VERSION;
|
||||
private final String VERSION;
|
||||
private final String CONTACT_INFORMATION;
|
||||
private final String CONTACT_NAME;
|
||||
private final String CONTACT_EMAIL;
|
||||
private final String LICENSE_INFORMATION;
|
||||
private final String LICENSE;
|
||||
private final String LICENSE_URL;
|
||||
private final String TERMS_OF_SERVICE;
|
||||
private final String URI_SCHEME;
|
||||
private final String HOST;
|
||||
private final String BASE_PATH;
|
||||
private final String SCHEMES;
|
||||
|
||||
public OverviewDocumentBuilder(Swagger2MarkupConverter.Context context, Swagger2MarkupExtensionRegistry extensionRegistry, Path outputPath){
|
||||
super(context, extensionRegistry, outputPath);
|
||||
|
||||
ResourceBundle labels = ResourceBundle.getBundle("io/github/swagger2markup/lang/labels", config.getOutputLanguage().toLocale());
|
||||
OVERVIEW = labels.getString("overview");
|
||||
CURRENT_VERSION = labels.getString("current_version");
|
||||
VERSION = labels.getString("version");
|
||||
CONTACT_INFORMATION = labels.getString("contact_information");
|
||||
CONTACT_NAME = labels.getString("contact_name");
|
||||
CONTACT_EMAIL = labels.getString("contact_email");
|
||||
LICENSE_INFORMATION = labels.getString("license_information");
|
||||
LICENSE = labels.getString("license");
|
||||
LICENSE_URL = labels.getString("license_url");
|
||||
TERMS_OF_SERVICE = labels.getString("terms_of_service");
|
||||
URI_SCHEME = labels.getString("uri_scheme");
|
||||
HOST = labels.getString("host");
|
||||
BASE_PATH = labels.getString("base_path");
|
||||
SCHEMES = labels.getString("schemes");
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the overview MarkupDocument.
|
||||
*
|
||||
* @return the overview MarkupDocument
|
||||
*/
|
||||
@Override
|
||||
public MarkupDocument build(){
|
||||
Swagger swagger = globalContext.getSwagger();
|
||||
Info info = swagger.getInfo();
|
||||
buildDocumentTitle(info.getTitle());
|
||||
applyOverviewDocumentExtension(new Context(Position.DOCUMENT_BEFORE, this.markupDocBuilder));
|
||||
buildOverviewTitle(OVERVIEW);
|
||||
applyOverviewDocumentExtension(new Context(Position.DOCUMENT_BEGIN, this.markupDocBuilder));
|
||||
buildDescriptionParagraph(info.getDescription(), this.markupDocBuilder);
|
||||
buildVersionInfoSection(info.getVersion());
|
||||
buildContactInfoSection(info.getContact());
|
||||
buildLicenseInfoSection(info.getLicense(), info.getTermsOfService());
|
||||
buildUriSchemeSection(swagger);
|
||||
buildTagsSection(swagger.getTags());
|
||||
buildConsumesSection(swagger.getConsumes());
|
||||
buildProducesSection(swagger.getProduces());
|
||||
applyOverviewDocumentExtension(new Context(Position.DOCUMENT_END, this.markupDocBuilder));
|
||||
applyOverviewDocumentExtension(new Context(Position.DOCUMENT_AFTER, this.markupDocBuilder));
|
||||
return new MarkupDocument(markupDocBuilder);
|
||||
}
|
||||
|
||||
private void buildDocumentTitle(String title) {
|
||||
this.markupDocBuilder.documentTitle(title);
|
||||
}
|
||||
|
||||
private void buildOverviewTitle(String title) {
|
||||
this.markupDocBuilder.sectionTitleWithAnchorLevel1(title, OVERVIEW_ANCHOR);
|
||||
}
|
||||
|
||||
private void buildVersionInfoSection(String version) {
|
||||
if(isNotBlank(version)){
|
||||
this.markupDocBuilder.sectionTitleLevel2(CURRENT_VERSION);
|
||||
|
||||
MarkupDocBuilder paragraph = copyMarkupDocBuilder();
|
||||
paragraph.italicText(VERSION).textLine(COLON + version);
|
||||
this.markupDocBuilder.paragraph(paragraph.toString(), true);
|
||||
}
|
||||
}
|
||||
|
||||
private void buildContactInfoSection(Contact contact) {
|
||||
if(contact != null){
|
||||
this.markupDocBuilder.sectionTitleLevel2(CONTACT_INFORMATION);
|
||||
MarkupDocBuilder paragraph = copyMarkupDocBuilder();
|
||||
if(isNotBlank(contact.getName())){
|
||||
paragraph.italicText(CONTACT_NAME).textLine(COLON + contact.getName());
|
||||
}
|
||||
if(isNotBlank(contact.getEmail())){
|
||||
paragraph.italicText(CONTACT_EMAIL).textLine(COLON + contact.getEmail());
|
||||
}
|
||||
this.markupDocBuilder.paragraph(paragraph.toString(), true);
|
||||
}
|
||||
}
|
||||
|
||||
private void buildLicenseInfoSection(License license, String termOfService) {
|
||||
if (
|
||||
(license != null && (isNotBlank(license.getName()) || isNotBlank(license.getUrl()))) ||
|
||||
(isNotBlank(termOfService))
|
||||
) {
|
||||
this.markupDocBuilder.sectionTitleLevel2(LICENSE_INFORMATION);
|
||||
MarkupDocBuilder paragraph = copyMarkupDocBuilder();
|
||||
if (license != null && isNotBlank(license.getName())) {
|
||||
paragraph.italicText(LICENSE).textLine(COLON + license.getName());
|
||||
}
|
||||
if (license != null && isNotBlank(license.getUrl())) {
|
||||
paragraph.italicText(LICENSE_URL).textLine(COLON + license.getUrl());
|
||||
}
|
||||
if(isNotBlank(termOfService)){
|
||||
paragraph.italicText(TERMS_OF_SERVICE).textLine(COLON + termOfService);
|
||||
}
|
||||
|
||||
this.markupDocBuilder.paragraph(paragraph.toString(), true);
|
||||
}
|
||||
}
|
||||
|
||||
private void buildUriSchemeSection(Swagger swagger) {
|
||||
if(isNotBlank(swagger.getHost()) || isNotBlank(swagger.getBasePath()) || isNotEmpty(swagger.getSchemes())) {
|
||||
this.markupDocBuilder.sectionTitleLevel2(URI_SCHEME);
|
||||
MarkupDocBuilder paragraph = copyMarkupDocBuilder();
|
||||
if (isNotBlank(swagger.getHost())) {
|
||||
paragraph.italicText(HOST).textLine(COLON + swagger.getHost());
|
||||
}
|
||||
if (isNotBlank(swagger.getBasePath())) {
|
||||
paragraph.italicText(BASE_PATH).textLine(COLON + swagger.getBasePath());
|
||||
}
|
||||
if (isNotEmpty(swagger.getSchemes())) {
|
||||
List<String> schemes = new ArrayList<>();
|
||||
for (Scheme scheme : swagger.getSchemes()) {
|
||||
schemes.add(scheme.toString());
|
||||
}
|
||||
paragraph.italicText(SCHEMES).textLine(COLON + join(schemes, ", "));
|
||||
}
|
||||
this.markupDocBuilder.paragraph(paragraph.toString(), true);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void buildTagsSection(List<Tag> tags) {
|
||||
if(isNotEmpty(tags)){
|
||||
this.markupDocBuilder.sectionTitleLevel2(TAGS);
|
||||
List<String> tagsList = new ArrayList<>();
|
||||
for(Tag tag : tags){
|
||||
String name = tag.getName();
|
||||
String description = tag.getDescription();
|
||||
if(isNoneBlank(description)){
|
||||
tagsList.add(name + COLON + description);
|
||||
}else{
|
||||
tagsList.add(name);
|
||||
}
|
||||
}
|
||||
this.markupDocBuilder.unorderedList(tagsList);
|
||||
}
|
||||
}
|
||||
|
||||
private void buildConsumesSection(List<String> consumes) {
|
||||
if (isNotEmpty(consumes)) {
|
||||
this.markupDocBuilder.sectionTitleLevel2(CONSUMES);
|
||||
this.markupDocBuilder.newLine();
|
||||
for (String consume : consumes) {
|
||||
this.markupDocBuilder.unorderedListItem(literalText(consume));
|
||||
}
|
||||
this.markupDocBuilder.newLine();
|
||||
}
|
||||
}
|
||||
|
||||
private void buildProducesSection(List<String> produces) {
|
||||
if (isNotEmpty(produces)) {
|
||||
this.markupDocBuilder.sectionTitleLevel2(PRODUCES);
|
||||
this.markupDocBuilder.newLine();
|
||||
for (String produce : produces) {
|
||||
this.markupDocBuilder.unorderedListItem(literalText(produce));
|
||||
}
|
||||
this.markupDocBuilder.newLine();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply extension context to all OverviewContentExtension
|
||||
*
|
||||
* @param context context
|
||||
*/
|
||||
private void applyOverviewDocumentExtension(Context context) {
|
||||
for (OverviewDocumentExtension extension : extensionRegistry.getOverviewDocumentExtensions()) {
|
||||
extension.apply(context);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,770 @@
|
||||
/*
|
||||
* Copyright 2016 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.document.builder;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.collect.Multimap;
|
||||
import io.github.swagger2markup.GroupBy;
|
||||
import io.github.swagger2markup.Swagger2MarkupConverter;
|
||||
import io.github.swagger2markup.Swagger2MarkupExtensionRegistry;
|
||||
import io.github.swagger2markup.internal.document.MarkupDocument;
|
||||
import io.github.swagger2markup.internal.type.ObjectType;
|
||||
import io.github.swagger2markup.internal.type.Type;
|
||||
import io.github.swagger2markup.internal.utils.ExamplesUtil;
|
||||
import io.github.swagger2markup.internal.utils.ParameterUtils;
|
||||
import io.github.swagger2markup.internal.utils.PropertyUtils;
|
||||
import io.github.swagger2markup.internal.utils.TagUtils;
|
||||
import io.github.swagger2markup.markup.builder.*;
|
||||
import io.github.swagger2markup.model.PathOperation;
|
||||
import io.github.swagger2markup.spi.PathsDocumentExtension;
|
||||
import io.swagger.models.*;
|
||||
import io.swagger.models.auth.SecuritySchemeDefinition;
|
||||
import io.swagger.models.parameters.Parameter;
|
||||
import io.swagger.models.properties.Property;
|
||||
import io.swagger.util.Json;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.apache.commons.lang3.text.WordUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
|
||||
import static io.github.swagger2markup.internal.utils.ListUtils.toSet;
|
||||
import static io.github.swagger2markup.internal.utils.MapUtils.toKeySet;
|
||||
import static io.github.swagger2markup.internal.utils.TagUtils.convertTagsListToMap;
|
||||
import static io.github.swagger2markup.internal.utils.TagUtils.getTagDescription;
|
||||
import static io.github.swagger2markup.spi.PathsDocumentExtension.Context;
|
||||
import static io.github.swagger2markup.spi.PathsDocumentExtension.Position;
|
||||
import static io.github.swagger2markup.utils.IOUtils.normalizeName;
|
||||
import static org.apache.commons.lang3.StringUtils.defaultString;
|
||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public class PathsDocumentBuilder extends MarkupDocumentBuilder {
|
||||
|
||||
private final String RESPONSE;
|
||||
private final String REQUEST;
|
||||
private final String PATHS;
|
||||
private final String RESOURCES;
|
||||
private final String PARAMETERS;
|
||||
private final String BODY_PARAMETER;
|
||||
private final String RESPONSES;
|
||||
private final String HEADERS_COLUMN;
|
||||
private final String EXAMPLE_REQUEST;
|
||||
private final String EXAMPLE_RESPONSE;
|
||||
|
||||
private final String SECURITY;
|
||||
private final String TYPE_COLUMN;
|
||||
private final String HTTP_CODE_COLUMN;
|
||||
|
||||
private final String DEPRECATED_OPERATION;
|
||||
private final String UNKNOWN;
|
||||
|
||||
private static final String PATHS_ANCHOR = "paths";
|
||||
|
||||
|
||||
public PathsDocumentBuilder(Swagger2MarkupConverter.Context globalContext, Swagger2MarkupExtensionRegistry extensionRegistry, java.nio.file.Path outputPath) {
|
||||
super(globalContext, extensionRegistry, outputPath);
|
||||
|
||||
ResourceBundle labels = ResourceBundle.getBundle("io/github/swagger2markup/lang/labels", config.getOutputLanguage().toLocale());
|
||||
RESPONSE = labels.getString("response");
|
||||
REQUEST = labels.getString("request");
|
||||
PATHS = labels.getString("paths");
|
||||
RESOURCES = labels.getString("resources");
|
||||
PARAMETERS = labels.getString("parameters");
|
||||
BODY_PARAMETER = labels.getString("body_parameter");
|
||||
RESPONSES = labels.getString("responses");
|
||||
HEADERS_COLUMN = labels.getString("headers_column");
|
||||
EXAMPLE_REQUEST = labels.getString("example_request");
|
||||
EXAMPLE_RESPONSE = labels.getString("example_response");
|
||||
SECURITY = labels.getString("security");
|
||||
TYPE_COLUMN = labels.getString("type_column");
|
||||
HTTP_CODE_COLUMN = labels.getString("http_code_column");
|
||||
DEPRECATED_OPERATION = labels.getString("operation.deprecated");
|
||||
UNKNOWN = labels.getString("unknown");
|
||||
|
||||
if (config.isGeneratedExamplesEnabled()) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Include examples is enabled.");
|
||||
}
|
||||
} else {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Include examples is disabled.");
|
||||
}
|
||||
}
|
||||
|
||||
if (config.isSeparatedOperationsEnabled()) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Create separated operation files is enabled.");
|
||||
}
|
||||
Validate.notNull(outputPath, "Output directory is required for separated operation files!");
|
||||
} else {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Create separated operation files is disabled.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the paths MarkupDocument.
|
||||
*
|
||||
* @return the paths MarkupDocument
|
||||
*/
|
||||
@Override
|
||||
public MarkupDocument build() {
|
||||
Map<String, Path> paths = globalContext.getSwagger().getPaths();
|
||||
if (MapUtils.isNotEmpty(paths)) {
|
||||
applyPathsDocumentExtension(new Context(Position.DOCUMENT_BEFORE, this.markupDocBuilder));
|
||||
buildPathsTitle();
|
||||
applyPathsDocumentExtension(new Context(Position.DOCUMENT_BEGIN, this.markupDocBuilder));
|
||||
buildsPathsSection(paths);
|
||||
applyPathsDocumentExtension(new Context(Position.DOCUMENT_END, this.markupDocBuilder));
|
||||
applyPathsDocumentExtension(new Context(Position.DOCUMENT_AFTER, this.markupDocBuilder));
|
||||
}
|
||||
return new MarkupDocument(markupDocBuilder);
|
||||
}
|
||||
|
||||
private void buildsPathsSection(Map<String, Path> paths) {
|
||||
Set<PathOperation> pathOperations = toPathOperationsSet(paths);
|
||||
if (CollectionUtils.isNotEmpty(pathOperations)) {
|
||||
if (config.getPathsGroupedBy() == GroupBy.AS_IS) {
|
||||
for (PathOperation operation : pathOperations) {
|
||||
buildOperation(operation);
|
||||
}
|
||||
} else {
|
||||
Multimap<String, PathOperation> operationsGroupedByTag = TagUtils.groupOperationsByTag(pathOperations, config.getTagOrdering(), config.getOperationOrdering());
|
||||
Map<String, Tag> tagsMap = convertTagsListToMap(globalContext.getSwagger().getTags());
|
||||
for (String tagName : operationsGroupedByTag.keySet()) {
|
||||
this.markupDocBuilder.sectionTitleWithAnchorLevel2(WordUtils.capitalize(tagName), tagName + "_resource");
|
||||
|
||||
Optional<String> tagDescription = getTagDescription(tagsMap, tagName);
|
||||
if (tagDescription.isPresent()) {
|
||||
this.markupDocBuilder.paragraph(tagDescription.get());
|
||||
}
|
||||
|
||||
for (PathOperation operation : operationsGroupedByTag.get(tagName)) {
|
||||
buildOperation(operation);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the path title depending on the operationsGroupedBy configuration setting.
|
||||
*/
|
||||
private void buildPathsTitle() {
|
||||
if (config.getPathsGroupedBy() == GroupBy.AS_IS) {
|
||||
buildPathsTitle(PATHS);
|
||||
} else {
|
||||
buildPathsTitle(RESOURCES);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the Swagger paths into a list PathOperations.
|
||||
*
|
||||
* @param paths the Swagger paths
|
||||
* @return the path operations
|
||||
*/
|
||||
private Set<PathOperation> toPathOperationsSet(Map<String, Path> paths) {
|
||||
Set<PathOperation> pathOperations;
|
||||
if (config.getOperationOrdering() != null) {
|
||||
pathOperations = new TreeSet<>(config.getOperationOrdering());
|
||||
} else {
|
||||
pathOperations = new LinkedHashSet<>();
|
||||
}
|
||||
for (Map.Entry<String, Path> path : paths.entrySet()) {
|
||||
Map<HttpMethod, Operation> operations = path.getValue().getOperationMap(); // TODO AS_IS does not work because of https://github.com/swagger-api/swagger-core/issues/1696
|
||||
if (MapUtils.isNotEmpty(operations)) {
|
||||
for (Map.Entry<HttpMethod, Operation> operation : operations.entrySet()) {
|
||||
pathOperations.add(new PathOperation(operation.getKey(), path.getKey(), operation.getValue()));
|
||||
}
|
||||
}
|
||||
}
|
||||
return pathOperations;
|
||||
}
|
||||
|
||||
private void buildPathsTitle(String title) {
|
||||
this.markupDocBuilder.sectionTitleWithAnchorLevel1(title, PATHS_ANCHOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply extension context to all OperationsContentExtension.
|
||||
*
|
||||
* @param context context
|
||||
*/
|
||||
private void applyPathsDocumentExtension(Context context) {
|
||||
for (PathsDocumentExtension extension : extensionRegistry.getPathsDocumentExtensions()) {
|
||||
extension.apply(context);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the operation filename depending on the generation mode
|
||||
*
|
||||
* @param operation operation
|
||||
* @return operation filename
|
||||
*/
|
||||
private String resolveOperationDocument(PathOperation operation) {
|
||||
if (config.isSeparatedOperationsEnabled())
|
||||
return new File(config.getSeparatedOperationsFolder(), this.markupDocBuilder.addFileExtension(normalizeName(operation.getId()))).getPath();
|
||||
else
|
||||
return this.markupDocBuilder.addFileExtension(config.getPathsDocument());
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a path operation depending on generation mode.
|
||||
*
|
||||
* @param operation operation
|
||||
*/
|
||||
private void buildOperation(PathOperation operation) {
|
||||
if (config.isSeparatedOperationsEnabled()) {
|
||||
MarkupDocBuilder pathDocBuilder = copyMarkupDocBuilder();
|
||||
buildOperation(operation, pathDocBuilder);
|
||||
java.nio.file.Path operationFile = outputPath.resolve(resolveOperationDocument(operation));
|
||||
pathDocBuilder.writeToFileWithoutExtension(operationFile, StandardCharsets.UTF_8);
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Separate operation file produced : '{}'", operationFile);
|
||||
}
|
||||
|
||||
buildOperationRef(operation, this.markupDocBuilder);
|
||||
|
||||
} else {
|
||||
buildOperation(operation, this.markupDocBuilder);
|
||||
}
|
||||
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Operation processed : '{}' (normalized id = '{}')", operation, normalizeName(operation.getId()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a path operation.
|
||||
*
|
||||
* @param operation the Swagger Operation
|
||||
* @param docBuilder the docbuilder do use for output
|
||||
*/
|
||||
private void buildOperation(PathOperation operation, MarkupDocBuilder docBuilder) {
|
||||
if (operation != null) {
|
||||
applyPathsDocumentExtension(new Context(Position.OPERATION_BEFORE, docBuilder, operation));
|
||||
buildDeprecatedSection(operation, docBuilder);
|
||||
buildOperationTitle(operation, docBuilder);
|
||||
applyPathsDocumentExtension(new Context(Position.OPERATION_BEGIN, docBuilder, operation));
|
||||
buildDescriptionSection(operation, docBuilder);
|
||||
inlineDefinitions(buildParametersSection(operation, docBuilder), operation.getPath() + " " + operation.getMethod(), docBuilder);
|
||||
inlineDefinitions(buildBodyParameterSection(operation, docBuilder), operation.getPath() + " " + operation.getMethod(), docBuilder);
|
||||
inlineDefinitions(buildResponsesSection(operation, docBuilder), operation.getPath() + " " + operation.getMethod(), docBuilder);
|
||||
buildConsumesSection(operation, docBuilder);
|
||||
buildProducesSection(operation, docBuilder);
|
||||
buildTagsSection(operation, docBuilder);
|
||||
buildSecuritySchemeSection(operation, docBuilder);
|
||||
buildExamplesSection(operation, docBuilder);
|
||||
applyPathsDocumentExtension(new Context(Position.OPERATION_END, docBuilder, operation));
|
||||
applyPathsDocumentExtension(new Context(Position.OPERATION_AFTER, docBuilder, operation));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a cross-reference to a separated operation file
|
||||
*
|
||||
* @param operation the Swagger Operation
|
||||
* @param docBuilder the docbuilder do use for output
|
||||
*/
|
||||
private void buildOperationRef(PathOperation operation, MarkupDocBuilder docBuilder) {
|
||||
String document;
|
||||
if (!config.isInterDocumentCrossReferencesEnabled() || outputPath == null)
|
||||
document = null;
|
||||
else if (config.isSeparatedOperationsEnabled())
|
||||
document = defaultString(config.getInterDocumentCrossReferencesPrefix()) + resolveOperationDocument(operation);
|
||||
else
|
||||
document = defaultString(config.getInterDocumentCrossReferencesPrefix()) + resolveOperationDocument(operation);
|
||||
|
||||
buildOperationTitle(copyMarkupDocBuilder().crossReference(document, operation.getId(), operation.getTitle()).toString(), "ref-" + operation.getId(), docBuilder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a warning if method is deprecated.
|
||||
*
|
||||
* @param operation the Swagger Operation
|
||||
* @param docBuilder the docbuilder do use for output
|
||||
*/
|
||||
private void buildDeprecatedSection(PathOperation operation, MarkupDocBuilder docBuilder) {
|
||||
Boolean deprecated = operation.getOperation().isDeprecated();
|
||||
if (deprecated != null && deprecated) {
|
||||
docBuilder.block(DEPRECATED_OPERATION, MarkupBlockStyle.EXAMPLE, null, MarkupAdmonition.CAUTION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the operation title to the document. If the operation has a summary, the title is the summary.
|
||||
* Otherwise the title is the method of the operation and the URL of the operation.
|
||||
*
|
||||
* @param operation the Swagger Operation
|
||||
* @param docBuilder the docbuilder do use for output
|
||||
*/
|
||||
private void buildOperationTitle(PathOperation operation, MarkupDocBuilder docBuilder) {
|
||||
buildOperationTitle(operation.getTitle(), operation.getId(), docBuilder);
|
||||
if (operation.getTitle().equals(operation.getOperation().getSummary())) {
|
||||
docBuilder.block(operation.getMethod() + " " + operation.getPath(), MarkupBlockStyle.LITERAL);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a operation title to the document.
|
||||
*
|
||||
* @param title the operation title
|
||||
* @param anchor optional anchor (null => auto-generate from title)
|
||||
* @param docBuilder the MarkupDocBuilder to use
|
||||
*/
|
||||
private void buildOperationTitle(String title, String anchor, MarkupDocBuilder docBuilder) {
|
||||
if (config.getPathsGroupedBy() == GroupBy.AS_IS) {
|
||||
docBuilder.sectionTitleWithAnchorLevel2(title, anchor);
|
||||
} else {
|
||||
docBuilder.sectionTitleWithAnchorLevel3(title, anchor);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a operation section title to the document.
|
||||
*
|
||||
* @param title the section title
|
||||
* @param docBuilder the MarkupDocBuilder to use
|
||||
*/
|
||||
private void buildSectionTitle(String title, MarkupDocBuilder docBuilder) {
|
||||
if (config.getPathsGroupedBy() == GroupBy.AS_IS) {
|
||||
docBuilder.sectionTitleLevel3(title);
|
||||
} else {
|
||||
docBuilder.sectionTitleLevel4(title);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a example title to the document.
|
||||
*
|
||||
* @param title the section title
|
||||
* @param docBuilder the MarkupDocBuilder to use
|
||||
*/
|
||||
private void buildExampleTitle(String title, MarkupDocBuilder docBuilder) {
|
||||
if (config.getPathsGroupedBy() == GroupBy.AS_IS) {
|
||||
docBuilder.sectionTitleLevel4(title);
|
||||
} else {
|
||||
docBuilder.sectionTitleLevel5(title);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a operation description to the document.
|
||||
*
|
||||
* @param operation the Swagger Operation
|
||||
* @param docBuilder the docbuilder do use for output
|
||||
*/
|
||||
private void buildDescriptionSection(PathOperation operation, MarkupDocBuilder docBuilder) {
|
||||
MarkupDocBuilder descriptionBuilder = copyMarkupDocBuilder();
|
||||
applyPathsDocumentExtension(new Context(Position.OPERATION_DESCRIPTION_BEGIN, descriptionBuilder, operation));
|
||||
buildDescriptionParagraph(operation.getOperation().getDescription(), descriptionBuilder);
|
||||
applyPathsDocumentExtension(new Context(Position.OPERATION_DESCRIPTION_END, descriptionBuilder, operation));
|
||||
String descriptionContent = descriptionBuilder.toString();
|
||||
|
||||
applyPathsDocumentExtension(new Context(Position.OPERATION_DESCRIPTION_BEFORE, docBuilder, operation));
|
||||
if (isNotBlank(descriptionContent)) {
|
||||
buildSectionTitle(DESCRIPTION, docBuilder);
|
||||
docBuilder.text(descriptionContent);
|
||||
}
|
||||
applyPathsDocumentExtension(new Context(Position.OPERATION_DESCRIPTION_AFTER, docBuilder, operation));
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter parameters to display in parameters section
|
||||
*
|
||||
* @param parameter parameter to filter
|
||||
* @return true if parameter can be displayed
|
||||
*/
|
||||
private boolean filterParameter(Parameter parameter) {
|
||||
return (!config.isFlatBodyEnabled() || !StringUtils.equals(parameter.getIn(), "body"));
|
||||
}
|
||||
|
||||
private List<ObjectType> buildParametersSection(PathOperation operation, MarkupDocBuilder docBuilder) {
|
||||
List<Parameter> parameters = operation.getOperation().getParameters();
|
||||
if (config.getParameterOrdering() != null)
|
||||
Collections.sort(parameters, config.getParameterOrdering());
|
||||
List<ObjectType> inlineDefinitions = new ArrayList<>();
|
||||
|
||||
boolean hasParameters = false;
|
||||
if (CollectionUtils.isNotEmpty(parameters)) {
|
||||
for (Parameter p : parameters) {
|
||||
if (filterParameter(p)) {
|
||||
hasParameters = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MarkupDocBuilder parametersBuilder = copyMarkupDocBuilder();
|
||||
applyPathsDocumentExtension(new Context(Position.OPERATION_DESCRIPTION_BEGIN, parametersBuilder, operation));
|
||||
if (hasParameters) {
|
||||
List<List<String>> cells = new ArrayList<>();
|
||||
List<MarkupTableColumn> cols = Arrays.asList(
|
||||
new MarkupTableColumn(TYPE_COLUMN).withWidthRatio(1).withHeaderColumn(false).withMarkupSpecifiers(MarkupLanguage.ASCIIDOC, ".^1"),
|
||||
new MarkupTableColumn(NAME_COLUMN).withWidthRatio(3).withHeaderColumn(false).withMarkupSpecifiers(MarkupLanguage.ASCIIDOC, ".^3"),
|
||||
new MarkupTableColumn(DESCRIPTION_COLUMN).withWidthRatio(10).withMarkupSpecifiers(MarkupLanguage.ASCIIDOC, ".^10"),
|
||||
new MarkupTableColumn(SCHEMA_COLUMN).withWidthRatio(4).withMarkupSpecifiers(MarkupLanguage.ASCIIDOC, ".^4"),
|
||||
new MarkupTableColumn(DEFAULT_COLUMN).withWidthRatio(2).withMarkupSpecifiers(MarkupLanguage.ASCIIDOC, ".^2"));
|
||||
for (Parameter parameter : parameters) {
|
||||
if (filterParameter(parameter)) {
|
||||
Type type = ParameterUtils.getType(parameter, globalContext.getSwagger().getDefinitions(), new DefinitionDocumentResolverFromOperation());
|
||||
|
||||
type = createInlineType(type, parameter.getName(), operation.getId() + " " + parameter.getName(), inlineDefinitions);
|
||||
|
||||
String parameterType = WordUtils.capitalize(parameter.getIn());
|
||||
|
||||
MarkupDocBuilder parameterNameContent = copyMarkupDocBuilder();
|
||||
parameterNameContent.boldTextLine(parameter.getName(), true);
|
||||
if (parameter.getRequired())
|
||||
parameterNameContent.italicText(FLAGS_REQUIRED.toLowerCase());
|
||||
else
|
||||
parameterNameContent.italicText(FLAGS_OPTIONAL.toLowerCase());
|
||||
|
||||
Object defaultValue = ParameterUtils.getDefaultValue(parameter);
|
||||
|
||||
List<String> content = Arrays.asList(
|
||||
boldText(parameterType),
|
||||
parameterNameContent.toString(),
|
||||
defaultString(swaggerMarkupDescription(parameter.getDescription())),
|
||||
type.displaySchema(markupDocBuilder),
|
||||
defaultValue != null ? literalText(Json.pretty(defaultValue)) : "");
|
||||
cells.add(content);
|
||||
}
|
||||
}
|
||||
parametersBuilder.tableWithColumnSpecs(cols, cells);
|
||||
}
|
||||
applyPathsDocumentExtension(new Context(Position.OPERATION_DESCRIPTION_END, parametersBuilder, operation));
|
||||
String parametersContent = parametersBuilder.toString();
|
||||
|
||||
applyPathsDocumentExtension(new Context(Position.OPERATION_PARAMETERS_BEFORE, docBuilder, operation));
|
||||
if (isNotBlank(parametersContent)) {
|
||||
buildSectionTitle(PARAMETERS, docBuilder);
|
||||
docBuilder.text(parametersContent);
|
||||
}
|
||||
applyPathsDocumentExtension(new Context(Position.OPERATION_PARAMETERS_AFTER, docBuilder, operation));
|
||||
|
||||
return inlineDefinitions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the body parameter section, if {@code Swagger2MarkupConfig.isIsolatedBody()} is true
|
||||
*
|
||||
* @param operation the Swagger Operation
|
||||
* @param docBuilder the docbuilder do use for output
|
||||
* @return a list of inlined types.
|
||||
*/
|
||||
private List<ObjectType> buildBodyParameterSection(PathOperation operation, MarkupDocBuilder docBuilder) {
|
||||
List<ObjectType> inlineDefinitions = new ArrayList<>();
|
||||
|
||||
if (config.isFlatBodyEnabled()) {
|
||||
List<Parameter> parameters = operation.getOperation().getParameters();
|
||||
if (CollectionUtils.isNotEmpty(parameters)) {
|
||||
for (Parameter parameter : parameters) {
|
||||
if (StringUtils.equals(parameter.getIn(), "body")) {
|
||||
Type type = ParameterUtils.getType(parameter, globalContext.getSwagger().getDefinitions(), new DefinitionDocumentResolverFromOperation());
|
||||
|
||||
if (!(type instanceof ObjectType)) {
|
||||
type = createInlineType(type, parameter.getName(), operation.getId() + " " + parameter.getName(), inlineDefinitions);
|
||||
}
|
||||
|
||||
buildSectionTitle(BODY_PARAMETER, docBuilder);
|
||||
if (isNotBlank(parameter.getDescription())) {
|
||||
buildDescriptionParagraph(parameter.getDescription(), docBuilder);
|
||||
}
|
||||
|
||||
MarkupDocBuilder typeInfos = copyMarkupDocBuilder();
|
||||
typeInfos.italicText(NAME_COLUMN).textLine(COLON + parameter.getName());
|
||||
typeInfos.italicText(FLAGS_COLUMN).textLine(COLON + (BooleanUtils.isTrue(parameter.getRequired()) ? FLAGS_REQUIRED.toLowerCase() : FLAGS_OPTIONAL.toLowerCase()));
|
||||
|
||||
if (!(type instanceof ObjectType)) {
|
||||
typeInfos.italicText(TYPE_COLUMN).textLine(COLON + type.displaySchema(docBuilder));
|
||||
}
|
||||
|
||||
docBuilder.paragraph(typeInfos.toString(), true);
|
||||
|
||||
if (type instanceof ObjectType) {
|
||||
inlineDefinitions.addAll(buildPropertiesTable(((ObjectType) type).getProperties(), operation.getId(), new DefinitionDocumentResolverFromOperation(), docBuilder));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return inlineDefinitions;
|
||||
}
|
||||
|
||||
private void buildConsumesSection(PathOperation operation, MarkupDocBuilder docBuilder) {
|
||||
List<String> consumes = operation.getOperation().getConsumes();
|
||||
if (CollectionUtils.isNotEmpty(consumes)) {
|
||||
buildSectionTitle(CONSUMES, docBuilder);
|
||||
docBuilder.newLine();
|
||||
for (String consume : consumes) {
|
||||
docBuilder.unorderedListItem(literalText(consume));
|
||||
}
|
||||
docBuilder.newLine();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void buildProducesSection(PathOperation operation, MarkupDocBuilder docBuilder) {
|
||||
List<String> produces = operation.getOperation().getProduces();
|
||||
if (CollectionUtils.isNotEmpty(produces)) {
|
||||
buildSectionTitle(PRODUCES, docBuilder);
|
||||
docBuilder.newLine();
|
||||
for (String produce : produces) {
|
||||
docBuilder.unorderedListItem(literalText(produce));
|
||||
}
|
||||
docBuilder.newLine();
|
||||
}
|
||||
}
|
||||
|
||||
private void buildTagsSection(PathOperation operation, MarkupDocBuilder docBuilder) {
|
||||
if (config.getPathsGroupedBy() == GroupBy.AS_IS) {
|
||||
List<String> tags = operation.getOperation().getTags();
|
||||
if (CollectionUtils.isNotEmpty(tags)) {
|
||||
buildSectionTitle(TAGS, docBuilder);
|
||||
Set<String> tagsSet = toSet(tags, config.getTagOrdering());
|
||||
docBuilder.unorderedList(new ArrayList<>(tagsSet));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the example section of a Swagger Operation.
|
||||
*
|
||||
* @param operation the Swagger Operation
|
||||
* @param docBuilder the docbuilder do use for output
|
||||
*/
|
||||
private void buildExamplesSection(PathOperation operation, MarkupDocBuilder docBuilder) {
|
||||
|
||||
Map<String, Object> generatedRequestExampleMap = ExamplesUtil.generateRequestExampleMap(config.isGeneratedExamplesEnabled(), operation, globalContext.getSwagger().getDefinitions(), markupDocBuilder);
|
||||
Map<String, Object> generatedResponseExampleMap = ExamplesUtil.generateResponseExampleMap(config.isGeneratedExamplesEnabled(), operation.getOperation(), globalContext.getSwagger().getDefinitions(), markupDocBuilder);
|
||||
|
||||
exampleMap(generatedRequestExampleMap, EXAMPLE_REQUEST, REQUEST, docBuilder);
|
||||
exampleMap(generatedResponseExampleMap, EXAMPLE_RESPONSE, RESPONSE, docBuilder);
|
||||
}
|
||||
|
||||
private void exampleMap(Map<String, Object> exampleMap, String operationSectionTitle, String sectionTitle, MarkupDocBuilder docBuilder) {
|
||||
if (exampleMap.size() > 0) {
|
||||
buildSectionTitle(operationSectionTitle, docBuilder);
|
||||
for (Map.Entry<String, Object> entry : exampleMap.entrySet()) {
|
||||
buildExampleTitle(sectionTitle + " " + entry.getKey(), docBuilder);
|
||||
docBuilder.listingBlock(Json.pretty(entry.getValue()), "json");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the security section of a Swagger Operation.
|
||||
*
|
||||
* @param operation the Swagger Operation
|
||||
* @param docBuilder the MarkupDocBuilder document builder
|
||||
*/
|
||||
private void buildSecuritySchemeSection(PathOperation operation, MarkupDocBuilder docBuilder) {
|
||||
List<Map<String, List<String>>> securitySchemes = operation.getOperation().getSecurity();
|
||||
|
||||
MarkupDocBuilder securityBuilder = copyMarkupDocBuilder();
|
||||
applyPathsDocumentExtension(new Context(Position.OPERATION_SECURITY_BEGIN, securityBuilder, operation));
|
||||
if (CollectionUtils.isNotEmpty(securitySchemes)) {
|
||||
|
||||
Map<String, SecuritySchemeDefinition> securityDefinitions = globalContext.getSwagger().getSecurityDefinitions();
|
||||
List<List<String>> cells = new ArrayList<>();
|
||||
List<MarkupTableColumn> cols = Arrays.asList(
|
||||
new MarkupTableColumn(TYPE_COLUMN).withWidthRatio(3).withHeaderColumn(false).withMarkupSpecifiers(MarkupLanguage.ASCIIDOC, ".^3"),
|
||||
new MarkupTableColumn(NAME_COLUMN).withWidthRatio(4).withHeaderColumn(false).withMarkupSpecifiers(MarkupLanguage.ASCIIDOC, ".^4"),
|
||||
new MarkupTableColumn(SCOPES_COLUMN).withWidthRatio(13).withMarkupSpecifiers(MarkupLanguage.ASCIIDOC, ".^13"));
|
||||
for (Map<String, List<String>> securityScheme : securitySchemes) {
|
||||
for (Map.Entry<String, List<String>> securityEntry : securityScheme.entrySet()) {
|
||||
String securityKey = securityEntry.getKey();
|
||||
String type = UNKNOWN;
|
||||
if (securityDefinitions != null && securityDefinitions.containsKey(securityKey)) {
|
||||
type = securityDefinitions.get(securityKey).getType();
|
||||
}
|
||||
|
||||
List<String> content = Arrays.asList(boldText(type), boldText(copyMarkupDocBuilder().crossReference(securityDocumentResolver(), securityKey, securityKey).toString()),
|
||||
Joiner.on(",").join(securityEntry.getValue()));
|
||||
cells.add(content);
|
||||
}
|
||||
}
|
||||
securityBuilder.tableWithColumnSpecs(cols, cells);
|
||||
}
|
||||
applyPathsDocumentExtension(new Context(Position.OPERATION_SECURITY_END, securityBuilder, operation));
|
||||
String securityContent = securityBuilder.toString();
|
||||
|
||||
applyPathsDocumentExtension(new Context(Position.OPERATION_SECURITY_BEFORE, docBuilder, operation));
|
||||
if (isNotBlank(securityContent)) {
|
||||
buildSectionTitle(SECURITY, docBuilder);
|
||||
docBuilder.text(securityContent);
|
||||
}
|
||||
applyPathsDocumentExtension(new Context(Position.OPERATION_SECURITY_AFTER, docBuilder, operation));
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve Security document for use in cross-references.
|
||||
*
|
||||
* @return document or null if cross-reference is not inter-document
|
||||
*/
|
||||
private String securityDocumentResolver() {
|
||||
if (!config.isInterDocumentCrossReferencesEnabled() || outputPath == null)
|
||||
return null;
|
||||
else
|
||||
return defaultString(config.getInterDocumentCrossReferencesPrefix()) + markupDocBuilder.addFileExtension(config.getSecurityDocument());
|
||||
}
|
||||
|
||||
private List<ObjectType> buildResponsesSection(PathOperation operation, MarkupDocBuilder docBuilder) {
|
||||
Map<String, Response> responses = operation.getOperation().getResponses();
|
||||
List<ObjectType> inlineDefinitions = new ArrayList<>();
|
||||
|
||||
MarkupDocBuilder responsesBuilder = copyMarkupDocBuilder();
|
||||
applyPathsDocumentExtension(new Context(Position.OPERATION_RESPONSES_BEGIN, responsesBuilder, operation));
|
||||
if (MapUtils.isNotEmpty(responses)) {
|
||||
List<MarkupTableColumn> responseCols = Arrays.asList(
|
||||
new MarkupTableColumn(HTTP_CODE_COLUMN).withWidthRatio(1).withHeaderColumn(false).withMarkupSpecifiers(MarkupLanguage.ASCIIDOC, ".^1"),
|
||||
new MarkupTableColumn(DESCRIPTION_COLUMN).withWidthRatio(15).withMarkupSpecifiers(MarkupLanguage.ASCIIDOC, ".^15"),
|
||||
new MarkupTableColumn(SCHEMA_COLUMN).withWidthRatio(4).withMarkupSpecifiers(MarkupLanguage.ASCIIDOC, ".^4"));
|
||||
|
||||
List<List<String>> cells = new ArrayList<>();
|
||||
|
||||
Set<String> responseNames = toKeySet(responses, config.getResponseOrdering());
|
||||
for (String responseName : responseNames) {
|
||||
Response response = responses.get(responseName);
|
||||
|
||||
String schemaContent = NO_CONTENT;
|
||||
if (response.getSchema() != null) {
|
||||
Property property = response.getSchema();
|
||||
Type type = PropertyUtils.getType(property, new DefinitionDocumentResolverFromOperation());
|
||||
|
||||
type = createInlineType(type, RESPONSE + " " + responseName, operation.getId() + " " + RESPONSE + " " + responseName, inlineDefinitions);
|
||||
|
||||
schemaContent = type.displaySchema(markupDocBuilder);
|
||||
}
|
||||
|
||||
MarkupDocBuilder descriptionBuilder = copyMarkupDocBuilder();
|
||||
|
||||
descriptionBuilder.text(defaultString(swaggerMarkupDescription(response.getDescription())));
|
||||
|
||||
Map<String, Property> headers = response.getHeaders();
|
||||
if (MapUtils.isNotEmpty(headers)) {
|
||||
descriptionBuilder.newLine(true).boldText(HEADERS_COLUMN).text(COLON);
|
||||
for (Map.Entry<String, Property> header : headers.entrySet()) {
|
||||
descriptionBuilder.newLine(true);
|
||||
Property headerProperty = header.getValue();
|
||||
Type propertyType = PropertyUtils.getType(headerProperty, null);
|
||||
String headerDescription = defaultString(swaggerMarkupDescription(headerProperty.getDescription()));
|
||||
Object defaultValue = PropertyUtils.getDefaultValue(headerProperty);
|
||||
|
||||
descriptionBuilder
|
||||
.literalText(header.getKey())
|
||||
.text(String.format(" (%s)", propertyType.displaySchema(markupDocBuilder)));
|
||||
|
||||
if (isNotBlank(headerDescription) || defaultValue != null) {
|
||||
descriptionBuilder.text(COLON);
|
||||
|
||||
if (isNotBlank(headerDescription) && !headerDescription.endsWith("."))
|
||||
headerDescription += ".";
|
||||
|
||||
descriptionBuilder.text(headerDescription);
|
||||
|
||||
if (defaultValue != null) {
|
||||
descriptionBuilder.text(" ").boldText(DEFAULT_COLUMN).text(COLON).literalText(Json.pretty(defaultValue));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cells.add(Arrays.asList(boldText(responseName), descriptionBuilder.toString(), schemaContent));
|
||||
}
|
||||
|
||||
responsesBuilder.tableWithColumnSpecs(responseCols, cells);
|
||||
}
|
||||
applyPathsDocumentExtension(new Context(Position.OPERATION_RESPONSES_END, responsesBuilder, operation));
|
||||
String responsesContent = responsesBuilder.toString();
|
||||
|
||||
applyPathsDocumentExtension(new Context(Position.OPERATION_RESPONSES_BEFORE, docBuilder, operation));
|
||||
if (isNotBlank(responsesContent)) {
|
||||
buildSectionTitle(RESPONSES, docBuilder);
|
||||
docBuilder.text(responsesContent);
|
||||
}
|
||||
applyPathsDocumentExtension(new Context(Position.OPERATION_RESPONSES_AFTER, docBuilder, operation));
|
||||
|
||||
return inlineDefinitions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the title of an inline schema.
|
||||
* Inline definitions should never been referenced in TOC because they have no real existence, so they are just text.
|
||||
*
|
||||
* @param title inline schema title
|
||||
* @param anchor inline schema anchor
|
||||
* @param docBuilder the docbuilder do use for output
|
||||
*/
|
||||
private void addInlineDefinitionTitle(String title, String anchor, MarkupDocBuilder docBuilder) {
|
||||
docBuilder.anchor(anchor);
|
||||
docBuilder.newLine();
|
||||
docBuilder.boldTextLine(title);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds inline schema definitions
|
||||
*
|
||||
* @param definitions all inline definitions to display
|
||||
* @param uniquePrefix unique prefix to prepend to inline object names to enforce unicity
|
||||
* @param docBuilder the docbuilder do use for output
|
||||
*/
|
||||
private void inlineDefinitions(List<ObjectType> definitions, String uniquePrefix, MarkupDocBuilder docBuilder) {
|
||||
if (CollectionUtils.isNotEmpty(definitions)) {
|
||||
for (ObjectType definition : definitions) {
|
||||
addInlineDefinitionTitle(definition.getName(), definition.getUniqueName(), docBuilder);
|
||||
|
||||
List<ObjectType> localDefinitions = buildPropertiesTable(definition.getProperties(), uniquePrefix, new DefinitionDocumentResolverFromOperation(), docBuilder);
|
||||
for (ObjectType localDefinition : localDefinitions)
|
||||
inlineDefinitions(Collections.singletonList(localDefinition), localDefinition.getUniqueName(), docBuilder);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides definition document resolver functor for inter-document cross-references from operations files.
|
||||
* This implementation adapt the relative paths to definitions files
|
||||
*/
|
||||
class DefinitionDocumentResolverFromOperation extends DefinitionDocumentResolverDefault {
|
||||
|
||||
public DefinitionDocumentResolverFromOperation() {
|
||||
}
|
||||
|
||||
public String apply(String definitionName) {
|
||||
String defaultResolver = super.apply(definitionName);
|
||||
|
||||
if (defaultResolver != null && config.isSeparatedOperationsEnabled())
|
||||
return defaultString(config.getInterDocumentCrossReferencesPrefix()) + new File("..", defaultResolver).getPath();
|
||||
else
|
||||
return defaultResolver;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
/*
|
||||
* Copyright 2016 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.document.builder;
|
||||
|
||||
import com.google.common.collect.Ordering;
|
||||
import io.github.swagger2markup.Swagger2MarkupConverter;
|
||||
import io.github.swagger2markup.Swagger2MarkupExtensionRegistry;
|
||||
import io.github.swagger2markup.internal.document.MarkupDocument;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import io.github.swagger2markup.markup.builder.MarkupLanguage;
|
||||
import io.github.swagger2markup.markup.builder.MarkupTableColumn;
|
||||
import io.github.swagger2markup.spi.SecurityDocumentExtension;
|
||||
import io.swagger.models.auth.ApiKeyAuthDefinition;
|
||||
import io.swagger.models.auth.OAuth2Definition;
|
||||
import io.swagger.models.auth.SecuritySchemeDefinition;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
|
||||
import static io.github.swagger2markup.internal.utils.MapUtils.toKeySet;
|
||||
import static io.github.swagger2markup.spi.SecurityDocumentExtension.Context;
|
||||
import static io.github.swagger2markup.spi.SecurityDocumentExtension.Position;
|
||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public class SecurityDocumentBuilder extends MarkupDocumentBuilder {
|
||||
|
||||
private static final String SECURITY_ANCHOR = "securityScheme";
|
||||
private final String SECURITY;
|
||||
private final String TYPE;
|
||||
private final String NAME;
|
||||
private final String IN;
|
||||
private final String FLOW;
|
||||
private final String AUTHORIZATION_URL;
|
||||
private final String TOKEN_URL;
|
||||
|
||||
public SecurityDocumentBuilder(Swagger2MarkupConverter.Context context, Swagger2MarkupExtensionRegistry extensionRegistry, Path outputPath) {
|
||||
super(context, extensionRegistry, outputPath);
|
||||
|
||||
ResourceBundle labels = ResourceBundle.getBundle("io/github/swagger2markup/lang/labels", config.getOutputLanguage().toLocale());
|
||||
SECURITY = labels.getString("security");
|
||||
TYPE = labels.getString("security_type");
|
||||
NAME = labels.getString("security_name");
|
||||
IN = labels.getString("security_in");
|
||||
FLOW = labels.getString("security_flow");
|
||||
AUTHORIZATION_URL = labels.getString("security_authorizationUrl");
|
||||
TOKEN_URL = labels.getString("security_tokenUrl");
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the security MarkupDocument.
|
||||
*
|
||||
* @return the security MarkupDocument
|
||||
*/
|
||||
@Override
|
||||
public MarkupDocument build(){
|
||||
Map<String, SecuritySchemeDefinition> definitions = globalContext.getSwagger().getSecurityDefinitions();
|
||||
if (MapUtils.isNotEmpty(definitions)) {
|
||||
applySecurityDocumentExtension(new Context(Position.DOCUMENT_BEFORE, this.markupDocBuilder));
|
||||
buildSecurityTitle(SECURITY);
|
||||
applySecurityDocumentExtension(new Context(Position.DOCUMENT_BEGIN, this.markupDocBuilder));
|
||||
buildSecuritySchemeDefinitionsSection(definitions);
|
||||
applySecurityDocumentExtension(new Context(Position.DOCUMENT_END, this.markupDocBuilder));
|
||||
applySecurityDocumentExtension(new Context(Position.DOCUMENT_AFTER, this.markupDocBuilder));
|
||||
}
|
||||
return new MarkupDocument(markupDocBuilder);
|
||||
}
|
||||
|
||||
private void buildSecurityTitle(String title) {
|
||||
this.markupDocBuilder.sectionTitleWithAnchorLevel1(title, SECURITY_ANCHOR);
|
||||
}
|
||||
|
||||
private void buildSecuritySchemeDefinitionsSection(Map<String, SecuritySchemeDefinition> securitySchemes) {
|
||||
Set<String> securitySchemeNames = toKeySet(securitySchemes, Ordering.natural()); // TODO : provide a dedicated ordering configuration for security schemes
|
||||
for (String securitySchemeName : securitySchemeNames) {
|
||||
SecuritySchemeDefinition securityScheme = securitySchemes.get(securitySchemeName);
|
||||
applySecurityDocumentExtension(new Context(Position.SECURITY_SCHEME_BEFORE, markupDocBuilder, securitySchemeName, securityScheme));
|
||||
buildSecuritySchemeDefinitionTitle(securitySchemeName);
|
||||
applySecurityDocumentExtension(new Context(Position.SECURITY_SCHEME_BEGIN, markupDocBuilder, securitySchemeName, securityScheme));
|
||||
buildDescriptionParagraph(securityScheme.getDescription(), this.markupDocBuilder);
|
||||
buildSecurityScheme(securityScheme);
|
||||
applySecurityDocumentExtension(new Context(Position.SECURITY_SCHEME_END, markupDocBuilder, securitySchemeName, securityScheme));
|
||||
applySecurityDocumentExtension(new Context(Position.SECURITY_SCHEME_AFTER, markupDocBuilder, securitySchemeName, securityScheme));
|
||||
}
|
||||
}
|
||||
|
||||
private MarkupDocBuilder buildSecuritySchemeDefinitionTitle(String securitySchemeName) {
|
||||
return markupDocBuilder.sectionTitleWithAnchorLevel2(securitySchemeName);
|
||||
}
|
||||
|
||||
private void buildSecurityScheme(SecuritySchemeDefinition securityScheme) {
|
||||
String type = securityScheme.getType();
|
||||
MarkupDocBuilder paragraph = copyMarkupDocBuilder();
|
||||
|
||||
paragraph.italicText(TYPE).textLine(COLON + type);
|
||||
|
||||
if (securityScheme instanceof ApiKeyAuthDefinition) {
|
||||
paragraph.italicText(NAME).textLine(COLON + ((ApiKeyAuthDefinition) securityScheme).getName());
|
||||
paragraph.italicText(IN).textLine(COLON + ((ApiKeyAuthDefinition) securityScheme).getIn());
|
||||
|
||||
markupDocBuilder.paragraph(paragraph.toString(), true);
|
||||
} else if (securityScheme instanceof OAuth2Definition) {
|
||||
OAuth2Definition oauth2Scheme = (OAuth2Definition) securityScheme;
|
||||
String flow = oauth2Scheme.getFlow();
|
||||
paragraph.italicText(FLOW).textLine(COLON + flow);
|
||||
if (isNotBlank(oauth2Scheme.getAuthorizationUrl())) {
|
||||
paragraph.italicText(AUTHORIZATION_URL).textLine(COLON + oauth2Scheme.getAuthorizationUrl());
|
||||
}
|
||||
if (isNotBlank(oauth2Scheme.getTokenUrl())) {
|
||||
paragraph.italicText(TOKEN_URL).textLine(COLON + oauth2Scheme.getTokenUrl());
|
||||
}
|
||||
|
||||
List<List<String>> cells = new ArrayList<>();
|
||||
List<MarkupTableColumn> cols = Arrays.asList(
|
||||
new MarkupTableColumn(NAME_COLUMN).withWidthRatio(3).withMarkupSpecifiers(MarkupLanguage.ASCIIDOC, ".^3"),
|
||||
new MarkupTableColumn(DESCRIPTION_COLUMN).withWidthRatio(17).withMarkupSpecifiers(MarkupLanguage.ASCIIDOC, ".^17"));
|
||||
for (Map.Entry<String, String> scope : oauth2Scheme.getScopes().entrySet()) {
|
||||
List<String> content = Arrays.asList(scope.getKey(), scope.getValue());
|
||||
cells.add(content);
|
||||
}
|
||||
|
||||
markupDocBuilder.paragraph(paragraph.toString(), true);
|
||||
markupDocBuilder.tableWithColumnSpecs(cols, cells);
|
||||
} else {
|
||||
markupDocBuilder.paragraph(paragraph.toString(), true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply extension context to all SecurityContentExtension
|
||||
*
|
||||
* @param context context
|
||||
*/
|
||||
private void applySecurityDocumentExtension(Context context) {
|
||||
for (SecurityDocumentExtension extension : extensionRegistry.getSecurityDocumentExtensions()) {
|
||||
extension.apply(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 Robert Winkler
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -25,8 +25,8 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
*/
|
||||
public class ArrayType extends Type {
|
||||
|
||||
private String collectionFormat;
|
||||
private Type ofType;
|
||||
protected String collectionFormat;
|
||||
protected Type ofType;
|
||||
|
||||
public ArrayType(String name, Type ofType) {
|
||||
this(name, ofType, null);
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 Robert Winkler
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -38,7 +38,7 @@ public class BasicType extends Type {
|
||||
|
||||
public BasicType(String type, String name, String format) {
|
||||
super(name);
|
||||
Validate.notBlank(type, "Type of parameter '%s' must not be blank", name);
|
||||
Validate.notBlank(type);
|
||||
this.type = type;
|
||||
this.format = format;
|
||||
}
|
||||
@@ -46,7 +46,7 @@ public class BasicType extends Type {
|
||||
@Override
|
||||
public String displaySchema(MarkupDocBuilder docBuilder) {
|
||||
if (isNotBlank(this.format))
|
||||
return String.format("%s (%s)", this.type, this.format);
|
||||
return String.format("%s(%s)", this.type, this.format);
|
||||
else
|
||||
return this.type;
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 Robert Winkler
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,11 +13,12 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.github.swagger2markup.extension;
|
||||
|
||||
package io.github.swagger2markup.internal.type;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
/**
|
||||
* Marker interface for Extensions registry.
|
||||
* A functor to return the document part of an inter-document cross-references, depending on the globalContext.
|
||||
*/
|
||||
public interface Schema2MarkupExtensionRegistry {
|
||||
|
||||
}
|
||||
public interface DefinitionDocumentResolver extends Function<String, String> {}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 Robert Winkler
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 Robert Winkler
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -23,9 +23,9 @@ import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
*/
|
||||
public class MapType extends Type {
|
||||
|
||||
private Type keyType = new BasicType("string", null);
|
||||
private Type valueType;
|
||||
|
||||
protected Type keyType = new BasicType("string", null);
|
||||
protected Type valueType;
|
||||
|
||||
public MapType(String name, Type valueType) {
|
||||
super(name);
|
||||
this.valueType = valueType;
|
||||
@@ -34,8 +34,7 @@ public class MapType extends Type {
|
||||
@Override
|
||||
public String displaySchema(MarkupDocBuilder docBuilder) {
|
||||
String keyTypeDisplay = keyType.displaySchema(docBuilder);
|
||||
// Display MapType with null valueType as object to fix https://github.com/swagger-api/swagger-parser/issues/346
|
||||
return valueType == null ? "object" : String.format("< %s, %s > map", keyTypeDisplay, valueType.displaySchema(docBuilder));
|
||||
return String.format("< %s, %s > map", keyTypeDisplay, valueType.displaySchema(docBuilder));
|
||||
}
|
||||
|
||||
public Type getKeyType() {
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 Robert Winkler
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -25,9 +25,9 @@ import java.util.Map;
|
||||
* Complex object abstraction
|
||||
*/
|
||||
public class ObjectType extends Type {
|
||||
|
||||
private Map<String, Property> properties;
|
||||
private ObjectTypePolymorphism polymorphism;
|
||||
|
||||
protected Map<String, Property> properties;
|
||||
protected ObjectTypePolymorphism polymorphism;
|
||||
|
||||
public ObjectType(String name, ObjectTypePolymorphism polymorphism, Map<String, Property> properties) {
|
||||
super(name);
|
||||
@@ -43,7 +43,7 @@ public class ObjectType extends Type {
|
||||
public String displaySchema(MarkupDocBuilder docBuilder) {
|
||||
return "object";
|
||||
}
|
||||
|
||||
|
||||
public ObjectTypePolymorphism getPolymorphism() {
|
||||
return polymorphism;
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 Robert Winkler
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,6 +17,12 @@
|
||||
package io.github.swagger2markup.internal.type;
|
||||
|
||||
public class ObjectTypePolymorphism {
|
||||
|
||||
public enum Nature {
|
||||
NONE,
|
||||
COMPOSITION,
|
||||
INHERITANCE
|
||||
}
|
||||
|
||||
public Nature nature = Nature.NONE;
|
||||
public String discriminator;
|
||||
@@ -42,10 +48,4 @@ public class ObjectTypePolymorphism {
|
||||
this.discriminator = discriminator;
|
||||
}
|
||||
|
||||
public enum Nature {
|
||||
NONE,
|
||||
COMPOSITION,
|
||||
INHERITANCE
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 Robert Winkler
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 Robert Winkler
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -24,7 +24,7 @@ import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
public abstract class Type {
|
||||
|
||||
protected String name;
|
||||
private String uniqueName;
|
||||
protected String uniqueName;
|
||||
|
||||
public Type(String name, String uniqueName) {
|
||||
this.name = name;
|
||||
@@ -35,14 +35,14 @@ public abstract class Type {
|
||||
this(name, name);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getUniqueName() {
|
||||
return uniqueName;
|
||||
}
|
||||
@@ -0,0 +1,314 @@
|
||||
/*
|
||||
* Copyright 2016 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.utils;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import io.github.swagger2markup.model.PathOperation;
|
||||
import io.swagger.models.*;
|
||||
import io.swagger.models.parameters.*;
|
||||
import io.swagger.models.properties.ArrayProperty;
|
||||
import io.swagger.models.properties.MapProperty;
|
||||
import io.swagger.models.properties.Property;
|
||||
import io.swagger.models.properties.RefProperty;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ExamplesUtil {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(ExamplesUtil.class);
|
||||
|
||||
/**
|
||||
* Generates a map of response examples from the given {@code operation}
|
||||
*
|
||||
* @param generateMissingExamples specifies the missing examples should be generated
|
||||
* @param operation the Swagger Operation
|
||||
* @param definitions the map of all available definitions
|
||||
* @param markupDocBuilder the markup builder
|
||||
* @return map containing response examples.
|
||||
*/
|
||||
public static Map<String, Object> generateResponseExampleMap(boolean generateMissingExamples, Operation operation, Map<String, Model> definitions, MarkupDocBuilder markupDocBuilder) {
|
||||
Map<String, Object> examples = new LinkedHashMap<>();
|
||||
Map<String, Response> responses = operation.getResponses();
|
||||
if (responses != null)
|
||||
for (Map.Entry<String, Response> responseEntry : responses.entrySet()) {
|
||||
Response response = responseEntry.getValue();
|
||||
Object example = response.getExamples();
|
||||
if (example == null) {
|
||||
Property schema = response.getSchema();
|
||||
if (schema != null) {
|
||||
example = schema.getExample();
|
||||
|
||||
if (example == null && schema instanceof RefProperty) {
|
||||
String simpleRef = ((RefProperty) schema).getSimpleRef();
|
||||
example = generateExampleForRefModel(generateMissingExamples, simpleRef, definitions, markupDocBuilder);
|
||||
}
|
||||
if (example == null && generateMissingExamples) {
|
||||
example = PropertyUtils.generateExample(schema, markupDocBuilder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (example != null)
|
||||
examples.put(responseEntry.getKey(), example);
|
||||
|
||||
}
|
||||
|
||||
return examples;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a map of request examples from the given {@code operation}
|
||||
*
|
||||
* @param generateMissingExamples specifies the missing examples should be generated
|
||||
* @param pathOperation the Swagger Operation
|
||||
* @param definitions the map of all available definitions
|
||||
* @param markupDocBuilder the markup builder
|
||||
* @return map containing request examples
|
||||
*/
|
||||
public static Map<String, Object> generateRequestExampleMap(boolean generateMissingExamples, PathOperation pathOperation, Map<String, Model> definitions, MarkupDocBuilder markupDocBuilder) {
|
||||
Operation operation = pathOperation.getOperation();
|
||||
List<Parameter> parameters = operation.getParameters();
|
||||
Map<String, Object> examples = new LinkedHashMap<>();
|
||||
|
||||
// Path example should always be included (if generateMissingExamples):
|
||||
if (generateMissingExamples)
|
||||
examples.put("path", pathOperation.getPath());
|
||||
for (Parameter parameter : parameters) {
|
||||
Object example = null;
|
||||
if (parameter instanceof BodyParameter) {
|
||||
example = ((BodyParameter) parameter).getExamples();
|
||||
if (example == null) {
|
||||
Model schema = ((BodyParameter) parameter).getSchema();
|
||||
if (schema instanceof RefModel) {
|
||||
String simpleRef = ((RefModel) schema).getSimpleRef();
|
||||
example = generateExampleForRefModel(generateMissingExamples, simpleRef, definitions, markupDocBuilder);
|
||||
} else if (generateMissingExamples) {
|
||||
if (schema instanceof ComposedModel) {
|
||||
example = exampleMapForProperties(getPropertiesForComposedModel(
|
||||
(ComposedModel) schema, definitions), definitions, markupDocBuilder);
|
||||
} else if (schema instanceof ArrayModel) {
|
||||
example = generateExampleForArrayModel((ArrayModel) schema, definitions, markupDocBuilder);
|
||||
} else {
|
||||
example = schema.getExample();
|
||||
if (example == null) {
|
||||
example = exampleMapForProperties(schema.getProperties(), definitions, markupDocBuilder);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (parameter instanceof AbstractSerializableParameter) {
|
||||
if (generateMissingExamples) {
|
||||
Object abstractSerializableParameterExample;
|
||||
abstractSerializableParameterExample = ((AbstractSerializableParameter) parameter).getExample();
|
||||
if (abstractSerializableParameterExample == null) {
|
||||
Property item = ((AbstractSerializableParameter) parameter).getItems();
|
||||
if (item != null) {
|
||||
abstractSerializableParameterExample = item.getExample();
|
||||
if (abstractSerializableParameterExample == null) {
|
||||
abstractSerializableParameterExample = PropertyUtils.generateExample(item, markupDocBuilder);
|
||||
}
|
||||
}
|
||||
if (abstractSerializableParameterExample == null) {
|
||||
abstractSerializableParameterExample = ParameterUtils.generateExample((AbstractSerializableParameter)parameter);
|
||||
}
|
||||
}
|
||||
if (parameter instanceof PathParameter) {
|
||||
String pathExample = (String) examples.get("path");
|
||||
pathExample = pathExample.replace('{' + parameter.getName() + '}', String.valueOf(abstractSerializableParameterExample));
|
||||
example = pathExample;
|
||||
} else {
|
||||
example = abstractSerializableParameterExample;
|
||||
}
|
||||
if (parameter instanceof QueryParameter) {
|
||||
//noinspection unchecked
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> queryExampleMap = (Map<String, Object>) examples.get("query");
|
||||
if (queryExampleMap == null) {
|
||||
queryExampleMap = new LinkedHashMap<>();
|
||||
}
|
||||
queryExampleMap.put(parameter.getName(), abstractSerializableParameterExample);
|
||||
example = queryExampleMap;
|
||||
}
|
||||
}
|
||||
} else if (parameter instanceof RefParameter) {
|
||||
String simpleRef = ((RefParameter) parameter).getSimpleRef();
|
||||
example = generateExampleForRefModel(generateMissingExamples, simpleRef, definitions, markupDocBuilder);
|
||||
}
|
||||
|
||||
if (example != null)
|
||||
examples.put(parameter.getIn(), example);
|
||||
}
|
||||
|
||||
return examples;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates an example object from a simple reference
|
||||
*
|
||||
* @param generateMissingExamples specifies the missing examples should be generated
|
||||
* @param simpleRef the simple reference string
|
||||
* @param definitions the map of definitions
|
||||
* @param markupDocBuilder the markup builder
|
||||
* @return returns an Object or Map of examples
|
||||
*/
|
||||
public static Object generateExampleForRefModel(boolean generateMissingExamples, String simpleRef, Map<String, Model> definitions, MarkupDocBuilder markupDocBuilder) {
|
||||
Model model = definitions.get(simpleRef);
|
||||
Object example = null;
|
||||
if (model != null) {
|
||||
example = model.getExample();
|
||||
// Workaround for https://github.com/swagger-api/swagger-parser/issues/255 returning a string
|
||||
if (model instanceof ArrayModel && example instanceof String) {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
try {
|
||||
example = mapper.readTree((String) example);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
if (example == null && generateMissingExamples) {
|
||||
if (model instanceof ComposedModel) {
|
||||
example = exampleMapForProperties(getPropertiesForComposedModel((ComposedModel) model, definitions), definitions, markupDocBuilder);
|
||||
} else {
|
||||
example = exampleMapForProperties(model.getProperties(), definitions, markupDocBuilder);
|
||||
}
|
||||
}
|
||||
}
|
||||
return example;
|
||||
}
|
||||
|
||||
private static Map<String, Property> getPropertiesForComposedModel(ComposedModel model, Map<String, Model> definitions) {
|
||||
Map<String, Property> combinedProperties;
|
||||
if (model.getParent() instanceof RefModel) {
|
||||
Map<String, Property> parentProperties = definitions.get(((RefModel) model.getParent()).getSimpleRef()).getProperties();
|
||||
if (parentProperties == null) {
|
||||
return null;
|
||||
} else {
|
||||
combinedProperties = new LinkedHashMap<>(parentProperties);
|
||||
}
|
||||
|
||||
} else {
|
||||
combinedProperties = new LinkedHashMap<>(model.getParent().getProperties());
|
||||
}
|
||||
Map<String, Property> childProperties;
|
||||
if (model.getChild() instanceof RefModel) {
|
||||
childProperties = definitions.get(((RefModel) model.getChild()).getSimpleRef()).getProperties();
|
||||
} else {
|
||||
childProperties = model.getChild().getProperties();
|
||||
}
|
||||
if (childProperties != null) {
|
||||
combinedProperties.putAll(childProperties);
|
||||
}
|
||||
return combinedProperties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a map of examples from a map of properties. If defined examples are found, those are used. Otherwise,
|
||||
* examples are generated from the type.
|
||||
*
|
||||
* @param properties the map of properties
|
||||
* @param definitions the map of definitions
|
||||
* @param markupDocBuilder the markup builder
|
||||
*
|
||||
* @return a Map of examples
|
||||
*/
|
||||
public static Map<String, Object> exampleMapForProperties(Map<String, Property> properties, Map<String, Model> definitions, MarkupDocBuilder markupDocBuilder) {
|
||||
Map<String, Object> exampleMap = new LinkedHashMap<>();
|
||||
if (properties != null) {
|
||||
for (Map.Entry<String, Property> property : properties.entrySet()) {
|
||||
Object exampleObject = property.getValue().getExample();
|
||||
if (exampleObject == null) {
|
||||
if (property.getValue() instanceof RefProperty) {
|
||||
exampleObject = generateExampleForRefModel(true, ((RefProperty) property.getValue()).getSimpleRef(), definitions, markupDocBuilder);
|
||||
} else if (property.getValue() instanceof ArrayProperty) {
|
||||
exampleObject = generateExampleForArrayProperty((ArrayProperty) property.getValue(), definitions, markupDocBuilder);
|
||||
} else if (property.getValue() instanceof MapProperty) {
|
||||
exampleObject = generateExampleForMapProperty((MapProperty) property.getValue(), markupDocBuilder);
|
||||
}
|
||||
if (exampleObject == null) {
|
||||
Property valueProperty = property.getValue();
|
||||
exampleObject = PropertyUtils.generateExample(valueProperty, markupDocBuilder);
|
||||
}
|
||||
}
|
||||
exampleMap.put(property.getKey(), exampleObject);
|
||||
}
|
||||
}
|
||||
return exampleMap;
|
||||
}
|
||||
|
||||
public static Object generateExampleForMapProperty(MapProperty property, MarkupDocBuilder markupDocBuilder) {
|
||||
if (property.getExample() != null) {
|
||||
return property.getExample();
|
||||
}
|
||||
Map<String, Object> exampleMap = new LinkedHashMap<>();
|
||||
Property valueProperty = property.getAdditionalProperties();
|
||||
if (valueProperty.getExample() != null) {
|
||||
return valueProperty.getExample();
|
||||
}
|
||||
exampleMap.put("string", PropertyUtils.generateExample(valueProperty, markupDocBuilder));
|
||||
return exampleMap;
|
||||
}
|
||||
|
||||
public static Object generateExampleForArrayModel(ArrayModel model, Map<String, Model> definitions, MarkupDocBuilder markupDocBuilder) {
|
||||
if (model.getExample() != null) {
|
||||
return model.getExample();
|
||||
} else if (model.getProperties() != null) {
|
||||
return new Object[]{exampleMapForProperties(model.getProperties(), definitions, markupDocBuilder)};
|
||||
} else {
|
||||
Property itemProperty = model.getItems();
|
||||
if (itemProperty.getExample() != null) {
|
||||
return new Object[]{itemProperty.getExample()};
|
||||
} else if (itemProperty instanceof ArrayProperty) {
|
||||
return new Object[]{generateExampleForArrayProperty((ArrayProperty) itemProperty, definitions, markupDocBuilder)};
|
||||
} else if (itemProperty instanceof RefProperty) {
|
||||
return new Object[]{generateExampleForRefModel(true, ((RefProperty) itemProperty).getSimpleRef(), definitions, markupDocBuilder)};
|
||||
} else {
|
||||
return new Object[]{PropertyUtils.generateExample(itemProperty, markupDocBuilder)};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates examples from an ArrayProperty
|
||||
*
|
||||
* @param value ArrayProperty
|
||||
* @param definitions map of definitions
|
||||
* @param markupDocBuilder the markup builder
|
||||
* @return array of Object
|
||||
*/
|
||||
public static Object[] generateExampleForArrayProperty(ArrayProperty value, Map<String, Model> definitions, MarkupDocBuilder markupDocBuilder) {
|
||||
Property property = value.getItems();
|
||||
if (property.getExample() != null) {
|
||||
return new Object[]{property.getExample()};
|
||||
} else if (property instanceof ArrayProperty) {
|
||||
return new Object[]{generateExampleForArrayProperty((ArrayProperty) property, definitions, markupDocBuilder)};
|
||||
} else if (property instanceof RefProperty) {
|
||||
return new Object[]{generateExampleForRefModel(true, ((RefProperty) property).getSimpleRef(), definitions, markupDocBuilder)};
|
||||
} else {
|
||||
return new Object[]{PropertyUtils.generateExample(property, markupDocBuilder)};
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 Robert Winkler
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,25 +13,28 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.github.swagger2markup;
|
||||
package io.github.swagger2markup.internal.utils;
|
||||
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.*;
|
||||
|
||||
public class Labels {
|
||||
|
||||
private ResourceBundle resourceBundle;
|
||||
|
||||
public Labels(ResourceBundle resourceBundle) {
|
||||
this.resourceBundle = resourceBundle;
|
||||
}
|
||||
public class ListUtils {
|
||||
|
||||
/**
|
||||
* Gets a label for the given key from this resource bundle.
|
||||
* Returns the List as an Set either ordered or as-is, if the comparator is null.
|
||||
*
|
||||
* @param key the key for the desired label
|
||||
* @return the label for the given key
|
||||
* @param list the List
|
||||
* @param comparator the comparator to use.
|
||||
* @return the Set
|
||||
*/
|
||||
public String getLabel(String key) {
|
||||
return resourceBundle.getString(key);
|
||||
public static Set<String> toSet(List<String> list, Comparator<String> comparator){
|
||||
Set<String> set;
|
||||
if (comparator == null)
|
||||
set = new LinkedHashSet<>();
|
||||
else
|
||||
set = new TreeSet<>(comparator);
|
||||
set.addAll(list);
|
||||
return set;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 Robert Winkler
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,29 +15,24 @@
|
||||
*/
|
||||
package io.github.swagger2markup.internal.utils;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import java.util.*;
|
||||
|
||||
public class MapUtils {
|
||||
|
||||
/**
|
||||
* Returns the the Map either ordered or as-is, if the comparator is null.
|
||||
* Returns the keys of the Map either ordered or as-is, if the comparator is null.
|
||||
*
|
||||
* @param <K> the type of keys maintained by the map parameter
|
||||
* @param <V> the type of mapped values
|
||||
* @param map the Map
|
||||
* @param map the Map
|
||||
* @param comparator the comparator to use.
|
||||
* @return the keySet of the Map
|
||||
*/
|
||||
public static <K, V> Map<K, V> toSortedMap(Map<K, V> map, Comparator<? super K> comparator) {
|
||||
Map<K, V> sortedMap;
|
||||
public static Set<String> toKeySet(Map<String, ?> map, Comparator<String> comparator){
|
||||
Set<String> keys;
|
||||
if (comparator == null)
|
||||
sortedMap = new LinkedHashMap<>();
|
||||
keys = new LinkedHashSet<>();
|
||||
else
|
||||
sortedMap = new TreeMap<>(comparator);
|
||||
sortedMap.putAll(map);
|
||||
return sortedMap;
|
||||
keys = new TreeSet<>(comparator);
|
||||
keys.addAll(map.keySet());
|
||||
return keys;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 Robert Winkler
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,25 +15,22 @@
|
||||
*/
|
||||
package io.github.swagger2markup.internal.utils;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import io.github.swagger2markup.internal.adapter.PropertyAdapter;
|
||||
import io.github.swagger2markup.internal.resolver.DocumentResolver;
|
||||
import io.github.swagger2markup.internal.type.*;
|
||||
import io.swagger.models.*;
|
||||
import io.swagger.models.properties.Property;
|
||||
import io.swagger.models.refs.RefFormat;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
|
||||
public final class ModelUtils {
|
||||
|
||||
/**
|
||||
* Recursively resolve referenced type if {@code type} is of type RefType
|
||||
*
|
||||
* @param type type to resolve
|
||||
* @return referenced type
|
||||
*/
|
||||
@@ -50,18 +47,17 @@ public final class ModelUtils {
|
||||
/**
|
||||
* Retrieves the type of a model, or otherwise null
|
||||
*
|
||||
* @param definitions a map of RefModel name keys to models
|
||||
* @param model the model
|
||||
* @param definitionDocumentResolver the definition document resolver
|
||||
* @return the type of the model, or otherwise null
|
||||
*/
|
||||
public static Type getType(Model model, Map<String, Model> definitions, DocumentResolver definitionDocumentResolver) {
|
||||
public static Type getType(Model model, Map<String, Model> definitions, Function<String, String> definitionDocumentResolver) {
|
||||
Validate.notNull(model, "model must not be null!");
|
||||
if (model instanceof ModelImpl) {
|
||||
ModelImpl modelImpl = (ModelImpl) model;
|
||||
|
||||
if (modelImpl.getAdditionalProperties() != null)
|
||||
return new MapType(modelImpl.getTitle(), new PropertyAdapter(modelImpl.getAdditionalProperties()).getType(definitionDocumentResolver));
|
||||
return new MapType(modelImpl.getTitle(), PropertyUtils.getType(modelImpl.getAdditionalProperties(), definitionDocumentResolver));
|
||||
else if (modelImpl.getEnum() != null)
|
||||
return new EnumType(modelImpl.getTitle(), modelImpl.getEnum());
|
||||
else if (modelImpl.getProperties() != null) {
|
||||
@@ -70,11 +66,7 @@ public final class ModelUtils {
|
||||
objectType.getPolymorphism().setDiscriminator(modelImpl.getDiscriminator());
|
||||
|
||||
return objectType;
|
||||
} else if (modelImpl.getType() == null)
|
||||
return null;
|
||||
else if (isNotBlank(modelImpl.getFormat()))
|
||||
return new BasicType(modelImpl.getType(), modelImpl.getTitle(), modelImpl.getFormat());
|
||||
else
|
||||
} else
|
||||
return new BasicType(modelImpl.getType(), modelImpl.getTitle());
|
||||
} else if (model instanceof ComposedModel) {
|
||||
ComposedModel composedModel = (ComposedModel) model;
|
||||
@@ -87,10 +79,7 @@ public final class ModelUtils {
|
||||
|
||||
for (Model innerModel : composedModel.getAllOf()) {
|
||||
Type innerModelType = resolveRefType(getType(innerModel, definitions, definitionDocumentResolver));
|
||||
|
||||
if (innerModelType != null) {
|
||||
name = innerModelType.getName();
|
||||
}
|
||||
name = innerModelType.getName();
|
||||
|
||||
if (innerModelType instanceof ObjectType) {
|
||||
|
||||
@@ -106,7 +95,7 @@ public final class ModelUtils {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return new ObjectType(name, polymorphism, allProperties);
|
||||
} else if (model instanceof RefModel) {
|
||||
RefModel refModel = (RefModel) model;
|
||||
@@ -123,7 +112,7 @@ public final class ModelUtils {
|
||||
} else if (model instanceof ArrayModel) {
|
||||
ArrayModel arrayModel = ((ArrayModel) model);
|
||||
|
||||
return new ArrayType(null, new PropertyAdapter(arrayModel.getItems()).getType(definitionDocumentResolver));
|
||||
return new ArrayType(null, PropertyUtils.getType(arrayModel.getItems(), definitionDocumentResolver));
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* Copyright 2016 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.utils;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import io.github.swagger2markup.internal.type.*;
|
||||
import io.swagger.models.Model;
|
||||
import io.swagger.models.parameters.AbstractSerializableParameter;
|
||||
import io.swagger.models.parameters.BodyParameter;
|
||||
import io.swagger.models.parameters.Parameter;
|
||||
import io.swagger.models.parameters.RefParameter;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public final class ParameterUtils {
|
||||
|
||||
/**
|
||||
* Retrieves the type of a parameter, or otherwise null
|
||||
*
|
||||
* @param parameter the parameter
|
||||
* @param definitionDocumentResolver the defintion document resolver
|
||||
* @return the type of the parameter, or otherwise null
|
||||
*/
|
||||
public static Type getType(Parameter parameter, Map<String, Model> definitions, Function<String, String> definitionDocumentResolver){
|
||||
Validate.notNull(parameter, "parameter must not be null!");
|
||||
Type type = null;
|
||||
|
||||
if(parameter instanceof BodyParameter){
|
||||
BodyParameter bodyParameter = (BodyParameter)parameter;
|
||||
Model model = bodyParameter.getSchema();
|
||||
|
||||
if(model != null){
|
||||
type = ModelUtils.getType(model, definitions, definitionDocumentResolver);
|
||||
}else{
|
||||
type = new BasicType("string", null);
|
||||
}
|
||||
|
||||
}
|
||||
else if(parameter instanceof AbstractSerializableParameter){
|
||||
AbstractSerializableParameter serializableParameter = (AbstractSerializableParameter)parameter;
|
||||
@SuppressWarnings("unchecked")
|
||||
List<String> enums = serializableParameter.getEnum();
|
||||
|
||||
if(CollectionUtils.isNotEmpty(enums)){
|
||||
type = new EnumType(null, enums);
|
||||
}else{
|
||||
type = new BasicType(serializableParameter.getType(), null, serializableParameter.getFormat());
|
||||
}
|
||||
if(serializableParameter.getType().equals("array")){
|
||||
String collectionFormat = serializableParameter.getCollectionFormat();
|
||||
|
||||
type = new ArrayType(null, PropertyUtils.getType(serializableParameter.getItems(), definitionDocumentResolver), collectionFormat);
|
||||
}
|
||||
}
|
||||
else if(parameter instanceof RefParameter){
|
||||
String refName = ((RefParameter)parameter).getSimpleRef();
|
||||
|
||||
type = new RefType(definitionDocumentResolver.apply(refName), new ObjectType(refName, null /* FIXME, not used for now */));
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the default value of a parameter, or otherwise returns null
|
||||
*
|
||||
* @param parameter the parameter
|
||||
* @return the default value of the parameter, or otherwise null
|
||||
*/
|
||||
public static Object getDefaultValue(Parameter parameter){
|
||||
Validate.notNull(parameter, "parameter must not be null!");
|
||||
Object defaultValue = null;
|
||||
|
||||
if(parameter instanceof AbstractSerializableParameter){
|
||||
AbstractSerializableParameter serializableParameter = (AbstractSerializableParameter)parameter;
|
||||
defaultValue = serializableParameter.getDefaultValue();
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a default example value for parameter.
|
||||
*
|
||||
* @param parameter parameter
|
||||
* @return a generated example for the parameter
|
||||
*/
|
||||
public static Object generateExample(AbstractSerializableParameter parameter) {
|
||||
switch (parameter.getType()) {
|
||||
case "integer":
|
||||
return 0;
|
||||
case "number":
|
||||
return 0.0;
|
||||
case "boolean":
|
||||
return true;
|
||||
case "string":
|
||||
return "string";
|
||||
default:
|
||||
return parameter.getType();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,210 @@
|
||||
/*
|
||||
* Copyright 2016 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.utils;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import io.github.swagger2markup.internal.type.*;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import io.swagger.models.properties.*;
|
||||
import io.swagger.models.refs.RefFormat;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
|
||||
public final class PropertyUtils {
|
||||
|
||||
/**
|
||||
* Retrieves the type and format of a property.
|
||||
*
|
||||
* @param property the property
|
||||
* @param definitionDocumentResolver the definition document resolver
|
||||
* @return the type of the property
|
||||
*/
|
||||
public static Type getType(Property property, Function<String, String> definitionDocumentResolver) {
|
||||
Validate.notNull(property, "property must not be null");
|
||||
Type type;
|
||||
if (property instanceof RefProperty) {
|
||||
RefProperty refProperty = (RefProperty) property;
|
||||
if (refProperty.getRefFormat() == RefFormat.RELATIVE)
|
||||
type = new ObjectType(refProperty.getTitle(), null); // FIXME : Workaround for https://github.com/swagger-api/swagger-parser/issues/177
|
||||
else
|
||||
type = new RefType(definitionDocumentResolver.apply(refProperty.getSimpleRef()), new ObjectType(refProperty.getSimpleRef(), null /* FIXME, not used for now */));
|
||||
} else if (property instanceof ArrayProperty) {
|
||||
ArrayProperty arrayProperty = (ArrayProperty) property;
|
||||
Property items = arrayProperty.getItems();
|
||||
if (items == null)
|
||||
type = new ArrayType(arrayProperty.getTitle(), new ObjectType(null, null)); // FIXME : Workaround for Swagger parser issue with composed models (https://github.com/Swagger2Markup/swagger2markup/issues/150)
|
||||
else
|
||||
type = new ArrayType(arrayProperty.getTitle(), getType(items, definitionDocumentResolver));
|
||||
} else if (property instanceof MapProperty) {
|
||||
MapProperty mapProperty = (MapProperty) property;
|
||||
Property additionalProperties = mapProperty.getAdditionalProperties();
|
||||
if (additionalProperties == null)
|
||||
type = new MapType(mapProperty.getTitle(), new ObjectType(null, null)); // FIXME : Workaround for Swagger parser issue with composed models (https://github.com/Swagger2Markup/swagger2markup/issues/150)
|
||||
else
|
||||
type = new MapType(mapProperty.getTitle(), getType(additionalProperties, definitionDocumentResolver));
|
||||
} else if (property instanceof StringProperty) {
|
||||
StringProperty stringProperty = (StringProperty) property;
|
||||
List<String> enums = stringProperty.getEnum();
|
||||
if (CollectionUtils.isNotEmpty(enums)) {
|
||||
type = new EnumType(stringProperty.getTitle(), enums);
|
||||
} else {
|
||||
type = new BasicType(stringProperty.getType(), stringProperty.getTitle());
|
||||
}
|
||||
} else if (property instanceof ObjectProperty) {
|
||||
type = new ObjectType(property.getTitle(), ((ObjectProperty) property).getProperties());
|
||||
} else {
|
||||
if (isNotBlank(property.getFormat())) {
|
||||
type = new BasicType(property.getType(), property.getTitle(), property.getFormat());
|
||||
} else {
|
||||
type = new BasicType(property.getType(), property.getTitle());
|
||||
}
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the default value of a property, or otherwise returns null.
|
||||
*
|
||||
* @param property the property
|
||||
* @return the default value of the property, or otherwise null
|
||||
*/
|
||||
public static Object getDefaultValue(Property property) {
|
||||
Validate.notNull(property, "property must not be null");
|
||||
Object defaultValue = null;
|
||||
if (property instanceof BooleanProperty) {
|
||||
BooleanProperty booleanProperty = (BooleanProperty) property;
|
||||
defaultValue = booleanProperty.getDefault();
|
||||
} else if (property instanceof StringProperty) {
|
||||
StringProperty stringProperty = (StringProperty) property;
|
||||
defaultValue = stringProperty.getDefault();
|
||||
} else if (property instanceof DoubleProperty) {
|
||||
DoubleProperty doubleProperty = (DoubleProperty) property;
|
||||
defaultValue = doubleProperty.getDefault();
|
||||
} else if (property instanceof FloatProperty) {
|
||||
FloatProperty floatProperty = (FloatProperty) property;
|
||||
defaultValue = floatProperty.getDefault();
|
||||
} else if (property instanceof IntegerProperty) {
|
||||
IntegerProperty integerProperty = (IntegerProperty) property;
|
||||
defaultValue = integerProperty.getDefault();
|
||||
} else if (property instanceof LongProperty) {
|
||||
LongProperty longProperty = (LongProperty) property;
|
||||
defaultValue = longProperty.getDefault();
|
||||
} else if (property instanceof UUIDProperty) {
|
||||
UUIDProperty uuidProperty = (UUIDProperty) property;
|
||||
defaultValue = uuidProperty.getDefault();
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return example display string for the given {@code property}.
|
||||
*
|
||||
* @param generateMissingExamples specifies if missing examples should be generated
|
||||
* @param property property
|
||||
* @param markupDocBuilder doc builder
|
||||
* @return property example display string
|
||||
*/
|
||||
public static Object getExample(boolean generateMissingExamples, Property property, MarkupDocBuilder markupDocBuilder) {
|
||||
Validate.notNull(property, "property must not be null");
|
||||
Object examplesValue = null;
|
||||
if (property.getExample() != null) {
|
||||
examplesValue = property.getExample();
|
||||
} else if (property instanceof MapProperty) {
|
||||
Property additionalProperty = ((MapProperty) property).getAdditionalProperties();
|
||||
if (additionalProperty.getExample() != null) {
|
||||
examplesValue = additionalProperty.getExample();
|
||||
} else if (generateMissingExamples) {
|
||||
Map<String, Object> exampleMap = new HashMap<>();
|
||||
exampleMap.put("string", generateExample(additionalProperty, markupDocBuilder));
|
||||
examplesValue = exampleMap;
|
||||
}
|
||||
} else if (property instanceof ArrayProperty) {
|
||||
if (generateMissingExamples) {
|
||||
Property itemProperty = ((ArrayProperty) property).getItems();
|
||||
List<Object> exampleArray = new ArrayList<>();
|
||||
exampleArray.add(generateExample(itemProperty, markupDocBuilder));
|
||||
examplesValue = exampleArray;
|
||||
}
|
||||
} else if (generateMissingExamples) {
|
||||
examplesValue = generateExample(property, markupDocBuilder);
|
||||
}
|
||||
|
||||
return examplesValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a default example value for property.
|
||||
*
|
||||
* @param property property
|
||||
* @param markupDocBuilder doc builder
|
||||
* @return a generated example for the property
|
||||
*/
|
||||
public static Object generateExample(Property property, MarkupDocBuilder markupDocBuilder) {
|
||||
switch (property.getType()) {
|
||||
case "integer":
|
||||
return 0;
|
||||
case "number":
|
||||
return 0.0;
|
||||
case "boolean":
|
||||
return true;
|
||||
case "string":
|
||||
return "string";
|
||||
case "ref":
|
||||
if (property instanceof RefProperty) {
|
||||
return markupDocBuilder.copy(false).crossReference(((RefProperty) property).getSimpleRef()).toString();
|
||||
}
|
||||
default:
|
||||
return property.getType();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a string {@code value} to specified {@code type}.
|
||||
*
|
||||
* @param value value to convert
|
||||
* @param type target conversion type
|
||||
* @return converted value as object
|
||||
*/
|
||||
public static Object convertExample(String value, String type) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
switch (type) {
|
||||
case "integer":
|
||||
return Integer.valueOf(value);
|
||||
case "number":
|
||||
return Float.valueOf(value);
|
||||
case "boolean":
|
||||
return Boolean.valueOf(value);
|
||||
case "string":
|
||||
return value;
|
||||
default:
|
||||
return value;
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
throw new RuntimeException(String.format("Value '%s' cannot be converted to '%s'", value, type), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* Copyright 2016 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.utils;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.MultimapBuilder;
|
||||
import com.google.common.collect.Ordering;
|
||||
import io.github.swagger2markup.model.PathOperation;
|
||||
import io.swagger.models.Tag;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class TagUtils {
|
||||
|
||||
private static Logger LOG = LoggerFactory.getLogger(TagUtils.class);
|
||||
|
||||
/**
|
||||
* Converts the global Tag list into a Map where the tag name is the key and the Tag the value.
|
||||
*
|
||||
* @param tags the List of tags
|
||||
* @return the Map of tags
|
||||
*/
|
||||
public static Map<String, Tag> convertTagsListToMap(List<Tag> tags) {
|
||||
if (tags == null) {
|
||||
tags = new ArrayList<>();
|
||||
}
|
||||
Map<String, Tag> tagsMap = new HashMap<>();
|
||||
for (Tag tag : tags) tagsMap.put(tag.getName(), tag);
|
||||
return tagsMap;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the optional description of a tag.
|
||||
*
|
||||
* @param tagsMap the Map of tags
|
||||
* @param tagName the name of the tag
|
||||
* @return the optional description of the tag
|
||||
*/
|
||||
public static Optional<String> getTagDescription(Map<String, Tag> tagsMap, String tagName) {
|
||||
Tag tag = tagsMap.get(tagName);
|
||||
if(tag != null){
|
||||
return Optional.fromNullable(tag.getDescription());
|
||||
}
|
||||
return Optional.absent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Groups the operations by tag. The key of the Multimap is the tag name.
|
||||
* The value of the Multimap is a PathOperation
|
||||
*
|
||||
* @param allOperations all operations
|
||||
* @param tagOrdering comparator for tags
|
||||
* @param operationOrdering comparator for operations, for a given tag
|
||||
* @return Operations grouped by Tag
|
||||
*/
|
||||
public static Multimap<String, PathOperation> groupOperationsByTag(Set<PathOperation> allOperations, Comparator<String> tagOrdering, Comparator<PathOperation> operationOrdering) {
|
||||
MultimapBuilder.MultimapBuilderWithKeys<String> multimapBuilderWithKeys;
|
||||
|
||||
if (tagOrdering == null)
|
||||
multimapBuilderWithKeys = MultimapBuilder.SortedSetMultimapBuilder.treeKeys(Ordering.<String>natural()); // FIXME as-is sorting not supported because of limitations in MultiMap::hashkeys(). Replaced with Ordering.natural()
|
||||
else
|
||||
multimapBuilderWithKeys = MultimapBuilder.SortedSetMultimapBuilder.treeKeys(tagOrdering);
|
||||
|
||||
Multimap<String, PathOperation> operationsGroupedByTag;
|
||||
if (operationOrdering == null)
|
||||
operationsGroupedByTag = multimapBuilderWithKeys.hashSetValues().build();
|
||||
else
|
||||
operationsGroupedByTag = multimapBuilderWithKeys.treeSetValues(operationOrdering).build();
|
||||
|
||||
for (PathOperation operation : allOperations) {
|
||||
List<String> tags = operation.getOperation().getTags();
|
||||
Validate.notEmpty(tags, "Can't GroupBy.TAGS > Operation '%s' has not tags", operation);
|
||||
for (String tag : tags) {
|
||||
if (LOG.isInfoEnabled()) {
|
||||
LOG.info("Added path operation '{}' to tag '{}'", operation, tag);
|
||||
}
|
||||
operationsGroupedByTag.put(tag, operation);
|
||||
}
|
||||
}
|
||||
|
||||
return operationsGroupedByTag;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright 2016 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.model;
|
||||
|
||||
import io.swagger.models.HttpMethod;
|
||||
import io.swagger.models.Operation;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.isBlank;
|
||||
|
||||
public class PathOperation {
|
||||
|
||||
protected HttpMethod method;
|
||||
protected String path;
|
||||
protected Operation operation;
|
||||
|
||||
public PathOperation(HttpMethod method, String path, Operation operation) {
|
||||
this.method = method;
|
||||
this.path = path;
|
||||
this.operation = operation;
|
||||
}
|
||||
|
||||
public HttpMethod getMethod() {
|
||||
return method;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the display title for an operation
|
||||
* @return the operation title
|
||||
*/
|
||||
public String getTitle() {
|
||||
String operationName = operation.getSummary();
|
||||
if (isBlank(operationName)) {
|
||||
operationName = getMethod().toString() + " " + getPath();
|
||||
}
|
||||
return operationName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an unique id for the operation.<br>
|
||||
* Use {@code <operation id>}, then {@code <operation path> lowercase(<operation method>)} if operation id is not set.
|
||||
*
|
||||
* @return operation unique id
|
||||
*/
|
||||
public String getId() {
|
||||
String id = operation.getOperationId();
|
||||
|
||||
if (id == null)
|
||||
id = getPath() + " " + getMethod().toString().toLowerCase();
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
public Operation getOperation() {
|
||||
return operation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getId();
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 Robert Winkler
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,21 +16,21 @@
|
||||
|
||||
package io.github.swagger2markup.spi;
|
||||
|
||||
import static io.github.swagger2markup.Swagger2MarkupConverter.SwaggerContext;
|
||||
import io.github.swagger2markup.Swagger2MarkupConverter;
|
||||
|
||||
/**
|
||||
* An abstract extension which must be extended by an extension
|
||||
*/
|
||||
abstract class AbstractExtension implements Extension {
|
||||
|
||||
public SwaggerContext globalContext;
|
||||
protected Swagger2MarkupConverter.Context globalContext;
|
||||
|
||||
/**
|
||||
* Global context lazy initialization
|
||||
*
|
||||
* @param globalContext Global context
|
||||
*/
|
||||
public void setGlobalContext(SwaggerContext globalContext) {
|
||||
public void setGlobalContext(Swagger2MarkupConverter.Context globalContext) {
|
||||
this.globalContext = globalContext;
|
||||
init(globalContext);
|
||||
}
|
||||
@@ -40,7 +40,8 @@ abstract class AbstractExtension implements Extension {
|
||||
*
|
||||
* @param globalContext Global context
|
||||
*/
|
||||
public void init(SwaggerContext globalContext) {
|
||||
public void init(Swagger2MarkupConverter.Context globalContext) {
|
||||
/* must be left empty */
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 Robert Winkler
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 Robert Winkler
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,51 +16,16 @@
|
||||
|
||||
package io.github.swagger2markup.spi;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import io.swagger.models.Model;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
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);
|
||||
|
||||
/**
|
||||
* Returns title level offset from 1 to apply to content
|
||||
*
|
||||
* @param context context
|
||||
* @return title level offset
|
||||
*/
|
||||
protected int levelOffset(Context context) throws RuntimeException {
|
||||
//TODO: Unused method, make sure this is never used and then remove it.
|
||||
int levelOffset;
|
||||
switch (context.position) {
|
||||
case DOCUMENT_BEFORE:
|
||||
case DOCUMENT_AFTER:
|
||||
levelOffset = 0;
|
||||
break;
|
||||
case DOCUMENT_BEGIN:
|
||||
case DOCUMENT_END:
|
||||
case DEFINITION_BEFORE:
|
||||
case DEFINITION_AFTER:
|
||||
levelOffset = 1;
|
||||
break;
|
||||
case DEFINITION_BEGIN:
|
||||
case DEFINITION_END:
|
||||
levelOffset = 2;
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException(String.format("Unknown position '%s'", context.position));
|
||||
}
|
||||
|
||||
return levelOffset;
|
||||
}
|
||||
|
||||
public enum Position {
|
||||
DOCUMENT_BEFORE,
|
||||
DOCUMENT_BEGIN,
|
||||
@@ -85,7 +50,7 @@ public abstract class DefinitionsDocumentExtension extends AbstractExtension {
|
||||
private Model model;
|
||||
|
||||
/**
|
||||
* @param position the current position
|
||||
* @param position the current position
|
||||
* @param docBuilder the MarkupDocBuilder
|
||||
*/
|
||||
public Context(Position position, MarkupDocBuilder docBuilder) {
|
||||
@@ -95,10 +60,10 @@ public abstract class DefinitionsDocumentExtension extends AbstractExtension {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param position the current position
|
||||
* @param docBuilder the MarkupDocBuilder
|
||||
* @param position the current position
|
||||
* @param docBuilder the MarkupDocBuilder
|
||||
* @param definitionName the name of the current definition
|
||||
* @param model the current Model of the definition
|
||||
* @param model the current Model of the definition
|
||||
*/
|
||||
public Context(Position position, MarkupDocBuilder docBuilder, String definitionName, Model model) {
|
||||
super(docBuilder);
|
||||
@@ -115,11 +80,45 @@ public abstract class DefinitionsDocumentExtension extends AbstractExtension {
|
||||
}
|
||||
|
||||
public Optional<String> getDefinitionName() {
|
||||
return Optional.ofNullable(definitionName);
|
||||
return Optional.fromNullable(definitionName);
|
||||
}
|
||||
|
||||
public Optional<Model> getModel() {
|
||||
return Optional.ofNullable(model);
|
||||
return Optional.fromNullable(model);
|
||||
}
|
||||
}
|
||||
|
||||
public DefinitionsDocumentExtension() {
|
||||
}
|
||||
|
||||
public abstract void apply(Context context);
|
||||
|
||||
/**
|
||||
* Returns title level offset from 1 to apply to content
|
||||
* @param context context
|
||||
* @return title level offset
|
||||
*/
|
||||
protected int levelOffset(Context context) {
|
||||
int levelOffset;
|
||||
switch (context.position) {
|
||||
case DOCUMENT_BEFORE:
|
||||
case DOCUMENT_AFTER:
|
||||
levelOffset = 0;
|
||||
break;
|
||||
case DOCUMENT_BEGIN:
|
||||
case DOCUMENT_END:
|
||||
case DEFINITION_BEFORE:
|
||||
case DEFINITION_AFTER:
|
||||
levelOffset = 1;
|
||||
break;
|
||||
case DEFINITION_BEGIN:
|
||||
case DEFINITION_END:
|
||||
levelOffset = 2;
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException(String.format("Unknown position '%s'", context.position));
|
||||
}
|
||||
|
||||
return levelOffset;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 Robert Winkler
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package io.github.swagger2markup.spi;
|
||||
|
||||
import io.github.swagger2markup.Swagger2MarkupConverter.SwaggerContext;
|
||||
import io.github.swagger2markup.Swagger2MarkupConverter;
|
||||
|
||||
/**
|
||||
* A marker interface which must be implemented by an extension
|
||||
@@ -28,6 +28,6 @@ interface Extension {
|
||||
*
|
||||
* @param globalContext Global context
|
||||
*/
|
||||
void setGlobalContext(SwaggerContext globalContext);
|
||||
void setGlobalContext(Swagger2MarkupConverter.Context globalContext);
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 Robert Winkler
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -23,17 +23,41 @@ import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
*/
|
||||
public abstract class OverviewDocumentExtension extends AbstractExtension {
|
||||
|
||||
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 docBuilder the MarkupDocBuilder
|
||||
*/
|
||||
public Context(Position position, MarkupDocBuilder docBuilder) {
|
||||
super(docBuilder);
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
public Position getPosition() {
|
||||
return position;
|
||||
}
|
||||
}
|
||||
|
||||
public OverviewDocumentExtension() {
|
||||
}
|
||||
|
||||
public abstract void apply(Context context);
|
||||
|
||||
/**
|
||||
* Returns title level offset from 1 to apply to content
|
||||
*
|
||||
* @param context context
|
||||
* @return title level offset
|
||||
*/
|
||||
protected int levelOffset(Context context) {
|
||||
//TODO: Unused method, make sure this is never used and then remove it.
|
||||
int levelOffset;
|
||||
switch (context.position) {
|
||||
case DOCUMENT_BEFORE:
|
||||
@@ -51,28 +75,4 @@ public abstract class OverviewDocumentExtension extends AbstractExtension {
|
||||
return levelOffset;
|
||||
}
|
||||
|
||||
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 docBuilder the MarkupDocBuilder
|
||||
*/
|
||||
public Context(Position position, MarkupDocBuilder docBuilder) {
|
||||
super(docBuilder);
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
public Position getPosition() {
|
||||
return position;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 Robert Winkler
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -27,68 +27,6 @@ import org.apache.commons.lang3.Validate;
|
||||
*/
|
||||
public abstract class PathsDocumentExtension extends AbstractExtension {
|
||||
|
||||
|
||||
public abstract void apply(Context context);
|
||||
|
||||
/**
|
||||
* Returns title level offset from 1 to apply to content
|
||||
*
|
||||
* @param context context
|
||||
* @return title level offset
|
||||
*/
|
||||
protected int levelOffset(Context context) {
|
||||
//TODO: Unused method, make sure this is never used and then remove it.
|
||||
int levelOffset;
|
||||
switch (context.position) {
|
||||
case DOCUMENT_BEFORE:
|
||||
case DOCUMENT_AFTER:
|
||||
levelOffset = 0;
|
||||
break;
|
||||
case DOCUMENT_BEGIN:
|
||||
case DOCUMENT_END:
|
||||
case OPERATION_BEFORE:
|
||||
case OPERATION_AFTER:
|
||||
levelOffset = 1;
|
||||
break;
|
||||
case OPERATION_BEGIN:
|
||||
case OPERATION_END:
|
||||
levelOffset = increaseLevelOffset(2);
|
||||
break;
|
||||
case OPERATION_DESCRIPTION_BEFORE:
|
||||
case OPERATION_DESCRIPTION_AFTER:
|
||||
case OPERATION_PARAMETERS_BEFORE:
|
||||
case OPERATION_PARAMETERS_AFTER:
|
||||
case OPERATION_RESPONSES_BEFORE:
|
||||
case OPERATION_RESPONSES_AFTER:
|
||||
case OPERATION_SECURITY_BEFORE:
|
||||
case OPERATION_SECURITY_AFTER:
|
||||
levelOffset = increaseLevelOffset(2);
|
||||
break;
|
||||
case OPERATION_DESCRIPTION_BEGIN:
|
||||
case OPERATION_DESCRIPTION_END:
|
||||
case OPERATION_PARAMETERS_BEGIN:
|
||||
case OPERATION_PARAMETERS_END:
|
||||
case OPERATION_RESPONSES_BEGIN:
|
||||
case OPERATION_RESPONSES_END:
|
||||
case OPERATION_SECURITY_BEGIN:
|
||||
case OPERATION_SECURITY_END:
|
||||
levelOffset = 3;
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException(String.format("Unknown position '%s'", context.position));
|
||||
}
|
||||
return levelOffset;
|
||||
}
|
||||
|
||||
private int increaseLevelOffset(int levelOffset) {
|
||||
//TODO: This method always receives levelOffset=2. Perhaps the parameter could be removed
|
||||
if (globalContext.getConfig().getPathsGroupedBy() == GroupBy.TAGS) {
|
||||
return ++levelOffset;
|
||||
} else {
|
||||
return levelOffset;
|
||||
}
|
||||
}
|
||||
|
||||
public enum Position {
|
||||
DOCUMENT_BEFORE,
|
||||
DOCUMENT_BEGIN,
|
||||
@@ -137,7 +75,6 @@ public abstract class PathsDocumentExtension extends AbstractExtension {
|
||||
|
||||
/**
|
||||
* Context for all other positions
|
||||
*
|
||||
* @param position the current position
|
||||
* @param docBuilder the MarkupDocBuilder
|
||||
* @param operation the current path operation
|
||||
@@ -158,4 +95,66 @@ public abstract class PathsDocumentExtension extends AbstractExtension {
|
||||
return Optional.fromNullable(operation);
|
||||
}
|
||||
}
|
||||
|
||||
public PathsDocumentExtension() {
|
||||
}
|
||||
|
||||
public abstract void apply(Context context);
|
||||
|
||||
/**
|
||||
* Returns title level offset from 1 to apply to content
|
||||
*
|
||||
* @param context context
|
||||
* @return title level offset
|
||||
*/
|
||||
protected int levelOffset(Context context) {
|
||||
int levelOffset;
|
||||
switch (context.position) {
|
||||
case DOCUMENT_BEFORE:
|
||||
case DOCUMENT_AFTER:
|
||||
levelOffset = 0;
|
||||
break;
|
||||
case DOCUMENT_BEGIN:
|
||||
case DOCUMENT_END:
|
||||
case OPERATION_BEFORE:
|
||||
case OPERATION_AFTER:
|
||||
levelOffset = 1;
|
||||
break;
|
||||
case OPERATION_BEGIN:
|
||||
case OPERATION_END:
|
||||
levelOffset = increaseLevelOffset(2);
|
||||
break;
|
||||
case OPERATION_DESCRIPTION_BEFORE:
|
||||
case OPERATION_DESCRIPTION_AFTER:
|
||||
case OPERATION_PARAMETERS_BEFORE:
|
||||
case OPERATION_PARAMETERS_AFTER:
|
||||
case OPERATION_RESPONSES_BEFORE:
|
||||
case OPERATION_RESPONSES_AFTER:
|
||||
case OPERATION_SECURITY_BEFORE:
|
||||
case OPERATION_SECURITY_AFTER:
|
||||
levelOffset = increaseLevelOffset(2);
|
||||
break;
|
||||
case OPERATION_DESCRIPTION_BEGIN:
|
||||
case OPERATION_DESCRIPTION_END:
|
||||
case OPERATION_PARAMETERS_BEGIN:
|
||||
case OPERATION_PARAMETERS_END:
|
||||
case OPERATION_RESPONSES_BEGIN:
|
||||
case OPERATION_RESPONSES_END:
|
||||
case OPERATION_SECURITY_BEGIN:
|
||||
case OPERATION_SECURITY_END:
|
||||
levelOffset = 3;
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException(String.format("Unknown position '%s'", context.position));
|
||||
}
|
||||
return levelOffset;
|
||||
}
|
||||
|
||||
private int increaseLevelOffset(int levelOffset) {
|
||||
if (globalContext.getConfig().getPathsGroupedBy() == GroupBy.TAGS) {
|
||||
return ++levelOffset;
|
||||
}else {
|
||||
return levelOffset;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 Robert Winkler
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -26,40 +26,6 @@ import org.apache.commons.lang3.Validate;
|
||||
*/
|
||||
public abstract class SecurityDocumentExtension extends AbstractExtension {
|
||||
|
||||
|
||||
public abstract void apply(Context context);
|
||||
|
||||
/**
|
||||
* Returns title level offset from 1 to apply to content
|
||||
*
|
||||
* @param context context
|
||||
* @return title level offset
|
||||
*/
|
||||
protected int levelOffset(Context context) {
|
||||
//TODO: Unused method, make sure this is never used and then remove it.
|
||||
int levelOffset;
|
||||
switch (context.position) {
|
||||
case DOCUMENT_BEFORE:
|
||||
case DOCUMENT_AFTER:
|
||||
levelOffset = 0;
|
||||
break;
|
||||
case DOCUMENT_BEGIN:
|
||||
case DOCUMENT_END:
|
||||
case SECURITY_SCHEME_BEFORE:
|
||||
case SECURITY_SCHEME_AFTER:
|
||||
levelOffset = 1;
|
||||
break;
|
||||
case SECURITY_SCHEME_BEGIN:
|
||||
case SECURITY_SCHEME_END:
|
||||
levelOffset = 2;
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException(String.format("Unknown position '%s'", context.position));
|
||||
}
|
||||
|
||||
return levelOffset;
|
||||
}
|
||||
|
||||
public enum Position {
|
||||
DOCUMENT_BEFORE,
|
||||
DOCUMENT_BEGIN,
|
||||
@@ -83,7 +49,7 @@ public abstract class SecurityDocumentExtension extends AbstractExtension {
|
||||
private SecuritySchemeDefinition securityScheme;
|
||||
|
||||
/**
|
||||
* @param position the current position
|
||||
* @param position the current position
|
||||
* @param docBuilder the MarkupDocBuilder
|
||||
*/
|
||||
public Context(Position position, MarkupDocBuilder docBuilder) {
|
||||
@@ -93,10 +59,10 @@ public abstract class SecurityDocumentExtension extends AbstractExtension {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param position the current position
|
||||
* @param docBuilder the MarkupDocBuilder
|
||||
* @param position the current position
|
||||
* @param docBuilder the MarkupDocBuilder
|
||||
* @param securitySchemeName the name of the current securityScheme
|
||||
* @param securityScheme the current security scheme securityScheme
|
||||
* @param securityScheme the current security scheme securityScheme
|
||||
*/
|
||||
public Context(Position position, MarkupDocBuilder docBuilder, String securitySchemeName, SecuritySchemeDefinition securityScheme) {
|
||||
super(docBuilder);
|
||||
@@ -121,4 +87,38 @@ public abstract class SecurityDocumentExtension extends AbstractExtension {
|
||||
}
|
||||
}
|
||||
|
||||
public SecurityDocumentExtension() {
|
||||
}
|
||||
|
||||
public abstract void apply(Context context);
|
||||
|
||||
/**
|
||||
* Returns title level offset from 1 to apply to content
|
||||
* @param context context
|
||||
* @return title level offset
|
||||
*/
|
||||
protected int levelOffset(Context context) {
|
||||
int levelOffset;
|
||||
switch (context.position) {
|
||||
case DOCUMENT_BEFORE:
|
||||
case DOCUMENT_AFTER:
|
||||
levelOffset = 0;
|
||||
break;
|
||||
case DOCUMENT_BEGIN:
|
||||
case DOCUMENT_END:
|
||||
case SECURITY_SCHEME_BEFORE:
|
||||
case SECURITY_SCHEME_AFTER:
|
||||
levelOffset = 1;
|
||||
break;
|
||||
case SECURITY_SCHEME_BEGIN:
|
||||
case SECURITY_SCHEME_END:
|
||||
levelOffset = 2;
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException(String.format("Unknown position '%s'", context.position));
|
||||
}
|
||||
|
||||
return levelOffset;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 Robert Winkler
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -23,6 +23,9 @@ import io.swagger.models.Swagger;
|
||||
*/
|
||||
public abstract class SwaggerModelExtension extends AbstractExtension {
|
||||
|
||||
public SwaggerModelExtension() {
|
||||
}
|
||||
|
||||
public abstract void apply(Swagger swagger);
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 Robert Winkler
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 Robert Winkler
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -23,7 +23,6 @@ import java.nio.file.Paths;
|
||||
public class URIUtils {
|
||||
/**
|
||||
* Return URI parent
|
||||
*
|
||||
* @param uri source URI
|
||||
* @return URI parent
|
||||
*/
|
||||
@@ -37,7 +36,7 @@ public class URIUtils {
|
||||
* @param uri the source URI
|
||||
* @return the converted URI
|
||||
*/
|
||||
public static URI convertUriWithoutSchemeToFileScheme(URI uri) {
|
||||
public static URI convertUriWithoutSchemeToFileScheme(URI uri){
|
||||
if (uri.getScheme() == null) {
|
||||
return Paths.get(uri.getPath()).toUri();
|
||||
}
|
||||
@@ -50,10 +49,10 @@ public class URIUtils {
|
||||
* @param input String representation of a URI or a Path.
|
||||
* @return the URI
|
||||
*/
|
||||
public static URI create(String input) {
|
||||
if (isFile(input) || isURL(input)) {
|
||||
public static URI create(String input){
|
||||
if(isFile(input) || isURL(input)){
|
||||
return URI.create(input);
|
||||
} else {
|
||||
}else{
|
||||
return Paths.get(input).toUri();
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
swagger2markup.markupLanguage=ASCIIDOC
|
||||
swagger2markup.swaggerMarkupLanguage=MARKDOWN
|
||||
swagger2markup.hostnameEnabled=false
|
||||
swagger2markup.basePathPrefixEnabled=false
|
||||
swagger2markup.generatedExamplesEnabled=false
|
||||
swagger2markup.operationExtensionsEnabled=false
|
||||
swagger2markup.definitionExtensionsEnabled=false
|
||||
swagger2markup.separatedDefinitionsEnabled=false
|
||||
@@ -11,7 +10,6 @@ swagger2markup.outputLanguage=EN
|
||||
swagger2markup.inlineSchemaEnabled=true
|
||||
swagger2markup.interDocumentCrossReferencesEnabled=false
|
||||
swagger2markup.flatBodyEnabled=false
|
||||
swagger2markup.pathSecuritySectionEnabled=true
|
||||
swagger2markup.overviewDocument=overview
|
||||
swagger2markup.pathsDocument=paths
|
||||
swagger2markup.definitionsDocument=definitions
|
||||
@@ -24,20 +22,3 @@ 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
|
||||
@@ -1,23 +1,12 @@
|
||||
definitions=Definitionen
|
||||
default_column=Standard
|
||||
# validators
|
||||
minlength_column=Mindestl\u00E4nge
|
||||
maxlength_column=Maximale L\u00E4nge
|
||||
length_column=L\u00E4nge
|
||||
pattern_column=Pattern
|
||||
minvalue_column=Mindestwert
|
||||
minvalue_exclusive_column=Mindestwert (exklusiv)
|
||||
maxvalue_column=Maximalwert
|
||||
maxvalue_exclusive_column=Maximalwert (exklusiv)
|
||||
min_items=Mindestanzahl
|
||||
max_items=Maximale Anzahl
|
||||
example_column=Beispiel
|
||||
flags.column=Flags
|
||||
flags.required=verpflichtend
|
||||
flags.optional=optional
|
||||
flags.read_only=Nur lesen
|
||||
flags.read_write=Lesen+Schreiben
|
||||
schema_column=Typ
|
||||
flags.required=Required
|
||||
flags.optional=Optional
|
||||
flags.read_only=Read-only
|
||||
flags.read_write=Read-write
|
||||
schema_column=Schema
|
||||
name_column=Name
|
||||
description_column=Beschreibung
|
||||
headers_column=Headers
|
||||
@@ -25,21 +14,21 @@ scopes_column=Scopes
|
||||
produces=Erzeugt
|
||||
consumes=Verarbeitet
|
||||
tags=Tags
|
||||
overview=\u00DCbersicht
|
||||
overview=<EFBFBD>bersicht
|
||||
current_version=Aktuelle Version
|
||||
version=Version
|
||||
contact_information=Kontaktinformationen
|
||||
contact_name=Kontakt
|
||||
contact_email=Kontakt E-Mail
|
||||
license_information=Lizenzinformationen
|
||||
license=Lizenz
|
||||
license=Linzenz
|
||||
license_url=Lizenz-URL
|
||||
terms_of_service=Nutzungsbedingungen
|
||||
uri_scheme=URI Schema
|
||||
host=Host
|
||||
base_path=Basis-Pfad
|
||||
schemes=Schemata
|
||||
security_name=Name
|
||||
security_name=
|
||||
security_type=Typ
|
||||
security_in=In
|
||||
security_flow=Flow
|
||||
@@ -47,7 +36,6 @@ security_authorizationUrl=Token URL
|
||||
security_tokenUrl=Token URL
|
||||
paths=Pfade
|
||||
resources=Ressourcen
|
||||
operations=Betrieb
|
||||
security=Sicherheit
|
||||
body_parameter=Body Parameter
|
||||
parameters=Parameter
|
||||
@@ -65,7 +53,4 @@ operation.deprecated=Diese Operation ist veraltet.
|
||||
polymorphism.column=Polymorphism
|
||||
polymorphism.discriminator=Discriminator
|
||||
polymorphism.nature.INHERITANCE=Inheritance
|
||||
polymorphism.nature.COMPOSITION=Composition
|
||||
external_docs=Externe Doku
|
||||
external_docs_desc=Beschreibung
|
||||
external_docs_url=URL
|
||||
polymorphism.nature.COMPOSITION=Composition
|
||||
@@ -1,16 +1,6 @@
|
||||
definitions=Definitions
|
||||
|
||||
default_column=Default
|
||||
# validators
|
||||
minlength_column=Minimum length
|
||||
maxlength_column=Maximal length
|
||||
length_column=Length
|
||||
pattern_column=Pattern
|
||||
minvalue_column=Minimum value
|
||||
minvalue_exclusive_column=Minimum value (exclusive)
|
||||
maxvalue_column=Maximum value
|
||||
maxvalue_exclusive_column=Maximum value (exclusive)
|
||||
min_items=Min count
|
||||
max_items=Max count
|
||||
example_column=Example
|
||||
flags.column=Flags
|
||||
flags.required=Required
|
||||
@@ -25,6 +15,7 @@ scopes_column=Scopes
|
||||
produces=Produces
|
||||
consumes=Consumes
|
||||
tags=Tags
|
||||
|
||||
overview=Overview
|
||||
current_version=Version information
|
||||
version=Version
|
||||
@@ -45,9 +36,9 @@ security_in=In
|
||||
security_flow=Flow
|
||||
security_authorizationUrl=Token URL
|
||||
security_tokenUrl=Token URL
|
||||
|
||||
paths=Paths
|
||||
resources=Resources
|
||||
operations=Operations
|
||||
security=Security
|
||||
parameters=Parameters
|
||||
body_parameter=Body parameter
|
||||
@@ -59,13 +50,11 @@ example_response=Example HTTP response
|
||||
type_column=Type
|
||||
http_code_column=HTTP Code
|
||||
parameter=Parameter
|
||||
|
||||
unknown=Unknown
|
||||
no_content=No Content
|
||||
operation.deprecated=This operation is deprecated.
|
||||
polymorphism.column=Polymorphism
|
||||
polymorphism.discriminator=Discriminator
|
||||
polymorphism.nature.INHERITANCE=Inheritance
|
||||
polymorphism.nature.COMPOSITION=Composition
|
||||
external_docs=External Docs
|
||||
external_docs_desc=Description
|
||||
external_docs_url=URL
|
||||
polymorphism.nature.COMPOSITION=Composition
|
||||
@@ -1,16 +1,6 @@
|
||||
definitions=D\u00E9finitions
|
||||
|
||||
default_column=D\u00E9faut
|
||||
# validators
|
||||
minlength_column=Longueur minimale
|
||||
maxlength_column=Longueur maximale
|
||||
length_column=Longueur
|
||||
pattern_column=Mod\u00E8le
|
||||
minvalue_column=Valeur minimale
|
||||
minvalue_exclusive_column=Valeur minimale (exclusif)
|
||||
maxvalue_column=Valeur maximale
|
||||
maxvalue_exclusive_column=Valeur maximale (exclusif)
|
||||
min_items=Nombre minimal
|
||||
max_items=Nombre maximal
|
||||
example_column=Exemple
|
||||
flags.column=Modificateurs
|
||||
flags.required=Requis
|
||||
@@ -25,6 +15,7 @@ scopes_column=P\u00E9rim\u00E8tre
|
||||
produces=Produit
|
||||
consumes=Consomme
|
||||
tags=Tags
|
||||
|
||||
overview=Vue g\u00E9n\u00E9rale
|
||||
current_version=Information de version
|
||||
version=Version
|
||||
@@ -45,9 +36,9 @@ security_in=Position
|
||||
security_flow=Flux
|
||||
security_authorizationUrl=URL d'autorisation
|
||||
security_tokenUrl=URL de jeton
|
||||
|
||||
paths=Op\u00E9rations
|
||||
resources=Ressources
|
||||
operations=Op\u00E9rations
|
||||
security=S\u00E9curit\u00E9
|
||||
parameters=Param\u00E8tres
|
||||
body_parameter=Contenu
|
||||
@@ -59,13 +50,11 @@ example_response=Exemple de r\u00E9ponse HTTP
|
||||
type_column=Type
|
||||
http_code_column=Code HTTP
|
||||
parameter=Param\u00E8tre
|
||||
unknown=Inconnu
|
||||
|
||||
unknown=Unknown
|
||||
no_content=Pas de contenu
|
||||
operation.deprecated=Cette op\u00E9ration est obsol\u00E8te.
|
||||
polymorphism.column=Polymorphisme
|
||||
polymorphism.discriminator=Discriminateur
|
||||
polymorphism.nature.INHERITANCE=H\u00E9ritage
|
||||
polymorphism.nature.COMPOSITION=Composition
|
||||
external_docs=External Docs
|
||||
external_docs_desc=Description
|
||||
external_docs_url=URL
|
||||
polymorphism.nature.COMPOSITION=Composition
|
||||
@@ -1,37 +1,28 @@
|
||||
definitions=\u041E\u043F\u0440\u0435\u0434\u0435\u043B\u0435\u043D\u0438\u044F
|
||||
|
||||
default_column=\u041F\u043E \u0443\u043C\u043E\u043B\u0447\u0430\u043D\u0438\u044E
|
||||
# validators
|
||||
minlength_column=\u041C\u0438\u043D\u0438\u043C\u0430\u043B\u044C\u043D\u0430\u044F \u0434\u043B\u0438\u043D\u0430
|
||||
maxlength_column=\u041C\u0430\u043A\u0441\u0438\u043C\u0430\u043B\u044C\u043D\u0430\u044F \u0434\u043B\u0438\u043D\u0430
|
||||
length_column=\u0414\u043B\u0438\u043D\u0430
|
||||
pattern_column=\u0428\u0430\u0431\u043B\u043E\u043D
|
||||
minvalue_column=\u041C\u0438\u043D\u0438\u043C\u0430\u043B\u044C\u043D\u043E\u0435 \u0437\u043D\u0430\u0447\u0435\u043D\u0438\u0435
|
||||
minvalue_exclusive_column=\u041C\u0438\u043D\u0438\u043C\u0430\u043B\u044C\u043D\u043E\u0435 \u0437\u043D\u0430\u0447\u0435\u043D\u0438\u0435 (\u0438\u0441\u043A\u043B\u044E\u0447\u0435\u043D\u0438\u0435)
|
||||
maxvalue_column=\u041C\u0430\u043A\u0441\u0438\u043C\u0430\u043B\u044C\u043D\u043E\u0435 \u0437\u043D\u0430\u0447\u0435\u043D\u0438\u0435
|
||||
maxvalue_exclusive_column=\u041C\u0430\u043A\u0441\u0438\u043C\u0430\u043B\u044C\u043D\u043E\u0435 \u0437\u043D\u0430\u0447\u0435\u043D\u0438\u0435 (\u0438\u0441\u043A\u043B\u044E\u0447\u0435\u043D\u0438\u0435)
|
||||
min_items=\u041C\u0438\u043D\u0438\u043C\u0430\u043B\u044C\u043D\u044B\u0439 \u0441\u0447\u0435\u0442\u0447\u0438\u043A
|
||||
max_items=\041C \0430 \043A \0441 \0438 \043C \0430 \043B \044C \043D \043E \0435 \043A \043E \043B \0438 \0447 \0435 \0441 \0442 \0432 \043E
|
||||
flags.column=\u0424\u043B\u0430\u0433\u0438
|
||||
flags.column=Flags
|
||||
flags.required=\u041E\u0431\u044F\u0437\u0430\u0442\u0435\u043B\u044C\u043D\u043E
|
||||
flags.optional=\u041D\u0435\u043E\u0431\u044F\u0437\u0430\u0442\u0435\u043B\u044C\u043D\u043E
|
||||
flags.read_only=\u0422\u043E\u043B\u044C\u043A\u043E \u0434\u043B\u044F \u0447\u0442\u0435\u043D\u0438\u044F
|
||||
flags.read_write=\u0427\u0442\u0435\u043D\u0438\u0435 \u0438 \u0437\u0430\u043F\u0438\u0441\u044C
|
||||
flags.optional=Optional
|
||||
flags.read_only=Read-only
|
||||
flags.read_write=Read-write
|
||||
example_column=\u041F\u0440\u0438\u043C\u0435\u0440
|
||||
schema_column=\u0421\u0445\u0435\u043C\u0430
|
||||
name_column=\u0418\u043C\u044F
|
||||
description_column=\u041E\u043F\u0438\u0441\u0430\u043D\u0438\u0435
|
||||
headers_column=\u0417\u0430\u0433\u043E\u043B\u043E\u0432\u043A\u0438
|
||||
headers_column=Headers
|
||||
scopes_column=\u041E\u0431\u043B\u0430\u0441\u0442\u0438 \u043F\u0440\u0438\u043C\u0435\u043D\u0435\u043D\u0438\u044F
|
||||
produces=\u0412\u043E\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442
|
||||
consumes=\u041F\u0440\u0438\u043D\u0438\u043C\u0430\u0435\u0442
|
||||
tags=\u0422\u0435\u0433\u0438
|
||||
tags=\u0422\u044D\u0433\u0438
|
||||
|
||||
overview=\u041E\u0431\u0437\u043E\u0440
|
||||
current_version=\u0418\u043D\u0444\u043E\u0440\u043C\u0430\u0446\u0438\u044F \u043E \u0432\u0435\u0440\u0441\u0438\u0438
|
||||
version=\u0412\u0435\u0440\u0441\u0438\u044F
|
||||
contact_information=\u041A\u043E\u043D\u0442\u0430\u043A\u0442\u043D\u0430\u044F \u0438\u043D\u0444\u043E\u0440\u043C\u0430\u0446\u0438\u044F
|
||||
contact_name=\u041A\u043E\u043D\u0442\u0430\u043A\u0442
|
||||
contact_email=E-mail \u043A\u043E\u043D\u0442\u0430\u043A\u0442\u0430
|
||||
license_information=\u0418\u043D\u0444\u043E\u0440\u043C\u0430\u0446\u0438\u044F \u043E \u043B\u0438\u0446\u0435\u043D\u0437\u0438\u0438
|
||||
contact_email=Email \u043A\u043E\u043D\u0442\u0430\u043A\u0442\u0430
|
||||
license_information=\u0418\u043D\u0444\u043E\u0440\u043C\u0430\u0446\u0438\u044F \u043E \u043B\u0438\u0446\u0435\u043D\u0446\u0438\u0438
|
||||
license=\u041B\u0438\u0446\u0435\u043D\u0437\u0438\u044F
|
||||
license_url=URL \u043B\u0438\u0446\u0435\u043D\u0437\u0438\u0438
|
||||
terms_of_service=\u0423\u0441\u043B\u043E\u0432\u0438\u044F \u0438\u0441\u043F\u043E\u043B\u044C\u0437\u043E\u0432\u0430\u043D\u0438\u044F
|
||||
@@ -45,9 +36,9 @@ security_in=\u0421\u043E\u0434\u0435\u0440\u0436\u0438\u0442\u0441\u044F \u0432
|
||||
security_flow=\u041F\u043E\u0442\u043E\u043A
|
||||
security_authorizationUrl=URL \u0430\u0432\u0442\u043E\u0440\u0438\u0437\u0430\u0446\u0438\u0438
|
||||
security_tokenUrl=URL \u0442\u043E\u043A\u0435\u043D\u0430
|
||||
|
||||
paths=\u041F\u0443\u0442\u0438
|
||||
resources=\u0420\u0435\u0441\u0443\u0440\u0441\u044B
|
||||
operations=\u041E\u043F\u0435\u0440\u0430\u0446\u0438\u0438
|
||||
resources=\u041E\u0442\u0432\u0435\u0442\u044B
|
||||
security=\u0411\u0435\u0437\u043E\u043F\u0430\u0441\u043D\u043E\u0441\u0442\u044C
|
||||
response=\u041E\u0442\u0432\u0435\u0442
|
||||
request=\u0417\u0430\u043F\u0440\u043E\u0441
|
||||
@@ -55,17 +46,15 @@ parameters=\u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440\u044B
|
||||
body_parameter=\u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440 \u0442\u0435\u043B\u0430 \u0437\u0430\u043F\u0440\u043E\u0441\u0430
|
||||
responses=\u041E\u0442\u0432\u0435\u0442\u044B
|
||||
example_request=\u041F\u0440\u0438\u043C\u0435\u0440 HTTP \u0437\u0430\u043F\u0440\u043E\u0441\u0430
|
||||
example_response=\u041F\u0440\u0438\u043C\u0435\u0440 HTTP \u043E\u0442\u0432\u0435\u0442\u0430
|
||||
example_response=\u041F\u0440\u0438\u043C\u0435\u0440 HTTP \u0437\u0430\u043F\u0440\u043E\u0441\u0430
|
||||
type_column=\u0422\u0438\u043F
|
||||
http_code_column=HTTP \u043A\u043E\u0434
|
||||
parameter=\u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440
|
||||
unknown=\u041D\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043D\u044B\u0439
|
||||
|
||||
unknown=Unknown
|
||||
no_content=\u0411\u0435\u0437 \u0441\u043E\u0434\u0435\u0440\u0436\u0438\u043C\u043E\u0433\u043E
|
||||
operation.deprecated=\u042D\u0442\u0430 \u043E\u043F\u0435\u0440\u0430\u0446\u0438\u044F \u0443\u0441\u0442\u0430\u0440\u0435\u043B\u0430.
|
||||
polymorphism.column=\u041F\u043E\u043B\u0438\u043C\u043E\u0440\u0444\u0438\u0437\u043C
|
||||
polymorphism.discriminator=\u0414\u0438\u0441\u043A\u0440\u0438\u043C\u0438\u043D\u0430\u0442\u043E\u0440
|
||||
polymorphism.nature.INHERITANCE=\u041D\u0430\u0441\u043B\u0435\u0434\u043E\u0432\u0430\u043D\u0438\u0435
|
||||
polymorphism.nature.COMPOSITION=\u0421\u0442\u0440\u0443\u043A\u0442\u0443\u0440\u0430
|
||||
external_docs=External Docs
|
||||
external_docs_desc=Description
|
||||
external_docs_url=URL
|
||||
polymorphism.column=Polymorphism
|
||||
polymorphism.discriminator=Discriminator
|
||||
polymorphism.nature.INHERITANCE=Inheritance
|
||||
polymorphism.nature.COMPOSITION=Composition
|
||||
@@ -1,16 +1,6 @@
|
||||
definitions=Tan\u0131mlar
|
||||
|
||||
default_column=Varsay\u0131lan
|
||||
# validators
|
||||
minlength_column=Minimum length
|
||||
maxlength_column=Maximal length
|
||||
length_column=Length
|
||||
pattern_column=Pattern
|
||||
minvalue_column=Minimum value
|
||||
minvalue_exclusive_column=Minimum value (exclusive)
|
||||
maxvalue_column=Maximum value
|
||||
maxvalue_exclusive_column=Maximum value (exclusive)
|
||||
min_items=Minimal say\u0131m
|
||||
max_items=Maksimum say\u0131m
|
||||
example_column=\u00D6rnek
|
||||
flags.column=Bayraklar
|
||||
flags.required=Gerekli
|
||||
@@ -25,6 +15,7 @@ scopes_column=Kapsamlar
|
||||
produces=\u00DCretilenler
|
||||
consumes=Kullan\u0131lanlar
|
||||
tags=Etiketler
|
||||
|
||||
overview=Genel Bak\u0131\u015F
|
||||
current_version=Versiyon bilgisi
|
||||
version=Versiyon
|
||||
@@ -45,9 +36,9 @@ security_in=Yer
|
||||
security_flow=Ak\u0131\u015F
|
||||
security_authorizationUrl=Yetkilendirme adresi
|
||||
security_tokenUrl=Token adresi
|
||||
|
||||
paths=Dizinler
|
||||
resources=Kaynaklar
|
||||
operations=Operasyonlar
|
||||
security=G\u00FCvenlik
|
||||
parameters=Parametreler
|
||||
body_parameter=G\u00F6vde parametresi
|
||||
@@ -59,13 +50,11 @@ example_response=\u00D6rnek HTTP cevab\u0131
|
||||
type_column=Tip
|
||||
http_code_column=HTTP Kodu
|
||||
parameter=Parametre
|
||||
|
||||
unknown=Bilinmeyen
|
||||
no_content=\u0130\u00E7erik yok
|
||||
operation.deprecated=Bu i\u015Flem \u00F6nerilmemektedir.
|
||||
polymorphism.column=\u00C7okbi\u00E7imlilik
|
||||
polymorphism.discriminator=Ayr\u0131\u015Ft\u0131r\u0131c\u0131
|
||||
polymorphism.nature.INHERITANCE=Kal\u0131t\u0131m
|
||||
polymorphism.nature.COMPOSITION=Birle\u015Ftirme
|
||||
external_docs=External Docs
|
||||
external_docs_desc=Description
|
||||
external_docs_url=URL
|
||||
polymorphism.nature.COMPOSITION=Birle\u015Ftirme
|
||||
@@ -0,0 +1,530 @@
|
||||
/*
|
||||
* Copyright 2016 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 io.github.swagger2markup.builder.Swagger2MarkupConfigBuilder;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.Files;
|
||||
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.failBecauseExceptionWasNotThrown;
|
||||
import static org.assertj.core.api.BDDAssertions.assertThat;
|
||||
|
||||
public class AsciidocConverterTest {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(AsciidocConverterTest.class);
|
||||
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 testSwagger2AsciiDocConversionAsString() throws IOException, URISyntaxException {
|
||||
//Given
|
||||
Path file = Paths.get(AsciidocConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI());
|
||||
|
||||
//When
|
||||
String asciiDocAsString = Swagger2MarkupConverter.from(file).build()
|
||||
.toString();
|
||||
//Then
|
||||
assertThat(asciiDocAsString).isNotEmpty();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSwagger2AsciiDocConversion() throws IOException, URISyntaxException {
|
||||
//Given
|
||||
Path file = Paths.get(AsciidocConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI());
|
||||
Path outputDirectory = Paths.get("build/test/asciidoc/default");
|
||||
FileUtils.deleteQuietly(outputDirectory.toFile());
|
||||
|
||||
//When
|
||||
Swagger2MarkupConverter.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/default").toURI());
|
||||
DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testSwagger2AsciiDocConversion.html");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSwagger2AsciiDocConversionInstagram() throws IOException, URISyntaxException {
|
||||
//Given
|
||||
Path file = Paths.get(AsciidocConverterTest.class.getResource("/yaml/swagger_instagram.yaml").toURI());
|
||||
Path outputDirectory = Paths.get("build/test/asciidoc/instagram");
|
||||
FileUtils.deleteQuietly(outputDirectory.toFile());
|
||||
|
||||
//When
|
||||
Swagger2MarkupConverter.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/instagram").toURI());
|
||||
DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testSwagger2AsciiDocConversionInstagram.html");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSwagger2AsciiDocConversionWithInterDocumentCrossReferences() throws IOException, URISyntaxException {
|
||||
//Given
|
||||
Path file = Paths.get(AsciidocConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI());
|
||||
Path outputDirectory = Paths.get("build/test/asciidoc/idxref");
|
||||
FileUtils.deleteQuietly(outputDirectory.toFile());
|
||||
|
||||
//When
|
||||
Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
|
||||
.withInterDocumentCrossReferences()
|
||||
.build();
|
||||
|
||||
Swagger2MarkupConverter.from(file).withConfig(config).build()
|
||||
.toFolder(outputDirectory);
|
||||
|
||||
//Then
|
||||
String[] files = outputDirectory.toFile().list();
|
||||
assertThat(files).hasSize(4).containsAll(expectedFiles);
|
||||
|
||||
Path expectedFilesDirectory = Paths.get(AsciidocConverterTest.class.getResource("/expected/asciidoc/idxref").toURI());
|
||||
DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testSwagger2AsciiDocConversionWithInterDocumentCrossReferences.html");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSwagger2AsciiDocConversionFromString() throws IOException, URISyntaxException {
|
||||
//Given
|
||||
String swaggerJsonString = IOUtils.toString(getClass().getResourceAsStream("/yaml/swagger_petstore.yaml"));
|
||||
Path outputDirectory = Paths.get("build/test/asciidoc/default");
|
||||
FileUtils.deleteQuietly(outputDirectory.toFile());
|
||||
|
||||
//When
|
||||
Swagger2MarkupConverter.from(swaggerJsonString).build()
|
||||
.toFolder(outputDirectory);
|
||||
|
||||
//Then
|
||||
String[] files = outputDirectory.toFile().list();
|
||||
assertThat(files).hasSize(4).containsAll(expectedFiles);
|
||||
|
||||
Path expectedFilesDirectory = Paths.get(AsciidocConverterTest.class.getResource("/expected/asciidoc/default").toURI());
|
||||
DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testSwagger2AsciiDocConversion.html");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSwagger2AsciiDocConversionWithExamples() throws IOException, URISyntaxException {
|
||||
//Given
|
||||
String swaggerJsonString = IOUtils.toString(getClass().getResourceAsStream("/json/swagger_examples.json"));
|
||||
Path outputDirectory = Paths.get("build/test/asciidoc/examples");
|
||||
FileUtils.deleteQuietly(outputDirectory.toFile());
|
||||
|
||||
//When
|
||||
Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
|
||||
.withoutInlineSchema()
|
||||
.build();
|
||||
|
||||
Swagger2MarkupConverter.from(swaggerJsonString)
|
||||
.withConfig(config)
|
||||
.build()
|
||||
.toFolder(outputDirectory);
|
||||
|
||||
//Then
|
||||
String[] files = outputDirectory.toFile().list();
|
||||
assertThat(files).hasSize(4).containsAll(expectedFiles);
|
||||
Path expectedFilesDirectory = Paths.get(AsciidocConverterTest.class.getResource("/expected/asciidoc/examples").toURI());
|
||||
DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testSwagger2AsciiDocConversionWithExamples.html");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSwagger2AsciiDocConversionWithGeneratedExamples() throws IOException, URISyntaxException {
|
||||
//Given
|
||||
String swaggerJsonString = IOUtils.toString(getClass().getResourceAsStream("/json/swagger_examples.json"));
|
||||
Path outputDirectory = Paths.get("build/test/asciidoc/generated_examples");
|
||||
FileUtils.deleteQuietly(outputDirectory.toFile());
|
||||
|
||||
//When
|
||||
Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
|
||||
.withGeneratedExamples()
|
||||
.build();
|
||||
|
||||
Swagger2MarkupConverter.from(swaggerJsonString)
|
||||
.withConfig(config)
|
||||
.build()
|
||||
.toFolder(outputDirectory);
|
||||
|
||||
//Then
|
||||
String[] files = outputDirectory.toFile().list();
|
||||
assertThat(files).hasSize(4).containsAll(expectedFiles);
|
||||
Path expectedFilesDirectory = Paths.get(AsciidocConverterTest.class.getResource("/expected/asciidoc/generated_examples").toURI());
|
||||
DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testSwagger2AsciiDocConversionWithGeneratedExamples.html");
|
||||
}
|
||||
|
||||
@Ignore("swagger-parser-1.0.21 ignore Location def because it's referenced from an external ref (ExternalLocation)")
|
||||
@Test
|
||||
public void testSwagger2AsciiDocWithInlineSchema() throws IOException, URISyntaxException {
|
||||
//Given
|
||||
Path file = Paths.get(AsciidocConverterTest.class.getResource("/yaml/swagger_inlineSchema.yaml").toURI());
|
||||
Path outputDirectory = Paths.get("build/test/asciidoc/inline_schema");
|
||||
FileUtils.deleteQuietly(outputDirectory.toFile());
|
||||
|
||||
//When
|
||||
Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
|
||||
.build();
|
||||
Swagger2MarkupConverter.from(file)
|
||||
.withConfig(config)
|
||||
.build()
|
||||
.toFolder(outputDirectory);
|
||||
|
||||
//Then
|
||||
String[] files = outputDirectory.toFile().list();
|
||||
assertThat(files).hasSize(4).containsAll(expectedFiles);
|
||||
Path expectedFilesDirectory = Paths.get(AsciidocConverterTest.class.getResource("/expected/asciidoc/inline_schema").toURI());
|
||||
DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testSwagger2AsciiDocWithInlineSchema.html");
|
||||
}
|
||||
|
||||
@Ignore("swagger-parser-1.0.21 ignore Location def because it's referenced from an external ref (ExternalLocation)")
|
||||
@Test
|
||||
public void testSwagger2AsciiDocWithInlineSchemaAndFlatBody() throws IOException, URISyntaxException {
|
||||
//Given
|
||||
Path file = Paths.get(AsciidocConverterTest.class.getResource("/yaml/swagger_inlineSchema.yaml").toURI());
|
||||
Path outputDirectory = Paths.get("build/test/asciidoc/inline_schema_flat_body");
|
||||
FileUtils.deleteQuietly(outputDirectory.toFile());
|
||||
|
||||
//When
|
||||
Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
|
||||
.withFlatBody()
|
||||
.build();
|
||||
Swagger2MarkupConverter.from(file)
|
||||
.withConfig(config)
|
||||
.build()
|
||||
.toFolder(outputDirectory);
|
||||
|
||||
//Then
|
||||
String[] files = outputDirectory.toFile().list();
|
||||
assertThat(files).hasSize(4).containsAll(expectedFiles);
|
||||
Path expectedFilesDirectory = Paths.get(AsciidocConverterTest.class.getResource("/expected/asciidoc/inline_schema_flat_body").toURI());
|
||||
DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testSwagger2AsciiDocWithInlineSchemaAndFlatBody.html");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSwagger2AsciiDocGroupedByTags() throws IOException, URISyntaxException {
|
||||
//Given
|
||||
Path file = Paths.get(AsciidocConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI());
|
||||
Path outputDirectory = Paths.get("build/test/asciidoc/group_by_tags");
|
||||
FileUtils.deleteQuietly(outputDirectory.toFile());
|
||||
//When
|
||||
Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
|
||||
.withPathsGroupedBy(GroupBy.TAGS)
|
||||
.build();
|
||||
Swagger2MarkupConverter.from(file)
|
||||
.withConfig(config)
|
||||
.build()
|
||||
.toFolder(outputDirectory);
|
||||
|
||||
//Then
|
||||
String[] files = outputDirectory.toFile().list();
|
||||
assertThat(files).hasSize(4).containsAll(expectedFiles);
|
||||
Path expectedFilesDirectory = Paths.get(AsciidocConverterTest.class.getResource("/expected/asciidoc/group_by_tags").toURI());
|
||||
DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testSwagger2AsciiDocGroupedByTags.html");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSwagger2AsciiDocGroupedByTagsWithMissingTag() throws IOException, URISyntaxException {
|
||||
//Given
|
||||
Path file = Paths.get(AsciidocConverterTest.class.getResource("/json/swagger_missing_tag.json").toURI());
|
||||
Path outputDirectory = Paths.get("build/test/asciidoc/generated");
|
||||
FileUtils.deleteQuietly(outputDirectory.toFile());
|
||||
//When
|
||||
try {
|
||||
Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
|
||||
.withPathsGroupedBy(GroupBy.TAGS)
|
||||
.build();
|
||||
|
||||
Swagger2MarkupConverter.from(file)
|
||||
.withConfig(config)
|
||||
.build()
|
||||
.toFolder(outputDirectory);
|
||||
// If NullPointerException was not thrown, test would fail the specified message
|
||||
failBecauseExceptionWasNotThrown(NullPointerException.class);
|
||||
} catch (Exception e) {
|
||||
assertThat(e).hasMessage("Can't GroupBy.TAGS > Operation 'updatePet' has not tags");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSwagger2AsciiDocConversionDoesNotContainUriScheme() throws IOException, URISyntaxException {
|
||||
//Given
|
||||
Path file = Paths.get(AsciidocConverterTest.class.getResource("/yaml/swagger_should_not_contain_uri_scheme.yaml").toURI());
|
||||
Path outputDirectory = Paths.get("build/test/asciidoc/generated");
|
||||
FileUtils.deleteQuietly(outputDirectory.toFile());
|
||||
|
||||
//When
|
||||
Swagger2MarkupConverter.from(file).build()
|
||||
.toFolder(outputDirectory);
|
||||
|
||||
//Then
|
||||
String[] files = outputDirectory.toFile().list();
|
||||
assertThat(files).hasSize(4).containsAll(expectedFiles);
|
||||
|
||||
assertThat(new String(Files.readAllBytes(outputDirectory.resolve("overview.adoc"))))
|
||||
.doesNotContain("=== URI scheme");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSwagger2AsciiDocConversionContainsUriScheme() throws IOException, URISyntaxException {
|
||||
//Given
|
||||
Path file = Paths.get(AsciidocConverterTest.class.getResource("/yaml/swagger_should_contain_uri_scheme.yaml").toURI());
|
||||
Path outputDirectory = Paths.get("build/test/asciidoc/generated");
|
||||
FileUtils.deleteQuietly(outputDirectory.toFile());
|
||||
|
||||
//When
|
||||
Swagger2MarkupConverter.from(file).build()
|
||||
.toFolder(outputDirectory);
|
||||
|
||||
//Then
|
||||
String[] files = outputDirectory.toFile().list();
|
||||
assertThat(files).hasSize(4).containsAll(expectedFiles);
|
||||
|
||||
assertThat(new String(Files.readAllBytes(outputDirectory.resolve("overview.adoc"))))
|
||||
.contains("=== URI scheme");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSwagger2AsciiDocConversionWithSeparatedDefinitions() throws IOException, URISyntaxException {
|
||||
//Given
|
||||
Path file = Paths.get(AsciidocConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI());
|
||||
Path outputDirectory = Paths.get("build/test/asciidoc/generated");
|
||||
FileUtils.deleteQuietly(outputDirectory.toFile());
|
||||
|
||||
//When
|
||||
Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
|
||||
.withSeparatedDefinitions()
|
||||
.build();
|
||||
Swagger2MarkupConverter.from(file).withConfig(config).build()
|
||||
.toFolder(outputDirectory);
|
||||
|
||||
//Then
|
||||
String[] files = outputDirectory.toFile().list();
|
||||
expectedFiles.add("definitions");
|
||||
assertThat(files).hasSize(5).containsAll(expectedFiles);
|
||||
|
||||
Path definitionsDirectory = outputDirectory.resolve("definitions");
|
||||
String[] definitions = definitionsDirectory.toFile().list();
|
||||
assertThat(definitions).hasSize(5).containsAll(
|
||||
asList("Category.adoc", "Order.adoc", "Pet.adoc", "Tag.adoc", "User.adoc"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSwagger2AsciiDocConversionWithSeparatedOperations() throws IOException, URISyntaxException {
|
||||
//Given
|
||||
Path file = Paths.get(AsciidocConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI());
|
||||
Path outputDirectory = Paths.get("build/test/asciidoc/generated");
|
||||
FileUtils.deleteQuietly(outputDirectory.toFile());
|
||||
|
||||
//When
|
||||
Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
|
||||
.withSeparatedOperations()
|
||||
.build();
|
||||
Swagger2MarkupConverter.from(file).withConfig(config).build()
|
||||
.toFolder(outputDirectory);
|
||||
|
||||
//Then
|
||||
String[] files = outputDirectory.toFile().list();
|
||||
expectedFiles.add("operations");
|
||||
assertThat(files).hasSize(5).containsAll(expectedFiles);
|
||||
|
||||
Path pathsDirectory = outputDirectory.resolve("operations");
|
||||
String[] paths = pathsDirectory.toFile().list();
|
||||
assertThat(paths).hasSize(18);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSwagger2AsciiDocConversionWithRussianOutputLanguage() throws IOException, URISyntaxException {
|
||||
//Given
|
||||
Path file = Paths.get(AsciidocConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI());
|
||||
Path outputDirectory = Paths.get("build/test/asciidoc/generated");
|
||||
FileUtils.deleteQuietly(outputDirectory.toFile());
|
||||
|
||||
//When
|
||||
Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
|
||||
.withOutputLanguage(Language.RU)
|
||||
.build();
|
||||
Swagger2MarkupConverter.from(file)
|
||||
.withConfig(config)
|
||||
.build()
|
||||
.toFolder(outputDirectory);
|
||||
|
||||
//Then
|
||||
assertThat(new String(Files.readAllBytes(outputDirectory.resolve("definitions.adoc")), Charset.forName("UTF-8")))
|
||||
.contains("== Определения");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSwagger2AsciiDocConversionWithFrenchOutputLanguage() throws IOException, URISyntaxException {
|
||||
//Given
|
||||
Path file = Paths.get(AsciidocConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI());
|
||||
Path outputDirectory = Paths.get("build/test/asciidoc/generated");
|
||||
FileUtils.deleteQuietly(outputDirectory.toFile());
|
||||
|
||||
//When
|
||||
Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
|
||||
.withOutputLanguage(Language.FR)
|
||||
.build();
|
||||
Swagger2MarkupConverter.from(file)
|
||||
.withConfig(config)
|
||||
.build()
|
||||
.toFolder(outputDirectory);
|
||||
|
||||
//Then
|
||||
assertThat(new String(Files.readAllBytes(outputDirectory.resolve("overview.adoc")), Charset.forName("UTF-8")))
|
||||
.contains("== Sch\u00E9ma d'URI");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSwagger2AsciiDocConversionWithMaps() throws IOException, URISyntaxException {
|
||||
//Given
|
||||
Path file = Paths.get(AsciidocConverterTest.class.getResource("/json/swagger_maps.json").toURI());
|
||||
Path outputDirectory = Paths.get("build/test/asciidoc/maps");
|
||||
FileUtils.deleteQuietly(outputDirectory.toFile());
|
||||
|
||||
//When
|
||||
Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
|
||||
.build();
|
||||
Swagger2MarkupConverter.from(file)
|
||||
.withConfig(config)
|
||||
.build()
|
||||
.toFolder(outputDirectory);
|
||||
|
||||
//Then
|
||||
String[] files = outputDirectory.toFile().list();
|
||||
assertThat(files).hasSize(4).containsAll(expectedFiles);
|
||||
|
||||
Path expectedFilesDirectory = Paths.get(AsciidocConverterTest.class.getResource("/expected/asciidoc/maps").toURI());
|
||||
DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testSwagger2AsciiDocConversionWithMaps.html");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSwagger2AsciiDocConversionWithEnums() throws IOException, URISyntaxException {
|
||||
//Given
|
||||
Path file = Paths.get(AsciidocConverterTest.class.getResource("/json/swagger_enums.json").toURI());
|
||||
Path outputDirectory = Paths.get("build/test/asciidoc/enums");
|
||||
FileUtils.deleteQuietly(outputDirectory.toFile());
|
||||
|
||||
//When
|
||||
Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
|
||||
.build();
|
||||
Swagger2MarkupConverter.from(file)
|
||||
.withConfig(config)
|
||||
.build()
|
||||
.toFolder(outputDirectory);
|
||||
|
||||
//Then
|
||||
String[] files = outputDirectory.toFile().list();
|
||||
assertThat(files).hasSize(4).containsAll(expectedFiles);
|
||||
|
||||
Path expectedFilesDirectory = Paths.get(AsciidocConverterTest.class.getResource("/expected/asciidoc/enums").toURI());
|
||||
DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testSwagger2AsciiDocConversionWithEnums.html");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSwagger2AsciiDocConversionWithPolymorphism() throws IOException, URISyntaxException {
|
||||
//Given
|
||||
Path file = Paths.get(AsciidocConverterTest.class.getResource("/json/swagger_polymorphism.json").toURI());
|
||||
Path outputDirectory = Paths.get("build/test/asciidoc/polymorphism");
|
||||
FileUtils.deleteQuietly(outputDirectory.toFile());
|
||||
|
||||
//When
|
||||
Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
|
||||
.build();
|
||||
Swagger2MarkupConverter.from(file)
|
||||
.withConfig(config)
|
||||
.build()
|
||||
.toFolder(outputDirectory);
|
||||
|
||||
//Then
|
||||
String[] files = outputDirectory.toFile().list();
|
||||
assertThat(files).hasSize(4).containsAll(expectedFiles);
|
||||
|
||||
Path expectedFilesDirectory = Paths.get(AsciidocConverterTest.class.getResource("/expected/asciidoc/polymorphism").toURI());
|
||||
DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testSwagger2AsciiDocConversionWithPolymorphism.html");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSwagger2AsciiDocConversionWithPolymorphismAsIsOrdering() throws IOException, URISyntaxException {
|
||||
//Given
|
||||
Path file = Paths.get(AsciidocConverterTest.class.getResource("/json/swagger_polymorphism.json").toURI());
|
||||
Path outputDirectory = Paths.get("build/test/asciidoc/polymorphismAsIsOrdering");
|
||||
FileUtils.deleteQuietly(outputDirectory.toFile());
|
||||
|
||||
//When
|
||||
Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
|
||||
.withPropertyOrdering(OrderBy.AS_IS)
|
||||
.build();
|
||||
Swagger2MarkupConverter.from(file)
|
||||
.withConfig(config)
|
||||
.build()
|
||||
.toFolder(outputDirectory);
|
||||
|
||||
//Then
|
||||
String[] files = outputDirectory.toFile().list();
|
||||
assertThat(files).hasSize(4).containsAll(expectedFiles);
|
||||
|
||||
Path expectedFilesDirectory = Paths.get(AsciidocConverterTest.class.getResource("/expected/asciidoc/polymorphismAsIsOrdering").toURI());
|
||||
DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testSwagger2AsciiDocConversionWithPolymorphismAsIsOrdering.html");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSwagger2AsciiDocConversionWithResponseHeaders() throws IOException, URISyntaxException {
|
||||
//Given
|
||||
Path file = Paths.get(AsciidocConverterTest.class.getResource("/yaml/swagger_response_headers.yaml").toURI());
|
||||
Path outputDirectory = Paths.get("build/test/asciidoc/response_headers");
|
||||
FileUtils.deleteQuietly(outputDirectory.toFile());
|
||||
|
||||
//When
|
||||
Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
|
||||
.build();
|
||||
Swagger2MarkupConverter.from(file)
|
||||
.withConfig(config)
|
||||
.build()
|
||||
.toFolder(outputDirectory);
|
||||
|
||||
//Then
|
||||
String[] files = outputDirectory.toFile().list();
|
||||
assertThat(files).hasSize(4).containsAll(expectedFiles);
|
||||
|
||||
Path expectedFilesDirectory = Paths.get(AsciidocConverterTest.class.getResource("/expected/asciidoc/response_headers").toURI());
|
||||
DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testSwagger2AsciiDocConversionWithResponseHeaders.html");
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 Robert Winkler
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,7 +19,6 @@ import io.github.swagger2markup.builder.MyExtension;
|
||||
import io.github.swagger2markup.builder.Swagger2MarkupConfigBuilder;
|
||||
import io.github.swagger2markup.builder.Swagger2MarkupExtensionRegistryBuilder;
|
||||
import io.github.swagger2markup.markup.builder.MarkupLanguage;
|
||||
import io.github.swagger2markup.spi.Swagger2MarkupExtensionRegistry;
|
||||
import org.apache.commons.configuration2.Configuration;
|
||||
import org.apache.commons.configuration2.builder.fluent.Configurations;
|
||||
import org.apache.commons.configuration2.ex.ConfigurationException;
|
||||
@@ -81,12 +80,12 @@ public class DocumentationTest {
|
||||
// end::convertIntoString[]
|
||||
}
|
||||
|
||||
public void swagger2MarkupConfigBuilder() {
|
||||
public void swagger2MarkupConfigBuilder(){
|
||||
Path localSwaggerFile = Paths.get("/path/to/swagger.yaml");
|
||||
|
||||
// tag::swagger2MarkupConfigBuilder[]
|
||||
Swagger2MarkupConfig config = (Swagger2MarkupConfig) new Swagger2MarkupConfigBuilder() //<1>
|
||||
.withMarkupLanguage(io.github.swagger2markup.MarkupLanguage.MARKDOWN) //<2>
|
||||
Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() //<1>
|
||||
.withMarkupLanguage(MarkupLanguage.MARKDOWN) //<2>
|
||||
.withOutputLanguage(Language.DE) //<3>
|
||||
.withPathsGroupedBy(GroupBy.TAGS) //<4>
|
||||
.build(); //<5>
|
||||
@@ -161,4 +160,4 @@ public class DocumentationTest {
|
||||
.build();
|
||||
// end::swagger2MarkupConfigFromCommonsConfiguration[]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 Robert Winkler
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,7 +15,10 @@
|
||||
*/
|
||||
package io.github.swagger2markup;
|
||||
|
||||
import io.github.swagger2markup.assertions.DiffUtils;
|
||||
import io.github.swagger2markup.builder.Swagger2MarkupConfigBuilder;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -37,10 +40,31 @@ public class GeneralConverterTest {
|
||||
private List<String> expectedFiles;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
public void setUp(){
|
||||
expectedFiles = new ArrayList<>(asList(EXPECTED_FILES));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToFileWithoutExtension() throws IOException, URISyntaxException {
|
||||
//Given
|
||||
String swaggerJsonString = IOUtils.toString(getClass().getResourceAsStream("/yaml/swagger_petstore.yaml"));
|
||||
Path outputFile = Paths.get("build/test/asciidoc/toFile/outputFile.adoc");
|
||||
|
||||
//When
|
||||
Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
|
||||
.withGeneratedExamples()
|
||||
.build();
|
||||
|
||||
Swagger2MarkupConverter.from(swaggerJsonString)
|
||||
.withConfig(config)
|
||||
.build()
|
||||
.toFileWithoutExtension(outputFile);
|
||||
|
||||
//Then
|
||||
Path expectedFile = Paths.get(AsciidocConverterTest.class.getResource("/expected/asciidoc/toFile/outputFile.adoc").toURI());
|
||||
DiffUtils.assertThatFileIsEqual(expectedFile, outputFile, "testOutputFile.html");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFromHttpURI() throws IOException, URISyntaxException {
|
||||
//Given
|
||||
@@ -48,8 +72,8 @@ public class GeneralConverterTest {
|
||||
FileUtils.deleteQuietly(outputDirectory.toFile());
|
||||
|
||||
//When
|
||||
Swagger2MarkupConverter.from(URI.create("https://petstore.swagger.io/v2/swagger.json")).build()
|
||||
.toFolder(outputDirectory);
|
||||
Swagger2MarkupConverter.from(URI.create("http://petstore.swagger.io/v2/swagger.json")).build()
|
||||
.toFolder(outputDirectory);
|
||||
|
||||
//Then
|
||||
String[] files = outputDirectory.toFile().list();
|
||||
@@ -108,12 +132,12 @@ public class GeneralConverterTest {
|
||||
FileUtils.deleteQuietly(outputDirectory.toFile());
|
||||
|
||||
//When
|
||||
Swagger2MarkupConverter.from(new URL("https://petstore.swagger.io/v2/swagger.json")).build()
|
||||
.toFolder(outputDirectory);
|
||||
Swagger2MarkupConverter.from(new URL("http://petstore.swagger.io/v2/swagger.json")).build()
|
||||
.toFolder(outputDirectory);
|
||||
|
||||
//Then
|
||||
String[] files = outputDirectory.toFile().list();
|
||||
assertThat(files).hasSize(4).containsAll(expectedFiles);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 Robert Winkler
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,6 +21,7 @@ import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import io.github.swagger2markup.assertions.DiffUtils;
|
||||
import io.github.swagger2markup.builder.Swagger2MarkupConfigBuilder;
|
||||
import io.github.swagger2markup.markup.builder.MarkupLanguage;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -47,6 +48,144 @@ public class MarkdownConverterTest {
|
||||
private static final String[] EXPECTED_FILES = new String[]{"definitions.md", "overview.md", "paths.md", "security.md"};
|
||||
private List<String> expectedFiles;
|
||||
|
||||
@Before
|
||||
public void setUp(){
|
||||
expectedFiles = new ArrayList<>(asList(EXPECTED_FILES));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSwagger2MarkdownConversion() throws IOException, URISyntaxException {
|
||||
//Given
|
||||
Path file = Paths.get(MarkdownConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI());
|
||||
Path outputDirectory = Paths.get("build/test/markdown/default");
|
||||
FileUtils.deleteQuietly(outputDirectory.toFile());
|
||||
|
||||
//When
|
||||
Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
|
||||
.withMarkupLanguage(MarkupLanguage.MARKDOWN)
|
||||
.build();
|
||||
Swagger2MarkupConverter.from(file)
|
||||
.withConfig(config)
|
||||
.build()
|
||||
.toFolder(outputDirectory);
|
||||
|
||||
//Then
|
||||
String[] files = outputDirectory.toFile().list();
|
||||
assertThat(files).hasSize(4).containsAll(expectedFiles);
|
||||
|
||||
Path expectedFilesDirectory = Paths.get(AsciidocConverterTest.class.getResource("/expected/markdown/default").toURI());
|
||||
DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testSwagger2MarkdownConversion.html");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSwagger2MarkdownConversionWithInterDocumentCrossReferences() throws IOException, URISyntaxException {
|
||||
//Given
|
||||
Path file = Paths.get(AsciidocConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI());
|
||||
Path outputDirectory = Paths.get("build/test/markdown/idxref");
|
||||
FileUtils.deleteQuietly(outputDirectory.toFile());
|
||||
|
||||
//When
|
||||
Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
|
||||
.withMarkupLanguage(MarkupLanguage.MARKDOWN)
|
||||
.withInterDocumentCrossReferences()
|
||||
.build();
|
||||
|
||||
Swagger2MarkupConverter.from(file).withConfig(config).build()
|
||||
.toFolder(outputDirectory);
|
||||
|
||||
//Then
|
||||
String[] files = outputDirectory.toFile().list();
|
||||
assertThat(files).hasSize(4).containsAll(expectedFiles);
|
||||
|
||||
Path expectedFilesDirectory = Paths.get(AsciidocConverterTest.class.getResource("/expected/markdown/idxref").toURI());
|
||||
DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testSwagger2MarkdownConversionWithInterDocumentCrossReferences.html");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSwagger2MarkdownConversionWithSeparatedDefinitions() throws IOException, URISyntaxException {
|
||||
//Given
|
||||
Path file = Paths.get(MarkdownConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI());
|
||||
Path outputDirectory = Paths.get("build/test/markdown/generated");
|
||||
FileUtils.deleteQuietly(outputDirectory.toFile());
|
||||
|
||||
//When
|
||||
Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
|
||||
.withSeparatedDefinitions()
|
||||
.withMarkupLanguage(MarkupLanguage.MARKDOWN)
|
||||
.build();
|
||||
Swagger2MarkupConverter.from(file)
|
||||
.withConfig(config)
|
||||
.build()
|
||||
.toFolder(outputDirectory);
|
||||
|
||||
//Then
|
||||
String[] files = outputDirectory.toFile().list();
|
||||
expectedFiles.add("definitions");
|
||||
assertThat(files).hasSize(5).containsAll(expectedFiles);
|
||||
|
||||
Path definitionsDirectory = outputDirectory.resolve("definitions");
|
||||
String[] definitions = definitionsDirectory.toFile().list();
|
||||
assertThat(definitions).hasSize(5).containsAll(
|
||||
asList("Category.md", "Order.md", "Pet.md", "Tag.md", "User.md"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSwagger2MarkdownConversionWithResponseHeaders() throws IOException, URISyntaxException {
|
||||
//Given
|
||||
Path file = Paths.get(AsciidocConverterTest.class.getResource("/yaml/swagger_response_headers.yaml").toURI());
|
||||
Path outputDirectory = Paths.get("build/test/markdown/response_headers");
|
||||
FileUtils.deleteQuietly(outputDirectory.toFile());
|
||||
|
||||
//When
|
||||
Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
|
||||
.withMarkupLanguage(MarkupLanguage.MARKDOWN)
|
||||
.build();
|
||||
Swagger2MarkupConverter.from(file)
|
||||
.withConfig(config)
|
||||
.build()
|
||||
.toFolder(outputDirectory);
|
||||
|
||||
//Then
|
||||
String[] files = outputDirectory.toFile().list();
|
||||
assertThat(files).hasSize(4).containsAll(expectedFiles);
|
||||
|
||||
Path expectedFilesDirectory = Paths.get(AsciidocConverterTest.class.getResource("/expected/markdown/response_headers").toURI());
|
||||
DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testSwagger2MarkdownConversionWithResponseHeaders.html");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSwagger2MarkdownConversionHandlesComposition() throws IOException, URISyntaxException {
|
||||
//Given
|
||||
Path file = Paths.get(MarkdownConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI());
|
||||
Path outputDirectory = Paths.get("build/test/markdown/generated");
|
||||
FileUtils.deleteQuietly(outputDirectory.toFile());
|
||||
|
||||
//When
|
||||
Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
|
||||
.withSeparatedDefinitions()
|
||||
.withMarkupLanguage(MarkupLanguage.MARKDOWN)
|
||||
.build();
|
||||
Swagger2MarkupConverter.from(file)
|
||||
.withConfig(config)
|
||||
.build()
|
||||
.toFolder(outputDirectory);
|
||||
|
||||
// Then
|
||||
String[] files = outputDirectory.toFile().list();
|
||||
expectedFiles.add("definitions");
|
||||
assertThat(files).hasSize(5).containsAll(expectedFiles);
|
||||
Path definitionsDirectory = outputDirectory.resolve("definitions");
|
||||
verifyMarkdownContainsFieldsInTables(
|
||||
definitionsDirectory.resolve("User.md").toFile(),
|
||||
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.
|
||||
@@ -58,7 +197,6 @@ public class MarkdownConverterTest {
|
||||
* @throws IOException if the markdown document could not be read
|
||||
*/
|
||||
private static void verifyMarkdownContainsFieldsInTables(File doc, Map<String, Set<String>> fieldsByTable) throws IOException {
|
||||
//TODO: This method is too complex, split it up in smaller methods to increase readability
|
||||
final List<String> lines = Files.readAllLines(doc.toPath(), Charset.defaultCharset());
|
||||
final Map<String, Set<String>> fieldsLeftByTable = Maps.newHashMap();
|
||||
for (Map.Entry<String, Set<String>> entry : fieldsByTable.entrySet()) {
|
||||
@@ -112,192 +250,4 @@ public class MarkdownConverterTest {
|
||||
? line.replace("###", "").trim()
|
||||
: null;
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
expectedFiles = new ArrayList<>(asList(EXPECTED_FILES));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToFolder() throws IOException, URISyntaxException {
|
||||
//Given
|
||||
Path file = Paths.get(MarkdownConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI());
|
||||
Path outputDirectory = Paths.get("build/test/markdown/to_folder");
|
||||
FileUtils.deleteQuietly(outputDirectory.toFile());
|
||||
|
||||
//When
|
||||
Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
|
||||
.withMarkupLanguage(MarkupLanguage.MARKDOWN)
|
||||
.build();
|
||||
Swagger2MarkupConverter.from(file)
|
||||
.withConfig(config)
|
||||
.build()
|
||||
.toFolder(outputDirectory);
|
||||
|
||||
//Then
|
||||
String[] files = outputDirectory.toFile().list();
|
||||
assertThat(files).hasSize(4).containsAll(expectedFiles);
|
||||
|
||||
Path expectedFilesDirectory = Paths.get(AsciidocConverterTest.class.getResource("/expected/markdown/to_folder").toURI());
|
||||
DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testToFolder.html");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithMinMaxItems() throws IOException, URISyntaxException {
|
||||
//Given
|
||||
Path file = Paths.get(MarkdownConverterTest.class.getResource("/yaml/swagger_petstore_min_max_items.yaml").toURI());
|
||||
Path outputDirectory = Paths.get("build/test/markdown/to_folder");
|
||||
FileUtils.deleteQuietly(outputDirectory.toFile());
|
||||
|
||||
//When
|
||||
Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
|
||||
.withMarkupLanguage(MarkupLanguage.MARKDOWN)
|
||||
.build();
|
||||
Swagger2MarkupConverter.from(file)
|
||||
.withConfig(config)
|
||||
.build()
|
||||
.toFolder(outputDirectory);
|
||||
|
||||
//Then
|
||||
String[] files = outputDirectory.toFile().list();
|
||||
assertThat(files).hasSize(4).containsAll(expectedFiles);
|
||||
|
||||
Path expectedFilesDirectory = Paths.get(AsciidocConverterTest.class.getResource("/expected/markdown/min_max_items").toURI());
|
||||
DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "min_max_items.html");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithInterDocumentCrossReferences() throws IOException, URISyntaxException {
|
||||
//Given
|
||||
Path file = Paths.get(AsciidocConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI());
|
||||
Path outputDirectory = Paths.get("build/test/markdown/idxref");
|
||||
FileUtils.deleteQuietly(outputDirectory.toFile());
|
||||
|
||||
//When
|
||||
Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
|
||||
.withMarkupLanguage(MarkupLanguage.MARKDOWN)
|
||||
.withInterDocumentCrossReferences()
|
||||
.build();
|
||||
|
||||
Swagger2MarkupConverter.from(file).withConfig(config).build()
|
||||
.toFolder(outputDirectory);
|
||||
|
||||
//Then
|
||||
String[] files = outputDirectory.toFile().list();
|
||||
assertThat(files).hasSize(4).containsAll(expectedFiles);
|
||||
|
||||
Path expectedFilesDirectory = Paths.get(AsciidocConverterTest.class.getResource("/expected/markdown/idxref").toURI());
|
||||
DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testWithInterDocumentCrossReferences.html");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithSeparatedDefinitions() throws IOException, URISyntaxException {
|
||||
//Given
|
||||
Path file = Paths.get(MarkdownConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI());
|
||||
Path outputDirectory = Paths.get("build/test/markdown/generated");
|
||||
FileUtils.deleteQuietly(outputDirectory.toFile());
|
||||
|
||||
//When
|
||||
Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
|
||||
.withSeparatedDefinitions()
|
||||
.withMarkupLanguage(MarkupLanguage.MARKDOWN)
|
||||
.build();
|
||||
Swagger2MarkupConverter.from(file)
|
||||
.withConfig(config)
|
||||
.build()
|
||||
.toFolder(outputDirectory);
|
||||
|
||||
//Then
|
||||
String[] files = outputDirectory.toFile().list();
|
||||
expectedFiles.add("definitions");
|
||||
assertThat(files).hasSize(5).containsAll(expectedFiles);
|
||||
|
||||
Path definitionsDirectory = outputDirectory.resolve("definitions");
|
||||
String[] definitions = definitionsDirectory.toFile().list();
|
||||
assertThat(definitions).hasSize(5).containsAll(
|
||||
asList("Category.md", "Order.md", "Pet.md", "Tag.md", "User.md"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithResponseHeaders() throws IOException, URISyntaxException {
|
||||
//Given
|
||||
Path file = Paths.get(AsciidocConverterTest.class.getResource("/yaml/swagger_response_headers.yaml").toURI());
|
||||
Path outputDirectory = Paths.get("build/test/markdown/response_headers");
|
||||
FileUtils.deleteQuietly(outputDirectory.toFile());
|
||||
|
||||
//When
|
||||
Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
|
||||
.withMarkupLanguage(MarkupLanguage.MARKDOWN)
|
||||
.build();
|
||||
Swagger2MarkupConverter.from(file)
|
||||
.withConfig(config)
|
||||
.build()
|
||||
.toFolder(outputDirectory);
|
||||
|
||||
//Then
|
||||
String[] files = outputDirectory.toFile().list();
|
||||
assertThat(files).hasSize(4).containsAll(expectedFiles);
|
||||
|
||||
Path expectedFilesDirectory = Paths.get(AsciidocConverterTest.class.getResource("/expected/markdown/response_headers").toURI());
|
||||
DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testWithResponseHeaders.html");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandlesComposition() throws IOException, URISyntaxException {
|
||||
//Given
|
||||
Path file = Paths.get(MarkdownConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI());
|
||||
Path outputDirectory = Paths.get("build/test/markdown/generated");
|
||||
FileUtils.deleteQuietly(outputDirectory.toFile());
|
||||
|
||||
//When
|
||||
Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
|
||||
.withSeparatedDefinitions()
|
||||
.withMarkupLanguage(MarkupLanguage.MARKDOWN)
|
||||
.build();
|
||||
Swagger2MarkupConverter.from(file)
|
||||
.withConfig(config)
|
||||
.build()
|
||||
.toFolder(outputDirectory);
|
||||
|
||||
// Then
|
||||
String[] files = outputDirectory.toFile().list();
|
||||
expectedFiles.add("definitions");
|
||||
assertThat(files).hasSize(5).containsAll(expectedFiles);
|
||||
Path definitionsDirectory = outputDirectory.resolve("definitions");
|
||||
verifyMarkdownContainsFieldsInTables(
|
||||
definitionsDirectory.resolve("User.md").toFile(),
|
||||
ImmutableMap.<String, Set<String>>builder()
|
||||
.put("User", ImmutableSet.of("id", "username", "firstName",
|
||||
"lastName", "email", "password", "phone", "userStatus"))
|
||||
.build()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFreeFormWithEmptyCurlyBracket() throws IOException, URISyntaxException {
|
||||
//Given
|
||||
Path file = Paths.get(MarkdownConverterTest.class.getResource("/yaml/swagger_freeform_with_emtpy_curly_brackets.yaml").toURI());
|
||||
Path outputDirectory = Paths.get("build/test/markdown/freeform");
|
||||
FileUtils.deleteQuietly(outputDirectory.toFile());
|
||||
|
||||
//When
|
||||
Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
|
||||
.withSeparatedDefinitions()
|
||||
.withMarkupLanguage(MarkupLanguage.MARKDOWN)
|
||||
.build();
|
||||
Swagger2MarkupConverter.from(file)
|
||||
.withConfig(config)
|
||||
.build()
|
||||
.toFolder(outputDirectory);
|
||||
|
||||
// Then
|
||||
String[] files = outputDirectory.toFile().list();
|
||||
expectedFiles.add("definitions");
|
||||
assertThat(files).hasSize(5).containsAll(expectedFiles);
|
||||
|
||||
Path expectedFilesDirectory = Paths.get(MarkdownConverterTest.class.getResource("/expected/markdown/freeform").toURI());
|
||||
DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "freeform.html");
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2017 Robert Winkler
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 Robert Winkler
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,8 +15,8 @@
|
||||
*/
|
||||
package io.github.swagger2markup.builder;
|
||||
|
||||
import io.github.swagger2markup.Schema2MarkupProperties;
|
||||
import io.github.swagger2markup.Swagger2MarkupConverter;
|
||||
import io.github.swagger2markup.Swagger2MarkupProperties;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import io.github.swagger2markup.markup.builder.MarkupLanguage;
|
||||
import io.github.swagger2markup.spi.DefinitionsDocumentExtension;
|
||||
@@ -32,11 +32,11 @@ public class MyExtension extends DefinitionsDocumentExtension {
|
||||
private String extensionProperty;
|
||||
|
||||
@Override
|
||||
public void init(Swagger2MarkupConverter.SwaggerContext globalContext) {
|
||||
public void init(Swagger2MarkupConverter.Context globalContext) {
|
||||
// init is executed once
|
||||
Schema2MarkupProperties extensionProperties = globalContext.getConfig().getExtensionsProperties(); //<1>
|
||||
Swagger2MarkupProperties extensionProperties = globalContext.getConfig().getExtensionsProperties(); //<1>
|
||||
extensionProperty = extensionProperties.getRequiredString(EXTENSION_ID + ".propertyName");
|
||||
Swagger model = globalContext.getSchema();
|
||||
Swagger model = globalContext.getSwagger();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -46,7 +46,7 @@ public class MyExtension extends DefinitionsDocumentExtension {
|
||||
String definitionName = context.getDefinitionName().get();
|
||||
Model definitionModel = context.getModel().get();
|
||||
|
||||
if (position.equals(Position.DEFINITION_END)) {
|
||||
if(position.equals(Position.DEFINITION_END)) {
|
||||
markupBuilder.sectionTitleLevel1(definitionName) //<4>
|
||||
.paragraph(definitionModel.getDescription())
|
||||
.importMarkup(new StringReader("*Markup*"), MarkupLanguage.ASCIIDOC);
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 Robert Winkler
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 Robert Winkler
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,16 +16,11 @@
|
||||
package io.github.swagger2markup.builder;
|
||||
|
||||
import com.google.common.collect.Ordering;
|
||||
import io.github.swagger2markup.Swagger2MarkupConfig;
|
||||
import io.github.swagger2markup.Swagger2MarkupProperties;
|
||||
import io.github.swagger2markup.GroupBy;
|
||||
import io.github.swagger2markup.Language;
|
||||
import io.github.swagger2markup.OrderBy;
|
||||
import io.github.swagger2markup.*;
|
||||
import io.github.swagger2markup.markup.builder.MarkupLanguage;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
@@ -40,7 +35,6 @@ public class Swagger2MarkupConfigBuilderTest {
|
||||
configMap.put(Swagger2MarkupProperties.MARKUP_LANGUAGE, MarkupLanguage.MARKDOWN.toString());
|
||||
configMap.put("swagger2markup.extensions.uniqueId1.customProperty1", "123");
|
||||
configMap.put("swagger2markup.extensions.uniqueId1.customProperty2", "123");
|
||||
configMap.put("swagger2markup.extensions.uniqueId2.customPropertyList1", "123,456");
|
||||
configMap.put("swagger2markup.uniqueId1.customProperty1", "123");
|
||||
configMap.put("swagger2markup.uniqueId1.customProperty2", "123");
|
||||
|
||||
@@ -54,10 +48,10 @@ public class Swagger2MarkupConfigBuilderTest {
|
||||
assertThat(config.isGeneratedExamplesEnabled()).isFalse();
|
||||
assertThat(config.isInlineSchemaEnabled()).isEqualTo(true);
|
||||
assertThat(config.getInterDocumentCrossReferencesPrefix()).isNull();
|
||||
assertThat(config.getMarkupLanguage().name()).isEqualTo(MarkupLanguage.MARKDOWN.name());
|
||||
assertThat(config.getMarkupLanguage()).isEqualTo(MarkupLanguage.MARKDOWN);
|
||||
assertThat(config.getOperationOrderBy()).isEqualTo(OrderBy.NATURAL);
|
||||
assertThat(config.getOperationOrdering()).isNotNull();
|
||||
assertThat(config.getLanguage()).isEqualTo(Language.EN);
|
||||
assertThat(config.getOutputLanguage()).isEqualTo(Language.EN);
|
||||
assertThat(config.getOverviewDocument()).isEqualTo("overview");
|
||||
assertThat(config.getParameterOrderBy()).isEqualTo(OrderBy.NATURAL);
|
||||
assertThat(config.getParameterOrdering()).isEqualTo(Swagger2MarkupConfigBuilder.PARAMETER_IN_NATURAL_ORDERING.compound(Swagger2MarkupConfigBuilder.PARAMETER_NAME_NATURAL_ORDERING));
|
||||
@@ -73,18 +67,13 @@ public class Swagger2MarkupConfigBuilderTest {
|
||||
assertThat(config.getTagOrderBy()).isEqualTo(OrderBy.NATURAL);
|
||||
assertThat(config.getTagOrdering()).isEqualTo(Ordering.natural());
|
||||
assertThat(config.isFlatBodyEnabled()).isFalse();
|
||||
assertThat(config.isPathSecuritySectionEnabled()).isTrue();
|
||||
assertThat(config.isInterDocumentCrossReferencesEnabled()).isFalse();
|
||||
assertThat(config.isSeparatedDefinitionsEnabled()).isFalse();
|
||||
assertThat(config.isSeparatedOperationsEnabled()).isFalse();
|
||||
assertThat(config.getExtensionsProperties().getKeys()).hasSize(3)
|
||||
.containsOnly("uniqueId1.customProperty1",
|
||||
"uniqueId1.customProperty2",
|
||||
"uniqueId2.customPropertyList1"
|
||||
assertThat(config.getExtensionsProperties().getKeys()).hasSize(2)
|
||||
.containsOnly("uniqueId1.customProperty1",
|
||||
"uniqueId1.customProperty2"
|
||||
);
|
||||
assertThat(config.getExtensionsProperties().getString("uniqueId1.customProperty1").get()).isEqualTo("123");
|
||||
assertThat(config.getExtensionsProperties().getPathList("uniqueId2.customPropertyList1")).hasSize(1)
|
||||
.containsOnly(Paths.get("123,456"));
|
||||
}
|
||||
|
||||
|
||||
@@ -101,13 +90,12 @@ public class Swagger2MarkupConfigBuilderTest {
|
||||
assertThat(config.getDefinitionOrdering()).isNull();
|
||||
assertThat(config.getDefinitionsDocument()).isEqualTo("definitionsTest");
|
||||
assertThat(config.isGeneratedExamplesEnabled()).isTrue();
|
||||
assertThat(config.isHostnameEnabled()).isEqualTo(false);
|
||||
assertThat(config.isInlineSchemaEnabled()).isEqualTo(false);
|
||||
assertThat(config.getInterDocumentCrossReferencesPrefix()).isEqualTo("xrefPrefix");
|
||||
assertThat(config.getMarkupLanguage().name()).isEqualTo(MarkupLanguage.MARKDOWN.name());
|
||||
assertThat(config.getMarkupLanguage()).isEqualTo(MarkupLanguage.MARKDOWN);
|
||||
assertThat(config.getOperationOrderBy()).isEqualTo(OrderBy.NATURAL);
|
||||
assertThat(config.getOperationOrdering()).isEqualTo(Swagger2MarkupConfigBuilder.OPERATION_PATH_NATURAL_ORDERING.compound(Swagger2MarkupConfigBuilder.OPERATION_METHOD_NATURAL_ORDERING));
|
||||
assertThat(config.getLanguage()).isEqualTo(Language.RU);
|
||||
assertThat(config.getOutputLanguage()).isEqualTo(Language.RU);
|
||||
assertThat(config.getOverviewDocument()).isEqualTo("overviewTest");
|
||||
assertThat(config.getParameterOrderBy()).isEqualTo(OrderBy.AS_IS);
|
||||
assertThat(config.getParameterOrdering()).isNull();
|
||||
@@ -120,24 +108,18 @@ public class Swagger2MarkupConfigBuilderTest {
|
||||
assertThat(config.getSecurityDocument()).isEqualTo("securityTest");
|
||||
assertThat(config.getSeparatedDefinitionsFolder()).isEqualTo("definitionsTest");
|
||||
assertThat(config.getSeparatedOperationsFolder()).isEqualTo("operationsTest");
|
||||
assertThat(config.isListDelimiterEnabled()).isEqualTo(true);
|
||||
assertThat(config.getListDelimiter()).isEqualTo(Character.valueOf('|'));
|
||||
assertThat(config.getTagOrderBy()).isEqualTo(OrderBy.AS_IS);
|
||||
assertThat(config.getTagOrdering()).isNull();
|
||||
assertThat(config.isFlatBodyEnabled()).isTrue();
|
||||
assertThat(config.isPathSecuritySectionEnabled()).isFalse();
|
||||
assertThat(config.isInterDocumentCrossReferencesEnabled()).isTrue();
|
||||
assertThat(config.isSeparatedDefinitionsEnabled()).isTrue();
|
||||
assertThat(config.isSeparatedOperationsEnabled()).isTrue();
|
||||
assertThat(config.getExtensionsProperties().getKeys()).hasSize(5)
|
||||
.containsOnly("uniqueId1.customProperty1",
|
||||
"uniqueId1.customProperty2",
|
||||
"uniqueId2.customProperty1",
|
||||
"uniqueId2.customProperty2",
|
||||
"uniqueId2.customPropertyList1"
|
||||
);
|
||||
assertThat(config.getExtensionsProperties().getPathList("uniqueId2.customPropertyList1")).hasSize(2)
|
||||
.containsOnly(Paths.get("123"), Paths.get("456"));
|
||||
assertThat(config.getExtensionsProperties().getKeys()).hasSize(4)
|
||||
.containsOnly("uniqueId1.customProperty1",
|
||||
"uniqueId1.customProperty2",
|
||||
"uniqueId2.customProperty1",
|
||||
"uniqueId2.customProperty2"
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -150,10 +132,8 @@ public class Swagger2MarkupConfigBuilderTest {
|
||||
assertThat(e.getMessage()).isEqualTo("You must provide a custom comparator if orderBy == OrderBy.CUSTOM");
|
||||
}
|
||||
builder.withTagOrdering(Ordering.<String>natural());
|
||||
|
||||
Swagger2MarkupConfig config = builder.build();
|
||||
assertThat(config.getTagOrderBy()).isEqualTo(OrderBy.CUSTOM);
|
||||
assertThat(config.getTagOrdering()).isEqualTo(Ordering.natural());
|
||||
assertThat(builder.config.getTagOrderBy()).isEqualTo(OrderBy.CUSTOM);
|
||||
assertThat(builder.config.getTagOrdering()).isEqualTo(Ordering.natural());
|
||||
|
||||
try {
|
||||
builder.withOperationOrdering(OrderBy.CUSTOM);
|
||||
@@ -161,9 +141,8 @@ public class Swagger2MarkupConfigBuilderTest {
|
||||
assertThat(e.getMessage()).isEqualTo("You must provide a custom comparator if orderBy == OrderBy.CUSTOM");
|
||||
}
|
||||
builder.withOperationOrdering(Swagger2MarkupConfigBuilder.OPERATION_PATH_NATURAL_ORDERING);
|
||||
config = builder.build();
|
||||
assertThat(config.getOperationOrderBy()).isEqualTo(OrderBy.CUSTOM);
|
||||
assertThat(config.getOperationOrdering()).isEqualTo(Swagger2MarkupConfigBuilder.OPERATION_PATH_NATURAL_ORDERING);
|
||||
assertThat(builder.config.getOperationOrderBy()).isEqualTo(OrderBy.CUSTOM);
|
||||
assertThat(builder.config.getOperationOrdering()).isEqualTo(Swagger2MarkupConfigBuilder.OPERATION_PATH_NATURAL_ORDERING);
|
||||
|
||||
try {
|
||||
builder.withDefinitionOrdering(OrderBy.CUSTOM);
|
||||
@@ -171,9 +150,8 @@ public class Swagger2MarkupConfigBuilderTest {
|
||||
assertThat(e.getMessage()).isEqualTo("You must provide a custom comparator if orderBy == OrderBy.CUSTOM");
|
||||
}
|
||||
builder.withDefinitionOrdering(Ordering.<String>natural());
|
||||
config = builder.build();
|
||||
assertThat(config.getDefinitionOrderBy()).isEqualTo(OrderBy.CUSTOM);
|
||||
assertThat(config.getDefinitionOrdering()).isEqualTo(Ordering.natural());
|
||||
assertThat(builder.config.getDefinitionOrderBy()).isEqualTo(OrderBy.CUSTOM);
|
||||
assertThat(builder.config.getDefinitionOrdering()).isEqualTo(Ordering.natural());
|
||||
|
||||
try {
|
||||
builder.withParameterOrdering(OrderBy.CUSTOM);
|
||||
@@ -181,9 +159,8 @@ public class Swagger2MarkupConfigBuilderTest {
|
||||
assertThat(e.getMessage()).isEqualTo("You must provide a custom comparator if orderBy == OrderBy.CUSTOM");
|
||||
}
|
||||
builder.withParameterOrdering(Swagger2MarkupConfigBuilder.PARAMETER_NAME_NATURAL_ORDERING);
|
||||
config = builder.build();
|
||||
assertThat(config.getParameterOrderBy()).isEqualTo(OrderBy.CUSTOM);
|
||||
assertThat(config.getParameterOrdering()).isEqualTo(Swagger2MarkupConfigBuilder.PARAMETER_NAME_NATURAL_ORDERING);
|
||||
assertThat(builder.config.getParameterOrderBy()).isEqualTo(OrderBy.CUSTOM);
|
||||
assertThat(builder.config.getParameterOrdering()).isEqualTo(Swagger2MarkupConfigBuilder.PARAMETER_NAME_NATURAL_ORDERING);
|
||||
|
||||
try {
|
||||
builder.withPropertyOrdering(OrderBy.CUSTOM);
|
||||
@@ -191,9 +168,8 @@ public class Swagger2MarkupConfigBuilderTest {
|
||||
assertThat(e.getMessage()).isEqualTo("You must provide a custom comparator if orderBy == OrderBy.CUSTOM");
|
||||
}
|
||||
builder.withPropertyOrdering(Ordering.<String>natural());
|
||||
config = builder.build();
|
||||
assertThat(config.getPropertyOrderBy()).isEqualTo(OrderBy.CUSTOM);
|
||||
assertThat(config.getPropertyOrdering()).isEqualTo(Ordering.natural());
|
||||
assertThat(builder.config.getPropertyOrderBy()).isEqualTo(OrderBy.CUSTOM);
|
||||
assertThat(builder.config.getPropertyOrdering()).isEqualTo(Ordering.natural());
|
||||
|
||||
try {
|
||||
builder.withResponseOrdering(OrderBy.CUSTOM);
|
||||
@@ -201,28 +177,8 @@ public class Swagger2MarkupConfigBuilderTest {
|
||||
assertThat(e.getMessage()).isEqualTo("You must provide a custom comparator if orderBy == OrderBy.CUSTOM");
|
||||
}
|
||||
builder.withResponseOrdering(Ordering.<String>natural());
|
||||
config = builder.build();
|
||||
assertThat(config.getResponseOrderBy()).isEqualTo(OrderBy.CUSTOM);
|
||||
assertThat(config.getResponseOrdering()).isEqualTo(Ordering.natural());
|
||||
|
||||
assertThat(config.isListDelimiterEnabled()).isEqualTo(false);
|
||||
builder.withListDelimiter();
|
||||
config = builder.build();
|
||||
assertThat(config.getListDelimiter()).isEqualTo(Character.valueOf(','));
|
||||
assertThat(config.isListDelimiterEnabled()).isEqualTo(true);
|
||||
|
||||
assertThat(builder.config.getResponseOrderBy()).isEqualTo(OrderBy.CUSTOM);
|
||||
assertThat(builder.config.getResponseOrdering()).isEqualTo(Ordering.natural());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfigBuilderListDelimiter() {
|
||||
Swagger2MarkupConfigBuilder builder = new Swagger2MarkupConfigBuilder();
|
||||
|
||||
builder.withListDelimiter();
|
||||
Swagger2MarkupConfig config = builder.build();
|
||||
assertThat(config.isListDelimiterEnabled()).isEqualTo(true);
|
||||
builder.withListDelimiter(Character.valueOf('|'));
|
||||
config = builder.build();
|
||||
assertThat(config.getListDelimiter()).isEqualTo(Character.valueOf('|'));
|
||||
assertThat(config.isListDelimiterEnabled()).isEqualTo(true);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 Robert Winkler
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package io.github.swagger2markup.builder;
|
||||
|
||||
import io.github.swagger2markup.spi.Swagger2MarkupExtensionRegistry;
|
||||
import io.github.swagger2markup.Swagger2MarkupExtensionRegistry;
|
||||
import io.github.swagger2markup.spi.SwaggerModelExtension;
|
||||
import io.swagger.models.Swagger;
|
||||
import org.junit.Test;
|
||||
@@ -8,7 +8,6 @@ swagger2markup.inlineSchemaEnabled=false
|
||||
swagger2markup.interDocumentCrossReferencesEnabled=true
|
||||
swagger2markup.interDocumentCrossReferencesPrefix=xrefPrefix
|
||||
swagger2markup.flatBodyEnabled=true
|
||||
swagger2markup.pathSecuritySectionEnabled=false
|
||||
swagger2markup.anchorPrefix=anchorPrefix
|
||||
swagger2markup.overviewDocument=overviewTest
|
||||
swagger2markup.pathsDocument=pathsTest
|
||||
@@ -16,8 +15,6 @@ swagger2markup.definitionsDocument=definitionsTest
|
||||
swagger2markup.securityDocument=securityTest
|
||||
swagger2markup.separatedOperationsFolder=operationsTest
|
||||
swagger2markup.separatedDefinitionsFolder=definitionsTest
|
||||
swagger2markup.listDelimiter=|
|
||||
swagger2markup.listDelimiterEnabled=true
|
||||
swagger2markup.tagOrderBy=AS_IS
|
||||
swagger2markup.operationOrderBy=NATURAL
|
||||
swagger2markup.definitionOrderBy=AS_IS
|
||||
@@ -28,5 +25,4 @@ swagger2markup.extensions.uniqueId1.customProperty1=test
|
||||
swagger2markup.extensions.uniqueId1.customProperty2=test
|
||||
swagger2markup.extensions.uniqueId2.customProperty1=test
|
||||
swagger2markup.extensions.uniqueId2.customProperty2=test
|
||||
swagger2markup.extensions.uniqueId2.customPropertyList1=123|456
|
||||
|
||||