diff --git a/README.md b/README.md index 6ac8f6ff8a..306b6dbf3a 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Swagger-core is the Java implementation of Swagger. Current version supports *JA Check out the [OpenAPI Specification](https://github.com/OAI/OpenAPI-Specification) for additional information about the Swagger project. ## Get started with Swagger! -See the guide on [getting started with swagger](https://github.com/frantuma/swagger-core/wiki/Swagger-2.X---Getting-started) to get started with adding swagger to your API. +See the guide on [getting started with swagger](https://github.com/swagger-api/swagger-core/wiki/Swagger-2.X---Getting-started) to get started with adding swagger to your API. ## See the Wiki! The [github wiki](https://github.com/swagger-api/swagger-core/wiki) contains documentation, samples, contributions, etc. Start there. diff --git a/modules/swagger-gradle-plugin/.gitignore b/modules/swagger-gradle-plugin/.gitignore new file mode 100644 index 0000000000..2e5ec09fe7 --- /dev/null +++ b/modules/swagger-gradle-plugin/.gitignore @@ -0,0 +1,117 @@ + +# Created by https://www.gitignore.io/api/java,gradle,intellij + +### Intellij ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff: +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/dictionaries + +# Sensitive or high-churn files: +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.xml +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml + +# Gradle: +.idea/**/gradle.xml +.idea/**/libraries + +# CMake +cmake-build-debug/ + +# Mongo Explorer plugin: +.idea/**/mongoSettings.xml + +## File-based project format: +*.iws + +## Plugin-specific files: + +# IntelliJ +/out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Ruby plugin and RubyMine +/.rakeTasks + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +### Intellij Patch ### +# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 + +# *.iml +# modules.xml +# .idea/misc.xml +# *.ipr + +# Sonarlint plugin +.idea/sonarlint + +### Java ### +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + +### Gradle ### +.gradle +**/build/ + +# Ignore Gradle GUI config +gradle-app.setting + +# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) +!gradle-wrapper.jar + +# Cache of project +.gradletasknamecache + +# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 +# gradle/wrapper/gradle-wrapper.properties + + +# End of https://www.gitignore.io/api/java,gradle,intellij + +.idea/modules +# IntelliJ IDEA +.idea/ +*.iml +*.iws +*.ipr diff --git a/modules/swagger-gradle-plugin/README.md b/modules/swagger-gradle-plugin/README.md new file mode 100644 index 0000000000..bc24927386 --- /dev/null +++ b/modules/swagger-gradle-plugin/README.md @@ -0,0 +1,69 @@ +# swagger-gradle-plugin + +## Installation +### Gradle 2.1 and higher + +``` +plugins { + id "io.swagger.core.v3.swagger-gradle-plugin" version "2.0.5-SNAPSHOT" +} +``` +### Gradle 1.x and 2.0 + +``` +buildscript { + repositories { + maven { + url "https://plugins.gradle.org/m2/" + } + } + dependencies { + classpath "gradle.plugin.io.swagger.core.v3.swagger-gradle-plugin:2.0.5-SNAPSHOT" + } +} + +apply plugin: "io.swagger.core.v3.swagger-gradle-plugin" +``` + +## Tasks +### resolve + +* Resolves project openAPI specification and saves the result in JSON, YAML or both formats. +All parameters except `outputFileName`, `outputFormat`, `classpath`, `skip`, `encoding` and `outputPath` correspond +to `swagger` [configuration property](https://github.com/swagger-api/swagger-core/wiki/Swagger-2.X---Integration-and-Configuration#configuration-properties) with same name. + +#### Example Usage + +``` + +resolve { + outputFileName = 'PetStoreAPI' + outputFormat = 'JSON' + prettyPrint = 'TRUE' + classpath = sourceSets.main.runtimeClasspath + resourcePackages = ['io.test'] + outputPath = 'test' +} +``` + +#### Parameters +Parameter | Description | Required | Default +--------- | ----------- | --------- | ------- +`classpath`|classpath for resources to scan (swagger and deps already included in classpath)|true| +`outputPath`|output path where file(s) are saved|true| +`outputFileName`|file name (no extension)|false|`openapi` +`outputFormat`|file format (`JSON`, `YAML`, `JSONANDYAML`|false|`JSON` +`skip`|if `TRUE` skip execution|false|`FALSE` +`encoding`|encoding of output file(s)|false| +`resourcePackages`|see [configuration property](https://github.com/swagger-api/swagger-core/wiki/Swagger-2.X---Integration-and-Configuration#configuration-properties)|false| +`resourceClasses`|see [configuration property](https://github.com/swagger-api/swagger-core/wiki/Swagger-2.X---Integration-and-Configuration#configuration-properties)|false| +`prettyPrint`|see [configuration property](https://github.com/swagger-api/swagger-core/wiki/Swagger-2.X---Integration-and-Configuration#configuration-properties)|false|`TRUE` +`openApiFile`|openapi file to be merged with resolved specification, see [config](https://github.com/swagger-api/swagger-core/wiki/Swagger-2.X---Integration-and-Configuration#configuration-properties)|false| +`filterClass`|see [configuration property](https://github.com/swagger-api/swagger-core/wiki/Swagger-2.X---Integration-and-Configuration#configuration-properties)|false| +`readerClass`|see [configuration property](https://github.com/swagger-api/swagger-core/wiki/Swagger-2.X---Integration-and-Configuration#configuration-properties)|false| +`scannerClass`|see [configuration property](https://github.com/swagger-api/swagger-core/wiki/Swagger-2.X---Integration-and-Configuration#configuration-properties)|false| +`readAllResources`|see [configuration property](https://github.com/swagger-api/swagger-core/wiki/Swagger-2.X---Integration-and-Configuration#configuration-properties)|false| +`ignoredRoutes`|see [configuration property](https://github.com/swagger-api/swagger-core/wiki/Swagger-2.X---Integration-and-Configuration#configuration-properties)|false| + +*** + diff --git a/modules/swagger-gradle-plugin/build.gradle b/modules/swagger-gradle-plugin/build.gradle new file mode 100644 index 0000000000..2e475d5180 --- /dev/null +++ b/modules/swagger-gradle-plugin/build.gradle @@ -0,0 +1,88 @@ +// * * * * * * * * * * * * +// Plugins +// * * * * * * * * * * * * +plugins { + id 'groovy' + id 'java-gradle-plugin' + id 'net.researchgate.release' version '2.6.0' + // Publishing publicly + id 'com.gradle.plugin-publish' version '0.10.0' + // Publishing to maven + id 'maven-publish' +} + +// * * * * * * * * * * * * +// Dependencies +// * * * * * * * * * * * * + +repositories { + jcenter() + mavenLocal() + mavenCentral() +} + +dependencies { + compile gradleApi() + compile group: 'org.apache.commons', name: 'commons-lang3', version:'3.7' + compile group: 'io.swagger.core.v3', name: 'swagger-jaxrs2', version:'2.0.5-SNAPSHOT' + compile group: 'javax.ws.rs', name: 'javax.ws.rs-api', version:'2.1' + compile group: 'javax.servlet', name: 'javax.servlet-api', version:'3.1.0' + testCompile group: 'com.github.tomakehurst', name: 'wiremock', version:'2.14.0' + testCompile gradleTestKit() + testCompile 'junit:junit:4+' + + +} + +// * * * * * * * * * * * * +// Project configuration +// * * * * * * * * * * * * + +project.description = 'Gradle Plugin for Swagger core' +project.group = 'io.swagger.core.v3' + +project.ext.name = 'swagger-gradle-plugin' +project.ext.pluginId = 'io.swagger.core.v3.swagger-gradle-plugin' +project.ext.scm = 'scm:git@github.com:swagger-api/swagger-core.git' +project.ext.url = 'https://github.com/swagger-api/swagger-core/modules/swagger-gradle-plugin' + +// Configuration for: java-gradle-plugin +gradlePlugin { + plugins { + swagger { + id = project.pluginId + implementationClass = 'io.swagger.v3.plugins.gradle.SwaggerPlugin' + } + } +} + +// * * * * * * * * * * * * +// Publishing +// * * * * * * * * * * * * + + +// Publishing to plugins.gradle.org +// -------------------------------- + +// Configuration for: com.gradle.plugin-publish +pluginBundle { + website = project.url + vcsUrl = project.scm + tags = ['swagger', 'openapi', 'api'] + + plugins { + swagger { + displayName = 'Swagger Gradle Plugin ' + description = project.description + id = project.pluginId + } + } +} + +publishing { + repositories { + maven { + url mavenLocal().url + } + } +} \ No newline at end of file diff --git a/modules/swagger-gradle-plugin/gradle.properties b/modules/swagger-gradle-plugin/gradle.properties new file mode 100644 index 0000000000..aa4cef907a --- /dev/null +++ b/modules/swagger-gradle-plugin/gradle.properties @@ -0,0 +1 @@ +version=2.0.5-SNAPSHOT diff --git a/modules/swagger-gradle-plugin/gradle/wrapper/gradle-wrapper.jar b/modules/swagger-gradle-plugin/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000000..01b8bf6b1f Binary files /dev/null and b/modules/swagger-gradle-plugin/gradle/wrapper/gradle-wrapper.jar differ diff --git a/modules/swagger-gradle-plugin/gradle/wrapper/gradle-wrapper.properties b/modules/swagger-gradle-plugin/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000000..b426bfe2e1 --- /dev/null +++ b/modules/swagger-gradle-plugin/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Thu Jun 21 16:50:21 IST 2018 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip diff --git a/modules/swagger-gradle-plugin/gradlew b/modules/swagger-gradle-plugin/gradlew new file mode 100755 index 0000000000..cccdd3d517 --- /dev/null +++ b/modules/swagger-gradle-plugin/gradlew @@ -0,0 +1,172 @@ +#!/usr/bin/env sh + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +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" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi + +exec "$JAVACMD" "$@" diff --git a/modules/swagger-gradle-plugin/gradlew.bat b/modules/swagger-gradle-plugin/gradlew.bat new file mode 100644 index 0000000000..e95643d6a2 --- /dev/null +++ b/modules/swagger-gradle-plugin/gradlew.bat @@ -0,0 +1,84 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/modules/swagger-gradle-plugin/settings.gradle b/modules/swagger-gradle-plugin/settings.gradle new file mode 100644 index 0000000000..aa1f239ad8 --- /dev/null +++ b/modules/swagger-gradle-plugin/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'swagger-gradle-plugin' diff --git a/modules/swagger-gradle-plugin/src/main/java/io/swagger/v3/plugins/gradle/SwaggerPlugin.java b/modules/swagger-gradle-plugin/src/main/java/io/swagger/v3/plugins/gradle/SwaggerPlugin.java new file mode 100644 index 0000000000..204cf4f6ef --- /dev/null +++ b/modules/swagger-gradle-plugin/src/main/java/io/swagger/v3/plugins/gradle/SwaggerPlugin.java @@ -0,0 +1,44 @@ +package io.swagger.v3.plugins.gradle; + +import io.swagger.v3.plugins.gradle.tasks.ResolveTask; +import org.gradle.api.Action; +import org.gradle.api.Plugin; +import org.gradle.api.Project; +import org.gradle.api.Task; +import org.gradle.api.artifacts.Configuration; +import org.gradle.api.artifacts.DependencySet; + +public class SwaggerPlugin implements Plugin { + public void apply(Project project) { + final Configuration config = project.getConfigurations().create("swaggerDeps") + .setVisible(false); + + config.defaultDependencies(new Action() { + public void execute(DependencySet dependencies) { + dependencies.add(project.getDependencies().create("org.apache.commons:commons-lang3:3.7")); + dependencies.add(project.getDependencies().create("io.swagger.core.v3:swagger-jaxrs2:2.0.5-SNAPSHOT")); + dependencies.add(project.getDependencies().create("javax.ws.rs:javax.ws.rs-api:2.1")); + dependencies.add(project.getDependencies().create("javax.servlet:javax.servlet-api:3.1.0")); + } + }); + Task task = project.getTasks().create("resolve", ResolveTask.class); + ((ResolveTask)task).setBuildClasspath(config); + + try { + if (project.getTasks().findByPath("classes") != null) { + task.dependsOn("classes"); + } + if (project.getTasks().findByPath("compileJava") != null) { + task.dependsOn("compileJava"); + } + if (project.getTasks().findByPath("compileTestJava") != null) { + task.dependsOn("compileTestJava"); + } + if (project.getTasks().findByPath("testClasses") != null) { + task.dependsOn("testClasses"); + } + } catch (Exception e) { + project.getLogger().warn("Exception in task dependencies: " + e.getMessage(), e); + } + } +} diff --git a/modules/swagger-gradle-plugin/src/main/java/io/swagger/v3/plugins/gradle/tasks/ResolveTask.java b/modules/swagger-gradle-plugin/src/main/java/io/swagger/v3/plugins/gradle/tasks/ResolveTask.java new file mode 100644 index 0000000000..ae27874d40 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/main/java/io/swagger/v3/plugins/gradle/tasks/ResolveTask.java @@ -0,0 +1,340 @@ +package io.swagger.v3.plugins.gradle.tasks; + +import org.apache.commons.lang3.StringUtils; +import org.gradle.api.DefaultTask; +import org.gradle.api.GradleException; +import org.gradle.api.logging.Logging; +import org.gradle.api.tasks.Classpath; +import org.gradle.api.tasks.Input; +import org.gradle.api.tasks.InputFile; +import org.gradle.api.tasks.InputFiles; +import org.gradle.api.tasks.Optional; +import org.gradle.api.tasks.OutputDirectory; +import org.gradle.api.tasks.TaskAction; +import org.slf4j.Logger; + +import java.io.File; +import java.io.IOException; +import java.lang.reflect.Method; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Collection; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.StreamSupport; + +public class ResolveTask extends DefaultTask { + private static Logger LOGGER = Logging.getLogger(ResolveTask.class); + + public enum Format {JSON, YAML, JSONANDYAML}; + + private String outputFileName = "openapi"; + + private String outputPath; + private File outputDir; + + private File openApiFile; + + private Format outputFormat = Format.JSON; + + private Set resourcePackages; + private Set resourceClasses; + private String filterClass; + private String readerClass; + private String scannerClass; + private Boolean prettyPrint = false; + private Boolean readAllResources = Boolean.TRUE; + private Collection ignoredRoutes; + private Iterable buildClasspath; + private Iterable classpath; + + private Boolean skip = Boolean.FALSE; + + private String encoding = "UTF-8"; + + @Input + @Optional + public String getOutputFileName() { + return outputFileName; + } + + @InputFile + @Optional + public File getOpenApiFile() { + return openApiFile; + } + + public void setOpenApiFile(File openApiFile) { + this.openApiFile = openApiFile; + } + + @Classpath + @InputFiles + public Iterable getClasspath() { + return classpath; + } + + public void setClasspath(Iterable classpath) { + this.classpath = classpath; + } + + @Classpath + @InputFiles + @Optional + public Iterable getBuildClasspath() { + return buildClasspath; + } + + public void setBuildClasspath(Iterable buildClasspath) { + this.buildClasspath = buildClasspath; + } + + public void setOutputFileName(String outputFileName) { + this.outputFileName = outputFileName; + } + + @Input + public String getOutputPath() { + return outputPath; + } + + public void setOutputPath(String outputPath) { + this.outputPath = outputPath; + outputDir = new File(outputPath); + } + + + @OutputDirectory + public File getOutputDir() { + return outputDir; + } + + public void setOutputDir(File outputDir) { + this.outputDir = outputDir; + } + + @Input + @Optional + public Format getOutputFormat() { + return outputFormat; + } + + public void setOutputFormat(Format outputFormat) { + this.outputFormat = outputFormat; + } + + @Input + @Optional + public Set getResourcePackages() { + return resourcePackages; + } + + public void setResourcePackages(Set resourcePackages) { + this.resourcePackages = resourcePackages; + } + + @Input + @Optional + public Set getResourceClasses() { + return resourceClasses; + } + + public void setResourceClasses(Set resourceClasses) { + this.resourceClasses = resourceClasses; + } + + @Input + @Optional + public String getFilterClass() { + return filterClass; + } + + public void setFilterClass(String filterClass) { + this.filterClass = filterClass; + } + + @Input + @Optional + public String getReaderClass() { + return readerClass; + } + + public void setReaderClass(String readerClass) { + this.readerClass = readerClass; + } + + @Input + @Optional + public String getScannerClass() { + return scannerClass; + } + + public void setScannerClass(String scannerClass) { + this.scannerClass = scannerClass; + } + + @Input + @Optional + public Boolean getPrettyPrint() { + return prettyPrint; + } + + public void setPrettyPrint(Boolean prettyPrint) { + this.prettyPrint = prettyPrint; + } + + @Input + @Optional + public Boolean getReadAllResources() { + return readAllResources; + } + + public void setReadAllResources(Boolean readAllResources) { + this.readAllResources = readAllResources; + } + + @Input + @Optional + public Collection getIgnoredRoutes() { + return ignoredRoutes; + } + + public void setIgnoredRoutes(Collection ignoredRoutes) { + this.ignoredRoutes = ignoredRoutes; + } + + @Input + @Optional + public Boolean getSkip() { + return skip; + } + + public void setSkip(Boolean skip) { + this.skip = skip; + } + + @Input + @Optional + public String getEncoding() { + return encoding; + } + + public void setEncoding(String resourceClasses) { + this.encoding = encoding; + } + + + @TaskAction + public void resolve() throws GradleException { + if (skip) { + LOGGER.info( "Skipping OpenAPI specification resolution" ); + return; + } + LOGGER.info( "Resolving OpenAPI specification.." ); + + Set urls = StreamSupport.stream(getClasspath().spliterator(), false).map(f -> { + try { + return f.toURI().toURL(); + } + catch (MalformedURLException e) { + throw new GradleException( + String.format("Could not create classpath for annotations task %s.", getName()), e); + } + }).collect(Collectors.toSet()); + + Set buildUrls = StreamSupport.stream(getBuildClasspath().spliterator(), false).map(f -> { + try { + return f.toURI().toURL(); + } + catch (MalformedURLException e) { + throw new GradleException( + String.format("Could not create classpath for annotations task %s.", getName()), e); + } + }).collect(Collectors.toSet()); + + urls.addAll(buildUrls); + + //ClassLoader classLoader = new URLClassLoader(urls.toArray(new URL[urls.size()]), Thread.currentThread().getContextClassLoader()); + ClassLoader classLoader = new URLClassLoader(urls.toArray(new URL[urls.size()])); + + try { + Class swaggerLoaderClass = classLoader.loadClass("io.swagger.v3.jaxrs2.integration.SwaggerLoader"); + Object swaggerLoader = swaggerLoaderClass.newInstance(); + + Method method = null; + method=swaggerLoaderClass.getDeclaredMethod("setOutputFormat",String.class); + method.invoke(swaggerLoader, outputFormat.name()); + + if (openApiFile != null) { + if (openApiFile.exists() && openApiFile.isFile()) { + String openapiFileContent = new String(Files.readAllBytes(openApiFile.toPath()), encoding); + if (StringUtils.isNotBlank(openapiFileContent)) { + method=swaggerLoaderClass.getDeclaredMethod("setOpenapiAsString",String.class); + method.invoke(swaggerLoader, openapiFileContent); + } + } + } + + if (resourcePackages != null && !resourcePackages.isEmpty()) { + method=swaggerLoaderClass.getDeclaredMethod("setResourcePackages",String.class); + method.invoke(swaggerLoader, resourcePackages.stream().map(Object::toString).collect(Collectors.joining(","))); + } + if (resourceClasses != null && !resourceClasses.isEmpty()) { + method=swaggerLoaderClass.getDeclaredMethod("setResourceClasses",String.class); + method.invoke(swaggerLoader, resourceClasses.stream().map(Object::toString).collect(Collectors.joining(","))); + } + if (ignoredRoutes != null && !ignoredRoutes.isEmpty()) { + method=swaggerLoaderClass.getDeclaredMethod("setIgnoredRoutes",String.class); + method.invoke(swaggerLoader, ignoredRoutes.stream().map(Object::toString).collect(Collectors.joining(","))); + } + + if (StringUtils.isNotBlank(filterClass)) { + method=swaggerLoaderClass.getDeclaredMethod("setFilterClass",String.class); + method.invoke(swaggerLoader, filterClass); + } + + if (StringUtils.isNotBlank(readerClass)) { + method=swaggerLoaderClass.getDeclaredMethod("setReaderClass",String.class); + method.invoke(swaggerLoader, readerClass); + } + + if (StringUtils.isNotBlank(scannerClass)) { + method=swaggerLoaderClass.getDeclaredMethod("setScannerClass",String.class); + method.invoke(swaggerLoader, scannerClass); + } + + method=swaggerLoaderClass.getDeclaredMethod("setPrettyPrint", Boolean.class); + method.invoke(swaggerLoader, prettyPrint); + + method=swaggerLoaderClass.getDeclaredMethod("setReadAllResources", Boolean.class); + method.invoke(swaggerLoader, readAllResources); + + method=swaggerLoaderClass.getDeclaredMethod("resolve"); + Map specs = (Map)method.invoke(swaggerLoader); + + Path path = Paths.get(outputPath, "temp"); + final File parentFile = path.toFile().getParentFile(); + if (parentFile != null) { + parentFile.mkdirs(); + } + if (specs.get("JSON") != null) { + path = Paths.get(outputPath, outputFileName + ".json"); + Files.write(path, specs.get("JSON").getBytes(Charset.forName(encoding))); + } + if (specs.get("YAML") != null) { + path = Paths.get(outputPath, outputFileName + ".yaml"); + Files.write(path, specs.get("YAML").getBytes(Charset.forName(encoding))); + } + } catch (IOException e) { + throw new GradleException("Failed to write API definition: " + e.getMessage(), e); + } catch (Exception e) { + throw new GradleException(e.getMessage(), e); + } + } +} diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/SwaggerResolveTest.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/SwaggerResolveTest.java new file mode 100644 index 0000000000..2704869496 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/SwaggerResolveTest.java @@ -0,0 +1,129 @@ +package io.swagger.v3.plugins.gradle; + +import org.gradle.testkit.runner.BuildResult; +import org.gradle.testkit.runner.GradleRunner; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; + +import static junit.framework.TestCase.assertTrue; +import static org.gradle.testkit.runner.TaskOutcome.SUCCESS; +import static org.junit.Assert.assertEquals; + +public class SwaggerResolveTest { + + @Rule + public final TemporaryFolder testProjectDir = new TemporaryFolder(); + private File buildFile; + private File openapiInputFile; + private String outputFile; + private String outputDir; + + @Before + public void setup() throws IOException { + buildFile = testProjectDir.newFile("build.gradle"); + openapiInputFile = testProjectDir.newFile("openapiinput.yaml"); + writeFile(openapiInputFile, "openapi: 3.0.1\n" + + "servers:\n" + + "- url: http://foo\n" + + " description: server 1\n" + + " variables:\n" + + " var1:\n" + + " description: var 1\n" + + " enum:\n" + + " - \"1\"\n" + + " - \"2\"\n" + + " default: \"2\"\n" + + " var2:\n" + + " description: var 2\n" + + " enum:\n" + + " - \"1\"\n" + + " - \"2\"\n" + + " default: \"2\""); + } + + @Test + public void testSwaggerResolveTask() throws IOException { + outputDir = testProjectDir.getRoot().toString() + "/target"; + outputFile = testProjectDir.getRoot().toString() + "/testAPI.json"; + outputDir = "/tmp/a/target"; + String resolveTask = "resolve"; + + String buildFileContent = + "buildscript {\n" + + " dependencies {\n" + + " classpath files(\"" + testProjectDir.getRoot().toString() + "/classes/java/test\")\n" + + " }\n" + + " }\n" + + "plugins {\n" + + " id 'groovy'\n" + + " id 'java'\n" + + " id 'io.swagger.core.v3.swagger-gradle-plugin'\n" + + "}\n" + + "sourceSets {\n" + + " test {\n" + + " java {\n" + + " srcDirs = ['" + new File("src/test/javatest").getAbsolutePath() + "']\n" + + " }\n" + + " }\n" + + "}\n" + + "repositories {\n" + + " jcenter()\n" + + " mavenLocal()\n" + + " mavenCentral()\n" + + "}\n" + + "dependencies { \n" + + //" compile configurations.runtime\n" + + " compile group: 'org.apache.commons', name: 'commons-lang3', version:'3.7'\n" + + " compile group: 'io.swagger.core.v3', name: 'swagger-jaxrs2', version:'2.0.5-SNAPSHOT'\n" + + " compile group: 'javax.ws.rs', name: 'javax.ws.rs-api', version:'2.1'\n" + + " compile group: 'javax.servlet', name: 'javax.servlet-api', version:'3.1.0'\n" + + " testCompile group: 'com.github.tomakehurst', name: 'wiremock', version:'2.14.0'\n" + + " testCompile 'junit:junit:4+'\n" + + "\n" + + "\n" + + "}\n" + + resolveTask + " {\n" + + " outputFileName = 'PetStoreAPI'\n" + + " outputFormat = 'JSON'\n" + + " prettyPrint = 'TRUE'\n" + + //" classpath = compileTestJava.outputs.files\n" + + " classpath = sourceSets.test.runtimeClasspath\n" + + " resourcePackages = ['io.swagger.v3.plugins.gradle.petstore']\n" + + " outputPath = \'" + outputDir + "\'\n" + + " openApiFile = file(\'" + openapiInputFile.getAbsolutePath() + "\')\n" + + "}"; + + + writeFile(buildFile, buildFileContent); + + BuildResult result = GradleRunner.create() + .withPluginClasspath() + .withProjectDir(testProjectDir.getRoot()) + .withDebug(true) + //.withArguments("build", "--stacktrace", "--info") + .withArguments(resolveTask, "--stacktrace") + .build(); + + assertEquals(SUCCESS, result.task(":" + resolveTask).getOutcome()); + assertTrue(new File(outputDir + "/PetStoreAPI.json").exists()); + } + + private void writeFile(File destination, String content) throws IOException { + BufferedWriter output = null; + try { + output = new BufferedWriter(new FileWriter(destination)); + output.write(content); + } finally { + if (output != null) { + output.close(); + } + } + } +} diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/EmptyPetResource.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/EmptyPetResource.java new file mode 100644 index 0000000000..3a60f75fe2 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/EmptyPetResource.java @@ -0,0 +1,7 @@ +package io.swagger.v3.plugins.gradle.petstore; + +/** + * An Empty PetResource Class + */ +public class EmptyPetResource { +} diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/PetResource.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/PetResource.java new file mode 100644 index 0000000000..a0d713071d --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/PetResource.java @@ -0,0 +1,165 @@ +/** + * Copyright 2016 SmartBear Software + *

+ * 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.swagger.v3.plugins.gradle.petstore; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.plugins.gradle.resources.QueryResultBean; +import io.swagger.v3.plugins.gradle.resources.data.PetData; +import io.swagger.v3.plugins.gradle.resources.exception.NotFoundException; +import io.swagger.v3.plugins.gradle.resources.model.Pet; + +import javax.ws.rs.BeanParam; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Response; + +@Consumes("application/json") +@Path("/pet") +@Produces({"application/json", "application/xml"}) +public class PetResource { + static PetData petData = new PetData(); + + @GET + @Path("/{petId}") + @Operation(summary = "Find pet by ID", + description = "Returns a pet when 0 < ID <= 10. ID > 10 or nonintegers will simulate API error conditions", + responses = { + @ApiResponse( + description = "The pet", content = @Content( + schema = @Schema(implementation = Pet.class) + )), + @ApiResponse(responseCode = "400", description = "Invalid ID supplied"), + @ApiResponse(responseCode = "404", description = "Pet not found") + }) + public Response getPetById( + @Parameter(description = "ID of pet that needs to be fetched"/*, _enum = "range[1,10]"*/, required = true) + @PathParam("petId") final Long petId) throws NotFoundException { + Pet pet = petData.getPetById(petId); + if (null != pet) { + return Response.ok().entity(pet).build(); + } else { + throw new NotFoundException(404, "Pet not found"); + } + } + + @POST + @Consumes({"application/json", "application/xml"}) + @Operation(summary = "Add a new pet to the store", + responses = { + @ApiResponse(responseCode = "405", description = "Invalid input") + }) + public Response addPet( + @Parameter(description = "Pet object that needs to be added to the store", required = true) final Pet pet) { + petData.addPet(pet); + return Response.ok().entity("SUCCESS").build(); + } + + @POST + @Path("/bodynoannotation") + @Consumes({"application/json", "application/xml"}) + @Produces({"application/json", "application/xml"}) + @Operation(summary = "Add a new pet to the store no annotation", + responses = { + @ApiResponse(responseCode = "405", description = "Invalid input") + }) + public Response addPetNoAnnotation(final Pet pet) { + petData.addPet(pet); + return Response.ok().entity("SUCCESS").build(); + } + + @POST + @Path("/bodyid") + @Consumes({"application/json", "application/xml"}) + @Operation(summary = "Add a new pet to the store passing an integer with generic parameter annotation", + responses = { + @ApiResponse(responseCode = "405", description = "Invalid input") + }) + public Response addPetByInteger( + @Parameter(description = "Pet object that needs to be added to the store", required = true) final int petId) { + return Response.ok().entity("SUCCESS").build(); + } + + @POST + @Path("/bodyidnoannotation") + @Consumes({"application/json", "application/xml"}) + @Operation(summary = "Add a new pet to the store passing an integer without parameter annotation", + responses = { + @ApiResponse(responseCode = "405", description = "Invalid input") + }) + public Response addPetByIntegerNoAnnotation(final int petId) { + return Response.ok().entity("SUCCESS").build(); + } + + @PUT + @Operation(summary = "Update an existing pet", + responses = { + @ApiResponse(responseCode = "400", description = "Invalid ID supplied"), + @ApiResponse(responseCode = "404", description = "Pet not found"), + @ApiResponse(responseCode = "405", description = "Validation exception")}) + public Response updatePet( + @Parameter(description = "Pet object that needs to be added to the store", required = true) final Pet pet) { + petData.addPet(pet); + return Response.ok().entity("SUCCESS").build(); + } + + @GET + @Path("/findByStatus") + @Produces("application/xml") + @Operation(summary = "Finds Pets by status", + description = "Multiple status values can be provided with comma seperated strings", + responses = { + @ApiResponse( + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Pet.class))), + @ApiResponse( + responseCode = "400", description = "Invalid status value" + )} + ) + public Response findPetsByStatus( + @Parameter(description = "Status values that need to be considered for filter", required = true) @QueryParam("status") final String status, + @BeanParam final QueryResultBean qr + ) { + return Response.ok(petData.findPetByStatus(status)).build(); + } + + @GET + @Path("/findByTags") + @Produces("application/json") + @Operation(summary = "Finds Pets by tags", + description = "Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.", + responses = { + @ApiResponse(description = "Pets matching criteria", + content = @Content(schema = @Schema(implementation = Pet.class)) + ), + @ApiResponse(description = "Invalid tag value", responseCode = "400") + }) + @Deprecated + public Response findPetsByTags( + @Parameter(description = "Tags to filter by", required = true) @QueryParam("tags") final String tags) { + return Response.ok(petData.findPetByTags(tags)).build(); + } +} diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/callback/ComplexCallbackResource.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/callback/ComplexCallbackResource.java new file mode 100644 index 0000000000..44dfc535ee --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/callback/ComplexCallbackResource.java @@ -0,0 +1,62 @@ +package io.swagger.v3.plugins.gradle.petstore.callback; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.callbacks.Callback; +import io.swagger.v3.oas.annotations.callbacks.Callbacks; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.plugins.gradle.resources.model.User; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.QueryParam; + +public class ComplexCallbackResource { + @Callbacks({ + @Callback( + name = "testCallback1", + operation = @Operation( + operationId = "getAllReviews", + summary = "get all the reviews", + method = "get", + responses = @ApiResponse( + responseCode = "200", + description = "successful operation", + content = @Content( + mediaType = "application/json", + schema = @Schema( + type = "integer", + format = "int32")))), + callbackUrlExpression = "http://www.url.com"), + @Callback( + name = "testCallback2", + operation = @Operation( + operationId = "getAnSpecificReviews", + summary = "get a review", + method = "get", + responses = @ApiResponse( + responseCode = "200", + description = "successful operation", + content = @Content( + mediaType = "application/json", + schema = @Schema( + implementation = User.class)))), + callbackUrlExpression = "http://www.url2.com") + }) + @Operation( + summary = "Simple get operation", + operationId = "getWithNoParameters", + responses = { + @ApiResponse( + responseCode = "200", + description = "voila!") + }) + @GET + @Path("/complexcallback") + public String simpleGet(@Parameter(description = "idParam", schema = @Schema(implementation = User.class)) + @QueryParam("id") final String id) { + return null; + } +} diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/callback/MultipleCallbacksTestWithOperationResource.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/callback/MultipleCallbacksTestWithOperationResource.java new file mode 100644 index 0000000000..2ec7309b1b --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/callback/MultipleCallbacksTestWithOperationResource.java @@ -0,0 +1,45 @@ +package io.swagger.v3.plugins.gradle.petstore.callback; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.callbacks.Callback; +import io.swagger.v3.oas.annotations.callbacks.Callbacks; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +public class MultipleCallbacksTestWithOperationResource { + @Callbacks({ + @Callback( + name = "testCallback1", + operation = @Operation( + operationId = "getAllReviews", + summary = "get all the reviews", + method = "get", + responses = @ApiResponse( + responseCode = "200", + description = "successful operation", + content = @Content( + mediaType = "application/json", + schema = @Schema( + type = "integer", + format = "int32")))), + callbackUrlExpression = "http://www.url.com"), + @Callback(name = "testCallback2", operation = @Operation(), callbackUrlExpression = "http://$request.query.url") + }) + @Operation( + summary = "Simple get operation", + operationId = "getWithNoParameters", + responses = { + @ApiResponse( + responseCode = "200", + description = "voila!") + }) + @GET + @Path("/multiplecallback") + public String simpleGet() { + return null; + } +} \ No newline at end of file diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/callback/RepeatableCallbackResource.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/callback/RepeatableCallbackResource.java new file mode 100644 index 0000000000..82a60ca110 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/callback/RepeatableCallbackResource.java @@ -0,0 +1,46 @@ +package io.swagger.v3.plugins.gradle.petstore.callback; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.callbacks.Callback; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +public class RepeatableCallbackResource { + @Callback(name = "testCallback", operation = + @Operation(), callbackUrlExpression = "http://$requests.query.url") + @Callback( + name = "testCallback1", + operation = @Operation( + operationId = "getAllReviews", + summary = "get all the reviews", + method = "get", + responses = @ApiResponse( + responseCode = "200", + description = "successful operation", + content = @Content( + mediaType = "application/json", + schema = @Schema( + type = "integer", + format = "int32")))), + callbackUrlExpression = "http://www.url.com") + @Callback(name = "testCallback2", operation = + @Operation(), + callbackUrlExpression = "http://$request.query.url") + @Operation( + summary = "Simple get operation", + operationId = "getWithNoParameters", + responses = { + @ApiResponse( + responseCode = "200", + description = "voila!") + }) + @GET + @Path("/repeatablecallback") + public String simpleGet() { + return null; + } +} \ No newline at end of file diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/callback/SimpleCallbackWithOperationResource.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/callback/SimpleCallbackWithOperationResource.java new file mode 100644 index 0000000000..2c6e543362 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/callback/SimpleCallbackWithOperationResource.java @@ -0,0 +1,44 @@ +package io.swagger.v3.plugins.gradle.petstore.callback; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.callbacks.Callback; +import io.swagger.v3.oas.annotations.callbacks.Callbacks; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +public class SimpleCallbackWithOperationResource { + @Callbacks({ + @Callback( + name = "testCallback1", + operation = @Operation( + operationId = "getAllReviews", + summary = "get all the reviews", + method = "get", + responses = @ApiResponse( + responseCode = "200", + description = "successful operation", + content = @Content( + mediaType = "application/json", + schema = @Schema( + type = "integer", + format = "int32")))), + callbackUrlExpression = "http://www.url.com") + }) + @Operation( + summary = "Simple get operation", + operationId = "getWithNoParameters", + responses = { + @ApiResponse( + responseCode = "200", + description = "voila!") + }) + @GET + @Path("/simplecallback") + public String simpleGet() { + return null; + } +} diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/example/ExamplesResource.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/example/ExamplesResource.java new file mode 100644 index 0000000000..84ae58bfb7 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/example/ExamplesResource.java @@ -0,0 +1,69 @@ +package io.swagger.v3.plugins.gradle.petstore.example; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.enums.ParameterIn; +import io.swagger.v3.oas.annotations.enums.ParameterStyle; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.ExampleObject; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.parameters.RequestBody; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.plugins.gradle.resources.model.User; + +import javax.ws.rs.POST; +import javax.ws.rs.Path; + +/** + * Examples Resource Scenario + */ +public class ExamplesResource { + @Path("/example") + @POST + @Operation( + operationId = "subscribe", + description = "subscribes a client to updates relevant to the requestor's account", + parameters = { + @Parameter(in = ParameterIn.PATH, name = "subscriptionId", required = true, + schema = @Schema(name = "Schema", description = "Schema", example = "Subscription example"), + style = ParameterStyle.SIMPLE, example = "example", + examples = { + @ExampleObject(name = "subscriptionId_1", value = "12345", + summary = "Subscription number 12345", externalValue = "Subscription external value 1"), + @ExampleObject(name = "subscriptionId_2", value = "54321", + summary = "Subscription number 54321", externalValue = "Subscription external value 2") + }) + }, + responses = { + @ApiResponse( + description = "test description", + content = @Content( + mediaType = "*/*", + schema = @Schema( + type = "string", + format = "uuid", + description = "the generated UUID", + accessMode = Schema.AccessMode.READ_ONLY, + example = "Schema example" + ), + examples = { + @ExampleObject(name = "Default Response", value = "SubscriptionResponse", + summary = "Subscription Response Example", externalValue = "Subscription Response value 1") + } + )) + }) + public SubscriptionResponse subscribe(@RequestBody(description = "Created user object", required = true, + content = @Content( + schema = @Schema( + type = "string", + format = "uuid", + description = "the generated UUID", + accessMode = Schema.AccessMode.READ_ONLY, + example = "Schema example"), + examples = { + @ExampleObject(name = "Default Request", value = "SubscriptionRequest", + summary = "Subscription Request Example", externalValue = "Subscription Request Value") + })) User user) { + return null; + } +} \ No newline at end of file diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/example/SubscriptionResponse.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/example/SubscriptionResponse.java new file mode 100644 index 0000000000..7b8bc707a4 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/example/SubscriptionResponse.java @@ -0,0 +1,5 @@ +package io.swagger.v3.plugins.gradle.petstore.example; + +public class SubscriptionResponse { + public String subscriptionId; +} \ No newline at end of file diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/link/LinksResource.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/link/LinksResource.java new file mode 100644 index 0000000000..8450a64abf --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/link/LinksResource.java @@ -0,0 +1,44 @@ +package io.swagger.v3.plugins.gradle.petstore.link; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.links.Link; +import io.swagger.v3.oas.annotations.links.LinkParameter; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.QueryParam; + +/** + * Class with Links + */ +public class LinksResource { + @Path("/links") + @Operation(operationId = "getUserWithAddress", + responses = { + @ApiResponse(description = "test description", + content = @Content(mediaType = "*/*", schema = @Schema(ref = "#/components/schemas/User")), + links = { + @Link( + name = "address", + operationId = "getAddress", + parameters = @LinkParameter( + name = "userId", + expression = "$request.query.userId")), + @Link( + name = "user", + operationId = "getUser", + operationRef = "#/components/links/MyLink", + parameters = @LinkParameter( + name = "userId", + expression = "$request.query.userId")) + })} + ) + @GET + public String getUser(@QueryParam("userId")final String userId) { + return null; + } + +} diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/openapidefintion/OpenAPIDefinitionResource.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/openapidefintion/OpenAPIDefinitionResource.java new file mode 100644 index 0000000000..5ac0c573fa --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/openapidefintion/OpenAPIDefinitionResource.java @@ -0,0 +1,38 @@ +package io.swagger.v3.plugins.gradle.petstore.openapidefintion; + +import io.swagger.v3.oas.annotations.ExternalDocumentation; +import io.swagger.v3.oas.annotations.OpenAPIDefinition; +import io.swagger.v3.oas.annotations.info.Contact; +import io.swagger.v3.oas.annotations.info.Info; +import io.swagger.v3.oas.annotations.info.License; +import io.swagger.v3.oas.annotations.security.SecurityRequirement; +import io.swagger.v3.oas.annotations.servers.Server; +import io.swagger.v3.oas.annotations.servers.ServerVariable; +import io.swagger.v3.oas.annotations.tags.Tag; + +/** + * OpenAPIDefinition Example + */ +@OpenAPIDefinition( + info = @Info( + title = "Pet Resource Example", + version = "2.0", + description = "API Definition", + termsOfService = "Terms of service", + license = @License(name = "Apache 2.0", url = "http://foo.bar"), + contact = @Contact(url = "http://gigantic-server.com", name = "Fred", email = "Fred@gigagantic-server.com") + ), + tags = { + @Tag(name = "Tag 1", description = "desc 1", externalDocs = @ExternalDocumentation(description = "docs desc")), + @Tag(name = "Tag 2", description = "desc 2", externalDocs = @ExternalDocumentation(description = "docs desc 2")), + @Tag(name = "Tag 3") + }, + externalDocs = @ExternalDocumentation(description = "definition docs desc"), + security = { + @SecurityRequirement(name = "req 1", scopes = {"a", "b"}), + @SecurityRequirement(name = "req 2", scopes = {"b", "c"}) + }) +public class OpenAPIDefinitionResource { + public void foo() { + } +} diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/operation/AnnotatedSameNameOperationResource.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/operation/AnnotatedSameNameOperationResource.java new file mode 100644 index 0000000000..db73258ef0 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/operation/AnnotatedSameNameOperationResource.java @@ -0,0 +1,26 @@ +package io.swagger.v3.plugins.gradle.petstore.operation; + +import io.swagger.v3.oas.annotations.Operation; + +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +/** + * Resource With a Default Operation without Annotation + */ +public class AnnotatedSameNameOperationResource { + @Path("/sameOperationName") + @GET + @Operation(description = "Same Operation Name") + public String getUser() { + return new String(); + } + + @Path("//sameOperationName") + @DELETE + @Operation(description = "Same Operation Name Duplicated") + public String getUser(final String id) { + return new String(); + } +} diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/operation/ExternalDocumentationResource.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/operation/ExternalDocumentationResource.java new file mode 100644 index 0000000000..a351ac68bf --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/operation/ExternalDocumentationResource.java @@ -0,0 +1,30 @@ +package io.swagger.v3.plugins.gradle.petstore.operation; + +import io.swagger.v3.oas.annotations.ExternalDocumentation; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.plugins.gradle.resources.exception.NotFoundException; +import io.swagger.v3.plugins.gradle.resources.model.Pet; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.core.Response; + +/** + * Resource with Operations Examples + */ +public class ExternalDocumentationResource { + @GET + @Path("/{petId}") + @Operation(summary = "Find pet by ID", + description = "Returns a pet when 0 < ID <= 10. ID > 10 or non integers will simulate API error conditions", + operationId = "petId", + externalDocs = @ExternalDocumentation(description = "External in Operation", url = "http://url.me")) + @ExternalDocumentation(description = "External Annotation Documentation", url = "http://url.me") + public Response getPetById( + @Parameter(description = "ID of pet that needs to be fetched", required = true) + @PathParam("petId") Long petId) throws NotFoundException { + return Response.ok().entity(new Pet()).build(); + } +} diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/operation/FullyAnnotatedOperationResource.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/operation/FullyAnnotatedOperationResource.java new file mode 100644 index 0000000000..2955c6590e --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/operation/FullyAnnotatedOperationResource.java @@ -0,0 +1,38 @@ +package io.swagger.v3.plugins.gradle.petstore.operation; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.plugins.gradle.resources.exception.NotFoundException; +import io.swagger.v3.plugins.gradle.resources.model.Pet; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.core.Response; + +/** + * Resource with Operations Examples + */ +public class FullyAnnotatedOperationResource { + @GET + @Path("/fullyannotatedoperation/{petId}") + @Operation(summary = "Find pet by ID", + description = "Returns a pet when 0 < ID <= 10. ID > 10 or non integers will simulate API error conditions", + operationId = "petId", + responses = { + @ApiResponse( + description = "The pet", content = @Content( + schema = @Schema(implementation = Pet.class) + )), + @ApiResponse(responseCode = "400", description = "Invalid ID supplied"), + @ApiResponse(responseCode = "404", description = "Pet not found") + }) + public Response getPetById( + @Parameter(description = "ID of pet that needs to be fetched", required = true) + @PathParam("petId")final Long petId) throws NotFoundException { + return Response.ok().entity(new Pet()).build(); + } +} diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/operation/HiddenOperationResource.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/operation/HiddenOperationResource.java new file mode 100644 index 0000000000..730e83657d --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/operation/HiddenOperationResource.java @@ -0,0 +1,29 @@ +package io.swagger.v3.plugins.gradle.petstore.operation; + +import io.swagger.v3.oas.annotations.Hidden; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.plugins.gradle.resources.model.Pet; +import io.swagger.v3.plugins.gradle.resources.model.User; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +/** + * Resource With a Hidden Operation + */ +public class HiddenOperationResource { + @Path("/hiddenbyflag") + @GET + @Operation(operationId = "Pets", description = "Pets Example", hidden = true) + public Pet getPet() { + return new Pet(); + } + + @Path("/hiddenbyannotation") + @GET + @Operation(operationId = "Users", description = "Users Example") + @Hidden + public User getUser() { + return new User(); + } +} diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/operation/InterfaceResource.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/operation/InterfaceResource.java new file mode 100644 index 0000000000..aa5418ecc6 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/operation/InterfaceResource.java @@ -0,0 +1,22 @@ +package io.swagger.v3.plugins.gradle.petstore.operation; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.core.Response; + +/** + * Interface resource + */ +public interface InterfaceResource { + @GET + @Path("/interfaceoperation/{petId}") + @Operation(summary = "Find pet by ID Operation in Parent", + description = "Returns a pet in Parent" + ) + Response getPetById(@Parameter(description = "ID of pet that needs to be fetched", required = true) + @PathParam("petId") final Long petId); +} diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/operation/NotAnnotatedSameNameOperationResource.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/operation/NotAnnotatedSameNameOperationResource.java new file mode 100644 index 0000000000..e8021608de --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/operation/NotAnnotatedSameNameOperationResource.java @@ -0,0 +1,21 @@ +package io.swagger.v3.plugins.gradle.petstore.operation; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +/** + * Resource With a Default Operation without Annotation + */ +public class NotAnnotatedSameNameOperationResource { + @Path("/notannotatedoperation") + @GET + public String getUser() { + return new String(); + } + + @Path("/notannotatedoperationduplicated") + @GET + public String getUser(final String id) { + return new String(); + } +} diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/operation/OperationResource.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/operation/OperationResource.java new file mode 100644 index 0000000000..fdc5e495ca --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/operation/OperationResource.java @@ -0,0 +1,77 @@ +package io.swagger.v3.plugins.gradle.petstore.operation; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.plugins.gradle.resources.model.Pet; + +import javax.ws.rs.GET; +import javax.ws.rs.HEAD; +import javax.ws.rs.NotFoundException; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Response; + +/** + * Resource with Complete Operations Examples + */ +public class OperationResource implements InterfaceResource { + @Override + @Operation(summary = "Find pet by ID Operation in SubResource", + description = "Returns a pet in SubResource" + ) + public Response getPetById(final Long petId) { + return Response.ok().entity(new Pet()).build(); + } + + @GET + @Path("/operationsresource") + @Operation(summary = "Find pet by ID", + description = "combinatedfullyannotatedoperation/{petId}", + operationId = "petId", + responses = { + @ApiResponse( + description = "The pet", content = @Content( + schema = @Schema(implementation = Pet.class) + )), + @ApiResponse(responseCode = "400", description = "Invalid ID supplied"), + @ApiResponse(responseCode = "404", description = "Pet not found") + }) + public Response getPetById( + @Parameter(description = "ID of pet that needs to be fetched", required = true) + @QueryParam("petId") final Long petId, final String message) throws NotFoundException { + return Response.ok().entity(new Pet()).build(); + } + + @Path("/operationsresource") + @POST + public String getUser(final String id) { + return new String(); + } + + @Path("/operationsresource") + @PUT + @Operation(operationId = "combinated sameOperationName", + description = "combinatedsameOperationName") + public String getPerson() { + return new String(); + } + + @Path("/operationsresource") + @HEAD + @Operation(operationId = "combinatedsameOperationNameDuplicated", + description = "combinatedsameOperationNameDuplicated") + public String getPerson(final String id) { + return new String(); + } + + @Path("/operationsresource2") + @GET + public String getUser() { + return new String(); + } +} diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/operation/OperationWithoutAnnotationResource.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/operation/OperationWithoutAnnotationResource.java new file mode 100644 index 0000000000..7c4bf2cd02 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/operation/OperationWithoutAnnotationResource.java @@ -0,0 +1,15 @@ +package io.swagger.v3.plugins.gradle.petstore.operation; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +/** + * Resource With a Default Operation without Annotation + */ +public class OperationWithoutAnnotationResource { + @Path("/operationwithouannotation") + @GET + public String getUser() { + return new String(); + } +} diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/operation/ServerOperationResource.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/operation/ServerOperationResource.java new file mode 100644 index 0000000000..725fed837b --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/operation/ServerOperationResource.java @@ -0,0 +1,25 @@ +package io.swagger.v3.plugins.gradle.petstore.operation; + +import io.swagger.v3.oas.annotations.OpenAPIDefinition; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.servers.Server; +import io.swagger.v3.plugins.gradle.resources.model.Pet; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +/** + * Resource With a Hidden Operation + */ +public class ServerOperationResource { + @Path("/serversoperation") + @GET + @Operation(operationId = "Pets", description = "Pets Example", + servers = { + @Server(description = "server 2", url = "http://foo2") + } + ) + public Pet getPet() { + return new Pet(); + } +} diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/operation/SubResource.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/operation/SubResource.java new file mode 100644 index 0000000000..d56a767030 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/operation/SubResource.java @@ -0,0 +1,20 @@ +package io.swagger.v3.plugins.gradle.petstore.operation; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.plugins.gradle.resources.model.Pet; + +import javax.ws.rs.core.Response; + +/** + * SubResource + */ + +public class SubResource implements InterfaceResource { + @Override + @Operation(summary = "Find pet by ID Operation in SubResource", + description = "Returns a pet in SubResource" + ) + public Response getPetById(final Long petId) { + return Response.ok().entity(new Pet()).build(); + } +} diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/parameter/ArraySchemaResource.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/parameter/ArraySchemaResource.java new file mode 100644 index 0000000000..1ec07a8ce8 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/parameter/ArraySchemaResource.java @@ -0,0 +1,44 @@ +package io.swagger.v3.plugins.gradle.petstore.parameter; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.enums.Explode; +import io.swagger.v3.oas.annotations.enums.ParameterIn; +import io.swagger.v3.oas.annotations.media.ArraySchema; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; + +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.Path; + +public class ArraySchemaResource { + @Path("/arrayschema") + @POST + @Operation( + operationId = "subscribe", + description = "subscribes a client to updates relevant to the requestor's account, as " + + "identified by the input token. The supplied url will be used as the delivery address for response payloads", + parameters = { + @Parameter(in = ParameterIn.QUERY, name = "arrayParameter", required = true, explode = Explode.TRUE, + array = @ArraySchema(maxItems = 10, minItems = 1, + schema = @Schema(implementation = ParametersResource.SubscriptionResponse.class), + uniqueItems = true + ) + ), + }, + responses = { + @ApiResponse( + description = "test description", content = @Content( + mediaType = "*/*", + schema = + @Schema( + implementation = ParametersResource.SubscriptionResponse.class) + )) + }) + @Consumes({"application/json", "application/xml"}) + public ParametersResource.SubscriptionResponse subscribe() { + return null; + } +} diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/parameter/ComplexParameterResource.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/parameter/ComplexParameterResource.java new file mode 100644 index 0000000000..c2ca2f84aa --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/parameter/ComplexParameterResource.java @@ -0,0 +1,33 @@ +package io.swagger.v3.plugins.gradle.petstore.parameter; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.plugins.gradle.resources.model.User; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.QueryParam; + +/** + * Class with a multiple annotated. + */ +public class ComplexParameterResource { + + @Parameter(description = "Phone definied in Field") + private String phone; + + public ComplexParameterResource(@Parameter(description = "phone Param", name = "phone") final String phone) { + this.phone = phone; + } + + @GET + @Path("/complexparameter") + @Operation(operationId = "create User") + public User findUser(@Parameter(description = "idParam") @QueryParam("id") final String id, + final String name, @QueryParam("lastName") final String lastName, + @Parameter(description = "address", schema = @Schema(implementation = User.class)) + @QueryParam("address") final String address) { + return new User(); + } +} diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/parameter/ComplexParameterWithOperationResource.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/parameter/ComplexParameterWithOperationResource.java new file mode 100644 index 0000000000..d1c36874c9 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/parameter/ComplexParameterWithOperationResource.java @@ -0,0 +1,37 @@ +package io.swagger.v3.plugins.gradle.petstore.parameter; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.enums.ParameterIn; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.plugins.gradle.resources.model.User; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.QueryParam; + +/** + * Class with a multiple annotated. + */ +public class ComplexParameterWithOperationResource { + + @Parameter(description = "Phone definied in Field") + private String phone; + + public ComplexParameterWithOperationResource(@Parameter(description = "phone Param", name = "phone") final String phone) { + this.phone = phone; + } + + @GET + @Path("/complexparameter") + @Operation(operationId = "create User", + parameters = { + @Parameter(description = "Phone", name = "phone", in = ParameterIn.PATH) + }) + public User findUser(@Parameter(description = "idParam") @QueryParam("id") final String id, + final String name, @QueryParam("lastName") final String lastName, + @Parameter(description = "address", schema = @Schema(implementation = User.class)) + @QueryParam("address") final String address) { + return new User(); + } +} diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/parameter/MultipleNotAnnotatedParameter.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/parameter/MultipleNotAnnotatedParameter.java new file mode 100644 index 0000000000..7303048545 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/parameter/MultipleNotAnnotatedParameter.java @@ -0,0 +1,18 @@ +package io.swagger.v3.plugins.gradle.petstore.parameter; + +import io.swagger.v3.oas.annotations.Operation; + +import javax.ws.rs.POST; +import javax.ws.rs.Path; + +/** + * Class with a multiple not annotated parameter. + */ +public class MultipleNotAnnotatedParameter { + @POST + @Path("/multiplenoannotatedparameter") + @Operation(operationId = "create User") + public void createUser(final String id, final String name) { + + } +} diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/parameter/OpenAPIJaxRSAnnotatedParameter.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/parameter/OpenAPIJaxRSAnnotatedParameter.java new file mode 100644 index 0000000000..9832b462db --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/parameter/OpenAPIJaxRSAnnotatedParameter.java @@ -0,0 +1,21 @@ +package io.swagger.v3.plugins.gradle.petstore.parameter; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.plugins.gradle.resources.model.User; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.QueryParam; + +/** + * Class with a single parameter annotated with jaxrs and open api annotation. + */ +public class OpenAPIJaxRSAnnotatedParameter { + @GET + @Path("/openapijaxrsannotatedparameter") + @Operation(operationId = "create User") + public User findUser(@Parameter(description = "idParam") @QueryParam("id") final String id) { + return new User(); + } +} diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/parameter/OpenAPIWithContentJaxRSAnnotatedParameter.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/parameter/OpenAPIWithContentJaxRSAnnotatedParameter.java new file mode 100644 index 0000000000..4c4f1ddc32 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/parameter/OpenAPIWithContentJaxRSAnnotatedParameter.java @@ -0,0 +1,25 @@ +package io.swagger.v3.plugins.gradle.petstore.parameter; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.plugins.gradle.resources.model.User; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.QueryParam; + +/** + * Class with a single parameter annotated with jaxrs and open api annotation. + */ +public class OpenAPIWithContentJaxRSAnnotatedParameter { + @GET + @Path("/openapiwithcontentjaxrsannotatedparameter") + @Operation(operationId = "create User") + public User findUser(@Parameter(description = "idParam", content = + @Content(schema = @Schema(description = "Id Schema Definition", required = true, name = "id"))) + @QueryParam("id") final String id) { + return new User(); + } +} diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/parameter/OpenAPIWithImplementationJaxRSAnnotatedParameter.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/parameter/OpenAPIWithImplementationJaxRSAnnotatedParameter.java new file mode 100644 index 0000000000..df23a83a76 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/parameter/OpenAPIWithImplementationJaxRSAnnotatedParameter.java @@ -0,0 +1,23 @@ +package io.swagger.v3.plugins.gradle.petstore.parameter; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.plugins.gradle.resources.model.User; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.QueryParam; + +/** + * Class with a single parameter annotated with jaxrs and open api annotation. + */ +public class OpenAPIWithImplementationJaxRSAnnotatedParameter { + @GET + @Path("/openapiwithimplementationjaxrsannotatedparameter") + @Operation(operationId = "create User") + public User findUser(@Parameter(description = "idParam", schema = @Schema(implementation = User.class)) + @QueryParam("id") final String id) { + return new User(); + } +} diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/parameter/ParametersResource.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/parameter/ParametersResource.java new file mode 100644 index 0000000000..5a7c40cbd3 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/parameter/ParametersResource.java @@ -0,0 +1,87 @@ +package io.swagger.v3.plugins.gradle.petstore.parameter; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.enums.Explode; +import io.swagger.v3.oas.annotations.enums.ParameterIn; +import io.swagger.v3.oas.annotations.enums.ParameterStyle; +import io.swagger.v3.oas.annotations.media.ArraySchema; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; + +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.QueryParam; + +/** + * Resource with some Parameters examples + */ +public class ParametersResource { + @Path("/parameters") + @POST + @Operation( + operationId = "subscribe", + description = "subscribes a client to updates relevant to the requestor's account, as " + + "identified by the input token. The supplied url will be used as the delivery address for response payloads", + parameters = { + @Parameter(in = ParameterIn.PATH, name = "subscriptionId", required = true, + schema = @Schema(implementation = RepeatableParametersResource.SubscriptionResponse.class), style = ParameterStyle.SIMPLE), + @Parameter(in = ParameterIn.QUERY, name = "formId", required = true, + example = "Example"), + @Parameter(in = ParameterIn.QUERY, name = "explodeFalse", required = true, explode = Explode.FALSE, + schema = @Schema(implementation = SubscriptionResponse.class)), + @Parameter(in = ParameterIn.QUERY, name = "explodeTrue", required = true, explode = Explode.TRUE, + schema = @Schema(implementation = SubscriptionResponse.class)), + @Parameter(in = ParameterIn.QUERY, name = "explodeAvoiding", required = true, explode = Explode.TRUE, + schema = @Schema( + type = "int", + format = "id", + description = "the generated id", + accessMode = Schema.AccessMode.READ_ONLY + )), + @Parameter(in = ParameterIn.QUERY, name = "arrayParameter", required = true, explode = Explode.TRUE, + array = @ArraySchema(maxItems = 10, minItems = 1, + schema = @Schema(implementation = SubscriptionResponse.class), + uniqueItems = true + ) + , + schema = @Schema( + type = "int", + format = "id", + description = "the generated id", + accessMode = Schema.AccessMode.READ_ONLY), + content = @Content(schema = @Schema(type = "number", + description = "the generated id", + accessMode = Schema.AccessMode.READ_ONLY)) + ), + @Parameter(in = ParameterIn.QUERY, name = "arrayParameterImplementation", required = true, explode = Explode.TRUE, + array = @ArraySchema(maxItems = 10, minItems = 1, + schema = @Schema(implementation = SubscriptionResponse.class), + uniqueItems = true + ) + ), + @Parameter(in = ParameterIn.QUERY, name = "arrayParameterImplementation2", required = true, explode = Explode.TRUE, + schema = @Schema(implementation = SubscriptionResponse.class)) + + }, + responses = { + @ApiResponse( + description = "test description", content = @Content( + mediaType = "*/*", + schema = + @Schema( + implementation = SubscriptionResponse.class) + )) + }) + @Consumes({"application/json", "application/xml"}) + public SubscriptionResponse subscribe(@Parameter(description = "idParam") + @QueryParam("id") final String id) { + return null; + } + + static class SubscriptionResponse { + public String subscriptionId; + } +} diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/parameter/RepeatableParametersResource.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/parameter/RepeatableParametersResource.java new file mode 100644 index 0000000000..2626f0c6ac --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/parameter/RepeatableParametersResource.java @@ -0,0 +1,80 @@ +package io.swagger.v3.plugins.gradle.petstore.parameter; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.enums.Explode; +import io.swagger.v3.oas.annotations.enums.ParameterIn; +import io.swagger.v3.oas.annotations.enums.ParameterStyle; +import io.swagger.v3.oas.annotations.media.ArraySchema; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; + +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.Path; + +public class RepeatableParametersResource { + @Path("/repeatableparameter") + @POST + @Parameter(in = ParameterIn.PATH, name = "subscriptionId", required = true, + schema = @Schema(implementation = ParametersResource.SubscriptionResponse.class), style = ParameterStyle.SIMPLE) + @Parameter(in = ParameterIn.QUERY, name = "formId", required = true, + example = "Example") + @Parameter(in = ParameterIn.QUERY, name = "explodeFalse", required = true, explode = Explode.FALSE, + schema = @Schema(implementation = ParametersResource.SubscriptionResponse.class)) + @Parameter(in = ParameterIn.QUERY, name = "explodeTrue", required = true, explode = Explode.TRUE, + schema = @Schema(implementation = ParametersResource.SubscriptionResponse.class)) + @Parameter(in = ParameterIn.QUERY, name = "explodeAvoiding", required = true, explode = Explode.TRUE, + schema = @Schema( + type = "int", + format = "id", + description = "the generated id", + accessMode = Schema.AccessMode.READ_ONLY + )) + @Parameter(in = ParameterIn.QUERY, name = "arrayParameter", required = true, explode = Explode.TRUE, + array = @ArraySchema(maxItems = 10, minItems = 1, + schema = @Schema(implementation = ParametersResource.SubscriptionResponse.class), + uniqueItems = true + ) + , + schema = @Schema( + type = "int", + format = "id", + description = "the generated id", + accessMode = Schema.AccessMode.READ_ONLY), + content = @Content(schema = @Schema(type = "number", + description = "the generated id", + accessMode = Schema.AccessMode.READ_ONLY)) + ) + @Parameter(in = ParameterIn.QUERY, name = "arrayParameterImplementation", required = true, explode = Explode.TRUE, + array = @ArraySchema(maxItems = 10, minItems = 1, + schema = @Schema(implementation = ParametersResource.SubscriptionResponse.class), + uniqueItems = true + ) + ) + @Parameter(in = ParameterIn.QUERY, name = "arrayParameterImplementation2", required = true, explode = Explode.TRUE, + schema = @Schema(implementation = ParametersResource.SubscriptionResponse.class)) + @Operation( + operationId = "subscribe", + description = "subscribes a client to updates relevant to the requestor's account, as " + + "identified by the input token. The supplied url will be used as the delivery address for response payloads", + responses = { + @ApiResponse( + description = "test description", content = @Content( + mediaType = "*/*", + schema = + @Schema( + implementation = ParametersResource.SubscriptionResponse.class) + )) + }) + @Consumes({"application/json", "application/xml"}) + public ParametersResource.SubscriptionResponse subscribe() { + return null; + } + + static class SubscriptionResponse { + public String subscriptionId; + } +} + diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/parameter/SingleJaxRSAnnotatedParameter.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/parameter/SingleJaxRSAnnotatedParameter.java new file mode 100644 index 0000000000..29788cd9eb --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/parameter/SingleJaxRSAnnotatedParameter.java @@ -0,0 +1,20 @@ +package io.swagger.v3.plugins.gradle.petstore.parameter; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.plugins.gradle.resources.model.User; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.QueryParam; + +/** + * Class with a single parameter annotated with jaxrs. + */ +public class SingleJaxRSAnnotatedParameter { + @GET + @Path("/singlejaxrsannotatedparameter") + @Operation(operationId = "create User") + public User findUser(@QueryParam("id") final String id) { + return new User(); + } +} diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/parameter/SingleNotAnnotatedParameter.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/parameter/SingleNotAnnotatedParameter.java new file mode 100644 index 0000000000..a322111708 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/parameter/SingleNotAnnotatedParameter.java @@ -0,0 +1,19 @@ +package io.swagger.v3.plugins.gradle.petstore.parameter; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.plugins.gradle.resources.model.User; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +/** + * Class with a single not annotated parameter. + */ +public class SingleNotAnnotatedParameter { + @GET + @Path("/singlenoannotatedparameter") + @Operation(operationId = "create User") + public User findUser(final String id) { + return new User(); + } +} diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/requestbody/RequestBodyMethodPriorityResource.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/requestbody/RequestBodyMethodPriorityResource.java new file mode 100644 index 0000000000..6e9ee3715b --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/requestbody/RequestBodyMethodPriorityResource.java @@ -0,0 +1,28 @@ +package io.swagger.v3.plugins.gradle.petstore.requestbody; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.parameters.RequestBody; +import io.swagger.v3.plugins.gradle.resources.model.User; + +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.core.Response; + +/** + * Resource with RequestBody inside Operation and another in Method + */ +public class RequestBodyMethodPriorityResource { + @POST + @Path("/requestbodymethodpriority") + @Operation(summary = "Create user", + description = "This can only be done by the logged in user.", + requestBody = @RequestBody(description = "Inside Operation")) + @RequestBody(description = "Created user object on Method", required = true, + content = @Content( + schema = @Schema(implementation = User.class))) + public Response methodWithRequestBodyAndTwoParameters(final User user) { + return Response.ok().entity("").build(); + } +} diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/requestbody/RequestBodyParameterPriorityResource.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/requestbody/RequestBodyParameterPriorityResource.java new file mode 100644 index 0000000000..f76a4781ae --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/requestbody/RequestBodyParameterPriorityResource.java @@ -0,0 +1,29 @@ +package io.swagger.v3.plugins.gradle.petstore.requestbody; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.parameters.RequestBody; +import io.swagger.v3.plugins.gradle.resources.model.User; + +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.core.Response; + +/** + * Resource with RequestBody inside Operation and another in Method + */ +public class RequestBodyParameterPriorityResource { + @POST + @Path("/requestbodyparameterpriority") + @Operation(summary = "Create user", + description = "This can only be done by the logged in user.", + requestBody = @RequestBody(description = "Inside Operation")) + @RequestBody(description = "On method") + public Response methodWithRequestBodyAndTwoParameters( + @RequestBody(description = "Created user object inside Parameter", required = true, + content = @Content( + schema = @Schema(implementation = User.class)))final User user) { + return Response.ok().entity("").build(); + } +} diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/requestbody/RequestBodyResource.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/requestbody/RequestBodyResource.java new file mode 100644 index 0000000000..b2e310e0cc --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/requestbody/RequestBodyResource.java @@ -0,0 +1,113 @@ +package io.swagger.v3.plugins.gradle.petstore.requestbody; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.parameters.RequestBody; +import io.swagger.v3.plugins.gradle.resources.model.Pet; +import io.swagger.v3.plugins.gradle.resources.model.User; + +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Response; + +/** + * Resource with RequestBody examples + */ +public class RequestBodyResource { + @GET + @Path("/methodWithRequestBodyWithoutContent") + @Operation(summary = "Create user", + description = "This can only be done by the logged in user.") + public Response methodWithRequestBodyWithoutContent( + @RequestBody(description = "Created user object", required = true) final User user) { + return Response.ok().entity("").build(); + } + + @GET + @Path("/methodWithRequestBodyWithoutContentWithoutImplementation") + @Operation(summary = "Create user", + description = "This can only be done by the logged in user.") + public Response methodWithRequestBodyWithoutContentWithoutImplementation( + @RequestBody(description = "Created user object", required = true, + content = @Content( + schema = @Schema(name = "User", description = "User description", + example = "User Description", required = true))) final User user) { + return Response.ok().entity("").build(); + } + + @POST + @Path("/methodWithRequestBodyAndTwoParameters") + @Operation(summary = "Create user", + description = "This can only be done by the logged in user.") + public Response methodWithRequestBodyAndTwoParameters( + @RequestBody(description = "Created user object", required = true, + content = @Content( + schema = @Schema(implementation = User.class))) final User user, + @QueryParam("name") final String name, @QueryParam("code") final String code) { + return Response.ok().entity("").build(); + } + + @PUT + @Path("/methodWithRequestBodyWithoutAnnotation") + @Operation(summary = "Modify user", + description = "Modifying user.") + public Response methodWithRequestBodyWithoutAnnotation( + final User user) { + return Response.ok().entity("").build(); + } + + @DELETE + @Path("/methodWithoutRequestBodyAndTwoParameters") + @Operation(summary = "Delete user", + description = "This can only be done by the logged in user.") + public Response methodWithoutRequestBodyAndTwoParameters( + @QueryParam("name") final String name, @QueryParam("code") final String code) { + return Response.ok().entity("").build(); + } + + @PUT + @Path("/methodWithRequestBodyWithoutAnnotationAndTwoConsumes") + @Operation(summary = "Modify pet", + description = "Modifying pet.") + @Consumes({"application/json", "application/xml"}) + public Response methodWithRequestBodyWithoutAnnotationAndTwoConsumes( + final User user) { + return Response.ok().entity("").build(); + } + + @POST + @Path("/methodWithTwoRequestBodyWithoutAnnotationAndTwoConsumes") + @Operation(summary = "Create pet", + description = "Creating pet.") + @Consumes({"application/json", "application/xml"}) + public Response methodWithTwoRequestBodyWithoutAnnotationAndTwoConsumes( + final Pet pet, final User user) { + return Response.ok().entity("").build(); + } + + @POST + @Path("/methodWithTwoRequestBodyWithAnnotationAndTwoConsumes") + @Operation(summary = "Create pet", + description = "Creating pet.") + @Consumes({"application/json", "application/xml"}) + public Response methodWithTwoRequestBodyWithAnnotationAndTwoConsumes( + final @RequestBody(description = "Request Body Pet") Pet pet, + @RequestBody(description = "Request Body User") final User user) { + return Response.ok().entity("").build(); + } + + @DELETE + @Path("/methodWithOneSimpleRequestBody") + @Operation(summary = "Delete pet", + description = "Deleting pet.") + @Consumes({"application/json", "application/xml"}) + public Response methodWithOneSimpleRequestBody(final int id) { + return Response.ok().entity("").build(); + } +} diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/responses/ComplexResponseResource.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/responses/ComplexResponseResource.java new file mode 100644 index 0000000000..db25ec92da --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/responses/ComplexResponseResource.java @@ -0,0 +1,34 @@ +package io.swagger.v3.plugins.gradle.petstore.responses; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.plugins.gradle.resources.exception.NotFoundException; +import io.swagger.v3.plugins.gradle.resources.model.Pet; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +/** + * Resource with some responses + */ +public class ComplexResponseResource { + @GET + @Path("/complexresponse") + @Operation(summary = "Find pets", + description = "Returns the Pets", + responses = { + @ApiResponse(description = "Response inside Operation", responseCode = "200", + content = @Content(schema = + @Schema(implementation = Pet.class))), + @ApiResponse(description = "Default Pet", + content = @Content(schema = + @Schema(name = "Default Pet", description = "Default Pet", + required = true, example = "New Pet"))) + }) + @ApiResponse(responseCode = "404", description = "Couldn't find pet") + public Pet getPets() throws NotFoundException { + return new Pet(); + } +} diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/responses/ImplementationResponseResource.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/responses/ImplementationResponseResource.java new file mode 100644 index 0000000000..88c163f348 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/responses/ImplementationResponseResource.java @@ -0,0 +1,71 @@ +package io.swagger.v3.plugins.gradle.petstore.responses; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +/** + * Resource with a Response at Method Level + */ +public class ImplementationResponseResource { + @GET + @Path("/implementationresponse") + @Operation( + summary = "Simple get operation", + description = "Defines a simple get operation with no inputs and a complex output object", + operationId = "getWithPayloadResponse", + deprecated = true, + responses = { + @ApiResponse( + responseCode = "200", + description = "voila!", + content = { + @Content( + mediaType = "application/json", + schema = + @Schema( + implementation = SampleResponseSchema.class) + ), + @Content( + mediaType = "application/json", + schema = + @Schema( + implementation = SecondSampleResponseSchema.class) + ) + } + + ), + @ApiResponse( + responseCode = "400", + description = "boo", + content = @Content( + mediaType = "*/*", + schema = + @Schema(implementation = GenericError.class) + ) + ) + } + ) + + public void getResponses() { + } + + static class SampleResponseSchema { + @Schema(description = "the user id") + private String id; + } + + static class SecondSampleResponseSchema { + @Schema(description = "the user id") + private String id; + } + + static class GenericError { + private int code; + private String message; + } +} diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/responses/MethodResponseResource.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/responses/MethodResponseResource.java new file mode 100644 index 0000000000..45eab02a09 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/responses/MethodResponseResource.java @@ -0,0 +1,24 @@ +package io.swagger.v3.plugins.gradle.petstore.responses; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.plugins.gradle.resources.exception.NotFoundException; +import io.swagger.v3.plugins.gradle.resources.model.Pet; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.core.Response; + +/** + * Resource with a Response at Method Level + */ +public class MethodResponseResource { + @GET + @Path("/responseinmethod") + @Operation(summary = "Find pets", + description = "Returns the Pets") + @ApiResponse(responseCode = "200", description = "Status OK") + public Response getPets() throws NotFoundException { + return Response.ok().entity(new Pet()).build(); + } +} diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/responses/NoImplementationResponseResource.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/responses/NoImplementationResponseResource.java new file mode 100644 index 0000000000..6659f6babe --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/responses/NoImplementationResponseResource.java @@ -0,0 +1,66 @@ +package io.swagger.v3.plugins.gradle.petstore.responses; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.links.Link; +import io.swagger.v3.oas.annotations.links.LinkParameter; +import io.swagger.v3.oas.annotations.responses.ApiResponse; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.QueryParam; + +/** + * Resource with a Response at Method Level + */ +public class NoImplementationResponseResource { + @Path("/noimplementationresponseresource") + @Operation(operationId = "getUser", + responses = { + @ApiResponse(description = "test description", responseCode = "400", + links = { + @Link( + name = "user", + operationId = "getUser", + operationRef = "#/components/links/MyLink", + parameters = @LinkParameter( + name = "userId", + expression = "$request.query.userId")) + }), + @ApiResponse(description = "200 description", responseCode = "200", + links = { + @Link( + name = "pet", + operationId = "getUser", + operationRef = "#/components/links/MyLink", + parameters = @LinkParameter( + name = "userId", + expression = "$request.query.userId")) + }) + } + ) + @GET + public User getUser(@QueryParam("userId") final String userId) { + return null; + } + + static class User { + private String id; + private String username; + + public String getId() { + return id; + } + + public void setId(final String id) { + this.id = id; + } + + public String getUsername() { + return username; + } + + public void setUsername(final String username) { + this.username = username; + } + } +} diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/responses/NoResponseResource.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/responses/NoResponseResource.java new file mode 100644 index 0000000000..432b452a53 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/responses/NoResponseResource.java @@ -0,0 +1,21 @@ +package io.swagger.v3.plugins.gradle.petstore.responses; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.plugins.gradle.resources.exception.NotFoundException; +import io.swagger.v3.plugins.gradle.resources.model.User; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +/** + * Resource with a Response at Method Level + */ +public class NoResponseResource { + @GET + @Path("/noresponse") + @Operation(summary = "Find pets", + description = "Returns the Pets") + public User getPets() throws NotFoundException { + return new User(); + } +} diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/responses/OperationResponseResource.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/responses/OperationResponseResource.java new file mode 100644 index 0000000000..38cbbc426e --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/responses/OperationResponseResource.java @@ -0,0 +1,25 @@ +package io.swagger.v3.plugins.gradle.petstore.responses; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.plugins.gradle.resources.exception.NotFoundException; +import io.swagger.v3.plugins.gradle.resources.model.User; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.core.Response; + +/** + * Resource with the response in the Operation Annotation + */ +public class OperationResponseResource { + @GET + @Path("/responseinoperation") + @Operation(summary = "Find Users", + description = "Returns the Users", + responses = {@ApiResponse(responseCode = "200", description = "Status OK")}) + public Response getUsers() throws NotFoundException { + return Response.ok().entity(new User()).build(); + } + +} diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/responses/PriorityResponseResource.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/responses/PriorityResponseResource.java new file mode 100644 index 0000000000..f14c1ff364 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/responses/PriorityResponseResource.java @@ -0,0 +1,25 @@ +package io.swagger.v3.plugins.gradle.petstore.responses; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.plugins.gradle.resources.exception.NotFoundException; +import io.swagger.v3.plugins.gradle.resources.model.Pet; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.core.Response; + +/** + * Resource with a Response at Method Level and Operation Level. + */ +public class PriorityResponseResource { + @GET + @Path("/priorityresponses") + @Operation(summary = "Find pets", + description = "Returns the Pets", + responses = {@ApiResponse(responseCode = "200", description = "Inside Operation Response")}) + @ApiResponse(responseCode = "200", description = "Inside Method Operation") + public Response getPets() throws NotFoundException { + return Response.ok().entity(new Pet()).build(); + } +} diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/security/SecurityResource.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/security/SecurityResource.java new file mode 100644 index 0000000000..b24bf3db65 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/security/SecurityResource.java @@ -0,0 +1,61 @@ +package io.swagger.v3.plugins.gradle.petstore.security; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.enums.SecuritySchemeIn; +import io.swagger.v3.oas.annotations.enums.SecuritySchemeType; +import io.swagger.v3.oas.annotations.security.OAuthFlow; +import io.swagger.v3.oas.annotations.security.OAuthFlows; +import io.swagger.v3.oas.annotations.security.OAuthScope; +import io.swagger.v3.oas.annotations.security.SecurityRequirement; +import io.swagger.v3.oas.annotations.security.SecurityScheme; + +import javax.ws.rs.GET; +import javax.ws.rs.PATCH; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; + +@SecurityScheme(name = "myOauth2Security", + type = SecuritySchemeType.OAUTH2, + in = SecuritySchemeIn.HEADER, + description = "myOauthSecurity Description", + flows = @OAuthFlows(implicit = @OAuthFlow(authorizationUrl = "http://x.com", + scopes = @OAuthScope( + name = "write:pets", + description = "modify pets in your account")) + ) +) +@SecurityRequirement(name = "security_key", + scopes = {"write:pets", "read:pets"} +) +@SecurityRequirement(name = "myOauth2Security", + scopes = {"write:pets"} +) +@Path("/security") +public class SecurityResource { + @GET + @Operation(operationId = "Operation Id", + description = "description") + @SecurityRequirement(name = "security_key", + scopes = {"write:pets", "read:pets"} + ) + public void getSecurity() { + } + + @PATCH + @Operation(operationId = "Operation Id 2", + description = "description 2") + @SecurityRequirement(name = "security_key2", + scopes = {"write:pets", "read:pets"} + ) + public void getSecurity2() { + } + + @PUT + @Operation(operationId = "Operation Id 3", + description = "description 3", security = + @SecurityRequirement(name = "security_key3", + scopes = {"write:pets", "read:pets"} + )) + public void setSecurity(String security) { + } +} diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/tags/CompleteTagResource.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/tags/CompleteTagResource.java new file mode 100644 index 0000000000..a643d76982 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/tags/CompleteTagResource.java @@ -0,0 +1,31 @@ +package io.swagger.v3.plugins.gradle.petstore.tags; + +import io.swagger.v3.oas.annotations.ExternalDocumentation; +import io.swagger.v3.oas.annotations.OpenAPIDefinition; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.core.Response; + +@OpenAPIDefinition(tags = { + @Tag(name = "Definition First Tag"), + @Tag(name = "Definition Second Tag full", description = "desc definition") +}) +@Tag(name = "Second Tag") +@Tag(name = "Fourth Tag Full", description = "desc class", externalDocs = @ExternalDocumentation(description = "docs desc class")) +@Tag(name = "Fifth Tag Full", description = "desc class", externalDocs = @ExternalDocumentation(description = "docs desc class")) +@Tag(name = "Sixth Tag") +public class CompleteTagResource { + + @GET + @Path("/completetags") + @Operation(tags = {"Example Tag", "Second Tag"}) + @Tag(name = "Third Tag") + @Tag(name = "Second Tag") + @Tag(name = "Fourth Tag Full", description = "desc", externalDocs = @ExternalDocumentation(description = "docs desc")) + public Response getTags() { + return Response.ok().entity("ok").build(); + } +} diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/tags/TagClassResource.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/tags/TagClassResource.java new file mode 100644 index 0000000000..96e3611d62 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/tags/TagClassResource.java @@ -0,0 +1,14 @@ +package io.swagger.v3.plugins.gradle.petstore.tags; + +import io.swagger.v3.oas.annotations.ExternalDocumentation; +import io.swagger.v3.oas.annotations.tags.Tag; + +/** + * Class with Tag Annotations at Class level + */ +@Tag(name = "Second Tag") +@Tag(name = "Fourth Tag Full", description = "desc class", externalDocs = @ExternalDocumentation(description = "docs desc class")) +@Tag(name = "Fifth Tag Full", description = "desc class", externalDocs = @ExternalDocumentation(description = "docs desc class")) +@Tag(name = "Sixth Tag") +public class TagClassResource { +} diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/tags/TagMethodResource.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/tags/TagMethodResource.java new file mode 100644 index 0000000000..c4c65f146c --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/tags/TagMethodResource.java @@ -0,0 +1,19 @@ +package io.swagger.v3.plugins.gradle.petstore.tags; + +import io.swagger.v3.oas.annotations.ExternalDocumentation; +import io.swagger.v3.oas.annotations.tags.Tag; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.core.Response; + +public class TagMethodResource { + @GET + @Path("/tagsinmethod") + @Tag(name = "Third Tag") + @Tag(name = "Second Tag") + @Tag(name = "Fourth Tag Full", description = "desc", externalDocs = @ExternalDocumentation(description = "docs desc")) + public Response getTags() { + return Response.ok().entity("ok").build(); + } +} diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/tags/TagOpenAPIDefinitionResource.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/tags/TagOpenAPIDefinitionResource.java new file mode 100644 index 0000000000..0362a7fba5 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/tags/TagOpenAPIDefinitionResource.java @@ -0,0 +1,14 @@ +package io.swagger.v3.plugins.gradle.petstore.tags; + +import io.swagger.v3.oas.annotations.OpenAPIDefinition; +import io.swagger.v3.oas.annotations.tags.Tag; + +/** + * Tag in the OpenAPIDefinition annotation + */ +@OpenAPIDefinition(tags = { + @Tag(name = "Definition First Tag"), + @Tag(name = "Definition Second Tag full", description = "desc definition") +}) +public class TagOpenAPIDefinitionResource { +} diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/tags/TagOperationResource.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/tags/TagOperationResource.java new file mode 100644 index 0000000000..58d67f1b1c --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/petstore/tags/TagOperationResource.java @@ -0,0 +1,20 @@ +package io.swagger.v3.plugins.gradle.petstore.tags; + +import io.swagger.v3.oas.annotations.Operation; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.core.Response; + +/** + * Resource with a Tag at Operation Level + */ +public class TagOperationResource { + + @GET + @Path("/tagoperation") + @Operation(tags = {"Example Tag", "Second Tag"}) + public Response getTags() { + return Response.ok().entity("ok").build(); + } +} diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/resources/QueryResultBean.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/resources/QueryResultBean.java new file mode 100644 index 0000000000..4ce4ed7528 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/resources/QueryResultBean.java @@ -0,0 +1,43 @@ +/** + * Copyright 2016 SmartBear Software + *

+ * 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.swagger.v3.plugins.gradle.resources; + +import javax.ws.rs.QueryParam; + +public class QueryResultBean { + @QueryParam("skip") + private Integer skip; + + @QueryParam("limit") + private Integer limit; + + public Integer getSkip() { + return skip; + } + + public void setSkip(Integer skip) { + this.skip = skip; + } + + public Integer getLimit() { + return limit; + } + + public void setLimit(Integer limit) { + this.limit = limit; + } +} diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/resources/data/PetData.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/resources/data/PetData.java new file mode 100644 index 0000000000..e221796180 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/resources/data/PetData.java @@ -0,0 +1,151 @@ +/** + * Copyright 2016 SmartBear Software + *

+ * 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.swagger.v3.plugins.gradle.resources.data; + +import io.swagger.v3.plugins.gradle.resources.model.Category; +import io.swagger.v3.plugins.gradle.resources.model.Pet; +import io.swagger.v3.plugins.gradle.resources.model.Tag; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +public class PetData { + static List pets = new ArrayList(); + static List categories = new ArrayList(); + + static { + categories.add(createCategory(1, "Dogs")); + categories.add(createCategory(2, "Cats")); + categories.add(createCategory(3, "Rabbits")); + categories.add(createCategory(4, "Lions")); + + pets.add(createPet(1, categories.get(1), "Cat 1", new String[]{ + "url1", "url2"}, new String[]{"tag1", "tag2"}, "available")); + pets.add(createPet(2, categories.get(1), "Cat 2", new String[]{ + "url1", "url2"}, new String[]{"tag2", "tag3"}, "available")); + pets.add(createPet(3, categories.get(1), "Cat 3", new String[]{ + "url1", "url2"}, new String[]{"tag3", "tag4"}, "pending")); + + pets.add(createPet(4, categories.get(0), "Dog 1", new String[]{ + "url1", "url2"}, new String[]{"tag1", "tag2"}, "available")); + pets.add(createPet(5, categories.get(0), "Dog 2", new String[]{ + "url1", "url2"}, new String[]{"tag2", "tag3"}, "sold")); + pets.add(createPet(6, categories.get(0), "Dog 3", new String[]{ + "url1", "url2"}, new String[]{"tag3", "tag4"}, "pending")); + + pets.add(createPet(7, categories.get(3), "Lion 1", new String[]{ + "url1", "url2"}, new String[]{"tag1", "tag2"}, "available")); + pets.add(createPet(8, categories.get(3), "Lion 2", new String[]{ + "url1", "url2"}, new String[]{"tag2", "tag3"}, "available")); + pets.add(createPet(9, categories.get(3), "Lion 3", new String[]{ + "url1", "url2"}, new String[]{"tag3", "tag4"}, "available")); + + pets.add(createPet(10, categories.get(2), "Rabbit 1", new String[]{ + "url1", "url2"}, new String[]{"tag3", "tag4"}, "available")); + } + + public Pet getPetById(long petId) { + for (Pet pet : pets) { + if (pet.getId() == petId) { + return pet; + } + } + return null; + } + + public List findPetByStatus(String status) { + String[] statues = status.split(","); + List result = new ArrayList(); + for (Pet pet : pets) { + for (String s : statues) { + if (s.equals(pet.getStatus())) { + result.add(pet); + } + } + } + return result; + } + + public List findPetByCategory(Category category) { + return pets.stream().filter(pet -> category.equals(pet.getCategory())).collect(Collectors.toList()); + } + + public List findPetByTags(String tags) { + String[] tagList = tags.split(","); + List result = new ArrayList(); + for (Pet pet : pets) { + if (null != pet.getTags()) { + for (Tag tag : pet.getTags()) { + for (String tagListString : tagList) { + if (tagListString.equals(tag.getName())) { + result.add(pet); + } + } + } + } + } + return result; + } + + public void addPet(Pet pet) { + if (pets.size() > 0) { + for (int i = pets.size() - 1; i >= 0; i--) { + if (pets.get(i).getId() == pet.getId()) { + pets.remove(i); + } + } + } + pets.add(pet); + } + + static Pet createPet(long id, Category cat, String name, String[] urls, + String[] tags, String status) { + Pet pet = new Pet(); + pet.setId(id); + pet.setCategory(cat); + pet.setName(name); + if (null != urls) { + List urlObjs = new ArrayList(); + for (String urlString : urls) { + urlObjs.add(urlString); + } + pet.setPhotoUrls(urlObjs); + } + List tagObjs = new ArrayList(); + int i = 0; + if (null != tags) { + for (String tagString : tags) { + i = i + 1; + Tag tag = new Tag(); + tag.setId(i); + tag.setName(tagString); + tagObjs.add(tag); + } + } + pet.setTags(tagObjs); + pet.setStatus(status); + return pet; + } + + static Category createCategory(long id, String name) { + Category category = new Category(); + category.setId(id); + category.setName(name); + return category; + } +} \ No newline at end of file diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/resources/data/UserData.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/resources/data/UserData.java new file mode 100644 index 0000000000..a23afc1ded --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/resources/data/UserData.java @@ -0,0 +1,98 @@ +/** + * Copyright 2016 SmartBear Software + *

+ * 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.swagger.v3.plugins.gradle.resources.data; + +import io.swagger.v3.plugins.gradle.resources.model.User; + +import java.util.ArrayList; +import java.util.List; + +public class UserData { + static List users = new ArrayList(); + + static { + users.add(createUser(1, "user1", "first name 1", "last name 1", + "email1@test.com", "123-456-7890", 1)); + users.add(createUser(2, "user2", "first name 2", "last name 2", + "email2@test.com", "123-456-7890", 2)); + users.add(createUser(3, "user3", "first name 3", "last name 3", + "email3@test.com", "123-456-7890", 3)); + users.add(createUser(4, "user4", "first name 4", "last name 4", + "email4@test.com", "123-456-7890", 1)); + users.add(createUser(5, "user5", "first name 5", "last name 5", + "email5@test.com", "123-456-7890", 2)); + users.add(createUser(6, "user6", "first name 6", "last name 6", + "email6@test.com", "123-456-7890", 3)); + users.add(createUser(7, "user7", "first name 7", "last name 7", + "email7@test.com", "123-456-7890", 1)); + users.add(createUser(8, "user8", "first name 8", "last name 8", + "email8@test.com", "123-456-7890", 2)); + users.add(createUser(9, "user9", "first name 9", "last name 9", + "email9@test.com", "123-456-7890", 3)); + users.add(createUser(10, "user10", "first name 10", "last name 10", + "email10@test.com", "123-456-7890", 1)); + users.add(createUser(11, "user?10", "first name ?10", "last name ?10", + "email101@test.com", "123-456-7890", 1)); + + } + + public User findUserByName(String username) { + for (User user : users) { + if (user.getUsername().equals(username)) { + return user; + } + } + return null; + } + + public void addUser(User user) { + if (users.size() > 0) { + for (int i = users.size() - 1; i >= 0; i--) { + if (users.get(i).getUsername().equals(user.getUsername())) { + users.remove(i); + } + } + } + users.add(user); + } + + public boolean removeUser(String username) { + if (users.size() > 0) { + for (int i = users.size() - 1; i >= 0; i--) { + if (users.get(i).getUsername().equals(username)) { + users.remove(i); + return true; + } + } + } + return false; + } + + private static User createUser(long id, String username, String firstName, + String lastName, String email, String phone, int userStatus) { + User user = new User(); + user.setId(id); + user.setUsername(username); + user.setFirstName(firstName); + user.setLastName(lastName); + user.setEmail(email); + user.setPassword("XXXXXXXXXXX"); + user.setPhone(phone); + user.setUserStatus(userStatus); + return user; + } +} \ No newline at end of file diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/resources/exception/ApiException.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/resources/exception/ApiException.java new file mode 100644 index 0000000000..5fd6be63d7 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/resources/exception/ApiException.java @@ -0,0 +1,26 @@ +/** + * Copyright 2016 SmartBear Software + *

+ * 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.swagger.v3.plugins.gradle.resources.exception; + +public class ApiException extends Exception { + private int code; + + public ApiException(int code, String msg) { + super(msg); + this.code = code; + } +} diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/resources/exception/NotFoundException.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/resources/exception/NotFoundException.java new file mode 100644 index 0000000000..545e6a9940 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/resources/exception/NotFoundException.java @@ -0,0 +1,26 @@ +/** + * Copyright 2016 SmartBear Software + *

+ * 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.swagger.v3.plugins.gradle.resources.exception; + +public class NotFoundException extends ApiException { + private int code; + + public NotFoundException(int code, String msg) { + super(code, msg); + this.code = code; + } +} diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/resources/model/Category.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/resources/model/Category.java new file mode 100644 index 0000000000..a973cb86d4 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/resources/model/Category.java @@ -0,0 +1,51 @@ +/** + * Copyright 2016 SmartBear Software + *

+ * 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.swagger.v3.plugins.gradle.resources.model; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement(name = "Category") +public class Category { + private long id; + private String name; + + @XmlElement(name = "id") + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + @XmlElement(name = "name") + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Category() { + } + + public Category(String name) { + this.name = name; + } +} \ No newline at end of file diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/resources/model/CustomGenerator.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/resources/model/CustomGenerator.java new file mode 100644 index 0000000000..c41bf37d3b --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/resources/model/CustomGenerator.java @@ -0,0 +1,32 @@ +package io.swagger.v3.plugins.gradle.resources.model; + +import com.fasterxml.jackson.annotation.ObjectIdGenerator; +import com.fasterxml.jackson.annotation.ObjectIdGenerators; + +public class CustomGenerator extends ObjectIdGenerators.PropertyGenerator { + private static final long serialVersionUID = 1L; + + protected CustomGenerator(Class scope) { + super(scope); + } + + @Override + public ObjectIdGenerator forScope(Class scope) { + return null; + } + + @Override + public ObjectIdGenerator newForSerialization(Object context) { + return null; + } + + @Override + public IdKey key(Object key) { + return null; + } + + @Override + public Object generateId(Object forPojo) { + return null; + } +} \ No newline at end of file diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/resources/model/ExtensionUser.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/resources/model/ExtensionUser.java new file mode 100644 index 0000000000..9615b3b170 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/resources/model/ExtensionUser.java @@ -0,0 +1,130 @@ +/** + * Copyright 2016 SmartBear Software + *

+ * 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.swagger.v3.plugins.gradle.resources.model; + +import io.swagger.v3.oas.annotations.extensions.Extension; +import io.swagger.v3.oas.annotations.extensions.ExtensionProperty; +import io.swagger.v3.oas.annotations.media.Schema; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement(name = "User") +@Schema( + description = "User", + extensions = { + @Extension(name = "x-user", properties = { + @ExtensionProperty(name = "name", value = "Josh")}), + @Extension(name = "user-extensions", properties = { + @ExtensionProperty(name = "lastName", value = "Hart"), + @ExtensionProperty(name = "address", value = "House")}) + } +) +public class ExtensionUser { + private long id; + private String username; + private String firstName; + private String lastName; + private String email; + private String password; + private String phone; + private int userStatus; + + @XmlElement(name = "id") + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + @XmlElement(name = "firstName") + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + @XmlElement(name = "username") + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + @XmlElement(name = "lastName") + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + @XmlElement(name = "email") + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + @XmlElement(name = "password") + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + @XmlElement(name = "phone") + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + @XmlElement(name = "userStatus") + //@Schema(description = "User Status", type = "string", allowableValues = {"1-registered", "2-active", "3-closed"}) + @Schema( + description = "User Status", + allowableValues = "1-registered,2-active,3-closed", + extensions = { + @Extension(name = "x-userStatus", properties = { + @ExtensionProperty(name = "name", value = "Josh")}), + @Extension(name = "userStatus-extensions", properties = { + @ExtensionProperty(name = "lastName", value = "Hart"), + @ExtensionProperty(name = "address", value = "House")}) + } + ) + public int getUserStatus() { + return userStatus; + } + + public void setUserStatus(int userStatus) { + this.userStatus = userStatus; + } +} \ No newline at end of file diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/resources/model/JacksonBean.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/resources/model/JacksonBean.java new file mode 100644 index 0000000000..6ab65aa81a --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/resources/model/JacksonBean.java @@ -0,0 +1,76 @@ +package io.swagger.v3.plugins.gradle.resources.model; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonUnwrapped; +import com.fasterxml.jackson.annotation.JsonValue; + +public class JacksonBean { + + private String id; + private String ignored; + private StringValueBean bean; + private NotFoundModel model; + private NotFoundModel model2; + + @JsonIgnore + public String getIgnored() { + return ignored; + } + + public void setIgnored(String ignored) { + this.ignored = ignored; + } + + public void setId(String id) { + this.id = id; + } + + public void setModel(NotFoundModel model) { + this.model = model; + } + + public StringValueBean getBean() { + return bean; + } + + public void setBean(StringValueBean bean) { + this.bean = bean; + } + + @JsonProperty("identity") + public String getId() { + return id; + } + + @JsonUnwrapped + public NotFoundModel getModel() { + return model; + } + + @JsonUnwrapped(prefix = "pre", suffix = "suf") + public NotFoundModel getModel2() { + return model2; + } + + public void setModel2(NotFoundModel model2) { + this.model2 = model2; + } + + public static class StringValueBean { + + private final String value; + + @JsonCreator + public StringValueBean(String value) { + this.value = value; + } + + @JsonValue + public String getValue() { + return value; + } + } + +} diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/resources/model/ListOfStringsBeanParam.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/resources/model/ListOfStringsBeanParam.java new file mode 100644 index 0000000000..d002e3c4ff --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/resources/model/ListOfStringsBeanParam.java @@ -0,0 +1,17 @@ +package io.swagger.v3.plugins.gradle.resources.model; + +import javax.ws.rs.QueryParam; +import java.util.List; + +public class ListOfStringsBeanParam { + @QueryParam(value = "listOfStrings") + private List list; + + public List getList() { + return list; + } + + public void setList(List list) { + this.list = list; + } +} \ No newline at end of file diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/resources/model/ModelWithJsonIdentity.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/resources/model/ModelWithJsonIdentity.java new file mode 100644 index 0000000000..72470ea57f --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/resources/model/ModelWithJsonIdentity.java @@ -0,0 +1,145 @@ +package io.swagger.v3.plugins.gradle.resources.model; + +import com.fasterxml.jackson.annotation.JsonIdentityInfo; +import com.fasterxml.jackson.annotation.JsonIdentityReference; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.ObjectIdGenerators; + +public class ModelWithJsonIdentity { + + @JsonIdentityReference(alwaysAsId = true) + @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "name") + @JsonProperty("PropertyGeneratorAsId") + public SourceDefinition1 testPropertyGeneratorAsId; + + @JsonIdentityReference(alwaysAsId = false) + @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "name") + @JsonProperty("PropertyGeneratorAsProperty") + public SourceDefinition1 testPropertyGeneratorAsProperty; + + public class SourceDefinition1 { + public String driver; + public String name; + } + + @JsonIdentityReference(alwaysAsId = true) + @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "driverId") + @JsonProperty("ChangedPropertyName") + public SourceDefinition2 testChangedPropertyName; + + @JsonIdentityReference(alwaysAsId = true) + @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "driverId") + @JsonProperty("ChangedPropertyName2") + public SourceDefinition2 testChangedPropertyName2; + + static public class SourceDefinition2 { + @JsonProperty("driverId") + public String driver; + public String name; + } + + @JsonIdentityReference(alwaysAsId = true) + @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class) + @JsonProperty("SourceWithoutPropertyAsId") + public SourceDefinition3 testWithoutPropertyAsId; + + @JsonIdentityReference(alwaysAsId = false) + @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class) + @JsonProperty("SourceWithoutPropertyAsProperty") + public SourceDefinition3 testWithoutPropertyAsProperty; + + public class SourceDefinition3 { + @JsonProperty("driverId") + public String driver; + public String name; + + @JsonProperty("@id") + public String id; + } + + @JsonIdentityReference(alwaysAsId = true) + @JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class, property = "testName1") + @JsonProperty("IntSequenceGeneratorAsId") + public SourceDefinition4 testIntSequenceGeneratorAsId; + + @JsonIdentityReference(alwaysAsId = false) + @JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class, property = "testName2") + @JsonProperty("IntSequenceGeneratorAsProperty") + public SourceDefinition4 testIntSequenceGeneratorAsProperty; + + public class SourceDefinition4 { + public String name; + } + + @JsonIdentityReference(alwaysAsId = true) + @JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class) + @JsonProperty("IntSequenceWithoutPropertyAsId") + public SourceDefinition5 testIntSequenceWithoutPropertyAsId; + + @JsonIdentityReference(alwaysAsId = false) + @JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class) + @JsonProperty("IntSequenceWithoutPropertyAsProperty") + public SourceDefinition5 testIntSequenceWithoutPropertyAsProperty; + + public class SourceDefinition5 { + public String name; + } + + @JsonIdentityReference(alwaysAsId = true) + @JsonIdentityInfo(generator = ObjectIdGenerators.UUIDGenerator.class, property = "UUID1") + @JsonProperty("UUIDGeneratorAsId") + public SourceDefinition6 testUUIDGeneratorAsId; + + @JsonIdentityReference(alwaysAsId = false) + @JsonIdentityInfo(generator = ObjectIdGenerators.UUIDGenerator.class, property = "UUID2") + @JsonProperty("UUIDGeneratorAsProperty") + public SourceDefinition6 testUUIDGeneratorAsProperty; + + public class SourceDefinition6 { + public String name; + } + + @JsonIdentityReference(alwaysAsId = true) + @JsonIdentityInfo(generator = ObjectIdGenerators.UUIDGenerator.class) + @JsonProperty("UUIDGeneratorWithoutPropertyAsId") + public SourceDefinition7 testUUIDGeneratorWithoutPropertyAsId; + + @JsonIdentityReference(alwaysAsId = false) + @JsonIdentityInfo(generator = ObjectIdGenerators.UUIDGenerator.class) + @JsonProperty("UUIDGeneratorWithoutPropertyAsProperty") + public SourceDefinition7 testUUIDGeneratorWithoutPropertyAsProperty; + + public class SourceDefinition7 { + public String name; + } + + @JsonIdentityReference(alwaysAsId = true) + @JsonIdentityInfo(generator = ObjectIdGenerators.None.class, property = "testGeneratorsNone") + @JsonProperty("GeneratorsNone") + public SourceDefinition8 testGeneratorsNone; + + public class SourceDefinition8 { + @JsonProperty("driverId") + public String driver; + public String name; + } + + @JsonIdentityReference(alwaysAsId = true) + @JsonIdentityInfo(generator = CustomGenerator.class, property = "name") + @JsonProperty("CustomGenerator") + public SourceDefinition9 testCustomGenerator; + + public class SourceDefinition9 { + public String driver; + public String name; + } + + @JsonIdentityInfo(generator = CustomGenerator.class, property = "name") + @JsonProperty("WithoutJsonIdentityReference") + public SourceDefinition10 testWithoutJsonIdentityReference; + + public class SourceDefinition10 { + public String driver; + public String name; + } +} \ No newline at end of file diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/resources/model/ModelWithJsonIdentityCyclic.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/resources/model/ModelWithJsonIdentityCyclic.java new file mode 100644 index 0000000000..e20f5fcf95 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/resources/model/ModelWithJsonIdentityCyclic.java @@ -0,0 +1,29 @@ +package io.swagger.v3.plugins.gradle.resources.model; + +import com.fasterxml.jackson.annotation.JsonIdentityInfo; +import com.fasterxml.jackson.annotation.JsonIdentityReference; +import com.fasterxml.jackson.annotation.ObjectIdGenerators; + +import java.util.List; + +public class ModelWithJsonIdentityCyclic { + + public Long id; + + public List sourceDefinitions; + + @JsonIdentityInfo( + generator = ObjectIdGenerators.PropertyGenerator.class, + property = "name") + public static class SourceDefinition { + public String driver; + public String name; + + @JsonIdentityReference(alwaysAsId=true) + @JsonIdentityInfo( + generator = ObjectIdGenerators.PropertyGenerator.class, + property = "id") + public ModelWithJsonIdentityCyclic model; + } + +} \ No newline at end of file diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/resources/model/MultipleBaseBean.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/resources/model/MultipleBaseBean.java new file mode 100644 index 0000000000..0d5966fa1e --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/resources/model/MultipleBaseBean.java @@ -0,0 +1,11 @@ +package io.swagger.v3.plugins.gradle.resources.model; + +@io.swagger.v3.oas.annotations.media.Schema( + description = "MultipleBaseBean", + subTypes = { MultipleSub1Bean.class, MultipleSub2Bean.class } +) +public class MultipleBaseBean { + public String beanType; + public int a; + public String b; +} \ No newline at end of file diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/resources/model/MultipleSub1Bean.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/resources/model/MultipleSub1Bean.java new file mode 100644 index 0000000000..c1a03258d0 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/resources/model/MultipleSub1Bean.java @@ -0,0 +1,8 @@ +package io.swagger.v3.plugins.gradle.resources.model; + +@io.swagger.v3.oas.annotations.media.Schema( + description = "MultipleSub1Bean" +) +public class MultipleSub1Bean extends MultipleBaseBean { + public int c; +} \ No newline at end of file diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/resources/model/MultipleSub2Bean.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/resources/model/MultipleSub2Bean.java new file mode 100644 index 0000000000..763e5f0454 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/resources/model/MultipleSub2Bean.java @@ -0,0 +1,8 @@ +package io.swagger.v3.plugins.gradle.resources.model; + +@io.swagger.v3.oas.annotations.media.Schema( + description = "MultipleSub2Bean" +) +public class MultipleSub2Bean extends MultipleBaseBean { + public int d; +} \ No newline at end of file diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/resources/model/NotFoundModel.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/resources/model/NotFoundModel.java new file mode 100644 index 0000000000..73e0b3f95c --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/resources/model/NotFoundModel.java @@ -0,0 +1,30 @@ +package io.swagger.v3.plugins.gradle.resources.model; + +public class NotFoundModel { + int code; + String message; + + public NotFoundModel() { + } + + public NotFoundModel(int code, String message) { + this.code = code; + this.message = message; + } + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } +} diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/resources/model/Pet.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/resources/model/Pet.java new file mode 100644 index 0000000000..0cf61e4857 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/resources/model/Pet.java @@ -0,0 +1,76 @@ +package io.swagger.v3.plugins.gradle.resources.model; + +import io.swagger.v3.oas.annotations.media.Schema; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElementWrapper; +import javax.xml.bind.annotation.XmlRootElement; +import java.util.ArrayList; +import java.util.List; + +@XmlRootElement(name = "Pet") +public class Pet { + private long id; + private Category category; + private String name; + private List photoUrls = new ArrayList(); + private List tags = new ArrayList(); + private String status; + + @XmlElement(name = "id") + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + @XmlElement(name = "category") + public Category getCategory() { + return category; + } + + public void setCategory(Category category) { + this.category = category; + } + + @XmlElement(name = "name") + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @XmlElementWrapper(name = "photoUrls") + @XmlElement(name = "photoUrl") + public List getPhotoUrls() { + return photoUrls; + } + + public void setPhotoUrls(List photoUrls) { + this.photoUrls = photoUrls; + } + + @XmlElementWrapper(name = "tags") + @XmlElement(name = "tag") + public List getTags() { + return tags; + } + + public void setTags(List tags) { + this.tags = tags; + } + + @XmlElement(name = "status") + @Schema(description = "pet status in the store", allowableValues = "available,pending,sold") + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } +} diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/resources/model/Tag.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/resources/model/Tag.java new file mode 100644 index 0000000000..107de03ebf --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/resources/model/Tag.java @@ -0,0 +1,44 @@ +/** + * Copyright 2016 SmartBear Software + *

+ * 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.swagger.v3.plugins.gradle.resources.model; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement(name = "Tag") +public class Tag { + private long id; + private String name; + + @XmlElement(name = "id") + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + @XmlElement(name = "name") + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} \ No newline at end of file diff --git a/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/resources/model/User.java b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/resources/model/User.java new file mode 100644 index 0000000000..ae67103476 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/resources/model/User.java @@ -0,0 +1,108 @@ +/** + * Copyright 2016 SmartBear Software + *

+ * 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.swagger.v3.plugins.gradle.resources.model; + +import io.swagger.v3.oas.annotations.media.Schema; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement(name = "User") +public class User { + private long id; + private String username; + private String firstName; + private String lastName; + private String email; + private String password; + private String phone; + private int userStatus; + + @XmlElement(name = "id") + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + @XmlElement(name = "firstName") + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + @XmlElement(name = "username") + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + @XmlElement(name = "lastName") + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + @XmlElement(name = "email") + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + @XmlElement(name = "password") + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + @XmlElement(name = "phone") + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + @XmlElement(name = "userStatus") + //@Schema(description = "User Status", type = "string", allowableValues = {"1-registered", "2-active", "3-closed"}) + @Schema(description = "User Status", allowableValues = "1-registered,2-active,3-closed") + public int getUserStatus() { + return userStatus; + } + + public void setUserStatus(int userStatus) { + this.userStatus = userStatus; + } +} \ No newline at end of file diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/EmptyPetResource.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/EmptyPetResource.java new file mode 100644 index 0000000000..3a60f75fe2 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/EmptyPetResource.java @@ -0,0 +1,7 @@ +package io.swagger.v3.plugins.gradle.petstore; + +/** + * An Empty PetResource Class + */ +public class EmptyPetResource { +} diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/PetResource.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/PetResource.java new file mode 100644 index 0000000000..a0d713071d --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/PetResource.java @@ -0,0 +1,165 @@ +/** + * Copyright 2016 SmartBear Software + *

+ * 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.swagger.v3.plugins.gradle.petstore; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.plugins.gradle.resources.QueryResultBean; +import io.swagger.v3.plugins.gradle.resources.data.PetData; +import io.swagger.v3.plugins.gradle.resources.exception.NotFoundException; +import io.swagger.v3.plugins.gradle.resources.model.Pet; + +import javax.ws.rs.BeanParam; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Response; + +@Consumes("application/json") +@Path("/pet") +@Produces({"application/json", "application/xml"}) +public class PetResource { + static PetData petData = new PetData(); + + @GET + @Path("/{petId}") + @Operation(summary = "Find pet by ID", + description = "Returns a pet when 0 < ID <= 10. ID > 10 or nonintegers will simulate API error conditions", + responses = { + @ApiResponse( + description = "The pet", content = @Content( + schema = @Schema(implementation = Pet.class) + )), + @ApiResponse(responseCode = "400", description = "Invalid ID supplied"), + @ApiResponse(responseCode = "404", description = "Pet not found") + }) + public Response getPetById( + @Parameter(description = "ID of pet that needs to be fetched"/*, _enum = "range[1,10]"*/, required = true) + @PathParam("petId") final Long petId) throws NotFoundException { + Pet pet = petData.getPetById(petId); + if (null != pet) { + return Response.ok().entity(pet).build(); + } else { + throw new NotFoundException(404, "Pet not found"); + } + } + + @POST + @Consumes({"application/json", "application/xml"}) + @Operation(summary = "Add a new pet to the store", + responses = { + @ApiResponse(responseCode = "405", description = "Invalid input") + }) + public Response addPet( + @Parameter(description = "Pet object that needs to be added to the store", required = true) final Pet pet) { + petData.addPet(pet); + return Response.ok().entity("SUCCESS").build(); + } + + @POST + @Path("/bodynoannotation") + @Consumes({"application/json", "application/xml"}) + @Produces({"application/json", "application/xml"}) + @Operation(summary = "Add a new pet to the store no annotation", + responses = { + @ApiResponse(responseCode = "405", description = "Invalid input") + }) + public Response addPetNoAnnotation(final Pet pet) { + petData.addPet(pet); + return Response.ok().entity("SUCCESS").build(); + } + + @POST + @Path("/bodyid") + @Consumes({"application/json", "application/xml"}) + @Operation(summary = "Add a new pet to the store passing an integer with generic parameter annotation", + responses = { + @ApiResponse(responseCode = "405", description = "Invalid input") + }) + public Response addPetByInteger( + @Parameter(description = "Pet object that needs to be added to the store", required = true) final int petId) { + return Response.ok().entity("SUCCESS").build(); + } + + @POST + @Path("/bodyidnoannotation") + @Consumes({"application/json", "application/xml"}) + @Operation(summary = "Add a new pet to the store passing an integer without parameter annotation", + responses = { + @ApiResponse(responseCode = "405", description = "Invalid input") + }) + public Response addPetByIntegerNoAnnotation(final int petId) { + return Response.ok().entity("SUCCESS").build(); + } + + @PUT + @Operation(summary = "Update an existing pet", + responses = { + @ApiResponse(responseCode = "400", description = "Invalid ID supplied"), + @ApiResponse(responseCode = "404", description = "Pet not found"), + @ApiResponse(responseCode = "405", description = "Validation exception")}) + public Response updatePet( + @Parameter(description = "Pet object that needs to be added to the store", required = true) final Pet pet) { + petData.addPet(pet); + return Response.ok().entity("SUCCESS").build(); + } + + @GET + @Path("/findByStatus") + @Produces("application/xml") + @Operation(summary = "Finds Pets by status", + description = "Multiple status values can be provided with comma seperated strings", + responses = { + @ApiResponse( + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Pet.class))), + @ApiResponse( + responseCode = "400", description = "Invalid status value" + )} + ) + public Response findPetsByStatus( + @Parameter(description = "Status values that need to be considered for filter", required = true) @QueryParam("status") final String status, + @BeanParam final QueryResultBean qr + ) { + return Response.ok(petData.findPetByStatus(status)).build(); + } + + @GET + @Path("/findByTags") + @Produces("application/json") + @Operation(summary = "Finds Pets by tags", + description = "Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.", + responses = { + @ApiResponse(description = "Pets matching criteria", + content = @Content(schema = @Schema(implementation = Pet.class)) + ), + @ApiResponse(description = "Invalid tag value", responseCode = "400") + }) + @Deprecated + public Response findPetsByTags( + @Parameter(description = "Tags to filter by", required = true) @QueryParam("tags") final String tags) { + return Response.ok(petData.findPetByTags(tags)).build(); + } +} diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/callback/ComplexCallbackResource.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/callback/ComplexCallbackResource.java new file mode 100644 index 0000000000..44dfc535ee --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/callback/ComplexCallbackResource.java @@ -0,0 +1,62 @@ +package io.swagger.v3.plugins.gradle.petstore.callback; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.callbacks.Callback; +import io.swagger.v3.oas.annotations.callbacks.Callbacks; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.plugins.gradle.resources.model.User; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.QueryParam; + +public class ComplexCallbackResource { + @Callbacks({ + @Callback( + name = "testCallback1", + operation = @Operation( + operationId = "getAllReviews", + summary = "get all the reviews", + method = "get", + responses = @ApiResponse( + responseCode = "200", + description = "successful operation", + content = @Content( + mediaType = "application/json", + schema = @Schema( + type = "integer", + format = "int32")))), + callbackUrlExpression = "http://www.url.com"), + @Callback( + name = "testCallback2", + operation = @Operation( + operationId = "getAnSpecificReviews", + summary = "get a review", + method = "get", + responses = @ApiResponse( + responseCode = "200", + description = "successful operation", + content = @Content( + mediaType = "application/json", + schema = @Schema( + implementation = User.class)))), + callbackUrlExpression = "http://www.url2.com") + }) + @Operation( + summary = "Simple get operation", + operationId = "getWithNoParameters", + responses = { + @ApiResponse( + responseCode = "200", + description = "voila!") + }) + @GET + @Path("/complexcallback") + public String simpleGet(@Parameter(description = "idParam", schema = @Schema(implementation = User.class)) + @QueryParam("id") final String id) { + return null; + } +} diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/callback/MultipleCallbacksTestWithOperationResource.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/callback/MultipleCallbacksTestWithOperationResource.java new file mode 100644 index 0000000000..2ec7309b1b --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/callback/MultipleCallbacksTestWithOperationResource.java @@ -0,0 +1,45 @@ +package io.swagger.v3.plugins.gradle.petstore.callback; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.callbacks.Callback; +import io.swagger.v3.oas.annotations.callbacks.Callbacks; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +public class MultipleCallbacksTestWithOperationResource { + @Callbacks({ + @Callback( + name = "testCallback1", + operation = @Operation( + operationId = "getAllReviews", + summary = "get all the reviews", + method = "get", + responses = @ApiResponse( + responseCode = "200", + description = "successful operation", + content = @Content( + mediaType = "application/json", + schema = @Schema( + type = "integer", + format = "int32")))), + callbackUrlExpression = "http://www.url.com"), + @Callback(name = "testCallback2", operation = @Operation(), callbackUrlExpression = "http://$request.query.url") + }) + @Operation( + summary = "Simple get operation", + operationId = "getWithNoParameters", + responses = { + @ApiResponse( + responseCode = "200", + description = "voila!") + }) + @GET + @Path("/multiplecallback") + public String simpleGet() { + return null; + } +} \ No newline at end of file diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/callback/RepeatableCallbackResource.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/callback/RepeatableCallbackResource.java new file mode 100644 index 0000000000..82a60ca110 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/callback/RepeatableCallbackResource.java @@ -0,0 +1,46 @@ +package io.swagger.v3.plugins.gradle.petstore.callback; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.callbacks.Callback; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +public class RepeatableCallbackResource { + @Callback(name = "testCallback", operation = + @Operation(), callbackUrlExpression = "http://$requests.query.url") + @Callback( + name = "testCallback1", + operation = @Operation( + operationId = "getAllReviews", + summary = "get all the reviews", + method = "get", + responses = @ApiResponse( + responseCode = "200", + description = "successful operation", + content = @Content( + mediaType = "application/json", + schema = @Schema( + type = "integer", + format = "int32")))), + callbackUrlExpression = "http://www.url.com") + @Callback(name = "testCallback2", operation = + @Operation(), + callbackUrlExpression = "http://$request.query.url") + @Operation( + summary = "Simple get operation", + operationId = "getWithNoParameters", + responses = { + @ApiResponse( + responseCode = "200", + description = "voila!") + }) + @GET + @Path("/repeatablecallback") + public String simpleGet() { + return null; + } +} \ No newline at end of file diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/callback/SimpleCallbackWithOperationResource.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/callback/SimpleCallbackWithOperationResource.java new file mode 100644 index 0000000000..2c6e543362 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/callback/SimpleCallbackWithOperationResource.java @@ -0,0 +1,44 @@ +package io.swagger.v3.plugins.gradle.petstore.callback; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.callbacks.Callback; +import io.swagger.v3.oas.annotations.callbacks.Callbacks; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +public class SimpleCallbackWithOperationResource { + @Callbacks({ + @Callback( + name = "testCallback1", + operation = @Operation( + operationId = "getAllReviews", + summary = "get all the reviews", + method = "get", + responses = @ApiResponse( + responseCode = "200", + description = "successful operation", + content = @Content( + mediaType = "application/json", + schema = @Schema( + type = "integer", + format = "int32")))), + callbackUrlExpression = "http://www.url.com") + }) + @Operation( + summary = "Simple get operation", + operationId = "getWithNoParameters", + responses = { + @ApiResponse( + responseCode = "200", + description = "voila!") + }) + @GET + @Path("/simplecallback") + public String simpleGet() { + return null; + } +} diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/example/ExamplesResource.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/example/ExamplesResource.java new file mode 100644 index 0000000000..84ae58bfb7 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/example/ExamplesResource.java @@ -0,0 +1,69 @@ +package io.swagger.v3.plugins.gradle.petstore.example; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.enums.ParameterIn; +import io.swagger.v3.oas.annotations.enums.ParameterStyle; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.ExampleObject; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.parameters.RequestBody; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.plugins.gradle.resources.model.User; + +import javax.ws.rs.POST; +import javax.ws.rs.Path; + +/** + * Examples Resource Scenario + */ +public class ExamplesResource { + @Path("/example") + @POST + @Operation( + operationId = "subscribe", + description = "subscribes a client to updates relevant to the requestor's account", + parameters = { + @Parameter(in = ParameterIn.PATH, name = "subscriptionId", required = true, + schema = @Schema(name = "Schema", description = "Schema", example = "Subscription example"), + style = ParameterStyle.SIMPLE, example = "example", + examples = { + @ExampleObject(name = "subscriptionId_1", value = "12345", + summary = "Subscription number 12345", externalValue = "Subscription external value 1"), + @ExampleObject(name = "subscriptionId_2", value = "54321", + summary = "Subscription number 54321", externalValue = "Subscription external value 2") + }) + }, + responses = { + @ApiResponse( + description = "test description", + content = @Content( + mediaType = "*/*", + schema = @Schema( + type = "string", + format = "uuid", + description = "the generated UUID", + accessMode = Schema.AccessMode.READ_ONLY, + example = "Schema example" + ), + examples = { + @ExampleObject(name = "Default Response", value = "SubscriptionResponse", + summary = "Subscription Response Example", externalValue = "Subscription Response value 1") + } + )) + }) + public SubscriptionResponse subscribe(@RequestBody(description = "Created user object", required = true, + content = @Content( + schema = @Schema( + type = "string", + format = "uuid", + description = "the generated UUID", + accessMode = Schema.AccessMode.READ_ONLY, + example = "Schema example"), + examples = { + @ExampleObject(name = "Default Request", value = "SubscriptionRequest", + summary = "Subscription Request Example", externalValue = "Subscription Request Value") + })) User user) { + return null; + } +} \ No newline at end of file diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/example/SubscriptionResponse.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/example/SubscriptionResponse.java new file mode 100644 index 0000000000..7b8bc707a4 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/example/SubscriptionResponse.java @@ -0,0 +1,5 @@ +package io.swagger.v3.plugins.gradle.petstore.example; + +public class SubscriptionResponse { + public String subscriptionId; +} \ No newline at end of file diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/link/LinksResource.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/link/LinksResource.java new file mode 100644 index 0000000000..8450a64abf --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/link/LinksResource.java @@ -0,0 +1,44 @@ +package io.swagger.v3.plugins.gradle.petstore.link; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.links.Link; +import io.swagger.v3.oas.annotations.links.LinkParameter; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.QueryParam; + +/** + * Class with Links + */ +public class LinksResource { + @Path("/links") + @Operation(operationId = "getUserWithAddress", + responses = { + @ApiResponse(description = "test description", + content = @Content(mediaType = "*/*", schema = @Schema(ref = "#/components/schemas/User")), + links = { + @Link( + name = "address", + operationId = "getAddress", + parameters = @LinkParameter( + name = "userId", + expression = "$request.query.userId")), + @Link( + name = "user", + operationId = "getUser", + operationRef = "#/components/links/MyLink", + parameters = @LinkParameter( + name = "userId", + expression = "$request.query.userId")) + })} + ) + @GET + public String getUser(@QueryParam("userId")final String userId) { + return null; + } + +} diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/openapidefintion/OpenAPIDefinitionResource.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/openapidefintion/OpenAPIDefinitionResource.java new file mode 100644 index 0000000000..5ac0c573fa --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/openapidefintion/OpenAPIDefinitionResource.java @@ -0,0 +1,38 @@ +package io.swagger.v3.plugins.gradle.petstore.openapidefintion; + +import io.swagger.v3.oas.annotations.ExternalDocumentation; +import io.swagger.v3.oas.annotations.OpenAPIDefinition; +import io.swagger.v3.oas.annotations.info.Contact; +import io.swagger.v3.oas.annotations.info.Info; +import io.swagger.v3.oas.annotations.info.License; +import io.swagger.v3.oas.annotations.security.SecurityRequirement; +import io.swagger.v3.oas.annotations.servers.Server; +import io.swagger.v3.oas.annotations.servers.ServerVariable; +import io.swagger.v3.oas.annotations.tags.Tag; + +/** + * OpenAPIDefinition Example + */ +@OpenAPIDefinition( + info = @Info( + title = "Pet Resource Example", + version = "2.0", + description = "API Definition", + termsOfService = "Terms of service", + license = @License(name = "Apache 2.0", url = "http://foo.bar"), + contact = @Contact(url = "http://gigantic-server.com", name = "Fred", email = "Fred@gigagantic-server.com") + ), + tags = { + @Tag(name = "Tag 1", description = "desc 1", externalDocs = @ExternalDocumentation(description = "docs desc")), + @Tag(name = "Tag 2", description = "desc 2", externalDocs = @ExternalDocumentation(description = "docs desc 2")), + @Tag(name = "Tag 3") + }, + externalDocs = @ExternalDocumentation(description = "definition docs desc"), + security = { + @SecurityRequirement(name = "req 1", scopes = {"a", "b"}), + @SecurityRequirement(name = "req 2", scopes = {"b", "c"}) + }) +public class OpenAPIDefinitionResource { + public void foo() { + } +} diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/operation/AnnotatedSameNameOperationResource.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/operation/AnnotatedSameNameOperationResource.java new file mode 100644 index 0000000000..db73258ef0 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/operation/AnnotatedSameNameOperationResource.java @@ -0,0 +1,26 @@ +package io.swagger.v3.plugins.gradle.petstore.operation; + +import io.swagger.v3.oas.annotations.Operation; + +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +/** + * Resource With a Default Operation without Annotation + */ +public class AnnotatedSameNameOperationResource { + @Path("/sameOperationName") + @GET + @Operation(description = "Same Operation Name") + public String getUser() { + return new String(); + } + + @Path("//sameOperationName") + @DELETE + @Operation(description = "Same Operation Name Duplicated") + public String getUser(final String id) { + return new String(); + } +} diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/operation/ExternalDocumentationResource.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/operation/ExternalDocumentationResource.java new file mode 100644 index 0000000000..a351ac68bf --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/operation/ExternalDocumentationResource.java @@ -0,0 +1,30 @@ +package io.swagger.v3.plugins.gradle.petstore.operation; + +import io.swagger.v3.oas.annotations.ExternalDocumentation; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.plugins.gradle.resources.exception.NotFoundException; +import io.swagger.v3.plugins.gradle.resources.model.Pet; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.core.Response; + +/** + * Resource with Operations Examples + */ +public class ExternalDocumentationResource { + @GET + @Path("/{petId}") + @Operation(summary = "Find pet by ID", + description = "Returns a pet when 0 < ID <= 10. ID > 10 or non integers will simulate API error conditions", + operationId = "petId", + externalDocs = @ExternalDocumentation(description = "External in Operation", url = "http://url.me")) + @ExternalDocumentation(description = "External Annotation Documentation", url = "http://url.me") + public Response getPetById( + @Parameter(description = "ID of pet that needs to be fetched", required = true) + @PathParam("petId") Long petId) throws NotFoundException { + return Response.ok().entity(new Pet()).build(); + } +} diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/operation/FullyAnnotatedOperationResource.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/operation/FullyAnnotatedOperationResource.java new file mode 100644 index 0000000000..2955c6590e --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/operation/FullyAnnotatedOperationResource.java @@ -0,0 +1,38 @@ +package io.swagger.v3.plugins.gradle.petstore.operation; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.plugins.gradle.resources.exception.NotFoundException; +import io.swagger.v3.plugins.gradle.resources.model.Pet; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.core.Response; + +/** + * Resource with Operations Examples + */ +public class FullyAnnotatedOperationResource { + @GET + @Path("/fullyannotatedoperation/{petId}") + @Operation(summary = "Find pet by ID", + description = "Returns a pet when 0 < ID <= 10. ID > 10 or non integers will simulate API error conditions", + operationId = "petId", + responses = { + @ApiResponse( + description = "The pet", content = @Content( + schema = @Schema(implementation = Pet.class) + )), + @ApiResponse(responseCode = "400", description = "Invalid ID supplied"), + @ApiResponse(responseCode = "404", description = "Pet not found") + }) + public Response getPetById( + @Parameter(description = "ID of pet that needs to be fetched", required = true) + @PathParam("petId")final Long petId) throws NotFoundException { + return Response.ok().entity(new Pet()).build(); + } +} diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/operation/HiddenOperationResource.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/operation/HiddenOperationResource.java new file mode 100644 index 0000000000..730e83657d --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/operation/HiddenOperationResource.java @@ -0,0 +1,29 @@ +package io.swagger.v3.plugins.gradle.petstore.operation; + +import io.swagger.v3.oas.annotations.Hidden; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.plugins.gradle.resources.model.Pet; +import io.swagger.v3.plugins.gradle.resources.model.User; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +/** + * Resource With a Hidden Operation + */ +public class HiddenOperationResource { + @Path("/hiddenbyflag") + @GET + @Operation(operationId = "Pets", description = "Pets Example", hidden = true) + public Pet getPet() { + return new Pet(); + } + + @Path("/hiddenbyannotation") + @GET + @Operation(operationId = "Users", description = "Users Example") + @Hidden + public User getUser() { + return new User(); + } +} diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/operation/InterfaceResource.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/operation/InterfaceResource.java new file mode 100644 index 0000000000..aa5418ecc6 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/operation/InterfaceResource.java @@ -0,0 +1,22 @@ +package io.swagger.v3.plugins.gradle.petstore.operation; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.core.Response; + +/** + * Interface resource + */ +public interface InterfaceResource { + @GET + @Path("/interfaceoperation/{petId}") + @Operation(summary = "Find pet by ID Operation in Parent", + description = "Returns a pet in Parent" + ) + Response getPetById(@Parameter(description = "ID of pet that needs to be fetched", required = true) + @PathParam("petId") final Long petId); +} diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/operation/NotAnnotatedSameNameOperationResource.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/operation/NotAnnotatedSameNameOperationResource.java new file mode 100644 index 0000000000..e8021608de --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/operation/NotAnnotatedSameNameOperationResource.java @@ -0,0 +1,21 @@ +package io.swagger.v3.plugins.gradle.petstore.operation; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +/** + * Resource With a Default Operation without Annotation + */ +public class NotAnnotatedSameNameOperationResource { + @Path("/notannotatedoperation") + @GET + public String getUser() { + return new String(); + } + + @Path("/notannotatedoperationduplicated") + @GET + public String getUser(final String id) { + return new String(); + } +} diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/operation/OperationResource.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/operation/OperationResource.java new file mode 100644 index 0000000000..fdc5e495ca --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/operation/OperationResource.java @@ -0,0 +1,77 @@ +package io.swagger.v3.plugins.gradle.petstore.operation; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.plugins.gradle.resources.model.Pet; + +import javax.ws.rs.GET; +import javax.ws.rs.HEAD; +import javax.ws.rs.NotFoundException; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Response; + +/** + * Resource with Complete Operations Examples + */ +public class OperationResource implements InterfaceResource { + @Override + @Operation(summary = "Find pet by ID Operation in SubResource", + description = "Returns a pet in SubResource" + ) + public Response getPetById(final Long petId) { + return Response.ok().entity(new Pet()).build(); + } + + @GET + @Path("/operationsresource") + @Operation(summary = "Find pet by ID", + description = "combinatedfullyannotatedoperation/{petId}", + operationId = "petId", + responses = { + @ApiResponse( + description = "The pet", content = @Content( + schema = @Schema(implementation = Pet.class) + )), + @ApiResponse(responseCode = "400", description = "Invalid ID supplied"), + @ApiResponse(responseCode = "404", description = "Pet not found") + }) + public Response getPetById( + @Parameter(description = "ID of pet that needs to be fetched", required = true) + @QueryParam("petId") final Long petId, final String message) throws NotFoundException { + return Response.ok().entity(new Pet()).build(); + } + + @Path("/operationsresource") + @POST + public String getUser(final String id) { + return new String(); + } + + @Path("/operationsresource") + @PUT + @Operation(operationId = "combinated sameOperationName", + description = "combinatedsameOperationName") + public String getPerson() { + return new String(); + } + + @Path("/operationsresource") + @HEAD + @Operation(operationId = "combinatedsameOperationNameDuplicated", + description = "combinatedsameOperationNameDuplicated") + public String getPerson(final String id) { + return new String(); + } + + @Path("/operationsresource2") + @GET + public String getUser() { + return new String(); + } +} diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/operation/OperationWithoutAnnotationResource.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/operation/OperationWithoutAnnotationResource.java new file mode 100644 index 0000000000..7c4bf2cd02 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/operation/OperationWithoutAnnotationResource.java @@ -0,0 +1,15 @@ +package io.swagger.v3.plugins.gradle.petstore.operation; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +/** + * Resource With a Default Operation without Annotation + */ +public class OperationWithoutAnnotationResource { + @Path("/operationwithouannotation") + @GET + public String getUser() { + return new String(); + } +} diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/operation/ServerOperationResource.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/operation/ServerOperationResource.java new file mode 100644 index 0000000000..725fed837b --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/operation/ServerOperationResource.java @@ -0,0 +1,25 @@ +package io.swagger.v3.plugins.gradle.petstore.operation; + +import io.swagger.v3.oas.annotations.OpenAPIDefinition; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.servers.Server; +import io.swagger.v3.plugins.gradle.resources.model.Pet; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +/** + * Resource With a Hidden Operation + */ +public class ServerOperationResource { + @Path("/serversoperation") + @GET + @Operation(operationId = "Pets", description = "Pets Example", + servers = { + @Server(description = "server 2", url = "http://foo2") + } + ) + public Pet getPet() { + return new Pet(); + } +} diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/operation/SubResource.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/operation/SubResource.java new file mode 100644 index 0000000000..d56a767030 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/operation/SubResource.java @@ -0,0 +1,20 @@ +package io.swagger.v3.plugins.gradle.petstore.operation; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.plugins.gradle.resources.model.Pet; + +import javax.ws.rs.core.Response; + +/** + * SubResource + */ + +public class SubResource implements InterfaceResource { + @Override + @Operation(summary = "Find pet by ID Operation in SubResource", + description = "Returns a pet in SubResource" + ) + public Response getPetById(final Long petId) { + return Response.ok().entity(new Pet()).build(); + } +} diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/parameter/ArraySchemaResource.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/parameter/ArraySchemaResource.java new file mode 100644 index 0000000000..1ec07a8ce8 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/parameter/ArraySchemaResource.java @@ -0,0 +1,44 @@ +package io.swagger.v3.plugins.gradle.petstore.parameter; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.enums.Explode; +import io.swagger.v3.oas.annotations.enums.ParameterIn; +import io.swagger.v3.oas.annotations.media.ArraySchema; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; + +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.Path; + +public class ArraySchemaResource { + @Path("/arrayschema") + @POST + @Operation( + operationId = "subscribe", + description = "subscribes a client to updates relevant to the requestor's account, as " + + "identified by the input token. The supplied url will be used as the delivery address for response payloads", + parameters = { + @Parameter(in = ParameterIn.QUERY, name = "arrayParameter", required = true, explode = Explode.TRUE, + array = @ArraySchema(maxItems = 10, minItems = 1, + schema = @Schema(implementation = ParametersResource.SubscriptionResponse.class), + uniqueItems = true + ) + ), + }, + responses = { + @ApiResponse( + description = "test description", content = @Content( + mediaType = "*/*", + schema = + @Schema( + implementation = ParametersResource.SubscriptionResponse.class) + )) + }) + @Consumes({"application/json", "application/xml"}) + public ParametersResource.SubscriptionResponse subscribe() { + return null; + } +} diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/parameter/ComplexParameterResource.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/parameter/ComplexParameterResource.java new file mode 100644 index 0000000000..c2ca2f84aa --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/parameter/ComplexParameterResource.java @@ -0,0 +1,33 @@ +package io.swagger.v3.plugins.gradle.petstore.parameter; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.plugins.gradle.resources.model.User; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.QueryParam; + +/** + * Class with a multiple annotated. + */ +public class ComplexParameterResource { + + @Parameter(description = "Phone definied in Field") + private String phone; + + public ComplexParameterResource(@Parameter(description = "phone Param", name = "phone") final String phone) { + this.phone = phone; + } + + @GET + @Path("/complexparameter") + @Operation(operationId = "create User") + public User findUser(@Parameter(description = "idParam") @QueryParam("id") final String id, + final String name, @QueryParam("lastName") final String lastName, + @Parameter(description = "address", schema = @Schema(implementation = User.class)) + @QueryParam("address") final String address) { + return new User(); + } +} diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/parameter/ComplexParameterWithOperationResource.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/parameter/ComplexParameterWithOperationResource.java new file mode 100644 index 0000000000..d1c36874c9 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/parameter/ComplexParameterWithOperationResource.java @@ -0,0 +1,37 @@ +package io.swagger.v3.plugins.gradle.petstore.parameter; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.enums.ParameterIn; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.plugins.gradle.resources.model.User; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.QueryParam; + +/** + * Class with a multiple annotated. + */ +public class ComplexParameterWithOperationResource { + + @Parameter(description = "Phone definied in Field") + private String phone; + + public ComplexParameterWithOperationResource(@Parameter(description = "phone Param", name = "phone") final String phone) { + this.phone = phone; + } + + @GET + @Path("/complexparameter") + @Operation(operationId = "create User", + parameters = { + @Parameter(description = "Phone", name = "phone", in = ParameterIn.PATH) + }) + public User findUser(@Parameter(description = "idParam") @QueryParam("id") final String id, + final String name, @QueryParam("lastName") final String lastName, + @Parameter(description = "address", schema = @Schema(implementation = User.class)) + @QueryParam("address") final String address) { + return new User(); + } +} diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/parameter/MultipleNotAnnotatedParameter.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/parameter/MultipleNotAnnotatedParameter.java new file mode 100644 index 0000000000..7303048545 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/parameter/MultipleNotAnnotatedParameter.java @@ -0,0 +1,18 @@ +package io.swagger.v3.plugins.gradle.petstore.parameter; + +import io.swagger.v3.oas.annotations.Operation; + +import javax.ws.rs.POST; +import javax.ws.rs.Path; + +/** + * Class with a multiple not annotated parameter. + */ +public class MultipleNotAnnotatedParameter { + @POST + @Path("/multiplenoannotatedparameter") + @Operation(operationId = "create User") + public void createUser(final String id, final String name) { + + } +} diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/parameter/OpenAPIJaxRSAnnotatedParameter.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/parameter/OpenAPIJaxRSAnnotatedParameter.java new file mode 100644 index 0000000000..9832b462db --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/parameter/OpenAPIJaxRSAnnotatedParameter.java @@ -0,0 +1,21 @@ +package io.swagger.v3.plugins.gradle.petstore.parameter; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.plugins.gradle.resources.model.User; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.QueryParam; + +/** + * Class with a single parameter annotated with jaxrs and open api annotation. + */ +public class OpenAPIJaxRSAnnotatedParameter { + @GET + @Path("/openapijaxrsannotatedparameter") + @Operation(operationId = "create User") + public User findUser(@Parameter(description = "idParam") @QueryParam("id") final String id) { + return new User(); + } +} diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/parameter/OpenAPIWithContentJaxRSAnnotatedParameter.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/parameter/OpenAPIWithContentJaxRSAnnotatedParameter.java new file mode 100644 index 0000000000..4c4f1ddc32 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/parameter/OpenAPIWithContentJaxRSAnnotatedParameter.java @@ -0,0 +1,25 @@ +package io.swagger.v3.plugins.gradle.petstore.parameter; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.plugins.gradle.resources.model.User; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.QueryParam; + +/** + * Class with a single parameter annotated with jaxrs and open api annotation. + */ +public class OpenAPIWithContentJaxRSAnnotatedParameter { + @GET + @Path("/openapiwithcontentjaxrsannotatedparameter") + @Operation(operationId = "create User") + public User findUser(@Parameter(description = "idParam", content = + @Content(schema = @Schema(description = "Id Schema Definition", required = true, name = "id"))) + @QueryParam("id") final String id) { + return new User(); + } +} diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/parameter/OpenAPIWithImplementationJaxRSAnnotatedParameter.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/parameter/OpenAPIWithImplementationJaxRSAnnotatedParameter.java new file mode 100644 index 0000000000..df23a83a76 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/parameter/OpenAPIWithImplementationJaxRSAnnotatedParameter.java @@ -0,0 +1,23 @@ +package io.swagger.v3.plugins.gradle.petstore.parameter; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.plugins.gradle.resources.model.User; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.QueryParam; + +/** + * Class with a single parameter annotated with jaxrs and open api annotation. + */ +public class OpenAPIWithImplementationJaxRSAnnotatedParameter { + @GET + @Path("/openapiwithimplementationjaxrsannotatedparameter") + @Operation(operationId = "create User") + public User findUser(@Parameter(description = "idParam", schema = @Schema(implementation = User.class)) + @QueryParam("id") final String id) { + return new User(); + } +} diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/parameter/ParametersResource.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/parameter/ParametersResource.java new file mode 100644 index 0000000000..849973f1a9 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/parameter/ParametersResource.java @@ -0,0 +1,87 @@ +package io.swagger.v3.plugins.gradle.petstore.parameter; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.enums.Explode; +import io.swagger.v3.oas.annotations.enums.ParameterIn; +import io.swagger.v3.oas.annotations.enums.ParameterStyle; +import io.swagger.v3.oas.annotations.media.ArraySchema; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; + +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.QueryParam; + +/** + * Resource with some Parameters examples + */ +public class ParametersResource { + @Path("/parameters") + @POST + @Operation( + operationId = "subscribe", + description = "subscribes a client to updates relevant to the requestor's account, as " + + "identified by the input token. The supplied url will be used as the delivery address for response payloads", + parameters = { + @Parameter(in = ParameterIn.PATH, name = "subscriptionId", required = true, + schema = @Schema(implementation = RepeatableParametersResource.SubscriptionResponse.class), style = ParameterStyle.SIMPLE), + @Parameter(in = ParameterIn.QUERY, name = "formId", required = true, + example = "Example"), + @Parameter(in = ParameterIn.QUERY, name = "explodeFalse", required = true, explode = Explode.FALSE, + schema = @Schema(implementation = ParametersResource.SubscriptionResponse.class)), + @Parameter(in = ParameterIn.QUERY, name = "explodeTrue", required = true, explode = Explode.TRUE, + schema = @Schema(implementation = ParametersResource.SubscriptionResponse.class)), + @Parameter(in = ParameterIn.QUERY, name = "explodeAvoiding", required = true, explode = Explode.TRUE, + schema = @Schema( + type = "int", + format = "id", + description = "the generated id", + accessMode = Schema.AccessMode.READ_ONLY + )), + @Parameter(in = ParameterIn.QUERY, name = "arrayParameter", required = true, explode = Explode.TRUE, + array = @ArraySchema(maxItems = 10, minItems = 1, + schema = @Schema(implementation = ParametersResource.SubscriptionResponse.class), + uniqueItems = true + ) + , + schema = @Schema( + type = "int", + format = "id", + description = "the generated id", + accessMode = Schema.AccessMode.READ_ONLY), + content = @Content(schema = @Schema(type = "number", + description = "the generated id", + accessMode = Schema.AccessMode.READ_ONLY)) + ), + @Parameter(in = ParameterIn.QUERY, name = "arrayParameterImplementation", required = true, explode = Explode.TRUE, + array = @ArraySchema(maxItems = 10, minItems = 1, + schema = @Schema(implementation = ParametersResource.SubscriptionResponse.class), + uniqueItems = true + ) + ), + @Parameter(in = ParameterIn.QUERY, name = "arrayParameterImplementation2", required = true, explode = Explode.TRUE, + schema = @Schema(implementation = ParametersResource.SubscriptionResponse.class)) + + }, + responses = { + @ApiResponse( + description = "test description", content = @Content( + mediaType = "*/*", + schema = + @Schema( + implementation = ParametersResource.SubscriptionResponse.class) + )) + }) + @Consumes({"application/json", "application/xml"}) + public ParametersResource.SubscriptionResponse subscribe(@Parameter(description = "idParam") + @QueryParam("id") final String id) { + return null; + } + + static class SubscriptionResponse { + public String subscriptionId; + } +} diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/parameter/RepeatableParametersResource.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/parameter/RepeatableParametersResource.java new file mode 100644 index 0000000000..2626f0c6ac --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/parameter/RepeatableParametersResource.java @@ -0,0 +1,80 @@ +package io.swagger.v3.plugins.gradle.petstore.parameter; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.enums.Explode; +import io.swagger.v3.oas.annotations.enums.ParameterIn; +import io.swagger.v3.oas.annotations.enums.ParameterStyle; +import io.swagger.v3.oas.annotations.media.ArraySchema; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; + +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.Path; + +public class RepeatableParametersResource { + @Path("/repeatableparameter") + @POST + @Parameter(in = ParameterIn.PATH, name = "subscriptionId", required = true, + schema = @Schema(implementation = ParametersResource.SubscriptionResponse.class), style = ParameterStyle.SIMPLE) + @Parameter(in = ParameterIn.QUERY, name = "formId", required = true, + example = "Example") + @Parameter(in = ParameterIn.QUERY, name = "explodeFalse", required = true, explode = Explode.FALSE, + schema = @Schema(implementation = ParametersResource.SubscriptionResponse.class)) + @Parameter(in = ParameterIn.QUERY, name = "explodeTrue", required = true, explode = Explode.TRUE, + schema = @Schema(implementation = ParametersResource.SubscriptionResponse.class)) + @Parameter(in = ParameterIn.QUERY, name = "explodeAvoiding", required = true, explode = Explode.TRUE, + schema = @Schema( + type = "int", + format = "id", + description = "the generated id", + accessMode = Schema.AccessMode.READ_ONLY + )) + @Parameter(in = ParameterIn.QUERY, name = "arrayParameter", required = true, explode = Explode.TRUE, + array = @ArraySchema(maxItems = 10, minItems = 1, + schema = @Schema(implementation = ParametersResource.SubscriptionResponse.class), + uniqueItems = true + ) + , + schema = @Schema( + type = "int", + format = "id", + description = "the generated id", + accessMode = Schema.AccessMode.READ_ONLY), + content = @Content(schema = @Schema(type = "number", + description = "the generated id", + accessMode = Schema.AccessMode.READ_ONLY)) + ) + @Parameter(in = ParameterIn.QUERY, name = "arrayParameterImplementation", required = true, explode = Explode.TRUE, + array = @ArraySchema(maxItems = 10, minItems = 1, + schema = @Schema(implementation = ParametersResource.SubscriptionResponse.class), + uniqueItems = true + ) + ) + @Parameter(in = ParameterIn.QUERY, name = "arrayParameterImplementation2", required = true, explode = Explode.TRUE, + schema = @Schema(implementation = ParametersResource.SubscriptionResponse.class)) + @Operation( + operationId = "subscribe", + description = "subscribes a client to updates relevant to the requestor's account, as " + + "identified by the input token. The supplied url will be used as the delivery address for response payloads", + responses = { + @ApiResponse( + description = "test description", content = @Content( + mediaType = "*/*", + schema = + @Schema( + implementation = ParametersResource.SubscriptionResponse.class) + )) + }) + @Consumes({"application/json", "application/xml"}) + public ParametersResource.SubscriptionResponse subscribe() { + return null; + } + + static class SubscriptionResponse { + public String subscriptionId; + } +} + diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/parameter/SingleJaxRSAnnotatedParameter.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/parameter/SingleJaxRSAnnotatedParameter.java new file mode 100644 index 0000000000..29788cd9eb --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/parameter/SingleJaxRSAnnotatedParameter.java @@ -0,0 +1,20 @@ +package io.swagger.v3.plugins.gradle.petstore.parameter; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.plugins.gradle.resources.model.User; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.QueryParam; + +/** + * Class with a single parameter annotated with jaxrs. + */ +public class SingleJaxRSAnnotatedParameter { + @GET + @Path("/singlejaxrsannotatedparameter") + @Operation(operationId = "create User") + public User findUser(@QueryParam("id") final String id) { + return new User(); + } +} diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/parameter/SingleNotAnnotatedParameter.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/parameter/SingleNotAnnotatedParameter.java new file mode 100644 index 0000000000..a322111708 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/parameter/SingleNotAnnotatedParameter.java @@ -0,0 +1,19 @@ +package io.swagger.v3.plugins.gradle.petstore.parameter; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.plugins.gradle.resources.model.User; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +/** + * Class with a single not annotated parameter. + */ +public class SingleNotAnnotatedParameter { + @GET + @Path("/singlenoannotatedparameter") + @Operation(operationId = "create User") + public User findUser(final String id) { + return new User(); + } +} diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/requestbody/RequestBodyMethodPriorityResource.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/requestbody/RequestBodyMethodPriorityResource.java new file mode 100644 index 0000000000..6e9ee3715b --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/requestbody/RequestBodyMethodPriorityResource.java @@ -0,0 +1,28 @@ +package io.swagger.v3.plugins.gradle.petstore.requestbody; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.parameters.RequestBody; +import io.swagger.v3.plugins.gradle.resources.model.User; + +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.core.Response; + +/** + * Resource with RequestBody inside Operation and another in Method + */ +public class RequestBodyMethodPriorityResource { + @POST + @Path("/requestbodymethodpriority") + @Operation(summary = "Create user", + description = "This can only be done by the logged in user.", + requestBody = @RequestBody(description = "Inside Operation")) + @RequestBody(description = "Created user object on Method", required = true, + content = @Content( + schema = @Schema(implementation = User.class))) + public Response methodWithRequestBodyAndTwoParameters(final User user) { + return Response.ok().entity("").build(); + } +} diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/requestbody/RequestBodyParameterPriorityResource.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/requestbody/RequestBodyParameterPriorityResource.java new file mode 100644 index 0000000000..f76a4781ae --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/requestbody/RequestBodyParameterPriorityResource.java @@ -0,0 +1,29 @@ +package io.swagger.v3.plugins.gradle.petstore.requestbody; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.parameters.RequestBody; +import io.swagger.v3.plugins.gradle.resources.model.User; + +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.core.Response; + +/** + * Resource with RequestBody inside Operation and another in Method + */ +public class RequestBodyParameterPriorityResource { + @POST + @Path("/requestbodyparameterpriority") + @Operation(summary = "Create user", + description = "This can only be done by the logged in user.", + requestBody = @RequestBody(description = "Inside Operation")) + @RequestBody(description = "On method") + public Response methodWithRequestBodyAndTwoParameters( + @RequestBody(description = "Created user object inside Parameter", required = true, + content = @Content( + schema = @Schema(implementation = User.class)))final User user) { + return Response.ok().entity("").build(); + } +} diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/requestbody/RequestBodyResource.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/requestbody/RequestBodyResource.java new file mode 100644 index 0000000000..b2e310e0cc --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/requestbody/RequestBodyResource.java @@ -0,0 +1,113 @@ +package io.swagger.v3.plugins.gradle.petstore.requestbody; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.parameters.RequestBody; +import io.swagger.v3.plugins.gradle.resources.model.Pet; +import io.swagger.v3.plugins.gradle.resources.model.User; + +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Response; + +/** + * Resource with RequestBody examples + */ +public class RequestBodyResource { + @GET + @Path("/methodWithRequestBodyWithoutContent") + @Operation(summary = "Create user", + description = "This can only be done by the logged in user.") + public Response methodWithRequestBodyWithoutContent( + @RequestBody(description = "Created user object", required = true) final User user) { + return Response.ok().entity("").build(); + } + + @GET + @Path("/methodWithRequestBodyWithoutContentWithoutImplementation") + @Operation(summary = "Create user", + description = "This can only be done by the logged in user.") + public Response methodWithRequestBodyWithoutContentWithoutImplementation( + @RequestBody(description = "Created user object", required = true, + content = @Content( + schema = @Schema(name = "User", description = "User description", + example = "User Description", required = true))) final User user) { + return Response.ok().entity("").build(); + } + + @POST + @Path("/methodWithRequestBodyAndTwoParameters") + @Operation(summary = "Create user", + description = "This can only be done by the logged in user.") + public Response methodWithRequestBodyAndTwoParameters( + @RequestBody(description = "Created user object", required = true, + content = @Content( + schema = @Schema(implementation = User.class))) final User user, + @QueryParam("name") final String name, @QueryParam("code") final String code) { + return Response.ok().entity("").build(); + } + + @PUT + @Path("/methodWithRequestBodyWithoutAnnotation") + @Operation(summary = "Modify user", + description = "Modifying user.") + public Response methodWithRequestBodyWithoutAnnotation( + final User user) { + return Response.ok().entity("").build(); + } + + @DELETE + @Path("/methodWithoutRequestBodyAndTwoParameters") + @Operation(summary = "Delete user", + description = "This can only be done by the logged in user.") + public Response methodWithoutRequestBodyAndTwoParameters( + @QueryParam("name") final String name, @QueryParam("code") final String code) { + return Response.ok().entity("").build(); + } + + @PUT + @Path("/methodWithRequestBodyWithoutAnnotationAndTwoConsumes") + @Operation(summary = "Modify pet", + description = "Modifying pet.") + @Consumes({"application/json", "application/xml"}) + public Response methodWithRequestBodyWithoutAnnotationAndTwoConsumes( + final User user) { + return Response.ok().entity("").build(); + } + + @POST + @Path("/methodWithTwoRequestBodyWithoutAnnotationAndTwoConsumes") + @Operation(summary = "Create pet", + description = "Creating pet.") + @Consumes({"application/json", "application/xml"}) + public Response methodWithTwoRequestBodyWithoutAnnotationAndTwoConsumes( + final Pet pet, final User user) { + return Response.ok().entity("").build(); + } + + @POST + @Path("/methodWithTwoRequestBodyWithAnnotationAndTwoConsumes") + @Operation(summary = "Create pet", + description = "Creating pet.") + @Consumes({"application/json", "application/xml"}) + public Response methodWithTwoRequestBodyWithAnnotationAndTwoConsumes( + final @RequestBody(description = "Request Body Pet") Pet pet, + @RequestBody(description = "Request Body User") final User user) { + return Response.ok().entity("").build(); + } + + @DELETE + @Path("/methodWithOneSimpleRequestBody") + @Operation(summary = "Delete pet", + description = "Deleting pet.") + @Consumes({"application/json", "application/xml"}) + public Response methodWithOneSimpleRequestBody(final int id) { + return Response.ok().entity("").build(); + } +} diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/responses/ComplexResponseResource.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/responses/ComplexResponseResource.java new file mode 100644 index 0000000000..db25ec92da --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/responses/ComplexResponseResource.java @@ -0,0 +1,34 @@ +package io.swagger.v3.plugins.gradle.petstore.responses; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.plugins.gradle.resources.exception.NotFoundException; +import io.swagger.v3.plugins.gradle.resources.model.Pet; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +/** + * Resource with some responses + */ +public class ComplexResponseResource { + @GET + @Path("/complexresponse") + @Operation(summary = "Find pets", + description = "Returns the Pets", + responses = { + @ApiResponse(description = "Response inside Operation", responseCode = "200", + content = @Content(schema = + @Schema(implementation = Pet.class))), + @ApiResponse(description = "Default Pet", + content = @Content(schema = + @Schema(name = "Default Pet", description = "Default Pet", + required = true, example = "New Pet"))) + }) + @ApiResponse(responseCode = "404", description = "Couldn't find pet") + public Pet getPets() throws NotFoundException { + return new Pet(); + } +} diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/responses/ImplementationResponseResource.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/responses/ImplementationResponseResource.java new file mode 100644 index 0000000000..779476fc5c --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/responses/ImplementationResponseResource.java @@ -0,0 +1,71 @@ +package io.swagger.v3.plugins.gradle.petstore.responses; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +/** + * Resource with a Response at Method Level + */ +public class ImplementationResponseResource { + @GET + @Path("/implementationresponse") + @Operation( + summary = "Simple get operation", + description = "Defines a simple get operation with no inputs and a complex output object", + operationId = "getWithPayloadResponse", + deprecated = true, + responses = { + @ApiResponse( + responseCode = "200", + description = "voila!", + content = { + @Content( + mediaType = "application/json", + schema = + @Schema( + implementation = ImplementationResponseResource.SampleResponseSchema.class) + ), + @Content( + mediaType = "application/json", + schema = + @Schema( + implementation = ImplementationResponseResource.SecondSampleResponseSchema.class) + ) + } + + ), + @ApiResponse( + responseCode = "400", + description = "boo", + content = @Content( + mediaType = "*/*", + schema = + @Schema(implementation = ImplementationResponseResource.GenericError.class) + ) + ) + } + ) + + public void getResponses() { + } + + static class SampleResponseSchema { + @Schema(description = "the user id") + private String id; + } + + static class SecondSampleResponseSchema { + @Schema(description = "the user id") + private String id; + } + + static class GenericError { + private int code; + private String message; + } +} diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/responses/MethodResponseResource.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/responses/MethodResponseResource.java new file mode 100644 index 0000000000..45eab02a09 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/responses/MethodResponseResource.java @@ -0,0 +1,24 @@ +package io.swagger.v3.plugins.gradle.petstore.responses; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.plugins.gradle.resources.exception.NotFoundException; +import io.swagger.v3.plugins.gradle.resources.model.Pet; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.core.Response; + +/** + * Resource with a Response at Method Level + */ +public class MethodResponseResource { + @GET + @Path("/responseinmethod") + @Operation(summary = "Find pets", + description = "Returns the Pets") + @ApiResponse(responseCode = "200", description = "Status OK") + public Response getPets() throws NotFoundException { + return Response.ok().entity(new Pet()).build(); + } +} diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/responses/NoImplementationResponseResource.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/responses/NoImplementationResponseResource.java new file mode 100644 index 0000000000..a4cea952b1 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/responses/NoImplementationResponseResource.java @@ -0,0 +1,66 @@ +package io.swagger.v3.plugins.gradle.petstore.responses; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.links.Link; +import io.swagger.v3.oas.annotations.links.LinkParameter; +import io.swagger.v3.oas.annotations.responses.ApiResponse; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.QueryParam; + +/** + * Resource with a Response at Method Level + */ +public class NoImplementationResponseResource { + @Path("/noimplementationresponseresource") + @Operation(operationId = "getUser", + responses = { + @ApiResponse(description = "test description", responseCode = "400", + links = { + @Link( + name = "user", + operationId = "getUser", + operationRef = "#/components/links/MyLink", + parameters = @LinkParameter( + name = "userId", + expression = "$request.query.userId")) + }), + @ApiResponse(description = "200 description", responseCode = "200", + links = { + @Link( + name = "pet", + operationId = "getUser", + operationRef = "#/components/links/MyLink", + parameters = @LinkParameter( + name = "userId", + expression = "$request.query.userId")) + }) + } + ) + @GET + public NoImplementationResponseResource.User getUser(@QueryParam("userId") final String userId) { + return null; + } + + static class User { + private String id; + private String username; + + public String getId() { + return id; + } + + public void setId(final String id) { + this.id = id; + } + + public String getUsername() { + return username; + } + + public void setUsername(final String username) { + this.username = username; + } + } +} diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/responses/NoResponseResource.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/responses/NoResponseResource.java new file mode 100644 index 0000000000..432b452a53 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/responses/NoResponseResource.java @@ -0,0 +1,21 @@ +package io.swagger.v3.plugins.gradle.petstore.responses; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.plugins.gradle.resources.exception.NotFoundException; +import io.swagger.v3.plugins.gradle.resources.model.User; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +/** + * Resource with a Response at Method Level + */ +public class NoResponseResource { + @GET + @Path("/noresponse") + @Operation(summary = "Find pets", + description = "Returns the Pets") + public User getPets() throws NotFoundException { + return new User(); + } +} diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/responses/OperationResponseResource.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/responses/OperationResponseResource.java new file mode 100644 index 0000000000..38cbbc426e --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/responses/OperationResponseResource.java @@ -0,0 +1,25 @@ +package io.swagger.v3.plugins.gradle.petstore.responses; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.plugins.gradle.resources.exception.NotFoundException; +import io.swagger.v3.plugins.gradle.resources.model.User; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.core.Response; + +/** + * Resource with the response in the Operation Annotation + */ +public class OperationResponseResource { + @GET + @Path("/responseinoperation") + @Operation(summary = "Find Users", + description = "Returns the Users", + responses = {@ApiResponse(responseCode = "200", description = "Status OK")}) + public Response getUsers() throws NotFoundException { + return Response.ok().entity(new User()).build(); + } + +} diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/responses/PriorityResponseResource.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/responses/PriorityResponseResource.java new file mode 100644 index 0000000000..f14c1ff364 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/responses/PriorityResponseResource.java @@ -0,0 +1,25 @@ +package io.swagger.v3.plugins.gradle.petstore.responses; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.plugins.gradle.resources.exception.NotFoundException; +import io.swagger.v3.plugins.gradle.resources.model.Pet; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.core.Response; + +/** + * Resource with a Response at Method Level and Operation Level. + */ +public class PriorityResponseResource { + @GET + @Path("/priorityresponses") + @Operation(summary = "Find pets", + description = "Returns the Pets", + responses = {@ApiResponse(responseCode = "200", description = "Inside Operation Response")}) + @ApiResponse(responseCode = "200", description = "Inside Method Operation") + public Response getPets() throws NotFoundException { + return Response.ok().entity(new Pet()).build(); + } +} diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/security/SecurityResource.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/security/SecurityResource.java new file mode 100644 index 0000000000..b24bf3db65 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/security/SecurityResource.java @@ -0,0 +1,61 @@ +package io.swagger.v3.plugins.gradle.petstore.security; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.enums.SecuritySchemeIn; +import io.swagger.v3.oas.annotations.enums.SecuritySchemeType; +import io.swagger.v3.oas.annotations.security.OAuthFlow; +import io.swagger.v3.oas.annotations.security.OAuthFlows; +import io.swagger.v3.oas.annotations.security.OAuthScope; +import io.swagger.v3.oas.annotations.security.SecurityRequirement; +import io.swagger.v3.oas.annotations.security.SecurityScheme; + +import javax.ws.rs.GET; +import javax.ws.rs.PATCH; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; + +@SecurityScheme(name = "myOauth2Security", + type = SecuritySchemeType.OAUTH2, + in = SecuritySchemeIn.HEADER, + description = "myOauthSecurity Description", + flows = @OAuthFlows(implicit = @OAuthFlow(authorizationUrl = "http://x.com", + scopes = @OAuthScope( + name = "write:pets", + description = "modify pets in your account")) + ) +) +@SecurityRequirement(name = "security_key", + scopes = {"write:pets", "read:pets"} +) +@SecurityRequirement(name = "myOauth2Security", + scopes = {"write:pets"} +) +@Path("/security") +public class SecurityResource { + @GET + @Operation(operationId = "Operation Id", + description = "description") + @SecurityRequirement(name = "security_key", + scopes = {"write:pets", "read:pets"} + ) + public void getSecurity() { + } + + @PATCH + @Operation(operationId = "Operation Id 2", + description = "description 2") + @SecurityRequirement(name = "security_key2", + scopes = {"write:pets", "read:pets"} + ) + public void getSecurity2() { + } + + @PUT + @Operation(operationId = "Operation Id 3", + description = "description 3", security = + @SecurityRequirement(name = "security_key3", + scopes = {"write:pets", "read:pets"} + )) + public void setSecurity(String security) { + } +} diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/tags/CompleteTagResource.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/tags/CompleteTagResource.java new file mode 100644 index 0000000000..a643d76982 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/tags/CompleteTagResource.java @@ -0,0 +1,31 @@ +package io.swagger.v3.plugins.gradle.petstore.tags; + +import io.swagger.v3.oas.annotations.ExternalDocumentation; +import io.swagger.v3.oas.annotations.OpenAPIDefinition; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.core.Response; + +@OpenAPIDefinition(tags = { + @Tag(name = "Definition First Tag"), + @Tag(name = "Definition Second Tag full", description = "desc definition") +}) +@Tag(name = "Second Tag") +@Tag(name = "Fourth Tag Full", description = "desc class", externalDocs = @ExternalDocumentation(description = "docs desc class")) +@Tag(name = "Fifth Tag Full", description = "desc class", externalDocs = @ExternalDocumentation(description = "docs desc class")) +@Tag(name = "Sixth Tag") +public class CompleteTagResource { + + @GET + @Path("/completetags") + @Operation(tags = {"Example Tag", "Second Tag"}) + @Tag(name = "Third Tag") + @Tag(name = "Second Tag") + @Tag(name = "Fourth Tag Full", description = "desc", externalDocs = @ExternalDocumentation(description = "docs desc")) + public Response getTags() { + return Response.ok().entity("ok").build(); + } +} diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/tags/TagClassResource.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/tags/TagClassResource.java new file mode 100644 index 0000000000..96e3611d62 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/tags/TagClassResource.java @@ -0,0 +1,14 @@ +package io.swagger.v3.plugins.gradle.petstore.tags; + +import io.swagger.v3.oas.annotations.ExternalDocumentation; +import io.swagger.v3.oas.annotations.tags.Tag; + +/** + * Class with Tag Annotations at Class level + */ +@Tag(name = "Second Tag") +@Tag(name = "Fourth Tag Full", description = "desc class", externalDocs = @ExternalDocumentation(description = "docs desc class")) +@Tag(name = "Fifth Tag Full", description = "desc class", externalDocs = @ExternalDocumentation(description = "docs desc class")) +@Tag(name = "Sixth Tag") +public class TagClassResource { +} diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/tags/TagMethodResource.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/tags/TagMethodResource.java new file mode 100644 index 0000000000..c4c65f146c --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/tags/TagMethodResource.java @@ -0,0 +1,19 @@ +package io.swagger.v3.plugins.gradle.petstore.tags; + +import io.swagger.v3.oas.annotations.ExternalDocumentation; +import io.swagger.v3.oas.annotations.tags.Tag; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.core.Response; + +public class TagMethodResource { + @GET + @Path("/tagsinmethod") + @Tag(name = "Third Tag") + @Tag(name = "Second Tag") + @Tag(name = "Fourth Tag Full", description = "desc", externalDocs = @ExternalDocumentation(description = "docs desc")) + public Response getTags() { + return Response.ok().entity("ok").build(); + } +} diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/tags/TagOpenAPIDefinitionResource.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/tags/TagOpenAPIDefinitionResource.java new file mode 100644 index 0000000000..0362a7fba5 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/tags/TagOpenAPIDefinitionResource.java @@ -0,0 +1,14 @@ +package io.swagger.v3.plugins.gradle.petstore.tags; + +import io.swagger.v3.oas.annotations.OpenAPIDefinition; +import io.swagger.v3.oas.annotations.tags.Tag; + +/** + * Tag in the OpenAPIDefinition annotation + */ +@OpenAPIDefinition(tags = { + @Tag(name = "Definition First Tag"), + @Tag(name = "Definition Second Tag full", description = "desc definition") +}) +public class TagOpenAPIDefinitionResource { +} diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/tags/TagOperationResource.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/tags/TagOperationResource.java new file mode 100644 index 0000000000..58d67f1b1c --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/petstore/tags/TagOperationResource.java @@ -0,0 +1,20 @@ +package io.swagger.v3.plugins.gradle.petstore.tags; + +import io.swagger.v3.oas.annotations.Operation; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.core.Response; + +/** + * Resource with a Tag at Operation Level + */ +public class TagOperationResource { + + @GET + @Path("/tagoperation") + @Operation(tags = {"Example Tag", "Second Tag"}) + public Response getTags() { + return Response.ok().entity("ok").build(); + } +} diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/resources/QueryResultBean.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/resources/QueryResultBean.java new file mode 100644 index 0000000000..4ce4ed7528 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/resources/QueryResultBean.java @@ -0,0 +1,43 @@ +/** + * Copyright 2016 SmartBear Software + *

+ * 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.swagger.v3.plugins.gradle.resources; + +import javax.ws.rs.QueryParam; + +public class QueryResultBean { + @QueryParam("skip") + private Integer skip; + + @QueryParam("limit") + private Integer limit; + + public Integer getSkip() { + return skip; + } + + public void setSkip(Integer skip) { + this.skip = skip; + } + + public Integer getLimit() { + return limit; + } + + public void setLimit(Integer limit) { + this.limit = limit; + } +} diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/resources/data/PetData.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/resources/data/PetData.java new file mode 100644 index 0000000000..e221796180 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/resources/data/PetData.java @@ -0,0 +1,151 @@ +/** + * Copyright 2016 SmartBear Software + *

+ * 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.swagger.v3.plugins.gradle.resources.data; + +import io.swagger.v3.plugins.gradle.resources.model.Category; +import io.swagger.v3.plugins.gradle.resources.model.Pet; +import io.swagger.v3.plugins.gradle.resources.model.Tag; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +public class PetData { + static List pets = new ArrayList(); + static List categories = new ArrayList(); + + static { + categories.add(createCategory(1, "Dogs")); + categories.add(createCategory(2, "Cats")); + categories.add(createCategory(3, "Rabbits")); + categories.add(createCategory(4, "Lions")); + + pets.add(createPet(1, categories.get(1), "Cat 1", new String[]{ + "url1", "url2"}, new String[]{"tag1", "tag2"}, "available")); + pets.add(createPet(2, categories.get(1), "Cat 2", new String[]{ + "url1", "url2"}, new String[]{"tag2", "tag3"}, "available")); + pets.add(createPet(3, categories.get(1), "Cat 3", new String[]{ + "url1", "url2"}, new String[]{"tag3", "tag4"}, "pending")); + + pets.add(createPet(4, categories.get(0), "Dog 1", new String[]{ + "url1", "url2"}, new String[]{"tag1", "tag2"}, "available")); + pets.add(createPet(5, categories.get(0), "Dog 2", new String[]{ + "url1", "url2"}, new String[]{"tag2", "tag3"}, "sold")); + pets.add(createPet(6, categories.get(0), "Dog 3", new String[]{ + "url1", "url2"}, new String[]{"tag3", "tag4"}, "pending")); + + pets.add(createPet(7, categories.get(3), "Lion 1", new String[]{ + "url1", "url2"}, new String[]{"tag1", "tag2"}, "available")); + pets.add(createPet(8, categories.get(3), "Lion 2", new String[]{ + "url1", "url2"}, new String[]{"tag2", "tag3"}, "available")); + pets.add(createPet(9, categories.get(3), "Lion 3", new String[]{ + "url1", "url2"}, new String[]{"tag3", "tag4"}, "available")); + + pets.add(createPet(10, categories.get(2), "Rabbit 1", new String[]{ + "url1", "url2"}, new String[]{"tag3", "tag4"}, "available")); + } + + public Pet getPetById(long petId) { + for (Pet pet : pets) { + if (pet.getId() == petId) { + return pet; + } + } + return null; + } + + public List findPetByStatus(String status) { + String[] statues = status.split(","); + List result = new ArrayList(); + for (Pet pet : pets) { + for (String s : statues) { + if (s.equals(pet.getStatus())) { + result.add(pet); + } + } + } + return result; + } + + public List findPetByCategory(Category category) { + return pets.stream().filter(pet -> category.equals(pet.getCategory())).collect(Collectors.toList()); + } + + public List findPetByTags(String tags) { + String[] tagList = tags.split(","); + List result = new ArrayList(); + for (Pet pet : pets) { + if (null != pet.getTags()) { + for (Tag tag : pet.getTags()) { + for (String tagListString : tagList) { + if (tagListString.equals(tag.getName())) { + result.add(pet); + } + } + } + } + } + return result; + } + + public void addPet(Pet pet) { + if (pets.size() > 0) { + for (int i = pets.size() - 1; i >= 0; i--) { + if (pets.get(i).getId() == pet.getId()) { + pets.remove(i); + } + } + } + pets.add(pet); + } + + static Pet createPet(long id, Category cat, String name, String[] urls, + String[] tags, String status) { + Pet pet = new Pet(); + pet.setId(id); + pet.setCategory(cat); + pet.setName(name); + if (null != urls) { + List urlObjs = new ArrayList(); + for (String urlString : urls) { + urlObjs.add(urlString); + } + pet.setPhotoUrls(urlObjs); + } + List tagObjs = new ArrayList(); + int i = 0; + if (null != tags) { + for (String tagString : tags) { + i = i + 1; + Tag tag = new Tag(); + tag.setId(i); + tag.setName(tagString); + tagObjs.add(tag); + } + } + pet.setTags(tagObjs); + pet.setStatus(status); + return pet; + } + + static Category createCategory(long id, String name) { + Category category = new Category(); + category.setId(id); + category.setName(name); + return category; + } +} \ No newline at end of file diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/resources/data/UserData.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/resources/data/UserData.java new file mode 100644 index 0000000000..a23afc1ded --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/resources/data/UserData.java @@ -0,0 +1,98 @@ +/** + * Copyright 2016 SmartBear Software + *

+ * 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.swagger.v3.plugins.gradle.resources.data; + +import io.swagger.v3.plugins.gradle.resources.model.User; + +import java.util.ArrayList; +import java.util.List; + +public class UserData { + static List users = new ArrayList(); + + static { + users.add(createUser(1, "user1", "first name 1", "last name 1", + "email1@test.com", "123-456-7890", 1)); + users.add(createUser(2, "user2", "first name 2", "last name 2", + "email2@test.com", "123-456-7890", 2)); + users.add(createUser(3, "user3", "first name 3", "last name 3", + "email3@test.com", "123-456-7890", 3)); + users.add(createUser(4, "user4", "first name 4", "last name 4", + "email4@test.com", "123-456-7890", 1)); + users.add(createUser(5, "user5", "first name 5", "last name 5", + "email5@test.com", "123-456-7890", 2)); + users.add(createUser(6, "user6", "first name 6", "last name 6", + "email6@test.com", "123-456-7890", 3)); + users.add(createUser(7, "user7", "first name 7", "last name 7", + "email7@test.com", "123-456-7890", 1)); + users.add(createUser(8, "user8", "first name 8", "last name 8", + "email8@test.com", "123-456-7890", 2)); + users.add(createUser(9, "user9", "first name 9", "last name 9", + "email9@test.com", "123-456-7890", 3)); + users.add(createUser(10, "user10", "first name 10", "last name 10", + "email10@test.com", "123-456-7890", 1)); + users.add(createUser(11, "user?10", "first name ?10", "last name ?10", + "email101@test.com", "123-456-7890", 1)); + + } + + public User findUserByName(String username) { + for (User user : users) { + if (user.getUsername().equals(username)) { + return user; + } + } + return null; + } + + public void addUser(User user) { + if (users.size() > 0) { + for (int i = users.size() - 1; i >= 0; i--) { + if (users.get(i).getUsername().equals(user.getUsername())) { + users.remove(i); + } + } + } + users.add(user); + } + + public boolean removeUser(String username) { + if (users.size() > 0) { + for (int i = users.size() - 1; i >= 0; i--) { + if (users.get(i).getUsername().equals(username)) { + users.remove(i); + return true; + } + } + } + return false; + } + + private static User createUser(long id, String username, String firstName, + String lastName, String email, String phone, int userStatus) { + User user = new User(); + user.setId(id); + user.setUsername(username); + user.setFirstName(firstName); + user.setLastName(lastName); + user.setEmail(email); + user.setPassword("XXXXXXXXXXX"); + user.setPhone(phone); + user.setUserStatus(userStatus); + return user; + } +} \ No newline at end of file diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/resources/exception/ApiException.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/resources/exception/ApiException.java new file mode 100644 index 0000000000..5fd6be63d7 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/resources/exception/ApiException.java @@ -0,0 +1,26 @@ +/** + * Copyright 2016 SmartBear Software + *

+ * 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.swagger.v3.plugins.gradle.resources.exception; + +public class ApiException extends Exception { + private int code; + + public ApiException(int code, String msg) { + super(msg); + this.code = code; + } +} diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/resources/exception/NotFoundException.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/resources/exception/NotFoundException.java new file mode 100644 index 0000000000..545e6a9940 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/resources/exception/NotFoundException.java @@ -0,0 +1,26 @@ +/** + * Copyright 2016 SmartBear Software + *

+ * 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.swagger.v3.plugins.gradle.resources.exception; + +public class NotFoundException extends ApiException { + private int code; + + public NotFoundException(int code, String msg) { + super(code, msg); + this.code = code; + } +} diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/resources/model/Category.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/resources/model/Category.java new file mode 100644 index 0000000000..a973cb86d4 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/resources/model/Category.java @@ -0,0 +1,51 @@ +/** + * Copyright 2016 SmartBear Software + *

+ * 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.swagger.v3.plugins.gradle.resources.model; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement(name = "Category") +public class Category { + private long id; + private String name; + + @XmlElement(name = "id") + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + @XmlElement(name = "name") + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Category() { + } + + public Category(String name) { + this.name = name; + } +} \ No newline at end of file diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/resources/model/CustomGenerator.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/resources/model/CustomGenerator.java new file mode 100644 index 0000000000..c41bf37d3b --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/resources/model/CustomGenerator.java @@ -0,0 +1,32 @@ +package io.swagger.v3.plugins.gradle.resources.model; + +import com.fasterxml.jackson.annotation.ObjectIdGenerator; +import com.fasterxml.jackson.annotation.ObjectIdGenerators; + +public class CustomGenerator extends ObjectIdGenerators.PropertyGenerator { + private static final long serialVersionUID = 1L; + + protected CustomGenerator(Class scope) { + super(scope); + } + + @Override + public ObjectIdGenerator forScope(Class scope) { + return null; + } + + @Override + public ObjectIdGenerator newForSerialization(Object context) { + return null; + } + + @Override + public IdKey key(Object key) { + return null; + } + + @Override + public Object generateId(Object forPojo) { + return null; + } +} \ No newline at end of file diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/resources/model/ExtensionUser.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/resources/model/ExtensionUser.java new file mode 100644 index 0000000000..9615b3b170 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/resources/model/ExtensionUser.java @@ -0,0 +1,130 @@ +/** + * Copyright 2016 SmartBear Software + *

+ * 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.swagger.v3.plugins.gradle.resources.model; + +import io.swagger.v3.oas.annotations.extensions.Extension; +import io.swagger.v3.oas.annotations.extensions.ExtensionProperty; +import io.swagger.v3.oas.annotations.media.Schema; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement(name = "User") +@Schema( + description = "User", + extensions = { + @Extension(name = "x-user", properties = { + @ExtensionProperty(name = "name", value = "Josh")}), + @Extension(name = "user-extensions", properties = { + @ExtensionProperty(name = "lastName", value = "Hart"), + @ExtensionProperty(name = "address", value = "House")}) + } +) +public class ExtensionUser { + private long id; + private String username; + private String firstName; + private String lastName; + private String email; + private String password; + private String phone; + private int userStatus; + + @XmlElement(name = "id") + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + @XmlElement(name = "firstName") + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + @XmlElement(name = "username") + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + @XmlElement(name = "lastName") + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + @XmlElement(name = "email") + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + @XmlElement(name = "password") + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + @XmlElement(name = "phone") + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + @XmlElement(name = "userStatus") + //@Schema(description = "User Status", type = "string", allowableValues = {"1-registered", "2-active", "3-closed"}) + @Schema( + description = "User Status", + allowableValues = "1-registered,2-active,3-closed", + extensions = { + @Extension(name = "x-userStatus", properties = { + @ExtensionProperty(name = "name", value = "Josh")}), + @Extension(name = "userStatus-extensions", properties = { + @ExtensionProperty(name = "lastName", value = "Hart"), + @ExtensionProperty(name = "address", value = "House")}) + } + ) + public int getUserStatus() { + return userStatus; + } + + public void setUserStatus(int userStatus) { + this.userStatus = userStatus; + } +} \ No newline at end of file diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/resources/model/JacksonBean.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/resources/model/JacksonBean.java new file mode 100644 index 0000000000..6ab65aa81a --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/resources/model/JacksonBean.java @@ -0,0 +1,76 @@ +package io.swagger.v3.plugins.gradle.resources.model; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonUnwrapped; +import com.fasterxml.jackson.annotation.JsonValue; + +public class JacksonBean { + + private String id; + private String ignored; + private StringValueBean bean; + private NotFoundModel model; + private NotFoundModel model2; + + @JsonIgnore + public String getIgnored() { + return ignored; + } + + public void setIgnored(String ignored) { + this.ignored = ignored; + } + + public void setId(String id) { + this.id = id; + } + + public void setModel(NotFoundModel model) { + this.model = model; + } + + public StringValueBean getBean() { + return bean; + } + + public void setBean(StringValueBean bean) { + this.bean = bean; + } + + @JsonProperty("identity") + public String getId() { + return id; + } + + @JsonUnwrapped + public NotFoundModel getModel() { + return model; + } + + @JsonUnwrapped(prefix = "pre", suffix = "suf") + public NotFoundModel getModel2() { + return model2; + } + + public void setModel2(NotFoundModel model2) { + this.model2 = model2; + } + + public static class StringValueBean { + + private final String value; + + @JsonCreator + public StringValueBean(String value) { + this.value = value; + } + + @JsonValue + public String getValue() { + return value; + } + } + +} diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/resources/model/ListOfStringsBeanParam.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/resources/model/ListOfStringsBeanParam.java new file mode 100644 index 0000000000..d002e3c4ff --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/resources/model/ListOfStringsBeanParam.java @@ -0,0 +1,17 @@ +package io.swagger.v3.plugins.gradle.resources.model; + +import javax.ws.rs.QueryParam; +import java.util.List; + +public class ListOfStringsBeanParam { + @QueryParam(value = "listOfStrings") + private List list; + + public List getList() { + return list; + } + + public void setList(List list) { + this.list = list; + } +} \ No newline at end of file diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/resources/model/ModelWithJsonIdentity.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/resources/model/ModelWithJsonIdentity.java new file mode 100644 index 0000000000..72470ea57f --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/resources/model/ModelWithJsonIdentity.java @@ -0,0 +1,145 @@ +package io.swagger.v3.plugins.gradle.resources.model; + +import com.fasterxml.jackson.annotation.JsonIdentityInfo; +import com.fasterxml.jackson.annotation.JsonIdentityReference; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.ObjectIdGenerators; + +public class ModelWithJsonIdentity { + + @JsonIdentityReference(alwaysAsId = true) + @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "name") + @JsonProperty("PropertyGeneratorAsId") + public SourceDefinition1 testPropertyGeneratorAsId; + + @JsonIdentityReference(alwaysAsId = false) + @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "name") + @JsonProperty("PropertyGeneratorAsProperty") + public SourceDefinition1 testPropertyGeneratorAsProperty; + + public class SourceDefinition1 { + public String driver; + public String name; + } + + @JsonIdentityReference(alwaysAsId = true) + @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "driverId") + @JsonProperty("ChangedPropertyName") + public SourceDefinition2 testChangedPropertyName; + + @JsonIdentityReference(alwaysAsId = true) + @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "driverId") + @JsonProperty("ChangedPropertyName2") + public SourceDefinition2 testChangedPropertyName2; + + static public class SourceDefinition2 { + @JsonProperty("driverId") + public String driver; + public String name; + } + + @JsonIdentityReference(alwaysAsId = true) + @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class) + @JsonProperty("SourceWithoutPropertyAsId") + public SourceDefinition3 testWithoutPropertyAsId; + + @JsonIdentityReference(alwaysAsId = false) + @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class) + @JsonProperty("SourceWithoutPropertyAsProperty") + public SourceDefinition3 testWithoutPropertyAsProperty; + + public class SourceDefinition3 { + @JsonProperty("driverId") + public String driver; + public String name; + + @JsonProperty("@id") + public String id; + } + + @JsonIdentityReference(alwaysAsId = true) + @JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class, property = "testName1") + @JsonProperty("IntSequenceGeneratorAsId") + public SourceDefinition4 testIntSequenceGeneratorAsId; + + @JsonIdentityReference(alwaysAsId = false) + @JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class, property = "testName2") + @JsonProperty("IntSequenceGeneratorAsProperty") + public SourceDefinition4 testIntSequenceGeneratorAsProperty; + + public class SourceDefinition4 { + public String name; + } + + @JsonIdentityReference(alwaysAsId = true) + @JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class) + @JsonProperty("IntSequenceWithoutPropertyAsId") + public SourceDefinition5 testIntSequenceWithoutPropertyAsId; + + @JsonIdentityReference(alwaysAsId = false) + @JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class) + @JsonProperty("IntSequenceWithoutPropertyAsProperty") + public SourceDefinition5 testIntSequenceWithoutPropertyAsProperty; + + public class SourceDefinition5 { + public String name; + } + + @JsonIdentityReference(alwaysAsId = true) + @JsonIdentityInfo(generator = ObjectIdGenerators.UUIDGenerator.class, property = "UUID1") + @JsonProperty("UUIDGeneratorAsId") + public SourceDefinition6 testUUIDGeneratorAsId; + + @JsonIdentityReference(alwaysAsId = false) + @JsonIdentityInfo(generator = ObjectIdGenerators.UUIDGenerator.class, property = "UUID2") + @JsonProperty("UUIDGeneratorAsProperty") + public SourceDefinition6 testUUIDGeneratorAsProperty; + + public class SourceDefinition6 { + public String name; + } + + @JsonIdentityReference(alwaysAsId = true) + @JsonIdentityInfo(generator = ObjectIdGenerators.UUIDGenerator.class) + @JsonProperty("UUIDGeneratorWithoutPropertyAsId") + public SourceDefinition7 testUUIDGeneratorWithoutPropertyAsId; + + @JsonIdentityReference(alwaysAsId = false) + @JsonIdentityInfo(generator = ObjectIdGenerators.UUIDGenerator.class) + @JsonProperty("UUIDGeneratorWithoutPropertyAsProperty") + public SourceDefinition7 testUUIDGeneratorWithoutPropertyAsProperty; + + public class SourceDefinition7 { + public String name; + } + + @JsonIdentityReference(alwaysAsId = true) + @JsonIdentityInfo(generator = ObjectIdGenerators.None.class, property = "testGeneratorsNone") + @JsonProperty("GeneratorsNone") + public SourceDefinition8 testGeneratorsNone; + + public class SourceDefinition8 { + @JsonProperty("driverId") + public String driver; + public String name; + } + + @JsonIdentityReference(alwaysAsId = true) + @JsonIdentityInfo(generator = CustomGenerator.class, property = "name") + @JsonProperty("CustomGenerator") + public SourceDefinition9 testCustomGenerator; + + public class SourceDefinition9 { + public String driver; + public String name; + } + + @JsonIdentityInfo(generator = CustomGenerator.class, property = "name") + @JsonProperty("WithoutJsonIdentityReference") + public SourceDefinition10 testWithoutJsonIdentityReference; + + public class SourceDefinition10 { + public String driver; + public String name; + } +} \ No newline at end of file diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/resources/model/ModelWithJsonIdentityCyclic.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/resources/model/ModelWithJsonIdentityCyclic.java new file mode 100644 index 0000000000..e20f5fcf95 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/resources/model/ModelWithJsonIdentityCyclic.java @@ -0,0 +1,29 @@ +package io.swagger.v3.plugins.gradle.resources.model; + +import com.fasterxml.jackson.annotation.JsonIdentityInfo; +import com.fasterxml.jackson.annotation.JsonIdentityReference; +import com.fasterxml.jackson.annotation.ObjectIdGenerators; + +import java.util.List; + +public class ModelWithJsonIdentityCyclic { + + public Long id; + + public List sourceDefinitions; + + @JsonIdentityInfo( + generator = ObjectIdGenerators.PropertyGenerator.class, + property = "name") + public static class SourceDefinition { + public String driver; + public String name; + + @JsonIdentityReference(alwaysAsId=true) + @JsonIdentityInfo( + generator = ObjectIdGenerators.PropertyGenerator.class, + property = "id") + public ModelWithJsonIdentityCyclic model; + } + +} \ No newline at end of file diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/resources/model/MultipleBaseBean.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/resources/model/MultipleBaseBean.java new file mode 100644 index 0000000000..0d5966fa1e --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/resources/model/MultipleBaseBean.java @@ -0,0 +1,11 @@ +package io.swagger.v3.plugins.gradle.resources.model; + +@io.swagger.v3.oas.annotations.media.Schema( + description = "MultipleBaseBean", + subTypes = { MultipleSub1Bean.class, MultipleSub2Bean.class } +) +public class MultipleBaseBean { + public String beanType; + public int a; + public String b; +} \ No newline at end of file diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/resources/model/MultipleSub1Bean.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/resources/model/MultipleSub1Bean.java new file mode 100644 index 0000000000..c1a03258d0 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/resources/model/MultipleSub1Bean.java @@ -0,0 +1,8 @@ +package io.swagger.v3.plugins.gradle.resources.model; + +@io.swagger.v3.oas.annotations.media.Schema( + description = "MultipleSub1Bean" +) +public class MultipleSub1Bean extends MultipleBaseBean { + public int c; +} \ No newline at end of file diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/resources/model/MultipleSub2Bean.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/resources/model/MultipleSub2Bean.java new file mode 100644 index 0000000000..763e5f0454 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/resources/model/MultipleSub2Bean.java @@ -0,0 +1,8 @@ +package io.swagger.v3.plugins.gradle.resources.model; + +@io.swagger.v3.oas.annotations.media.Schema( + description = "MultipleSub2Bean" +) +public class MultipleSub2Bean extends MultipleBaseBean { + public int d; +} \ No newline at end of file diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/resources/model/NotFoundModel.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/resources/model/NotFoundModel.java new file mode 100644 index 0000000000..73e0b3f95c --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/resources/model/NotFoundModel.java @@ -0,0 +1,30 @@ +package io.swagger.v3.plugins.gradle.resources.model; + +public class NotFoundModel { + int code; + String message; + + public NotFoundModel() { + } + + public NotFoundModel(int code, String message) { + this.code = code; + this.message = message; + } + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } +} diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/resources/model/Pet.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/resources/model/Pet.java new file mode 100644 index 0000000000..0cf61e4857 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/resources/model/Pet.java @@ -0,0 +1,76 @@ +package io.swagger.v3.plugins.gradle.resources.model; + +import io.swagger.v3.oas.annotations.media.Schema; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElementWrapper; +import javax.xml.bind.annotation.XmlRootElement; +import java.util.ArrayList; +import java.util.List; + +@XmlRootElement(name = "Pet") +public class Pet { + private long id; + private Category category; + private String name; + private List photoUrls = new ArrayList(); + private List tags = new ArrayList(); + private String status; + + @XmlElement(name = "id") + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + @XmlElement(name = "category") + public Category getCategory() { + return category; + } + + public void setCategory(Category category) { + this.category = category; + } + + @XmlElement(name = "name") + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @XmlElementWrapper(name = "photoUrls") + @XmlElement(name = "photoUrl") + public List getPhotoUrls() { + return photoUrls; + } + + public void setPhotoUrls(List photoUrls) { + this.photoUrls = photoUrls; + } + + @XmlElementWrapper(name = "tags") + @XmlElement(name = "tag") + public List getTags() { + return tags; + } + + public void setTags(List tags) { + this.tags = tags; + } + + @XmlElement(name = "status") + @Schema(description = "pet status in the store", allowableValues = "available,pending,sold") + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } +} diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/resources/model/Tag.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/resources/model/Tag.java new file mode 100644 index 0000000000..107de03ebf --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/resources/model/Tag.java @@ -0,0 +1,44 @@ +/** + * Copyright 2016 SmartBear Software + *

+ * 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.swagger.v3.plugins.gradle.resources.model; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement(name = "Tag") +public class Tag { + private long id; + private String name; + + @XmlElement(name = "id") + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + @XmlElement(name = "name") + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} \ No newline at end of file diff --git a/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/resources/model/User.java b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/resources/model/User.java new file mode 100644 index 0000000000..ae67103476 --- /dev/null +++ b/modules/swagger-gradle-plugin/src/test/javatest/io/swagger/v3/plugins/gradle/resources/model/User.java @@ -0,0 +1,108 @@ +/** + * Copyright 2016 SmartBear Software + *

+ * 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.swagger.v3.plugins.gradle.resources.model; + +import io.swagger.v3.oas.annotations.media.Schema; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement(name = "User") +public class User { + private long id; + private String username; + private String firstName; + private String lastName; + private String email; + private String password; + private String phone; + private int userStatus; + + @XmlElement(name = "id") + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + @XmlElement(name = "firstName") + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + @XmlElement(name = "username") + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + @XmlElement(name = "lastName") + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + @XmlElement(name = "email") + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + @XmlElement(name = "password") + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + @XmlElement(name = "phone") + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + @XmlElement(name = "userStatus") + //@Schema(description = "User Status", type = "string", allowableValues = {"1-registered", "2-active", "3-closed"}) + @Schema(description = "User Status", allowableValues = "1-registered,2-active,3-closed") + public int getUserStatus() { + return userStatus; + } + + public void setUserStatus(int userStatus) { + this.userStatus = userStatus; + } +} \ No newline at end of file diff --git a/modules/swagger-jaxrs2/src/main/java/io/swagger/v3/jaxrs2/integration/SwaggerLoader.java b/modules/swagger-jaxrs2/src/main/java/io/swagger/v3/jaxrs2/integration/SwaggerLoader.java new file mode 100644 index 0000000000..7e18db375c --- /dev/null +++ b/modules/swagger-jaxrs2/src/main/java/io/swagger/v3/jaxrs2/integration/SwaggerLoader.java @@ -0,0 +1,183 @@ +package io.swagger.v3.jaxrs2.integration; + +import io.swagger.v3.core.util.Json; +import io.swagger.v3.core.util.Yaml; +import io.swagger.v3.oas.integration.OpenApiConfigurationException; +import io.swagger.v3.oas.integration.SwaggerConfiguration; +import io.swagger.v3.oas.models.OpenAPI; +import org.apache.commons.lang3.StringUtils; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +public class SwaggerLoader { + + private String outputFormat; + + private String resourcePackages; + private String resourceClasses; + private String filterClass; + private String readerClass; + private String scannerClass; + private Boolean prettyPrint = false; + private Boolean readAllResources = Boolean.TRUE; + private String ignoredRoutes; + + private String openapiAsString; + + public String getOutputFormat() { + return outputFormat; + } + + public void setOutputFormat(String outputFormat) { + this.outputFormat = outputFormat; + } + + public String getResourcePackages() { + return resourcePackages; + } + + public void setResourcePackages(String resourcePackages) { + this.resourcePackages = resourcePackages; + } + + public String getResourceClasses() { + return resourceClasses; + } + + public void setResourceClasses(String resourceClasses) { + this.resourceClasses = resourceClasses; + } + + public String getFilterClass() { + return filterClass; + } + + public void setFilterClass(String filterClass) { + this.filterClass = filterClass; + } + + public String getReaderClass() { + return readerClass; + } + + public void setReaderClass(String readerClass) { + this.readerClass = readerClass; + } + + public String getScannerClass() { + return scannerClass; + } + + public void setScannerClass(String scannerClass) { + this.scannerClass = scannerClass; + } + + public Boolean getPrettyPrint() { + return prettyPrint; + } + + public void setPrettyPrint(Boolean prettyPrint) { + this.prettyPrint = prettyPrint; + } + + public Boolean getReadAllResources() { + return readAllResources; + } + + public void setReadAllResources(Boolean readAllResources) { + this.readAllResources = readAllResources; + } + + public String getIgnoredRoutes() { + return ignoredRoutes; + } + + public void setIgnoredRoutes(String ignoredRoutes) { + this.ignoredRoutes = ignoredRoutes; + } + + public String getOpenapiAsString() { + return openapiAsString; + } + + public void setOpenapiAsString(String openapiAsString) { + this.openapiAsString = openapiAsString; + } + + + public Map resolve() throws Exception{ + + Set ignoredRoutesSet = null; + if (StringUtils.isNotBlank(ignoredRoutes)) { + ignoredRoutesSet = new HashSet<>(Arrays.asList(ignoredRoutes.split(","))); + } + Set resourceClassesSet = null; + if (StringUtils.isNotBlank(resourceClasses)) { + resourceClassesSet = new HashSet<>(Arrays.asList(resourceClasses.split(","))); + } + Set resourcePackagesSet = null; + if (StringUtils.isNotBlank(resourcePackages)) { + resourcePackagesSet = new HashSet<>(Arrays.asList(resourcePackages.split(","))); + } + + OpenAPI openAPIInput = null; + if (StringUtils.isNotBlank(openapiAsString)) { + try { + openAPIInput = Json.mapper().readValue(openapiAsString, OpenAPI.class); + } catch (Exception e) { + try { + openAPIInput = Yaml.mapper().readValue(openapiAsString, OpenAPI.class); + } catch (Exception e1) { + throw new Exception("Error reading/deserializing openapi input: " + e.getMessage(), e); + } + } + } + + SwaggerConfiguration config = new SwaggerConfiguration() + .filterClass(filterClass) + .ignoredRoutes(ignoredRoutesSet) + .prettyPrint(prettyPrint) + .readAllResources(readAllResources) + .openAPI(openAPIInput) + .readerClass(readerClass) + .scannerClass(scannerClass) + .resourceClasses(resourceClassesSet) + .resourcePackages(resourcePackagesSet); + try { + OpenAPI openAPI = new JaxrsOpenApiContextBuilder() + .openApiConfiguration(config) + .buildContext(true) + .read(); + String openapiJson = null; + String openapiYaml = null; + if ("JSON".equals(outputFormat) || "JSONANDYAML".equals(outputFormat)) { + if (prettyPrint) { + openapiJson = Json.pretty(openAPI); + } else { + openapiJson = Json.mapper().writeValueAsString(openAPI); + } + } + if ("YAML".equals(outputFormat) || "JSONANDYAML".equals(outputFormat)) { + if (prettyPrint) { + openapiYaml = Yaml.pretty(openAPI); + } else { + openapiYaml = Yaml.mapper().writeValueAsString(openAPI); + } + + } + HashMap map = new HashMap(); + map.put("JSON", openapiJson); + map.put("YAML", openapiYaml); + return map; + } catch (OpenApiConfigurationException e) { + throw new Exception("Error resolving API specification: " + e.getMessage(), e); + } catch (Exception e) { + throw new Exception("Error resolving API specification: " + e.getMessage(), e); + } + + } +} diff --git a/modules/swagger-maven-plugin/README.md b/modules/swagger-maven-plugin/README.md new file mode 100644 index 0000000000..292f29f01b --- /dev/null +++ b/modules/swagger-maven-plugin/README.md @@ -0,0 +1,79 @@ +# swagger-maven-plugin + +* Resolves project openAPI specification and saves the result in JSON, YAML or both formats. +All parameters except `outputFileName`, `outputFormat`, `skip`, `encoding` and `outputPath` correspond +to `swagger` [configuration property](https://github.com/swagger-api/swagger-core/wiki/Swagger-2.X---Integration-and-Configuration#configuration-properties) with same name. + +## Configuration example + + +```xml + + + + + io.swagger.core.v3 + swagger-maven-plugin + 2.0.5-SNAPSHOT + + openapi + ${project.build.directory}/generatedtest + JSONANDYAML + + test.petstore + + TRUE + + + + compile + + resolve + + + + + + + + + io.swagger.core.v3 + swagger-jaxrs2 + 2.0.5-SNAPSHOT + + + + javax.ws.rs + javax.ws.rs-api + 2.1 + + + javax.servlet + javax.servlet-api + 3.1.0 + + + +``` + + +#### Parameters +Parameter | Description | Required | Default +--------- | ----------- | --------- | ------- +`outputPath`|output path where file(s) are saved|true| +`outputFileName`|file name (no extension)|false|`openapi` +`outputFormat`|file format (`JSON`, `YAML`, `JSONANDYAML`|false|`JSON` +`skip`|if `TRUE` skip execution|false|`FALSE` +`encoding`|encoding of output file(s)|false| +`resourcePackages`|see [configuration property](https://github.com/swagger-api/swagger-core/wiki/Swagger-2.X---Integration-and-Configuration#configuration-properties)|false| +`resourceClasses`|see [configuration property](https://github.com/swagger-api/swagger-core/wiki/Swagger-2.X---Integration-and-Configuration#configuration-properties)|false| +`prettyPrint`|see [configuration property](https://github.com/swagger-api/swagger-core/wiki/Swagger-2.X---Integration-and-Configuration#configuration-properties)|false|`TRUE` +`openapiFilePath`|path to openapi file to be merged with resolved specification, see [config](https://github.com/swagger-api/swagger-core/wiki/Swagger-2.X---Integration-and-Configuration#configuration-properties)|false| +`filterClass`|see [configuration property](https://github.com/swagger-api/swagger-core/wiki/Swagger-2.X---Integration-and-Configuration#configuration-properties)|false| +`readerClass`|see [configuration property](https://github.com/swagger-api/swagger-core/wiki/Swagger-2.X---Integration-and-Configuration#configuration-properties)|false| +`scannerClass`|see [configuration property](https://github.com/swagger-api/swagger-core/wiki/Swagger-2.X---Integration-and-Configuration#configuration-properties)|false| +`readAllResources`|see [configuration property](https://github.com/swagger-api/swagger-core/wiki/Swagger-2.X---Integration-and-Configuration#configuration-properties)|false| +`ignoredRoutes`|see [configuration property](https://github.com/swagger-api/swagger-core/wiki/Swagger-2.X---Integration-and-Configuration#configuration-properties)|false| + +*** + diff --git a/modules/swagger-maven-plugin/pom.xml b/modules/swagger-maven-plugin/pom.xml new file mode 100644 index 0000000000..453a215634 --- /dev/null +++ b/modules/swagger-maven-plugin/pom.xml @@ -0,0 +1,176 @@ + + + io.swagger.core.v3 + swagger-project + 2.0.5-SNAPSHOT + ../.. + + 4.0.0 + swagger-maven-plugin + maven-plugin + swagger-maven-plugin + + + + org.codehaus.plexus + plexus-component-metadata + 1.7.1 + + + + generate-metadata + + + + + + org.apache.maven.plugins + maven-plugin-plugin + 3.5.1 + + + + + + org.apache.maven + maven-plugin-api + ${maven.version} + + + org.codehaus.plexus + plexus-utils + + + + + org.apache.maven.plugin-tools + maven-plugin-annotations + 3.3 + provided + + + org.apache.maven + maven-artifact + + + + + org.apache.maven.plugin-testing + maven-plugin-testing-harness + 3.3.0 + test + + + junit + junit + + + org.codehaus.plexus + plexus-utils + + + org.codehaus.plexus + plexus-component-annotations + + + + + org.apache.commons + commons-lang3 + 3.7 + + + org.codehaus.plexus + plexus-utils + 3.0.24 + + + org.codehaus.plexus + plexus-component-annotations + 1.5.5 + + + + org.apache.maven + maven-compat + ${maven.version} + + + com.google.guava + guava + + + org.codehaus.plexus + plexus-utils + + + org.codehaus.plexus + plexus-component-annotations + + + + + io.swagger.core.v3 + swagger-jaxrs2 + ${project.version} + + + + junit + junit + ${junit.version} + test + + + com.github.tomakehurst + wiremock + 2.15.0 + test + + + junit + junit + + + com.google.guava + guava + + + + + ch.qos.logback + logback-classic + 1.2.3 + test + + + ch.qos.logback + logback-core + 1.2.3 + test + + + javax.ws.rs + javax.ws.rs-api + 2.1 + test + + + javax.servlet + javax.servlet-api + 3.1.0 + test + + + + + UTF-8 + 3.5.0 + 4.12 + + diff --git a/modules/swagger-maven-plugin/src/main/java/io/swagger/v3/plugin/maven/IncludeProjectDependenciesComponentConfigurator.java b/modules/swagger-maven-plugin/src/main/java/io/swagger/v3/plugin/maven/IncludeProjectDependenciesComponentConfigurator.java new file mode 100644 index 0000000000..48046735f4 --- /dev/null +++ b/modules/swagger-maven-plugin/src/main/java/io/swagger/v3/plugin/maven/IncludeProjectDependenciesComponentConfigurator.java @@ -0,0 +1,71 @@ +package io.swagger.v3.plugin.maven; + +import org.codehaus.plexus.classworlds.realm.ClassRealm; +import org.codehaus.plexus.component.annotations.Component; +import org.codehaus.plexus.component.configurator.AbstractComponentConfigurator; +import org.codehaus.plexus.component.configurator.ComponentConfigurationException; +import org.codehaus.plexus.component.configurator.ComponentConfigurator; +import org.codehaus.plexus.component.configurator.ConfigurationListener; +import org.codehaus.plexus.component.configurator.converters.composite.ObjectWithFieldsConverter; +import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; +import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; +import org.codehaus.plexus.configuration.PlexusConfiguration; + +import java.io.File; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; + +/* + * Thanks to original post by Brian Jackson (http://jaxzin.github.io/) http://maven.40175.n5.nabble.com/Adding-project-dependencies-and-generated-classes-to-classpath-of-my-plugin-tp110119p110121.html + */ +@Component(role = ComponentConfigurator.class, hint = "include-project-dependencies") +public class IncludeProjectDependenciesComponentConfigurator extends AbstractComponentConfigurator { + + @Override + public void configureComponent(Object component, PlexusConfiguration configuration, + ExpressionEvaluator expressionEvaluator, ClassRealm containerRealm, + ConfigurationListener listener) + throws ComponentConfigurationException { + + addProjectDependenciesToClassRealm(expressionEvaluator, containerRealm); + + ObjectWithFieldsConverter converter = new ObjectWithFieldsConverter(); + converter.processConfiguration(converterLookup, component, containerRealm, configuration, + expressionEvaluator, listener); + } + + private void addProjectDependenciesToClassRealm(ExpressionEvaluator expressionEvaluator, ClassRealm containerRealm) throws ComponentConfigurationException { + List compileClasspathElements; + try { + //noinspection unchecked + compileClasspathElements = (List) expressionEvaluator.evaluate("${project.compileClasspathElements}"); + } catch (ExpressionEvaluationException e) { + throw new ComponentConfigurationException("There was a problem evaluating: ${project.compileClasspathElements}", e); + } + + // Add the project dependencies to the ClassRealm + final URL[] urls = buildURLs(compileClasspathElements); + for (URL url : urls) { + containerRealm.addURL(url); + } + } + + private URL[] buildURLs(List runtimeClasspathElements) throws ComponentConfigurationException { + // Add the projects classes and dependencies + List urls = new ArrayList(runtimeClasspathElements.size()); + for (String element : runtimeClasspathElements) { + try { + final URL url = new File(element).toURI().toURL(); + urls.add(url); + } catch (MalformedURLException e) { + throw new ComponentConfigurationException("Unable to access project dependency: " + element, e); + } + } + + // Add the plugin's dependencies (so Trove stuff works if Trove isn't on + return urls.toArray(new URL[urls.size()]); + } + +} \ No newline at end of file diff --git a/modules/swagger-maven-plugin/src/main/java/io/swagger/v3/plugin/maven/SwaggerMojo.java b/modules/swagger-maven-plugin/src/main/java/io/swagger/v3/plugin/maven/SwaggerMojo.java new file mode 100644 index 0000000000..79dd428c19 --- /dev/null +++ b/modules/swagger-maven-plugin/src/main/java/io/swagger/v3/plugin/maven/SwaggerMojo.java @@ -0,0 +1,189 @@ +package io.swagger.v3.plugin.maven; + +import io.swagger.v3.core.util.Json; +import io.swagger.v3.core.util.Yaml; +import io.swagger.v3.jaxrs2.integration.JaxrsOpenApiContextBuilder; +import io.swagger.v3.oas.integration.OpenApiConfigurationException; +import io.swagger.v3.oas.integration.SwaggerConfiguration; +import io.swagger.v3.oas.models.OpenAPI; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.plugins.annotations.ResolutionScope; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.util.StringUtils; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Collection; +import java.util.Set; + +@Mojo( + name = "resolve", + requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME, + defaultPhase = LifecyclePhase.COMPILE, + threadSafe = true, + configurator = "include-project-dependencies" +) +public class SwaggerMojo extends AbstractMojo { + + public enum Format {JSON, YAML, JSONANDYAML}; + + public void execute() throws MojoExecutionException, MojoFailureException + { + if (skip) { + getLog().info( "Skipping OpenAPI specification resolution" ); + return; + } + getLog().info( "Resolving OpenAPI specification.." ); + + if(project !=null) { + String pEnc = project.getProperties().getProperty("project.build.sourceEncoding"); + if (StringUtils.isNotBlank(pEnc)) { + projectEncoding = pEnc; + } + } + if (StringUtils.isBlank(encoding)) { + encoding = projectEncoding; + } + + OpenAPI openAPIInput = null; + try { + if (StringUtils.isNotBlank(openapiFilePath)) { + Path openapiPath = Paths.get(openapiFilePath); + if (openapiPath.toFile().exists() && openapiPath.toFile().isFile()) { + String openapiFileContent = new String(Files.readAllBytes(openapiPath), encoding); + if (StringUtils.isNotBlank(openapiFileContent)) { + try { + openAPIInput = Json.mapper().readValue(openapiFileContent, OpenAPI.class); + } catch (Exception e) { + try { + openAPIInput = Yaml.mapper().readValue(openapiFileContent, OpenAPI.class); + } catch (Exception e1) { + getLog().error( "Error reading/deserializing openapi file" , e); + throw new MojoFailureException(e.getMessage(), e); + } + } + } + } + } + } catch (Exception e) { + getLog().error( "Error reading/deserializing openapi file" , e); + throw new MojoFailureException(e.getMessage(), e); + } + + SwaggerConfiguration config = new SwaggerConfiguration() + .filterClass(filterClass) + .ignoredRoutes(ignoredRoutes) + .prettyPrint(prettyPrint) + .readAllResources(readAllResources) + .readerClass(readerClass) + .scannerClass(scannerClass) + .resourceClasses(resourceClasses) + .openAPI(openAPIInput) + .resourcePackages(resourcePackages); + try { + OpenAPI openAPI = new JaxrsOpenApiContextBuilder() + .openApiConfiguration(config) + .buildContext(true) + .read(); + String openapiJson = null; + String openapiYaml = null; + if (Format.JSON.equals(outputFormat) || Format.JSONANDYAML.equals(outputFormat)) { + if (prettyPrint) { + openapiJson = Json.pretty(openAPI); + } else { + openapiJson = Json.mapper().writeValueAsString(openAPI); + } + + } + if (Format.YAML.equals(outputFormat) || Format.JSONANDYAML.equals(outputFormat)) { + if (prettyPrint) { + openapiYaml = Yaml.pretty(openAPI); + } else { + openapiYaml = Yaml.mapper().writeValueAsString(openAPI); + } + + } + Path path = Paths.get(outputPath, "temp"); + final File parentFile = path.toFile().getParentFile(); + if (parentFile != null) { + parentFile.mkdirs(); + } + + if (openapiJson != null) { + path = Paths.get(outputPath, outputFileName + ".json"); + Files.write(path, openapiJson.getBytes(Charset.forName(encoding))); + } + if (openapiYaml != null) { + path = Paths.get(outputPath, outputFileName + ".yaml"); + Files.write(path, openapiYaml.getBytes(Charset.forName(encoding))); + } + + } catch (OpenApiConfigurationException e) { + getLog().error( "Error resolving API specification" , e); + throw new MojoFailureException(e.getMessage(), e); + } catch (IOException e) { + getLog().error( "Error writing API specification" , e); + throw new MojoExecutionException("Failed to write API definition", e); + } catch (Exception e) { + getLog().error( "Error resolving API specification" , e); + throw new MojoExecutionException(e.getMessage(), e); + } + } + + @Parameter( property = "resolve.outputFileName", defaultValue = "openapi") + private String outputFileName = "openapi"; + + @Parameter( property = "resolve.outputPath" ) + private String outputPath; + + @Parameter( property = "resolve.outputFormat", defaultValue = "JSON") + private Format outputFormat = Format.JSON; + + @Parameter( property = "resolve.resourcePackages" ) + private Set resourcePackages; + @Parameter( property = "resolve.resourceClasses" ) + private Set resourceClasses; + @Parameter( property = "resolve.filterClass" ) + private String filterClass; + @Parameter( property = "resolve.readerClass" ) + private String readerClass; + @Parameter( property = "resolve.scannerClass" ) + private String scannerClass; + @Parameter( property = "resolve.prettyPrint" ) + private Boolean prettyPrint = false; + @Parameter( property = "resolve.readAllResources" ) + private Boolean readAllResources = Boolean.TRUE; + @Parameter( property = "resolve.ignoredRoutes" ) + private Collection ignoredRoutes; + + @Parameter( property = "resolve.skip" ) + private Boolean skip = Boolean.FALSE; + + @Parameter( property = "resolve.openapiFilePath") + private String openapiFilePath; + + @Parameter(defaultValue = "${project}", readonly = true) + private MavenProject project; + + @Parameter( property = "resolve.encoding" ) + private String encoding; + + private String projectEncoding = "UTF-8"; + + public String getOutputPath() { + return outputPath; + } + public String getOpenapiFilePath() { + return openapiFilePath; + } + +} diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/BetterAbstractMojoTestCase.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/BetterAbstractMojoTestCase.java new file mode 100644 index 0000000000..6d5fedc3aa --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/BetterAbstractMojoTestCase.java @@ -0,0 +1,105 @@ +package io.swagger.v3.plugin.maven; + +import org.apache.maven.DefaultMaven; +import org.apache.maven.Maven; +import org.apache.maven.execution.DefaultMavenExecutionRequest; +import org.apache.maven.execution.DefaultMavenExecutionResult; +import org.apache.maven.execution.MavenExecutionRequest; +import org.apache.maven.execution.MavenExecutionRequestPopulator; +import org.apache.maven.execution.MavenExecutionResult; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.plugin.Mojo; +import org.apache.maven.plugin.testing.AbstractMojoTestCase; +import org.apache.maven.project.MavenProject; +import org.apache.maven.project.ProjectBuilder; +import org.apache.maven.project.ProjectBuildingRequest; +import org.eclipse.aether.DefaultRepositorySystemSession; +import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory; +import org.eclipse.aether.repository.LocalRepository; + +import java.io.File; +import java.util.Arrays; + +/** + * Copied from https://github.com/ahgittin/license-audit-maven-plugin + */ + +/** + * Use this as you would {@link AbstractMojoTestCase}, + * where you want more of the standard maven defaults to be set + * (and where the {@link AbstractMojoTestCase} leaves them as null or empty). + * This includes: + *

  • local repo, repo sessions and managers configured + *
  • maven default remote repos installed (NB: this does not use your ~/.m2 local settings) + *
  • system properties are copies + *

    + * No changes to subclass code is needed; this simply intercepts the {@link #newMavenSession(MavenProject)} method + * used by the various {@link #lookupMojo(String, File)} methods. + *

    + * This also provides new methods, {@link #newMavenSession()} to conveniently create a maven session, + * and {@link #lookupConfiguredMojo(File, String)} so you don't have to always build the project yourself. + */ +public abstract class BetterAbstractMojoTestCase extends AbstractMojoTestCase { + + protected MavenSession newMavenSession() { + try { + MavenExecutionRequest request = new DefaultMavenExecutionRequest(); + MavenExecutionResult result = new DefaultMavenExecutionResult(); + + // populate sensible defaults, including repository basedir and remote repos + MavenExecutionRequestPopulator populator; + populator = getContainer().lookup(MavenExecutionRequestPopulator.class); + populator.populateDefaults(request); + + // this is needed to allow java profiles to get resolved; i.e. avoid during project builds: + // [ERROR] Failed to determine Java version for profile java-1.5-detected @ org.apache.commons:commons-parent:22, /Users/alex/.m2/repository/org/apache/commons/commons-parent/22/commons-parent-22.pom, line 909, column 14 + request.setSystemProperties(System.getProperties()); + + // and this is needed so that the repo session in the maven session + // has a repo manager, and it points at the local repo + // (cf MavenRepositorySystemUtils.newSession() which is what is otherwise done) + DefaultMaven maven = (DefaultMaven) getContainer().lookup(Maven.class); + DefaultRepositorySystemSession repoSession = + (DefaultRepositorySystemSession) maven.newRepositorySession(request); + repoSession.setLocalRepositoryManager( + new SimpleLocalRepositoryManagerFactory().newInstance(repoSession, + new LocalRepository(request.getLocalRepository().getBasedir()))); + + @SuppressWarnings("deprecation") + MavenSession session = new MavenSession(getContainer(), + repoSession, + request, result); + return session; + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + /** + * Extends the super to use the new {@link #newMavenSession()} introduced here + * which sets the defaults one expects from maven; the standard test case leaves a lot of things blank + */ + @Override + protected MavenSession newMavenSession(MavenProject project) { + MavenSession session = newMavenSession(); + session.setCurrentProject(project); + session.setProjects(Arrays.asList(project)); + return session; + } + + /** + * As {@link #lookupConfiguredMojo(MavenProject, String)} but taking the pom file + * and creating the {@link MavenProject}. + */ + protected Mojo lookupConfiguredMojo(File pom, String goal) throws Exception { + assertNotNull(pom); + assertTrue(pom.exists()); + this.getContainer().addComponent(new IncludeProjectDependenciesComponentConfigurator(), org.codehaus.plexus.component.configurator.ComponentConfigurator.class, "include-project-dependencies"); + ProjectBuildingRequest buildingRequest = newMavenSession().getProjectBuildingRequest(); + ProjectBuilder projectBuilder = lookup(ProjectBuilder.class); + MavenProject project = projectBuilder.build(pom, buildingRequest).getProject(); + + return lookupConfiguredMojo(project, goal); + } + +} \ No newline at end of file diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/SwaggerResolveTest.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/SwaggerResolveTest.java new file mode 100644 index 0000000000..74af1d47ab --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/SwaggerResolveTest.java @@ -0,0 +1,81 @@ +package io.swagger.v3.plugin.maven; + +import io.swagger.v3.core.util.Json; +import io.swagger.v3.core.util.Yaml; +import io.swagger.v3.oas.models.OpenAPI; +import org.apache.commons.io.FileUtils; +import org.codehaus.plexus.configuration.PlexusConfiguration; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +public class SwaggerResolveTest extends BetterAbstractMojoTestCase{ + + protected static Logger LOGGER = LoggerFactory.getLogger(SwaggerResolveTest.class); + + protected void setUp() throws Exception { + // required for mojo lookups to work + super.setUp(); + } + + public void testResolve() throws Exception { + File pom = getTestFile("src/test/resources/pom.resolveToFile.xml"); + + runTest(pom); + } + + public void testResolveNoName() throws Exception { + File pom = getTestFile("src/test/resources/pom.resolveToFileNoName.xml"); + + runTest(pom); + } + + public void testResolveJsonAndYaml() throws Exception { + File pom = getTestFile("src/test/resources/pom.resolveToFileJsonAndYaml.xml"); + + runTest(pom); + } + + private void runTest(File pom) throws Exception { + assertNotNull(pom); + assertTrue( pom.exists() ); + + SwaggerMojo swaggerMojo = (SwaggerMojo) lookupConfiguredMojo(pom, "resolve"); + assertNotNull( swaggerMojo ); + + swaggerMojo.execute(); + final PlexusConfiguration config = extractPluginConfiguration("swagger-maven-plugin", pom); + //String outputPath = config.getChild("outputPath").getValue(); + String outputPath = swaggerMojo.getOutputPath(); + String outputFile = config.getChild("outputFileName").getValue(); + if (outputFile == null) { + outputFile = "openapi"; + } + String format = config.getChild("outputFormat").getValue(); + if (format.toLowerCase().equals("yaml") || format.toLowerCase().equals("jsonandyaml")) { + Path path = Paths.get(outputPath, outputFile + ".yaml"); + File file = path.toFile(); + assertTrue(Files.isRegularFile(path)); + String content = FileUtils.readFileToString(file, "UTF-8"); + final OpenAPI openAPI; + openAPI = Yaml.mapper().readValue(content, OpenAPI.class); + assertNotNull(openAPI); + assertEquals(openAPI.getServers().get(0).getVariables().size(), 2); + } + if (format.toLowerCase().equals("json") || format.toLowerCase().equals("jsonandyaml")) { + Path path = Paths.get(outputPath, outputFile + ".json"); + File file = path.toFile(); + assertTrue(Files.isRegularFile(path)); + String content = FileUtils.readFileToString(file, "UTF-8"); + final OpenAPI openAPI; + openAPI = Json.mapper().readValue(content, OpenAPI.class); + assertNotNull(openAPI); + assertEquals(openAPI.getServers().get(0).getVariables().size(), 2); + } + + } +} \ No newline at end of file diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/EmptyPetResource.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/EmptyPetResource.java new file mode 100644 index 0000000000..fdb40cd00d --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/EmptyPetResource.java @@ -0,0 +1,7 @@ +package io.swagger.v3.plugin.maven.petstore.petstore; + +/** + * An Empty PetResource Class + */ +public class EmptyPetResource { +} diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/PetResource.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/PetResource.java new file mode 100644 index 0000000000..e6b2be94dc --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/PetResource.java @@ -0,0 +1,166 @@ +/** + * Copyright 2016 SmartBear Software + *

    + * 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.swagger.v3.plugin.maven.petstore.petstore; + +import io.swagger.v3.plugin.maven.resources.QueryResultBean; +import io.swagger.v3.plugin.maven.resources.data.PetData; +import io.swagger.v3.plugin.maven.resources.exception.NotFoundException; +import io.swagger.v3.plugin.maven.resources.model.Pet; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.plugin.maven.resources.QueryResultBean; + +import javax.ws.rs.BeanParam; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Response; + +@Consumes("application/json") +@Path("/pet") +@Produces({"application/json", "application/xml"}) +public class PetResource { + static PetData petData = new PetData(); + + @GET + @Path("/{petId}") + @Operation(summary = "Find pet by ID", + description = "Returns a pet when 0 < ID <= 10. ID > 10 or nonintegers will simulate API error conditions", + responses = { + @ApiResponse( + description = "The pet", content = @Content( + schema = @Schema(implementation = Pet.class) + )), + @ApiResponse(responseCode = "400", description = "Invalid ID supplied"), + @ApiResponse(responseCode = "404", description = "Pet not found") + }) + public Response getPetById( + @Parameter(description = "ID of pet that needs to be fetched"/*, _enum = "range[1,10]"*/, required = true) + @PathParam("petId") final Long petId) throws NotFoundException { + Pet pet = petData.getPetById(petId); + if (null != pet) { + return Response.ok().entity(pet).build(); + } else { + throw new NotFoundException(404, "Pet not found"); + } + } + + @POST + @Consumes({"application/json", "application/xml"}) + @Operation(summary = "Add a new pet to the store", + responses = { + @ApiResponse(responseCode = "405", description = "Invalid input") + }) + public Response addPet( + @Parameter(description = "Pet object that needs to be added to the store", required = true) final Pet pet) { + petData.addPet(pet); + return Response.ok().entity("SUCCESS").build(); + } + + @POST + @Path("/bodynoannotation") + @Consumes({"application/json", "application/xml"}) + @Produces({"application/json", "application/xml"}) + @Operation(summary = "Add a new pet to the store no annotation", + responses = { + @ApiResponse(responseCode = "405", description = "Invalid input") + }) + public Response addPetNoAnnotation(final Pet pet) { + petData.addPet(pet); + return Response.ok().entity("SUCCESS").build(); + } + + @POST + @Path("/bodyid") + @Consumes({"application/json", "application/xml"}) + @Operation(summary = "Add a new pet to the store passing an integer with generic parameter annotation", + responses = { + @ApiResponse(responseCode = "405", description = "Invalid input") + }) + public Response addPetByInteger( + @Parameter(description = "Pet object that needs to be added to the store", required = true) final int petId) { + return Response.ok().entity("SUCCESS").build(); + } + + @POST + @Path("/bodyidnoannotation") + @Consumes({"application/json", "application/xml"}) + @Operation(summary = "Add a new pet to the store passing an integer without parameter annotation", + responses = { + @ApiResponse(responseCode = "405", description = "Invalid input") + }) + public Response addPetByIntegerNoAnnotation(final int petId) { + return Response.ok().entity("SUCCESS").build(); + } + + @PUT + @Operation(summary = "Update an existing pet", + responses = { + @ApiResponse(responseCode = "400", description = "Invalid ID supplied"), + @ApiResponse(responseCode = "404", description = "Pet not found"), + @ApiResponse(responseCode = "405", description = "Validation exception")}) + public Response updatePet( + @Parameter(description = "Pet object that needs to be added to the store", required = true) final Pet pet) { + petData.addPet(pet); + return Response.ok().entity("SUCCESS").build(); + } + + @GET + @Path("/findByStatus") + @Produces("application/xml") + @Operation(summary = "Finds Pets by status", + description = "Multiple status values can be provided with comma seperated strings", + responses = { + @ApiResponse( + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Pet.class))), + @ApiResponse( + responseCode = "400", description = "Invalid status value" + )} + ) + public Response findPetsByStatus( + @Parameter(description = "Status values that need to be considered for filter", required = true) @QueryParam("status") final String status, + @BeanParam final QueryResultBean qr + ) { + return Response.ok(petData.findPetByStatus(status)).build(); + } + + @GET + @Path("/findByTags") + @Produces("application/json") + @Operation(summary = "Finds Pets by tags", + description = "Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.", + responses = { + @ApiResponse(description = "Pets matching criteria", + content = @Content(schema = @Schema(implementation = Pet.class)) + ), + @ApiResponse(description = "Invalid tag value", responseCode = "400") + }) + @Deprecated + public Response findPetsByTags( + @Parameter(description = "Tags to filter by", required = true) @QueryParam("tags") final String tags) { + return Response.ok(petData.findPetByTags(tags)).build(); + } +} diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/callback/ComplexCallbackResource.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/callback/ComplexCallbackResource.java new file mode 100644 index 0000000000..a9572f76d0 --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/callback/ComplexCallbackResource.java @@ -0,0 +1,62 @@ +package io.swagger.v3.plugin.maven.petstore.petstore.callback; + +import io.swagger.v3.plugin.maven.resources.model.User; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.callbacks.Callback; +import io.swagger.v3.oas.annotations.callbacks.Callbacks; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.QueryParam; + +public class ComplexCallbackResource { + @Callbacks({ + @Callback( + name = "testCallback1", + operation = @Operation( + operationId = "getAllReviews", + summary = "get all the reviews", + method = "get", + responses = @ApiResponse( + responseCode = "200", + description = "successful operation", + content = @Content( + mediaType = "application/json", + schema = @Schema( + type = "integer", + format = "int32")))), + callbackUrlExpression = "http://www.url.com"), + @Callback( + name = "testCallback2", + operation = @Operation( + operationId = "getAnSpecificReviews", + summary = "get a review", + method = "get", + responses = @ApiResponse( + responseCode = "200", + description = "successful operation", + content = @Content( + mediaType = "application/json", + schema = @Schema( + implementation = User.class)))), + callbackUrlExpression = "http://www.url2.com") + }) + @Operation( + summary = "Simple get operation", + operationId = "getWithNoParameters", + responses = { + @ApiResponse( + responseCode = "200", + description = "voila!") + }) + @GET + @Path("/complexcallback") + public String simpleGet(@Parameter(description = "idParam", schema = @Schema(implementation = User.class)) + @QueryParam("id") final String id) { + return null; + } +} diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/callback/MultipleCallbacksTestWithOperationResource.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/callback/MultipleCallbacksTestWithOperationResource.java new file mode 100644 index 0000000000..9ac962674f --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/callback/MultipleCallbacksTestWithOperationResource.java @@ -0,0 +1,45 @@ +package io.swagger.v3.plugin.maven.petstore.petstore.callback; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.callbacks.Callback; +import io.swagger.v3.oas.annotations.callbacks.Callbacks; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +public class MultipleCallbacksTestWithOperationResource { + @Callbacks({ + @Callback( + name = "testCallback1", + operation = @Operation( + operationId = "getAllReviews", + summary = "get all the reviews", + method = "get", + responses = @ApiResponse( + responseCode = "200", + description = "successful operation", + content = @Content( + mediaType = "application/json", + schema = @Schema( + type = "integer", + format = "int32")))), + callbackUrlExpression = "http://www.url.com"), + @Callback(name = "testCallback2", operation = @Operation(), callbackUrlExpression = "http://$request.query.url") + }) + @Operation( + summary = "Simple get operation", + operationId = "getWithNoParameters", + responses = { + @ApiResponse( + responseCode = "200", + description = "voila!") + }) + @GET + @Path("/multiplecallback") + public String simpleGet() { + return null; + } +} \ No newline at end of file diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/callback/RepeatableCallbackResource.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/callback/RepeatableCallbackResource.java new file mode 100644 index 0000000000..3615402099 --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/callback/RepeatableCallbackResource.java @@ -0,0 +1,46 @@ +package io.swagger.v3.plugin.maven.petstore.petstore.callback; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.callbacks.Callback; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +public class RepeatableCallbackResource { + @Callback(name = "testCallback", operation = + @Operation(), callbackUrlExpression = "http://$requests.query.url") + @Callback( + name = "testCallback1", + operation = @Operation( + operationId = "getAllReviews", + summary = "get all the reviews", + method = "get", + responses = @ApiResponse( + responseCode = "200", + description = "successful operation", + content = @Content( + mediaType = "application/json", + schema = @Schema( + type = "integer", + format = "int32")))), + callbackUrlExpression = "http://www.url.com") + @Callback(name = "testCallback2", operation = + @Operation(), + callbackUrlExpression = "http://$request.query.url") + @Operation( + summary = "Simple get operation", + operationId = "getWithNoParameters", + responses = { + @ApiResponse( + responseCode = "200", + description = "voila!") + }) + @GET + @Path("/repeatablecallback") + public String simpleGet() { + return null; + } +} \ No newline at end of file diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/callback/SimpleCallbackWithOperationResource.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/callback/SimpleCallbackWithOperationResource.java new file mode 100644 index 0000000000..056e82fb92 --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/callback/SimpleCallbackWithOperationResource.java @@ -0,0 +1,44 @@ +package io.swagger.v3.plugin.maven.petstore.petstore.callback; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.callbacks.Callback; +import io.swagger.v3.oas.annotations.callbacks.Callbacks; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +public class SimpleCallbackWithOperationResource { + @Callbacks({ + @Callback( + name = "testCallback1", + operation = @Operation( + operationId = "getAllReviews", + summary = "get all the reviews", + method = "get", + responses = @ApiResponse( + responseCode = "200", + description = "successful operation", + content = @Content( + mediaType = "application/json", + schema = @Schema( + type = "integer", + format = "int32")))), + callbackUrlExpression = "http://www.url.com") + }) + @Operation( + summary = "Simple get operation", + operationId = "getWithNoParameters", + responses = { + @ApiResponse( + responseCode = "200", + description = "voila!") + }) + @GET + @Path("/simplecallback") + public String simpleGet() { + return null; + } +} diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/example/ExamplesResource.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/example/ExamplesResource.java new file mode 100644 index 0000000000..7a5db966cb --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/example/ExamplesResource.java @@ -0,0 +1,69 @@ +package io.swagger.v3.plugin.maven.petstore.petstore.example; + +import io.swagger.v3.plugin.maven.resources.model.User; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.enums.ParameterIn; +import io.swagger.v3.oas.annotations.enums.ParameterStyle; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.ExampleObject; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.parameters.RequestBody; +import io.swagger.v3.oas.annotations.responses.ApiResponse; + +import javax.ws.rs.POST; +import javax.ws.rs.Path; + +/** + * Examples Resource Scenario + */ +public class ExamplesResource { + @Path("/example") + @POST + @Operation( + operationId = "subscribe", + description = "subscribes a client to updates relevant to the requestor's account", + parameters = { + @Parameter(in = ParameterIn.PATH, name = "subscriptionId", required = true, + schema = @Schema(name = "Schema", description = "Schema", example = "Subscription example"), + style = ParameterStyle.SIMPLE, example = "example", + examples = { + @ExampleObject(name = "subscriptionId_1", value = "12345", + summary = "Subscription number 12345", externalValue = "Subscription external value 1"), + @ExampleObject(name = "subscriptionId_2", value = "54321", + summary = "Subscription number 54321", externalValue = "Subscription external value 2") + }) + }, + responses = { + @ApiResponse( + description = "test description", + content = @Content( + mediaType = "*/*", + schema = @Schema( + type = "string", + format = "uuid", + description = "the generated UUID", + accessMode = Schema.AccessMode.READ_ONLY, + example = "Schema example" + ), + examples = { + @ExampleObject(name = "Default Response", value = "SubscriptionResponse", + summary = "Subscription Response Example", externalValue = "Subscription Response value 1") + } + )) + }) + public SubscriptionResponse subscribe(@RequestBody(description = "Created user object", required = true, + content = @Content( + schema = @Schema( + type = "string", + format = "uuid", + description = "the generated UUID", + accessMode = Schema.AccessMode.READ_ONLY, + example = "Schema example"), + examples = { + @ExampleObject(name = "Default Request", value = "SubscriptionRequest", + summary = "Subscription Request Example", externalValue = "Subscription Request Value") + })) User user) { + return null; + } +} \ No newline at end of file diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/example/SubscriptionResponse.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/example/SubscriptionResponse.java new file mode 100644 index 0000000000..143bbe9e76 --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/example/SubscriptionResponse.java @@ -0,0 +1,5 @@ +package io.swagger.v3.plugin.maven.petstore.petstore.example; + +public class SubscriptionResponse { + public String subscriptionId; +} \ No newline at end of file diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/link/LinksResource.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/link/LinksResource.java new file mode 100644 index 0000000000..97123f4704 --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/link/LinksResource.java @@ -0,0 +1,44 @@ +package io.swagger.v3.plugin.maven.petstore.petstore.link; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.links.Link; +import io.swagger.v3.oas.annotations.links.LinkParameter; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.QueryParam; + +/** + * Class with Links + */ +public class LinksResource { + @Path("/links") + @Operation(operationId = "getUserWithAddress", + responses = { + @ApiResponse(description = "test description", + content = @Content(mediaType = "*/*", schema = @Schema(ref = "#/components/schemas/User")), + links = { + @Link( + name = "address", + operationId = "getAddress", + parameters = @LinkParameter( + name = "userId", + expression = "$request.query.userId")), + @Link( + name = "user", + operationId = "getUser", + operationRef = "#/components/links/MyLink", + parameters = @LinkParameter( + name = "userId", + expression = "$request.query.userId")) + })} + ) + @GET + public String getUser(@QueryParam("userId")final String userId) { + return null; + } + +} diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/openapidefintion/OpenAPIDefinitionResource.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/openapidefintion/OpenAPIDefinitionResource.java new file mode 100644 index 0000000000..a6a2b6604e --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/openapidefintion/OpenAPIDefinitionResource.java @@ -0,0 +1,49 @@ +package io.swagger.v3.plugin.maven.petstore.petstore.openapidefintion; + +import io.swagger.v3.oas.annotations.ExternalDocumentation; +import io.swagger.v3.oas.annotations.OpenAPIDefinition; +import io.swagger.v3.oas.annotations.info.Contact; +import io.swagger.v3.oas.annotations.info.Info; +import io.swagger.v3.oas.annotations.info.License; +import io.swagger.v3.oas.annotations.security.SecurityRequirement; +import io.swagger.v3.oas.annotations.servers.Server; +import io.swagger.v3.oas.annotations.servers.ServerVariable; +import io.swagger.v3.oas.annotations.tags.Tag; + +/** + * OpenAPIDefinition Example + */ +@OpenAPIDefinition( + info = @Info( + title = "Pet Resource Example", + version = "2.0", + description = "API Definition", + termsOfService = "Terms of service", + license = @License(name = "Apache 2.0", url = "http://foo.bar"), + contact = @Contact(url = "http://gigantic-server.com", name = "Fred", email = "Fred@gigagantic-server.com") + ), + tags = { + @Tag(name = "Tag 1", description = "desc 1", externalDocs = @ExternalDocumentation(description = "docs desc")), + @Tag(name = "Tag 2", description = "desc 2", externalDocs = @ExternalDocumentation(description = "docs desc 2")), + @Tag(name = "Tag 3") + }, + externalDocs = @ExternalDocumentation(description = "definition docs desc"), + security = { + @SecurityRequirement(name = "req 1", scopes = {"a", "b"}), + @SecurityRequirement(name = "req 2", scopes = {"b", "c"}) + } +/* , + servers = { + @Server( + description = "server 1", + url = "http://foo", + variables = { + @ServerVariable(name = "var1", description = "var 1", defaultValue = "1", allowableValues = {"1", "2"}), + @ServerVariable(name = "var2", description = "var 2", defaultValue = "1", allowableValues = {"1", "2"}) + }) + }*/ +) +public class OpenAPIDefinitionResource { + public void foo() { + } +} diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/operation/AnnotatedSameNameOperationResource.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/operation/AnnotatedSameNameOperationResource.java new file mode 100644 index 0000000000..5eec9d0b97 --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/operation/AnnotatedSameNameOperationResource.java @@ -0,0 +1,26 @@ +package io.swagger.v3.plugin.maven.petstore.petstore.operation; + +import io.swagger.v3.oas.annotations.Operation; + +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +/** + * Resource With a Default Operation without Annotation + */ +public class AnnotatedSameNameOperationResource { + @Path("/sameOperationName") + @GET + @Operation(description = "Same Operation Name") + public String getUser() { + return new String(); + } + + @Path("//sameOperationName") + @DELETE + @Operation(description = "Same Operation Name Duplicated") + public String getUser(final String id) { + return new String(); + } +} diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/operation/ExternalDocumentationResource.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/operation/ExternalDocumentationResource.java new file mode 100644 index 0000000000..dd08c56fc1 --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/operation/ExternalDocumentationResource.java @@ -0,0 +1,30 @@ +package io.swagger.v3.plugin.maven.petstore.petstore.operation; + +import io.swagger.v3.plugin.maven.resources.exception.NotFoundException; +import io.swagger.v3.plugin.maven.resources.model.Pet; +import io.swagger.v3.oas.annotations.ExternalDocumentation; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.core.Response; + +/** + * Resource with Operations Examples + */ +public class ExternalDocumentationResource { + @GET + @Path("/{petId}") + @Operation(summary = "Find pet by ID", + description = "Returns a pet when 0 < ID <= 10. ID > 10 or non integers will simulate API error conditions", + operationId = "petId", + externalDocs = @ExternalDocumentation(description = "External in Operation", url = "http://url.me")) + @ExternalDocumentation(description = "External Annotation Documentation", url = "http://url.me") + public Response getPetById( + @Parameter(description = "ID of pet that needs to be fetched", required = true) + @PathParam("petId") Long petId) throws NotFoundException { + return Response.ok().entity(new Pet()).build(); + } +} diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/operation/FullyAnnotatedOperationResource.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/operation/FullyAnnotatedOperationResource.java new file mode 100644 index 0000000000..4f4b548237 --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/operation/FullyAnnotatedOperationResource.java @@ -0,0 +1,38 @@ +package io.swagger.v3.plugin.maven.petstore.petstore.operation; + +import io.swagger.v3.plugin.maven.resources.exception.NotFoundException; +import io.swagger.v3.plugin.maven.resources.model.Pet; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.core.Response; + +/** + * Resource with Operations Examples + */ +public class FullyAnnotatedOperationResource { + @GET + @Path("/fullyannotatedoperation/{petId}") + @Operation(summary = "Find pet by ID", + description = "Returns a pet when 0 < ID <= 10. ID > 10 or non integers will simulate API error conditions", + operationId = "petId", + responses = { + @ApiResponse( + description = "The pet", content = @Content( + schema = @Schema(implementation = Pet.class) + )), + @ApiResponse(responseCode = "400", description = "Invalid ID supplied"), + @ApiResponse(responseCode = "404", description = "Pet not found") + }) + public Response getPetById( + @Parameter(description = "ID of pet that needs to be fetched", required = true) + @PathParam("petId")final Long petId) throws NotFoundException { + return Response.ok().entity(new Pet()).build(); + } +} diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/operation/HiddenOperationResource.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/operation/HiddenOperationResource.java new file mode 100644 index 0000000000..c18083196d --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/operation/HiddenOperationResource.java @@ -0,0 +1,29 @@ +package io.swagger.v3.plugin.maven.petstore.petstore.operation; + +import io.swagger.v3.plugin.maven.resources.model.Pet; +import io.swagger.v3.plugin.maven.resources.model.User; +import io.swagger.v3.oas.annotations.Hidden; +import io.swagger.v3.oas.annotations.Operation; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +/** + * Resource With a Hidden Operation + */ +public class HiddenOperationResource { + @Path("/hiddenbyflag") + @GET + @Operation(operationId = "Pets", description = "Pets Example", hidden = true) + public Pet getPet() { + return new Pet(); + } + + @Path("/hiddenbyannotation") + @GET + @Operation(operationId = "Users", description = "Users Example") + @Hidden + public User getUser() { + return new User(); + } +} diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/operation/InterfaceResource.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/operation/InterfaceResource.java new file mode 100644 index 0000000000..ada2d56da1 --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/operation/InterfaceResource.java @@ -0,0 +1,22 @@ +package io.swagger.v3.plugin.maven.petstore.petstore.operation; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.core.Response; + +/** + * Interface resource + */ +public interface InterfaceResource { + @GET + @Path("/interfaceoperation/{petId}") + @Operation(summary = "Find pet by ID Operation in Parent", + description = "Returns a pet in Parent" + ) + Response getPetById(@Parameter(description = "ID of pet that needs to be fetched", required = true) + @PathParam("petId") final Long petId); +} diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/operation/NotAnnotatedSameNameOperationResource.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/operation/NotAnnotatedSameNameOperationResource.java new file mode 100644 index 0000000000..9d8a7c6537 --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/operation/NotAnnotatedSameNameOperationResource.java @@ -0,0 +1,21 @@ +package io.swagger.v3.plugin.maven.petstore.petstore.operation; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +/** + * Resource With a Default Operation without Annotation + */ +public class NotAnnotatedSameNameOperationResource { + @Path("/notannotatedoperation") + @GET + public String getUser() { + return new String(); + } + + @Path("/notannotatedoperationduplicated") + @GET + public String getUser(final String id) { + return new String(); + } +} diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/operation/OperationResource.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/operation/OperationResource.java new file mode 100644 index 0000000000..98d3c1142e --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/operation/OperationResource.java @@ -0,0 +1,77 @@ +package io.swagger.v3.plugin.maven.petstore.petstore.operation; + +import io.swagger.v3.plugin.maven.resources.model.Pet; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; + +import javax.ws.rs.GET; +import javax.ws.rs.HEAD; +import javax.ws.rs.NotFoundException; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Response; + +/** + * Resource with Complete Operations Examples + */ +public class OperationResource implements InterfaceResource { + @Override + @Operation(summary = "Find pet by ID Operation in SubResource", + description = "Returns a pet in SubResource" + ) + public Response getPetById(final Long petId) { + return Response.ok().entity(new Pet()).build(); + } + + @GET + @Path("/operationsresource") + @Operation(summary = "Find pet by ID", + description = "combinatedfullyannotatedoperation/{petId}", + operationId = "petId", + responses = { + @ApiResponse( + description = "The pet", content = @Content( + schema = @Schema(implementation = Pet.class) + )), + @ApiResponse(responseCode = "400", description = "Invalid ID supplied"), + @ApiResponse(responseCode = "404", description = "Pet not found") + }) + public Response getPetById( + @Parameter(description = "ID of pet that needs to be fetched", required = true) + @QueryParam("petId") final Long petId, final String message) throws NotFoundException { + return Response.ok().entity(new Pet()).build(); + } + + @Path("/operationsresource") + @POST + public String getUser(final String id) { + return new String(); + } + + @Path("/operationsresource") + @PUT + @Operation(operationId = "combinated sameOperationName", + description = "combinatedsameOperationName") + public String getPerson() { + return new String(); + } + + @Path("/operationsresource") + @HEAD + @Operation(operationId = "combinatedsameOperationNameDuplicated", + description = "combinatedsameOperationNameDuplicated") + public String getPerson(final String id) { + return new String(); + } + + @Path("/operationsresource2") + @GET + public String getUser() { + return new String(); + } +} diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/operation/OperationWithoutAnnotationResource.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/operation/OperationWithoutAnnotationResource.java new file mode 100644 index 0000000000..7740873aa3 --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/operation/OperationWithoutAnnotationResource.java @@ -0,0 +1,15 @@ +package io.swagger.v3.plugin.maven.petstore.petstore.operation; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +/** + * Resource With a Default Operation without Annotation + */ +public class OperationWithoutAnnotationResource { + @Path("/operationwithouannotation") + @GET + public String getUser() { + return new String(); + } +} diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/operation/ServerOperationResource.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/operation/ServerOperationResource.java new file mode 100644 index 0000000000..1299bcaf8a --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/operation/ServerOperationResource.java @@ -0,0 +1,24 @@ +package io.swagger.v3.plugin.maven.petstore.petstore.operation; + +import io.swagger.v3.plugin.maven.resources.model.Pet; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.servers.Server; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +/** + * Resource With a Hidden Operation + */ +public class ServerOperationResource { + @Path("/serversoperation") + @GET + @Operation(operationId = "Pets", description = "Pets Example", + servers = { + @Server(description = "server 2", url = "http://foo2") + } + ) + public Pet getPet() { + return new Pet(); + } +} diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/operation/SubResource.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/operation/SubResource.java new file mode 100644 index 0000000000..5f8e9c2d14 --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/operation/SubResource.java @@ -0,0 +1,20 @@ +package io.swagger.v3.plugin.maven.petstore.petstore.operation; + +import io.swagger.v3.plugin.maven.resources.model.Pet; +import io.swagger.v3.oas.annotations.Operation; + +import javax.ws.rs.core.Response; + +/** + * SubResource + */ + +public class SubResource implements InterfaceResource { + @Override + @Operation(summary = "Find pet by ID Operation in SubResource", + description = "Returns a pet in SubResource" + ) + public Response getPetById(final Long petId) { + return Response.ok().entity(new Pet()).build(); + } +} diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/parameter/ArraySchemaResource.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/parameter/ArraySchemaResource.java new file mode 100644 index 0000000000..41cdaaed16 --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/parameter/ArraySchemaResource.java @@ -0,0 +1,44 @@ +package io.swagger.v3.plugin.maven.petstore.petstore.parameter; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.enums.Explode; +import io.swagger.v3.oas.annotations.enums.ParameterIn; +import io.swagger.v3.oas.annotations.media.ArraySchema; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; + +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.Path; + +public class ArraySchemaResource { + @Path("/arrayschema") + @POST + @Operation( + operationId = "subscribe", + description = "subscribes a client to updates relevant to the requestor's account, as " + + "identified by the input token. The supplied url will be used as the delivery address for response payloads", + parameters = { + @Parameter(in = ParameterIn.QUERY, name = "arrayParameter", required = true, explode = Explode.TRUE, + array = @ArraySchema(maxItems = 10, minItems = 1, + schema = @Schema(implementation = ParametersResource.SubscriptionResponse.class), + uniqueItems = true + ) + ), + }, + responses = { + @ApiResponse( + description = "test description", content = @Content( + mediaType = "*/*", + schema = + @Schema( + implementation = ParametersResource.SubscriptionResponse.class) + )) + }) + @Consumes({"application/json", "application/xml"}) + public ParametersResource.SubscriptionResponse subscribe() { + return null; + } +} diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/parameter/ComplexParameterResource.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/parameter/ComplexParameterResource.java new file mode 100644 index 0000000000..f5f7507893 --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/parameter/ComplexParameterResource.java @@ -0,0 +1,33 @@ +package io.swagger.v3.plugin.maven.petstore.petstore.parameter; + +import io.swagger.v3.plugin.maven.resources.model.User; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Schema; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.QueryParam; + +/** + * Class with a multiple annotated. + */ +public class ComplexParameterResource { + + @Parameter(description = "Phone definied in Field") + private String phone; + + public ComplexParameterResource(@Parameter(description = "phone Param", name = "phone") final String phone) { + this.phone = phone; + } + + @GET + @Path("/complexparameter") + @Operation(operationId = "create User") + public User findUser(@Parameter(description = "idParam") @QueryParam("id") final String id, + final String name, @QueryParam("lastName") final String lastName, + @Parameter(description = "address", schema = @Schema(implementation = User.class)) + @QueryParam("address") final String address) { + return new User(); + } +} diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/parameter/ComplexParameterWithOperationResource.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/parameter/ComplexParameterWithOperationResource.java new file mode 100644 index 0000000000..3b36cfa07b --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/parameter/ComplexParameterWithOperationResource.java @@ -0,0 +1,37 @@ +package io.swagger.v3.plugin.maven.petstore.petstore.parameter; + +import io.swagger.v3.plugin.maven.resources.model.User; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.enums.ParameterIn; +import io.swagger.v3.oas.annotations.media.Schema; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.QueryParam; + +/** + * Class with a multiple annotated. + */ +public class ComplexParameterWithOperationResource { + + @Parameter(description = "Phone definied in Field") + private String phone; + + public ComplexParameterWithOperationResource(@Parameter(description = "phone Param", name = "phone") final String phone) { + this.phone = phone; + } + + @GET + @Path("/complexparameter") + @Operation(operationId = "create User", + parameters = { + @Parameter(description = "Phone", name = "phone", in = ParameterIn.PATH) + }) + public User findUser(@Parameter(description = "idParam") @QueryParam("id") final String id, + final String name, @QueryParam("lastName") final String lastName, + @Parameter(description = "address", schema = @Schema(implementation = User.class)) + @QueryParam("address") final String address) { + return new User(); + } +} diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/parameter/MultipleNotAnnotatedParameter.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/parameter/MultipleNotAnnotatedParameter.java new file mode 100644 index 0000000000..d5ca534c6a --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/parameter/MultipleNotAnnotatedParameter.java @@ -0,0 +1,18 @@ +package io.swagger.v3.plugin.maven.petstore.petstore.parameter; + +import io.swagger.v3.oas.annotations.Operation; + +import javax.ws.rs.POST; +import javax.ws.rs.Path; + +/** + * Class with a multiple not annotated parameter. + */ +public class MultipleNotAnnotatedParameter { + @POST + @Path("/multiplenoannotatedparameter") + @Operation(operationId = "create User") + public void createUser(final String id, final String name) { + + } +} diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/parameter/OpenAPIJaxRSAnnotatedParameter.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/parameter/OpenAPIJaxRSAnnotatedParameter.java new file mode 100644 index 0000000000..d9c15c2b38 --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/parameter/OpenAPIJaxRSAnnotatedParameter.java @@ -0,0 +1,21 @@ +package io.swagger.v3.plugin.maven.petstore.petstore.parameter; + +import io.swagger.v3.plugin.maven.resources.model.User; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.QueryParam; + +/** + * Class with a single parameter annotated with jaxrs and open api annotation. + */ +public class OpenAPIJaxRSAnnotatedParameter { + @GET + @Path("/openapijaxrsannotatedparameter") + @Operation(operationId = "create User") + public User findUser(@Parameter(description = "idParam") @QueryParam("id") final String id) { + return new User(); + } +} diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/parameter/OpenAPIWithContentJaxRSAnnotatedParameter.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/parameter/OpenAPIWithContentJaxRSAnnotatedParameter.java new file mode 100644 index 0000000000..cdaf233999 --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/parameter/OpenAPIWithContentJaxRSAnnotatedParameter.java @@ -0,0 +1,25 @@ +package io.swagger.v3.plugin.maven.petstore.petstore.parameter; + +import io.swagger.v3.plugin.maven.resources.model.User; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.QueryParam; + +/** + * Class with a single parameter annotated with jaxrs and open api annotation. + */ +public class OpenAPIWithContentJaxRSAnnotatedParameter { + @GET + @Path("/openapiwithcontentjaxrsannotatedparameter") + @Operation(operationId = "create User") + public User findUser(@Parameter(description = "idParam", content = + @Content(schema = @Schema(description = "Id Schema Definition", required = true, name = "id"))) + @QueryParam("id") final String id) { + return new User(); + } +} diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/parameter/OpenAPIWithImplementationJaxRSAnnotatedParameter.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/parameter/OpenAPIWithImplementationJaxRSAnnotatedParameter.java new file mode 100644 index 0000000000..252886e104 --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/parameter/OpenAPIWithImplementationJaxRSAnnotatedParameter.java @@ -0,0 +1,23 @@ +package io.swagger.v3.plugin.maven.petstore.petstore.parameter; + +import io.swagger.v3.plugin.maven.resources.model.User; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Schema; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.QueryParam; + +/** + * Class with a single parameter annotated with jaxrs and open api annotation. + */ +public class OpenAPIWithImplementationJaxRSAnnotatedParameter { + @GET + @Path("/openapiwithimplementationjaxrsannotatedparameter") + @Operation(operationId = "create User") + public User findUser(@Parameter(description = "idParam", schema = @Schema(implementation = User.class)) + @QueryParam("id") final String id) { + return new User(); + } +} diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/parameter/ParametersResource.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/parameter/ParametersResource.java new file mode 100644 index 0000000000..c28cc96b3f --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/parameter/ParametersResource.java @@ -0,0 +1,87 @@ +package io.swagger.v3.plugin.maven.petstore.petstore.parameter; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.enums.Explode; +import io.swagger.v3.oas.annotations.enums.ParameterIn; +import io.swagger.v3.oas.annotations.enums.ParameterStyle; +import io.swagger.v3.oas.annotations.media.ArraySchema; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; + +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.QueryParam; + +/** + * Resource with some Parameters examples + */ +public class ParametersResource { + @Path("/parameters") + @POST + @Operation( + operationId = "subscribe", + description = "subscribes a client to updates relevant to the requestor's account, as " + + "identified by the input token. The supplied url will be used as the delivery address for response payloads", + parameters = { + @Parameter(in = ParameterIn.PATH, name = "subscriptionId", required = true, + schema = @Schema(implementation = RepeatableParametersResource.SubscriptionResponse.class), style = ParameterStyle.SIMPLE), + @Parameter(in = ParameterIn.QUERY, name = "formId", required = true, + example = "Example"), + @Parameter(in = ParameterIn.QUERY, name = "explodeFalse", required = true, explode = Explode.FALSE, + schema = @Schema(implementation = ParametersResource.SubscriptionResponse.class)), + @Parameter(in = ParameterIn.QUERY, name = "explodeTrue", required = true, explode = Explode.TRUE, + schema = @Schema(implementation = ParametersResource.SubscriptionResponse.class)), + @Parameter(in = ParameterIn.QUERY, name = "explodeAvoiding", required = true, explode = Explode.TRUE, + schema = @Schema( + type = "int", + format = "id", + description = "the generated id", + accessMode = Schema.AccessMode.READ_ONLY + )), + @Parameter(in = ParameterIn.QUERY, name = "arrayParameter", required = true, explode = Explode.TRUE, + array = @ArraySchema(maxItems = 10, minItems = 1, + schema = @Schema(implementation = ParametersResource.SubscriptionResponse.class), + uniqueItems = true + ) + , + schema = @Schema( + type = "int", + format = "id", + description = "the generated id", + accessMode = Schema.AccessMode.READ_ONLY), + content = @Content(schema = @Schema(type = "number", + description = "the generated id", + accessMode = Schema.AccessMode.READ_ONLY)) + ), + @Parameter(in = ParameterIn.QUERY, name = "arrayParameterImplementation", required = true, explode = Explode.TRUE, + array = @ArraySchema(maxItems = 10, minItems = 1, + schema = @Schema(implementation = ParametersResource.SubscriptionResponse.class), + uniqueItems = true + ) + ), + @Parameter(in = ParameterIn.QUERY, name = "arrayParameterImplementation2", required = true, explode = Explode.TRUE, + schema = @Schema(implementation = ParametersResource.SubscriptionResponse.class)) + + }, + responses = { + @ApiResponse( + description = "test description", content = @Content( + mediaType = "*/*", + schema = + @Schema( + implementation = ParametersResource.SubscriptionResponse.class) + )) + }) + @Consumes({"application/json", "application/xml"}) + public ParametersResource.SubscriptionResponse subscribe(@Parameter(description = "idParam") + @QueryParam("id") final String id) { + return null; + } + + static class SubscriptionResponse { + public String subscriptionId; + } +} diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/parameter/RepeatableParametersResource.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/parameter/RepeatableParametersResource.java new file mode 100644 index 0000000000..530d9c30ee --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/parameter/RepeatableParametersResource.java @@ -0,0 +1,80 @@ +package io.swagger.v3.plugin.maven.petstore.petstore.parameter; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.enums.Explode; +import io.swagger.v3.oas.annotations.enums.ParameterIn; +import io.swagger.v3.oas.annotations.enums.ParameterStyle; +import io.swagger.v3.oas.annotations.media.ArraySchema; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; + +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.Path; + +public class RepeatableParametersResource { + @Path("/repeatableparameter") + @POST + @Parameter(in = ParameterIn.PATH, name = "subscriptionId", required = true, + schema = @Schema(implementation = ParametersResource.SubscriptionResponse.class), style = ParameterStyle.SIMPLE) + @Parameter(in = ParameterIn.QUERY, name = "formId", required = true, + example = "Example") + @Parameter(in = ParameterIn.QUERY, name = "explodeFalse", required = true, explode = Explode.FALSE, + schema = @Schema(implementation = ParametersResource.SubscriptionResponse.class)) + @Parameter(in = ParameterIn.QUERY, name = "explodeTrue", required = true, explode = Explode.TRUE, + schema = @Schema(implementation = ParametersResource.SubscriptionResponse.class)) + @Parameter(in = ParameterIn.QUERY, name = "explodeAvoiding", required = true, explode = Explode.TRUE, + schema = @Schema( + type = "int", + format = "id", + description = "the generated id", + accessMode = Schema.AccessMode.READ_ONLY + )) + @Parameter(in = ParameterIn.QUERY, name = "arrayParameter", required = true, explode = Explode.TRUE, + array = @ArraySchema(maxItems = 10, minItems = 1, + schema = @Schema(implementation = ParametersResource.SubscriptionResponse.class), + uniqueItems = true + ) + , + schema = @Schema( + type = "int", + format = "id", + description = "the generated id", + accessMode = Schema.AccessMode.READ_ONLY), + content = @Content(schema = @Schema(type = "number", + description = "the generated id", + accessMode = Schema.AccessMode.READ_ONLY)) + ) + @Parameter(in = ParameterIn.QUERY, name = "arrayParameterImplementation", required = true, explode = Explode.TRUE, + array = @ArraySchema(maxItems = 10, minItems = 1, + schema = @Schema(implementation = ParametersResource.SubscriptionResponse.class), + uniqueItems = true + ) + ) + @Parameter(in = ParameterIn.QUERY, name = "arrayParameterImplementation2", required = true, explode = Explode.TRUE, + schema = @Schema(implementation = ParametersResource.SubscriptionResponse.class)) + @Operation( + operationId = "subscribe", + description = "subscribes a client to updates relevant to the requestor's account, as " + + "identified by the input token. The supplied url will be used as the delivery address for response payloads", + responses = { + @ApiResponse( + description = "test description", content = @Content( + mediaType = "*/*", + schema = + @Schema( + implementation = ParametersResource.SubscriptionResponse.class) + )) + }) + @Consumes({"application/json", "application/xml"}) + public ParametersResource.SubscriptionResponse subscribe() { + return null; + } + + static class SubscriptionResponse { + public String subscriptionId; + } +} + diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/parameter/SingleJaxRSAnnotatedParameter.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/parameter/SingleJaxRSAnnotatedParameter.java new file mode 100644 index 0000000000..6542dde245 --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/parameter/SingleJaxRSAnnotatedParameter.java @@ -0,0 +1,20 @@ +package io.swagger.v3.plugin.maven.petstore.petstore.parameter; + +import io.swagger.v3.plugin.maven.resources.model.User; +import io.swagger.v3.oas.annotations.Operation; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.QueryParam; + +/** + * Class with a single parameter annotated with jaxrs. + */ +public class SingleJaxRSAnnotatedParameter { + @GET + @Path("/singlejaxrsannotatedparameter") + @Operation(operationId = "create User") + public User findUser(@QueryParam("id") final String id) { + return new User(); + } +} diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/parameter/SingleNotAnnotatedParameter.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/parameter/SingleNotAnnotatedParameter.java new file mode 100644 index 0000000000..a645892c6f --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/parameter/SingleNotAnnotatedParameter.java @@ -0,0 +1,19 @@ +package io.swagger.v3.plugin.maven.petstore.petstore.parameter; + +import io.swagger.v3.plugin.maven.resources.model.User; +import io.swagger.v3.oas.annotations.Operation; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +/** + * Class with a single not annotated parameter. + */ +public class SingleNotAnnotatedParameter { + @GET + @Path("/singlenoannotatedparameter") + @Operation(operationId = "create User") + public User findUser(final String id) { + return new User(); + } +} diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/requestbody/RequestBodyMethodPriorityResource.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/requestbody/RequestBodyMethodPriorityResource.java new file mode 100644 index 0000000000..cc063d4ea6 --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/requestbody/RequestBodyMethodPriorityResource.java @@ -0,0 +1,28 @@ +package io.swagger.v3.plugin.maven.petstore.petstore.requestbody; + +import io.swagger.v3.plugin.maven.resources.model.User; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.parameters.RequestBody; + +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.core.Response; + +/** + * Resource with RequestBody inside Operation and another in Method + */ +public class RequestBodyMethodPriorityResource { + @POST + @Path("/requestbodymethodpriority") + @Operation(summary = "Create user", + description = "This can only be done by the logged in user.", + requestBody = @RequestBody(description = "Inside Operation")) + @RequestBody(description = "Created user object on Method", required = true, + content = @Content( + schema = @Schema(implementation = User.class))) + public Response methodWithRequestBodyAndTwoParameters(final User user) { + return Response.ok().entity("").build(); + } +} diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/requestbody/RequestBodyParameterPriorityResource.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/requestbody/RequestBodyParameterPriorityResource.java new file mode 100644 index 0000000000..abf363d0b3 --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/requestbody/RequestBodyParameterPriorityResource.java @@ -0,0 +1,29 @@ +package io.swagger.v3.plugin.maven.petstore.petstore.requestbody; + +import io.swagger.v3.plugin.maven.resources.model.User; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.parameters.RequestBody; + +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.core.Response; + +/** + * Resource with RequestBody inside Operation and another in Method + */ +public class RequestBodyParameterPriorityResource { + @POST + @Path("/requestbodyparameterpriority") + @Operation(summary = "Create user", + description = "This can only be done by the logged in user.", + requestBody = @RequestBody(description = "Inside Operation")) + @RequestBody(description = "On method") + public Response methodWithRequestBodyAndTwoParameters( + @RequestBody(description = "Created user object inside Parameter", required = true, + content = @Content( + schema = @Schema(implementation = User.class)))final User user) { + return Response.ok().entity("").build(); + } +} diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/requestbody/RequestBodyResource.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/requestbody/RequestBodyResource.java new file mode 100644 index 0000000000..a72364537c --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/requestbody/RequestBodyResource.java @@ -0,0 +1,113 @@ +package io.swagger.v3.plugin.maven.petstore.petstore.requestbody; + +import io.swagger.v3.plugin.maven.resources.model.Pet; +import io.swagger.v3.plugin.maven.resources.model.User; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.parameters.RequestBody; + +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Response; + +/** + * Resource with RequestBody examples + */ +public class RequestBodyResource { + @GET + @Path("/methodWithRequestBodyWithoutContent") + @Operation(summary = "Create user", + description = "This can only be done by the logged in user.") + public Response methodWithRequestBodyWithoutContent( + @RequestBody(description = "Created user object", required = true) final User user) { + return Response.ok().entity("").build(); + } + + @GET + @Path("/methodWithRequestBodyWithoutContentWithoutImplementation") + @Operation(summary = "Create user", + description = "This can only be done by the logged in user.") + public Response methodWithRequestBodyWithoutContentWithoutImplementation( + @RequestBody(description = "Created user object", required = true, + content = @Content( + schema = @Schema(name = "User", description = "User description", + example = "User Description", required = true))) final User user) { + return Response.ok().entity("").build(); + } + + @POST + @Path("/methodWithRequestBodyAndTwoParameters") + @Operation(summary = "Create user", + description = "This can only be done by the logged in user.") + public Response methodWithRequestBodyAndTwoParameters( + @RequestBody(description = "Created user object", required = true, + content = @Content( + schema = @Schema(implementation = User.class))) final User user, + @QueryParam("name") final String name, @QueryParam("code") final String code) { + return Response.ok().entity("").build(); + } + + @PUT + @Path("/methodWithRequestBodyWithoutAnnotation") + @Operation(summary = "Modify user", + description = "Modifying user.") + public Response methodWithRequestBodyWithoutAnnotation( + final User user) { + return Response.ok().entity("").build(); + } + + @DELETE + @Path("/methodWithoutRequestBodyAndTwoParameters") + @Operation(summary = "Delete user", + description = "This can only be done by the logged in user.") + public Response methodWithoutRequestBodyAndTwoParameters( + @QueryParam("name") final String name, @QueryParam("code") final String code) { + return Response.ok().entity("").build(); + } + + @PUT + @Path("/methodWithRequestBodyWithoutAnnotationAndTwoConsumes") + @Operation(summary = "Modify pet", + description = "Modifying pet.") + @Consumes({"application/json", "application/xml"}) + public Response methodWithRequestBodyWithoutAnnotationAndTwoConsumes( + final User user) { + return Response.ok().entity("").build(); + } + + @POST + @Path("/methodWithTwoRequestBodyWithoutAnnotationAndTwoConsumes") + @Operation(summary = "Create pet", + description = "Creating pet.") + @Consumes({"application/json", "application/xml"}) + public Response methodWithTwoRequestBodyWithoutAnnotationAndTwoConsumes( + final Pet pet, final User user) { + return Response.ok().entity("").build(); + } + + @POST + @Path("/methodWithTwoRequestBodyWithAnnotationAndTwoConsumes") + @Operation(summary = "Create pet", + description = "Creating pet.") + @Consumes({"application/json", "application/xml"}) + public Response methodWithTwoRequestBodyWithAnnotationAndTwoConsumes( + final @RequestBody(description = "Request Body Pet") Pet pet, + @RequestBody(description = "Request Body User") final User user) { + return Response.ok().entity("").build(); + } + + @DELETE + @Path("/methodWithOneSimpleRequestBody") + @Operation(summary = "Delete pet", + description = "Deleting pet.") + @Consumes({"application/json", "application/xml"}) + public Response methodWithOneSimpleRequestBody(final int id) { + return Response.ok().entity("").build(); + } +} diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/responses/ComplexResponseResource.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/responses/ComplexResponseResource.java new file mode 100644 index 0000000000..488614cda4 --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/responses/ComplexResponseResource.java @@ -0,0 +1,34 @@ +package io.swagger.v3.plugin.maven.petstore.petstore.responses; + +import io.swagger.v3.plugin.maven.resources.exception.NotFoundException; +import io.swagger.v3.plugin.maven.resources.model.Pet; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +/** + * Resource with some responses + */ +public class ComplexResponseResource { + @GET + @Path("/complexresponse") + @Operation(summary = "Find pets", + description = "Returns the Pets", + responses = { + @ApiResponse(description = "Response inside Operation", responseCode = "200", + content = @Content(schema = + @Schema(implementation = Pet.class))), + @ApiResponse(description = "Default Pet", + content = @Content(schema = + @Schema(name = "Default Pet", description = "Default Pet", + required = true, example = "New Pet"))) + }) + @ApiResponse(responseCode = "404", description = "Couldn't find pet") + public Pet getPets() throws NotFoundException { + return new Pet(); + } +} diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/responses/ImplementationResponseResource.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/responses/ImplementationResponseResource.java new file mode 100644 index 0000000000..c73a9a4346 --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/responses/ImplementationResponseResource.java @@ -0,0 +1,71 @@ +package io.swagger.v3.plugin.maven.petstore.petstore.responses; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +/** + * Resource with a Response at Method Level + */ +public class ImplementationResponseResource { + @GET + @Path("/implementationresponse") + @Operation( + summary = "Simple get operation", + description = "Defines a simple get operation with no inputs and a complex output object", + operationId = "getWithPayloadResponse", + deprecated = true, + responses = { + @ApiResponse( + responseCode = "200", + description = "voila!", + content = { + @Content( + mediaType = "application/json", + schema = + @Schema( + implementation = ImplementationResponseResource.SampleResponseSchema.class) + ), + @Content( + mediaType = "application/json", + schema = + @Schema( + implementation = ImplementationResponseResource.SecondSampleResponseSchema.class) + ) + } + + ), + @ApiResponse( + responseCode = "400", + description = "boo", + content = @Content( + mediaType = "*/*", + schema = + @Schema(implementation = ImplementationResponseResource.GenericError.class) + ) + ) + } + ) + + public void getResponses() { + } + + static class SampleResponseSchema { + @Schema(description = "the user id") + private String id; + } + + static class SecondSampleResponseSchema { + @Schema(description = "the user id") + private String id; + } + + static class GenericError { + private int code; + private String message; + } +} diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/responses/MethodResponseResource.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/responses/MethodResponseResource.java new file mode 100644 index 0000000000..336cb804ac --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/responses/MethodResponseResource.java @@ -0,0 +1,24 @@ +package io.swagger.v3.plugin.maven.petstore.petstore.responses; + +import io.swagger.v3.plugin.maven.resources.exception.NotFoundException; +import io.swagger.v3.plugin.maven.resources.model.Pet; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.responses.ApiResponse; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.core.Response; + +/** + * Resource with a Response at Method Level + */ +public class MethodResponseResource { + @GET + @Path("/responseinmethod") + @Operation(summary = "Find pets", + description = "Returns the Pets") + @ApiResponse(responseCode = "200", description = "Status OK") + public Response getPets() throws NotFoundException { + return Response.ok().entity(new Pet()).build(); + } +} diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/responses/NoImplementationResponseResource.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/responses/NoImplementationResponseResource.java new file mode 100644 index 0000000000..069698aaf2 --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/responses/NoImplementationResponseResource.java @@ -0,0 +1,66 @@ +package io.swagger.v3.plugin.maven.petstore.petstore.responses; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.links.Link; +import io.swagger.v3.oas.annotations.links.LinkParameter; +import io.swagger.v3.oas.annotations.responses.ApiResponse; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.QueryParam; + +/** + * Resource with a Response at Method Level + */ +public class NoImplementationResponseResource { + @Path("/noimplementationresponseresource") + @Operation(operationId = "getUser", + responses = { + @ApiResponse(description = "test description", responseCode = "400", + links = { + @Link( + name = "user", + operationId = "getUser", + operationRef = "#/components/links/MyLink", + parameters = @LinkParameter( + name = "userId", + expression = "$request.query.userId")) + }), + @ApiResponse(description = "200 description", responseCode = "200", + links = { + @Link( + name = "pet", + operationId = "getUser", + operationRef = "#/components/links/MyLink", + parameters = @LinkParameter( + name = "userId", + expression = "$request.query.userId")) + }) + } + ) + @GET + public NoImplementationResponseResource.User getUser(@QueryParam("userId") final String userId) { + return null; + } + + static class User { + private String id; + private String username; + + public String getId() { + return id; + } + + public void setId(final String id) { + this.id = id; + } + + public String getUsername() { + return username; + } + + public void setUsername(final String username) { + this.username = username; + } + } +} diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/responses/NoResponseResource.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/responses/NoResponseResource.java new file mode 100644 index 0000000000..3a7ea5b8ea --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/responses/NoResponseResource.java @@ -0,0 +1,21 @@ +package io.swagger.v3.plugin.maven.petstore.petstore.responses; + +import io.swagger.v3.plugin.maven.resources.exception.NotFoundException; +import io.swagger.v3.plugin.maven.resources.model.User; +import io.swagger.v3.oas.annotations.Operation; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +/** + * Resource with a Response at Method Level + */ +public class NoResponseResource { + @GET + @Path("/noresponse") + @Operation(summary = "Find pets", + description = "Returns the Pets") + public User getPets() throws NotFoundException { + return new User(); + } +} diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/responses/OperationResponseResource.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/responses/OperationResponseResource.java new file mode 100644 index 0000000000..dfacd71fa6 --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/responses/OperationResponseResource.java @@ -0,0 +1,25 @@ +package io.swagger.v3.plugin.maven.petstore.petstore.responses; + +import io.swagger.v3.plugin.maven.resources.exception.NotFoundException; +import io.swagger.v3.plugin.maven.resources.model.User; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.responses.ApiResponse; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.core.Response; + +/** + * Resource with the response in the Operation Annotation + */ +public class OperationResponseResource { + @GET + @Path("/responseinoperation") + @Operation(summary = "Find Users", + description = "Returns the Users", + responses = {@ApiResponse(responseCode = "200", description = "Status OK")}) + public Response getUsers() throws NotFoundException { + return Response.ok().entity(new User()).build(); + } + +} diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/responses/PriorityResponseResource.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/responses/PriorityResponseResource.java new file mode 100644 index 0000000000..06394cfc75 --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/responses/PriorityResponseResource.java @@ -0,0 +1,25 @@ +package io.swagger.v3.plugin.maven.petstore.petstore.responses; + +import io.swagger.v3.plugin.maven.resources.exception.NotFoundException; +import io.swagger.v3.plugin.maven.resources.model.Pet; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.responses.ApiResponse; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.core.Response; + +/** + * Resource with a Response at Method Level and Operation Level. + */ +public class PriorityResponseResource { + @GET + @Path("/priorityresponses") + @Operation(summary = "Find pets", + description = "Returns the Pets", + responses = {@ApiResponse(responseCode = "200", description = "Inside Operation Response")}) + @ApiResponse(responseCode = "200", description = "Inside Method Operation") + public Response getPets() throws NotFoundException { + return Response.ok().entity(new Pet()).build(); + } +} diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/security/SecurityResource.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/security/SecurityResource.java new file mode 100644 index 0000000000..9ab1d59b4e --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/security/SecurityResource.java @@ -0,0 +1,61 @@ +package io.swagger.v3.plugin.maven.petstore.petstore.security; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.enums.SecuritySchemeIn; +import io.swagger.v3.oas.annotations.enums.SecuritySchemeType; +import io.swagger.v3.oas.annotations.security.OAuthFlow; +import io.swagger.v3.oas.annotations.security.OAuthFlows; +import io.swagger.v3.oas.annotations.security.OAuthScope; +import io.swagger.v3.oas.annotations.security.SecurityRequirement; +import io.swagger.v3.oas.annotations.security.SecurityScheme; + +import javax.ws.rs.GET; +import javax.ws.rs.PATCH; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; + +@SecurityScheme(name = "myOauth2Security", + type = SecuritySchemeType.OAUTH2, + in = SecuritySchemeIn.HEADER, + description = "myOauthSecurity Description", + flows = @OAuthFlows(implicit = @OAuthFlow(authorizationUrl = "http://x.com", + scopes = @OAuthScope( + name = "write:pets", + description = "modify pets in your account")) + ) +) +@SecurityRequirement(name = "security_key", + scopes = {"write:pets", "read:pets"} +) +@SecurityRequirement(name = "myOauth2Security", + scopes = {"write:pets"} +) +@Path("/security") +public class SecurityResource { + @GET + @Operation(operationId = "Operation Id", + description = "description") + @SecurityRequirement(name = "security_key", + scopes = {"write:pets", "read:pets"} + ) + public void getSecurity() { + } + + @PATCH + @Operation(operationId = "Operation Id 2", + description = "description 2") + @SecurityRequirement(name = "security_key2", + scopes = {"write:pets", "read:pets"} + ) + public void getSecurity2() { + } + + @PUT + @Operation(operationId = "Operation Id 3", + description = "description 3", security = + @SecurityRequirement(name = "security_key3", + scopes = {"write:pets", "read:pets"} + )) + public void setSecurity(String security) { + } +} diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/tags/CompleteTagResource.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/tags/CompleteTagResource.java new file mode 100644 index 0000000000..5ea76e9ef6 --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/tags/CompleteTagResource.java @@ -0,0 +1,31 @@ +package io.swagger.v3.plugin.maven.petstore.petstore.tags; + +import io.swagger.v3.oas.annotations.ExternalDocumentation; +import io.swagger.v3.oas.annotations.OpenAPIDefinition; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.core.Response; + +@OpenAPIDefinition(tags = { + @Tag(name = "Definition First Tag"), + @Tag(name = "Definition Second Tag full", description = "desc definition") +}) +@Tag(name = "Second Tag") +@Tag(name = "Fourth Tag Full", description = "desc class", externalDocs = @ExternalDocumentation(description = "docs desc class")) +@Tag(name = "Fifth Tag Full", description = "desc class", externalDocs = @ExternalDocumentation(description = "docs desc class")) +@Tag(name = "Sixth Tag") +public class CompleteTagResource { + + @GET + @Path("/completetags") + @Operation(tags = {"Example Tag", "Second Tag"}) + @Tag(name = "Third Tag") + @Tag(name = "Second Tag") + @Tag(name = "Fourth Tag Full", description = "desc", externalDocs = @ExternalDocumentation(description = "docs desc")) + public Response getTags() { + return Response.ok().entity("ok").build(); + } +} diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/tags/TagClassResource.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/tags/TagClassResource.java new file mode 100644 index 0000000000..f4e9f345f7 --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/tags/TagClassResource.java @@ -0,0 +1,14 @@ +package io.swagger.v3.plugin.maven.petstore.petstore.tags; + +import io.swagger.v3.oas.annotations.ExternalDocumentation; +import io.swagger.v3.oas.annotations.tags.Tag; + +/** + * Class with Tag Annotations at Class level + */ +@Tag(name = "Second Tag") +@Tag(name = "Fourth Tag Full", description = "desc class", externalDocs = @ExternalDocumentation(description = "docs desc class")) +@Tag(name = "Fifth Tag Full", description = "desc class", externalDocs = @ExternalDocumentation(description = "docs desc class")) +@Tag(name = "Sixth Tag") +public class TagClassResource { +} diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/tags/TagMethodResource.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/tags/TagMethodResource.java new file mode 100644 index 0000000000..e6294186f1 --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/tags/TagMethodResource.java @@ -0,0 +1,19 @@ +package io.swagger.v3.plugin.maven.petstore.petstore.tags; + +import io.swagger.v3.oas.annotations.ExternalDocumentation; +import io.swagger.v3.oas.annotations.tags.Tag; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.core.Response; + +public class TagMethodResource { + @GET + @Path("/tagsinmethod") + @Tag(name = "Third Tag") + @Tag(name = "Second Tag") + @Tag(name = "Fourth Tag Full", description = "desc", externalDocs = @ExternalDocumentation(description = "docs desc")) + public Response getTags() { + return Response.ok().entity("ok").build(); + } +} diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/tags/TagOpenAPIDefinitionResource.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/tags/TagOpenAPIDefinitionResource.java new file mode 100644 index 0000000000..dae705929d --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/tags/TagOpenAPIDefinitionResource.java @@ -0,0 +1,14 @@ +package io.swagger.v3.plugin.maven.petstore.petstore.tags; + +import io.swagger.v3.oas.annotations.OpenAPIDefinition; +import io.swagger.v3.oas.annotations.tags.Tag; + +/** + * Tag in the OpenAPIDefinition annotation + */ +@OpenAPIDefinition(tags = { + @Tag(name = "Definition First Tag"), + @Tag(name = "Definition Second Tag full", description = "desc definition") +}) +public class TagOpenAPIDefinitionResource { +} diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/tags/TagOperationResource.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/tags/TagOperationResource.java new file mode 100644 index 0000000000..b01e09f426 --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/petstore/petstore/tags/TagOperationResource.java @@ -0,0 +1,20 @@ +package io.swagger.v3.plugin.maven.petstore.petstore.tags; + +import io.swagger.v3.oas.annotations.Operation; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.core.Response; + +/** + * Resource with a Tag at Operation Level + */ +public class TagOperationResource { + + @GET + @Path("/tagoperation") + @Operation(tags = {"Example Tag", "Second Tag"}) + public Response getTags() { + return Response.ok().entity("ok").build(); + } +} diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/resources/QueryResultBean.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/resources/QueryResultBean.java new file mode 100644 index 0000000000..e64264e309 --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/resources/QueryResultBean.java @@ -0,0 +1,43 @@ +/** + * Copyright 2016 SmartBear Software + *

    + * 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.swagger.v3.plugin.maven.resources; + +import javax.ws.rs.QueryParam; + +public class QueryResultBean { + @QueryParam("skip") + private Integer skip; + + @QueryParam("limit") + private Integer limit; + + public Integer getSkip() { + return skip; + } + + public void setSkip(Integer skip) { + this.skip = skip; + } + + public Integer getLimit() { + return limit; + } + + public void setLimit(Integer limit) { + this.limit = limit; + } +} diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/resources/data/PetData.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/resources/data/PetData.java new file mode 100644 index 0000000000..a3999c8875 --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/resources/data/PetData.java @@ -0,0 +1,151 @@ +/** + * Copyright 2016 SmartBear Software + *

    + * 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.swagger.v3.plugin.maven.resources.data; + +import io.swagger.v3.plugin.maven.resources.model.Category; +import io.swagger.v3.plugin.maven.resources.model.Pet; +import io.swagger.v3.plugin.maven.resources.model.Tag; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +public class PetData { + static List pets = new ArrayList(); + static List categories = new ArrayList(); + + static { + categories.add(createCategory(1, "Dogs")); + categories.add(createCategory(2, "Cats")); + categories.add(createCategory(3, "Rabbits")); + categories.add(createCategory(4, "Lions")); + + pets.add(createPet(1, categories.get(1), "Cat 1", new String[]{ + "url1", "url2"}, new String[]{"tag1", "tag2"}, "available")); + pets.add(createPet(2, categories.get(1), "Cat 2", new String[]{ + "url1", "url2"}, new String[]{"tag2", "tag3"}, "available")); + pets.add(createPet(3, categories.get(1), "Cat 3", new String[]{ + "url1", "url2"}, new String[]{"tag3", "tag4"}, "pending")); + + pets.add(createPet(4, categories.get(0), "Dog 1", new String[]{ + "url1", "url2"}, new String[]{"tag1", "tag2"}, "available")); + pets.add(createPet(5, categories.get(0), "Dog 2", new String[]{ + "url1", "url2"}, new String[]{"tag2", "tag3"}, "sold")); + pets.add(createPet(6, categories.get(0), "Dog 3", new String[]{ + "url1", "url2"}, new String[]{"tag3", "tag4"}, "pending")); + + pets.add(createPet(7, categories.get(3), "Lion 1", new String[]{ + "url1", "url2"}, new String[]{"tag1", "tag2"}, "available")); + pets.add(createPet(8, categories.get(3), "Lion 2", new String[]{ + "url1", "url2"}, new String[]{"tag2", "tag3"}, "available")); + pets.add(createPet(9, categories.get(3), "Lion 3", new String[]{ + "url1", "url2"}, new String[]{"tag3", "tag4"}, "available")); + + pets.add(createPet(10, categories.get(2), "Rabbit 1", new String[]{ + "url1", "url2"}, new String[]{"tag3", "tag4"}, "available")); + } + + public Pet getPetById(long petId) { + for (Pet pet : pets) { + if (pet.getId() == petId) { + return pet; + } + } + return null; + } + + public List findPetByStatus(String status) { + String[] statues = status.split(","); + List result = new ArrayList(); + for (Pet pet : pets) { + for (String s : statues) { + if (s.equals(pet.getStatus())) { + result.add(pet); + } + } + } + return result; + } + + public List findPetByCategory(Category category) { + return pets.stream().filter(pet -> category.equals(pet.getCategory())).collect(Collectors.toList()); + } + + public List findPetByTags(String tags) { + String[] tagList = tags.split(","); + List result = new ArrayList(); + for (Pet pet : pets) { + if (null != pet.getTags()) { + for (Tag tag : pet.getTags()) { + for (String tagListString : tagList) { + if (tagListString.equals(tag.getName())) { + result.add(pet); + } + } + } + } + } + return result; + } + + public void addPet(Pet pet) { + if (pets.size() > 0) { + for (int i = pets.size() - 1; i >= 0; i--) { + if (pets.get(i).getId() == pet.getId()) { + pets.remove(i); + } + } + } + pets.add(pet); + } + + static Pet createPet(long id, Category cat, String name, String[] urls, + String[] tags, String status) { + Pet pet = new Pet(); + pet.setId(id); + pet.setCategory(cat); + pet.setName(name); + if (null != urls) { + List urlObjs = new ArrayList(); + for (String urlString : urls) { + urlObjs.add(urlString); + } + pet.setPhotoUrls(urlObjs); + } + List tagObjs = new ArrayList(); + int i = 0; + if (null != tags) { + for (String tagString : tags) { + i = i + 1; + Tag tag = new Tag(); + tag.setId(i); + tag.setName(tagString); + tagObjs.add(tag); + } + } + pet.setTags(tagObjs); + pet.setStatus(status); + return pet; + } + + static Category createCategory(long id, String name) { + Category category = new Category(); + category.setId(id); + category.setName(name); + return category; + } +} \ No newline at end of file diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/resources/data/UserData.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/resources/data/UserData.java new file mode 100644 index 0000000000..a745864832 --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/resources/data/UserData.java @@ -0,0 +1,98 @@ +/** + * Copyright 2016 SmartBear Software + *

    + * 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.swagger.v3.plugin.maven.resources.data; + +import io.swagger.v3.plugin.maven.resources.model.User; + +import java.util.ArrayList; +import java.util.List; + +public class UserData { + static List users = new ArrayList(); + + static { + users.add(createUser(1, "user1", "first name 1", "last name 1", + "email1@test.com", "123-456-7890", 1)); + users.add(createUser(2, "user2", "first name 2", "last name 2", + "email2@test.com", "123-456-7890", 2)); + users.add(createUser(3, "user3", "first name 3", "last name 3", + "email3@test.com", "123-456-7890", 3)); + users.add(createUser(4, "user4", "first name 4", "last name 4", + "email4@test.com", "123-456-7890", 1)); + users.add(createUser(5, "user5", "first name 5", "last name 5", + "email5@test.com", "123-456-7890", 2)); + users.add(createUser(6, "user6", "first name 6", "last name 6", + "email6@test.com", "123-456-7890", 3)); + users.add(createUser(7, "user7", "first name 7", "last name 7", + "email7@test.com", "123-456-7890", 1)); + users.add(createUser(8, "user8", "first name 8", "last name 8", + "email8@test.com", "123-456-7890", 2)); + users.add(createUser(9, "user9", "first name 9", "last name 9", + "email9@test.com", "123-456-7890", 3)); + users.add(createUser(10, "user10", "first name 10", "last name 10", + "email10@test.com", "123-456-7890", 1)); + users.add(createUser(11, "user?10", "first name ?10", "last name ?10", + "email101@test.com", "123-456-7890", 1)); + + } + + public User findUserByName(String username) { + for (User user : users) { + if (user.getUsername().equals(username)) { + return user; + } + } + return null; + } + + public void addUser(User user) { + if (users.size() > 0) { + for (int i = users.size() - 1; i >= 0; i--) { + if (users.get(i).getUsername().equals(user.getUsername())) { + users.remove(i); + } + } + } + users.add(user); + } + + public boolean removeUser(String username) { + if (users.size() > 0) { + for (int i = users.size() - 1; i >= 0; i--) { + if (users.get(i).getUsername().equals(username)) { + users.remove(i); + return true; + } + } + } + return false; + } + + private static User createUser(long id, String username, String firstName, + String lastName, String email, String phone, int userStatus) { + User user = new User(); + user.setId(id); + user.setUsername(username); + user.setFirstName(firstName); + user.setLastName(lastName); + user.setEmail(email); + user.setPassword("XXXXXXXXXXX"); + user.setPhone(phone); + user.setUserStatus(userStatus); + return user; + } +} \ No newline at end of file diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/resources/exception/ApiException.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/resources/exception/ApiException.java new file mode 100644 index 0000000000..9228e1e86e --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/resources/exception/ApiException.java @@ -0,0 +1,26 @@ +/** + * Copyright 2016 SmartBear Software + *

    + * 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.swagger.v3.plugin.maven.resources.exception; + +public class ApiException extends Exception { + private int code; + + public ApiException(int code, String msg) { + super(msg); + this.code = code; + } +} diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/resources/exception/NotFoundException.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/resources/exception/NotFoundException.java new file mode 100644 index 0000000000..95c0775184 --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/resources/exception/NotFoundException.java @@ -0,0 +1,26 @@ +/** + * Copyright 2016 SmartBear Software + *

    + * 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.swagger.v3.plugin.maven.resources.exception; + +public class NotFoundException extends ApiException { + private int code; + + public NotFoundException(int code, String msg) { + super(code, msg); + this.code = code; + } +} diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/resources/model/Category.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/resources/model/Category.java new file mode 100644 index 0000000000..679f8bdbff --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/resources/model/Category.java @@ -0,0 +1,51 @@ +/** + * Copyright 2016 SmartBear Software + *

    + * 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.swagger.v3.plugin.maven.resources.model; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement(name = "Category") +public class Category { + private long id; + private String name; + + @XmlElement(name = "id") + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + @XmlElement(name = "name") + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Category() { + } + + public Category(String name) { + this.name = name; + } +} \ No newline at end of file diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/resources/model/CustomGenerator.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/resources/model/CustomGenerator.java new file mode 100644 index 0000000000..f2e2047d9a --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/resources/model/CustomGenerator.java @@ -0,0 +1,32 @@ +package io.swagger.v3.plugin.maven.resources.model; + +import com.fasterxml.jackson.annotation.ObjectIdGenerator; +import com.fasterxml.jackson.annotation.ObjectIdGenerators; + +public class CustomGenerator extends ObjectIdGenerators.PropertyGenerator { + private static final long serialVersionUID = 1L; + + protected CustomGenerator(Class scope) { + super(scope); + } + + @Override + public ObjectIdGenerator forScope(Class scope) { + return null; + } + + @Override + public ObjectIdGenerator newForSerialization(Object context) { + return null; + } + + @Override + public IdKey key(Object key) { + return null; + } + + @Override + public Object generateId(Object forPojo) { + return null; + } +} \ No newline at end of file diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/resources/model/ExtensionUser.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/resources/model/ExtensionUser.java new file mode 100644 index 0000000000..210c56a332 --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/resources/model/ExtensionUser.java @@ -0,0 +1,130 @@ +/** + * Copyright 2016 SmartBear Software + *

    + * 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.swagger.v3.plugin.maven.resources.model; + +import io.swagger.v3.oas.annotations.extensions.Extension; +import io.swagger.v3.oas.annotations.extensions.ExtensionProperty; +import io.swagger.v3.oas.annotations.media.Schema; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement(name = "User") +@Schema( + description = "User", + extensions = { + @Extension(name = "x-user", properties = { + @ExtensionProperty(name = "name", value = "Josh")}), + @Extension(name = "user-extensions", properties = { + @ExtensionProperty(name = "lastName", value = "Hart"), + @ExtensionProperty(name = "address", value = "House")}) + } +) +public class ExtensionUser { + private long id; + private String username; + private String firstName; + private String lastName; + private String email; + private String password; + private String phone; + private int userStatus; + + @XmlElement(name = "id") + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + @XmlElement(name = "firstName") + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + @XmlElement(name = "username") + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + @XmlElement(name = "lastName") + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + @XmlElement(name = "email") + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + @XmlElement(name = "password") + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + @XmlElement(name = "phone") + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + @XmlElement(name = "userStatus") + //@Schema(description = "User Status", type = "string", allowableValues = {"1-registered", "2-active", "3-closed"}) + @Schema( + description = "User Status", + allowableValues = "1-registered,2-active,3-closed", + extensions = { + @Extension(name = "x-userStatus", properties = { + @ExtensionProperty(name = "name", value = "Josh")}), + @Extension(name = "userStatus-extensions", properties = { + @ExtensionProperty(name = "lastName", value = "Hart"), + @ExtensionProperty(name = "address", value = "House")}) + } + ) + public int getUserStatus() { + return userStatus; + } + + public void setUserStatus(int userStatus) { + this.userStatus = userStatus; + } +} \ No newline at end of file diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/resources/model/JacksonBean.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/resources/model/JacksonBean.java new file mode 100644 index 0000000000..ecf38e7494 --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/resources/model/JacksonBean.java @@ -0,0 +1,76 @@ +package io.swagger.v3.plugin.maven.resources.model; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonUnwrapped; +import com.fasterxml.jackson.annotation.JsonValue; + +public class JacksonBean { + + private String id; + private String ignored; + private StringValueBean bean; + private NotFoundModel model; + private NotFoundModel model2; + + @JsonIgnore + public String getIgnored() { + return ignored; + } + + public void setIgnored(String ignored) { + this.ignored = ignored; + } + + public void setId(String id) { + this.id = id; + } + + public void setModel(NotFoundModel model) { + this.model = model; + } + + public StringValueBean getBean() { + return bean; + } + + public void setBean(StringValueBean bean) { + this.bean = bean; + } + + @JsonProperty("identity") + public String getId() { + return id; + } + + @JsonUnwrapped + public NotFoundModel getModel() { + return model; + } + + @JsonUnwrapped(prefix = "pre", suffix = "suf") + public NotFoundModel getModel2() { + return model2; + } + + public void setModel2(NotFoundModel model2) { + this.model2 = model2; + } + + public static class StringValueBean { + + private final String value; + + @JsonCreator + public StringValueBean(String value) { + this.value = value; + } + + @JsonValue + public String getValue() { + return value; + } + } + +} diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/resources/model/ListOfStringsBeanParam.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/resources/model/ListOfStringsBeanParam.java new file mode 100644 index 0000000000..a9b2271623 --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/resources/model/ListOfStringsBeanParam.java @@ -0,0 +1,17 @@ +package io.swagger.v3.plugin.maven.resources.model; + +import javax.ws.rs.QueryParam; +import java.util.List; + +public class ListOfStringsBeanParam { + @QueryParam(value = "listOfStrings") + private List list; + + public List getList() { + return list; + } + + public void setList(List list) { + this.list = list; + } +} \ No newline at end of file diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/resources/model/ModelWithJsonIdentity.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/resources/model/ModelWithJsonIdentity.java new file mode 100644 index 0000000000..32bb930902 --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/resources/model/ModelWithJsonIdentity.java @@ -0,0 +1,145 @@ +package io.swagger.v3.plugin.maven.resources.model; + +import com.fasterxml.jackson.annotation.JsonIdentityInfo; +import com.fasterxml.jackson.annotation.JsonIdentityReference; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.ObjectIdGenerators; + +public class ModelWithJsonIdentity { + + @JsonIdentityReference(alwaysAsId = true) + @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "name") + @JsonProperty("PropertyGeneratorAsId") + public SourceDefinition1 testPropertyGeneratorAsId; + + @JsonIdentityReference(alwaysAsId = false) + @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "name") + @JsonProperty("PropertyGeneratorAsProperty") + public SourceDefinition1 testPropertyGeneratorAsProperty; + + public class SourceDefinition1 { + public String driver; + public String name; + } + + @JsonIdentityReference(alwaysAsId = true) + @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "driverId") + @JsonProperty("ChangedPropertyName") + public SourceDefinition2 testChangedPropertyName; + + @JsonIdentityReference(alwaysAsId = true) + @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "driverId") + @JsonProperty("ChangedPropertyName2") + public SourceDefinition2 testChangedPropertyName2; + + static public class SourceDefinition2 { + @JsonProperty("driverId") + public String driver; + public String name; + } + + @JsonIdentityReference(alwaysAsId = true) + @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class) + @JsonProperty("SourceWithoutPropertyAsId") + public SourceDefinition3 testWithoutPropertyAsId; + + @JsonIdentityReference(alwaysAsId = false) + @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class) + @JsonProperty("SourceWithoutPropertyAsProperty") + public SourceDefinition3 testWithoutPropertyAsProperty; + + public class SourceDefinition3 { + @JsonProperty("driverId") + public String driver; + public String name; + + @JsonProperty("@id") + public String id; + } + + @JsonIdentityReference(alwaysAsId = true) + @JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class, property = "testName1") + @JsonProperty("IntSequenceGeneratorAsId") + public SourceDefinition4 testIntSequenceGeneratorAsId; + + @JsonIdentityReference(alwaysAsId = false) + @JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class, property = "testName2") + @JsonProperty("IntSequenceGeneratorAsProperty") + public SourceDefinition4 testIntSequenceGeneratorAsProperty; + + public class SourceDefinition4 { + public String name; + } + + @JsonIdentityReference(alwaysAsId = true) + @JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class) + @JsonProperty("IntSequenceWithoutPropertyAsId") + public SourceDefinition5 testIntSequenceWithoutPropertyAsId; + + @JsonIdentityReference(alwaysAsId = false) + @JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class) + @JsonProperty("IntSequenceWithoutPropertyAsProperty") + public SourceDefinition5 testIntSequenceWithoutPropertyAsProperty; + + public class SourceDefinition5 { + public String name; + } + + @JsonIdentityReference(alwaysAsId = true) + @JsonIdentityInfo(generator = ObjectIdGenerators.UUIDGenerator.class, property = "UUID1") + @JsonProperty("UUIDGeneratorAsId") + public SourceDefinition6 testUUIDGeneratorAsId; + + @JsonIdentityReference(alwaysAsId = false) + @JsonIdentityInfo(generator = ObjectIdGenerators.UUIDGenerator.class, property = "UUID2") + @JsonProperty("UUIDGeneratorAsProperty") + public SourceDefinition6 testUUIDGeneratorAsProperty; + + public class SourceDefinition6 { + public String name; + } + + @JsonIdentityReference(alwaysAsId = true) + @JsonIdentityInfo(generator = ObjectIdGenerators.UUIDGenerator.class) + @JsonProperty("UUIDGeneratorWithoutPropertyAsId") + public SourceDefinition7 testUUIDGeneratorWithoutPropertyAsId; + + @JsonIdentityReference(alwaysAsId = false) + @JsonIdentityInfo(generator = ObjectIdGenerators.UUIDGenerator.class) + @JsonProperty("UUIDGeneratorWithoutPropertyAsProperty") + public SourceDefinition7 testUUIDGeneratorWithoutPropertyAsProperty; + + public class SourceDefinition7 { + public String name; + } + + @JsonIdentityReference(alwaysAsId = true) + @JsonIdentityInfo(generator = ObjectIdGenerators.None.class, property = "testGeneratorsNone") + @JsonProperty("GeneratorsNone") + public SourceDefinition8 testGeneratorsNone; + + public class SourceDefinition8 { + @JsonProperty("driverId") + public String driver; + public String name; + } + + @JsonIdentityReference(alwaysAsId = true) + @JsonIdentityInfo(generator = CustomGenerator.class, property = "name") + @JsonProperty("CustomGenerator") + public SourceDefinition9 testCustomGenerator; + + public class SourceDefinition9 { + public String driver; + public String name; + } + + @JsonIdentityInfo(generator = CustomGenerator.class, property = "name") + @JsonProperty("WithoutJsonIdentityReference") + public SourceDefinition10 testWithoutJsonIdentityReference; + + public class SourceDefinition10 { + public String driver; + public String name; + } +} \ No newline at end of file diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/resources/model/ModelWithJsonIdentityCyclic.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/resources/model/ModelWithJsonIdentityCyclic.java new file mode 100644 index 0000000000..db30023271 --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/resources/model/ModelWithJsonIdentityCyclic.java @@ -0,0 +1,29 @@ +package io.swagger.v3.plugin.maven.resources.model; + +import com.fasterxml.jackson.annotation.JsonIdentityInfo; +import com.fasterxml.jackson.annotation.JsonIdentityReference; +import com.fasterxml.jackson.annotation.ObjectIdGenerators; + +import java.util.List; + +public class ModelWithJsonIdentityCyclic { + + public Long id; + + public List sourceDefinitions; + + @JsonIdentityInfo( + generator = ObjectIdGenerators.PropertyGenerator.class, + property = "name") + public static class SourceDefinition { + public String driver; + public String name; + + @JsonIdentityReference(alwaysAsId=true) + @JsonIdentityInfo( + generator = ObjectIdGenerators.PropertyGenerator.class, + property = "id") + public ModelWithJsonIdentityCyclic model; + } + +} \ No newline at end of file diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/resources/model/MultipleBaseBean.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/resources/model/MultipleBaseBean.java new file mode 100644 index 0000000000..c820b4255a --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/resources/model/MultipleBaseBean.java @@ -0,0 +1,11 @@ +package io.swagger.v3.plugin.maven.resources.model; + +@io.swagger.v3.oas.annotations.media.Schema( + description = "MultipleBaseBean", + subTypes = { MultipleSub1Bean.class, MultipleSub2Bean.class } +) +public class MultipleBaseBean { + public String beanType; + public int a; + public String b; +} \ No newline at end of file diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/resources/model/MultipleSub1Bean.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/resources/model/MultipleSub1Bean.java new file mode 100644 index 0000000000..b7ae993096 --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/resources/model/MultipleSub1Bean.java @@ -0,0 +1,8 @@ +package io.swagger.v3.plugin.maven.resources.model; + +@io.swagger.v3.oas.annotations.media.Schema( + description = "MultipleSub1Bean" +) +public class MultipleSub1Bean extends MultipleBaseBean { + public int c; +} \ No newline at end of file diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/resources/model/MultipleSub2Bean.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/resources/model/MultipleSub2Bean.java new file mode 100644 index 0000000000..882d6d37d6 --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/resources/model/MultipleSub2Bean.java @@ -0,0 +1,8 @@ +package io.swagger.v3.plugin.maven.resources.model; + +@io.swagger.v3.oas.annotations.media.Schema( + description = "MultipleSub2Bean" +) +public class MultipleSub2Bean extends MultipleBaseBean { + public int d; +} \ No newline at end of file diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/resources/model/NotFoundModel.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/resources/model/NotFoundModel.java new file mode 100644 index 0000000000..fccf2e0f98 --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/resources/model/NotFoundModel.java @@ -0,0 +1,30 @@ +package io.swagger.v3.plugin.maven.resources.model; + +public class NotFoundModel { + int code; + String message; + + public NotFoundModel() { + } + + public NotFoundModel(int code, String message) { + this.code = code; + this.message = message; + } + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } +} diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/resources/model/Pet.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/resources/model/Pet.java new file mode 100644 index 0000000000..54b31e9946 --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/resources/model/Pet.java @@ -0,0 +1,76 @@ +package io.swagger.v3.plugin.maven.resources.model; + +import io.swagger.v3.oas.annotations.media.Schema; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElementWrapper; +import javax.xml.bind.annotation.XmlRootElement; +import java.util.ArrayList; +import java.util.List; + +@XmlRootElement(name = "Pet") +public class Pet { + private long id; + private Category category; + private String name; + private List photoUrls = new ArrayList(); + private List tags = new ArrayList(); + private String status; + + @XmlElement(name = "id") + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + @XmlElement(name = "category") + public Category getCategory() { + return category; + } + + public void setCategory(Category category) { + this.category = category; + } + + @XmlElement(name = "name") + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @XmlElementWrapper(name = "photoUrls") + @XmlElement(name = "photoUrl") + public List getPhotoUrls() { + return photoUrls; + } + + public void setPhotoUrls(List photoUrls) { + this.photoUrls = photoUrls; + } + + @XmlElementWrapper(name = "tags") + @XmlElement(name = "tag") + public List getTags() { + return tags; + } + + public void setTags(List tags) { + this.tags = tags; + } + + @XmlElement(name = "status") + @Schema(description = "pet status in the store", allowableValues = "available,pending,sold") + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } +} diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/resources/model/Tag.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/resources/model/Tag.java new file mode 100644 index 0000000000..6d3d128292 --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/resources/model/Tag.java @@ -0,0 +1,44 @@ +/** + * Copyright 2016 SmartBear Software + *

    + * 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.swagger.v3.plugin.maven.resources.model; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement(name = "Tag") +public class Tag { + private long id; + private String name; + + @XmlElement(name = "id") + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + @XmlElement(name = "name") + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} \ No newline at end of file diff --git a/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/resources/model/User.java b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/resources/model/User.java new file mode 100644 index 0000000000..248d713160 --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/java/io/swagger/v3/plugin/maven/resources/model/User.java @@ -0,0 +1,108 @@ +/** + * Copyright 2016 SmartBear Software + *

    + * 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.swagger.v3.plugin.maven.resources.model; + +import io.swagger.v3.oas.annotations.media.Schema; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement(name = "User") +public class User { + private long id; + private String username; + private String firstName; + private String lastName; + private String email; + private String password; + private String phone; + private int userStatus; + + @XmlElement(name = "id") + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + @XmlElement(name = "firstName") + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + @XmlElement(name = "username") + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + @XmlElement(name = "lastName") + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + @XmlElement(name = "email") + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + @XmlElement(name = "password") + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + @XmlElement(name = "phone") + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + @XmlElement(name = "userStatus") + //@Schema(description = "User Status", type = "string", allowableValues = {"1-registered", "2-active", "3-closed"}) + @Schema(description = "User Status", allowableValues = "1-registered,2-active,3-closed") + public int getUserStatus() { + return userStatus; + } + + public void setUserStatus(int userStatus) { + this.userStatus = userStatus; + } +} \ No newline at end of file diff --git a/modules/swagger-maven-plugin/src/test/resources/openapiinput.yaml b/modules/swagger-maven-plugin/src/test/resources/openapiinput.yaml new file mode 100644 index 0000000000..126a36d76b --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/resources/openapiinput.yaml @@ -0,0 +1,17 @@ +openapi: 3.0.1 +servers: +- url: http://foo + description: server 1 + variables: + var1: + description: var 1 + enum: + - "1" + - "2" + default: "1" + var2: + description: var 2 + enum: + - "1" + - "2" + default: "1" \ No newline at end of file diff --git a/modules/swagger-maven-plugin/src/test/resources/pom.resolveToFile.xml b/modules/swagger-maven-plugin/src/test/resources/pom.resolveToFile.xml new file mode 100644 index 0000000000..9cd84a64d8 --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/resources/pom.resolveToFile.xml @@ -0,0 +1,51 @@ + + 4.0.0 + io.swagger.core.v3 + swagger-maven-plugin-test + jar + 1.0-SNAPSHOT + Test Resolve YAML + + + + + io.swagger.core.v3 + swagger-maven-plugin + + spec + ${project.basedir}/../../../target/generatedtest + ${project.basedir}/../../../src/test/resources/openapiinput.yaml + YAML + + io.swagger.v3.plugin.maven.petstore.petstore + + TRUE + + + + + + + + io.swagger.core.v3 + swagger-jaxrs2 + ${project.version} + + + + javax.ws.rs + javax.ws.rs-api + 2.1 + + + javax.servlet + javax.servlet-api + 3.1 + + + + + ISO-8859-1 + + \ No newline at end of file diff --git a/modules/swagger-maven-plugin/src/test/resources/pom.resolveToFileJsonAndYaml.xml b/modules/swagger-maven-plugin/src/test/resources/pom.resolveToFileJsonAndYaml.xml new file mode 100644 index 0000000000..364744242b --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/resources/pom.resolveToFileJsonAndYaml.xml @@ -0,0 +1,48 @@ + + 4.0.0 + io.swagger.core.v3 + swagger-maven-plugin-test + jar + 1.0-SNAPSHOT + Test Resolve YAML + + + + + io.swagger.core.v3 + swagger-maven-plugin + + openapi + ${project.basedir}/../../../target/generatedtest + ${project.basedir}/../../../src/test/resources/openapiinput.yaml + JSONANDYAML + + io.swagger.v3.plugin.maven.petstore.petstore + + TRUE + + + + + + + + io.swagger.core.v3 + swagger-jaxrs2 + ${project.version} + + + + javax.ws.rs + javax.ws.rs-api + 2.1 + + + javax.servlet + javax.servlet-api + 3.1 + + + + \ No newline at end of file diff --git a/modules/swagger-maven-plugin/src/test/resources/pom.resolveToFileNoName.xml b/modules/swagger-maven-plugin/src/test/resources/pom.resolveToFileNoName.xml new file mode 100644 index 0000000000..b0d6b15288 --- /dev/null +++ b/modules/swagger-maven-plugin/src/test/resources/pom.resolveToFileNoName.xml @@ -0,0 +1,47 @@ + + 4.0.0 + io.swagger.core.v3 + swagger-maven-plugin-test + jar + 1.0-SNAPSHOT + Test Resolve YAML + + + + + io.swagger.core.v3 + swagger-maven-plugin + + ${project.basedir}/../../../target/generatedtest + ${project.basedir}/../../../src/test/resources/openapiinput.yaml + YAML + + io.swagger.v3.plugin.maven.petstore.petstore + + TRUE + + + + + + + + io.swagger.core.v3 + swagger-jaxrs2 + ${project.version} + + + + javax.ws.rs + javax.ws.rs-api + 2.1 + + + javax.servlet + javax.servlet-api + 3.1 + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 1b3ded17f1..97cdffb112 100644 --- a/pom.xml +++ b/pom.xml @@ -309,6 +309,7 @@ modules/swagger-integration modules/swagger-jaxrs2 modules/swagger-jaxrs2-servlet-initializer + modules/swagger-maven-plugin