Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
052b417fdb | ||
|
|
8f16457e49 | ||
|
|
2d8f46f5f6 | ||
|
|
2886d30dec | ||
|
|
282e74becb | ||
|
|
164b1ad2a8 |
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
|
||||
1
.gitignore
vendored
@@ -6,3 +6,4 @@ build
|
||||
/.classpath
|
||||
/.project
|
||||
/.settings/
|
||||
/out/
|
||||
@@ -1,6 +1,6 @@
|
||||
language: java
|
||||
jdk:
|
||||
- openjdk8
|
||||
- oraclejdk8
|
||||
before_install:
|
||||
- chmod +x gradlew
|
||||
after_success:
|
||||
|
||||
17
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.3.1/[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]
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -117,7 +102,6 @@
|
||||
* 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.
|
||||
@@ -131,10 +115,6 @@
|
||||
* 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
|
||||
@@ -152,21 +132,3 @@
|
||||
|
||||
=== 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)
|
||||
|
||||
|
||||
|
||||
153
build.gradle
@@ -1,117 +1,70 @@
|
||||
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.3.2-SNAPSHOT'
|
||||
ext.releaseVersion = '1.3.1'
|
||||
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 plugin: 'eclipse'
|
||||
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.1.1'
|
||||
compile 'io.swagger:swagger-compat-spec-parser:1.0.25'
|
||||
compile 'org.apache.commons:commons-configuration2:2.1'
|
||||
compile 'commons-beanutils:commons-beanutils:1.9.2'
|
||||
compile 'org.apache.commons:commons-collections4:4.1'
|
||||
compile 'io.javaslang:javaslang:2.0.5'
|
||||
compile 'ch.netzwerg:paleo-core:0.10.2'
|
||||
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.5.2'
|
||||
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'
|
||||
}
|
||||
|
||||
|
||||
task wrapper(type: Wrapper) {
|
||||
gradleVersion = '3.3'
|
||||
}
|
||||
|
||||
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'
|
||||
}
|
||||
35
gradle/documentation.gradle
Normal file
@@ -0,0 +1,35 @@
|
||||
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: '',
|
||||
'release-version': project.releaseVersion
|
||||
]
|
||||
}
|
||||
|
||||
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.releaseVersion
|
||||
}
|
||||
}
|
||||
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 Jan 05 14:27:30 CET 2017
|
||||
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-3.3-bin.zip
|
||||
|
||||
23
gradlew
vendored
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env sh
|
||||
#!/usr/bin/env bash
|
||||
|
||||
##############################################################################
|
||||
##
|
||||
@@ -33,11 +33,11 @@ DEFAULT_JVM_OPTS=""
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD="maximum"
|
||||
|
||||
warn () {
|
||||
warn ( ) {
|
||||
echo "$*"
|
||||
}
|
||||
|
||||
die () {
|
||||
die ( ) {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
@@ -154,19 +154,16 @@ 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 "$@")
|
||||
|
||||
# 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"
|
||||
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
|
||||
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
|
||||
|
||||
# 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
|
||||
if [[ "$(uname)" == "Darwin" ]] && [[ "$HOME" == "$PWD" ]]; then
|
||||
cd "$(dirname "$0")"
|
||||
fi
|
||||
|
||||
exec "$JAVACMD" "$@"
|
||||
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
|
||||
|
||||
@@ -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'
|
||||
@@ -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
|
||||
|
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 |
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
@@ -139,6 +139,7 @@ The following tables list all available properties of Swagger2Markup:
|
||||
|swagger2markup.pathsGroupedBy| Specifies how the paths should be grouped | AS_IS, TAGS, REGEX | 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 |
|
||||
@@ -183,7 +184,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"]
|
||||
@@ -200,59 +201,6 @@ The following tables list all available properties of Swagger2Markup:
|
||||
|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.
|
||||
14
src/main/java/io/github/swagger2markup/ExampleType.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package io.github.swagger2markup;
|
||||
|
||||
/**
|
||||
* swagger2markup (c) Duco Hosting
|
||||
* Created by cas on 02-Oct-17.
|
||||
*/
|
||||
public enum ExampleType {
|
||||
QUERY,
|
||||
POST,
|
||||
HEADER,
|
||||
PATH,
|
||||
BODY,
|
||||
OTHER
|
||||
}
|
||||
@@ -15,9 +15,6 @@
|
||||
*/
|
||||
package io.github.swagger2markup;
|
||||
|
||||
/**
|
||||
* GroupBy enum for ordering
|
||||
*/
|
||||
public enum GroupBy {
|
||||
AS_IS,
|
||||
TAGS,
|
||||
@@ -15,10 +15,9 @@
|
||||
*/
|
||||
package io.github.swagger2markup;
|
||||
|
||||
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public class SwaggerLabels extends Labels {
|
||||
public class Labels {
|
||||
|
||||
public static final String DEFAULT_COLUMN = "default_column";
|
||||
public static final String MAXLENGTH_COLUMN = "maxlength_column";
|
||||
@@ -90,15 +89,25 @@ public class SwaggerLabels extends Labels {
|
||||
public static final String BODY_PARAMETER = "body_parameter";
|
||||
public static final String RESPONSES = "responses";
|
||||
public static final String HEADERS_COLUMN = "headers_column";
|
||||
public static final String MIN_ITEMS = "min_items";
|
||||
public static final String MAX_ITEMS = "max_items";
|
||||
public static final String EXAMPLE_REQUEST = "example_request";
|
||||
public static final String EXAMPLE_RESPONSE = "example_response";
|
||||
public static final String HTTP_CODE_COLUMN = "http_code_column";
|
||||
public static final String DEPRECATED_OPERATION = "operation.deprecated";
|
||||
public static final String UNKNOWN = "unknown";
|
||||
|
||||
public SwaggerLabels(Swagger2MarkupConfig config) {
|
||||
super(ResourceBundle.getBundle("io/github/swagger2markup/lang/labels", config.getLanguage().toLocale()));
|
||||
private ResourceBundle resourceBundle;
|
||||
|
||||
public Labels(Swagger2MarkupConfig config) {
|
||||
this.resourceBundle = ResourceBundle.getBundle("io/github/swagger2markup/lang/labels", config.getOutputLanguage().toLocale());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a label for the given key from this resource bundle.
|
||||
*
|
||||
* @param key the key for the desired label
|
||||
* @return the label for the given key
|
||||
*/
|
||||
public String getLabel(String key) {
|
||||
return resourceBundle.getString(key);
|
||||
}
|
||||
}
|
||||
@@ -30,8 +30,7 @@ public enum Language {
|
||||
ZH(Locale.CHINESE),
|
||||
ES(new Locale("es")),
|
||||
BR(new Locale("pt", "BR")),
|
||||
JA(Locale.JAPANESE),
|
||||
PL(new Locale("pl"));
|
||||
JA(Locale.JAPANESE);
|
||||
|
||||
private final Locale lang;
|
||||
|
||||
@@ -15,9 +15,6 @@
|
||||
*/
|
||||
package io.github.swagger2markup;
|
||||
|
||||
/**
|
||||
* Marker interface for PageBreak enums
|
||||
*/
|
||||
public enum PageBreakLocations {
|
||||
BEFORE_OPERATION,
|
||||
BEFORE_OPERATION_DESCRIPTION,
|
||||
@@ -13,11 +13,12 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.github.swagger2markup.config;
|
||||
package io.github.swagger2markup;
|
||||
|
||||
import io.github.swagger2markup.*;
|
||||
import io.github.swagger2markup.model.Parameter;
|
||||
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;
|
||||
import java.util.List;
|
||||
@@ -26,202 +27,141 @@ import java.util.regex.Pattern;
|
||||
/**
|
||||
* Swagger2Markup configuration interface.
|
||||
*/
|
||||
public interface Schema2MarkupConfig {
|
||||
public interface Swagger2MarkupConfig {
|
||||
|
||||
/**
|
||||
* Specifies the markup language which should be used to generate the files.
|
||||
*
|
||||
* @return 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 MarkupLanguage#MARKDOWN} is assumed.
|
||||
*
|
||||
* @return Specifies the markup language used in Swagger descriptions.
|
||||
* By default, {@link io.github.swagger2markup.markup.builder.MarkupLanguage#MARKDOWN} is assumed.
|
||||
*/
|
||||
MarkupLanguage getSchemaMarkupLanguage();
|
||||
MarkupLanguage getSwaggerMarkupLanguage();
|
||||
|
||||
/**
|
||||
* Include generated examples into the documents.
|
||||
*
|
||||
* @return Include generated examples into the documents.
|
||||
*/
|
||||
boolean isGeneratedExamplesEnabled();
|
||||
|
||||
/**
|
||||
* Prepend the hostname to all paths.
|
||||
*
|
||||
* @return Prepend the hostname to all paths.
|
||||
*/
|
||||
boolean isHostnameEnabled();
|
||||
|
||||
/**
|
||||
* Prepend the base path to all paths.
|
||||
*
|
||||
* @return Prepend the base path to all paths.
|
||||
*/
|
||||
boolean isBasePathPrefixEnabled();
|
||||
|
||||
/**
|
||||
* In addition to the Definitions file, also create separate definition files for each model definition.
|
||||
*
|
||||
* @return 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.
|
||||
*
|
||||
* @return 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.
|
||||
*
|
||||
* @return Specifies if the operations should be grouped by tags or stay as-is.
|
||||
*/
|
||||
GroupBy getPathsGroupedBy();
|
||||
|
||||
/**
|
||||
* Specifies labels language of output files.
|
||||
*
|
||||
* @return Specifies labels language of output files.
|
||||
*/
|
||||
Language getLanguage();
|
||||
Language getOutputLanguage();
|
||||
|
||||
/**
|
||||
* Specifies if inline schemas are detailed
|
||||
*
|
||||
* @return Specifies if inline schemas are detailed
|
||||
*/
|
||||
boolean isInlineSchemaEnabled();
|
||||
|
||||
/**
|
||||
* Specifies tag ordering.
|
||||
*
|
||||
* @return Specifies tag ordering.
|
||||
*/
|
||||
OrderBy getTagOrderBy();
|
||||
|
||||
/**
|
||||
* Specifies the regex pattern used for header matching
|
||||
*
|
||||
* @return Specifies the regex pattern used for header matching
|
||||
*/
|
||||
Pattern getHeaderPattern();
|
||||
|
||||
/**
|
||||
* Specifies a custom comparator function to order tags.
|
||||
*
|
||||
* @return Specifies a custom comparator function to order tags.
|
||||
*/
|
||||
Comparator<String> getTagOrdering();
|
||||
|
||||
/**
|
||||
* Specifies operation ordering.
|
||||
*
|
||||
* @return Specifies operation ordering.
|
||||
*/
|
||||
OrderBy getOperationOrderBy();
|
||||
|
||||
/**
|
||||
* Specifies a custom comparator function to order operations.
|
||||
*
|
||||
* @return Specifies a custom comparator function to order operations.
|
||||
*/
|
||||
Comparator<PathOperation> getOperationOrdering();
|
||||
|
||||
/**
|
||||
* Specifies definition ordering.
|
||||
*
|
||||
* @return Specifies definition ordering.
|
||||
*/
|
||||
OrderBy getDefinitionOrderBy();
|
||||
|
||||
/**
|
||||
* Specifies a custom comparator function to order definitions.
|
||||
*
|
||||
* @return Specifies a custom comparator function to order definitions.
|
||||
*/
|
||||
Comparator<String> getDefinitionOrdering();
|
||||
|
||||
/**
|
||||
* Specifies parameter ordering.
|
||||
*
|
||||
* @return Specifies parameter ordering.
|
||||
*/
|
||||
OrderBy getParameterOrderBy();
|
||||
|
||||
/**
|
||||
* Specifies a custom comparator function to order parameters.
|
||||
*
|
||||
* @return Specifies a custom comparator function to order parameters.
|
||||
*/
|
||||
Comparator<Parameter> getParameterOrdering();
|
||||
|
||||
/**
|
||||
* Specifies property ordering.
|
||||
*
|
||||
* @return Specifies property ordering.
|
||||
*/
|
||||
OrderBy getPropertyOrderBy();
|
||||
|
||||
/**
|
||||
* Specifies a custom comparator function to order properties.
|
||||
*
|
||||
* @return Specifies a custom comparator function to order properties.
|
||||
*/
|
||||
Comparator<String> getPropertyOrdering();
|
||||
|
||||
/**
|
||||
* Specifies response ordering.
|
||||
*
|
||||
* @return Specifies response ordering.
|
||||
*/
|
||||
OrderBy getResponseOrderBy();
|
||||
|
||||
/**
|
||||
* Specifies a custom comparator function to order responses.
|
||||
*
|
||||
* @return Specifies a custom comparator function to order responses.
|
||||
*/
|
||||
Comparator<String> getResponseOrdering();
|
||||
|
||||
/**
|
||||
* Enable use of inter-document cross-references when needed.
|
||||
*
|
||||
* @return Enable use of inter-document cross-references when needed.
|
||||
*/
|
||||
boolean isInterDocumentCrossReferencesEnabled();
|
||||
|
||||
/**
|
||||
* Inter-document cross-references optional prefix.
|
||||
*
|
||||
* @return Inter-document cross-references optional prefix.
|
||||
*/
|
||||
String getInterDocumentCrossReferencesPrefix();
|
||||
|
||||
/**
|
||||
* Optionally isolate the body parameter, if any, from other parameters.
|
||||
*
|
||||
* @return Optionally isolate the body parameter, if any, from other parameters.
|
||||
*/
|
||||
boolean isFlatBodyEnabled();
|
||||
|
||||
/**
|
||||
* Optionally disable the security section for path sections
|
||||
*
|
||||
* @return Optionally disable the security section for path sections
|
||||
*/
|
||||
boolean isPathSecuritySectionEnabled();
|
||||
|
||||
/**
|
||||
* Optionally prefix all anchors for uniqueness.
|
||||
*
|
||||
* @return Optionally prefix all anchors for uniqueness.
|
||||
*/
|
||||
String getAnchorPrefix();
|
||||
|
||||
@@ -276,15 +216,13 @@ public interface Schema2MarkupConfig {
|
||||
|
||||
/**
|
||||
* Specifies the array element delimiter to use for multi-valued properties.
|
||||
*
|
||||
* @return the element delimiter if any
|
||||
*/
|
||||
Character getListDelimiter();
|
||||
|
||||
|
||||
/**
|
||||
* Optionally allow lists in property values. Uses the {{@link #getListDelimiter()} to
|
||||
* Optionally allow lists in property values. Uses the {{@link #getListDelimiter()} to
|
||||
* delimit list values.
|
||||
*
|
||||
* @return whether lists are converted to arrays
|
||||
*/
|
||||
boolean isListDelimiterEnabled();
|
||||
@@ -294,7 +232,7 @@ public interface Schema2MarkupConfig {
|
||||
*
|
||||
* @return the extension properties
|
||||
*/
|
||||
Schema2MarkupProperties getExtensionsProperties();
|
||||
Swagger2MarkupProperties getExtensionsProperties();
|
||||
|
||||
/**
|
||||
* Returns the list of page break locations
|
||||
@@ -302,62 +240,4 @@ public interface Schema2MarkupConfig {
|
||||
* @return List of PageBreakLocations
|
||||
*/
|
||||
List<PageBreakLocations> getPageBreakLocations();
|
||||
|
||||
/**
|
||||
* Returns custom timeout value.
|
||||
*
|
||||
* @return custom timeout value
|
||||
*/
|
||||
int getAsciidocPegdownTimeoutMillis();
|
||||
|
||||
/**
|
||||
* Returns format name which should be used to format request example string.
|
||||
*
|
||||
* @return `basic`, `curl` or `invoke-webrequest`
|
||||
*/
|
||||
String getRequestExamplesFormat();
|
||||
|
||||
/**
|
||||
* Returns format name which should be used to highlight source block with request example string
|
||||
*
|
||||
* @return any string or `default`
|
||||
*/
|
||||
String getRequestExamplesSourceFormat();
|
||||
|
||||
/**
|
||||
* Should we output optional query params in source block with request example string
|
||||
*
|
||||
* @return false if example request should contain only required params
|
||||
*/
|
||||
boolean getRequestExamplesIncludeAllQueryParams();
|
||||
|
||||
/**
|
||||
* How we should output array query params:
|
||||
*
|
||||
* @return `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.
|
||||
*/
|
||||
String getRequestExamplesQueryArrayStyle();
|
||||
|
||||
/**
|
||||
* Should we hide, inherit or override hostname (e.g. with google.com) from yml file
|
||||
*
|
||||
* @return `hide`, `inherit` or string with hostname to be used in request example
|
||||
*/
|
||||
String getRequestExamplesHost();
|
||||
|
||||
/**
|
||||
* Should we hide, inherit or override schema (http, https name it) from yml file
|
||||
*
|
||||
* @return `hide`, `inherit` or string with schema name to be used in request example
|
||||
*/
|
||||
String getRequestExamplesSchema();
|
||||
|
||||
/**
|
||||
* Should we hide or show base path in example request endpoint address
|
||||
*
|
||||
* @return true or false
|
||||
*/
|
||||
boolean getRequestExamplesHideBasePath();
|
||||
}
|
||||
@@ -21,11 +21,8 @@ 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.utils.URIUtils;
|
||||
import io.swagger.models.Swagger;
|
||||
import io.swagger.parser.SwaggerParser;
|
||||
@@ -49,20 +46,20 @@ import java.nio.file.StandardOpenOption;
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public class Swagger2MarkupConverter extends AbstractSchema2MarkupConverter<Swagger> {
|
||||
public class Swagger2MarkupConverter {
|
||||
|
||||
private final Context context;
|
||||
private final OverviewDocument overviewDocument;
|
||||
private final PathsDocument pathsDocument;
|
||||
private final DefinitionsDocument definitionsDocument;
|
||||
private final SecurityDocument securityDocument;
|
||||
private final SwaggerContext swaggerContext;
|
||||
|
||||
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);
|
||||
public Swagger2MarkupConverter(Context context) {
|
||||
this.context = context;
|
||||
this.overviewDocument = new OverviewDocument(context);
|
||||
this.pathsDocument = new PathsDocument(context);
|
||||
this.definitionsDocument = new DefinitionsDocument(context);
|
||||
this.securityDocument = new SecurityDocument(context);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -166,8 +163,8 @@ public class Swagger2MarkupConverter extends AbstractSchema2MarkupConverter<Swag
|
||||
*
|
||||
* @return the global Context
|
||||
*/
|
||||
public SwaggerContext getContext() {
|
||||
return swaggerContext;
|
||||
public Context getContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -178,40 +175,40 @@ public class Swagger2MarkupConverter extends AbstractSchema2MarkupConverter<Swag
|
||||
public void toFolder(Path outputDirectory) {
|
||||
Validate.notNull(outputDirectory, "outputDirectory must not be null");
|
||||
|
||||
swaggerContext.setOutputPath(outputDirectory);
|
||||
context.setOutputPath(outputDirectory);
|
||||
|
||||
applyOverviewDocument()
|
||||
.writeToFile(outputDirectory.resolve(swaggerContext.config.getOverviewDocument()), StandardCharsets.UTF_8);
|
||||
.writeToFile(outputDirectory.resolve(context.config.getOverviewDocument()), StandardCharsets.UTF_8);
|
||||
applyPathsDocument()
|
||||
.writeToFile(outputDirectory.resolve(swaggerContext.config.getPathsDocument()), StandardCharsets.UTF_8);
|
||||
.writeToFile(outputDirectory.resolve(context.config.getPathsDocument()), StandardCharsets.UTF_8);
|
||||
applyDefinitionsDocument()
|
||||
.writeToFile(outputDirectory.resolve(swaggerContext.config.getDefinitionsDocument()), StandardCharsets.UTF_8);
|
||||
.writeToFile(outputDirectory.resolve(context.config.getDefinitionsDocument()), StandardCharsets.UTF_8);
|
||||
applySecurityDocument()
|
||||
.writeToFile(outputDirectory.resolve(swaggerContext.config.getSecurityDocument()), StandardCharsets.UTF_8);
|
||||
.writeToFile(outputDirectory.resolve(context.config.getSecurityDocument()), StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
private MarkupDocBuilder applyOverviewDocument() {
|
||||
return overviewDocument.apply(
|
||||
swaggerContext.createMarkupDocBuilder(),
|
||||
OverviewDocument.parameters(swaggerContext.getSchema()));
|
||||
context.createMarkupDocBuilder(),
|
||||
OverviewDocument.parameters(context.getSwagger()));
|
||||
}
|
||||
|
||||
private MarkupDocBuilder applyPathsDocument() {
|
||||
return pathsDocument.apply(
|
||||
swaggerContext.createMarkupDocBuilder(),
|
||||
PathsDocument.parameters(swaggerContext.getSchema().getPaths()));
|
||||
context.createMarkupDocBuilder(),
|
||||
PathsDocument.parameters(context.getSwagger().getPaths()));
|
||||
}
|
||||
|
||||
private MarkupDocBuilder applyDefinitionsDocument() {
|
||||
return definitionsDocument.apply(
|
||||
swaggerContext.createMarkupDocBuilder(),
|
||||
DefinitionsDocument.parameters(swaggerContext.getSchema().getDefinitions()));
|
||||
context.createMarkupDocBuilder(),
|
||||
DefinitionsDocument.parameters(context.getSwagger().getDefinitions()));
|
||||
}
|
||||
|
||||
private MarkupDocBuilder applySecurityDocument() {
|
||||
return securityDocument.apply(
|
||||
swaggerContext.createMarkupDocBuilder(),
|
||||
SecurityDocument.parameters(swaggerContext.getSchema().getSecurityDefinitions()));
|
||||
context.createMarkupDocBuilder(),
|
||||
SecurityDocument.parameters(context.getSwagger().getSecurityDefinitions()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -346,8 +343,8 @@ 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, extensionRegistry, swagger, swaggerLocation);
|
||||
|
||||
initExtensions(context);
|
||||
|
||||
@@ -356,7 +353,7 @@ public class Swagger2MarkupConverter extends AbstractSchema2MarkupConverter<Swag
|
||||
return new Swagger2MarkupConverter(context);
|
||||
}
|
||||
|
||||
private void initExtensions(SwaggerContext context) {
|
||||
private void initExtensions(Context context) {
|
||||
extensionRegistry.getSwaggerModelExtensions().forEach(extension -> extension.setGlobalContext(context));
|
||||
extensionRegistry.getOverviewDocumentExtensions().forEach(extension -> extension.setGlobalContext(context));
|
||||
extensionRegistry.getDefinitionsDocumentExtensions().forEach(extension -> extension.setGlobalContext(context));
|
||||
@@ -364,44 +361,61 @@ public class Swagger2MarkupConverter extends AbstractSchema2MarkupConverter<Swag
|
||||
extensionRegistry.getSecurityDocumentExtensions().forEach(extension -> extension.setGlobalContext(context));
|
||||
}
|
||||
|
||||
private void applySwaggerExtensions(SwaggerContext context) {
|
||||
extensionRegistry.getSwaggerModelExtensions().forEach(extension -> extension.apply(context.getSchema()));
|
||||
private void applySwaggerExtensions(Context context) {
|
||||
extensionRegistry.getSwaggerModelExtensions().forEach(extension -> extension.apply(context.getSwagger()));
|
||||
}
|
||||
}
|
||||
|
||||
public static class SwaggerContext extends Context<Swagger> {
|
||||
private Swagger2MarkupConfig config;
|
||||
private Swagger2MarkupExtensionRegistry extensionRegistry;
|
||||
public static class Context {
|
||||
private final Swagger2MarkupConfig config;
|
||||
private final Swagger swagger;
|
||||
private final URI swaggerLocation;
|
||||
private final Swagger2MarkupExtensionRegistry extensionRegistry;
|
||||
private final Labels labels;
|
||||
private Path outputPath;
|
||||
|
||||
public SwaggerContext(Swagger2MarkupConfig config,
|
||||
Swagger2MarkupExtensionRegistry extensionRegistry,
|
||||
Swagger schema, URI swaggerLocation, Labels labels) {
|
||||
super(config, extensionRegistry, schema, swaggerLocation, labels);
|
||||
public Context(Swagger2MarkupConfig config,
|
||||
Swagger2MarkupExtensionRegistry extensionRegistry,
|
||||
Swagger swagger,
|
||||
URI swaggerLocation) {
|
||||
this.config = config;
|
||||
this.extensionRegistry = extensionRegistry;
|
||||
this.swagger = swagger;
|
||||
this.swaggerLocation = swaggerLocation;
|
||||
this.labels = new Labels(config);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Swagger2MarkupConfig getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Swagger getSwagger() {
|
||||
return swagger;
|
||||
}
|
||||
|
||||
public URI getSwaggerLocation() {
|
||||
return swaggerLocation;
|
||||
}
|
||||
|
||||
public Swagger2MarkupExtensionRegistry getExtensionRegistry() {
|
||||
return extensionRegistry;
|
||||
}
|
||||
|
||||
public Labels getLabels() {
|
||||
return labels;
|
||||
}
|
||||
|
||||
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());
|
||||
return MarkupDocBuilders.documentBuilder(config.getMarkupLanguage(),
|
||||
config.getLineSeparator()).withAnchorPrefix(config.getAnchorPrefix());
|
||||
}
|
||||
|
||||
public Path getOutputPath() {
|
||||
return outputPath;
|
||||
}
|
||||
|
||||
public void setOutputPath(Path outputPath) {
|
||||
this.outputPath = outputPath;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,16 +13,16 @@
|
||||
* 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.
|
||||
*
|
||||
@@ -15,7 +15,9 @@
|
||||
*/
|
||||
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;
|
||||
@@ -28,24 +30,16 @@ import java.nio.file.Paths;
|
||||
import java.util.*;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
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";
|
||||
@@ -74,7 +68,6 @@ public class Schema2MarkupProperties {
|
||||
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,22 +76,18 @@ 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.
|
||||
*
|
||||
@@ -146,7 +135,6 @@ public class Schema2MarkupProperties {
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
@@ -161,7 +149,6 @@ 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
|
||||
*/
|
||||
@@ -196,13 +183,16 @@ public class Schema2MarkupProperties {
|
||||
*/
|
||||
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
|
||||
*/
|
||||
@@ -225,13 +215,17 @@ public class Schema2MarkupProperties {
|
||||
*/
|
||||
public Optional<Path> getPath(String key) {
|
||||
Optional<String> property = getString(key);
|
||||
return property.map(s -> Paths.get(s));
|
||||
if (property.isPresent()) {
|
||||
return Optional.of(Paths.get(property.get()));
|
||||
} else {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of Path property values associated with the given key,
|
||||
* 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
|
||||
@@ -255,7 +249,6 @@ public class Schema2MarkupProperties {
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
@@ -269,22 +262,25 @@ public class Schema2MarkupProperties {
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
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}).
|
||||
* Return the MarkupLanguage 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
|
||||
* @throws IllegalStateException if the key cannot be resolved
|
||||
*/
|
||||
public MarkupLanguage getRequiredMarkupLanguage(String key) {
|
||||
@@ -329,7 +325,6 @@ public class Schema2MarkupProperties {
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
@@ -372,13 +367,17 @@ public class Schema2MarkupProperties {
|
||||
|
||||
public List<PageBreakLocations> getPageBreakLocations(String key) {
|
||||
List<PageBreakLocations> result = configuration.getList(PageBreakLocations.class, key);
|
||||
if (result == null) result = new ArrayList<>();
|
||||
if(result == null) result = new ArrayList<PageBreakLocations>();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public Optional<Pattern> getHeaderPattern(String key) {
|
||||
Optional<String> property = getString(key);
|
||||
return property.map(Pattern::compile);
|
||||
if (property.isPresent()) {
|
||||
return Optional.of(Pattern.compile(property.get()));
|
||||
} else {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,116 +14,112 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.github.swagger2markup.config.builder;
|
||||
package io.github.swagger2markup.builder;
|
||||
|
||||
import com.google.common.collect.Ordering;
|
||||
import io.github.swagger2markup.*;
|
||||
import io.github.swagger2markup.config.*;
|
||||
import io.github.swagger2markup.model.Parameter;
|
||||
import io.github.swagger2markup.markup.builder.LineSeparator;
|
||||
import io.github.swagger2markup.markup.builder.MarkupLanguage;
|
||||
import io.github.swagger2markup.model.PathOperation;
|
||||
import org.apache.commons.configuration2.AbstractConfiguration;
|
||||
import org.apache.commons.configuration2.CompositeConfiguration;
|
||||
import org.apache.commons.configuration2.Configuration;
|
||||
import org.apache.commons.configuration2.SystemConfiguration;
|
||||
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.convert.DefaultListDelimiterHandler;
|
||||
import org.apache.commons.configuration2.ex.ConfigurationException;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.*;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.regex.PatternSyntaxException;
|
||||
|
||||
import static io.github.swagger2markup.Schema2MarkupProperties.*;
|
||||
import static io.github.swagger2markup.Swagger2MarkupProperties.*;
|
||||
|
||||
public abstract class Schema2MarkupConfigBuilder<T extends Schema2MarkupConfigBuilder, C extends Schema2MarkupConfigBuilder.DefaultSchema2MarkupConfig> {
|
||||
public class Swagger2MarkupConfigBuilder {
|
||||
|
||||
public static final Ordering<PathOperation> OPERATION_METHOD_NATURAL_ORDERING = Ordering
|
||||
.explicit("POST", "GET", "PUT",
|
||||
"DELETE", "PATCH", "HEAD", "OPTIONS")
|
||||
.onResultOf(PathOperation::getHttpMethod);
|
||||
public static final Ordering<PathOperation> OPERATION_PATH_NATURAL_ORDERING = Ordering
|
||||
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(PathOperation::getMethod);
|
||||
static final Ordering<PathOperation> OPERATION_PATH_NATURAL_ORDERING = Ordering
|
||||
.natural()
|
||||
.onResultOf(PathOperation::getPath);
|
||||
public static final Ordering<Parameter> PARAMETER_IN_NATURAL_ORDERING = Ordering
|
||||
static final Ordering<Parameter> PARAMETER_IN_NATURAL_ORDERING = Ordering
|
||||
.explicit("header", "path", "query", "formData", "body")
|
||||
.onResultOf(Parameter::getIn);
|
||||
public static final Ordering<Parameter> PARAMETER_NAME_NATURAL_ORDERING = Ordering
|
||||
static final Ordering<Parameter> PARAMETER_NAME_NATURAL_ORDERING = Ordering
|
||||
.natural()
|
||||
.onResultOf(Parameter::getName);
|
||||
private static final String PROPERTIES_DEFAULT = "io/github/swagger2markup/config/default.properties";
|
||||
DefaultSwagger2MarkupConfig config = new DefaultSwagger2MarkupConfig();
|
||||
|
||||
static final String PROPERTIES_DEFAULT = "io/github/swagger2markup/config/default.properties";
|
||||
protected C config;
|
||||
public Swagger2MarkupConfigBuilder() {
|
||||
this(new PropertiesConfiguration());
|
||||
}
|
||||
|
||||
//reference to self as the subclass type
|
||||
private final T self;
|
||||
public Swagger2MarkupConfigBuilder(Properties properties) {
|
||||
this(ConfigurationConverter.getConfiguration(properties));
|
||||
}
|
||||
|
||||
public Schema2MarkupConfigBuilder(final Class<T> selfClass,
|
||||
C config,
|
||||
Schema2MarkupProperties schema2MarkupProperties,
|
||||
Configuration configuration) {
|
||||
this.self = selfClass.cast(this);
|
||||
this.config = config;
|
||||
public Swagger2MarkupConfigBuilder(Map<String, String> map) {
|
||||
this(new MapConfiguration(map));
|
||||
}
|
||||
|
||||
config.listDelimiterEnabled = schema2MarkupProperties.getBoolean(LIST_DELIMITER_ENABLED, false);
|
||||
config.listDelimiter = schema2MarkupProperties.getString(LIST_DELIMITER, ",").charAt(0);
|
||||
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.basePathPrefixEnabled = swagger2MarkupProperties.getRequiredBoolean(BASE_PATH_PREFIX_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.pathSecuritySectionEnabled = swagger2MarkupProperties.getRequiredBoolean(PATH_SECURITY_SECTION_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());
|
||||
}
|
||||
|
||||
config.pageBreakLocations = swagger2MarkupProperties.getPageBreakLocations(PAGE_BREAK_LOCATIONS);
|
||||
|
||||
Optional<Pattern> headerPattern = swagger2MarkupProperties.getHeaderPattern(HEADER_REGEX);
|
||||
|
||||
config.headerPattern = headerPattern.orElse(null);
|
||||
|
||||
config.listDelimiterEnabled = swagger2MarkupProperties.getBoolean(LIST_DELIMITER_ENABLED, false);
|
||||
config.listDelimiter = swagger2MarkupProperties.getString(LIST_DELIMITER, ",").charAt(0);
|
||||
|
||||
if (config.listDelimiterEnabled && configuration instanceof AbstractConfiguration) {
|
||||
((AbstractConfiguration) configuration).setListDelimiterHandler(new DefaultListDelimiterHandler(config.listDelimiter));
|
||||
}
|
||||
|
||||
config.requestExamplesFormat = schema2MarkupProperties.getRequiredString(REQUEST_EXAMPLES_FORMAT);
|
||||
config.requestExamplesSourceFormat = schema2MarkupProperties.getRequiredString(REQUEST_EXAMPLES_SOURCE_FORMAT);
|
||||
config.requestExamplesHost = schema2MarkupProperties.getRequiredString(REQUEST_EXAMPLES_HOST);
|
||||
config.requestExamplesSchema = schema2MarkupProperties.getRequiredString(REQUEST_EXAMPLES_SCHEMA);
|
||||
config.requestExamplesHideBasePath = schema2MarkupProperties.getRequiredBoolean(REQUEST_EXAMPLES_HIDE_BASE_PATH);
|
||||
config.requestExamplesQueryArrayStyle = schema2MarkupProperties.getRequiredString(REQUEST_EXAMPLES_QUERY_ARRAY_STYLE);
|
||||
config.requestExamplesIncludeAllQueryParams = schema2MarkupProperties.getRequiredBoolean(REQUEST_EXAMPLES_INCLUDE_ALL_QUERY_PARAMS);
|
||||
config.markupLanguage = schema2MarkupProperties.getRequiredMarkupLanguage(MARKUP_LANGUAGE);
|
||||
config.schemaMarkupLanguage = schema2MarkupProperties.getRequiredMarkupLanguage(SWAGGER_MARKUP_LANGUAGE);
|
||||
config.generatedExamplesEnabled = schema2MarkupProperties.getRequiredBoolean(GENERATED_EXAMPLES_ENABLED);
|
||||
config.hostnameEnabled = schema2MarkupProperties.getRequiredBoolean(HOSTNAME_ENABLED);
|
||||
config.basePathPrefixEnabled = schema2MarkupProperties.getRequiredBoolean(BASE_PATH_PREFIX_ENABLED);
|
||||
config.separatedDefinitionsEnabled = schema2MarkupProperties.getRequiredBoolean(SEPARATED_DEFINITIONS_ENABLED);
|
||||
config.separatedOperationsEnabled = schema2MarkupProperties.getRequiredBoolean(SEPARATED_OPERATIONS_ENABLED);
|
||||
config.pathsGroupedBy = schema2MarkupProperties.getGroupBy(PATHS_GROUPED_BY);
|
||||
config.language = schema2MarkupProperties.getLanguage(OUTPUT_LANGUAGE);
|
||||
config.inlineSchemaEnabled = schema2MarkupProperties.getRequiredBoolean(INLINE_SCHEMA_ENABLED);
|
||||
config.interDocumentCrossReferencesEnabled = schema2MarkupProperties.getRequiredBoolean(INTER_DOCUMENT_CROSS_REFERENCES_ENABLED);
|
||||
config.interDocumentCrossReferencesPrefix = schema2MarkupProperties.getString(INTER_DOCUMENT_CROSS_REFERENCES_PREFIX, null);
|
||||
config.flatBodyEnabled = schema2MarkupProperties.getRequiredBoolean(FLAT_BODY_ENABLED);
|
||||
config.pathSecuritySectionEnabled = schema2MarkupProperties.getRequiredBoolean(PATH_SECURITY_SECTION_ENABLED);
|
||||
config.anchorPrefix = schema2MarkupProperties.getString(ANCHOR_PREFIX, null);
|
||||
config.overviewDocument = schema2MarkupProperties.getRequiredString(OVERVIEW_DOCUMENT);
|
||||
config.pathsDocument = schema2MarkupProperties.getRequiredString(PATHS_DOCUMENT);
|
||||
config.definitionsDocument = schema2MarkupProperties.getRequiredString(DEFINITIONS_DOCUMENT);
|
||||
config.securityDocument = schema2MarkupProperties.getRequiredString(SECURITY_DOCUMENT);
|
||||
config.separatedOperationsFolder = schema2MarkupProperties.getRequiredString(SEPARATED_OPERATIONS_FOLDER);
|
||||
config.separatedDefinitionsFolder = schema2MarkupProperties.getRequiredString(SEPARATED_DEFINITIONS_FOLDER);
|
||||
config.tagOrderBy = schema2MarkupProperties.getOrderBy(TAG_ORDER_BY);
|
||||
config.operationOrderBy = schema2MarkupProperties.getOrderBy(OPERATION_ORDER_BY);
|
||||
config.definitionOrderBy = schema2MarkupProperties.getOrderBy(DEFINITION_ORDER_BY);
|
||||
config.parameterOrderBy = schema2MarkupProperties.getOrderBy(PARAMETER_ORDER_BY);
|
||||
config.propertyOrderBy = schema2MarkupProperties.getOrderBy(PROPERTY_ORDER_BY);
|
||||
config.responseOrderBy = schema2MarkupProperties.getOrderBy(RESPONSE_ORDER_BY);
|
||||
Optional<String> lineSeparator = schema2MarkupProperties.getString(LINE_SEPARATOR);
|
||||
if (lineSeparator.isPresent() && StringUtils.isNoneBlank(lineSeparator.get())) {
|
||||
config.lineSeparator = LineSeparator.valueOf(lineSeparator.get());
|
||||
}
|
||||
|
||||
config.pageBreakLocations = schema2MarkupProperties.getPageBreakLocations(PAGE_BREAK_LOCATIONS);
|
||||
|
||||
Optional<Pattern> headerPattern = schema2MarkupProperties.getHeaderPattern(HEADER_REGEX);
|
||||
|
||||
config.headerPattern = headerPattern.orElse(null);
|
||||
|
||||
Configuration swagger2markupConfiguration = schema2MarkupProperties.getConfiguration().subset(PROPERTIES_PREFIX);
|
||||
Configuration swagger2markupConfiguration = compositeConfiguration.subset(PROPERTIES_PREFIX);
|
||||
Configuration extensionsConfiguration = swagger2markupConfiguration.subset(EXTENSION_PREFIX);
|
||||
config.extensionsProperties = new Schema2MarkupProperties(extensionsConfiguration);
|
||||
config.asciidocPegdownTimeoutMillis = schema2MarkupProperties.getRequiredInt(ASCIIDOC_PEGDOWN_TIMEOUT);
|
||||
config.extensionsProperties = new Swagger2MarkupProperties(extensionsConfiguration);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -131,7 +127,7 @@ public abstract class Schema2MarkupConfigBuilder<T extends Schema2MarkupConfigBu
|
||||
*
|
||||
* @return the default properties
|
||||
*/
|
||||
public static Configuration getDefaultConfiguration() {
|
||||
private Configuration getDefaultConfiguration() {
|
||||
Configurations configs = new Configurations();
|
||||
try {
|
||||
return configs.properties(PROPERTIES_DEFAULT);
|
||||
@@ -140,7 +136,18 @@ public abstract class Schema2MarkupConfigBuilder<T extends Schema2MarkupConfigBu
|
||||
}
|
||||
}
|
||||
|
||||
protected void buildNaturalOrdering() {
|
||||
/**
|
||||
* 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)
|
||||
@@ -155,35 +162,28 @@ public abstract class Schema2MarkupConfigBuilder<T extends Schema2MarkupConfigBu
|
||||
config.responseOrdering = Ordering.natural();
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the OpenApi2MarkupConfig.
|
||||
*
|
||||
* @return the OpenApi2MarkupConfig
|
||||
*/
|
||||
public abstract C build();
|
||||
|
||||
/**
|
||||
* 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 T withMarkupLanguage(MarkupLanguage markupLanguage) {
|
||||
Validate.notNull(markupLanguage, "%s must not be null", "outputLanguage");
|
||||
public Swagger2MarkupConfigBuilder withMarkupLanguage(MarkupLanguage markupLanguage) {
|
||||
Validate.notNull(markupLanguage, "%s must not be null", "markupLanguage");
|
||||
config.markupLanguage = markupLanguage;
|
||||
return self;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies the markup language used in Swagger descriptions.
|
||||
*
|
||||
* @param markupLanguage the markup language used in Swagger descriptions
|
||||
* @param swaggerMarkupLanguage the markup language used in Swagger descriptions
|
||||
* @return this builder
|
||||
*/
|
||||
public T withSwaggerMarkupLanguage(MarkupLanguage markupLanguage) {
|
||||
Validate.notNull(markupLanguage, "%s must not be null", "outputLanguage");
|
||||
config.schemaMarkupLanguage = markupLanguage;
|
||||
return self;
|
||||
public Swagger2MarkupConfigBuilder withSwaggerMarkupLanguage(MarkupLanguage swaggerMarkupLanguage) {
|
||||
Validate.notNull(swaggerMarkupLanguage, "%s must not be null", "swaggerMarkupLanguage");
|
||||
config.swaggerMarkupLanguage = swaggerMarkupLanguage;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -191,9 +191,9 @@ public abstract class Schema2MarkupConfigBuilder<T extends Schema2MarkupConfigBu
|
||||
*
|
||||
* @return this builder
|
||||
*/
|
||||
public T withGeneratedExamples() {
|
||||
public Swagger2MarkupConfigBuilder withGeneratedExamples() {
|
||||
config.generatedExamplesEnabled = true;
|
||||
return self;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -201,9 +201,9 @@ public abstract class Schema2MarkupConfigBuilder<T extends Schema2MarkupConfigBu
|
||||
*
|
||||
* @return this builder
|
||||
*/
|
||||
public T withSeparatedDefinitions() {
|
||||
public Swagger2MarkupConfigBuilder withSeparatedDefinitions() {
|
||||
config.separatedDefinitionsEnabled = true;
|
||||
return self;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -212,9 +212,9 @@ public abstract class Schema2MarkupConfigBuilder<T extends Schema2MarkupConfigBu
|
||||
*
|
||||
* @return this builder
|
||||
*/
|
||||
public T withSeparatedOperations() {
|
||||
public Swagger2MarkupConfigBuilder withSeparatedOperations() {
|
||||
config.separatedOperationsEnabled = true;
|
||||
return self;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -222,9 +222,9 @@ public abstract class Schema2MarkupConfigBuilder<T extends Schema2MarkupConfigBu
|
||||
*
|
||||
* @return this builder
|
||||
*/
|
||||
public T withListDelimiter() {
|
||||
public Swagger2MarkupConfigBuilder withListDelimiter() {
|
||||
config.listDelimiterEnabled = true;
|
||||
return self;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -233,11 +233,11 @@ public abstract class Schema2MarkupConfigBuilder<T extends Schema2MarkupConfigBu
|
||||
* @param delimiter the delimiter
|
||||
* @return this builder
|
||||
*/
|
||||
public T withListDelimiter(Character delimiter) {
|
||||
public Swagger2MarkupConfigBuilder withListDelimiter(Character delimiter) {
|
||||
Validate.notNull(delimiter, "%s must not be null", "delimiter");
|
||||
config.listDelimiter = delimiter;
|
||||
config.listDelimiterEnabled = true;
|
||||
return self;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -247,10 +247,10 @@ public abstract class Schema2MarkupConfigBuilder<T extends Schema2MarkupConfigBu
|
||||
* @param pathsGroupedBy the GroupBy enum
|
||||
* @return this builder
|
||||
*/
|
||||
public T withPathsGroupedBy(GroupBy pathsGroupedBy) {
|
||||
public Swagger2MarkupConfigBuilder withPathsGroupedBy(GroupBy pathsGroupedBy) {
|
||||
Validate.notNull(pathsGroupedBy, "%s must not be null", "pathsGroupedBy");
|
||||
config.pathsGroupedBy = pathsGroupedBy;
|
||||
return self;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -260,10 +260,10 @@ public abstract class Schema2MarkupConfigBuilder<T extends Schema2MarkupConfigBu
|
||||
* @return this builder
|
||||
* @throws PatternSyntaxException when pattern cannot be compiled
|
||||
*/
|
||||
public T withHeaderRegex(String headerRegex) {
|
||||
public Swagger2MarkupConfigBuilder withHeaderRegex(String headerRegex) {
|
||||
Validate.notNull(headerRegex, "%s must not be null", headerRegex);
|
||||
config.headerPattern = Pattern.compile(headerRegex);
|
||||
return self;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -272,10 +272,10 @@ public abstract class Schema2MarkupConfigBuilder<T extends Schema2MarkupConfigBu
|
||||
* @param language the enum
|
||||
* @return this builder
|
||||
*/
|
||||
public T withOutputLanguage(Language language) {
|
||||
public Swagger2MarkupConfigBuilder withOutputLanguage(Language language) {
|
||||
Validate.notNull(language, "%s must not be null", "language");
|
||||
config.language = language;
|
||||
return self;
|
||||
config.outputLanguage = language;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -283,24 +283,24 @@ public abstract class Schema2MarkupConfigBuilder<T extends Schema2MarkupConfigBu
|
||||
*
|
||||
* @return this builder
|
||||
*/
|
||||
public T withoutInlineSchema() {
|
||||
public Swagger2MarkupConfigBuilder withoutInlineSchema() {
|
||||
config.inlineSchemaEnabled = false;
|
||||
return self;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies tag ordering.<br>
|
||||
* By default tag ordering == {@link OrderBy#NATURAL}.<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 T withTagOrdering(OrderBy orderBy) {
|
||||
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 self;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -309,26 +309,26 @@ public abstract class Schema2MarkupConfigBuilder<T extends Schema2MarkupConfigBu
|
||||
* @param tagOrdering tag ordering
|
||||
* @return this builder
|
||||
*/
|
||||
public T withTagOrdering(Comparator<String> tagOrdering) {
|
||||
public Swagger2MarkupConfigBuilder withTagOrdering(Comparator<String> tagOrdering) {
|
||||
Validate.notNull(tagOrdering, "%s must not be null", "tagOrdering");
|
||||
config.tagOrderBy = OrderBy.CUSTOM;
|
||||
config.tagOrdering = tagOrdering;
|
||||
return self;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies operation ordering.<br>
|
||||
* By default operation ordering == {@link OrderBy#AS_IS}.<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 T withOperationOrdering(OrderBy orderBy) {
|
||||
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 self;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -337,26 +337,26 @@ public abstract class Schema2MarkupConfigBuilder<T extends Schema2MarkupConfigBu
|
||||
* @param operationOrdering operation ordering
|
||||
* @return this builder
|
||||
*/
|
||||
public T withOperationOrdering(Comparator<PathOperation> operationOrdering) {
|
||||
public Swagger2MarkupConfigBuilder withOperationOrdering(Comparator<PathOperation> operationOrdering) {
|
||||
Validate.notNull(operationOrdering, "%s must not be null", "operationOrdering");
|
||||
config.operationOrderBy = OrderBy.CUSTOM;
|
||||
config.operationOrdering = operationOrdering;
|
||||
return self;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies definition ordering.<br>
|
||||
* By default definition ordering == {@link OrderBy#NATURAL}.<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 T withDefinitionOrdering(OrderBy orderBy) {
|
||||
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 self;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -365,11 +365,11 @@ public abstract class Schema2MarkupConfigBuilder<T extends Schema2MarkupConfigBu
|
||||
* @param definitionOrdering definition ordering
|
||||
* @return this builder
|
||||
*/
|
||||
public T withDefinitionOrdering(Comparator<String> definitionOrdering) {
|
||||
public Swagger2MarkupConfigBuilder withDefinitionOrdering(Comparator<String> definitionOrdering) {
|
||||
Validate.notNull(definitionOrdering, "%s must not be null", "definitionOrdering");
|
||||
config.definitionOrderBy = OrderBy.CUSTOM;
|
||||
config.definitionOrdering = definitionOrdering;
|
||||
return self;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -380,11 +380,11 @@ public abstract class Schema2MarkupConfigBuilder<T extends Schema2MarkupConfigBu
|
||||
* @param orderBy parameter ordering
|
||||
* @return this builder
|
||||
*/
|
||||
public T withParameterOrdering(OrderBy orderBy) {
|
||||
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 self;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -393,27 +393,27 @@ public abstract class Schema2MarkupConfigBuilder<T extends Schema2MarkupConfigBu
|
||||
* @param parameterOrdering parameter ordering
|
||||
* @return this builder
|
||||
*/
|
||||
public T withParameterOrdering(Comparator<Parameter> parameterOrdering) {
|
||||
public Swagger2MarkupConfigBuilder withParameterOrdering(Comparator<Parameter> parameterOrdering) {
|
||||
Validate.notNull(parameterOrdering, "%s must not be null", "parameterOrdering");
|
||||
|
||||
config.parameterOrderBy = OrderBy.CUSTOM;
|
||||
config.parameterOrdering = parameterOrdering;
|
||||
return self;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies property ordering.<br>
|
||||
* By default property ordering == {@link OrderBy#NATURAL}.<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 T withPropertyOrdering(OrderBy orderBy) {
|
||||
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 self;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -422,27 +422,27 @@ public abstract class Schema2MarkupConfigBuilder<T extends Schema2MarkupConfigBu
|
||||
* @param propertyOrdering property ordering
|
||||
* @return this builder
|
||||
*/
|
||||
public T withPropertyOrdering(Comparator<String> propertyOrdering) {
|
||||
public Swagger2MarkupConfigBuilder withPropertyOrdering(Comparator<String> propertyOrdering) {
|
||||
Validate.notNull(propertyOrdering, "%s must not be null", "propertyOrdering");
|
||||
|
||||
config.propertyOrderBy = OrderBy.CUSTOM;
|
||||
config.propertyOrdering = propertyOrdering;
|
||||
return self;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies response ordering.<br>
|
||||
* By default response ordering == {@link OrderBy#NATURAL}.<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 T withResponseOrdering(OrderBy orderBy) {
|
||||
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 self;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -451,12 +451,12 @@ public abstract class Schema2MarkupConfigBuilder<T extends Schema2MarkupConfigBu
|
||||
* @param responseOrdering response ordering
|
||||
* @return this builder
|
||||
*/
|
||||
public T withResponseOrdering(Comparator<String> responseOrdering) {
|
||||
public Swagger2MarkupConfigBuilder withResponseOrdering(Comparator<String> responseOrdering) {
|
||||
Validate.notNull(responseOrdering, "%s must not be null", "responseOrdering");
|
||||
|
||||
config.responseOrderBy = OrderBy.CUSTOM;
|
||||
config.responseOrdering = responseOrdering;
|
||||
return self;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -465,11 +465,11 @@ public abstract class Schema2MarkupConfigBuilder<T extends Schema2MarkupConfigBu
|
||||
* @param prefix Prefix to document in all inter-document cross-references.
|
||||
* @return this builder
|
||||
*/
|
||||
public T withInterDocumentCrossReferences(String prefix) {
|
||||
public Swagger2MarkupConfigBuilder withInterDocumentCrossReferences(String prefix) {
|
||||
Validate.notNull(prefix, "%s must not be null", "prefix");
|
||||
config.interDocumentCrossReferencesEnabled = true;
|
||||
config.interDocumentCrossReferencesPrefix = prefix;
|
||||
return self;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -477,9 +477,9 @@ public abstract class Schema2MarkupConfigBuilder<T extends Schema2MarkupConfigBu
|
||||
*
|
||||
* @return this builder
|
||||
*/
|
||||
public T withInterDocumentCrossReferences() {
|
||||
public Swagger2MarkupConfigBuilder withInterDocumentCrossReferences() {
|
||||
config.interDocumentCrossReferencesEnabled = true;
|
||||
return self;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -487,9 +487,9 @@ public abstract class Schema2MarkupConfigBuilder<T extends Schema2MarkupConfigBu
|
||||
*
|
||||
* @return this builder
|
||||
*/
|
||||
public T withFlatBody() {
|
||||
public Swagger2MarkupConfigBuilder withFlatBody() {
|
||||
config.flatBodyEnabled = true;
|
||||
return self;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -497,9 +497,9 @@ public abstract class Schema2MarkupConfigBuilder<T extends Schema2MarkupConfigBu
|
||||
*
|
||||
* @return this builder
|
||||
*/
|
||||
public T withoutPathSecuritySection() {
|
||||
public Swagger2MarkupConfigBuilder withoutPathSecuritySection() {
|
||||
config.pathSecuritySectionEnabled = false;
|
||||
return self;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -507,9 +507,9 @@ public abstract class Schema2MarkupConfigBuilder<T extends Schema2MarkupConfigBu
|
||||
*
|
||||
* @return this builder
|
||||
*/
|
||||
public T withBasePathPrefix() {
|
||||
public Swagger2MarkupConfigBuilder withBasePathPrefix() {
|
||||
config.basePathPrefixEnabled = true;
|
||||
return self;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -518,10 +518,10 @@ public abstract class Schema2MarkupConfigBuilder<T extends Schema2MarkupConfigBu
|
||||
* @param anchorPrefix anchor prefix.
|
||||
* @return this builder
|
||||
*/
|
||||
public T withAnchorPrefix(String anchorPrefix) {
|
||||
public Swagger2MarkupConfigBuilder withAnchorPrefix(String anchorPrefix) {
|
||||
Validate.notNull(anchorPrefix, "%s must not be null", "anchorPrefix");
|
||||
config.anchorPrefix = anchorPrefix;
|
||||
return self;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -530,10 +530,10 @@ public abstract class Schema2MarkupConfigBuilder<T extends Schema2MarkupConfigBu
|
||||
* @param locations List of locations to create new pages
|
||||
* @return this builder
|
||||
*/
|
||||
public T withPageBreaks(List<PageBreakLocations> locations) {
|
||||
public Swagger2MarkupConfigBuilder withPageBreaks(List<PageBreakLocations> locations) {
|
||||
Validate.notNull(locations, "%s must not be null", "locations");
|
||||
config.pageBreakLocations = locations;
|
||||
return self;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -542,162 +542,56 @@ public abstract class Schema2MarkupConfigBuilder<T extends Schema2MarkupConfigBu
|
||||
* @param lineSeparator the lineSeparator
|
||||
* @return this builder
|
||||
*/
|
||||
public T withLineSeparator(LineSeparator lineSeparator) {
|
||||
public Swagger2MarkupConfigBuilder withLineSeparator(LineSeparator lineSeparator) {
|
||||
Validate.notNull(lineSeparator, "%s must no be null", "lineSeparator");
|
||||
config.lineSeparator = lineSeparator;
|
||||
return self;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies the request examples format to use.
|
||||
*
|
||||
* @param requestExamplesFormat `basic`, `curl` or `invoke-webrequest`
|
||||
* @return this builder
|
||||
*/
|
||||
public T withRequestExamplesFormat(String requestExamplesFormat) {
|
||||
Validate.notNull(requestExamplesFormat, "%s must not be null", requestExamplesFormat);
|
||||
config.requestExamplesFormat = requestExamplesFormat;
|
||||
return self;
|
||||
}
|
||||
static class DefaultSwagger2MarkupConfig implements Swagger2MarkupConfig {
|
||||
|
||||
/**
|
||||
* format name which should be used to highlight source block with request example string
|
||||
*
|
||||
* @param requestExamplesSourceFormat any string or `default`
|
||||
* @return this builder
|
||||
*/
|
||||
public T withRequestExamplesSourceFormat(String requestExamplesSourceFormat) {
|
||||
Validate.notNull(requestExamplesSourceFormat, "%s must not be null", requestExamplesSourceFormat);
|
||||
config.requestExamplesSourceFormat = requestExamplesSourceFormat;
|
||||
return self;
|
||||
}
|
||||
private MarkupLanguage markupLanguage;
|
||||
private MarkupLanguage swaggerMarkupLanguage;
|
||||
private boolean generatedExamplesEnabled;
|
||||
private boolean basePathPrefixEnabled;
|
||||
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 boolean pathSecuritySectionEnabled;
|
||||
private String anchorPrefix;
|
||||
private LineSeparator lineSeparator;
|
||||
|
||||
/**
|
||||
* Should we hide, inherit or override hostname (e.g. with google.com) from yml file
|
||||
*
|
||||
* @param requestExamplesHost `hide`, `inherit` or string with hostname to be used in request example
|
||||
* @return this builder
|
||||
*/
|
||||
public T withRequestExamplesHost(String requestExamplesHost) {
|
||||
Validate.notNull(requestExamplesHost, "%s must not ber null", requestExamplesHost);
|
||||
config.requestExamplesHost = requestExamplesHost;
|
||||
return self;
|
||||
}
|
||||
private String overviewDocument;
|
||||
private String pathsDocument;
|
||||
private String definitionsDocument;
|
||||
private String securityDocument;
|
||||
private String separatedOperationsFolder;
|
||||
private String separatedDefinitionsFolder;
|
||||
private Character listDelimiter;
|
||||
private boolean listDelimiterEnabled;
|
||||
|
||||
/**
|
||||
* Should we hide, inherit or override schema (http, https name it) from yml file
|
||||
*
|
||||
* @param requestExamplesSchema `hide`, `inherit` or string with schema name to be used in request example
|
||||
* @return this builder
|
||||
*/
|
||||
public T withRequestExamplesSchema(String requestExamplesSchema) {
|
||||
Validate.notNull(requestExamplesSchema, "%s must not be null", requestExamplesSchema);
|
||||
config.requestExamplesSchema = requestExamplesSchema;
|
||||
return self;
|
||||
}
|
||||
private List<PageBreakLocations> pageBreakLocations;
|
||||
|
||||
/**
|
||||
* Should we hide or show base path in example request endpoint address
|
||||
*
|
||||
* @param requestExamplesHideBasePath true or false
|
||||
* @return this builder
|
||||
* @throws PatternSyntaxException when pattern cannot be compiled
|
||||
*/
|
||||
public T withRequestExamplesHideBasePath(boolean requestExamplesHideBasePath) {
|
||||
config.requestExamplesHideBasePath = requestExamplesHideBasePath;
|
||||
return self;
|
||||
}
|
||||
private Pattern headerPattern;
|
||||
|
||||
/**
|
||||
* Should we output optional query params in source block with request example string
|
||||
*
|
||||
* @param requestExamplesIncludeAllQueryParams false if example request should contain only required params
|
||||
* @return this builder
|
||||
*/
|
||||
public T withRequestExamplesIncludeAllQueryParams(boolean requestExamplesIncludeAllQueryParams) {
|
||||
config.requestExamplesIncludeAllQueryParams = requestExamplesIncludeAllQueryParams;
|
||||
return self;
|
||||
}
|
||||
|
||||
/**
|
||||
* How we should output array query params
|
||||
*
|
||||
* @param requestExamplesQueryArrayStyle `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.
|
||||
* @return this builder
|
||||
*/
|
||||
public T withRequestExamplesQueryArrayStyle(String requestExamplesQueryArrayStyle) {
|
||||
Validate.notNull(requestExamplesQueryArrayStyle, "%s must not be null", requestExamplesQueryArrayStyle);
|
||||
config.requestExamplesQueryArrayStyle = requestExamplesQueryArrayStyle;
|
||||
return self;
|
||||
}
|
||||
|
||||
protected static CompositeConfiguration getCompositeConfiguration(Configuration configuration) {
|
||||
CompositeConfiguration compositeConfiguration = new CompositeConfiguration();
|
||||
compositeConfiguration.addConfiguration(new SystemConfiguration());
|
||||
compositeConfiguration.addConfiguration(configuration);
|
||||
compositeConfiguration.addConfiguration(getDefaultConfiguration());
|
||||
return compositeConfiguration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default implementation of {@link Schema2MarkupConfig}
|
||||
*/
|
||||
public static class DefaultSchema2MarkupConfig implements Schema2MarkupConfig {
|
||||
MarkupLanguage markupLanguage;
|
||||
MarkupLanguage schemaMarkupLanguage;
|
||||
boolean generatedExamplesEnabled;
|
||||
|
||||
String requestExamplesFormat;
|
||||
String requestExamplesSourceFormat;
|
||||
String requestExamplesHost;
|
||||
String requestExamplesSchema;
|
||||
boolean requestExamplesHideBasePath;
|
||||
boolean requestExamplesIncludeAllQueryParams;
|
||||
String requestExamplesQueryArrayStyle;
|
||||
|
||||
boolean hostnameEnabled;
|
||||
boolean basePathPrefixEnabled;
|
||||
boolean separatedDefinitionsEnabled;
|
||||
boolean separatedOperationsEnabled;
|
||||
GroupBy pathsGroupedBy;
|
||||
Language language;
|
||||
boolean inlineSchemaEnabled;
|
||||
OrderBy tagOrderBy;
|
||||
Comparator<String> tagOrdering;
|
||||
OrderBy operationOrderBy;
|
||||
Comparator<PathOperation> operationOrdering;
|
||||
OrderBy definitionOrderBy;
|
||||
Comparator<String> definitionOrdering;
|
||||
OrderBy parameterOrderBy;
|
||||
Comparator<Parameter> parameterOrdering;
|
||||
OrderBy propertyOrderBy;
|
||||
Comparator<String> propertyOrdering;
|
||||
OrderBy responseOrderBy;
|
||||
Comparator<String> responseOrdering;
|
||||
boolean interDocumentCrossReferencesEnabled;
|
||||
String interDocumentCrossReferencesPrefix;
|
||||
boolean flatBodyEnabled;
|
||||
boolean pathSecuritySectionEnabled;
|
||||
String anchorPrefix;
|
||||
LineSeparator lineSeparator;
|
||||
|
||||
String overviewDocument;
|
||||
String pathsDocument;
|
||||
String definitionsDocument;
|
||||
String securityDocument;
|
||||
String separatedOperationsFolder;
|
||||
String separatedDefinitionsFolder;
|
||||
Character listDelimiter;
|
||||
boolean listDelimiterEnabled;
|
||||
int asciidocPegdownTimeoutMillis;
|
||||
|
||||
List<PageBreakLocations> pageBreakLocations;
|
||||
|
||||
Pattern headerPattern;
|
||||
|
||||
Schema2MarkupProperties extensionsProperties;
|
||||
private Swagger2MarkupProperties extensionsProperties;
|
||||
|
||||
@Override
|
||||
public MarkupLanguage getMarkupLanguage() {
|
||||
@@ -705,8 +599,8 @@ public abstract class Schema2MarkupConfigBuilder<T extends Schema2MarkupConfigBu
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupLanguage getSchemaMarkupLanguage() {
|
||||
return schemaMarkupLanguage;
|
||||
public MarkupLanguage getSwaggerMarkupLanguage() {
|
||||
return swaggerMarkupLanguage;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -730,8 +624,8 @@ public abstract class Schema2MarkupConfigBuilder<T extends Schema2MarkupConfigBu
|
||||
}
|
||||
|
||||
@Override
|
||||
public Language getLanguage() {
|
||||
return language;
|
||||
public Language getOutputLanguage() {
|
||||
return outputLanguage;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -875,15 +769,10 @@ public abstract class Schema2MarkupConfigBuilder<T extends Schema2MarkupConfigBu
|
||||
}
|
||||
|
||||
@Override
|
||||
public Schema2MarkupProperties getExtensionsProperties() {
|
||||
public Swagger2MarkupProperties getExtensionsProperties() {
|
||||
return extensionsProperties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isHostnameEnabled() {
|
||||
return hostnameEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBasePathPrefixEnabled() {
|
||||
return basePathPrefixEnabled;
|
||||
@@ -893,44 +782,5 @@ public abstract class Schema2MarkupConfigBuilder<T extends Schema2MarkupConfigBu
|
||||
public List<PageBreakLocations> getPageBreakLocations() {
|
||||
return pageBreakLocations;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAsciidocPegdownTimeoutMillis() {
|
||||
return asciidocPegdownTimeoutMillis;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRequestExamplesFormat() {
|
||||
return requestExamplesFormat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRequestExamplesSourceFormat() {
|
||||
return requestExamplesSourceFormat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getRequestExamplesIncludeAllQueryParams() {
|
||||
return requestExamplesIncludeAllQueryParams;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRequestExamplesQueryArrayStyle() {
|
||||
return requestExamplesQueryArrayStyle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRequestExamplesHost() {
|
||||
return requestExamplesHost;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRequestExamplesSchema() {
|
||||
return requestExamplesSchema;
|
||||
}
|
||||
@Override
|
||||
public boolean getRequestExamplesHideBasePath() {
|
||||
return requestExamplesHideBasePath;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package io.github.swagger2markup.builder;
|
||||
|
||||
import io.github.swagger2markup.Swagger2MarkupExtensionRegistry;
|
||||
import io.github.swagger2markup.spi.*;
|
||||
|
||||
import java.util.List;
|
||||
@@ -106,17 +107,17 @@ public class Swagger2MarkupExtensionRegistryBuilder {
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,21 +17,22 @@ package io.github.swagger2markup.internal.adapter;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import io.github.swagger2markup.Swagger2MarkupConfig;
|
||||
import io.github.swagger2markup.Swagger2MarkupConverter.SwaggerContext;
|
||||
import io.github.swagger2markup.Swagger2MarkupConverter;
|
||||
import io.github.swagger2markup.internal.resolver.DocumentResolver;
|
||||
import io.github.swagger2markup.internal.type.*;
|
||||
import io.github.swagger2markup.internal.utils.ExamplesUtil;
|
||||
import io.github.swagger2markup.internal.utils.InlineSchemaUtils;
|
||||
import io.github.swagger2markup.internal.utils.ModelUtils;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import io.github.swagger2markup.markup.builder.MarkupLanguage;
|
||||
import io.github.swagger2markup.model.PathOperation;
|
||||
import io.swagger.models.Model;
|
||||
import io.swagger.models.parameters.*;
|
||||
import io.swagger.models.parameters.AbstractSerializableParameter;
|
||||
import io.swagger.models.parameters.BodyParameter;
|
||||
import io.swagger.models.parameters.Parameter;
|
||||
import io.swagger.models.parameters.RefParameter;
|
||||
import io.swagger.util.Json;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.apache.commons.text.WordUtils;
|
||||
import org.apache.commons.lang3.text.WordUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -47,13 +48,13 @@ public class ParameterAdapter {
|
||||
private final Swagger2MarkupConfig config;
|
||||
private Type type;
|
||||
|
||||
public ParameterAdapter(SwaggerContext context,
|
||||
public ParameterAdapter(Swagger2MarkupConverter.Context context,
|
||||
PathOperation operation,
|
||||
Parameter parameter,
|
||||
DocumentResolver definitionDocumentResolver) {
|
||||
Validate.notNull(parameter, "parameter must not be null");
|
||||
this.parameter = parameter;
|
||||
type = getType(context.getSchema().getDefinitions(), definitionDocumentResolver);
|
||||
type = getType(context.getSwagger().getDefinitions(), definitionDocumentResolver);
|
||||
config = context.getConfig();
|
||||
if (config.isInlineSchemaEnabled()) {
|
||||
if (config.isFlatBodyEnabled()) {
|
||||
@@ -72,7 +73,7 @@ public class ParameterAdapter {
|
||||
* @param parameter parameter
|
||||
* @return a generated example for the parameter
|
||||
*/
|
||||
public static Object generateExample(AbstractSerializableParameter<?> parameter) {
|
||||
public static Object generateExample(AbstractSerializableParameter parameter) {
|
||||
switch (parameter.getType()) {
|
||||
case "integer":
|
||||
return 0;
|
||||
@@ -81,7 +82,7 @@ public class ParameterAdapter {
|
||||
case "boolean":
|
||||
return true;
|
||||
case "string":
|
||||
return ExamplesUtil.generateStringExample(parameter.getFormat(), parameter.getEnum());
|
||||
return "string";
|
||||
default:
|
||||
return parameter.getType();
|
||||
}
|
||||
@@ -109,8 +110,7 @@ public class ParameterAdapter {
|
||||
}
|
||||
|
||||
public String displayDescription(MarkupDocBuilder markupDocBuilder) {
|
||||
io.github.swagger2markup.MarkupLanguage schemaMarkupLanguage = config.getSchemaMarkupLanguage();
|
||||
return markupDescription(MarkupLanguage.valueOf(schemaMarkupLanguage.name()), markupDocBuilder, getDescription());
|
||||
return markupDescription(config.getSwaggerMarkupLanguage(), markupDocBuilder, getDescription());
|
||||
}
|
||||
|
||||
public String displayType(MarkupDocBuilder markupDocBuilder) {
|
||||
@@ -202,19 +202,4 @@ public class ParameterAdapter {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public Optional<Integer> getMinItems() {
|
||||
if (parameter instanceof SerializableParameter) {
|
||||
Integer minItems = ((SerializableParameter) parameter).getMinItems();
|
||||
return Optional.ofNullable(minItems);
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public Optional<Integer> getMaxItems() {
|
||||
if (parameter instanceof SerializableParameter) {
|
||||
Integer maxItems = ((SerializableParameter) parameter).getMaxItems();
|
||||
return Optional.ofNullable(maxItems);
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
@@ -16,29 +16,9 @@
|
||||
package io.github.swagger2markup.internal.adapter;
|
||||
|
||||
import io.github.swagger2markup.internal.resolver.DocumentResolver;
|
||||
import io.github.swagger2markup.internal.type.ArrayType;
|
||||
import io.github.swagger2markup.internal.type.BasicType;
|
||||
import io.github.swagger2markup.internal.type.EnumType;
|
||||
import io.github.swagger2markup.internal.type.MapType;
|
||||
import io.github.swagger2markup.internal.type.ObjectType;
|
||||
import io.github.swagger2markup.internal.type.RefType;
|
||||
import io.github.swagger2markup.internal.type.Type;
|
||||
import io.github.swagger2markup.internal.utils.ExamplesUtil;
|
||||
import io.github.swagger2markup.internal.type.*;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import io.swagger.models.properties.AbstractNumericProperty;
|
||||
import io.swagger.models.properties.ArrayProperty;
|
||||
import io.swagger.models.properties.BaseIntegerProperty;
|
||||
import io.swagger.models.properties.BooleanProperty;
|
||||
import io.swagger.models.properties.DoubleProperty;
|
||||
import io.swagger.models.properties.FloatProperty;
|
||||
import io.swagger.models.properties.IntegerProperty;
|
||||
import io.swagger.models.properties.LongProperty;
|
||||
import io.swagger.models.properties.MapProperty;
|
||||
import io.swagger.models.properties.ObjectProperty;
|
||||
import io.swagger.models.properties.Property;
|
||||
import io.swagger.models.properties.RefProperty;
|
||||
import io.swagger.models.properties.StringProperty;
|
||||
import io.swagger.models.properties.UUIDProperty;
|
||||
import io.swagger.models.properties.*;
|
||||
import io.swagger.models.refs.RefFormat;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
@@ -47,12 +27,7 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.*;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
|
||||
@@ -75,19 +50,15 @@ public final class PropertyAdapter {
|
||||
*/
|
||||
public static Object generateExample(Property property, MarkupDocBuilder markupDocBuilder) {
|
||||
|
||||
if (property.getType() == null) {
|
||||
return "untyped";
|
||||
}
|
||||
|
||||
switch (property.getType()) {
|
||||
case "integer":
|
||||
return ExamplesUtil.generateIntegerExample(property instanceof IntegerProperty ? ((IntegerProperty) property).getEnum() : null);
|
||||
return 0;
|
||||
case "number":
|
||||
return 0.0;
|
||||
case "boolean":
|
||||
return true;
|
||||
case "string":
|
||||
return ExamplesUtil.generateStringExample(property.getFormat(), property instanceof StringProperty ? ((StringProperty) property).getEnum() : null);
|
||||
return "string";
|
||||
case "ref":
|
||||
if (property instanceof RefProperty) {
|
||||
if (logger.isDebugEnabled()) logger.debug("generateExample RefProperty for " + property.getName());
|
||||
@@ -168,13 +139,8 @@ public final class PropertyAdapter {
|
||||
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 arrayType = new PropertyAdapter(items).getType(definitionDocumentResolver);
|
||||
if (arrayType == 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(), new PropertyAdapter(items).getType(definitionDocumentResolver));
|
||||
}
|
||||
else
|
||||
type = new ArrayType(arrayProperty.getTitle(), new PropertyAdapter(items).getType(definitionDocumentResolver));
|
||||
} else if (property instanceof MapProperty) {
|
||||
MapProperty mapProperty = (MapProperty) property;
|
||||
Property additionalProperties = mapProperty.getAdditionalProperties();
|
||||
@@ -194,22 +160,8 @@ public final class PropertyAdapter {
|
||||
}
|
||||
} else if (property instanceof ObjectProperty) {
|
||||
type = new ObjectType(property.getTitle(), ((ObjectProperty) property).getProperties());
|
||||
} else if (property instanceof IntegerProperty) {
|
||||
IntegerProperty integerProperty = (IntegerProperty) property;
|
||||
List<Integer> enums = integerProperty.getEnum();
|
||||
if (CollectionUtils.isNotEmpty(enums)) {
|
||||
// first, convert integer enum values to strings
|
||||
List<String> enumValuesAsString = enums.stream().map(String::valueOf).collect(Collectors.toList());
|
||||
type = new EnumType(integerProperty.getTitle(), enumValuesAsString);
|
||||
} else if (isNotBlank(integerProperty.getFormat())) {
|
||||
type = new BasicType(integerProperty.getType(), integerProperty.getTitle(), integerProperty.getFormat());
|
||||
} else {
|
||||
type = new BasicType(property.getType(), property.getTitle());
|
||||
}
|
||||
} else {
|
||||
if (property.getType() == null) {
|
||||
return null;
|
||||
} else if (isNotBlank(property.getFormat())) {
|
||||
if (isNotBlank(property.getFormat())) {
|
||||
type = new BasicType(property.getType(), property.getTitle(), property.getFormat());
|
||||
} else {
|
||||
type = new BasicType(property.getType(), property.getTitle());
|
||||
@@ -327,9 +279,9 @@ public final class PropertyAdapter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the maximum value of a property
|
||||
* Retrieves the minimum value of a property
|
||||
*
|
||||
* @return the maximum value of the property
|
||||
* @return the minimum value of the property
|
||||
*/
|
||||
public Optional<BigDecimal> getMax() {
|
||||
if (property instanceof BaseIntegerProperty) {
|
||||
@@ -16,15 +16,14 @@
|
||||
package io.github.swagger2markup.internal.component;
|
||||
|
||||
|
||||
import io.github.swagger2markup.Swagger2MarkupConverter;
|
||||
import io.github.swagger2markup.GroupBy;
|
||||
import io.github.swagger2markup.Swagger2MarkupConverter;
|
||||
import io.github.swagger2markup.internal.adapter.ParameterAdapter;
|
||||
import io.github.swagger2markup.internal.resolver.DocumentResolver;
|
||||
import io.github.swagger2markup.internal.type.ObjectType;
|
||||
import io.github.swagger2markup.internal.type.Type;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import io.github.swagger2markup.markup.builder.MarkupLanguage;
|
||||
import io.github.swagger2markup.model.SwaggerPathOperation;
|
||||
import io.github.swagger2markup.model.PathOperation;
|
||||
import io.github.swagger2markup.spi.MarkupComponent;
|
||||
import io.swagger.models.parameters.Parameter;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
@@ -35,7 +34,7 @@ import org.apache.commons.lang3.Validate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static io.github.swagger2markup.SwaggerLabels.*;
|
||||
import static io.github.swagger2markup.Labels.*;
|
||||
import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.copyMarkupDocBuilder;
|
||||
import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.markupDescription;
|
||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
@@ -45,21 +44,21 @@ public class BodyParameterComponent extends MarkupComponent<BodyParameterCompone
|
||||
private final DocumentResolver definitionDocumentResolver;
|
||||
private final PropertiesTableComponent propertiesTableComponent;
|
||||
|
||||
public BodyParameterComponent(Swagger2MarkupConverter.SwaggerContext context,
|
||||
public BodyParameterComponent(Swagger2MarkupConverter.Context context,
|
||||
DocumentResolver definitionDocumentResolver) {
|
||||
super(context);
|
||||
this.definitionDocumentResolver = Validate.notNull(definitionDocumentResolver, "DocumentResolver must not be null");
|
||||
this.propertiesTableComponent = new PropertiesTableComponent(context, definitionDocumentResolver);
|
||||
}
|
||||
|
||||
public static BodyParameterComponent.Parameters parameters(SwaggerPathOperation operation,
|
||||
public static BodyParameterComponent.Parameters parameters(PathOperation operation,
|
||||
List<ObjectType> inlineDefinitions) {
|
||||
return new BodyParameterComponent.Parameters(operation, inlineDefinitions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, Parameters params) {
|
||||
SwaggerPathOperation operation = params.operation;
|
||||
PathOperation operation = params.operation;
|
||||
List<ObjectType> inlineDefinitions = params.inlineDefinitions;
|
||||
if (config.isFlatBodyEnabled()) {
|
||||
List<Parameter> parameters = operation.getOperation().getParameters();
|
||||
@@ -75,8 +74,7 @@ public class BodyParameterComponent extends MarkupComponent<BodyParameterCompone
|
||||
buildSectionTitle(markupDocBuilder, labels.getLabel(BODY_PARAMETER));
|
||||
String description = parameter.getDescription();
|
||||
if (isNotBlank(description)) {
|
||||
MarkupLanguage markupLanguage = MarkupLanguage.valueOf(config.getSchemaMarkupLanguage().name());
|
||||
markupDocBuilder.paragraph(markupDescription(markupLanguage, markupDocBuilder, description));
|
||||
markupDocBuilder.paragraph(markupDescription(config.getSwaggerMarkupLanguage(), markupDocBuilder, description));
|
||||
}
|
||||
|
||||
MarkupDocBuilder typeInfos = copyMarkupDocBuilder(markupDocBuilder);
|
||||
@@ -117,9 +115,9 @@ public class BodyParameterComponent extends MarkupComponent<BodyParameterCompone
|
||||
|
||||
public static class Parameters {
|
||||
private final List<ObjectType> inlineDefinitions;
|
||||
private SwaggerPathOperation operation;
|
||||
private PathOperation operation;
|
||||
|
||||
public Parameters(SwaggerPathOperation operation,
|
||||
public Parameters(PathOperation operation,
|
||||
List<ObjectType> inlineDefinitions) {
|
||||
Validate.notNull(operation, "Operation must not be null");
|
||||
this.operation = operation;
|
||||
@@ -16,8 +16,8 @@
|
||||
package io.github.swagger2markup.internal.component;
|
||||
|
||||
|
||||
import io.github.swagger2markup.Labels;
|
||||
import io.github.swagger2markup.Swagger2MarkupConverter;
|
||||
import io.github.swagger2markup.SwaggerLabels;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import io.github.swagger2markup.spi.MarkupComponent;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
@@ -29,7 +29,7 @@ import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.lite
|
||||
|
||||
public class ConsumesComponent extends MarkupComponent<ConsumesComponent.Parameters> {
|
||||
|
||||
public ConsumesComponent(Swagger2MarkupConverter.SwaggerContext context) {
|
||||
public ConsumesComponent(Swagger2MarkupConverter.Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ public class ConsumesComponent extends MarkupComponent<ConsumesComponent.Paramet
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, Parameters params) {
|
||||
markupDocBuilder.sectionTitleLevel(params.titleLevel, labels.getLabel(SwaggerLabels.CONSUMES));
|
||||
markupDocBuilder.sectionTitleLevel(params.titleLevel, labels.getLabel(Labels.CONSUMES));
|
||||
markupDocBuilder.unorderedList(params.consumes.stream()
|
||||
.map(value -> literalText(markupDocBuilder, value)).collect(Collectors.toList()));
|
||||
return markupDocBuilder;
|
||||
@@ -16,8 +16,8 @@
|
||||
package io.github.swagger2markup.internal.component;
|
||||
|
||||
|
||||
import io.github.swagger2markup.Labels;
|
||||
import io.github.swagger2markup.Swagger2MarkupConverter;
|
||||
import io.github.swagger2markup.SwaggerLabels;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import io.github.swagger2markup.spi.MarkupComponent;
|
||||
import io.swagger.models.Contact;
|
||||
@@ -28,7 +28,7 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
|
||||
public class ContactInfoComponent extends MarkupComponent<ContactInfoComponent.Parameters> {
|
||||
|
||||
public ContactInfoComponent(Swagger2MarkupConverter.SwaggerContext context) {
|
||||
public ContactInfoComponent(Swagger2MarkupConverter.Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@@ -41,14 +41,14 @@ public class ContactInfoComponent extends MarkupComponent<ContactInfoComponent.P
|
||||
public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, Parameters params) {
|
||||
Contact contact = params.contact;
|
||||
if (isNotBlank(contact.getName()) || isNotBlank(contact.getEmail())) {
|
||||
markupDocBuilder.sectionTitleLevel(params.titleLevel, labels.getLabel(SwaggerLabels.CONTACT_INFORMATION));
|
||||
markupDocBuilder.sectionTitleLevel(params.titleLevel, labels.getLabel(Labels.CONTACT_INFORMATION));
|
||||
MarkupDocBuilder paragraphBuilder = copyMarkupDocBuilder(markupDocBuilder);
|
||||
if (isNotBlank(contact.getName())) {
|
||||
paragraphBuilder.italicText(labels.getLabel(SwaggerLabels.CONTACT_NAME))
|
||||
paragraphBuilder.italicText(labels.getLabel(Labels.CONTACT_NAME))
|
||||
.textLine(COLON + contact.getName());
|
||||
}
|
||||
if (isNotBlank(contact.getEmail())) {
|
||||
paragraphBuilder.italicText(labels.getLabel(SwaggerLabels.CONTACT_EMAIL))
|
||||
paragraphBuilder.italicText(labels.getLabel(Labels.CONTACT_EMAIL))
|
||||
.textLine(COLON + contact.getEmail());
|
||||
}
|
||||
markupDocBuilder.paragraph(paragraphBuilder.toString(), true);
|
||||
@@ -23,20 +23,18 @@ 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.markup.builder.MarkupLanguage;
|
||||
import io.github.swagger2markup.spi.DefinitionsDocumentExtension;
|
||||
import io.github.swagger2markup.spi.MarkupComponent;
|
||||
import io.swagger.models.Model;
|
||||
import io.swagger.models.properties.Property;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static io.github.swagger2markup.SwaggerLabels.*;
|
||||
import static io.github.swagger2markup.Labels.*;
|
||||
import static io.github.swagger2markup.internal.utils.InlineSchemaUtils.createInlineType;
|
||||
import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.copyMarkupDocBuilder;
|
||||
import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.markupDescription;
|
||||
import static io.github.swagger2markup.spi.DefinitionsDocumentExtension.Context;
|
||||
import static io.github.swagger2markup.spi.DefinitionsDocumentExtension.Position;
|
||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
|
||||
@@ -50,10 +48,10 @@ public class DefinitionComponent extends MarkupComponent<DefinitionComponent.Par
|
||||
private final DocumentResolver definitionsDocumentResolver;
|
||||
private PropertiesTableComponent propertiesTableComponent;
|
||||
|
||||
public DefinitionComponent(Swagger2MarkupConverter.SwaggerContext context,
|
||||
public DefinitionComponent(Swagger2MarkupConverter.Context context,
|
||||
DocumentResolver definitionsDocumentResolver) {
|
||||
super(context);
|
||||
this.definitions = context.getSchema().getDefinitions();
|
||||
this.definitions = context.getSwagger().getDefinitions();
|
||||
this.definitionsDocumentResolver = definitionsDocumentResolver;
|
||||
POLYMORPHISM_NATURE = new HashMap<ObjectTypePolymorphism.Nature, String>() {{
|
||||
put(ObjectTypePolymorphism.Nature.COMPOSITION, labels.getLabel(POLYMORPHISM_NATURE_COMPOSITION));
|
||||
@@ -71,38 +69,21 @@ public class DefinitionComponent extends MarkupComponent<DefinitionComponent.Par
|
||||
@Override
|
||||
public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, Parameters params) {
|
||||
String definitionName = params.definitionName;
|
||||
String definitionTitle = determineDefinitionTitle(params);
|
||||
|
||||
Model model = params.model;
|
||||
applyDefinitionsDocumentExtension(new Context(Position.DEFINITION_BEFORE, markupDocBuilder, definitionName, model));
|
||||
markupDocBuilder.sectionTitleWithAnchorLevel(params.titleLevel, definitionTitle, definitionName);
|
||||
applyDefinitionsDocumentExtension(new Context(Position.DEFINITION_BEGIN, markupDocBuilder, definitionName, model));
|
||||
applyDefinitionsDocumentExtension(new DefinitionsDocumentExtension.Context(Position.DEFINITION_BEFORE, markupDocBuilder, definitionName, model));
|
||||
markupDocBuilder.sectionTitleWithAnchorLevel(params.titleLevel, definitionName, definitionName);
|
||||
applyDefinitionsDocumentExtension(new DefinitionsDocumentExtension.Context(Position.DEFINITION_BEGIN, markupDocBuilder, definitionName, model));
|
||||
String description = model.getDescription();
|
||||
if (isNotBlank(description)) {
|
||||
markupDocBuilder.paragraph(markupDescription(MarkupLanguage.valueOf(config.getSchemaMarkupLanguage().name()),
|
||||
markupDocBuilder, description));
|
||||
markupDocBuilder.paragraph(markupDescription(config.getSwaggerMarkupLanguage(), markupDocBuilder, description));
|
||||
}
|
||||
inlineDefinitions(markupDocBuilder, typeSection(markupDocBuilder, definitionName, model), definitionName);
|
||||
applyDefinitionsDocumentExtension(new Context(Position.DEFINITION_END, markupDocBuilder, definitionName, model));
|
||||
applyDefinitionsDocumentExtension(new Context(Position.DEFINITION_AFTER, markupDocBuilder, definitionName, model));
|
||||
applyDefinitionsDocumentExtension(new DefinitionsDocumentExtension.Context(Position.DEFINITION_END, markupDocBuilder, definitionName, model));
|
||||
applyDefinitionsDocumentExtension(new DefinitionsDocumentExtension.Context(Position.DEFINITION_AFTER, markupDocBuilder, definitionName, model));
|
||||
|
||||
return markupDocBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines title for definition. If title is present, it is used, definitionName is returned otherwise.
|
||||
*
|
||||
* @param params params object for this definition
|
||||
* @return Definition title - value from title tag if present, definitionName otherwise
|
||||
*/
|
||||
private String determineDefinitionTitle(Parameters params) {
|
||||
if (params.model.getTitle() != null) {
|
||||
return params.model.getTitle();
|
||||
} else {
|
||||
return params.definitionName;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
@@ -176,14 +157,11 @@ public class DefinitionComponent extends MarkupComponent<DefinitionComponent.Par
|
||||
if (isNotBlank(typeInfosString))
|
||||
markupDocBuilder.paragraph(typeInfosString, true);
|
||||
|
||||
Map<String, Property> properties = ((ObjectType) modelType).getProperties();
|
||||
if (!properties.isEmpty()) {
|
||||
propertiesTableComponent.apply(markupDocBuilder,
|
||||
PropertiesTableComponent.parameters(
|
||||
properties,
|
||||
definitionName,
|
||||
inlineDefinitions));
|
||||
}
|
||||
propertiesTableComponent.apply(markupDocBuilder,
|
||||
PropertiesTableComponent.parameters(
|
||||
((ObjectType) modelType).getProperties(),
|
||||
definitionName,
|
||||
inlineDefinitions));
|
||||
} else if (modelType != null) {
|
||||
MarkupDocBuilder typeInfos = copyMarkupDocBuilder(markupDocBuilder);
|
||||
typeInfos.italicText(labels.getLabel(TYPE_COLUMN)).textLine(COLON + modelType.displaySchema(markupDocBuilder));
|
||||
@@ -199,7 +177,7 @@ public class DefinitionComponent extends MarkupComponent<DefinitionComponent.Par
|
||||
*
|
||||
* @param context context
|
||||
*/
|
||||
private void applyDefinitionsDocumentExtension(Context context) {
|
||||
private void applyDefinitionsDocumentExtension(DefinitionsDocumentExtension.Context context) {
|
||||
extensionRegistry.getDefinitionsDocumentExtensions().forEach(extension -> extension.apply(context));
|
||||
}
|
||||
|
||||
@@ -21,13 +21,15 @@ import io.github.swagger2markup.spi.MarkupComponent;
|
||||
import io.swagger.models.ExternalDocs;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import static io.github.swagger2markup.SwaggerLabels.*;
|
||||
import static io.github.swagger2markup.Labels.EXTERNAL_DOCS;
|
||||
import static io.github.swagger2markup.Labels.EXTERNAL_DOCS_DESC;
|
||||
import static io.github.swagger2markup.Labels.EXTERNAL_DOCS_URL;
|
||||
import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.copyMarkupDocBuilder;
|
||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
|
||||
public class ExternalDocsComponent extends MarkupComponent<ExternalDocsComponent.Parameters> {
|
||||
|
||||
public ExternalDocsComponent(Swagger2MarkupConverter.SwaggerContext context) {
|
||||
public ExternalDocsComponent(Swagger2MarkupConverter.Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@@ -22,13 +22,13 @@ import io.swagger.models.Info;
|
||||
import io.swagger.models.License;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import static io.github.swagger2markup.SwaggerLabels.*;
|
||||
import static io.github.swagger2markup.Labels.*;
|
||||
import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.copyMarkupDocBuilder;
|
||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
|
||||
public class LicenseInfoComponent extends MarkupComponent<LicenseInfoComponent.Parameters> {
|
||||
|
||||
public LicenseInfoComponent(Swagger2MarkupConverter.SwaggerContext context) {
|
||||
public LicenseInfoComponent(Swagger2MarkupConverter.Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import io.github.swagger2markup.internal.adapter.ParameterAdapter;
|
||||
import io.github.swagger2markup.internal.resolver.DocumentResolver;
|
||||
import io.github.swagger2markup.internal.type.ObjectType;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import io.github.swagger2markup.model.SwaggerPathOperation;
|
||||
import io.github.swagger2markup.model.PathOperation;
|
||||
import io.github.swagger2markup.spi.MarkupComponent;
|
||||
import io.github.swagger2markup.spi.PathsDocumentExtension;
|
||||
import io.swagger.models.parameters.Parameter;
|
||||
@@ -30,12 +30,11 @@ import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static ch.netzwerg.paleo.ColumnIds.StringColumnId;
|
||||
import static io.github.swagger2markup.SwaggerLabels.*;
|
||||
import static io.github.swagger2markup.Labels.*;
|
||||
import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.copyMarkupDocBuilder;
|
||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
|
||||
@@ -45,7 +44,7 @@ public class ParameterTableComponent extends MarkupComponent<ParameterTableCompo
|
||||
private final DocumentResolver definitionDocumentResolver;
|
||||
private final TableComponent tableComponent;
|
||||
|
||||
ParameterTableComponent(Swagger2MarkupConverter.SwaggerContext context,
|
||||
ParameterTableComponent(Swagger2MarkupConverter.Context context,
|
||||
DocumentResolver definitionDocumentResolver) {
|
||||
super(context);
|
||||
this.definitionDocumentResolver = Validate.notNull(definitionDocumentResolver, "DocumentResolver must not be null");
|
||||
@@ -53,7 +52,7 @@ public class ParameterTableComponent extends MarkupComponent<ParameterTableCompo
|
||||
|
||||
}
|
||||
|
||||
public static ParameterTableComponent.Parameters parameters(SwaggerPathOperation operation,
|
||||
public static ParameterTableComponent.Parameters parameters(PathOperation operation,
|
||||
List<ObjectType> inlineDefinitions,
|
||||
int titleLevel) {
|
||||
return new ParameterTableComponent.Parameters(operation, inlineDefinitions, titleLevel);
|
||||
@@ -61,17 +60,11 @@ public class ParameterTableComponent extends MarkupComponent<ParameterTableCompo
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, Parameters params) {
|
||||
SwaggerPathOperation operation = params.operation;
|
||||
PathOperation operation = params.operation;
|
||||
List<ObjectType> inlineDefinitions = params.inlineDefinitions;
|
||||
List<Parameter> parameters = operation.getOperation().getParameters();
|
||||
if (config.getParameterOrdering() != null) {
|
||||
Comparator<io.github.swagger2markup.model.Parameter> parameterOrdering = config.getParameterOrdering();
|
||||
parameters.sort((o1, o2) -> {
|
||||
io.github.swagger2markup.model.Parameter p1 = new io.github.swagger2markup.model.Parameter(o1.getName(), o1.getIn());
|
||||
io.github.swagger2markup.model.Parameter p2 = new io.github.swagger2markup.model.Parameter(o2.getName(), o2.getIn());
|
||||
return parameterOrdering.compare(p1, p2);
|
||||
});
|
||||
}
|
||||
if (config.getParameterOrdering() != null)
|
||||
parameters.sort(config.getParameterOrdering());
|
||||
|
||||
// Filter parameters to display in parameters section
|
||||
List<Parameter> filteredParameters = parameters.stream()
|
||||
@@ -102,7 +95,7 @@ public class ParameterTableComponent extends MarkupComponent<ParameterTableCompo
|
||||
|
||||
typeColumnBuilder.add(parameterAdapter.displayType(markupDocBuilder));
|
||||
nameColumnBuilder.add(getParameterNameColumnContent(markupDocBuilder, parameterAdapter));
|
||||
descriptionColumnBuilder.add(buildDescriptionForParameter(markupDocBuilder, parameterAdapter));
|
||||
descriptionColumnBuilder.add(parameterAdapter.displayDescription(markupDocBuilder));
|
||||
schemaColumnBuilder.add(parameterAdapter.displaySchema(markupDocBuilder));
|
||||
defaultColumnBuilder.add(parameterAdapter.displayDefaultValue(markupDocBuilder));
|
||||
}
|
||||
@@ -127,20 +120,6 @@ public class ParameterTableComponent extends MarkupComponent<ParameterTableCompo
|
||||
return markupDocBuilder;
|
||||
}
|
||||
|
||||
private String buildDescriptionForParameter(MarkupDocBuilder markupDocBuilder, ParameterAdapter parameterAdapter) {
|
||||
MarkupDocBuilder descriptionBuilder = copyMarkupDocBuilder(markupDocBuilder);
|
||||
String basicDescription = parameterAdapter.displayDescription(descriptionBuilder);
|
||||
descriptionBuilder.text(basicDescription);
|
||||
|
||||
if (parameterAdapter.getMinItems().isPresent()) {
|
||||
descriptionBuilder.newLine(true).boldText(labels.getLabel(MIN_ITEMS)).text(COLON).text(String.valueOf(parameterAdapter.getMinItems().get()));
|
||||
}
|
||||
if (parameterAdapter.getMaxItems().isPresent()) {
|
||||
descriptionBuilder.newLine().boldText(labels.getLabel(MAX_ITEMS)).text(COLON).text(String.valueOf(parameterAdapter.getMaxItems().get()));
|
||||
}
|
||||
return descriptionBuilder.toString();
|
||||
}
|
||||
|
||||
private String getParameterNameColumnContent(MarkupDocBuilder markupDocBuilder, ParameterAdapter parameter) {
|
||||
MarkupDocBuilder parameterNameContent = copyMarkupDocBuilder(markupDocBuilder);
|
||||
|
||||
@@ -172,11 +151,11 @@ public class ParameterTableComponent extends MarkupComponent<ParameterTableCompo
|
||||
}
|
||||
|
||||
public static class Parameters {
|
||||
private final SwaggerPathOperation operation;
|
||||
private final PathOperation operation;
|
||||
private final int titleLevel;
|
||||
private final List<ObjectType> inlineDefinitions;
|
||||
|
||||
public Parameters(SwaggerPathOperation operation,
|
||||
public Parameters(PathOperation operation,
|
||||
List<ObjectType> inlineDefinitions,
|
||||
int titleLevel) {
|
||||
this.operation = Validate.notNull(operation, "PathOperation must not be null");
|
||||
@@ -19,38 +19,32 @@ package io.github.swagger2markup.internal.component;
|
||||
import com.fasterxml.jackson.core.JsonFactory;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.github.swagger2markup.Swagger2MarkupConverter;
|
||||
import io.github.swagger2markup.GroupBy;
|
||||
import io.github.swagger2markup.PageBreakLocations;
|
||||
import io.github.swagger2markup.Swagger2MarkupConverter;
|
||||
import io.github.swagger2markup.internal.resolver.DocumentResolver;
|
||||
import io.github.swagger2markup.internal.type.ObjectType;
|
||||
import io.github.swagger2markup.internal.utils.ExamplesUtil;
|
||||
import io.github.swagger2markup.internal.utils.pathexamples.BasicPathExample;
|
||||
import io.github.swagger2markup.internal.utils.pathexamples.CurlPathExample;
|
||||
import io.github.swagger2markup.internal.utils.pathexamples.PathExample;
|
||||
import io.github.swagger2markup.internal.utils.pathexamples.InvokeWebRequestPathExample;
|
||||
import io.github.swagger2markup.markup.builder.MarkupAdmonition;
|
||||
import io.github.swagger2markup.markup.builder.MarkupBlockStyle;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import io.github.swagger2markup.markup.builder.MarkupLanguage;
|
||||
import io.github.swagger2markup.model.SwaggerPathOperation;
|
||||
import io.github.swagger2markup.model.PathOperation;
|
||||
import io.github.swagger2markup.spi.MarkupComponent;
|
||||
import io.github.swagger2markup.spi.PathsDocumentExtension;
|
||||
import io.swagger.models.Model;
|
||||
import io.swagger.util.Json;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.commons.lang3.StringEscapeUtils;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
import org.apache.commons.text.StringEscapeUtils;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import static io.github.swagger2markup.Labels.*;
|
||||
import static io.github.swagger2markup.PageBreakLocations.*;
|
||||
import static io.github.swagger2markup.SwaggerLabels.*;
|
||||
import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.copyMarkupDocBuilder;
|
||||
import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.markupDescription;
|
||||
import static io.github.swagger2markup.spi.PathsDocumentExtension.Context;
|
||||
import static io.github.swagger2markup.spi.PathsDocumentExtension.Position;
|
||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
|
||||
@@ -66,11 +60,11 @@ public class PathOperationComponent extends MarkupComponent<PathOperationCompone
|
||||
private final BodyParameterComponent bodyParameterComponent;
|
||||
private final ResponseComponent responseComponent;
|
||||
|
||||
public PathOperationComponent(Swagger2MarkupConverter.SwaggerContext context,
|
||||
public PathOperationComponent(Swagger2MarkupConverter.Context context,
|
||||
DocumentResolver definitionDocumentResolver,
|
||||
DocumentResolver securityDocumentResolver) {
|
||||
super(context);
|
||||
this.definitions = context.getSchema().getDefinitions();
|
||||
this.definitions = context.getSwagger().getDefinitions();
|
||||
this.definitionDocumentResolver = Validate.notNull(definitionDocumentResolver, "DocumentResolver must not be null");
|
||||
this.propertiesTableComponent = new PropertiesTableComponent(context, definitionDocumentResolver);
|
||||
this.parameterTableComponent = new ParameterTableComponent(context, definitionDocumentResolver);
|
||||
@@ -81,21 +75,21 @@ public class PathOperationComponent extends MarkupComponent<PathOperationCompone
|
||||
this.responseComponent = new ResponseComponent(context, definitionDocumentResolver);
|
||||
}
|
||||
|
||||
public static PathOperationComponent.Parameters parameters(SwaggerPathOperation operation) {
|
||||
public static PathOperationComponent.Parameters parameters(PathOperation operation) {
|
||||
return new PathOperationComponent.Parameters(operation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, Parameters params) {
|
||||
SwaggerPathOperation operation = params.operation;
|
||||
PathOperation operation = params.operation;
|
||||
List<PageBreakLocations> locations = config.getPageBreakLocations();
|
||||
|
||||
applyPathsDocumentExtension(new Context(Position.OPERATION_BEFORE, markupDocBuilder, operation));
|
||||
applyPathsDocumentExtension(new PathsDocumentExtension.Context(Position.OPERATION_BEFORE, markupDocBuilder, operation));
|
||||
|
||||
if (locations.contains(BEFORE_OPERATION)) markupDocBuilder.pageBreak();
|
||||
buildOperationTitle(markupDocBuilder, operation);
|
||||
|
||||
applyPathsDocumentExtension(new Context(Position.OPERATION_BEGIN, markupDocBuilder, operation));
|
||||
applyPathsDocumentExtension(new PathsDocumentExtension.Context(Position.OPERATION_BEGIN, markupDocBuilder, operation));
|
||||
buildDeprecatedSection(markupDocBuilder, operation);
|
||||
|
||||
if (locations.contains(BEFORE_OPERATION_DESCRIPTION)) markupDocBuilder.pageBreak();
|
||||
@@ -103,13 +97,13 @@ public class PathOperationComponent extends MarkupComponent<PathOperationCompone
|
||||
if (locations.contains(AFTER_OPERATION_DESCRIPTION)) markupDocBuilder.pageBreak();
|
||||
|
||||
if (locations.contains(BEFORE_OPERATION_PARAMETERS)) markupDocBuilder.pageBreak();
|
||||
inlineDefinitions(markupDocBuilder, buildParametersSection(markupDocBuilder, operation), operation.getPath() + " " + operation.getHttpMethod());
|
||||
inlineDefinitions(markupDocBuilder, buildParametersSection(markupDocBuilder, operation), operation.getPath() + " " + operation.getMethod());
|
||||
if (locations.contains(AFTER_OPERATION_PARAMETERS)) markupDocBuilder.pageBreak();
|
||||
|
||||
inlineDefinitions(markupDocBuilder, buildBodyParameterSection(markupDocBuilder, operation), operation.getPath() + " " + operation.getHttpMethod());
|
||||
inlineDefinitions(markupDocBuilder, buildBodyParameterSection(markupDocBuilder, operation), operation.getPath() + " " + operation.getMethod());
|
||||
|
||||
if (locations.contains(BEFORE_OPERATION_RESPONSES)) markupDocBuilder.pageBreak();
|
||||
inlineDefinitions(markupDocBuilder, buildResponsesSection(markupDocBuilder, operation), operation.getPath() + " " + operation.getHttpMethod());
|
||||
inlineDefinitions(markupDocBuilder, buildResponsesSection(markupDocBuilder, operation), operation.getPath() + " " + operation.getMethod());
|
||||
if (locations.contains(AFTER_OPERATION_RESPONSES)) markupDocBuilder.pageBreak();
|
||||
|
||||
if (locations.contains(BEFORE_OPERATION_CONSUMES)) markupDocBuilder.pageBreak();
|
||||
@@ -123,8 +117,8 @@ public class PathOperationComponent extends MarkupComponent<PathOperationCompone
|
||||
buildTagsSection(markupDocBuilder, operation);
|
||||
buildSecuritySchemeSection(markupDocBuilder, operation);
|
||||
buildExamplesSection(markupDocBuilder, operation, locations);
|
||||
applyPathsDocumentExtension(new Context(Position.OPERATION_END, markupDocBuilder, operation));
|
||||
applyPathsDocumentExtension(new Context(Position.OPERATION_AFTER, markupDocBuilder, operation));
|
||||
applyPathsDocumentExtension(new PathsDocumentExtension.Context(Position.OPERATION_END, markupDocBuilder, operation));
|
||||
applyPathsDocumentExtension(new PathsDocumentExtension.Context(Position.OPERATION_AFTER, markupDocBuilder, operation));
|
||||
|
||||
if (locations.contains(AFTER_OPERATION)) markupDocBuilder.pageBreak();
|
||||
|
||||
@@ -137,10 +131,10 @@ public class PathOperationComponent extends MarkupComponent<PathOperationCompone
|
||||
*
|
||||
* @param operation the Swagger Operation
|
||||
*/
|
||||
private void buildOperationTitle(MarkupDocBuilder markupDocBuilder, SwaggerPathOperation operation) {
|
||||
private void buildOperationTitle(MarkupDocBuilder markupDocBuilder, PathOperation operation) {
|
||||
buildOperationTitle(markupDocBuilder, operation.getTitle(), operation.getId());
|
||||
if (operation.getTitle().equals(operation.getOperation().getSummary())) {
|
||||
markupDocBuilder.block(operation.getHttpMethod() + " " + operation.getPath(), MarkupBlockStyle.LITERAL);
|
||||
markupDocBuilder.block(operation.getMethod() + " " + operation.getPath(), MarkupBlockStyle.LITERAL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,9 +157,9 @@ public class PathOperationComponent extends MarkupComponent<PathOperationCompone
|
||||
*
|
||||
* @param operation the Swagger Operation
|
||||
*/
|
||||
private void buildDeprecatedSection(MarkupDocBuilder markupDocBuilder, SwaggerPathOperation operation) {
|
||||
private void buildDeprecatedSection(MarkupDocBuilder markupDocBuilder, PathOperation operation) {
|
||||
if (BooleanUtils.isTrue(operation.getOperation().isDeprecated())) {
|
||||
markupDocBuilder.block(labels.getLabel(DEPRECATED_OPERATION), MarkupBlockStyle.EXAMPLE, null, MarkupAdmonition.CAUTION);
|
||||
markupDocBuilder.block(DEPRECATED_OPERATION, MarkupBlockStyle.EXAMPLE, null, MarkupAdmonition.CAUTION);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,22 +168,22 @@ public class PathOperationComponent extends MarkupComponent<PathOperationCompone
|
||||
*
|
||||
* @param operation the Swagger Operation
|
||||
*/
|
||||
private void buildDescriptionSection(MarkupDocBuilder markupDocBuilder, SwaggerPathOperation operation) {
|
||||
private void buildDescriptionSection(MarkupDocBuilder markupDocBuilder, PathOperation operation) {
|
||||
MarkupDocBuilder descriptionBuilder = copyMarkupDocBuilder(markupDocBuilder);
|
||||
applyPathsDocumentExtension(new Context(Position.OPERATION_DESCRIPTION_BEGIN, descriptionBuilder, operation));
|
||||
applyPathsDocumentExtension(new PathsDocumentExtension.Context(Position.OPERATION_DESCRIPTION_BEGIN, descriptionBuilder, operation));
|
||||
String description = operation.getOperation().getDescription();
|
||||
if (isNotBlank(description)) {
|
||||
descriptionBuilder.paragraph(markupDescription(MarkupLanguage.valueOf(config.getSchemaMarkupLanguage().name()), markupDocBuilder, description));
|
||||
descriptionBuilder.paragraph(markupDescription(config.getSwaggerMarkupLanguage(), markupDocBuilder, description));
|
||||
}
|
||||
applyPathsDocumentExtension(new Context(Position.OPERATION_DESCRIPTION_END, descriptionBuilder, operation));
|
||||
applyPathsDocumentExtension(new PathsDocumentExtension.Context(Position.OPERATION_DESCRIPTION_END, descriptionBuilder, operation));
|
||||
String descriptionContent = descriptionBuilder.toString();
|
||||
|
||||
applyPathsDocumentExtension(new Context(Position.OPERATION_DESCRIPTION_BEFORE, markupDocBuilder, operation));
|
||||
applyPathsDocumentExtension(new PathsDocumentExtension.Context(Position.OPERATION_DESCRIPTION_BEFORE, markupDocBuilder, operation));
|
||||
if (isNotBlank(descriptionContent)) {
|
||||
buildSectionTitle(markupDocBuilder, labels.getLabel(DESCRIPTION));
|
||||
markupDocBuilder.text(descriptionContent);
|
||||
}
|
||||
applyPathsDocumentExtension(new Context(Position.OPERATION_DESCRIPTION_AFTER, markupDocBuilder, operation));
|
||||
applyPathsDocumentExtension(new PathsDocumentExtension.Context(Position.OPERATION_DESCRIPTION_AFTER, markupDocBuilder, operation));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -197,7 +191,7 @@ public class PathOperationComponent extends MarkupComponent<PathOperationCompone
|
||||
*
|
||||
* @param operation the Swagger Operation
|
||||
*/
|
||||
private List<ObjectType> buildParametersSection(MarkupDocBuilder markupDocBuilder, SwaggerPathOperation operation) {
|
||||
private List<ObjectType> buildParametersSection(MarkupDocBuilder markupDocBuilder, PathOperation operation) {
|
||||
|
||||
List<ObjectType> inlineDefinitions = new ArrayList<>();
|
||||
|
||||
@@ -216,7 +210,7 @@ public class PathOperationComponent extends MarkupComponent<PathOperationCompone
|
||||
* @param operation the Swagger Operation
|
||||
* @return a list of inlined types.
|
||||
*/
|
||||
private List<ObjectType> buildBodyParameterSection(MarkupDocBuilder markupDocBuilder, SwaggerPathOperation operation) {
|
||||
private List<ObjectType> buildBodyParameterSection(MarkupDocBuilder markupDocBuilder, PathOperation operation) {
|
||||
List<ObjectType> inlineDefinitions = new ArrayList<>();
|
||||
|
||||
bodyParameterComponent.apply(markupDocBuilder, BodyParameterComponent.parameters(
|
||||
@@ -227,7 +221,7 @@ public class PathOperationComponent extends MarkupComponent<PathOperationCompone
|
||||
return inlineDefinitions;
|
||||
}
|
||||
|
||||
private List<ObjectType> buildResponsesSection(MarkupDocBuilder markupDocBuilder, SwaggerPathOperation operation) {
|
||||
private List<ObjectType> buildResponsesSection(MarkupDocBuilder markupDocBuilder, PathOperation operation) {
|
||||
List<ObjectType> inlineDefinitions = new ArrayList<>();
|
||||
|
||||
responseComponent.apply(markupDocBuilder, ResponseComponent.parameters(
|
||||
@@ -290,7 +284,7 @@ public class PathOperationComponent extends MarkupComponent<PathOperationCompone
|
||||
|
||||
}
|
||||
|
||||
private void buildConsumesSection(MarkupDocBuilder markupDocBuilder, SwaggerPathOperation operation) {
|
||||
private void buildConsumesSection(MarkupDocBuilder markupDocBuilder, PathOperation operation) {
|
||||
List<String> consumes = operation.getOperation().getConsumes();
|
||||
if (CollectionUtils.isNotEmpty(consumes)) {
|
||||
consumesComponent.apply(markupDocBuilder, ConsumesComponent.parameters(consumes,
|
||||
@@ -299,7 +293,7 @@ public class PathOperationComponent extends MarkupComponent<PathOperationCompone
|
||||
|
||||
}
|
||||
|
||||
private void buildProducesSection(MarkupDocBuilder markupDocBuilder, SwaggerPathOperation operation) {
|
||||
private void buildProducesSection(MarkupDocBuilder markupDocBuilder, PathOperation operation) {
|
||||
List<String> produces = operation.getOperation().getProduces();
|
||||
if (CollectionUtils.isNotEmpty(produces)) {
|
||||
producesComponent.apply(markupDocBuilder, ProducesComponent.parameters(produces,
|
||||
@@ -307,7 +301,7 @@ public class PathOperationComponent extends MarkupComponent<PathOperationCompone
|
||||
}
|
||||
}
|
||||
|
||||
private void buildTagsSection(MarkupDocBuilder markupDocBuilder, SwaggerPathOperation operation) {
|
||||
private void buildTagsSection(MarkupDocBuilder markupDocBuilder, PathOperation operation) {
|
||||
if (config.getPathsGroupedBy() == GroupBy.AS_IS) {
|
||||
List<String> tags = operation.getOperation().getTags();
|
||||
if (CollectionUtils.isNotEmpty(tags)) {
|
||||
@@ -325,7 +319,7 @@ public class PathOperationComponent extends MarkupComponent<PathOperationCompone
|
||||
*
|
||||
* @param operation the Swagger Operation
|
||||
*/
|
||||
private void buildSecuritySchemeSection(MarkupDocBuilder markupDocBuilder, SwaggerPathOperation operation) {
|
||||
private void buildSecuritySchemeSection(MarkupDocBuilder markupDocBuilder, PathOperation operation) {
|
||||
if (config.isPathSecuritySectionEnabled()) {
|
||||
securitySchemeComponent.apply(markupDocBuilder, SecuritySchemeComponent.parameters(
|
||||
operation,
|
||||
@@ -350,33 +344,18 @@ public class PathOperationComponent extends MarkupComponent<PathOperationCompone
|
||||
*
|
||||
* @param operation the Swagger Operation
|
||||
*/
|
||||
private void buildExamplesSection(MarkupDocBuilder markupDocBuilder, SwaggerPathOperation operation, List<PageBreakLocations> locations) {
|
||||
PathExample pathGenerator;
|
||||
switch (config.getRequestExamplesFormat().toLowerCase()) {
|
||||
case "curl":
|
||||
pathGenerator = new CurlPathExample(context, definitionDocumentResolver, operation);
|
||||
break;
|
||||
case "invoke-webrequest":
|
||||
pathGenerator = new InvokeWebRequestPathExample(context, definitionDocumentResolver, operation);
|
||||
break;
|
||||
case "basic":
|
||||
pathGenerator = new BasicPathExample(context, definitionDocumentResolver, operation);
|
||||
break;
|
||||
default:
|
||||
logger.warn(
|
||||
"Unknown format name '{}' for requestExamplesFormat config parameter, falling back to 'basic'",
|
||||
config.getRequestExamplesFormat());
|
||||
pathGenerator = new BasicPathExample(context, definitionDocumentResolver, operation);
|
||||
}
|
||||
|
||||
Map<String, Object> generatedRequestExampleMap = ExamplesUtil.generateRequestExampleMap(pathGenerator, definitions, markupDocBuilder);
|
||||
private void buildExamplesSection(MarkupDocBuilder markupDocBuilder, PathOperation operation, List<PageBreakLocations> locations) {
|
||||
// Generate examples
|
||||
Map<String, Object> generatedRequestExampleMap = ExamplesUtil.generateRequestExampleMap(config.isGeneratedExamplesEnabled(), operation, definitions, definitionDocumentResolver, markupDocBuilder);
|
||||
Map<String, Object> generatedResponseExampleMap = ExamplesUtil.generateResponseExampleMap(config.isGeneratedExamplesEnabled(), operation, definitions, definitionDocumentResolver, markupDocBuilder);
|
||||
|
||||
// Get page break settings
|
||||
boolean beforeExampleRequestBreak = locations.contains(BEFORE_OPERATION_EXAMPLE_REQUEST);
|
||||
boolean afterExampleRequestBreak = locations.contains(AFTER_OPERATION_EXAMPLE_REQUEST);
|
||||
boolean beforeExampleResponseBreak = locations.contains(BEFORE_OPERATION_EXAMPLE_RESPONSE);
|
||||
boolean afterExampleResponseBreak = locations.contains(AFTER_OPERATION_EXAMPLE_RESPONSE);
|
||||
|
||||
// Write examples
|
||||
exampleMap(markupDocBuilder, generatedRequestExampleMap, labels.getLabel(EXAMPLE_REQUEST), labels.getLabel(REQUEST), beforeExampleRequestBreak, afterExampleRequestBreak);
|
||||
exampleMap(markupDocBuilder, generatedResponseExampleMap, labels.getLabel(EXAMPLE_RESPONSE), labels.getLabel(RESPONSE), beforeExampleResponseBreak, afterExampleResponseBreak);
|
||||
}
|
||||
@@ -390,11 +369,12 @@ public class PathOperationComponent extends MarkupComponent<PathOperationCompone
|
||||
// Example title, like "Response 200" or "Request Body"
|
||||
buildExampleTitle(markupDocBuilder, sectionTitle + " " + entry.getKey());
|
||||
|
||||
if (NumberUtils.isCreatable(entry.getKey())) {
|
||||
if (NumberUtils.isNumber(entry.getKey())) {
|
||||
// Section header is an HTTP status code (numeric)
|
||||
JsonNode rootNode = parseExample(entry.getValue());
|
||||
Iterator<Map.Entry<String, JsonNode>> fieldsIterator = rootNode.fields();
|
||||
|
||||
|
||||
if (!fieldsIterator.hasNext()) {
|
||||
// rootNode contains a single example, no need to further iterate.
|
||||
String example = Json.pretty(rootNode);
|
||||
@@ -405,13 +385,13 @@ public class PathOperationComponent extends MarkupComponent<PathOperationCompone
|
||||
while (fieldsIterator.hasNext()) {
|
||||
Map.Entry<String, JsonNode> field = fieldsIterator.next();
|
||||
|
||||
if (field.getKey().equals("application/json") || field.getKey().contains("+json")) {
|
||||
if (field.getKey().equals("application/json")) {
|
||||
String example = Json.pretty(field.getValue());
|
||||
example = stripExampleQuotes(StringEscapeUtils.unescapeJson(example));
|
||||
|
||||
markupDocBuilder.listingBlock(example, "json");
|
||||
|
||||
} else if (field.getKey().equals("application/xml") || field.getKey().contains("+xml")) {
|
||||
} else if (field.getKey().equals("application/xml")) {
|
||||
|
||||
String example = stripExampleQuotes(field.getValue().toString());
|
||||
example = StringEscapeUtils.unescapeJava(example);
|
||||
@@ -427,44 +407,13 @@ public class PathOperationComponent extends MarkupComponent<PathOperationCompone
|
||||
}
|
||||
} else if (entry.getKey().equals("path")) {
|
||||
// Path shouldn't have quotes around it
|
||||
PathExample pathGenerator = ((PathExample) entry.getValue());
|
||||
markupDocBuilder.listingBlock(pathGenerator.getRequestString(), pathGenerator.getAsciidocCodeLanguage());
|
||||
} else if (entry.getKey().equals("header")) {
|
||||
// Header should have format: apikey:"string"
|
||||
markupDocBuilder.listingBlock(entry.getValue().toString(), "json");
|
||||
markupDocBuilder.listingBlock(entry.getValue().toString());
|
||||
} else if (entry.getKey().equals("query")) {
|
||||
//TODO issue #264: print query parameters in table
|
||||
// markupDocBuilder.listingBlock(entry.getValue().toString());
|
||||
logger.debug("Skipping query parameter: " + entry.getValue().toString());
|
||||
} else {
|
||||
|
||||
Object value = entry.getValue();
|
||||
|
||||
if (value instanceof Map) {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, String> examplesByContentType = (Map<String, String>) value;
|
||||
|
||||
for (Entry<String, String> entryByType : examplesByContentType.entrySet()) {
|
||||
if (entryByType.getKey().equals("application/json")) {
|
||||
String example = Json.pretty(entryByType.getValue());
|
||||
example = stripExampleQuotes(StringEscapeUtils.unescapeJson(example));
|
||||
|
||||
markupDocBuilder.listingBlock(example, "json");
|
||||
|
||||
} else if (entryByType.getKey().equals("application/xml")) {
|
||||
|
||||
String example = stripExampleQuotes(entryByType.getValue());
|
||||
example = StringEscapeUtils.unescapeJava(example);
|
||||
|
||||
//TODO: pretty print XML
|
||||
|
||||
markupDocBuilder.listingBlock(example, "xml");
|
||||
} else {
|
||||
String example = Json.pretty(entry.getValue());
|
||||
markupDocBuilder.listingBlock(example, "json");
|
||||
break; // No need to print the same example multiple times
|
||||
}
|
||||
}
|
||||
} else {
|
||||
markupDocBuilder.listingBlock(Json.pretty(value), "json");
|
||||
}
|
||||
markupDocBuilder.listingBlock(Json.pretty(entry.getValue()), "json");
|
||||
}
|
||||
}
|
||||
if (afterBreak) markupDocBuilder.pageBreak();
|
||||
@@ -518,15 +467,15 @@ public class PathOperationComponent extends MarkupComponent<PathOperationCompone
|
||||
*
|
||||
* @param context context
|
||||
*/
|
||||
private void applyPathsDocumentExtension(Context context) {
|
||||
private void applyPathsDocumentExtension(PathsDocumentExtension.Context context) {
|
||||
extensionRegistry.getPathsDocumentExtensions().forEach(extension -> extension.apply(context));
|
||||
}
|
||||
|
||||
public static class Parameters {
|
||||
|
||||
private final SwaggerPathOperation operation;
|
||||
private final PathOperation operation;
|
||||
|
||||
public Parameters(SwaggerPathOperation operation) {
|
||||
public Parameters(PathOperation operation) {
|
||||
this.operation = Validate.notNull(operation, "PathOperation must not be null");
|
||||
}
|
||||
}
|
||||
@@ -16,8 +16,8 @@
|
||||
package io.github.swagger2markup.internal.component;
|
||||
|
||||
|
||||
import io.github.swagger2markup.Labels;
|
||||
import io.github.swagger2markup.Swagger2MarkupConverter;
|
||||
import io.github.swagger2markup.SwaggerLabels;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import io.github.swagger2markup.spi.MarkupComponent;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
@@ -30,7 +30,7 @@ import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.lite
|
||||
public class ProducesComponent extends MarkupComponent<ProducesComponent.Parameters> {
|
||||
|
||||
|
||||
public ProducesComponent(Swagger2MarkupConverter.SwaggerContext context) {
|
||||
public ProducesComponent(Swagger2MarkupConverter.Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ public class ProducesComponent extends MarkupComponent<ProducesComponent.Paramet
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, Parameters params) {
|
||||
markupDocBuilder.sectionTitleLevel(params.titleLevel, labels.getLabel(SwaggerLabels.PRODUCES));
|
||||
markupDocBuilder.sectionTitleLevel(params.titleLevel, labels.getLabel(Labels.PRODUCES));
|
||||
markupDocBuilder.unorderedList(params.produces.stream()
|
||||
.map(value -> literalText(markupDocBuilder, value)).collect(Collectors.toList()));
|
||||
return markupDocBuilder;
|
||||
@@ -24,7 +24,6 @@ import io.github.swagger2markup.internal.type.ObjectType;
|
||||
import io.github.swagger2markup.internal.type.RefType;
|
||||
import io.github.swagger2markup.internal.type.Type;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import io.github.swagger2markup.markup.builder.MarkupLanguage;
|
||||
import io.github.swagger2markup.spi.MarkupComponent;
|
||||
import io.swagger.models.properties.Property;
|
||||
import io.swagger.util.Json;
|
||||
@@ -38,7 +37,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import static io.github.swagger2markup.SwaggerLabels.*;
|
||||
import static io.github.swagger2markup.Labels.*;
|
||||
import static io.github.swagger2markup.internal.utils.InlineSchemaUtils.createInlineType;
|
||||
import static io.github.swagger2markup.internal.utils.MapUtils.toSortedMap;
|
||||
import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.copyMarkupDocBuilder;
|
||||
@@ -57,7 +56,7 @@ public class PropertiesTableComponent extends MarkupComponent<PropertiesTableCom
|
||||
*
|
||||
* @param definitionDocumentResolver definition document resolver to apply to property type cross-reference
|
||||
*/
|
||||
PropertiesTableComponent(Swagger2MarkupConverter.SwaggerContext context,
|
||||
PropertiesTableComponent(Swagger2MarkupConverter.Context context,
|
||||
DocumentResolver definitionDocumentResolver) {
|
||||
super(context);
|
||||
this.definitionDocumentResolver = definitionDocumentResolver;
|
||||
@@ -117,8 +116,7 @@ public class PropertiesTableComponent extends MarkupComponent<PropertiesTableCom
|
||||
}
|
||||
|
||||
MarkupDocBuilder descriptionContent = copyMarkupDocBuilder(markupDocBuilder);
|
||||
String description = markupDescription(MarkupLanguage.valueOf(config.getSchemaMarkupLanguage().name()),
|
||||
markupDocBuilder, property.getDescription());
|
||||
String description = markupDescription(config.getSwaggerMarkupLanguage(), markupDocBuilder, property.getDescription());
|
||||
if (isNotBlank(description))
|
||||
descriptionContent.text(description);
|
||||
|
||||
@@ -169,7 +167,7 @@ public class PropertiesTableComponent extends MarkupComponent<PropertiesTableCom
|
||||
}
|
||||
|
||||
DecimalFormat numberFormatter = new DecimalFormat("#.##",
|
||||
DecimalFormatSymbols.getInstance(config.getLanguage().toLocale()));
|
||||
DecimalFormatSymbols.getInstance(config.getOutputLanguage().toLocale()));
|
||||
|
||||
if (optionalMinValue.isPresent()) {
|
||||
if (isNotBlank(descriptionContent.toString())) {
|
||||
@@ -188,7 +186,7 @@ public class PropertiesTableComponent extends MarkupComponent<PropertiesTableCom
|
||||
}
|
||||
|
||||
if (optionalExample.isPresent()) {
|
||||
if (isNotBlank(descriptionContent.toString())) {
|
||||
if (isNotBlank(description) || optionalDefaultValue.isPresent()) {
|
||||
descriptionContent.newLine(true);
|
||||
}
|
||||
|
||||
@@ -20,16 +20,12 @@ import ch.netzwerg.paleo.StringColumn;
|
||||
import io.github.swagger2markup.Swagger2MarkupConverter;
|
||||
import io.github.swagger2markup.internal.adapter.PropertyAdapter;
|
||||
import io.github.swagger2markup.internal.resolver.DocumentResolver;
|
||||
import io.github.swagger2markup.internal.type.BasicType;
|
||||
import io.github.swagger2markup.internal.type.ObjectType;
|
||||
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.markup.builder.MarkupLanguage;
|
||||
import io.github.swagger2markup.model.SwaggerPathOperation;
|
||||
import io.github.swagger2markup.model.PathOperation;
|
||||
import io.github.swagger2markup.spi.MarkupComponent;
|
||||
import io.github.swagger2markup.spi.PathsDocumentExtension;
|
||||
import io.swagger.models.Model;
|
||||
import io.swagger.models.Response;
|
||||
import io.swagger.models.properties.Property;
|
||||
import io.swagger.util.Json;
|
||||
@@ -41,7 +37,7 @@ import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import static ch.netzwerg.paleo.ColumnIds.StringColumnId;
|
||||
import static io.github.swagger2markup.SwaggerLabels.*;
|
||||
import static io.github.swagger2markup.Labels.*;
|
||||
import static io.github.swagger2markup.internal.utils.InlineSchemaUtils.createInlineType;
|
||||
import static io.github.swagger2markup.internal.utils.MapUtils.toSortedMap;
|
||||
import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.*;
|
||||
@@ -50,18 +46,16 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
public class ResponseComponent extends MarkupComponent<ResponseComponent.Parameters> {
|
||||
|
||||
private final TableComponent tableComponent;
|
||||
private final Map<String, Model> definitions;
|
||||
private final DocumentResolver definitionDocumentResolver;
|
||||
|
||||
ResponseComponent(Swagger2MarkupConverter.SwaggerContext context,
|
||||
ResponseComponent(Swagger2MarkupConverter.Context context,
|
||||
DocumentResolver definitionDocumentResolver) {
|
||||
super(context);
|
||||
this.definitions = context.getSchema().getDefinitions();
|
||||
this.definitionDocumentResolver = Validate.notNull(definitionDocumentResolver, "DocumentResolver must not be null");
|
||||
this.tableComponent = new TableComponent(context);
|
||||
}
|
||||
|
||||
public static ResponseComponent.Parameters parameters(SwaggerPathOperation operation,
|
||||
public static ResponseComponent.Parameters parameters(PathOperation operation,
|
||||
int titleLevel,
|
||||
List<ObjectType> inlineDefinitions) {
|
||||
return new ResponseComponent.Parameters(operation, titleLevel, inlineDefinitions);
|
||||
@@ -69,7 +63,7 @@ public class ResponseComponent extends MarkupComponent<ResponseComponent.Paramet
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, Parameters params) {
|
||||
SwaggerPathOperation operation = params.operation;
|
||||
PathOperation operation = params.operation;
|
||||
Map<String, Response> responses = operation.getOperation().getResponses();
|
||||
|
||||
MarkupDocBuilder responsesBuilder = copyMarkupDocBuilder(markupDocBuilder);
|
||||
@@ -87,15 +81,9 @@ public class ResponseComponent extends MarkupComponent<ResponseComponent.Paramet
|
||||
Map<String, Response> sortedResponses = toSortedMap(responses, config.getResponseOrdering());
|
||||
sortedResponses.forEach((String responseName, Response response) -> {
|
||||
String schemaContent = labels.getLabel(NO_CONTENT);
|
||||
if (response.getResponseSchema() != null) {
|
||||
Model model = response.getResponseSchema();
|
||||
Type type = null;
|
||||
|
||||
if (model != null) {
|
||||
type = ModelUtils.getType(model, definitions, definitionDocumentResolver);
|
||||
} else {
|
||||
type = new BasicType("string", responseName);
|
||||
}
|
||||
if (response.getSchema() != null) {
|
||||
Property property = response.getSchema();
|
||||
Type type = new PropertyAdapter(property).getType(definitionDocumentResolver);
|
||||
|
||||
if (config.isInlineSchemaEnabled()) {
|
||||
type = createInlineType(type, labels.getLabel(RESPONSE) + " " + responseName, operation.getId() + " " + labels.getLabel(RESPONSE) + " " + responseName, params.inlineDefinitions);
|
||||
@@ -106,8 +94,7 @@ public class ResponseComponent extends MarkupComponent<ResponseComponent.Paramet
|
||||
|
||||
MarkupDocBuilder descriptionBuilder = copyMarkupDocBuilder(markupDocBuilder);
|
||||
|
||||
descriptionBuilder.text(markupDescription(MarkupLanguage.valueOf(config.getSchemaMarkupLanguage().name()),
|
||||
markupDocBuilder, response.getDescription()));
|
||||
descriptionBuilder.text(markupDescription(config.getSwaggerMarkupLanguage(), markupDocBuilder, response.getDescription()));
|
||||
|
||||
Map<String, Property> headers = response.getHeaders();
|
||||
if (MapUtils.isNotEmpty(headers)) {
|
||||
@@ -117,8 +104,7 @@ public class ResponseComponent extends MarkupComponent<ResponseComponent.Paramet
|
||||
Property headerProperty = header.getValue();
|
||||
PropertyAdapter headerPropertyAdapter = new PropertyAdapter(headerProperty);
|
||||
Type propertyType = headerPropertyAdapter.getType(definitionDocumentResolver);
|
||||
String headerDescription = markupDescription(MarkupLanguage.valueOf(config.getSchemaMarkupLanguage().name()),
|
||||
markupDocBuilder, headerProperty.getDescription());
|
||||
String headerDescription = markupDescription(config.getSwaggerMarkupLanguage(), markupDocBuilder, headerProperty.getDescription());
|
||||
Optional<Object> optionalDefaultValue = headerPropertyAdapter.getDefaultValue();
|
||||
|
||||
descriptionBuilder
|
||||
@@ -171,11 +157,11 @@ public class ResponseComponent extends MarkupComponent<ResponseComponent.Paramet
|
||||
}
|
||||
|
||||
public static class Parameters {
|
||||
private final SwaggerPathOperation operation;
|
||||
private final PathOperation operation;
|
||||
private final int titleLevel;
|
||||
private final List<ObjectType> inlineDefinitions;
|
||||
|
||||
public Parameters(SwaggerPathOperation operation,
|
||||
public Parameters(PathOperation operation,
|
||||
int titleLevel,
|
||||
List<ObjectType> inlineDefinitions) {
|
||||
|
||||
@@ -21,7 +21,7 @@ import com.google.common.base.Joiner;
|
||||
import io.github.swagger2markup.Swagger2MarkupConverter;
|
||||
import io.github.swagger2markup.internal.resolver.DocumentResolver;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import io.github.swagger2markup.model.SwaggerPathOperation;
|
||||
import io.github.swagger2markup.model.PathOperation;
|
||||
import io.github.swagger2markup.spi.MarkupComponent;
|
||||
import io.github.swagger2markup.spi.PathsDocumentExtension;
|
||||
import io.swagger.models.auth.SecuritySchemeDefinition;
|
||||
@@ -32,7 +32,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static ch.netzwerg.paleo.ColumnIds.StringColumnId;
|
||||
import static io.github.swagger2markup.SwaggerLabels.*;
|
||||
import static io.github.swagger2markup.Labels.*;
|
||||
import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.*;
|
||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
|
||||
@@ -42,22 +42,22 @@ public class SecuritySchemeComponent extends MarkupComponent<SecuritySchemeCompo
|
||||
private final DocumentResolver securityDocumentResolver;
|
||||
private final TableComponent tableComponent;
|
||||
|
||||
public SecuritySchemeComponent(Swagger2MarkupConverter.SwaggerContext context,
|
||||
public SecuritySchemeComponent(Swagger2MarkupConverter.Context context,
|
||||
DocumentResolver securityDocumentResolver) {
|
||||
super(context);
|
||||
this.securityDefinitions = context.getSchema().getSecurityDefinitions();
|
||||
this.securityDefinitions = context.getSwagger().getSecurityDefinitions();
|
||||
this.securityDocumentResolver = Validate.notNull(securityDocumentResolver, "SecurityDocumentResolver must not be null");
|
||||
this.tableComponent = new TableComponent(context);
|
||||
}
|
||||
|
||||
public static SecuritySchemeComponent.Parameters parameters(SwaggerPathOperation operation,
|
||||
public static SecuritySchemeComponent.Parameters parameters(PathOperation operation,
|
||||
int titleLevel) {
|
||||
return new SecuritySchemeComponent.Parameters(operation, titleLevel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, Parameters params) {
|
||||
SwaggerPathOperation operation = params.operation;
|
||||
PathOperation operation = params.operation;
|
||||
MarkupDocBuilder securityBuilder = copyMarkupDocBuilder(markupDocBuilder);
|
||||
List<Map<String, List<String>>> securitySchemes = operation.getOperation().getSecurity();
|
||||
applyPathsDocumentExtension(new PathsDocumentExtension.Context(PathsDocumentExtension.Position.OPERATION_SECURITY_BEGIN, securityBuilder, operation));
|
||||
@@ -111,10 +111,10 @@ public class SecuritySchemeComponent extends MarkupComponent<SecuritySchemeCompo
|
||||
}
|
||||
|
||||
public static class Parameters {
|
||||
private final SwaggerPathOperation operation;
|
||||
private final PathOperation operation;
|
||||
private final int titleLevel;
|
||||
|
||||
public Parameters(SwaggerPathOperation operation,
|
||||
public Parameters(PathOperation operation,
|
||||
int titleLevel) {
|
||||
this.operation = Validate.notNull(operation, "PathOperation must not be null");
|
||||
this.titleLevel = titleLevel;
|
||||
@@ -19,8 +19,8 @@ package io.github.swagger2markup.internal.component;
|
||||
import ch.netzwerg.paleo.StringColumn;
|
||||
import io.github.swagger2markup.Swagger2MarkupConverter;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import io.github.swagger2markup.markup.builder.MarkupLanguage;
|
||||
import io.github.swagger2markup.spi.MarkupComponent;
|
||||
import io.github.swagger2markup.spi.SecurityDocumentExtension;
|
||||
import io.swagger.models.auth.ApiKeyAuthDefinition;
|
||||
import io.swagger.models.auth.OAuth2Definition;
|
||||
import io.swagger.models.auth.SecuritySchemeDefinition;
|
||||
@@ -29,10 +29,9 @@ import org.apache.commons.lang3.Validate;
|
||||
import java.util.Map;
|
||||
|
||||
import static ch.netzwerg.paleo.ColumnIds.StringColumnId;
|
||||
import static io.github.swagger2markup.SwaggerLabels.*;
|
||||
import static io.github.swagger2markup.Labels.*;
|
||||
import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.copyMarkupDocBuilder;
|
||||
import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.markupDescription;
|
||||
import static io.github.swagger2markup.spi.SecurityDocumentExtension.Context;
|
||||
import static io.github.swagger2markup.spi.SecurityDocumentExtension.Position;
|
||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
|
||||
@@ -40,7 +39,7 @@ public class SecuritySchemeDefinitionComponent extends MarkupComponent<SecurityS
|
||||
|
||||
private final TableComponent tableComponent;
|
||||
|
||||
public SecuritySchemeDefinitionComponent(Swagger2MarkupConverter.SwaggerContext context) {
|
||||
public SecuritySchemeDefinitionComponent(Swagger2MarkupConverter.Context context) {
|
||||
super(context);
|
||||
this.tableComponent = new TableComponent(context);
|
||||
}
|
||||
@@ -55,17 +54,16 @@ public class SecuritySchemeDefinitionComponent extends MarkupComponent<SecurityS
|
||||
public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, Parameters params) {
|
||||
String securitySchemeDefinitionName = params.securitySchemeDefinitionName;
|
||||
SecuritySchemeDefinition securitySchemeDefinition = params.securitySchemeDefinition;
|
||||
applySecurityDocumentExtension(new Context(Position.SECURITY_SCHEME_BEFORE, markupDocBuilder, securitySchemeDefinitionName, securitySchemeDefinition));
|
||||
applySecurityDocumentExtension(new SecurityDocumentExtension.Context(Position.SECURITY_SCHEME_BEFORE, markupDocBuilder, securitySchemeDefinitionName, securitySchemeDefinition));
|
||||
markupDocBuilder.sectionTitleWithAnchorLevel(params.titleLevel, securitySchemeDefinitionName);
|
||||
applySecurityDocumentExtension(new Context(Position.SECURITY_SCHEME_BEGIN, markupDocBuilder, securitySchemeDefinitionName, securitySchemeDefinition));
|
||||
applySecurityDocumentExtension(new SecurityDocumentExtension.Context(Position.SECURITY_SCHEME_BEGIN, markupDocBuilder, securitySchemeDefinitionName, securitySchemeDefinition));
|
||||
String description = securitySchemeDefinition.getDescription();
|
||||
if (isNotBlank(description)) {
|
||||
markupDocBuilder.paragraph(markupDescription(MarkupLanguage.valueOf(config.getSchemaMarkupLanguage().name()),
|
||||
markupDocBuilder, description));
|
||||
markupDocBuilder.paragraph(markupDescription(config.getSwaggerMarkupLanguage(), markupDocBuilder, description));
|
||||
}
|
||||
buildSecurityScheme(markupDocBuilder, securitySchemeDefinition);
|
||||
applySecurityDocumentExtension(new Context(Position.SECURITY_SCHEME_END, markupDocBuilder, securitySchemeDefinitionName, securitySchemeDefinition));
|
||||
applySecurityDocumentExtension(new Context(Position.SECURITY_SCHEME_AFTER, markupDocBuilder, securitySchemeDefinitionName, securitySchemeDefinition));
|
||||
applySecurityDocumentExtension(new SecurityDocumentExtension.Context(Position.SECURITY_SCHEME_END, markupDocBuilder, securitySchemeDefinitionName, securitySchemeDefinition));
|
||||
applySecurityDocumentExtension(new SecurityDocumentExtension.Context(Position.SECURITY_SCHEME_AFTER, markupDocBuilder, securitySchemeDefinitionName, securitySchemeDefinition));
|
||||
return markupDocBuilder;
|
||||
}
|
||||
|
||||
@@ -90,29 +88,23 @@ public class SecuritySchemeDefinitionComponent extends MarkupComponent<SecurityS
|
||||
if (isNotBlank(oauth2Scheme.getTokenUrl())) {
|
||||
paragraphBuilder.italicText(labels.getLabel(TOKEN_URL)).textLine(COLON + oauth2Scheme.getTokenUrl());
|
||||
}
|
||||
StringColumn.Builder nameColumnBuilder = StringColumn.builder(StringColumnId.of(labels.getLabel(NAME_COLUMN)))
|
||||
.putMetaData(TableComponent.WIDTH_RATIO, "3")
|
||||
.putMetaData(TableComponent.HEADER_COLUMN, "true");
|
||||
StringColumn.Builder descriptionColumnBuilder = StringColumn.builder(StringColumnId.of(labels.getLabel(DESCRIPTION_COLUMN)))
|
||||
.putMetaData(TableComponent.WIDTH_RATIO, "17")
|
||||
.putMetaData(TableComponent.HEADER_COLUMN, "true");
|
||||
|
||||
markupDocBuilder.paragraph(paragraphBuilder.toString(), true);
|
||||
|
||||
if (oauth2Scheme.getScopes() != null && !oauth2Scheme.getScopes().isEmpty()) {
|
||||
StringColumn.Builder nameColumnBuilder = StringColumn.builder(StringColumnId.of(labels.getLabel(NAME_COLUMN)))
|
||||
.putMetaData(TableComponent.WIDTH_RATIO, "3")
|
||||
.putMetaData(TableComponent.HEADER_COLUMN, "true");
|
||||
StringColumn.Builder descriptionColumnBuilder = StringColumn.builder(StringColumnId.of(labels.getLabel(DESCRIPTION_COLUMN)))
|
||||
.putMetaData(TableComponent.WIDTH_RATIO, "17")
|
||||
.putMetaData(TableComponent.HEADER_COLUMN, "true");
|
||||
|
||||
if (oauth2Scheme.getScopes() != null) {
|
||||
for (Map.Entry<String, String> scope : oauth2Scheme.getScopes().entrySet()) {
|
||||
nameColumnBuilder.add(scope.getKey());
|
||||
descriptionColumnBuilder.add(scope.getValue());
|
||||
}
|
||||
|
||||
return tableComponent.apply(markupDocBuilder, TableComponent.parameters(nameColumnBuilder.build(),
|
||||
descriptionColumnBuilder.build()));
|
||||
} else {
|
||||
|
||||
return markupDocBuilder;
|
||||
}
|
||||
|
||||
markupDocBuilder.paragraph(paragraphBuilder.toString(), true);
|
||||
return tableComponent.apply(markupDocBuilder, TableComponent.parameters(nameColumnBuilder.build(),
|
||||
descriptionColumnBuilder.build()));
|
||||
} else {
|
||||
return markupDocBuilder.paragraph(paragraphBuilder.toString(), true);
|
||||
}
|
||||
@@ -123,7 +115,7 @@ public class SecuritySchemeDefinitionComponent extends MarkupComponent<SecurityS
|
||||
*
|
||||
* @param context context
|
||||
*/
|
||||
private void applySecurityDocumentExtension(Context context) {
|
||||
private void applySecurityDocumentExtension(SecurityDocumentExtension.Context context) {
|
||||
extensionRegistry.getSecurityDocumentExtensions().forEach(extension -> extension.apply(context));
|
||||
}
|
||||
|
||||
@@ -22,9 +22,9 @@ 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.MarkupComponent;
|
||||
import io.vavr.collection.Array;
|
||||
import io.vavr.collection.IndexedSeq;
|
||||
import io.vavr.collection.List;
|
||||
import javaslang.collection.Array;
|
||||
import javaslang.collection.IndexedSeq;
|
||||
import javaslang.collection.List;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ public class TableComponent extends MarkupComponent<TableComponent.Parameters> {
|
||||
public static final String WIDTH_RATIO = "widthRatio";
|
||||
public static final String HEADER_COLUMN = "headerColumn";
|
||||
|
||||
public TableComponent(Swagger2MarkupConverter.SwaggerContext context) {
|
||||
public TableComponent(Swagger2MarkupConverter.Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ public class TableComponent extends MarkupComponent<TableComponent.Parameters> {
|
||||
return new MarkupTableColumn(column.getId().getName())
|
||||
.withWidthRatio(widthRatio)
|
||||
.withHeaderColumn(Boolean.parseBoolean(column.getMetaData().get(HEADER_COLUMN).getOrElse("false")))
|
||||
.withMarkupSpecifiers(MarkupLanguage.ASCIIDOC, ".^" + widthRatio + "a");
|
||||
.withMarkupSpecifiers(MarkupLanguage.ASCIIDOC, ".^" + widthRatio);
|
||||
}
|
||||
).toJavaList();
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
package io.github.swagger2markup.internal.component;
|
||||
|
||||
|
||||
import io.github.swagger2markup.Labels;
|
||||
import io.github.swagger2markup.Swagger2MarkupConverter;
|
||||
import io.github.swagger2markup.SwaggerLabels;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import io.github.swagger2markup.spi.MarkupComponent;
|
||||
import io.swagger.models.Tag;
|
||||
@@ -31,7 +31,7 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
|
||||
public class TagsComponent extends MarkupComponent<TagsComponent.Parameters> {
|
||||
|
||||
public TagsComponent(Swagger2MarkupConverter.SwaggerContext context) {
|
||||
public TagsComponent(Swagger2MarkupConverter.Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ public class TagsComponent extends MarkupComponent<TagsComponent.Parameters> {
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, Parameters params) {
|
||||
markupDocBuilder.sectionTitleLevel(params.titleLevel, labels.getLabel(SwaggerLabels.TAGS));
|
||||
markupDocBuilder.sectionTitleLevel(params.titleLevel, labels.getLabel(Labels.TAGS));
|
||||
|
||||
List<String> tagsList = params.tags.stream()
|
||||
.map(this::mapToString).collect(Collectors.toList());
|
||||
@@ -15,8 +15,8 @@
|
||||
*/
|
||||
package io.github.swagger2markup.internal.component;
|
||||
|
||||
import io.github.swagger2markup.Labels;
|
||||
import io.github.swagger2markup.Swagger2MarkupConverter;
|
||||
import io.github.swagger2markup.SwaggerLabels;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import io.github.swagger2markup.spi.MarkupComponent;
|
||||
import io.swagger.models.Swagger;
|
||||
@@ -33,7 +33,7 @@ import static org.apache.commons.lang3.StringUtils.join;
|
||||
public class UriSchemeComponent extends MarkupComponent<UriSchemeComponent.Parameters> {
|
||||
|
||||
|
||||
public UriSchemeComponent(Swagger2MarkupConverter.SwaggerContext context) {
|
||||
public UriSchemeComponent(Swagger2MarkupConverter.Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@@ -45,21 +45,21 @@ public class UriSchemeComponent extends MarkupComponent<UriSchemeComponent.Param
|
||||
public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, Parameters params) {
|
||||
Swagger swagger = params.swagger;
|
||||
if (isNotBlank(swagger.getHost()) || isNotBlank(swagger.getBasePath()) || isNotEmpty(swagger.getSchemes())) {
|
||||
markupDocBuilder.sectionTitleLevel(params.titleLevel, labels.getLabel(SwaggerLabels.URI_SCHEME));
|
||||
markupDocBuilder.sectionTitleLevel(params.titleLevel, labels.getLabel(Labels.URI_SCHEME));
|
||||
MarkupDocBuilder paragraphBuilder = copyMarkupDocBuilder(markupDocBuilder);
|
||||
if (isNotBlank(swagger.getHost())) {
|
||||
paragraphBuilder.italicText(labels.getLabel(SwaggerLabels.HOST))
|
||||
paragraphBuilder.italicText(labels.getLabel(Labels.HOST))
|
||||
.textLine(COLON + swagger.getHost());
|
||||
}
|
||||
if (isNotBlank(swagger.getBasePath())) {
|
||||
paragraphBuilder.italicText(labels.getLabel(SwaggerLabels.BASE_PATH))
|
||||
paragraphBuilder.italicText(labels.getLabel(Labels.BASE_PATH))
|
||||
.textLine(COLON + swagger.getBasePath());
|
||||
}
|
||||
if (isNotEmpty(swagger.getSchemes())) {
|
||||
List<String> schemes = swagger.getSchemes().stream()
|
||||
.map(Enum::toString)
|
||||
.collect(Collectors.toList());
|
||||
paragraphBuilder.italicText(labels.getLabel(SwaggerLabels.SCHEMES))
|
||||
paragraphBuilder.italicText(labels.getLabel(Labels.SCHEMES))
|
||||
.textLine(COLON + join(schemes, ", "));
|
||||
}
|
||||
markupDocBuilder.paragraph(paragraphBuilder.toString(), true);
|
||||
@@ -15,8 +15,8 @@
|
||||
*/
|
||||
package io.github.swagger2markup.internal.component;
|
||||
|
||||
import io.github.swagger2markup.Labels;
|
||||
import io.github.swagger2markup.Swagger2MarkupConverter;
|
||||
import io.github.swagger2markup.SwaggerLabels;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import io.github.swagger2markup.spi.MarkupComponent;
|
||||
import io.swagger.models.Info;
|
||||
@@ -28,7 +28,7 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
public class VersionInfoComponent extends MarkupComponent<VersionInfoComponent.Parameters> {
|
||||
|
||||
|
||||
public VersionInfoComponent(Swagger2MarkupConverter.SwaggerContext context) {
|
||||
public VersionInfoComponent(Swagger2MarkupConverter.Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@@ -41,9 +41,9 @@ public class VersionInfoComponent extends MarkupComponent<VersionInfoComponent.P
|
||||
public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, Parameters params) {
|
||||
String version = params.info.getVersion();
|
||||
if (isNotBlank(version)) {
|
||||
markupDocBuilder.sectionTitleLevel(params.titleLevel, labels.getLabel(SwaggerLabels.CURRENT_VERSION));
|
||||
markupDocBuilder.sectionTitleLevel(params.titleLevel, labels.getLabel(Labels.CURRENT_VERSION));
|
||||
MarkupDocBuilder paragraphBuilder = copyMarkupDocBuilder(markupDocBuilder);
|
||||
paragraphBuilder.italicText(labels.getLabel(SwaggerLabels.VERSION)).textLine(COLON + version);
|
||||
paragraphBuilder.italicText(labels.getLabel(Labels.VERSION)).textLine(COLON + version);
|
||||
markupDocBuilder.paragraph(paragraphBuilder.toString(), true);
|
||||
}
|
||||
return markupDocBuilder;
|
||||
@@ -15,14 +15,13 @@
|
||||
*/
|
||||
package io.github.swagger2markup.internal.document;
|
||||
|
||||
import io.github.swagger2markup.Labels;
|
||||
import io.github.swagger2markup.Swagger2MarkupConverter;
|
||||
import io.github.swagger2markup.SwaggerLabels;
|
||||
import io.github.swagger2markup.internal.component.DefinitionComponent;
|
||||
import io.github.swagger2markup.internal.resolver.DefinitionDocumentNameResolver;
|
||||
import io.github.swagger2markup.internal.resolver.DefinitionDocumentResolverDefault;
|
||||
import io.github.swagger2markup.internal.resolver.DefinitionDocumentResolverFromDefinition;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import io.github.swagger2markup.spi.DefinitionsDocumentExtension.Context;
|
||||
import io.github.swagger2markup.spi.MarkupComponent;
|
||||
import io.swagger.models.Model;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
@@ -36,6 +35,7 @@ import java.util.Map;
|
||||
import static io.github.swagger2markup.internal.utils.MapUtils.toSortedMap;
|
||||
import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.copyMarkupDocBuilder;
|
||||
import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.crossReference;
|
||||
import static io.github.swagger2markup.spi.DefinitionsDocumentExtension.Context;
|
||||
import static io.github.swagger2markup.spi.DefinitionsDocumentExtension.Position;
|
||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
|
||||
@@ -51,7 +51,7 @@ public class DefinitionsDocument extends MarkupComponent<DefinitionsDocument.Par
|
||||
private final DefinitionDocumentResolverDefault definitionDocumentResolverDefault;
|
||||
private final DefinitionDocumentNameResolver definitionDocumentNameResolver;
|
||||
|
||||
public DefinitionsDocument(Swagger2MarkupConverter.SwaggerContext context) {
|
||||
public DefinitionsDocument(Swagger2MarkupConverter.Context context) {
|
||||
super(context);
|
||||
if (config.isSeparatedDefinitionsEnabled()) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
@@ -81,7 +81,7 @@ public class DefinitionsDocument extends MarkupComponent<DefinitionsDocument.Par
|
||||
Map<String, Model> definitions = params.definitions;
|
||||
if (MapUtils.isNotEmpty(definitions)) {
|
||||
applyDefinitionsDocumentExtension(new Context(Position.DOCUMENT_BEFORE, markupDocBuilder));
|
||||
buildDefinitionsTitle(markupDocBuilder, labels.getLabel(SwaggerLabels.DEFINITIONS));
|
||||
buildDefinitionsTitle(markupDocBuilder, labels.getLabel(Labels.DEFINITIONS));
|
||||
applyDefinitionsDocumentExtension(new Context(Position.DOCUMENT_BEGIN, markupDocBuilder));
|
||||
buildDefinitionsSection(markupDocBuilder, definitions);
|
||||
applyDefinitionsDocumentExtension(new Context(Position.DOCUMENT_END, markupDocBuilder));
|
||||
@@ -15,19 +15,18 @@
|
||||
*/
|
||||
package io.github.swagger2markup.internal.document;
|
||||
|
||||
import io.github.swagger2markup.Labels;
|
||||
import io.github.swagger2markup.Swagger2MarkupConverter;
|
||||
import io.github.swagger2markup.SwaggerLabels;
|
||||
import io.github.swagger2markup.internal.component.*;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import io.github.swagger2markup.markup.builder.MarkupLanguage;
|
||||
import io.github.swagger2markup.spi.MarkupComponent;
|
||||
import io.github.swagger2markup.spi.OverviewDocumentExtension.Context;
|
||||
import io.swagger.models.*;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.markupDescription;
|
||||
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.isNotBlank;
|
||||
@@ -45,7 +44,7 @@ public class OverviewDocument extends MarkupComponent<OverviewDocument.Parameter
|
||||
private final ConsumesComponent consumesComponent;
|
||||
private final ExternalDocsComponent externalDocsComponent;
|
||||
|
||||
public OverviewDocument(Swagger2MarkupConverter.SwaggerContext context) {
|
||||
public OverviewDocument(Swagger2MarkupConverter.Context context) {
|
||||
super(context);
|
||||
versionInfoComponent = new VersionInfoComponent(context);
|
||||
contactInfoComponent = new ContactInfoComponent(context);
|
||||
@@ -72,7 +71,7 @@ public class OverviewDocument extends MarkupComponent<OverviewDocument.Parameter
|
||||
Info info = swagger.getInfo();
|
||||
buildDocumentTitle(markupDocBuilder, info.getTitle());
|
||||
applyOverviewDocumentExtension(new Context(Position.DOCUMENT_BEFORE, markupDocBuilder));
|
||||
buildOverviewTitle(markupDocBuilder, labels.getLabel(SwaggerLabels.OVERVIEW));
|
||||
buildOverviewTitle(markupDocBuilder, labels.getLabel(Labels.OVERVIEW));
|
||||
applyOverviewDocumentExtension(new Context(Position.DOCUMENT_BEGIN, markupDocBuilder));
|
||||
buildDescriptionParagraph(markupDocBuilder, info.getDescription());
|
||||
buildVersionInfoSection(markupDocBuilder, info);
|
||||
@@ -98,8 +97,7 @@ public class OverviewDocument extends MarkupComponent<OverviewDocument.Parameter
|
||||
|
||||
void buildDescriptionParagraph(MarkupDocBuilder markupDocBuilder, String description) {
|
||||
if (isNotBlank(description)) {
|
||||
markupDocBuilder.paragraph(markupDescription(MarkupLanguage.valueOf(config.getSchemaMarkupLanguage().name()),
|
||||
markupDocBuilder, description));
|
||||
markupDocBuilder.paragraph(markupDescription(config.getSwaggerMarkupLanguage(), markupDocBuilder, description));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,10 +16,10 @@
|
||||
package io.github.swagger2markup.internal.document;
|
||||
|
||||
import com.google.common.collect.Multimap;
|
||||
import io.github.swagger2markup.Swagger2MarkupConfig;
|
||||
import io.github.swagger2markup.Swagger2MarkupConverter.SwaggerContext;
|
||||
import io.github.swagger2markup.SwaggerLabels;
|
||||
import io.github.swagger2markup.GroupBy;
|
||||
import io.github.swagger2markup.Labels;
|
||||
import io.github.swagger2markup.Swagger2MarkupConfig;
|
||||
import io.github.swagger2markup.Swagger2MarkupConverter;
|
||||
import io.github.swagger2markup.internal.component.PathOperationComponent;
|
||||
import io.github.swagger2markup.internal.resolver.DefinitionDocumentResolverFromOperation;
|
||||
import io.github.swagger2markup.internal.resolver.OperationDocumentNameResolver;
|
||||
@@ -30,17 +30,14 @@ import io.github.swagger2markup.internal.utils.RegexUtils;
|
||||
import io.github.swagger2markup.internal.utils.TagUtils;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import io.github.swagger2markup.model.PathOperation;
|
||||
import io.github.swagger2markup.model.SwaggerPathOperation;
|
||||
import io.github.swagger2markup.spi.MarkupComponent;
|
||||
import io.github.swagger2markup.spi.PathsDocumentExtension.Context;
|
||||
import io.github.swagger2markup.spi.PathsDocumentExtension.Position;
|
||||
import io.swagger.models.Path;
|
||||
import io.swagger.models.Tag;
|
||||
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 org.apache.commons.text.WordUtils;
|
||||
import org.apache.commons.lang3.text.WordUtils;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
@@ -50,6 +47,8 @@ import java.util.regex.Pattern;
|
||||
|
||||
import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.copyMarkupDocBuilder;
|
||||
import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.crossReference;
|
||||
import static io.github.swagger2markup.spi.PathsDocumentExtension.Context;
|
||||
import static io.github.swagger2markup.spi.PathsDocumentExtension.Position;
|
||||
import static io.github.swagger2markup.utils.IOUtils.normalizeName;
|
||||
|
||||
/**
|
||||
@@ -62,7 +61,7 @@ public class PathsDocument extends MarkupComponent<PathsDocument.Parameters> {
|
||||
private final OperationDocumentNameResolver operationDocumentNameResolver;
|
||||
private final OperationDocumentResolverDefault operationDocumentResolverDefault;
|
||||
|
||||
public PathsDocument(SwaggerContext context) {
|
||||
public PathsDocument(Swagger2MarkupConverter.Context context) {
|
||||
super(context);
|
||||
this.pathOperationComponent = new PathOperationComponent(context,
|
||||
new DefinitionDocumentResolverFromOperation(context),
|
||||
@@ -114,16 +113,16 @@ public class PathsDocument extends MarkupComponent<PathsDocument.Parameters> {
|
||||
* @param paths the Swagger paths
|
||||
*/
|
||||
private void buildsPathsSection(MarkupDocBuilder markupDocBuilder, Map<String, Path> paths) {
|
||||
List<SwaggerPathOperation> pathOperations = PathUtils.toPathOperationsList(paths, getHostname(), getBasePath(), config.getOperationOrdering());
|
||||
List<PathOperation> pathOperations = PathUtils.toPathOperationsList(paths, getBasePath(), config.getOperationOrdering());
|
||||
if (CollectionUtils.isNotEmpty(pathOperations)) {
|
||||
if (config.getPathsGroupedBy() == GroupBy.AS_IS) {
|
||||
pathOperations.forEach(operation -> buildOperation(markupDocBuilder, operation, config));
|
||||
} else if (config.getPathsGroupedBy() == GroupBy.TAGS) {
|
||||
Validate.notEmpty(context.getSchema().getTags(), "Tags must not be empty, when operations are grouped by tags");
|
||||
Validate.notEmpty(context.getSwagger().getTags(), "Tags must not be empty, when operations are grouped by tags");
|
||||
// Group operations by tag
|
||||
Multimap<String, SwaggerPathOperation> operationsGroupedByTag = TagUtils.groupOperationsByTag(pathOperations, config.getOperationOrdering());
|
||||
Multimap<String, PathOperation> operationsGroupedByTag = TagUtils.groupOperationsByTag(pathOperations, config.getOperationOrdering());
|
||||
|
||||
Map<String, Tag> tagsMap = TagUtils.toSortedMap(context.getSchema().getTags(), config.getTagOrdering());
|
||||
Map<String, Tag> tagsMap = TagUtils.toSortedMap(context.getSwagger().getTags(), config.getTagOrdering());
|
||||
|
||||
tagsMap.forEach((String tagName, Tag tag) -> {
|
||||
markupDocBuilder.sectionTitleWithAnchorLevel2(WordUtils.capitalize(tagName), tagName + "_resource");
|
||||
@@ -138,7 +137,7 @@ public class PathsDocument extends MarkupComponent<PathsDocument.Parameters> {
|
||||
Validate.notNull(config.getHeaderPattern(), "Header regex pattern must not be empty when operations are grouped using regex");
|
||||
|
||||
Pattern headerPattern = config.getHeaderPattern();
|
||||
Multimap<String, SwaggerPathOperation> operationsGroupedByRegex = RegexUtils.groupOperationsByRegex(pathOperations, headerPattern);
|
||||
Multimap<String, PathOperation> operationsGroupedByRegex = RegexUtils.groupOperationsByRegex(pathOperations, headerPattern);
|
||||
Set<String> keys = operationsGroupedByRegex.keySet();
|
||||
String[] sortedHeaders = RegexUtils.toSortedArray(keys);
|
||||
|
||||
@@ -155,26 +154,14 @@ public class PathsDocument extends MarkupComponent<PathsDocument.Parameters> {
|
||||
*/
|
||||
private void buildPathsTitle(MarkupDocBuilder markupDocBuilder) {
|
||||
if (config.getPathsGroupedBy() == GroupBy.AS_IS) {
|
||||
buildPathsTitle(markupDocBuilder, labels.getLabel(SwaggerLabels.PATHS));
|
||||
buildPathsTitle(markupDocBuilder, labels.getLabel(Labels.PATHS));
|
||||
} else if (config.getPathsGroupedBy() == GroupBy.REGEX) {
|
||||
buildPathsTitle(markupDocBuilder, labels.getLabel(SwaggerLabels.OPERATIONS));
|
||||
buildPathsTitle(markupDocBuilder, labels.getLabel(Labels.OPERATIONS));
|
||||
} else {
|
||||
buildPathsTitle(markupDocBuilder, labels.getLabel(SwaggerLabels.RESOURCES));
|
||||
buildPathsTitle(markupDocBuilder, labels.getLabel(Labels.RESOURCES));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the hostname which should be prepended to the relative path
|
||||
*
|
||||
* @return either the relative or the full path
|
||||
*/
|
||||
private String getHostname() {
|
||||
if (config.isHostnameEnabled()) {
|
||||
return StringUtils.defaultString(context.getSchema().getHost());
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the basePath which should be prepended to the relative path
|
||||
*
|
||||
@@ -182,7 +169,7 @@ public class PathsDocument extends MarkupComponent<PathsDocument.Parameters> {
|
||||
*/
|
||||
private String getBasePath() {
|
||||
if (config.isBasePathPrefixEnabled()) {
|
||||
return StringUtils.defaultString(context.getSchema().getBasePath());
|
||||
return StringUtils.defaultString(context.getSwagger().getBasePath());
|
||||
}
|
||||
return "";
|
||||
}
|
||||
@@ -205,7 +192,7 @@ public class PathsDocument extends MarkupComponent<PathsDocument.Parameters> {
|
||||
*
|
||||
* @param operation operation
|
||||
*/
|
||||
private void buildOperation(MarkupDocBuilder markupDocBuilder, SwaggerPathOperation operation, Swagger2MarkupConfig config) {
|
||||
private void buildOperation(MarkupDocBuilder markupDocBuilder, PathOperation operation, Swagger2MarkupConfig config) {
|
||||
if (config.isSeparatedOperationsEnabled()) {
|
||||
MarkupDocBuilder pathDocBuilder = copyMarkupDocBuilder(markupDocBuilder);
|
||||
applyPathOperationComponent(pathDocBuilder, operation);
|
||||
@@ -231,7 +218,7 @@ public class PathsDocument extends MarkupComponent<PathsDocument.Parameters> {
|
||||
* @param markupDocBuilder the docbuilder do use for output
|
||||
* @param operation the Swagger Operation
|
||||
*/
|
||||
private void applyPathOperationComponent(MarkupDocBuilder markupDocBuilder, SwaggerPathOperation operation) {
|
||||
private void applyPathOperationComponent(MarkupDocBuilder markupDocBuilder, PathOperation operation) {
|
||||
if (operation != null) {
|
||||
pathOperationComponent.apply(markupDocBuilder, PathOperationComponent.parameters(operation));
|
||||
}
|
||||
@@ -244,8 +231,7 @@ public class PathsDocument extends MarkupComponent<PathsDocument.Parameters> {
|
||||
* @param operation the Swagger Operation
|
||||
*/
|
||||
private void buildOperationRef(MarkupDocBuilder markupDocBuilder, PathOperation operation) {
|
||||
buildOperationTitle(markupDocBuilder, crossReference(markupDocBuilder, operationDocumentResolverDefault.apply(operation),
|
||||
operation.getId(), operation.getTitle()), "ref-" + operation.getId());
|
||||
buildOperationTitle(markupDocBuilder, crossReference(markupDocBuilder, operationDocumentResolverDefault.apply(operation), operation.getId(), operation.getTitle()), "ref-" + operation.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -19,14 +19,14 @@ import io.github.swagger2markup.Swagger2MarkupConverter;
|
||||
import io.github.swagger2markup.internal.component.SecuritySchemeDefinitionComponent;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import io.github.swagger2markup.spi.MarkupComponent;
|
||||
import io.github.swagger2markup.spi.SecurityDocumentExtension.Context;
|
||||
import io.swagger.models.auth.SecuritySchemeDefinition;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static io.github.swagger2markup.SwaggerLabels.SECURITY;
|
||||
import static io.github.swagger2markup.Labels.SECURITY;
|
||||
import static io.github.swagger2markup.internal.utils.MapUtils.toSortedMap;
|
||||
import static io.github.swagger2markup.spi.SecurityDocumentExtension.Context;
|
||||
import static io.github.swagger2markup.spi.SecurityDocumentExtension.Position;
|
||||
|
||||
/**
|
||||
@@ -37,7 +37,7 @@ public class SecurityDocument extends MarkupComponent<SecurityDocument.Parameter
|
||||
private static final String SECURITY_ANCHOR = "securityScheme";
|
||||
private final SecuritySchemeDefinitionComponent securitySchemeDefinitionComponent;
|
||||
|
||||
public SecurityDocument(Swagger2MarkupConverter.SwaggerContext context) {
|
||||
public SecurityDocument(Swagger2MarkupConverter.Context context) {
|
||||
super(context);
|
||||
this.securitySchemeDefinitionComponent = new SecuritySchemeDefinitionComponent(context);
|
||||
}
|
||||
@@ -24,7 +24,7 @@ import static io.github.swagger2markup.utils.IOUtils.normalizeName;
|
||||
|
||||
public class DefinitionDocumentNameResolver extends DocumentResolver {
|
||||
|
||||
public DefinitionDocumentNameResolver(Swagger2MarkupConverter.SwaggerContext context) {
|
||||
public DefinitionDocumentNameResolver(Swagger2MarkupConverter.Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ public class DefinitionDocumentResolverDefault extends DocumentResolver {
|
||||
|
||||
private final DefinitionDocumentNameResolver definitionDocumentNameResolver;
|
||||
|
||||
public DefinitionDocumentResolverDefault(Swagger2MarkupConverter.SwaggerContext context) {
|
||||
public DefinitionDocumentResolverDefault(Swagger2MarkupConverter.Context context) {
|
||||
super(context);
|
||||
this.definitionDocumentNameResolver = new DefinitionDocumentNameResolver(context);
|
||||
}
|
||||
@@ -27,7 +27,7 @@ import static org.apache.commons.lang3.StringUtils.defaultString;
|
||||
*/
|
||||
public class DefinitionDocumentResolverFromDefinition extends DefinitionDocumentResolverDefault {
|
||||
|
||||
public DefinitionDocumentResolverFromDefinition(Swagger2MarkupConverter.SwaggerContext context) {
|
||||
public DefinitionDocumentResolverFromDefinition(Swagger2MarkupConverter.Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import static org.apache.commons.lang3.StringUtils.defaultString;
|
||||
*/
|
||||
public class DefinitionDocumentResolverFromOperation extends DefinitionDocumentResolverDefault {
|
||||
|
||||
public DefinitionDocumentResolverFromOperation(Swagger2MarkupConverter.SwaggerContext context) {
|
||||
public DefinitionDocumentResolverFromOperation(Swagger2MarkupConverter.Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ package io.github.swagger2markup.internal.resolver;
|
||||
import io.github.swagger2markup.Swagger2MarkupConfig;
|
||||
import io.github.swagger2markup.Swagger2MarkupConverter;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import io.vavr.Function1;
|
||||
import javaslang.Function1;
|
||||
|
||||
/**
|
||||
* A functor to return the document part of an inter-document cross-references, depending on the context.
|
||||
@@ -30,7 +30,7 @@ public abstract class DocumentResolver implements Function1<String, String> {
|
||||
MarkupDocBuilder markupDocBuilder;
|
||||
Swagger2MarkupConfig config;
|
||||
|
||||
public DocumentResolver(Swagger2MarkupConverter.SwaggerContext context) {
|
||||
public DocumentResolver(Swagger2MarkupConverter.Context context) {
|
||||
this.context = context;
|
||||
this.markupDocBuilder = context.createMarkupDocBuilder();
|
||||
this.config = context.getConfig();
|
||||
@@ -25,7 +25,7 @@ import static io.github.swagger2markup.utils.IOUtils.normalizeName;
|
||||
|
||||
public class OperationDocumentNameResolver extends OperationDocumentResolver {
|
||||
|
||||
public OperationDocumentNameResolver(Swagger2MarkupConverter.SwaggerContext context) {
|
||||
public OperationDocumentNameResolver(Swagger2MarkupConverter.Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import io.github.swagger2markup.Swagger2MarkupConfig;
|
||||
import io.github.swagger2markup.Swagger2MarkupConverter;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import io.github.swagger2markup.model.PathOperation;
|
||||
import io.vavr.Function1;
|
||||
import javaslang.Function1;
|
||||
|
||||
/**
|
||||
* A functor to return the document part of an inter-document cross-references, depending on the context.
|
||||
@@ -31,7 +31,7 @@ public abstract class OperationDocumentResolver implements Function1<PathOperati
|
||||
MarkupDocBuilder markupDocBuilder;
|
||||
Swagger2MarkupConfig config;
|
||||
|
||||
public OperationDocumentResolver(Swagger2MarkupConverter.SwaggerContext context) {
|
||||
public OperationDocumentResolver(Swagger2MarkupConverter.Context context) {
|
||||
this.context = context;
|
||||
this.markupDocBuilder = context.createMarkupDocBuilder();
|
||||
this.config = context.getConfig();
|
||||
@@ -27,7 +27,7 @@ public class OperationDocumentResolverDefault extends OperationDocumentResolver
|
||||
|
||||
private final OperationDocumentNameResolver operationDocumentNameResolver;
|
||||
|
||||
public OperationDocumentResolverDefault(Swagger2MarkupConverter.SwaggerContext context) {
|
||||
public OperationDocumentResolverDefault(Swagger2MarkupConverter.Context context) {
|
||||
super(context);
|
||||
this.operationDocumentNameResolver = new OperationDocumentNameResolver(context);
|
||||
}
|
||||
@@ -21,7 +21,7 @@ import static org.apache.commons.lang3.StringUtils.defaultString;
|
||||
|
||||
public class SecurityDocumentResolver extends DocumentResolver {
|
||||
|
||||
public SecurityDocumentResolver(Swagger2MarkupConverter.SwaggerContext context) {
|
||||
public SecurityDocumentResolver(Swagger2MarkupConverter.Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
@@ -0,0 +1,25 @@
|
||||
package io.github.swagger2markup.internal.utils;
|
||||
|
||||
import io.github.swagger2markup.ExampleType;
|
||||
|
||||
/**
|
||||
* swagger2markup (c) Duco Hosting
|
||||
* Created by cas on 02-Oct-17.
|
||||
*/
|
||||
public class Example {
|
||||
private ExampleType type;
|
||||
private Object example;
|
||||
|
||||
public Example(ExampleType type, Object example) {
|
||||
this.type = type;
|
||||
this.example = example;
|
||||
}
|
||||
|
||||
public ExampleType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public Object getExample() {
|
||||
return example;
|
||||
}
|
||||
}
|
||||
@@ -20,17 +20,15 @@ import io.github.swagger2markup.internal.adapter.ParameterAdapter;
|
||||
import io.github.swagger2markup.internal.adapter.PropertyAdapter;
|
||||
import io.github.swagger2markup.internal.resolver.DocumentResolver;
|
||||
import io.github.swagger2markup.internal.type.ObjectType;
|
||||
import io.github.swagger2markup.internal.utils.pathexamples.BasicPathExample;
|
||||
import io.github.swagger2markup.internal.utils.pathexamples.PathExample;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import io.github.swagger2markup.model.SwaggerPathOperation;
|
||||
import io.github.swagger2markup.model.PathOperation;
|
||||
import io.swagger.models.*;
|
||||
import io.swagger.models.parameters.*;
|
||||
import io.swagger.models.properties.*;
|
||||
import io.swagger.models.utils.PropertyModelConverter;
|
||||
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 java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
@@ -43,14 +41,13 @@ public class ExamplesUtil {
|
||||
/**
|
||||
* Generates a Map of response examples
|
||||
*
|
||||
* @param definitionDocumentResolver DocumentResolver
|
||||
* @param generateMissingExamples specifies the missing examples should be generated
|
||||
* @param operation the Swagger Operation
|
||||
* @param definitions the map of definitions
|
||||
* @param markupDocBuilder the markup builder
|
||||
* @param generateMissingExamples specifies the missing examples should be generated
|
||||
* @param operation the Swagger Operation
|
||||
* @param definitions the map of definitions
|
||||
* @param markupDocBuilder the markup builder
|
||||
* @return map containing response examples.
|
||||
*/
|
||||
public static Map<String, Object> generateResponseExampleMap(boolean generateMissingExamples, SwaggerPathOperation operation, Map<String, Model> definitions, DocumentResolver definitionDocumentResolver, MarkupDocBuilder markupDocBuilder) {
|
||||
public static Map<String, Object> generateResponseExampleMap(boolean generateMissingExamples, PathOperation operation, Map<String, Model> definitions, DocumentResolver definitionDocumentResolver, MarkupDocBuilder markupDocBuilder) {
|
||||
Map<String, Object> examples = new LinkedHashMap<>();
|
||||
Map<String, Response> responses = operation.getOperation().getResponses();
|
||||
if (responses != null)
|
||||
@@ -58,25 +55,19 @@ public class ExamplesUtil {
|
||||
Response response = responseEntry.getValue();
|
||||
Object example = response.getExamples();
|
||||
if (example == null) {
|
||||
Model model = response.getResponseSchema();
|
||||
if (model != null) {
|
||||
Property schema = new PropertyModelConverter().modelToProperty(model);
|
||||
if (schema != null) {
|
||||
example = schema.getExample();
|
||||
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, definitionDocumentResolver, markupDocBuilder, new HashMap<>());
|
||||
}
|
||||
if (example == null && schema instanceof ArrayProperty && generateMissingExamples) {
|
||||
example = generateExampleForArrayProperty((ArrayProperty) schema, definitions, definitionDocumentResolver, markupDocBuilder, new HashMap<>());
|
||||
}
|
||||
if (example == null && schema instanceof ObjectProperty && generateMissingExamples) {
|
||||
example = exampleMapForProperties(((ObjectProperty) schema).getProperties(), definitions, definitionDocumentResolver, markupDocBuilder, new HashMap<>());
|
||||
}
|
||||
if (example == null && generateMissingExamples) {
|
||||
example = PropertyAdapter.generateExample(schema, markupDocBuilder);
|
||||
}
|
||||
if (example == null && schema instanceof RefProperty) {
|
||||
String simpleRef = ((RefProperty) schema).getSimpleRef();
|
||||
example = generateExampleForRefModel(generateMissingExamples, simpleRef, definitions, definitionDocumentResolver, markupDocBuilder, new HashMap<>());
|
||||
}
|
||||
if (example == null && schema instanceof ArrayProperty && generateMissingExamples) {
|
||||
example = generateExampleForArrayProperty((ArrayProperty) schema, definitions, definitionDocumentResolver, markupDocBuilder, new HashMap<>());
|
||||
}
|
||||
if (example == null && generateMissingExamples) {
|
||||
example = PropertyAdapter.generateExample(schema, markupDocBuilder);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -92,93 +83,27 @@ public class ExamplesUtil {
|
||||
/**
|
||||
* Generates examples for request
|
||||
*
|
||||
* @param requestPathGenerator contains context, definitionDocumentResolver, operation and generates path
|
||||
* for example request
|
||||
* @param definitions the map of definitions
|
||||
* @param markupDocBuilder the markup builder
|
||||
* @param generateMissingExamples specifies the missing examples should be generated
|
||||
* @param pathOperation the Swagger Operation
|
||||
* @param definitions the map of definitions
|
||||
* @param markupDocBuilder the markup builder
|
||||
* @return an Optional with the example content
|
||||
*/
|
||||
public static Map<String, Object> generateRequestExampleMap(
|
||||
PathExample requestPathGenerator,
|
||||
Map<String, Model> definitions,
|
||||
MarkupDocBuilder markupDocBuilder) {
|
||||
boolean generateMissingExamples = requestPathGenerator.getContext().getConfig().isGeneratedExamplesEnabled();
|
||||
DocumentResolver definitionDocumentResolver = requestPathGenerator.getDefinitionDocumentResolver();
|
||||
|
||||
Operation operation = requestPathGenerator.getOperation().getOperation();
|
||||
public static Map<String, Object> generateRequestExampleMap(boolean generateMissingExamples, PathOperation pathOperation, Map<String, Model> definitions, DocumentResolver definitionDocumentResolver, 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", requestPathGenerator);
|
||||
}
|
||||
|
||||
if (generateMissingExamples)
|
||||
examples.put("path", pathOperation.getPath());
|
||||
for (Parameter parameter : parameters) {
|
||||
Object example = null;
|
||||
if (parameter instanceof BodyParameter) {
|
||||
example = getExamplesFromBodyParameter(parameter);
|
||||
if (example == null) {
|
||||
Model schema = ((BodyParameter) parameter).getSchema();
|
||||
if (schema instanceof RefModel) {
|
||||
String simpleRef = ((RefModel) schema).getSimpleRef();
|
||||
example = generateExampleForRefModel(generateMissingExamples, simpleRef, definitions, definitionDocumentResolver, markupDocBuilder, new HashMap<>());
|
||||
} else if (generateMissingExamples) {
|
||||
if (schema instanceof ComposedModel) {
|
||||
ObjectType objectType = (ObjectType) ModelUtils.getType(schema, definitions, definitionDocumentResolver);
|
||||
if(objectType != null) {
|
||||
example = exampleMapForProperties(
|
||||
objectType.getProperties(),
|
||||
definitions,
|
||||
definitionDocumentResolver,
|
||||
markupDocBuilder,
|
||||
new HashMap<>()
|
||||
);
|
||||
}
|
||||
} else if (schema instanceof ArrayModel) {
|
||||
example = generateExampleForArrayModel((ArrayModel) schema, definitions, definitionDocumentResolver, markupDocBuilder, new HashMap<>());
|
||||
} else {
|
||||
example = schema.getExample();
|
||||
if (example == null) {
|
||||
example = exampleMapForProperties(schema.getProperties(), definitions, definitionDocumentResolver, markupDocBuilder, new HashMap<>());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
requestPathGenerator.updateBodyParameterValue(parameter, example);
|
||||
example = generateBodyParameterExample(parameter, generateMissingExamples, definitions, definitionDocumentResolver, markupDocBuilder);
|
||||
} else if (parameter instanceof AbstractSerializableParameter) {
|
||||
if (generateMissingExamples) {
|
||||
Object abstractSerializableParameterExample;
|
||||
abstractSerializableParameterExample = ((AbstractSerializableParameter) parameter).getExample();
|
||||
if (abstractSerializableParameterExample == null) {
|
||||
abstractSerializableParameterExample = parameter.getVendorExtensions().get("x-example");
|
||||
}
|
||||
if (abstractSerializableParameterExample == null) {
|
||||
Property item = ((AbstractSerializableParameter) parameter).getItems();
|
||||
if (item != null) {
|
||||
abstractSerializableParameterExample = item.getExample();
|
||||
if (abstractSerializableParameterExample == null) {
|
||||
abstractSerializableParameterExample = PropertyAdapter.generateExample(item, markupDocBuilder);
|
||||
}
|
||||
}
|
||||
if (abstractSerializableParameterExample == null) {
|
||||
abstractSerializableParameterExample = ParameterAdapter.generateExample((AbstractSerializableParameter) parameter);
|
||||
}
|
||||
}
|
||||
if (parameter instanceof HeaderParameter) {
|
||||
if(requestPathGenerator.getClass() == BasicPathExample.class) {
|
||||
example = parameter.getName() + ":\"" + ((HeaderParameter) parameter).getType() + "\"";
|
||||
} else {
|
||||
requestPathGenerator.updateHeaderParameterValue(parameter, abstractSerializableParameterExample);
|
||||
}
|
||||
} else if (parameter instanceof PathParameter) {
|
||||
requestPathGenerator.updatePathParameterValue(parameter, abstractSerializableParameterExample);
|
||||
} else if (parameter instanceof QueryParameter) {
|
||||
requestPathGenerator.updateQueryParameterValue(parameter, abstractSerializableParameterExample);
|
||||
} else {
|
||||
example = abstractSerializableParameterExample;
|
||||
}
|
||||
example = generateAbstractSerializableParameterExample(parameter, examples, markupDocBuilder);
|
||||
}
|
||||
} else if (parameter instanceof RefParameter) {
|
||||
String simpleRef = ((RefParameter) parameter).getSimpleRef();
|
||||
@@ -187,38 +112,84 @@ public class ExamplesUtil {
|
||||
|
||||
if (example != null)
|
||||
examples.put(parameter.getIn(), example);
|
||||
|
||||
}
|
||||
|
||||
return examples;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves example payloads for body parameter either from examples or from vendor extensions.
|
||||
* Generates example for a body parameter
|
||||
*
|
||||
* @param parameter parameter to get the examples for
|
||||
* @return examples if found otherwise null
|
||||
* @param parameter Body paramteter to generate example for
|
||||
* @param generateMissingExamples Should an example be generated if none is defined
|
||||
* @param definitions the map of definitions
|
||||
* @param definitionDocumentResolver definitions document resolver
|
||||
* @param markupDocBuilder the markup builder
|
||||
* @return Object containing example
|
||||
*/
|
||||
private static Object getExamplesFromBodyParameter(Parameter parameter) {
|
||||
Object examples = ((BodyParameter) parameter).getExamples();
|
||||
if (examples == null) {
|
||||
examples = parameter.getVendorExtensions().get("x-examples");
|
||||
private static Object generateBodyParameterExample(Parameter parameter, Boolean generateMissingExamples, Map<String, Model> definitions, DocumentResolver definitionDocumentResolver, MarkupDocBuilder markupDocBuilder) {
|
||||
Object 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, definitionDocumentResolver, markupDocBuilder, new HashMap<>());
|
||||
} else if (generateMissingExamples) {
|
||||
if (schema instanceof ComposedModel) {
|
||||
//FIXME: getProperties() may throw NullPointerException
|
||||
example = exampleMapForProperties(((ObjectType) ModelUtils.getType(schema, definitions, definitionDocumentResolver)).getProperties(), definitions, definitionDocumentResolver, markupDocBuilder, new HashMap<>());
|
||||
} else if (schema instanceof ArrayModel) {
|
||||
example = generateExampleForArrayModel((ArrayModel) schema, definitions, definitionDocumentResolver, markupDocBuilder, new HashMap<>());
|
||||
} else {
|
||||
example = schema.getExample();
|
||||
if (example == null) {
|
||||
example = exampleMapForProperties(schema.getProperties(), definitions, definitionDocumentResolver, markupDocBuilder, new HashMap<>());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return examples;
|
||||
|
||||
return example;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes an example value for use in an URL
|
||||
*
|
||||
* @param example the example value
|
||||
* @return encoded example value
|
||||
*/
|
||||
public static String encodeExampleForUrl(Object example) {
|
||||
try {
|
||||
return URLEncoder.encode(String.valueOf(example), "UTF-8");
|
||||
} catch (UnsupportedEncodingException exception) {
|
||||
throw new RuntimeException(exception);
|
||||
private static Object generateAbstractSerializableParameterExample(Parameter parameter, Map<String, Object> examples, MarkupDocBuilder markupDocBuilder) {
|
||||
Object abstractSerializableParameterExample;
|
||||
Object example;
|
||||
abstractSerializableParameterExample = ((AbstractSerializableParameter) parameter).getExample();
|
||||
if (abstractSerializableParameterExample == null) {
|
||||
abstractSerializableParameterExample = parameter.getVendorExtensions().get("x-example");
|
||||
}
|
||||
if (abstractSerializableParameterExample == null) {
|
||||
Property item = ((AbstractSerializableParameter) parameter).getItems();
|
||||
if (item != null) {
|
||||
abstractSerializableParameterExample = item.getExample();
|
||||
if (abstractSerializableParameterExample == null) {
|
||||
abstractSerializableParameterExample = PropertyAdapter.generateExample(item, markupDocBuilder);
|
||||
}
|
||||
}
|
||||
if (abstractSerializableParameterExample == null) {
|
||||
abstractSerializableParameterExample = ParameterAdapter.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) {
|
||||
//TODO: #264 query parameters seem to be collected here
|
||||
//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;
|
||||
}
|
||||
return example;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -382,54 +353,6 @@ public class ExamplesUtil {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates examples for string properties or parameters with given format
|
||||
*
|
||||
* @param format the format of the string property
|
||||
* @param enumValues the enum values
|
||||
* @return example
|
||||
*/
|
||||
public static String generateStringExample(String format, List<String> enumValues) {
|
||||
if (enumValues == null || enumValues.isEmpty()) {
|
||||
if (format == null) {
|
||||
return "string";
|
||||
} else {
|
||||
switch (format) {
|
||||
case "byte":
|
||||
return "Ynl0ZQ==";
|
||||
case "date":
|
||||
return "1970-01-01";
|
||||
case "date-time":
|
||||
return "1970-01-01T00:00:00Z";
|
||||
case "email":
|
||||
return "email@example.com";
|
||||
case "password":
|
||||
return "secret";
|
||||
case "uuid":
|
||||
return "f81d4fae-7dec-11d0-a765-00a0c91e6bf6";
|
||||
default:
|
||||
return "string";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return enumValues.get(0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates examples for integer properties - if there are enums, it uses first enum value, returns 0 otherwise.
|
||||
*
|
||||
* @param enumValues the enum values
|
||||
* @return example
|
||||
*/
|
||||
public static Integer generateIntegerExample(List<Integer> enumValues) {
|
||||
if (enumValues == null || enumValues.isEmpty()) {
|
||||
return 0;
|
||||
} else {
|
||||
return enumValues.get(0);
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: Unused method, make sure this is never used and then remove it.
|
||||
//FIXME: getProperties() may throw NullPointerException
|
||||
|
||||
@@ -25,8 +25,6 @@ public class MapUtils {
|
||||
/**
|
||||
* Returns the 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 comparator the comparator to use.
|
||||
* @return the keySet of the Map
|
||||
@@ -50,7 +50,6 @@ 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
|
||||
@@ -70,9 +69,7 @@ public final class ModelUtils {
|
||||
objectType.getPolymorphism().setDiscriminator(modelImpl.getDiscriminator());
|
||||
|
||||
return objectType;
|
||||
} else if (modelImpl.getType() == null)
|
||||
return null;
|
||||
else if (isNotBlank(modelImpl.getFormat()))
|
||||
} else if (isNotBlank(modelImpl.getFormat()))
|
||||
return new BasicType(modelImpl.getType(), modelImpl.getTitle(), modelImpl.getFormat());
|
||||
else
|
||||
return new BasicType(modelImpl.getType(), modelImpl.getTitle());
|
||||
@@ -87,10 +84,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) {
|
||||
|
||||
@@ -16,15 +16,12 @@
|
||||
package io.github.swagger2markup.internal.utils;
|
||||
|
||||
import io.github.swagger2markup.model.PathOperation;
|
||||
import io.github.swagger2markup.model.SwaggerPathOperation;
|
||||
import io.swagger.models.HttpMethod;
|
||||
import io.swagger.models.Operation;
|
||||
import io.swagger.models.Path;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.isBlank;
|
||||
|
||||
public class PathUtils {
|
||||
|
||||
/**
|
||||
@@ -65,19 +62,17 @@ public class PathUtils {
|
||||
* Converts the Swagger paths into a list of PathOperations.
|
||||
*
|
||||
* @param paths the Swagger paths
|
||||
* @param host the host of all paths
|
||||
* @param basePath the basePath of all paths
|
||||
* @param comparator the comparator to use.
|
||||
* @return the path operations
|
||||
*/
|
||||
public static List<SwaggerPathOperation> toPathOperationsList(Map<String, Path> paths,
|
||||
String host,
|
||||
String basePath,
|
||||
Comparator<PathOperation> comparator) {
|
||||
List<SwaggerPathOperation> pathOperations = new ArrayList<>();
|
||||
public static List<PathOperation> toPathOperationsList(Map<String, Path> paths,
|
||||
String basePath,
|
||||
Comparator<PathOperation> comparator) {
|
||||
List<PathOperation> pathOperations = new ArrayList<>();
|
||||
|
||||
paths.forEach((relativePath, path) ->
|
||||
pathOperations.addAll(toPathOperationsList(host + basePath + relativePath, path)));
|
||||
pathOperations.addAll(toPathOperationsList(basePath + relativePath, path)));
|
||||
if (comparator != null) {
|
||||
pathOperations.sort(comparator);
|
||||
}
|
||||
@@ -91,19 +86,10 @@ public class PathUtils {
|
||||
* @param pathModel the Swagger Path model
|
||||
* @return the path operations
|
||||
*/
|
||||
public static List<SwaggerPathOperation> toPathOperationsList(String path, Path pathModel) {
|
||||
List<SwaggerPathOperation> pathOperations = new ArrayList<>();
|
||||
getOperationMap(pathModel).forEach((httpMethod, operation) -> {
|
||||
String id = operation.getOperationId();
|
||||
if (id == null)
|
||||
id = path + " " + httpMethod.toString().toLowerCase();
|
||||
|
||||
String operationName = operation.getSummary();
|
||||
if (isBlank(operationName)) {
|
||||
operationName = httpMethod.toString() + " " + path;
|
||||
}
|
||||
pathOperations.add(new SwaggerPathOperation(httpMethod.name(), path, id, operationName, operation));
|
||||
});
|
||||
public static List<PathOperation> toPathOperationsList(String path, Path pathModel) {
|
||||
List<PathOperation> pathOperations = new ArrayList<>();
|
||||
getOperationMap(pathModel).forEach((httpMethod, operation) ->
|
||||
pathOperations.add(new PathOperation(httpMethod, path, operation)));
|
||||
return pathOperations;
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ package io.github.swagger2markup.internal.utils;
|
||||
|
||||
import com.google.common.collect.LinkedHashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import io.github.swagger2markup.model.SwaggerPathOperation;
|
||||
import io.github.swagger2markup.model.PathOperation;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -55,12 +55,12 @@ public class RegexUtils {
|
||||
* @param headerPattern regex pattern used for determining headers
|
||||
* @return Operations grouped by regex
|
||||
*/
|
||||
public static Multimap<String, SwaggerPathOperation> groupOperationsByRegex(List<SwaggerPathOperation> allOperations, Pattern headerPattern) {
|
||||
public static Multimap<String, PathOperation> groupOperationsByRegex(List<PathOperation> allOperations, Pattern headerPattern) {
|
||||
|
||||
Multimap<String, SwaggerPathOperation> operationsGroupedByRegex = LinkedHashMultimap.create();
|
||||
Multimap<String, PathOperation> operationsGroupedByRegex = LinkedHashMultimap.create();
|
||||
|
||||
|
||||
for (SwaggerPathOperation operation : allOperations) {
|
||||
for (PathOperation operation : allOperations) {
|
||||
String path = operation.getPath();
|
||||
Matcher m = headerPattern.matcher(path);
|
||||
|
||||
@@ -19,7 +19,6 @@ import com.google.common.collect.LinkedHashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.MultimapBuilder;
|
||||
import io.github.swagger2markup.model.PathOperation;
|
||||
import io.github.swagger2markup.model.SwaggerPathOperation;
|
||||
import io.swagger.models.Tag;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.slf4j.Logger;
|
||||
@@ -57,15 +56,15 @@ public class TagUtils {
|
||||
* @param operationOrdering comparator for operations, for a given tag
|
||||
* @return Operations grouped by Tag
|
||||
*/
|
||||
public static Multimap<String, SwaggerPathOperation> groupOperationsByTag(List<SwaggerPathOperation> allOperations, Comparator<PathOperation> operationOrdering) {
|
||||
public static Multimap<String, PathOperation> groupOperationsByTag(List<PathOperation> allOperations, Comparator<PathOperation> operationOrdering) {
|
||||
|
||||
Multimap<String, SwaggerPathOperation> operationsGroupedByTag;
|
||||
Multimap<String, PathOperation> operationsGroupedByTag;
|
||||
if (operationOrdering == null) {
|
||||
operationsGroupedByTag = LinkedHashMultimap.create();
|
||||
} else {
|
||||
operationsGroupedByTag = MultimapBuilder.linkedHashKeys().treeSetValues(operationOrdering).build();
|
||||
}
|
||||
for (SwaggerPathOperation operation : allOperations) {
|
||||
for (PathOperation operation : allOperations) {
|
||||
List<String> tags = operation.getOperation().getTags();
|
||||
|
||||
Validate.notEmpty(tags, "Can't GroupBy.TAGS. Operation '%s' has no tags", operation);
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright 2017 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.github.swagger2markup.model;
|
||||
|
||||
import io.swagger.models.HttpMethod;
|
||||
import io.swagger.models.Operation;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.isBlank;
|
||||
|
||||
public class PathOperation {
|
||||
|
||||
private HttpMethod method;
|
||||
private String path;
|
||||
private 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();
|
||||
}
|
||||
}
|
||||
@@ -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 */
|
||||
}
|
||||
|
||||
}
|
||||