first commit
This commit is contained in:
commit
bb84603051
|
@ -0,0 +1,37 @@
|
|||
HELP.md
|
||||
.gradle
|
||||
build/
|
||||
!gradle/wrapper/gradle-wrapper.jar
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
bin/
|
||||
!**/src/main/**/bin/
|
||||
!**/src/test/**/bin/
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
out/
|
||||
!**/src/main/**/out/
|
||||
!**/src/test/**/out/
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
|
@ -0,0 +1,70 @@
|
|||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
import org.openapitools.generator.gradle.plugin.tasks.GenerateTask
|
||||
|
||||
plugins {
|
||||
id("org.springframework.boot") version "3.1.4"
|
||||
id("io.spring.dependency-management") version "1.1.3"
|
||||
kotlin("jvm") version "1.8.22"
|
||||
kotlin("plugin.spring") version "1.8.22"
|
||||
id("org.openapi.generator") version "7.0.1"
|
||||
}
|
||||
|
||||
group = "dev.usbharu"
|
||||
version = "0.0.1-SNAPSHOT"
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("org.springframework.boot:spring-boot-starter-web")
|
||||
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
|
||||
implementation("org.jetbrains.kotlin:kotlin-reflect")
|
||||
testImplementation("org.springframework.boot:spring-boot-starter-test")
|
||||
|
||||
implementation("jakarta.validation:jakarta.validation-api")
|
||||
implementation("jakarta.annotation:jakarta.annotation-api:2.1.0")
|
||||
compileOnly("io.swagger.core.v3:swagger-annotations:2.2.6")
|
||||
implementation("io.swagger.core.v3:swagger-models:2.2.6")
|
||||
}
|
||||
|
||||
tasks.withType<KotlinCompile> {
|
||||
kotlinOptions {
|
||||
freeCompilerArgs += "-Xjsr305=strict"
|
||||
jvmTarget = "17"
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType<Test> {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
tasks.create<GenerateTask>("openApiGenerateMastodonCompatibleApi", GenerateTask::class) {
|
||||
generatorName.set("kotlin-spring")
|
||||
inputSpec.set("$rootDir/src/main/resources/openapi/mastodon.yaml")
|
||||
outputDir.set("$buildDir/generated/sources/mastodon")
|
||||
apiPackage.set("dev.usbharu.hideout.controller.mastodon.generated")
|
||||
modelPackage.set("dev.usbharu.hideout.domain.mastodon.model.generated")
|
||||
configOptions.put("interfaceOnly", "true")
|
||||
configOptions.put("useSpringBoot3", "true")
|
||||
additionalProperties.put("useTags", "true")
|
||||
importMappings.put("org.springframework.core.io.Resource", "org.springframework.web.multipart.MultipartFile")
|
||||
typeMappings.put("org.springframework.core.io.Resource", "org.springframework.web.multipart.MultipartFile")
|
||||
templateDir.set("$rootDir/templates")
|
||||
globalProperties.put("debugModels","true")
|
||||
globalProperties.put("debugOpenAPI","true")
|
||||
globalProperties.put("debugOperations","true")
|
||||
}
|
||||
|
||||
|
||||
sourceSets.main {
|
||||
kotlin.srcDirs(
|
||||
"$buildDir/generated/ksp/main",
|
||||
"$buildDir/generated/sources/openapi/src/main/kotlin",
|
||||
"$buildDir/generated/sources/mastodon/src/main/kotlin"
|
||||
)
|
||||
}
|
Binary file not shown.
|
@ -0,0 +1,7 @@
|
|||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
|
@ -0,0 +1,248 @@
|
|||
#!/bin/sh
|
||||
|
||||
#
|
||||
# Copyright © 2015-2021 the original authors.
|
||||
#
|
||||
# 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
|
||||
#
|
||||
# https://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.
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# Gradle start up script for POSIX generated by Gradle.
|
||||
#
|
||||
# Important for running:
|
||||
#
|
||||
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||
# noncompliant, but you have some other compliant shell such as ksh or
|
||||
# bash, then to run this script, type that shell name before the whole
|
||||
# command line, like:
|
||||
#
|
||||
# ksh Gradle
|
||||
#
|
||||
# Busybox and similar reduced shells will NOT work, because this script
|
||||
# requires all of these POSIX shell features:
|
||||
# * functions;
|
||||
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||
# * compound commands having a testable exit status, especially «case»;
|
||||
# * various built-in commands including «command», «set», and «ulimit».
|
||||
#
|
||||
# Important for patching:
|
||||
#
|
||||
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||
#
|
||||
# The "traditional" practice of packing multiple parameters into a
|
||||
# space-separated string is a well documented source of bugs and security
|
||||
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||
# options in "$@", and eventually passing that to Java.
|
||||
#
|
||||
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||
# see the in-line comments for details.
|
||||
#
|
||||
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
|
||||
# Resolve links: $0 may be a link
|
||||
app_path=$0
|
||||
|
||||
# Need this for daisy-chained symlinks.
|
||||
while
|
||||
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||
[ -h "$app_path" ]
|
||||
do
|
||||
ls=$( ls -ld "$app_path" )
|
||||
link=${ls#*' -> '}
|
||||
case $link in #(
|
||||
/*) app_path=$link ;; #(
|
||||
*) app_path=$APP_HOME$link ;;
|
||||
esac
|
||||
done
|
||||
|
||||
# This is normally unused
|
||||
# shellcheck disable=SC2034
|
||||
APP_BASE_NAME=${0##*/}
|
||||
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
} >&2
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
} >&2
|
||||
|
||||
# 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 ;; #(
|
||||
MSYS* | 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
|
||||
if ! command -v java >/dev/null 2>&1
|
||||
then
|
||||
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
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||
case $MAX_FD in #(
|
||||
max*)
|
||||
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC3045
|
||||
MAX_FD=$( ulimit -H -n ) ||
|
||||
warn "Could not query maximum file descriptor limit"
|
||||
esac
|
||||
case $MAX_FD in #(
|
||||
'' | soft) :;; #(
|
||||
*)
|
||||
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC3045
|
||||
ulimit -n "$MAX_FD" ||
|
||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||
esac
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command, stacking in reverse order:
|
||||
# * args from the command line
|
||||
# * the main class name
|
||||
# * -classpath
|
||||
# * -D...appname settings
|
||||
# * --module-path (only if needed)
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if "$cygwin" || "$msys" ; then
|
||||
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
||||
|
||||
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
for arg do
|
||||
if
|
||||
case $arg in #(
|
||||
-*) false ;; # don't mess with options #(
|
||||
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||
[ -e "$t" ] ;; #(
|
||||
*) false ;;
|
||||
esac
|
||||
then
|
||||
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||
fi
|
||||
# Roll the args list around exactly as many times as the number of
|
||||
# args, so each arg winds up back in the position where it started, but
|
||||
# possibly modified.
|
||||
#
|
||||
# NB: a `for` loop captures its iteration list before it begins, so
|
||||
# changing the positional parameters here affects neither the number of
|
||||
# iterations, nor the values presented in `arg`.
|
||||
shift # remove old arg
|
||||
set -- "$@" "$arg" # push replacement arg
|
||||
done
|
||||
fi
|
||||
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Collect all arguments for the java command;
|
||||
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
||||
# shell script including quotes and variable substitutions, so put them in
|
||||
# double quotes to make sure that they get re-expanded; and
|
||||
# * put everything else in single quotes, so that it's not re-expanded.
|
||||
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
-classpath "$CLASSPATH" \
|
||||
org.gradle.wrapper.GradleWrapperMain \
|
||||
"$@"
|
||||
|
||||
# Stop when "xargs" is not available.
|
||||
if ! command -v xargs >/dev/null 2>&1
|
||||
then
|
||||
die "xargs is not available"
|
||||
fi
|
||||
|
||||
# Use "xargs" to parse quoted args.
|
||||
#
|
||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||
#
|
||||
# In Bash we could simply go:
|
||||
#
|
||||
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||
# set -- "${ARGS[@]}" "$@"
|
||||
#
|
||||
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||
# character that might be a shell metacharacter, then use eval to reverse
|
||||
# that process (while maintaining the separation between arguments), and wrap
|
||||
# the whole thing up as a single "set" statement.
|
||||
#
|
||||
# This will of course break if any of these variables contains a newline or
|
||||
# an unmatched quote.
|
||||
#
|
||||
|
||||
eval "set -- $(
|
||||
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||
xargs -n1 |
|
||||
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||
tr '\n' ' '
|
||||
)" '"$@"'
|
||||
|
||||
exec "$JAVACMD" "$@"
|
|
@ -0,0 +1,92 @@
|
|||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
|
||||
@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=.
|
||||
@rem This is normally unused
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||
|
||||
@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="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if %ERRORLEVEL% equ 0 goto execute
|
||||
|
||||
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 execute
|
||||
|
||||
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
|
||||
|
||||
: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 %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if %ERRORLEVEL% equ 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!
|
||||
set EXIT_CODE=%ERRORLEVEL%
|
||||
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
||||
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
||||
exit /b %EXIT_CODE%
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
|
@ -0,0 +1 @@
|
|||
rootProject.name = "openapi-spring-boot"
|
|
@ -0,0 +1,14 @@
|
|||
package dev.usbharu.openapispringboot
|
||||
|
||||
import dev.usbharu.hideout.controller.mastodon.generated.DefaultApi
|
||||
import dev.usbharu.hideout.domain.mastodon.model.generated.StatusesRequest
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.stereotype.Controller
|
||||
|
||||
@Controller
|
||||
class DefaultApiImpl : DefaultApi {
|
||||
override fun hogePost(statusesRequest: StatusesRequest): ResponseEntity<Unit> {
|
||||
println(statusesRequest)
|
||||
return ResponseEntity.ok(Unit)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
package dev.usbharu.openapispringboot
|
||||
|
||||
@MustBeDocumented
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
@Target(AnnotationTarget.VALUE_PARAMETER)
|
||||
annotation class JsonOrForm()
|
|
@ -0,0 +1,43 @@
|
|||
package dev.usbharu.openapispringboot
|
||||
|
||||
import org.springframework.core.MethodParameter
|
||||
import org.springframework.web.bind.support.WebDataBinderFactory
|
||||
import org.springframework.web.context.request.NativeWebRequest
|
||||
import org.springframework.web.method.annotation.ModelAttributeMethodProcessor
|
||||
import org.springframework.web.method.support.HandlerMethodArgumentResolver
|
||||
import org.springframework.web.method.support.ModelAndViewContainer
|
||||
import org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor
|
||||
|
||||
class JsonOrFormModelMethodProcessor(
|
||||
private val modelAttributeMethodProcessor: ModelAttributeMethodProcessor,
|
||||
private val requestResponseBodyMethodProcessor: RequestResponseBodyMethodProcessor
|
||||
) : HandlerMethodArgumentResolver {
|
||||
override fun supportsParameter(parameter: MethodParameter): Boolean {
|
||||
return parameter.hasParameterAnnotation(JsonOrForm::class.java)
|
||||
}
|
||||
|
||||
private val isJsonRegex = Regex("application/((\\w*)\\+)?json")
|
||||
|
||||
override fun resolveArgument(
|
||||
parameter: MethodParameter,
|
||||
mavContainer: ModelAndViewContainer?,
|
||||
webRequest: NativeWebRequest,
|
||||
binderFactory: WebDataBinderFactory?
|
||||
): Any? {
|
||||
|
||||
if (webRequest.getHeader("Content-Type").orEmpty().contains(isJsonRegex)) {
|
||||
return requestResponseBodyMethodProcessor.resolveArgument(
|
||||
parameter,
|
||||
mavContainer,
|
||||
webRequest,
|
||||
binderFactory
|
||||
)
|
||||
}
|
||||
|
||||
return try {
|
||||
modelAttributeMethodProcessor.resolveArgument(parameter, mavContainer, webRequest, binderFactory)
|
||||
} catch (e: Exception) {
|
||||
requestResponseBodyMethodProcessor.resolveArgument(parameter, mavContainer, webRequest, binderFactory)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package dev.usbharu.openapispringboot
|
||||
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.Configuration
|
||||
import org.springframework.http.converter.HttpMessageConverter
|
||||
import org.springframework.web.method.annotation.ModelAttributeMethodProcessor
|
||||
import org.springframework.web.method.support.HandlerMethodArgumentResolver
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
|
||||
import org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor
|
||||
import org.springframework.web.servlet.mvc.method.annotation.ServletModelAttributeMethodProcessor
|
||||
|
||||
@Configuration
|
||||
class MyMvcConfigurer(private val jsonOrFormModelMethodProcessor: JsonOrFormModelMethodProcessor) : WebMvcConfigurer {
|
||||
override fun addArgumentResolvers(resolvers: MutableList<HandlerMethodArgumentResolver>) {
|
||||
resolvers.add(jsonOrFormModelMethodProcessor)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
class Config{
|
||||
@Bean
|
||||
fun jsonOrFormModelMethodProcessor(httpMessageConverter:List<HttpMessageConverter<*>>):JsonOrFormModelMethodProcessor{
|
||||
return JsonOrFormModelMethodProcessor(ServletModelAttributeMethodProcessor(true),
|
||||
RequestResponseBodyMethodProcessor(httpMessageConverter)
|
||||
)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package dev.usbharu.openapispringboot
|
||||
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication
|
||||
import org.springframework.boot.runApplication
|
||||
|
||||
@SpringBootApplication
|
||||
class OpenapiSpringBootApplication
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
runApplication<OpenapiSpringBootApplication>(*args)
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
|
|
@ -0,0 +1,37 @@
|
|||
openapi: 3.0.3
|
||||
info:
|
||||
title: Title
|
||||
description: Title
|
||||
version: 1.0.0
|
||||
servers:
|
||||
- url: 'https'
|
||||
paths:
|
||||
/hoge:
|
||||
post:
|
||||
requestBody:
|
||||
description: 投稿する内容
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/StatusesRequest"
|
||||
application/x-www-form-urlencoded:
|
||||
schema:
|
||||
$ref: "#/components/schemas/StatusesRequest"
|
||||
responses:
|
||||
200:
|
||||
description: ok
|
||||
description: ""
|
||||
|
||||
components:
|
||||
schemas:
|
||||
StatusesRequest:
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
type: string
|
||||
text:
|
||||
type: string
|
||||
required:
|
||||
- id
|
||||
- text
|
|
@ -0,0 +1,13 @@
|
|||
package dev.usbharu.openapispringboot
|
||||
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.springframework.boot.test.context.SpringBootTest
|
||||
|
||||
@SpringBootTest
|
||||
class OpenapiSpringBootApplicationTests {
|
||||
|
||||
@Test
|
||||
fun contextLoads() {
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
package {{package}}
|
||||
|
||||
{{#imports}}import {{import}}
|
||||
{{/imports}}
|
||||
{{#swagger2AnnotationLibrary}}
|
||||
import io.swagger.v3.oas.annotations.*
|
||||
import io.swagger.v3.oas.annotations.enums.*
|
||||
import io.swagger.v3.oas.annotations.media.*
|
||||
import io.swagger.v3.oas.annotations.responses.*
|
||||
import io.swagger.v3.oas.annotations.security.*
|
||||
{{/swagger2AnnotationLibrary}}
|
||||
{{#swagger1AnnotationLibrary}}
|
||||
import io.swagger.annotations.Api
|
||||
import io.swagger.annotations.ApiOperation
|
||||
import io.swagger.annotations.ApiParam
|
||||
import io.swagger.annotations.ApiResponse
|
||||
import io.swagger.annotations.ApiResponses
|
||||
import io.swagger.annotations.Authorization
|
||||
import io.swagger.annotations.AuthorizationScope
|
||||
{{/swagger1AnnotationLibrary}}
|
||||
import org.springframework.http.HttpStatus
|
||||
import org.springframework.http.MediaType
|
||||
import org.springframework.http.ResponseEntity
|
||||
|
||||
import org.springframework.web.bind.annotation.*
|
||||
{{#useBeanValidation}}
|
||||
import org.springframework.validation.annotation.Validated
|
||||
{{/useBeanValidation}}
|
||||
import org.springframework.web.context.request.NativeWebRequest
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
|
||||
{{#useBeanValidation}}
|
||||
import {{javaxPackage}}.validation.Valid
|
||||
import {{javaxPackage}}.validation.constraints.DecimalMax
|
||||
import {{javaxPackage}}.validation.constraints.DecimalMin
|
||||
import {{javaxPackage}}.validation.constraints.Email
|
||||
import {{javaxPackage}}.validation.constraints.Max
|
||||
import {{javaxPackage}}.validation.constraints.Min
|
||||
import {{javaxPackage}}.validation.constraints.NotNull
|
||||
import {{javaxPackage}}.validation.constraints.Pattern
|
||||
import {{javaxPackage}}.validation.constraints.Size
|
||||
{{/useBeanValidation}}
|
||||
|
||||
{{#reactive}}
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
{{/reactive}}
|
||||
import kotlin.collections.List
|
||||
import kotlin.collections.Map
|
||||
|
||||
@RestController{{#beanQualifiers}}("{{package}}.{{classname}}Controller"){{/beanQualifiers}}
|
||||
{{#useBeanValidation}}
|
||||
@Validated
|
||||
{{/useBeanValidation}}
|
||||
{{#swagger1AnnotationLibrary}}
|
||||
@Api(value = "{{{baseName}}}", description = "The {{{baseName}}} API")
|
||||
{{/swagger1AnnotationLibrary}}
|
||||
{{=<% %>=}}
|
||||
@RequestMapping("\${api.base-path:<%contextPath%>}")
|
||||
<%={{ }}=%>
|
||||
{{#operations}}
|
||||
class {{classname}}Controller({{#serviceInterface}}@Autowired(required = true) val service: {{classname}}Service{{/serviceInterface}}) {
|
||||
{{#operation}}
|
||||
|
||||
{{#swagger2AnnotationLibrary}}
|
||||
@Operation(
|
||||
summary = "{{{summary}}}",
|
||||
operationId = "{{{operationId}}}",
|
||||
description = """{{{unescapedNotes}}}""",
|
||||
responses = [{{#responses}}
|
||||
ApiResponse(responseCode = "{{{code}}}", description = "{{{message}}}"{{#baseType}}, content = [Content({{#isArray}}array = ArraySchema({{/isArray}}schema = Schema(implementation = {{{baseType}}}::class)){{#isArray}}){{/isArray}}]{{/baseType}}){{^-last}},{{/-last}}{{/responses}} ]{{#hasAuthMethods}},
|
||||
security = [ {{#authMethods}}SecurityRequirement(name = "{{name}}"{{#isOAuth}}, scopes = [ {{#scopes}}"{{scope}}"{{^-last}}, {{/-last}}{{/scopes}} ]{{/isOAuth}}){{^-last}},{{/-last}}{{/authMethods}} ]{{/hasAuthMethods}}
|
||||
){{/swagger2AnnotationLibrary}}{{#swagger1AnnotationLibrary}}
|
||||
@ApiOperation(
|
||||
value = "{{{summary}}}",
|
||||
nickname = "{{{operationId}}}",
|
||||
notes = "{{{notes}}}"{{#returnBaseType}},
|
||||
response = {{{.}}}::class{{/returnBaseType}}{{#returnContainer}},
|
||||
responseContainer = "{{{.}}}"{{/returnContainer}}{{#hasAuthMethods}},
|
||||
authorizations = [{{#authMethods}}Authorization(value = "{{name}}"{{#isOAuth}}, scopes = [{{#scopes}}AuthorizationScope(scope = "{{scope}}", description = "{{description}}"){{^-last}}, {{/-last}}{{/scopes}}]{{/isOAuth}}){{^-last}}, {{/-last}}{{/authMethods}}]{{/hasAuthMethods}})
|
||||
@ApiResponses(
|
||||
value = [{{#responses}}ApiResponse(code = {{{code}}}, message = "{{{message}}}"{{#baseType}}, response = {{{.}}}::class{{/baseType}}{{#containerType}}, responseContainer = "{{{.}}}"{{/containerType}}){{^-last}},{{/-last}}{{/responses}}]){{/swagger1AnnotationLibrary}}
|
||||
@RequestMapping(
|
||||
method = [RequestMethod.{{httpMethod}}],
|
||||
value = ["{{#lambda.escapeDoubleQuote}}{{path}}{{/lambda.escapeDoubleQuote}}"]{{#singleContentTypes}}{{#hasProduces}},
|
||||
produces = "{{{vendorExtensions.x-accepts}}}"{{/hasProduces}}{{#hasConsumes}},
|
||||
consumes = "{{{vendorExtensions.x-content-type}}}"{{/hasConsumes}}{{/singleContentTypes}}{{^singleContentTypes}}{{#hasProduces}},
|
||||
produces = [{{#produces}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/produces}}]{{/hasProduces}}{{#hasConsumes}},
|
||||
consumes = [{{#consumes}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/consumes}}]{{/hasConsumes}}{{/singleContentTypes}}
|
||||
)
|
||||
{{#reactive}}{{^isArray}}suspend {{/isArray}}{{/reactive}}fun {{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{^-last}},{{/-last}}{{/allParams}}): ResponseEntity<{{>returnTypes}}> {
|
||||
return {{>returnValue}}
|
||||
}
|
||||
{{/operation}}
|
||||
}
|
||||
{{/operations}}
|
|
@ -0,0 +1,25 @@
|
|||
package {{package}}
|
||||
|
||||
import org.springframework.stereotype.Controller
|
||||
import org.springframework.web.bind.annotation.RequestMapping
|
||||
import java.util.Optional
|
||||
import dev.usbharu.openapispringboot.JsonOrForm
|
||||
|
||||
{{>generatedAnnotation}}
|
||||
@Controller{{#beanQualifiers}}("{{package}}.{{classname}}Controller"){{/beanQualifiers}}
|
||||
{{=<% %>=}}
|
||||
@RequestMapping("\${openapi.<%title%>.base-path:<%>defaultBasePath%>}")
|
||||
<%={{ }}=%>
|
||||
{{#operations}}
|
||||
class {{classname}}Controller(
|
||||
@org.springframework.beans.factory.annotation.Autowired(required = false) delegate: {{classname}}Delegate?
|
||||
) : {{classname}} {
|
||||
private val delegate: {{classname}}Delegate
|
||||
|
||||
init {
|
||||
this.delegate = Optional.ofNullable(delegate).orElse(object : {{classname}}Delegate {})
|
||||
}
|
||||
|
||||
override fun getDelegate(): {{classname}}Delegate = delegate
|
||||
}
|
||||
{{/operations}}
|
|
@ -0,0 +1,40 @@
|
|||
package {{package}}
|
||||
|
||||
{{#imports}}import {{import}}
|
||||
{{/imports}}
|
||||
import org.springframework.http.HttpStatus
|
||||
import org.springframework.http.MediaType
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.web.context.request.NativeWebRequest
|
||||
import org.springframework.core.io.Resource
|
||||
{{#reactive}}
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
{{/reactive}}
|
||||
|
||||
import java.util.Optional
|
||||
{{#async}}
|
||||
import java.util.concurrent.CompletableFuture
|
||||
{{/async}}
|
||||
|
||||
{{#operations}}
|
||||
/**
|
||||
* A delegate to be called by the {@link {{classname}}Controller}}.
|
||||
* Implement this interface with a {@link org.springframework.stereotype.Service} annotated class.
|
||||
*/
|
||||
{{>generatedAnnotation}}
|
||||
interface {{classname}}Delegate {
|
||||
|
||||
fun getRequest(): Optional<NativeWebRequest> = Optional.empty()
|
||||
{{#operation}}
|
||||
|
||||
/**
|
||||
* @see {{classname}}#{{operationId}}
|
||||
*/
|
||||
{{#reactive}}{{^isArray}}suspend {{/isArray}}{{/reactive}}fun {{operationId}}({{#allParams}}{{paramName}}: {{^isFile}}{{^reactive}}{{>optionalDataType}}{{/reactive}}{{#reactive}}{{^isArray}}{{>optionalDataType}}{{/isArray}}{{#isArray}}{{#isBodyParam}}Flow<{{{baseType}}}>{{/isBodyParam}}{{^isBodyParam}}{{>optionalDataType}}{{/isBodyParam}}{{/isArray}}{{/reactive}}{{/isFile}}{{#isFile}}Resource?{{/isFile}}{{^-last}},
|
||||
{{/-last}}{{/allParams}}): {{#responseWrapper}}{{.}}<{{/responseWrapper}}ResponseEntity<{{>returnTypes}}>{{#responseWrapper}}>{{/responseWrapper}} {
|
||||
{{>methodBody}}
|
||||
}
|
||||
|
||||
{{/operation}}
|
||||
}
|
||||
{{/operations}}
|
|
@ -0,0 +1,112 @@
|
|||
/**
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) ({{{generatorVersion}}}).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
package {{package}}
|
||||
|
||||
{{#imports}}import {{import}}
|
||||
{{/imports}}
|
||||
{{#swagger2AnnotationLibrary}}
|
||||
import io.swagger.v3.oas.annotations.*
|
||||
import io.swagger.v3.oas.annotations.enums.*
|
||||
import io.swagger.v3.oas.annotations.media.*
|
||||
import io.swagger.v3.oas.annotations.responses.*
|
||||
import io.swagger.v3.oas.annotations.security.*
|
||||
{{/swagger2AnnotationLibrary}}
|
||||
{{#swagger1AnnotationLibrary}}
|
||||
import io.swagger.annotations.Api
|
||||
import io.swagger.annotations.ApiOperation
|
||||
import io.swagger.annotations.ApiParam
|
||||
import io.swagger.annotations.ApiResponse
|
||||
import io.swagger.annotations.ApiResponses
|
||||
import io.swagger.annotations.Authorization
|
||||
import io.swagger.annotations.AuthorizationScope
|
||||
{{/swagger1AnnotationLibrary}}
|
||||
import org.springframework.http.HttpStatus
|
||||
import org.springframework.http.MediaType
|
||||
import org.springframework.http.ResponseEntity
|
||||
|
||||
import org.springframework.web.bind.annotation.*
|
||||
{{#useBeanValidation}}
|
||||
import org.springframework.validation.annotation.Validated
|
||||
{{/useBeanValidation}}
|
||||
import org.springframework.web.context.request.NativeWebRequest
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
|
||||
{{#useBeanValidation}}
|
||||
import {{javaxPackage}}.validation.constraints.DecimalMax
|
||||
import {{javaxPackage}}.validation.constraints.DecimalMin
|
||||
import {{javaxPackage}}.validation.constraints.Email
|
||||
import {{javaxPackage}}.validation.constraints.Max
|
||||
import {{javaxPackage}}.validation.constraints.Min
|
||||
import {{javaxPackage}}.validation.constraints.NotNull
|
||||
import {{javaxPackage}}.validation.constraints.Pattern
|
||||
import {{javaxPackage}}.validation.constraints.Size
|
||||
import {{javaxPackage}}.validation.Valid
|
||||
{{/useBeanValidation}}
|
||||
|
||||
{{#reactive}}
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
{{/reactive}}
|
||||
import kotlin.collections.List
|
||||
import kotlin.collections.Map
|
||||
import dev.usbharu.openapispringboot.JsonOrForm
|
||||
|
||||
{{#useBeanValidation}}
|
||||
@Validated
|
||||
{{/useBeanValidation}}
|
||||
{{#swagger1AnnotationLibrary}}
|
||||
@Api(value = "{{{baseName}}}", description = "The {{{baseName}}} API")
|
||||
{{/swagger1AnnotationLibrary}}
|
||||
{{^useFeignClient}}
|
||||
{{=<% %>=}}
|
||||
@RequestMapping("\${api.base-path:<%contextPath%>}")
|
||||
<%={{ }}=%>
|
||||
{{/useFeignClient}}
|
||||
{{#operations}}
|
||||
interface {{classname}} {
|
||||
{{#isDelegate}}
|
||||
|
||||
fun getDelegate(): {{classname}}Delegate = object: {{classname}}Delegate {}
|
||||
{{/isDelegate}}
|
||||
{{#operation}}
|
||||
|
||||
{{#swagger2AnnotationLibrary}}
|
||||
@Operation(
|
||||
summary = "{{{summary}}}",
|
||||
operationId = "{{{operationId}}}",
|
||||
description = """{{{unescapedNotes}}}""",
|
||||
responses = [{{#responses}}
|
||||
ApiResponse(responseCode = "{{{code}}}", description = "{{{message}}}"{{#baseType}}, content = [Content({{#isArray}}array = ArraySchema({{/isArray}}schema = Schema(implementation = {{{baseType}}}::class)){{#isArray}}){{/isArray}}]{{/baseType}}){{^-last}},{{/-last}}{{/responses}}
|
||||
]{{#hasAuthMethods}},
|
||||
security = [ {{#authMethods}}SecurityRequirement(name = "{{name}}"{{#isOAuth}}, scopes = [ {{#scopes}}"{{scope}}"{{^-last}}, {{/-last}}{{/scopes}} ]{{/isOAuth}}){{^-last}},{{/-last}}{{/authMethods}} ]{{/hasAuthMethods}}
|
||||
){{/swagger2AnnotationLibrary}}{{#swagger1AnnotationLibrary}}
|
||||
@ApiOperation(
|
||||
value = "{{{summary}}}",
|
||||
nickname = "{{{operationId}}}",
|
||||
notes = "{{{notes}}}"{{#returnBaseType}},
|
||||
response = {{{.}}}::class{{/returnBaseType}}{{#returnContainer}},
|
||||
responseContainer = "{{{.}}}"{{/returnContainer}}{{#hasAuthMethods}},
|
||||
authorizations = [{{#authMethods}}Authorization(value = "{{name}}"{{#isOAuth}}, scopes = [{{#scopes}}AuthorizationScope(scope = "{{scope}}", description = "{{description}}"){{^-last}}, {{/-last}}{{/scopes}}]{{/isOAuth}}){{^-last}}, {{/-last}}{{/authMethods}}]{{/hasAuthMethods}})
|
||||
@ApiResponses(
|
||||
value = [{{#responses}}ApiResponse(code = {{{code}}}, message = "{{{message}}}"{{#baseType}}, response = {{{.}}}::class{{/baseType}}{{#containerType}}, responseContainer = "{{{.}}}"{{/containerType}}){{^-last}}, {{/-last}}{{/responses}}]){{/swagger1AnnotationLibrary}}
|
||||
@RequestMapping(
|
||||
method = [RequestMethod.{{httpMethod}}],
|
||||
value = ["{{#lambda.escapeDoubleQuote}}{{path}}{{/lambda.escapeDoubleQuote}}"]{{#singleContentTypes}}{{#hasProduces}},
|
||||
produces = "{{{vendorExtensions.x-accepts}}}"{{/hasProduces}}{{#hasConsumes}},
|
||||
consumes = "{{{vendorExtensions.x-content-type}}}"{{/hasConsumes}}{{/singleContentTypes}}{{^singleContentTypes}}{{#hasProduces}},
|
||||
produces = [{{#produces}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/produces}}]{{/hasProduces}}{{#hasConsumes}},
|
||||
consumes = [{{#consumes}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/consumes}}]{{/hasConsumes}}{{/singleContentTypes}}
|
||||
)
|
||||
{{#reactive}}{{^isArray}}suspend {{/isArray}}{{/reactive}}fun {{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{^-last}},{{/-last}}{{/allParams}}): ResponseEntity<{{>returnTypes}}>{{^skipDefaultInterface}} {
|
||||
{{^isDelegate}}
|
||||
return {{>returnValue}}
|
||||
{{/isDelegate}}
|
||||
{{#isDelegate}}
|
||||
return getDelegate().{{operationId}}({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}})
|
||||
{{/isDelegate}}
|
||||
}{{/skipDefaultInterface}}
|
||||
{{/operation}}
|
||||
}
|
||||
{{/operations}}
|
|
@ -0,0 +1,23 @@
|
|||
package {{apiPackage}}
|
||||
|
||||
{{^reactive}}
|
||||
import org.springframework.web.context.request.NativeWebRequest
|
||||
|
||||
import {{javaxPackage}}.servlet.http.HttpServletResponse
|
||||
import java.io.IOException
|
||||
{{/reactive}}
|
||||
|
||||
object ApiUtil {
|
||||
{{^reactive}}
|
||||
fun setExampleResponse(req: NativeWebRequest, contentType: String, example: String) {
|
||||
try {
|
||||
val res = req.getNativeResponse(HttpServletResponse::class.java)
|
||||
res?.characterEncoding = "UTF-8"
|
||||
res?.addHeader("Content-Type", contentType)
|
||||
res?.writer?.print(example)
|
||||
} catch (e: IOException) {
|
||||
throw RuntimeException(e)
|
||||
}
|
||||
}
|
||||
{{/reactive}}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package {{package}}
|
||||
|
||||
{{#imports}}import {{import}}
|
||||
{{/imports}}
|
||||
import org.junit.jupiter.api.Test
|
||||
{{#reactive}}
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.test.runBlockingTest
|
||||
{{/reactive}}
|
||||
import org.springframework.http.ResponseEntity
|
||||
|
||||
class {{classname}}Test {
|
||||
|
||||
{{#serviceInterface}}
|
||||
private val service: {{classname}}Service = {{classname}}ServiceImpl()
|
||||
{{/serviceInterface}}
|
||||
private val api: {{classname}}Controller = {{classname}}Controller({{#serviceInterface}}service{{/serviceInterface}})
|
||||
{{#operations}}
|
||||
{{#operation}}
|
||||
|
||||
/**
|
||||
* To test {{classname}}Controller.{{operationId}}
|
||||
*
|
||||
* @throws ApiException
|
||||
* if the Api call fails
|
||||
*/
|
||||
@Test
|
||||
fun {{operationId}}Test() {{#reactive}}= runBlockingTest {{/reactive}}{
|
||||
{{#allParams}}
|
||||
val {{{paramName}}}: {{>optionalDataType}} = TODO()
|
||||
{{/allParams}}
|
||||
val response: ResponseEntity<{{>returnTypes}}> = api.{{operationId}}({{#allParams}}{{{paramName}}}{{^-last}}, {{/-last}}{{/allParams}})
|
||||
|
||||
// TODO: test validations
|
||||
}
|
||||
{{/operation}}
|
||||
{{/operations}}
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
{{#isContainer}}{{^isPrimitiveType}}{{^isEnum}}
|
||||
@field:Valid{{/isEnum}}{{/isPrimitiveType}}{{/isContainer}}{{!
|
||||
}}{{^isContainer}}{{^isPrimitiveType}}{{^isNumber}}{{^isUuid}}{{^isDateTime}}
|
||||
@field:Valid{{/isDateTime}}{{/isUuid}}{{/isNumber}}{{/isPrimitiveType}}{{/isContainer}}
|
|
@ -0,0 +1,38 @@
|
|||
{{!
|
||||
format: email
|
||||
}}{{#isEmail}}
|
||||
@get:Email{{/isEmail}}{{!
|
||||
pattern set
|
||||
}}{{#pattern}}
|
||||
@get:Pattern(regexp="{{{.}}}"){{/pattern}}{{!
|
||||
minLength && maxLength set
|
||||
}}{{#minLength}}{{#maxLength}}
|
||||
@get:Size(min={{minLength}},max={{maxLength}}){{/maxLength}}{{/minLength}}{{!
|
||||
minLength set, maxLength not
|
||||
}}{{#minLength}}{{^maxLength}}
|
||||
@get:Size(min={{minLength}}){{/maxLength}}{{/minLength}}{{!
|
||||
minLength not set, maxLength set
|
||||
}}{{^minLength}}{{#maxLength}}
|
||||
@get:Size(max={{.}}){{/maxLength}}{{/minLength}}{{!
|
||||
@Size: minItems && maxItems set
|
||||
}}{{#minItems}}{{#maxItems}}
|
||||
@get:Size(min={{minItems}},max={{maxItems}}) {{/maxItems}}{{/minItems}}{{!
|
||||
@Size: minItems set, maxItems not
|
||||
}}{{#minItems}}{{^maxItems}}
|
||||
@get:Size(min={{minItems}}){{/maxItems}}{{/minItems}}{{!
|
||||
@Size: minItems not set && maxItems set
|
||||
}}{{^minItems}}{{#maxItems}}
|
||||
@get:Size(max={{.}}){{/maxItems}}{{/minItems}}{{!
|
||||
check for integer or long / all others=decimal type with @Decimal*
|
||||
isInteger set
|
||||
}}{{#isInteger}}{{#minimum}}
|
||||
@get:Min({{.}}){{/minimum}}{{#maximum}}
|
||||
@get:Max({{.}}){{/maximum}}{{/isInteger}}{{!
|
||||
isLong set
|
||||
}}{{#isLong}}{{#minimum}}
|
||||
@get:Min({{.}}L){{/minimum}}{{#maximum}}
|
||||
@get:Max({{.}}L){{/maximum}}{{/isLong}}{{!
|
||||
Not Integer, not Long => we have a decimal value!
|
||||
}}{{^isInteger}}{{^isLong}}{{#minimum}}
|
||||
@get:DecimalMin("{{.}}"){{/minimum}}{{#maximum}}
|
||||
@get:DecimalMax("{{.}}"){{/maximum}}{{/isLong}}{{/isInteger}}
|
|
@ -0,0 +1,22 @@
|
|||
{{#isEmail}}@Email {{/isEmail}}{{!
|
||||
pattern set
|
||||
}}{{#pattern}}@Pattern(regexp="{{{.}}}") {{/pattern}}{{!
|
||||
minLength && maxLength set
|
||||
}}{{#minLength}}{{#maxLength}}@Size(min={{minLength}},max={{maxLength}}) {{/maxLength}}{{/minLength}}{{!
|
||||
minLength set, maxLength not
|
||||
}}{{#minLength}}{{^maxLength}}@Size(min={{minLength}}) {{/maxLength}}{{/minLength}}{{!
|
||||
minLength not set, maxLength set
|
||||
}}{{^minLength}}{{#maxLength}}@Size(max={{.}}) {{/maxLength}}{{/minLength}}{{!
|
||||
@Size: minItems && maxItems set
|
||||
}}{{#minItems}}{{#maxItems}}@Size(min={{minItems}},max={{maxItems}}) {{/maxItems}}{{/minItems}}{{!
|
||||
@Size: minItems set, maxItems not
|
||||
}}{{#minItems}}{{^maxItems}}@Size(min={{minItems}}) {{/maxItems}}{{/minItems}}{{!
|
||||
@Size: minItems not set && maxItems set
|
||||
}}{{^minItems}}{{#maxItems}}@Size(max={{.}}) {{/maxItems}}{{/minItems}}{{!
|
||||
check for integer or long / all others=decimal type with @Decimal*
|
||||
isInteger set
|
||||
}}{{#isInteger}}{{#minimum}}@Min({{.}}){{/minimum}}{{#maximum}} @Max({{.}}) {{/maximum}}{{/isInteger}}{{!
|
||||
isLong set
|
||||
}}{{#isLong}}{{#minimum}}@Min({{.}}L){{/minimum}}{{#maximum}} @Max({{.}}L) {{/maximum}}{{/isLong}}{{!
|
||||
Not Integer, not Long => we have a decimal value!
|
||||
}}{{^isInteger}}{{^isLong}}{{#minimum}}@DecimalMin("{{.}}"){{/minimum}}{{#maximum}} @DecimalMax("{{.}}") {{/maximum}}{{/isLong}}{{/isInteger}}
|
|
@ -0,0 +1 @@
|
|||
{{! PathParam is always required, no @NotNull necessary }}{{>beanValidationPath}}
|
|
@ -0,0 +1 @@
|
|||
{{#required}}@NotNull {{/required}}{{>beanValidationPath}}
|
|
@ -0,0 +1 @@
|
|||
{{#isBodyParam}}{{#swagger2AnnotationLibrary}}@Parameter(description = "{{{description}}}"{{#required}}, required = true{{/required}}{{^isContainer}}{{#allowableValues}}{{#defaultValue}}, schema = Schema(allowableValues = ["{{{allowableValues}}}"], defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}){{/defaultValue}}{{/allowableValues}}{{^allowableValues}}{{#defaultValue}}, schema = Schema(defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}){{/defaultValue}}{{/allowableValues}}{{#allowableValues}}{{^defaultValue}}, schema = Schema(allowableValues = ["{{{allowableValues}}}"]){{/defaultValue}}{{/allowableValues}}{{/isContainer}}){{/swagger2AnnotationLibrary}}{{#swagger1AnnotationLibrary}}@ApiParam(value = "{{{description}}}"{{#required}}, required = true{{/required}}{{^isContainer}}{{#allowableValues}}, allowableValues = "{{{.}}}"{{/allowableValues}}{{/isContainer}}{{#defaultValue}}, defaultValue = "{{{.}}}"{{/defaultValue}}){{/swagger1AnnotationLibrary}} {{#useBeanValidation}}@Valid{{/useBeanValidation}} @JsonOrForm {{{paramName}}}: {{^reactive}}{{>optionalDataType}}{{/reactive}}{{#reactive}}{{^isArray}}{{>optionalDataType}}{{/isArray}}{{#isArray}}Flow<{{{baseType}}}>{{/isArray}}{{/reactive}}{{/isBodyParam}}
|
|
@ -0,0 +1,33 @@
|
|||
/**
|
||||
* {{{description}}}
|
||||
{{#vars}}
|
||||
* @param {{name}} {{{description}}}
|
||||
{{/vars}}
|
||||
*/{{#discriminator}}
|
||||
{{>typeInfoAnnotation}}{{/discriminator}}
|
||||
{{#discriminator}}interface {{classname}}{{/discriminator}}{{^discriminator}}{{#hasVars}}data {{/hasVars}}class {{classname}}(
|
||||
{{#requiredVars}}
|
||||
{{>dataClassReqVar}}{{^-last}},
|
||||
{{/-last}}{{/requiredVars}}{{#hasRequired}}{{#hasOptional}},
|
||||
{{/hasOptional}}{{/hasRequired}}{{#optionalVars}}{{>dataClassOptVar}}{{^-last}},
|
||||
{{/-last}}{{/optionalVars}}
|
||||
) {{/discriminator}}{{#parent}}: {{{.}}}{{/parent}}{
|
||||
{{#discriminator}}
|
||||
{{#requiredVars}}
|
||||
{{>interfaceReqVar}}
|
||||
{{/requiredVars}}
|
||||
{{#optionalVars}}
|
||||
{{>interfaceOptVar}}
|
||||
{{/optionalVars}}
|
||||
{{/discriminator}}
|
||||
{{#hasEnums}}{{#vars}}{{#isEnum}}
|
||||
/**
|
||||
* {{{description}}}
|
||||
* Values: {{#allowableValues}}{{#enumVars}}{{&name}}{{^-last}},{{/-last}}{{/enumVars}}{{/allowableValues}}
|
||||
*/
|
||||
enum class {{{nameInCamelCase}}}(val value: {{#isContainer}}{{#items}}{{{dataType}}}{{/items}}{{/isContainer}}{{^isContainer}}{{{dataType}}}{{/isContainer}}) {
|
||||
{{#allowableValues}}{{#enumVars}}
|
||||
@JsonProperty({{{value}}}) {{{name}}}({{{value}}}){{^-last}},{{/-last}}{{/enumVars}}{{/allowableValues}}
|
||||
}
|
||||
{{/isEnum}}{{/vars}}{{/hasEnums}}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
{{#useBeanValidation}}{{>beanValidation}}{{>beanValidationModel}}{{/useBeanValidation}}{{#swagger2AnnotationLibrary}}
|
||||
@Schema({{#example}}example = "{{#lambdaRemoveLineBreak}}{{#lambdaEscapeDoubleQuote}}{{{.}}}{{/lambdaEscapeDoubleQuote}}{{/lambdaRemoveLineBreak}}", {{/example}}{{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}description = "{{{description}}}"){{/swagger2AnnotationLibrary}}{{#swagger1AnnotationLibrary}}
|
||||
@ApiModelProperty({{#example}}example = "{{#lambdaRemoveLineBreak}}{{#lambdaEscapeDoubleQuote}}{{{.}}}{{/lambdaEscapeDoubleQuote}}{{/lambdaRemoveLineBreak}}", {{/example}}{{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}value = "{{{description}}}"){{/swagger1AnnotationLibrary}}{{#deprecated}}
|
||||
@Deprecated(message = ""){{/deprecated}}
|
||||
@get:JsonProperty("{{{baseName}}}"){{#isInherited}} override{{/isInherited}} {{>modelMutable}} {{{name}}}: {{#isEnum}}{{#isArray}}{{baseType}}<{{/isArray}}{{classname}}.{{{nameInCamelCase}}}{{#isArray}}>{{/isArray}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}? = {{{defaultValue}}}{{^defaultValue}}null{{/defaultValue}}
|
|
@ -0,0 +1,4 @@
|
|||
{{#useBeanValidation}}{{>beanValidation}}{{>beanValidationModel}}{{/useBeanValidation}}{{#swagger2AnnotationLibrary}}
|
||||
@Schema({{#example}}example = "{{#lambdaRemoveLineBreak}}{{#lambdaEscapeDoubleQuote}}{{{.}}}{{/lambdaEscapeDoubleQuote}}{{/lambdaRemoveLineBreak}}", {{/example}}required = true, {{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}description = "{{{description}}}"){{/swagger2AnnotationLibrary}}{{#swagger1AnnotationLibrary}}
|
||||
@ApiModelProperty({{#example}}example = "{{#lambdaRemoveLineBreak}}{{#lambdaEscapeDoubleQuote}}{{{.}}}{{/lambdaEscapeDoubleQuote}}{{/lambdaRemoveLineBreak}}", {{/example}}required = true, {{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}value = "{{{description}}}"){{/swagger1AnnotationLibrary}}
|
||||
@get:JsonProperty("{{{baseName}}}", required = true){{#isInherited}} override{{/isInherited}} {{>modelMutable}} {{{name}}}: {{#isEnum}}{{#isArray}}{{baseType}}<{{/isArray}}{{classname}}.{{{nameInCamelCase}}}{{#isArray}}>{{/isArray}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{#isNullable}}?{{/isNullable}}{{#defaultValue}} = {{{.}}}{{/defaultValue}}
|
|
@ -0,0 +1,8 @@
|
|||
/**
|
||||
* {{{description}}}
|
||||
* Values: {{#allowableValues}}{{#enumVars}}{{&name}}{{^-last}},{{/-last}}{{/enumVars}}{{/allowableValues}}
|
||||
*/
|
||||
enum class {{classname}}(val value: {{dataType}}) {
|
||||
{{#allowableValues}}{{#enumVars}}
|
||||
@JsonProperty({{{value}}}) {{&name}}({{{value}}}){{^-last}},{{/-last}}{{/enumVars}}{{/allowableValues}}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package {{apiPackage}}
|
||||
|
||||
import org.springframework.http.HttpStatus
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler
|
||||
import {{javaxPackage}}.servlet.http.HttpServletResponse
|
||||
import {{javaxPackage}}.validation.ConstraintViolationException
|
||||
|
||||
// TODO Extend ApiException for custom exception handling, e.g. the below NotFound exception
|
||||
sealed class ApiException(msg: String, val code: Int) : Exception(msg)
|
||||
|
||||
class NotFoundException(msg: String, code: Int = HttpStatus.NOT_FOUND.value()) : ApiException(msg, code)
|
||||
|
||||
|
||||
@ControllerAdvice
|
||||
class DefaultExceptionHandler {
|
||||
|
||||
@ExceptionHandler(value = [ApiException::class])
|
||||
fun onApiException(ex: ApiException, response: HttpServletResponse): Unit =
|
||||
response.sendError(ex.code, ex.message)
|
||||
|
||||
@ExceptionHandler(value = [NotImplementedError::class])
|
||||
fun onNotImplemented(ex: NotImplementedError, response: HttpServletResponse): Unit =
|
||||
response.sendError(HttpStatus.NOT_IMPLEMENTED.value())
|
||||
|
||||
@ExceptionHandler(value = [ConstraintViolationException::class])
|
||||
fun onConstraintViolation(ex: ConstraintViolationException, response: HttpServletResponse): Unit =
|
||||
response.sendError(HttpStatus.BAD_REQUEST.value(), ex.constraintViolations.joinToString(", ") { it.message })
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
{{#isFormParam}}{{^isFile}}{{#swagger2AnnotationLibrary}}@Parameter(description = "{{{description}}}"{{#required}}, required = true{{/required}}{{#allowableValues}}{{#defaultValue}}, schema = Schema(allowableValues = [{{#values}}"{{{.}}}"{{^-last}}, {{/-last}}{{/values}}]{{^isContainer}}, defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{/isContainer}}){{/defaultValue}}{{/allowableValues}}{{#allowableValues}}{{^defaultValue}}, schema = Schema(allowableValues = [{{#values}}"{{{.}}}"{{^-last}}, {{/-last}}{{/values}}]){{/defaultValue}}{{/allowableValues}}{{^allowableValues}}{{#defaultValue}}{{^isContainer}}, schema = Schema(defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}){{/isContainer}}{{/defaultValue}}{{/allowableValues}}){{/swagger2AnnotationLibrary}}{{#swagger1AnnotationLibrary}}@ApiParam(value = "{{{description}}}"{{#required}}, required = true{{/required}}{{#allowableValues}}, allowableValues = "{{#values}}{{{.}}}{{^-last}}, {{/-last}}{{/values}}"{{/allowableValues}}{{#defaultValue}}, defaultValue = "{{{.}}}"{{/defaultValue}}){{/swagger1AnnotationLibrary}} @RequestParam(value = "{{baseName}}"{{#required}}, required = true{{/required}}{{^required}}, required = false{{/required}}) {{paramName}}: {{>optionalDataType}} {{/isFile}}{{#isFile}}{{#swagger2AnnotationLibrary}}@Parameter(description = "file detail"){{/swagger2AnnotationLibrary}}{{#swagger1AnnotationLibrary}}@ApiParam(value = "file detail"){{/swagger1AnnotationLibrary}} {{#useBeanValidation}}@Valid{{/useBeanValidation}} @RequestPart("file") {{baseName}}: {{>optionalDataType}}{{/isFile}}{{/isFormParam}}
|
|
@ -0,0 +1 @@
|
|||
@{{javaxPackage}}.annotation.Generated(value = ["{{generatorClass}}"]{{^hideGenerationTimestamp}}, date = "{{generatedDate}}"{{/hideGenerationTimestamp}})
|
|
@ -0,0 +1 @@
|
|||
{{#isHeaderParam}}{{#useBeanValidation}}{{>beanValidationPath}}{{/useBeanValidation}}{{#swagger2AnnotationLibrary}}@Parameter(description = "{{{description}}}", `in` = ParameterIn.HEADER{{#required}}, required = true{{/required}}{{#allowableValues}}{{#defaultValue}}, schema = Schema(allowableValues = [{{#values}}"{{{.}}}"{{^-last}}, {{/-last}}{{/values}}]{{^isContainer}}, defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{/isContainer}}){{/defaultValue}}{{/allowableValues}}{{#allowableValues}}{{^defaultValue}}, schema = Schema(allowableValues = [{{#values}}"{{{.}}}"{{^-last}}, {{/-last}}{{/values}}]){{/defaultValue}}{{/allowableValues}}{{^allowableValues}}{{#defaultValue}}{{^isContainer}}, schema = Schema(defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}){{/isContainer}}{{/defaultValue}}{{/allowableValues}}){{/swagger2AnnotationLibrary}}{{#swagger1AnnotationLibrary}}@ApiParam(value = "{{{description}}}"{{#required}}, required = true{{/required}}{{#allowableValues}}, allowableValues = "{{#values}}{{{.}}}{{^-last}}, {{/-last}}{{/values}}"{{/allowableValues}}{{#defaultValue}}, defaultValue = "{{{.}}}"{{/defaultValue}}){{/swagger1AnnotationLibrary}} @RequestHeader(value = "{{baseName}}", required = {{#required}}true{{/required}}{{^required}}false{{/required}}) {{paramName}}: {{>optionalDataType}}{{/isHeaderParam}}
|
|
@ -0,0 +1,89 @@
|
|||
package {{basePackage}}
|
||||
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.stereotype.Controller
|
||||
import org.springframework.web.bind.annotation.RequestMapping
|
||||
{{#sourceDocumentationProvider}}
|
||||
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper
|
||||
import org.springframework.beans.factory.annotation.Value
|
||||
import org.springframework.core.io.Resource
|
||||
import org.springframework.util.StreamUtils
|
||||
import org.springframework.web.bind.annotation.ResponseBody
|
||||
import org.springframework.web.bind.annotation.GetMapping
|
||||
{{/sourceDocumentationProvider}}
|
||||
{{^sourceDocumentationProvider}}
|
||||
{{#useSwaggerUI}}
|
||||
import org.springframework.web.bind.annotation.ResponseBody
|
||||
import org.springframework.web.bind.annotation.GetMapping
|
||||
{{/useSwaggerUI}}
|
||||
{{/sourceDocumentationProvider}}
|
||||
{{#reactive}}
|
||||
import org.springframework.web.reactive.function.server.HandlerFunction
|
||||
import org.springframework.web.reactive.function.server.RequestPredicates.GET
|
||||
import org.springframework.web.reactive.function.server.RouterFunction
|
||||
import org.springframework.web.reactive.function.server.RouterFunctions.route
|
||||
import org.springframework.web.reactive.function.server.ServerResponse
|
||||
import java.net.URI
|
||||
{{/reactive}}
|
||||
{{#sourceDocumentationProvider}}
|
||||
import java.nio.charset.Charset
|
||||
{{/sourceDocumentationProvider}}
|
||||
|
||||
/**
|
||||
* Home redirection to OpenAPI api documentation
|
||||
*/
|
||||
@Controller
|
||||
class HomeController {
|
||||
{{#useSwaggerUI}}
|
||||
{{^springDocDocumentationProvider}}
|
||||
{{#sourceDocumentationProvider}}
|
||||
private val apiDocsPath = "/openapi.json"
|
||||
{{/sourceDocumentationProvider}}
|
||||
{{#springFoxDocumentationProvider}}
|
||||
private val apiDocsPath = "/v2/api-docs"
|
||||
{{/springFoxDocumentationProvider}}
|
||||
{{/springDocDocumentationProvider}}
|
||||
{{/useSwaggerUI}}
|
||||
{{#sourceDocumentationProvider}}
|
||||
private val yamlMapper = YAMLMapper()
|
||||
|
||||
@Value("classpath:/openapi.yaml")
|
||||
private lateinit var openapi: Resource
|
||||
|
||||
@Bean
|
||||
fun openapiContent(): String {
|
||||
return openapi.inputStream.use {
|
||||
StreamUtils.copyToString(it, Charset.defaultCharset())
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping(value = ["/openapi.yaml"], produces = ["application/vnd.oai.openapi"])
|
||||
@ResponseBody
|
||||
fun openapiYaml(): String = openapiContent()
|
||||
|
||||
@GetMapping(value = ["/openapi.json"], produces = ["application/json"])
|
||||
@ResponseBody
|
||||
fun openapiJson(): Any = yamlMapper.readValue(openapiContent(), Any::class.java)
|
||||
{{/sourceDocumentationProvider}}
|
||||
{{#useSwaggerUI}}
|
||||
{{^springDocDocumentationProvider}}
|
||||
|
||||
@GetMapping(value = ["/swagger-config.yaml"], produces = ["text/plain"])
|
||||
@ResponseBody
|
||||
fun swaggerConfig(): String = "url: $apiDocsPath\n"
|
||||
{{/springDocDocumentationProvider}}
|
||||
{{#reactive}}
|
||||
|
||||
@Bean
|
||||
fun index(): RouterFunction<ServerResponse> = route(
|
||||
GET("/"), HandlerFunction<ServerResponse> {
|
||||
ServerResponse.temporaryRedirect(URI.create("swagger-ui.html")).build()
|
||||
})
|
||||
{{/reactive}}
|
||||
{{^reactive}}
|
||||
|
||||
@RequestMapping("/")
|
||||
fun index(): String = "redirect:swagger-ui.html"
|
||||
{{/reactive}}
|
||||
{{/useSwaggerUI}}
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
{{#swagger2AnnotationLibrary}}
|
||||
@get:Schema({{#example}}example = "{{{.}}}", {{/example}}{{#required}}requiredMode = Schema.RequiredMode.REQUIRED, {{/required}}{{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}description = "{{{description}}}"){{/swagger2AnnotationLibrary}}{{#swagger1AnnotationLibrary}}
|
||||
@get:ApiModelProperty({{#example}}example = "{{{.}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}{{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}value = "{{{description}}}"){{/swagger1AnnotationLibrary}}
|
||||
{{>modelMutable}} {{{name}}}: {{#isEnum}}{{classname}}.{{nameInCamelCase}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}? {{^discriminator}}= {{{defaultValue}}}{{^defaultValue}}null{{/defaultValue}}{{/discriminator}}
|
|
@ -0,0 +1,4 @@
|
|||
{{#swagger2AnnotationLibrary}}
|
||||
@get:Schema({{#example}}example = "{{{.}}}", {{/example}}{{#required}}requiredMode = Schema.RequiredMode.REQUIRED, {{/required}}{{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}description = "{{{description}}}"){{/swagger2AnnotationLibrary}}{{#swagger1AnnotationLibrary}}
|
||||
@get:ApiModelProperty({{#example}}example = "{{{.}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}{{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}value = "{{{description}}}"){{/swagger1AnnotationLibrary}}
|
||||
{{>modelMutable}} {{{name}}}: {{#isEnum}}{{classname}}.{{nameInCamelCase}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}
|
|
@ -0,0 +1,21 @@
|
|||
# {{title}}{{^title}}Generated Kotlin Spring Boot App{{/title}}
|
||||
|
||||
This Kotlin based [Spring Boot](https://spring.io/projects/spring-boot) application has been generated using the [OpenAPI Generator](https://github.com/OpenAPITools/openapi-generator).
|
||||
|
||||
## Getting Started
|
||||
|
||||
This document assumes you have either maven or gradle available, either via the wrapper or otherwise. This does not come with a gradle / maven wrapper checked in.
|
||||
|
||||
By default a [`pom.xml`](pom.xml) file will be generated. If you specified `gradleBuildFile=true` when generating this project, a `build.gradle.kts` will also be generated. Note this uses [Gradle Kotlin DSL](https://github.com/gradle/kotlin-dsl).
|
||||
|
||||
To build the project using maven, run:
|
||||
```bash
|
||||
mvn package && java -jar target/{{artifactId}}-{{artifactVersion}}.jar
|
||||
```
|
||||
|
||||
To build the project using gradle, run:
|
||||
```bash
|
||||
gradle build && java -jar build/libs/{{artifactId}}-{{artifactVersion}}.jar
|
||||
```
|
||||
|
||||
If all builds successfully, the server should run on [http://localhost:8080/](http://localhost:{{serverPort}}/)
|
|
@ -0,0 +1,10 @@
|
|||
spring:
|
||||
application:
|
||||
name: {{title}}
|
||||
|
||||
jackson:
|
||||
serialization:
|
||||
WRITE_DATES_AS_TIMESTAMPS: false
|
||||
|
||||
server:
|
||||
port: {{serverPort}}
|
|
@ -0,0 +1,57 @@
|
|||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
|
||||
group = "{{groupId}}"
|
||||
version = "{{artifactVersion}}"
|
||||
java.sourceCompatibility = JavaVersion.VERSION_17
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven { url = uri("https://repo.spring.io/milestone") }
|
||||
}
|
||||
|
||||
tasks.withType<KotlinCompile> {
|
||||
kotlinOptions.jvmTarget = "17"
|
||||
}
|
||||
|
||||
plugins {
|
||||
val kotlinVersion = "1.7.10"
|
||||
id("org.jetbrains.kotlin.jvm") version kotlinVersion
|
||||
id("org.jetbrains.kotlin.plugin.jpa") version kotlinVersion
|
||||
id("org.jetbrains.kotlin.plugin.spring") version kotlinVersion
|
||||
id("org.springframework.boot") version "3.0.2"
|
||||
id("io.spring.dependency-management") version "1.0.14.RELEASE"
|
||||
}
|
||||
|
||||
dependencies {
|
||||
{{#reactive}} val kotlinxCoroutinesVersion = "1.6.1"
|
||||
{{/reactive}} implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
|
||||
implementation("org.jetbrains.kotlin:kotlin-reflect"){{^reactive}}
|
||||
implementation("org.springframework.boot:spring-boot-starter-web"){{/reactive}}{{#reactive}}
|
||||
implementation("org.springframework.boot:spring-boot-starter-webflux")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlinxCoroutinesVersion")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactor:$kotlinxCoroutinesVersion"){{/reactive}}{{#springDocDocumentationProvider}}{{#useSwaggerUI}}
|
||||
implementation("org.springdoc:springdoc-openapi-starter-{{#reactive}}webflux{{/reactive}}{{^reactive}}webmvc{{/reactive}}-ui:2.0.0-M5"){{/useSwaggerUI}}{{^useSwaggerUI}}
|
||||
implementation("org.springdoc:springdoc-openapi-{{#reactive}}webflux{{/reactive}}{{^reactive}}webmvc{{/reactive}}-core:2.0.0-M5"){{/useSwaggerUI}}{{/springDocDocumentationProvider}}{{#springFoxDocumentationProvider}}
|
||||
implementation("io.springfox:springfox-swagger2:2.9.2"){{/springFoxDocumentationProvider}}{{#useSwaggerUI}}{{^springDocDocumentationProvider}}
|
||||
implementation("org.webjars:swagger-ui:4.10.3")
|
||||
implementation("org.webjars:webjars-locator-core"){{/springDocDocumentationProvider}}{{/useSwaggerUI}}{{^springFoxDocumentationProvider}}{{^springDocDocumentationProvider}}{{#swagger1AnnotationLibrary}}
|
||||
implementation("io.swagger:swagger-annotations:1.6.6"){{/swagger1AnnotationLibrary}}{{#swagger2AnnotationLibrary}}
|
||||
implementation("io.swagger.core.v3:swagger-annotations:2.2.0"){{/swagger2AnnotationLibrary}}{{/springDocDocumentationProvider}}{{/springFoxDocumentationProvider}}
|
||||
|
||||
implementation("com.google.code.findbugs:jsr305:3.0.2")
|
||||
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml")
|
||||
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-xml")
|
||||
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310")
|
||||
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
|
||||
{{#useBeanValidation}}
|
||||
implementation("jakarta.validation:jakarta.validation-api"){{/useBeanValidation}}
|
||||
implementation("jakarta.annotation:jakarta.annotation-api:2.1.0")
|
||||
|
||||
testImplementation("org.jetbrains.kotlin:kotlin-test-junit5")
|
||||
testImplementation("org.springframework.boot:spring-boot-starter-test") {
|
||||
exclude(module = "junit")
|
||||
}
|
||||
{{#reactive}}
|
||||
testImplementation`("org.jetbrains.kotlinx:kotlinx-coroutines-test:$kotlinxCoroutinesVersion")
|
||||
{{/reactive}}
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.6.7")
|
||||
}
|
||||
}
|
||||
|
||||
group = "{{groupId}}"
|
||||
version = "{{artifactVersion}}"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
tasks.withType<KotlinCompile> {
|
||||
kotlinOptions.jvmTarget = "1.8"
|
||||
}
|
||||
|
||||
plugins {
|
||||
val kotlinVersion = "1.6.21"
|
||||
id("org.jetbrains.kotlin.jvm") version kotlinVersion
|
||||
id("org.jetbrains.kotlin.plugin.jpa") version kotlinVersion
|
||||
id("org.jetbrains.kotlin.plugin.spring") version kotlinVersion
|
||||
id("org.springframework.boot") version "2.6.7"
|
||||
id("io.spring.dependency-management") version "1.0.11.RELEASE"
|
||||
}
|
||||
|
||||
dependencies {
|
||||
{{#reactive}} val kotlinxCoroutinesVersion = "1.6.1"
|
||||
{{/reactive}} compile("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
|
||||
compile("org.jetbrains.kotlin:kotlin-reflect"){{^reactive}}
|
||||
compile("org.springframework.boot:spring-boot-starter-web"){{/reactive}}{{#reactive}}
|
||||
compile("org.springframework.boot:spring-boot-starter-webflux")
|
||||
compile("org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlinxCoroutinesVersion")
|
||||
compile("org.jetbrains.kotlinx:kotlinx-coroutines-reactor:$kotlinxCoroutinesVersion"){{/reactive}}{{#springDocDocumentationProvider}}{{#useSwaggerUI}}
|
||||
compile("org.springdoc:springdoc-openapi-{{#reactive}}webflux-{{/reactive}}ui:1.6.8"){{/useSwaggerUI}}{{^useSwaggerUI}}
|
||||
compile("org.springdoc:springdoc-openapi-{{#reactive}}webflux{{/reactive}}{{^reactive}}webmvc{{/reactive}}-core:1.6.8"){{/useSwaggerUI}}{{/springDocDocumentationProvider}}{{#springFoxDocumentationProvider}}
|
||||
compile("io.springfox:springfox-swagger2:2.9.2"){{/springFoxDocumentationProvider}}{{#useSwaggerUI}}{{^springDocDocumentationProvider}}
|
||||
compile("org.webjars:swagger-ui:4.10.3")
|
||||
compile("org.webjars:webjars-locator-core"){{/springDocDocumentationProvider}}{{/useSwaggerUI}}{{^springFoxDocumentationProvider}}{{^springDocDocumentationProvider}}{{#swagger1AnnotationLibrary}}
|
||||
compile("io.swagger:swagger-annotations:1.6.6"){{/swagger1AnnotationLibrary}}{{#swagger2AnnotationLibrary}}
|
||||
compile("io.swagger.core.v3:swagger-annotations:2.2.0"){{/swagger2AnnotationLibrary}}{{/springDocDocumentationProvider}}{{/springFoxDocumentationProvider}}
|
||||
|
||||
compile("com.google.code.findbugs:jsr305:3.0.2")
|
||||
compile("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml")
|
||||
compile("com.fasterxml.jackson.dataformat:jackson-dataformat-xml")
|
||||
compile("com.fasterxml.jackson.datatype:jackson-datatype-jsr310")
|
||||
compile("com.fasterxml.jackson.module:jackson-module-kotlin")
|
||||
{{#useBeanValidation}}
|
||||
compile("jakarta.validation:jakarta.validation-api"){{/useBeanValidation}}
|
||||
compile("jakarta.annotation:jakarta.annotation-api:2.1.0")
|
||||
|
||||
testCompile("org.jetbrains.kotlin:kotlin-test-junit5")
|
||||
testCompile("org.springframework.boot:spring-boot-starter-test") {
|
||||
exclude(module = "junit")
|
||||
}
|
||||
{{#reactive}}
|
||||
testCompile("org.jetbrains.kotlinx:kotlinx-coroutines-test:$kotlinxCoroutinesVersion")
|
||||
{{/reactive}}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
{{contextPath}}
|
|
@ -0,0 +1,200 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>{{groupId}}</groupId>
|
||||
<artifactId>{{artifactId}}</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>{{artifactId}}</name>
|
||||
<version>{{artifactVersion}}</version>
|
||||
<properties>{{#reactive}}
|
||||
<kotlinx-coroutines.version>1.6.1</kotlinx-coroutines.version>{{/reactive}}{{#springDocDocumentationProvider}}{{#useSwaggerUI}}
|
||||
<springdoc-openapi.version>2.0.2</springdoc-openapi.version>{{/useSwaggerUI}}{{/springDocDocumentationProvider}}{{#springFoxDocumentationProvider}}
|
||||
<springfox-swagger2.version>2.9.2</springfox-swagger2.version>{{/springFoxDocumentationProvider}}{{#useSwaggerUI}}{{^springDocDocumentationProvider}}
|
||||
<swagger-ui.version>4.15.5</swagger-ui.version>{{/springDocDocumentationProvider}}{{/useSwaggerUI}}{{^springFoxDocumentationProvider}}{{^springDocDocumentationProvider}}{{#swagger1AnnotationLibrary}}
|
||||
<swagger-annotations.version>1.6.6</swagger-annotations.version>{{/swagger1AnnotationLibrary}}{{#swagger2AnnotationLibrary}}
|
||||
<swagger-annotations.version>2.2.7</swagger-annotations.version>{{/swagger2AnnotationLibrary}}{{/springDocDocumentationProvider}}{{/springFoxDocumentationProvider}}
|
||||
<findbugs-jsr305.version>3.0.2</findbugs-jsr305.version>
|
||||
<jakarta-annotation.version>2.1.0</jakarta-annotation.version>
|
||||
<kotlin-test-junit5.version>1.7.10</kotlin-test-junit5.version>
|
||||
|
||||
<kotlin.version>1.7.10</kotlin.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.0.2</version>
|
||||
</parent>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>repository.spring.milestone</id>
|
||||
<name>Spring Milestone Repository</name>
|
||||
<url>https://repo.spring.io/milestone</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>spring-milestones</id>
|
||||
<url>https://repo.spring.io/milestone</url>
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
<build>
|
||||
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
|
||||
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
|
||||
<plugins>{{^interfaceOnly}}
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>{{/interfaceOnly}}
|
||||
<plugin>
|
||||
<artifactId>kotlin-maven-plugin</artifactId>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<version>${kotlin.version}</version>
|
||||
<configuration>
|
||||
<compilerPlugins>
|
||||
<plugin>spring</plugin>
|
||||
</compilerPlugins>
|
||||
<jvmTarget>17</jvmTarget>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>compile</id>
|
||||
<phase>compile</phase>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>test-compile</id>
|
||||
<phase>test-compile</phase>
|
||||
<goals>
|
||||
<goal>test-compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-maven-allopen</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib-jdk8</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-reflect</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
</dependency>{{^reactive}}
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>{{/reactive}}{{#reactive}}
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-webflux</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlinx</groupId>
|
||||
<artifactId>kotlinx-coroutines-core</artifactId>
|
||||
<version>${kotlinx-coroutines.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlinx</groupId>
|
||||
<artifactId>kotlinx-coroutines-reactor</artifactId>
|
||||
<version>${kotlinx-coroutines.version}</version>
|
||||
</dependency>{{/reactive}}
|
||||
|
||||
{{#springDocDocumentationProvider}}
|
||||
<!--SpringDoc dependencies -->{{#useSwaggerUI}}
|
||||
<dependency>
|
||||
<groupId>org.springdoc</groupId>
|
||||
<artifactId>springdoc-openapi-starter-{{#reactive}}webflux{{/reactive}}{{^reactive}}webmvc{{/reactive}}-ui</artifactId>
|
||||
<version>${springdoc-openapi.version}</version>
|
||||
</dependency>{{/useSwaggerUI}}{{^useSwaggerUI}}
|
||||
<dependency>
|
||||
<groupId>org.springdoc</groupId>
|
||||
<artifactId>springdoc-openapi-{{#reactive}}webflux{{/reactive}}{{^reactive}}webmvc{{/reactive}}-core</artifactId>
|
||||
<version>${springdoc-openapi.version}</version>
|
||||
</dependency>{{/useSwaggerUI}}{{/springDocDocumentationProvider}}{{#springFoxDocumentationProvider}}
|
||||
<!--SpringFox dependencies -->
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger2</artifactId>
|
||||
<version>${springfox-swagger2.version}</version>
|
||||
</dependency>{{/springFoxDocumentationProvider}}{{#useSwaggerUI}}{{^springDocDocumentationProvider}}
|
||||
<dependency>
|
||||
<groupId>org.webjars</groupId>
|
||||
<artifactId>swagger-ui</artifactId>
|
||||
<version>${swagger-ui.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.webjars</groupId>
|
||||
<artifactId>webjars-locator-core</artifactId>
|
||||
</dependency>{{/springDocDocumentationProvider}}{{/useSwaggerUI}}{{^springFoxDocumentationProvider}}{{^springDocDocumentationProvider}}{{#swagger1AnnotationLibrary}}
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-annotations</artifactId>
|
||||
<version>${swagger-annotations.version}</version>
|
||||
</dependency>{{/swagger1AnnotationLibrary}}{{#swagger2AnnotationLibrary}}
|
||||
<dependency>
|
||||
<groupId>io.swagger.core.v3</groupId>
|
||||
<artifactId>swagger-annotations</artifactId>
|
||||
<version>${swagger-annotations.version}</version>
|
||||
</dependency>{{/swagger2AnnotationLibrary}}{{/springDocDocumentationProvider}}{{/springFoxDocumentationProvider}}
|
||||
|
||||
<!-- @Nullable annotation -->
|
||||
<dependency>
|
||||
<groupId>com.google.code.findbugs</groupId>
|
||||
<artifactId>jsr305</artifactId>
|
||||
<version>${findbugs-jsr305.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||
<artifactId>jackson-dataformat-yaml</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||
<artifactId>jackson-dataformat-xml</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.module</groupId>
|
||||
<artifactId>jackson-module-kotlin</artifactId>
|
||||
</dependency>
|
||||
{{#useBeanValidation}}
|
||||
<!-- Bean Validation API support -->
|
||||
<dependency>
|
||||
<groupId>jakarta.validation</groupId>
|
||||
<artifactId>jakarta.validation-api</artifactId>
|
||||
</dependency>{{/useBeanValidation}}
|
||||
<dependency>
|
||||
<groupId>jakarta.annotation</groupId>
|
||||
<artifactId>jakarta.annotation-api</artifactId>
|
||||
<version>${jakarta-annotation.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-test-junit5</artifactId>
|
||||
<version>${kotlin-test-junit5.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,187 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>{{groupId}}</groupId>
|
||||
<artifactId>{{artifactId}}</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>{{artifactId}}</name>
|
||||
<version>{{artifactVersion}}</version>
|
||||
<properties>{{#reactive}}
|
||||
<kotlinx-coroutines.version>1.6.1</kotlinx-coroutines.version>{{/reactive}}{{#springDocDocumentationProvider}}{{#useSwaggerUI}}
|
||||
<springdoc-openapi.version>1.6.8</springdoc-openapi.version>{{/useSwaggerUI}}{{/springDocDocumentationProvider}}{{#springFoxDocumentationProvider}}
|
||||
<springfox-swagger2.version>2.9.2</springfox-swagger2.version>{{/springFoxDocumentationProvider}}{{#useSwaggerUI}}{{^springDocDocumentationProvider}}
|
||||
<swagger-ui.version>4.10.3</swagger-ui.version>{{/springDocDocumentationProvider}}{{/useSwaggerUI}}{{^springFoxDocumentationProvider}}{{^springDocDocumentationProvider}}{{#swagger1AnnotationLibrary}}
|
||||
<swagger-annotations.version>1.6.6</swagger-annotations.version>{{/swagger1AnnotationLibrary}}{{#swagger2AnnotationLibrary}}
|
||||
<swagger-annotations.version>2.2.0</swagger-annotations.version>{{/swagger2AnnotationLibrary}}{{/springDocDocumentationProvider}}{{/springFoxDocumentationProvider}}
|
||||
<findbugs-jsr305.version>3.0.2</findbugs-jsr305.version>
|
||||
<jakarta-annotation.version>2.1.0</jakarta-annotation.version>
|
||||
<kotlin-test-junit5.version>1.6.21</kotlin-test-junit5.version>
|
||||
|
||||
<kotlin.version>1.6.21</kotlin.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.6.7</version>
|
||||
</parent>
|
||||
<build>
|
||||
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
|
||||
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
|
||||
<plugins>{{^interfaceOnly}}
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>{{/interfaceOnly}}
|
||||
<plugin>
|
||||
<artifactId>kotlin-maven-plugin</artifactId>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<version>${kotlin.version}</version>
|
||||
<configuration>
|
||||
<compilerPlugins>
|
||||
<plugin>spring</plugin>
|
||||
</compilerPlugins>
|
||||
<jvmTarget>1.8</jvmTarget>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>compile</id>
|
||||
<phase>compile</phase>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>test-compile</id>
|
||||
<phase>test-compile</phase>
|
||||
<goals>
|
||||
<goal>test-compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-maven-allopen</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib-jdk8</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-reflect</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
</dependency>{{^reactive}}
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>{{/reactive}}{{#reactive}}
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-webflux</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlinx</groupId>
|
||||
<artifactId>kotlinx-coroutines-core</artifactId>
|
||||
<version>${kotlinx-coroutines.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlinx</groupId>
|
||||
<artifactId>kotlinx-coroutines-reactor</artifactId>
|
||||
<version>${kotlinx-coroutines.version}</version>
|
||||
</dependency>{{/reactive}}
|
||||
|
||||
{{#springDocDocumentationProvider}}
|
||||
<!--SpringDoc dependencies -->{{#useSwaggerUI}}
|
||||
<dependency>
|
||||
<groupId>org.springdoc</groupId>
|
||||
<artifactId>springdoc-openapi-{{#reactive}}webflux-{{/reactive}}ui</artifactId>
|
||||
<version>${springdoc-openapi.version}</version>
|
||||
</dependency>{{/useSwaggerUI}}{{^useSwaggerUI}}
|
||||
<dependency>
|
||||
<groupId>org.springdoc</groupId>
|
||||
<artifactId>springdoc-openapi-{{#reactive}}webflux{{/reactive}}{{^reactive}}webmvc{{/reactive}}-core</artifactId>
|
||||
<version>${springdoc-openapi.version}</version>
|
||||
</dependency>{{/useSwaggerUI}}{{/springDocDocumentationProvider}}{{#springFoxDocumentationProvider}}
|
||||
<!--SpringFox dependencies -->
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger2</artifactId>
|
||||
<version>${springfox-swagger2.version}</version>
|
||||
</dependency>{{/springFoxDocumentationProvider}}{{#useSwaggerUI}}{{^springDocDocumentationProvider}}
|
||||
<dependency>
|
||||
<groupId>org.webjars</groupId>
|
||||
<artifactId>swagger-ui</artifactId>
|
||||
<version>${swagger-ui.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.webjars</groupId>
|
||||
<artifactId>webjars-locator-core</artifactId>
|
||||
</dependency>{{/springDocDocumentationProvider}}{{/useSwaggerUI}}{{^springFoxDocumentationProvider}}{{^springDocDocumentationProvider}}{{#swagger1AnnotationLibrary}}
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-annotations</artifactId>
|
||||
<version>${swagger-annotations.version}</version>
|
||||
</dependency>{{/swagger1AnnotationLibrary}}{{#swagger2AnnotationLibrary}}
|
||||
<dependency>
|
||||
<groupId>io.swagger.core.v3</groupId>
|
||||
<artifactId>swagger-annotations</artifactId>
|
||||
<version>${swagger-annotations.version}</version>
|
||||
</dependency>{{/swagger2AnnotationLibrary}}{{/springDocDocumentationProvider}}{{/springFoxDocumentationProvider}}
|
||||
|
||||
<!-- @Nullable annotation -->
|
||||
<dependency>
|
||||
<groupId>com.google.code.findbugs</groupId>
|
||||
<artifactId>jsr305</artifactId>
|
||||
<version>${findbugs-jsr305.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||
<artifactId>jackson-dataformat-yaml</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||
<artifactId>jackson-dataformat-xml</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.module</groupId>
|
||||
<artifactId>jackson-module-kotlin</artifactId>
|
||||
</dependency>
|
||||
{{#useBeanValidation}}
|
||||
<!-- Bean Validation API support -->
|
||||
<dependency>
|
||||
<groupId>jakarta.validation</groupId>
|
||||
<artifactId>jakarta.validation-api</artifactId>
|
||||
</dependency>{{/useBeanValidation}}
|
||||
<dependency>
|
||||
<groupId>jakarta.annotation</groupId>
|
||||
<artifactId>jakarta.annotation-api</artifactId>
|
||||
<version>${jakarta-annotation.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-test-junit5</artifactId>
|
||||
<version>${kotlin-test-junit5.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,15 @@
|
|||
pluginManagement {
|
||||
repositories {
|
||||
maven { url = uri("https://repo.spring.io/snapshot") }
|
||||
maven { url = uri("https://repo.spring.io/milestone") }
|
||||
gradlePluginPortal()
|
||||
}
|
||||
resolutionStrategy {
|
||||
eachPlugin {
|
||||
if (requested.id.id == "org.springframework.boot") {
|
||||
useModule("org.springframework.boot:spring-boot-gradle-plugin:${requested.version}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
rootProject.name = "{{artifactId}}"
|
|
@ -0,0 +1,13 @@
|
|||
package {{basePackage}}
|
||||
|
||||
import org.springframework.boot.runApplication
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication
|
||||
import org.springframework.context.annotation.ComponentScan
|
||||
|
||||
@SpringBootApplication
|
||||
@ComponentScan(basePackages = ["{{basePackage}}", "{{apiPackage}}", "{{modelPackage}}"])
|
||||
class Application
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
runApplication<Application>(*args)
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
<!-- HTML for static distribution bundle build -->
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Swagger UI</title>
|
||||
<link rel="stylesheet" type="text/css" href="webjars/swagger-ui/swagger-ui.css" />
|
||||
<link rel="icon" type="image/png" href="webjars/swagger-ui/favicon-32x32.png" sizes="32x32" />
|
||||
<link rel="icon" type="image/png" href="webjars/swagger-ui/favicon-16x16.png" sizes="16x16" />
|
||||
<style>
|
||||
html
|
||||
{
|
||||
box-sizing: border-box;
|
||||
overflow: -moz-scrollbars-vertical;
|
||||
overflow-y: scroll;
|
||||
}
|
||||
|
||||
*,
|
||||
*:before,
|
||||
*:after
|
||||
{
|
||||
box-sizing: inherit;
|
||||
}
|
||||
|
||||
body
|
||||
{
|
||||
margin:0;
|
||||
background: #fafafa;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="swagger-ui"></div>
|
||||
|
||||
<script src="webjars/swagger-ui/swagger-ui-bundle.js" charset="UTF-8"> </script>
|
||||
<script src="webjars/swagger-ui/swagger-ui-standalone-preset.js" charset="UTF-8"> </script>
|
||||
<script>
|
||||
window.onload = function() {
|
||||
// Begin Swagger UI call region
|
||||
const ui = SwaggerUIBundle({
|
||||
configUrl: 'swagger-config.yaml',
|
||||
dom_id: '#swagger-ui',
|
||||
deepLinking: true,
|
||||
presets: [
|
||||
SwaggerUIBundle.presets.apis,
|
||||
SwaggerUIStandalonePreset
|
||||
],
|
||||
plugins: [
|
||||
SwaggerUIBundle.plugins.DownloadUrl
|
||||
],
|
||||
layout: "StandaloneLayout"
|
||||
});
|
||||
// End Swagger UI call region
|
||||
|
||||
window.ui = ui;
|
||||
};
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,83 @@
|
|||
{{^interfaceOnly}}
|
||||
# {{artifactId}}
|
||||
|
||||
## Requirements
|
||||
|
||||
Building the API client library requires [Maven](https://maven.apache.org/) to be installed.
|
||||
|
||||
## Installation
|
||||
|
||||
To install the API client library to your local Maven repository, simply execute:
|
||||
|
||||
```shell
|
||||
mvn install
|
||||
```
|
||||
|
||||
To deploy it to a remote Maven repository instead, configure the settings of the repository and execute:
|
||||
|
||||
```shell
|
||||
mvn deploy
|
||||
```
|
||||
|
||||
Refer to the [official documentation](https://maven.apache.org/plugins/maven-deploy-plugin/usage.html) for more information.
|
||||
|
||||
### Maven users
|
||||
|
||||
Add this dependency to your project's POM:
|
||||
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>{{{groupId}}}</groupId>
|
||||
<artifactId>{{{artifactId}}}</artifactId>
|
||||
<version>{{{artifactVersion}}}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
### Gradle users
|
||||
|
||||
Add this dependency to your project's build file:
|
||||
|
||||
```groovy
|
||||
compile "{{{groupId}}}:{{{artifactId}}}:{{{artifactVersion}}}"
|
||||
```
|
||||
|
||||
### Others
|
||||
|
||||
At first generate the JAR by executing:
|
||||
|
||||
mvn package
|
||||
|
||||
Then manually install the following JARs:
|
||||
|
||||
* target/{{{artifactId}}}-{{{artifactVersion}}}.jar
|
||||
* target/lib/*.jar
|
||||
{{/interfaceOnly}}
|
||||
{{#interfaceOnly}}
|
||||
# OpenAPI generated API stub
|
||||
|
||||
Spring Framework stub
|
||||
|
||||
|
||||
## Overview
|
||||
This code was generated by the [OpenAPI Generator](https://openapi-generator.tech) project.
|
||||
By using the [OpenAPI-Spec](https://openapis.org), you can easily generate an API stub.
|
||||
This is an example of building API stub interfaces in Java using the Spring framework.
|
||||
|
||||
The stubs generated can be used in your existing Spring-MVC or Spring-Boot application to create controller endpoints
|
||||
by adding ```@Controller``` classes that implement the interface. Eg:
|
||||
```java
|
||||
@Controller
|
||||
public class PetController implements PetApi {
|
||||
// implement all PetApi methods
|
||||
}
|
||||
```
|
||||
|
||||
You can also use the interface to create [Spring-Cloud Feign clients](http://projects.spring.io/spring-cloud/spring-cloud.html#spring-cloud-feign-inheritance).Eg:
|
||||
```java
|
||||
@FeignClient(name="pet", url="http://petstore.swagger.io/v2")
|
||||
public interface PetClient extends PetApi {
|
||||
|
||||
}
|
||||
```
|
||||
{{/interfaceOnly}}
|
|
@ -0,0 +1,11 @@
|
|||
package {{package}}
|
||||
|
||||
import org.springframework.cloud.openfeign.FeignClient
|
||||
import {{configPackage}}.ClientConfiguration
|
||||
|
||||
@FeignClient(
|
||||
name="\${{openbrace}}{{classVarName}}.name:{{classVarName}}{{closebrace}}",
|
||||
{{#useFeignClientUrl}}url="\${{openbrace}}{{classVarName}}.url:{{basePath}}{{closebrace}}", {{/useFeignClientUrl}}
|
||||
configuration = [ClientConfiguration::class]
|
||||
)
|
||||
interface {{classname}}Client : {{classname}}
|
|
@ -0,0 +1,19 @@
|
|||
package {{configPackage}}
|
||||
|
||||
import feign.RequestInterceptor
|
||||
import feign.RequestTemplate
|
||||
|
||||
class ApiKeyRequestInterceptor(
|
||||
private val location: String,
|
||||
private val name: String,
|
||||
private val value: String,
|
||||
) : RequestInterceptor {
|
||||
|
||||
override fun apply(requestTemplate: RequestTemplate) {
|
||||
if (location == "header") {
|
||||
requestTemplate.header(name, value)
|
||||
} else if (location == "query") {
|
||||
requestTemplate.query(name, value)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
|
||||
group = "{{groupId}}"
|
||||
version = "{{artifactVersion}}"
|
||||
java.sourceCompatibility = JavaVersion.VERSION_17
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven { url = uri("https://repo.spring.io/milestone") }
|
||||
}
|
||||
|
||||
tasks.withType<KotlinCompile> {
|
||||
kotlinOptions.jvmTarget = "17"
|
||||
}
|
||||
|
||||
plugins {
|
||||
val kotlinVersion = "1.7.10"
|
||||
id("org.jetbrains.kotlin.jvm") version kotlinVersion
|
||||
id("org.jetbrains.kotlin.plugin.jpa") version kotlinVersion
|
||||
id("org.jetbrains.kotlin.plugin.spring") version kotlinVersion
|
||||
id("org.springframework.boot") version "3.0.2"
|
||||
id("io.spring.dependency-management") version "1.0.14.RELEASE"
|
||||
}
|
||||
|
||||
tasks.getByName("bootJar") {
|
||||
enabled = false
|
||||
}
|
||||
|
||||
tasks.getByName("jar") {
|
||||
enabled = true
|
||||
}
|
||||
|
||||
dependencyManagement {
|
||||
imports {
|
||||
mavenBom("org.springframework.cloud:spring-cloud-dependencies:2021.0.5")
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
{{#reactive}} val kotlinxCoroutinesVersion = "1.6.1"
|
||||
{{/reactive}} implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
|
||||
implementation("org.jetbrains.kotlin:kotlin-reflect"){{^reactive}}
|
||||
implementation("org.springframework.boot:spring-boot-starter-web"){{/reactive}}{{#reactive}}
|
||||
implementation("org.springframework.boot:spring-boot-starter-webflux")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlinxCoroutinesVersion")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactor:$kotlinxCoroutinesVersion"){{/reactive}}{{#springDocDocumentationProvider}}{{#useSwaggerUI}}
|
||||
implementation("org.springdoc:springdoc-openapi-starter-{{#reactive}}webflux{{/reactive}}{{^reactive}}webmvc{{/reactive}}-ui:2.0.0-M5"){{/useSwaggerUI}}{{^useSwaggerUI}}
|
||||
implementation("org.springdoc:springdoc-openapi-{{#reactive}}webflux{{/reactive}}{{^reactive}}webmvc{{/reactive}}-core:2.0.0-M5"){{/useSwaggerUI}}{{/springDocDocumentationProvider}}{{#springFoxDocumentationProvider}}
|
||||
implementation("io.springfox:springfox-swagger2:2.9.2"){{/springFoxDocumentationProvider}}{{#useSwaggerUI}}{{^springDocDocumentationProvider}}
|
||||
implementation("org.webjars:swagger-ui:4.10.3")
|
||||
implementation("org.webjars:webjars-locator-core"){{/springDocDocumentationProvider}}{{/useSwaggerUI}}{{^springFoxDocumentationProvider}}{{^springDocDocumentationProvider}}{{#swagger1AnnotationLibrary}}
|
||||
implementation("io.swagger:swagger-annotations:1.6.6"){{/swagger1AnnotationLibrary}}{{#swagger2AnnotationLibrary}}
|
||||
implementation("io.swagger.core.v3:swagger-annotations:2.2.0"){{/swagger2AnnotationLibrary}}{{/springDocDocumentationProvider}}{{/springFoxDocumentationProvider}}
|
||||
|
||||
implementation("com.google.code.findbugs:jsr305:3.0.2")
|
||||
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml")
|
||||
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-xml")
|
||||
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310")
|
||||
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
|
||||
|
||||
implementation("org.springframework.cloud:spring-cloud-starter-openfeign"){{#hasAuthMethods}}
|
||||
implementation("org.springframework.cloud:spring-cloud-starter-oauth2:2.2.5.RELEASE"){{/hasAuthMethods}}
|
||||
|
||||
{{#useBeanValidation}}
|
||||
implementation("jakarta.validation:jakarta.validation-api"){{/useBeanValidation}}
|
||||
implementation("jakarta.annotation:jakarta.annotation-api:2.1.0")
|
||||
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.6.7")
|
||||
}
|
||||
}
|
||||
|
||||
group = "{{groupId}}"
|
||||
version = "{{artifactVersion}}"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
tasks.withType<KotlinCompile> {
|
||||
kotlinOptions.jvmTarget = "1.8"
|
||||
}
|
||||
|
||||
plugins {
|
||||
val kotlinVersion = "1.6.21"
|
||||
id("org.jetbrains.kotlin.jvm") version kotlinVersion
|
||||
id("org.jetbrains.kotlin.plugin.jpa") version kotlinVersion
|
||||
id("org.jetbrains.kotlin.plugin.spring") version kotlinVersion
|
||||
id("org.springframework.boot") version "2.6.7"
|
||||
id("io.spring.dependency-management") version "1.0.11.RELEASE"
|
||||
}
|
||||
|
||||
tasks.getByName("bootJar") {
|
||||
enabled = false
|
||||
}
|
||||
|
||||
tasks.getByName("jar") {
|
||||
enabled = true
|
||||
}
|
||||
|
||||
dependencyManagement {
|
||||
imports {
|
||||
mavenBom("org.springframework.cloud:spring-cloud-dependencies:2021.0.5")
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
{{#reactive}} val kotlinxCoroutinesVersion = "1.6.1"
|
||||
{{/reactive}} implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
|
||||
implementation("org.jetbrains.kotlin:kotlin-reflect"){{^reactive}}
|
||||
implementation("org.springframework.boot:spring-boot-starter-web"){{/reactive}}{{#reactive}}
|
||||
implementation("org.springframework.boot:spring-boot-starter-webflux")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlinxCoroutinesVersion")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactor:$kotlinxCoroutinesVersion"){{/reactive}}{{#springDocDocumentationProvider}}{{#useSwaggerUI}}
|
||||
implementation("org.springdoc:springdoc-openapi-{{#reactive}}webflux-{{/reactive}}ui:1.6.8"){{/useSwaggerUI}}{{^useSwaggerUI}}
|
||||
implementation("org.springdoc:springdoc-openapi-{{#reactive}}webflux{{/reactive}}{{^reactive}}webmvc{{/reactive}}-core:1.6.8"){{/useSwaggerUI}}{{/springDocDocumentationProvider}}{{#springFoxDocumentationProvider}}
|
||||
implementation("io.springfox:springfox-swagger2:2.9.2"){{/springFoxDocumentationProvider}}{{#useSwaggerUI}}{{^springDocDocumentationProvider}}
|
||||
implementation("org.webjars:swagger-ui:4.10.3")
|
||||
implementation("org.webjars:webjars-locator-core"){{/springDocDocumentationProvider}}{{/useSwaggerUI}}{{^springFoxDocumentationProvider}}{{^springDocDocumentationProvider}}{{#swagger1AnnotationLibrary}}
|
||||
implementation("io.swagger:swagger-annotations:1.6.6"){{/swagger1AnnotationLibrary}}{{#swagger2AnnotationLibrary}}
|
||||
implementation("io.swagger.core.v3:swagger-annotations:2.2.0"){{/swagger2AnnotationLibrary}}{{/springDocDocumentationProvider}}{{/springFoxDocumentationProvider}}
|
||||
|
||||
implementation("com.google.code.findbugs:jsr305:3.0.2")
|
||||
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml")
|
||||
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-xml")
|
||||
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310")
|
||||
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
|
||||
|
||||
implementation("org.springframework.cloud:spring-cloud-starter-openfeign"){{#hasAuthMethods}}
|
||||
implementation("org.springframework.cloud:spring-cloud-starter-oauth2:2.2.5.RELEASE"){{/hasAuthMethods}}
|
||||
|
||||
{{#useBeanValidation}}
|
||||
implementation("jakarta.validation:jakarta.validation-api"){{/useBeanValidation}}
|
||||
implementation("jakarta.annotation:jakarta.annotation-api:2.1.0")
|
||||
|
||||
}
|
|
@ -0,0 +1,132 @@
|
|||
package {{configPackage}}
|
||||
|
||||
{{#authMethods}}
|
||||
{{#isBasicBasic}}
|
||||
import feign.auth.BasicAuthRequestInterceptor
|
||||
{{/isBasicBasic}}
|
||||
{{#-first}}
|
||||
import org.springframework.beans.factory.annotation.Value
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
|
||||
{{/-first}}
|
||||
{{#isOAuth}}
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties
|
||||
{{/isOAuth}}
|
||||
{{/authMethods}}
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties
|
||||
{{#authMethods}}
|
||||
{{#-first}}
|
||||
import org.springframework.context.annotation.Bean
|
||||
{{/-first}}
|
||||
{{/authMethods}}
|
||||
import org.springframework.context.annotation.Configuration
|
||||
{{#authMethods}}
|
||||
{{#isOAuth}}
|
||||
import org.springframework.cloud.openfeign.security.OAuth2FeignRequestInterceptor
|
||||
import org.springframework.security.oauth2.client.DefaultOAuth2ClientContext
|
||||
import org.springframework.security.oauth2.client.OAuth2ClientContext
|
||||
{{#isApplication}}
|
||||
import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails
|
||||
{{/isApplication}}
|
||||
{{#isCode}}
|
||||
import org.springframework.security.oauth2.client.token.grant.code.AuthorizationCodeResourceDetails
|
||||
{{/isCode}}
|
||||
{{#isImplicit}}
|
||||
import org.springframework.security.oauth2.client.token.grant.implicit.ImplicitResourceDetails
|
||||
{{/isImplicit}}
|
||||
{{#isPassword}}
|
||||
import org.springframework.security.oauth2.client.token.grant.password.ResourceOwnerPasswordResourceDetails
|
||||
{{/isPassword}}
|
||||
{{/isOAuth}}
|
||||
{{/authMethods}}
|
||||
|
||||
@Configuration
|
||||
@EnableConfigurationProperties
|
||||
class ClientConfiguration {
|
||||
|
||||
{{#authMethods}}
|
||||
{{#isBasicBasic}}
|
||||
@Value("\${{openbrace}}{{#lambda.lowercase}}{{{title}}}{{/lambda.lowercase}}.security.{{{name}}}.username:{{closebrace}}")
|
||||
private lateinit var {{#lambda.camelcase}}{{{name}}}{{/lambda.camelcase}}Username: String
|
||||
|
||||
@Value("\${{openbrace}}{{#lambda.lowercase}}{{{title}}}{{/lambda.lowercase}}.security.{{{name}}}.password:{{closebrace}}")
|
||||
private lateinit var {{#lambda.camelcase}}{{{name}}}{{/lambda.camelcase}}Password: String
|
||||
|
||||
@Bean
|
||||
@ConditionalOnProperty("{{#lambda.lowercase}}{{{title}}}{{/lambda.lowercase}}.security.{{{name}}}.username")
|
||||
fun {{{name}}}RequestInterceptor(): BasicAuthRequestInterceptor {
|
||||
return BasicAuthRequestInterceptor(this.{{#lambda.camelcase}}{{{name}}}{{/lambda.camelcase}}Username, this.{{#lambda.camelcase}}{{{name}}}{{/lambda.camelcase}}Password)
|
||||
}
|
||||
|
||||
{{/isBasicBasic}}
|
||||
{{#isApiKey}}
|
||||
@Value("\${{openbrace}}{{#lambda.lowercase}}{{{title}}}{{/lambda.lowercase}}.security.{{{name}}}.key:{{closebrace}}")
|
||||
private lateinit var {{#lambda.camelcase}}{{{name}}}{{/lambda.camelcase}}Key: String
|
||||
|
||||
@Bean
|
||||
@ConditionalOnProperty("{{#lambda.lowercase}}{{{title}}}{{/lambda.lowercase}}.security.{{{name}}}.key")
|
||||
fun {{#lambda.camelcase}}{{{name}}}{{/lambda.camelcase}}RequestInterceptor(): ApiKeyRequestInterceptor {
|
||||
return ApiKeyRequestInterceptor({{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{^isKeyInHeader}}"query"{{/isKeyInHeader}}, "{{{keyParamName}}}", this.{{#lambda.camelcase}}{{{name}}}{{/lambda.camelcase}}Key)
|
||||
}
|
||||
|
||||
{{/isApiKey}}
|
||||
{{#isOAuth}}
|
||||
@Bean
|
||||
@ConditionalOnProperty("{{#lambda.lowercase}}{{{title}}}{{/lambda.lowercase}}.security.{{{name}}}.client-id")
|
||||
fun {{#lambda.camelcase}}{{{name}}}{{/lambda.camelcase}}RequestInterceptor(oAuth2ClientContext: OAuth2ClientContext): OAuth2FeignRequestInterceptor {
|
||||
return OAuth2FeignRequestInterceptor(oAuth2ClientContext, {{#lambda.camelcase}}{{{name}}}{{/lambda.camelcase}}ResourceDetails())
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnProperty("{{#lambda.lowercase}}{{{title}}}{{/lambda.lowercase}}.security.{{{name}}}.client-id")
|
||||
fun oAuth2ClientContext(): OAuth2ClientContext {
|
||||
return DefaultOAuth2ClientContext()
|
||||
}
|
||||
|
||||
{{#isCode}}
|
||||
@Bean
|
||||
@ConditionalOnProperty("{{#lambda.lowercase}}{{{title}}}{{/lambda.lowercase}}.security.{{{name}}}.client-id")
|
||||
@ConfigurationProperties("{{#lambda.lowercase}}{{{title}}}{{/lambda.lowercase}}.security.{{{name}}}")
|
||||
fun {{#lambda.camelcase}}{{{name}}}{{/lambda.camelcase}}ResourceDetails(): AuthorizationCodeResourceDetails {
|
||||
val details = AuthorizationCodeResourceDetails()
|
||||
details.accessTokenUri = "{{{tokenUrl}}}"
|
||||
details.userAuthorizationUri = "{{{authorizationUrl}}}"
|
||||
return details
|
||||
}
|
||||
|
||||
{{/isCode}}
|
||||
{{#isPassword}}
|
||||
@Bean
|
||||
@ConditionalOnProperty("{{#lambda.lowercase}}{{{title}}}{{/lambda.lowercase}}.security.{{{name}}}.client-id")
|
||||
@ConfigurationProperties("{{#lambda.lowercase}}{{{title}}}{{/lambda.lowercase}}.security.{{{name}}}")
|
||||
fun {{#lambda.camelcase}}{{{name}}}{{/lambda.camelcase}}ResourceDetails(): ResourceOwnerPasswordResourceDetails {
|
||||
val details = ResourceOwnerPasswordResourceDetails()
|
||||
details.accessTokenUri = "{{{tokenUrl}}}"
|
||||
return details
|
||||
}
|
||||
|
||||
{{/isPassword}}
|
||||
{{#isApplication}}
|
||||
@Bean
|
||||
@ConditionalOnProperty("{{#lambda.lowercase}}{{{title}}}{{/lambda.lowercase}}.security.{{{name}}}.client-id")
|
||||
@ConfigurationProperties("{{#lambda.lowercase}}{{{title}}}{{/lambda.lowercase}}.security.{{{name}}}")
|
||||
fun {{#lambda.camelcase}}{{{name}}}{{/lambda.camelcase}}ResourceDetails(): ClientCredentialsResourceDetails {
|
||||
val details = ClientCredentialsResourceDetails()
|
||||
details.accessTokenUri = "{{{tokenUrl}}}"
|
||||
return details
|
||||
}
|
||||
|
||||
{{/isApplication}}
|
||||
{{#isImplicit}}
|
||||
@Bean
|
||||
@ConditionalOnProperty("{{#lambda.lowercase}}{{{title}}}{{/lambda.lowercase}}.security.{{{name}}}.client-id")
|
||||
@ConfigurationProperties("{{#lambda.lowercase}}{{{title}}}{{/lambda.lowercase}}.security.{{{name}}}")
|
||||
fun {{#lambda.camelcase}}{{{name}}}{{/lambda.camelcase}}ResourceDetails(): ImplicitResourceDetails {
|
||||
val details = ImplicitResourceDetails()
|
||||
details.userAuthorizationUri= "{{{authorizationUrl}}}"
|
||||
return details
|
||||
}
|
||||
|
||||
{{/isImplicit}}
|
||||
{{/isOAuth}}
|
||||
{{/authMethods}}
|
||||
}
|
|
@ -0,0 +1,233 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>{{groupId}}</groupId>
|
||||
<artifactId>{{artifactId}}</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>{{artifactId}}</name>
|
||||
<version>{{artifactVersion}}</version>
|
||||
<properties>{{#reactive}}
|
||||
<kotlinx-coroutines.version>1.6.1
|
||||
</kotlinx-coroutines.version>{{/reactive}}{{#springDocDocumentationProvider}}{{#useSwaggerUI}}
|
||||
<springdoc-openapi.version>2.0.2
|
||||
</springdoc-openapi.version>{{/useSwaggerUI}}{{/springDocDocumentationProvider}}{{#springFoxDocumentationProvider}}
|
||||
<springfox-swagger2.version>2.9.2
|
||||
</springfox-swagger2.version>{{/springFoxDocumentationProvider}}{{#useSwaggerUI}}{{^springDocDocumentationProvider}}
|
||||
<swagger-ui.version>4.15.5
|
||||
</swagger-ui.version>{{/springDocDocumentationProvider}}{{/useSwaggerUI}}{{^springFoxDocumentationProvider}}{{^springDocDocumentationProvider}}{{#swagger1AnnotationLibrary}}
|
||||
<swagger-annotations.version>1.6.6
|
||||
</swagger-annotations.version>{{/swagger1AnnotationLibrary}}{{#swagger2AnnotationLibrary}}
|
||||
<swagger-annotations.version>2.2.7
|
||||
</swagger-annotations.version>{{/swagger2AnnotationLibrary}}{{/springDocDocumentationProvider}}{{/springFoxDocumentationProvider}}
|
||||
<findbugs-jsr305.version>3.0.2</findbugs-jsr305.version>
|
||||
<jakarta-annotation.version>2.1.0</jakarta-annotation.version>
|
||||
<kotlin-test-junit5.version>1.7.10</kotlin-test-junit5.version>
|
||||
|
||||
<kotlin.version>1.7.10</kotlin.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.0.2</version>
|
||||
</parent>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-parent</artifactId>
|
||||
<version>2021.0.5</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>repository.spring.milestone</id>
|
||||
<name>Spring Milestone Repository</name>
|
||||
<url>https://repo.spring.io/milestone</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>spring-milestones</id>
|
||||
<url>https://repo.spring.io/milestone</url>
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
<build>
|
||||
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
|
||||
<plugins>{{^interfaceOnly}}
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>{{/interfaceOnly}}
|
||||
<plugin>
|
||||
<artifactId>kotlin-maven-plugin</artifactId>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<version>${kotlin.version}</version>
|
||||
<configuration>
|
||||
<compilerPlugins>
|
||||
<plugin>spring</plugin>
|
||||
</compilerPlugins>
|
||||
<jvmTarget>17</jvmTarget>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>compile</id>
|
||||
<phase>compile</phase>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>test-compile</id>
|
||||
<phase>test-compile</phase>
|
||||
<goals>
|
||||
<goal>test-compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-maven-allopen</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib-jdk8</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-reflect</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
</dependency>{{^reactive}}
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>{{/reactive}}{{#reactive}}
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-webflux</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlinx</groupId>
|
||||
<artifactId>kotlinx-coroutines-core</artifactId>
|
||||
<version>${kotlinx-coroutines.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlinx</groupId>
|
||||
<artifactId>kotlinx-coroutines-reactor</artifactId>
|
||||
<version>${kotlinx-coroutines.version}</version>
|
||||
</dependency>{{/reactive}}
|
||||
|
||||
{{#springDocDocumentationProvider}}
|
||||
<!--SpringDoc dependencies -->{{#useSwaggerUI}}
|
||||
<dependency>
|
||||
<groupId>org.springdoc</groupId>
|
||||
<artifactId>springdoc-openapi-starter-{{#reactive}}
|
||||
webflux{{/reactive}}{{^reactive}}webmvc{{/reactive}}-ui
|
||||
</artifactId>
|
||||
<version>${springdoc-openapi.version}</version>
|
||||
</dependency>{{/useSwaggerUI}}{{^useSwaggerUI}}
|
||||
<dependency>
|
||||
<groupId>org.springdoc</groupId>
|
||||
<artifactId>springdoc-openapi-{{#reactive}}webflux{{/reactive}}{{^reactive}}webmvc{{/reactive}}-core
|
||||
</artifactId>
|
||||
<version>${springdoc-openapi.version}</version>
|
||||
</dependency>{{/useSwaggerUI}}{{/springDocDocumentationProvider}}{{#springFoxDocumentationProvider}}
|
||||
<!--SpringFox dependencies -->
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger2</artifactId>
|
||||
<version>${springfox-swagger2.version}</version>
|
||||
</dependency>{{/springFoxDocumentationProvider}}{{#useSwaggerUI}}{{^springDocDocumentationProvider}}
|
||||
<dependency>
|
||||
<groupId>org.webjars</groupId>
|
||||
<artifactId>swagger-ui</artifactId>
|
||||
<version>${swagger-ui.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.webjars</groupId>
|
||||
<artifactId>webjars-locator-core</artifactId>
|
||||
</dependency>{{/springDocDocumentationProvider}}{{/useSwaggerUI}}{{^springFoxDocumentationProvider}}{{^springDocDocumentationProvider}}{{#swagger1AnnotationLibrary}}
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-annotations</artifactId>
|
||||
<version>${swagger-annotations.version}</version>
|
||||
</dependency>{{/swagger1AnnotationLibrary}}{{#swagger2AnnotationLibrary}}
|
||||
<dependency>
|
||||
<groupId>io.swagger.core.v3</groupId>
|
||||
<artifactId>swagger-annotations</artifactId>
|
||||
<version>${swagger-annotations.version}</version>
|
||||
</dependency>{{/swagger2AnnotationLibrary}}{{/springDocDocumentationProvider}}{{/springFoxDocumentationProvider}}
|
||||
|
||||
<!-- @Nullable annotation -->
|
||||
<dependency>
|
||||
<groupId>com.google.code.findbugs</groupId>
|
||||
<artifactId>jsr305</artifactId>
|
||||
<version>${findbugs-jsr305.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||
</dependency>
|
||||
{{#hasAuthMethods}}
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-oauth2</artifactId>
|
||||
{{^parentOverridden}}
|
||||
<version>2.2.5.RELEASE</version>
|
||||
{{/parentOverridden}}
|
||||
</dependency>
|
||||
{{/hasAuthMethods}}
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||
<artifactId>jackson-dataformat-yaml</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||
<artifactId>jackson-dataformat-xml</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.module</groupId>
|
||||
<artifactId>jackson-module-kotlin</artifactId>
|
||||
</dependency>
|
||||
{{#useBeanValidation}}
|
||||
<!-- Bean Validation API support -->
|
||||
<dependency>
|
||||
<groupId>jakarta.validation</groupId>
|
||||
<artifactId>jakarta.validation-api</artifactId>
|
||||
</dependency>{{/useBeanValidation}}
|
||||
<dependency>
|
||||
<groupId>jakarta.annotation</groupId>
|
||||
<artifactId>jakarta.annotation-api</artifactId>
|
||||
<version>${jakarta-annotation.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-test-junit5</artifactId>
|
||||
<version>${kotlin-test-junit5.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,210 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>{{groupId}}</groupId>
|
||||
<artifactId>{{artifactId}}</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>{{artifactId}}</name>
|
||||
<version>{{artifactVersion}}</version>
|
||||
<properties>{{#reactive}}
|
||||
<kotlinx-coroutines.version>1.6.1</kotlinx-coroutines.version>{{/reactive}}{{#springDocDocumentationProvider}}{{#useSwaggerUI}}
|
||||
<springdoc-openapi.version>1.6.8</springdoc-openapi.version>{{/useSwaggerUI}}{{/springDocDocumentationProvider}}{{#springFoxDocumentationProvider}}
|
||||
<springfox-swagger2.version>2.9.2</springfox-swagger2.version>{{/springFoxDocumentationProvider}}{{#useSwaggerUI}}{{^springDocDocumentationProvider}}
|
||||
<swagger-ui.version>4.10.3</swagger-ui.version>{{/springDocDocumentationProvider}}{{/useSwaggerUI}}{{^springFoxDocumentationProvider}}{{^springDocDocumentationProvider}}{{#swagger1AnnotationLibrary}}
|
||||
<swagger-annotations.version>1.6.6</swagger-annotations.version>{{/swagger1AnnotationLibrary}}{{#swagger2AnnotationLibrary}}
|
||||
<swagger-annotations.version>2.2.0</swagger-annotations.version>{{/swagger2AnnotationLibrary}}{{/springDocDocumentationProvider}}{{/springFoxDocumentationProvider}}
|
||||
<findbugs-jsr305.version>3.0.2</findbugs-jsr305.version>
|
||||
<jakarta-annotation.version>2.1.0</jakarta-annotation.version>
|
||||
<kotlin-test-junit5.version>1.6.21</kotlin-test-junit5.version>
|
||||
|
||||
<kotlin.version>1.6.21</kotlin.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.6.7</version>
|
||||
</parent>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-parent</artifactId>
|
||||
<version>2021.0.5</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
<build>
|
||||
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
|
||||
<plugins>{{^interfaceOnly}}
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>{{/interfaceOnly}}
|
||||
<plugin>
|
||||
<artifactId>kotlin-maven-plugin</artifactId>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<version>${kotlin.version}</version>
|
||||
<configuration>
|
||||
<compilerPlugins>
|
||||
<plugin>spring</plugin>
|
||||
</compilerPlugins>
|
||||
<jvmTarget>1.8</jvmTarget>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>compile</id>
|
||||
<phase>compile</phase>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>test-compile</id>
|
||||
<phase>test-compile</phase>
|
||||
<goals>
|
||||
<goal>test-compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-maven-allopen</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib-jdk8</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-reflect</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
</dependency>{{^reactive}}
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>{{/reactive}}{{#reactive}}
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-webflux</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlinx</groupId>
|
||||
<artifactId>kotlinx-coroutines-core</artifactId>
|
||||
<version>${kotlinx-coroutines.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlinx</groupId>
|
||||
<artifactId>kotlinx-coroutines-reactor</artifactId>
|
||||
<version>${kotlinx-coroutines.version}</version>
|
||||
</dependency>{{/reactive}}
|
||||
|
||||
{{#springDocDocumentationProvider}}
|
||||
<!--SpringDoc dependencies -->{{#useSwaggerUI}}
|
||||
<dependency>
|
||||
<groupId>org.springdoc</groupId>
|
||||
<artifactId>springdoc-openapi-{{#reactive}}webflux-{{/reactive}}ui</artifactId>
|
||||
<version>${springdoc-openapi.version}</version>
|
||||
</dependency>{{/useSwaggerUI}}{{^useSwaggerUI}}
|
||||
<dependency>
|
||||
<groupId>org.springdoc</groupId>
|
||||
<artifactId>springdoc-openapi-{{#reactive}}webflux{{/reactive}}{{^reactive}}webmvc{{/reactive}}-core</artifactId>
|
||||
<version>${springdoc-openapi.version}</version>
|
||||
</dependency>{{/useSwaggerUI}}{{/springDocDocumentationProvider}}{{#springFoxDocumentationProvider}}
|
||||
<!--SpringFox dependencies -->
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger2</artifactId>
|
||||
<version>${springfox-swagger2.version}</version>
|
||||
</dependency>{{/springFoxDocumentationProvider}}{{#useSwaggerUI}}{{^springDocDocumentationProvider}}
|
||||
<dependency>
|
||||
<groupId>org.webjars</groupId>
|
||||
<artifactId>swagger-ui</artifactId>
|
||||
<version>${swagger-ui.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.webjars</groupId>
|
||||
<artifactId>webjars-locator-core</artifactId>
|
||||
</dependency>{{/springDocDocumentationProvider}}{{/useSwaggerUI}}{{^springFoxDocumentationProvider}}{{^springDocDocumentationProvider}}{{#swagger1AnnotationLibrary}}
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-annotations</artifactId>
|
||||
<version>${swagger-annotations.version}</version>
|
||||
</dependency>{{/swagger1AnnotationLibrary}}{{#swagger2AnnotationLibrary}}
|
||||
<dependency>
|
||||
<groupId>io.swagger.core.v3</groupId>
|
||||
<artifactId>swagger-annotations</artifactId>
|
||||
<version>${swagger-annotations.version}</version>
|
||||
</dependency>{{/swagger2AnnotationLibrary}}{{/springDocDocumentationProvider}}{{/springFoxDocumentationProvider}}
|
||||
|
||||
<!-- @Nullable annotation -->
|
||||
<dependency>
|
||||
<groupId>com.google.code.findbugs</groupId>
|
||||
<artifactId>jsr305</artifactId>
|
||||
<version>${findbugs-jsr305.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||
</dependency>
|
||||
{{#hasAuthMethods}}
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-oauth2</artifactId>
|
||||
{{^parentOverridden}}
|
||||
<version>2.2.5.RELEASE</version>
|
||||
{{/parentOverridden}}
|
||||
</dependency>
|
||||
{{/hasAuthMethods}}
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||
<artifactId>jackson-dataformat-yaml</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||
<artifactId>jackson-dataformat-xml</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.module</groupId>
|
||||
<artifactId>jackson-module-kotlin</artifactId>
|
||||
</dependency>
|
||||
{{#useBeanValidation}}
|
||||
<!-- Bean Validation API support -->
|
||||
<dependency>
|
||||
<groupId>jakarta.validation</groupId>
|
||||
<artifactId>jakarta.validation-api</artifactId>
|
||||
</dependency>{{/useBeanValidation}}
|
||||
<dependency>
|
||||
<groupId>jakarta.annotation</groupId>
|
||||
<artifactId>jakarta.annotation-api</artifactId>
|
||||
<version>${jakarta-annotation.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-test-junit5</artifactId>
|
||||
<version>${kotlin-test-junit5.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,15 @@
|
|||
pluginManagement {
|
||||
repositories {
|
||||
maven { url = uri("https://repo.spring.io/snapshot") }
|
||||
maven { url = uri("https://repo.spring.io/milestone") }
|
||||
gradlePluginPortal()
|
||||
}
|
||||
resolutionStrategy {
|
||||
eachPlugin {
|
||||
if (requested.id.id == "org.springframework.boot") {
|
||||
useModule("org.springframework.boot:spring-boot-gradle-plugin:${requested.version}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
rootProject.name = "{{artifactId}}"
|
|
@ -0,0 +1,28 @@
|
|||
{{^reactive}}
|
||||
{{#examples}}
|
||||
{{#-first}}
|
||||
{{#async}}
|
||||
return CompletableFuture.supplyAsync(()-> {
|
||||
{{/async}}getRequest().ifPresent { request ->
|
||||
{{#async}} {{/async}} for (mediaType in MediaType.parseMediaTypes(request.getHeader("Accept"))) {
|
||||
{{/-first}}
|
||||
{{#async}} {{/async}}{{^async}} {{/async}} if (mediaType.isCompatibleWith(MediaType.valueOf("{{{contentType}}}"))) {
|
||||
{{#async}} {{/async}}{{^async}} {{/async}} ApiUtil.setExampleResponse(request, "{{{contentType}}}", "{{#lambdaRemoveLineBreak}}{{#lambdaEscapeDoubleQuote}}{{{example}}}{{/lambdaEscapeDoubleQuote}}{{/lambdaRemoveLineBreak}}")
|
||||
{{#async}} {{/async}}{{^async}} {{/async}} break
|
||||
{{#async}} {{/async}}{{^async}} {{/async}} }
|
||||
{{#-last}}
|
||||
{{#async}} {{/async}}{{^async}} {{/async}} }
|
||||
{{#async}} {{/async}} }
|
||||
{{#async}} {{/async}} return ResponseEntity({{#returnSuccessCode}}HttpStatus.valueOf({{{statusCode}}}){{/returnSuccessCode}}{{^returnSuccessCode}}HttpStatus.NOT_IMPLEMENTED{{/returnSuccessCode}})
|
||||
{{#async}}
|
||||
}, Runnable::run)
|
||||
{{/async}}
|
||||
{{/-last}}
|
||||
{{/examples}}
|
||||
{{^examples}}
|
||||
return {{#async}}CompletableFuture.completedFuture({{/async}}ResponseEntity({{#returnSuccessCode}}HttpStatus.OK{{/returnSuccessCode}}{{^returnSuccessCode}}HttpStatus.NOT_IMPLEMENTED{{/returnSuccessCode}})
|
||||
{{/examples}}
|
||||
{{/reactive}}
|
||||
{{#reactive}}
|
||||
return ResponseEntity({{#returnSuccessCode}}HttpStatus.OK{{/returnSuccessCode}}{{^returnSuccessCode}}HttpStatus.NOT_IMPLEMENTED{{/returnSuccessCode}})
|
||||
{{/reactive}}
|
|
@ -0,0 +1,28 @@
|
|||
package {{package}}
|
||||
|
||||
import java.util.Objects
|
||||
{{#imports}}import {{import}}
|
||||
{{/imports}}
|
||||
{{#useBeanValidation}}
|
||||
import {{javaxPackage}}.validation.constraints.DecimalMax
|
||||
import {{javaxPackage}}.validation.constraints.DecimalMin
|
||||
import {{javaxPackage}}.validation.constraints.Email
|
||||
import {{javaxPackage}}.validation.constraints.Max
|
||||
import {{javaxPackage}}.validation.constraints.Min
|
||||
import {{javaxPackage}}.validation.constraints.NotNull
|
||||
import {{javaxPackage}}.validation.constraints.Pattern
|
||||
import {{javaxPackage}}.validation.constraints.Size
|
||||
import {{javaxPackage}}.validation.Valid
|
||||
{{/useBeanValidation}}
|
||||
{{#swagger2AnnotationLibrary}}
|
||||
import io.swagger.v3.oas.annotations.media.Schema
|
||||
{{/swagger2AnnotationLibrary}}
|
||||
{{#swagger1AnnotationLibrary}}
|
||||
import io.swagger.annotations.ApiModelProperty
|
||||
{{/swagger1AnnotationLibrary}}
|
||||
|
||||
{{#models}}
|
||||
{{#model}}
|
||||
{{#isEnum}}{{>enumClass}}{{/isEnum}}{{^isEnum}}{{>dataClass}}{{/isEnum}}
|
||||
{{/model}}
|
||||
{{/models}}
|
|
@ -0,0 +1 @@
|
|||
{{#modelMutable}}var{{/modelMutable}}{{^modelMutable}}val{{/modelMutable}}
|
|
@ -0,0 +1 @@
|
|||
{{{openapi-yaml}}}
|
|
@ -0,0 +1 @@
|
|||
{{#required}}{{{dataType}}}{{/required}}{{^required}}{{#defaultValue}}{{{dataType}}}{{/defaultValue}}{{^defaultValue}}{{{dataType}}}?{{/defaultValue}}{{/required}}
|
|
@ -0,0 +1 @@
|
|||
{{#isPathParam}}{{#useBeanValidation}}{{>beanValidationPathParams}}{{/useBeanValidation}}{{#swagger2AnnotationLibrary}}@Parameter(description = "{{{description}}}"{{#required}}, required = true{{/required}}{{#allowableValues}}{{#defaultValue}}, schema = Schema(allowableValues = [{{#enumVars}}"{{#lambdaEscapeDoubleQuote}}{{{value}}}{{/lambdaEscapeDoubleQuote}}"{{^-last}}, {{/-last}}{{/enumVars}}]{{^isContainer}}, defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{/isContainer}}{{/defaultValue}}{{/allowableValues}}{{#allowableValues}}{{^defaultValue}}, schema = Schema(allowableValues = [{{#enumVars}}"{{#lambdaEscapeDoubleQuote}}{{{value}}}{{/lambdaEscapeDoubleQuote}}"{{^-last}}, {{/-last}}{{/enumVars}}]){{/defaultValue}}{{/allowableValues}}{{^allowableValues}}{{#defaultValue}}{{^isContainer}}, schema = Schema(defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{/isContainer}}{{/defaultValue}}{{/allowableValues}}){{/swagger2AnnotationLibrary}}{{#swagger1AnnotationLibrary}}@ApiParam(value = "{{{description}}}"{{#required}}, required = true{{/required}}{{#allowableValues}}, allowableValues = "{{#enumVars}}{{#lambda.escapeDoubleQuote}}{{{value}}}{{/lambda.escapeDoubleQuote}}{{^-last}}, {{/-last}}{{/enumVars}}"{{/allowableValues}}{{#defaultValue}}, defaultValue = "{{{.}}}"{{/defaultValue}}){{/swagger1AnnotationLibrary}} @PathVariable("{{baseName}}") {{paramName}}: {{>optionalDataType}}{{/isPathParam}}
|
|
@ -0,0 +1 @@
|
|||
{{#isQueryParam}}{{#useBeanValidation}}{{>beanValidationQueryParams}}{{/useBeanValidation}}{{#swagger2AnnotationLibrary}}@Parameter(description = "{{{description}}}"{{#required}}, required = true{{/required}}{{#allowableValues}}{{#defaultValue}}, schema = Schema(allowableValues = [{{#values}}"{{{.}}}"{{^-last}}, {{/-last}}{{/values}}]{{^isContainer}}, defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{/isContainer}}){{/defaultValue}}{{/allowableValues}}{{#allowableValues}}{{^defaultValue}}, schema = Schema(allowableValues = [{{#values}}"{{{.}}}"{{^-last}}, {{/-last}}{{/values}}]){{/defaultValue}}{{/allowableValues}}{{^allowableValues}}{{#defaultValue}}{{^isContainer}}, schema = Schema(defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}){{/isContainer}}{{/defaultValue}}{{/allowableValues}}){{/swagger2AnnotationLibrary}}{{#swagger1AnnotationLibrary}}@ApiParam(value = "{{{description}}}"{{#required}}, required = true{{/required}}{{#allowableValues}}, allowableValues = "{{#values}}{{{.}}}{{^-last}}, {{/-last}}{{/values}}"{{/allowableValues}}{{^isContainer}}{{#defaultValue}}, defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{/defaultValue}}{{/isContainer}}){{/swagger1AnnotationLibrary}}{{#useBeanValidation}} @Valid{{/useBeanValidation}}{{^isModel}} @RequestParam(value = "{{baseName}}"{{#required}}, required = true{{/required}}{{^required}}, required = false{{/required}}{{^isContainer}}{{#defaultValue}}, defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{/defaultValue}}{{/isContainer}}){{/isModel}}{{#isDate}} @org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE){{/isDate}}{{#isDateTime}} @org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE_TIME){{/isDateTime}} {{paramName}}: {{>optionalDataType}}{{/isQueryParam}}
|
|
@ -0,0 +1 @@
|
|||
{{#isMap}}Map<String, {{{returnType}}}>{{/isMap}}{{#isArray}}{{#reactive}}Flow{{/reactive}}{{^reactive}}{{{returnContainer}}}{{/reactive}}<{{{returnType}}}>{{/isArray}}{{^returnContainer}}{{{returnType}}}{{/returnContainer}}
|
|
@ -0,0 +1 @@
|
|||
{{#serviceInterface}}ResponseEntity(service.{{operationId}}({{#allParams}}{{{paramName}}}{{^-last}}, {{/-last}}{{/allParams}}), {{#responses}}{{#-first}}HttpStatus.valueOf({{code}}){{/-first}}{{/responses}}){{/serviceInterface}}{{^serviceInterface}}ResponseEntity(HttpStatus.NOT_IMPLEMENTED){{/serviceInterface}}
|
|
@ -0,0 +1,36 @@
|
|||
package {{package}}
|
||||
|
||||
{{#imports}}import {{import}}
|
||||
{{/imports}}
|
||||
{{#reactive}}
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
{{/reactive}}
|
||||
|
||||
{{#operations}}
|
||||
interface {{classname}}Service {
|
||||
{{#operation}}
|
||||
|
||||
/**
|
||||
* {{httpMethod}} {{{path}}}{{#summary}} : {{.}}{{/summary}}
|
||||
{{#notes}}
|
||||
* {{.}}
|
||||
{{/notes}}
|
||||
*
|
||||
{{#allParams}}
|
||||
* @param {{{paramName}}} {{description}}{{#required}} (required){{/required}}{{^required}} (optional{{#defaultValue}}, default to {{.}}{{/defaultValue}}){{/required}}
|
||||
{{/allParams}}
|
||||
* @return {{#responses}}{{message}} (status code {{code}}){{^-last}}
|
||||
* or {{/-last}}{{/responses}}
|
||||
{{#isDeprecated}}
|
||||
* @deprecated
|
||||
{{/isDeprecated}}
|
||||
{{#externalDocs}}
|
||||
* {{description}}
|
||||
* @see <a href="{{url}}">{{summary}} Documentation</a>
|
||||
{{/externalDocs}}
|
||||
* @see {{classname}}#{{operationId}}
|
||||
*/
|
||||
{{#reactive}}{{^isArray}}suspend {{/isArray}}{{/reactive}}fun {{operationId}}({{#allParams}}{{{paramName}}}: {{^isBodyParam}}{{>optionalDataType}}{{/isBodyParam}}{{#isBodyParam}}{{^reactive}}{{>optionalDataType}}{{/reactive}}{{#reactive}}{{^isArray}}{{>optionalDataType}}{{/isArray}}{{#isArray}}Flow<{{{baseType}}}>{{/isArray}}{{/reactive}}{{/isBodyParam}}{{^-last}}, {{/-last}}{{/allParams}}): {{>returnTypes}}
|
||||
{{/operation}}
|
||||
}
|
||||
{{/operations}}
|
|
@ -0,0 +1,19 @@
|
|||
package {{package}}
|
||||
|
||||
{{#imports}}import {{import}}
|
||||
{{/imports}}
|
||||
{{#reactive}}
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
{{/reactive}}
|
||||
import org.springframework.stereotype.Service
|
||||
@Service
|
||||
{{#operations}}
|
||||
class {{classname}}ServiceImpl : {{classname}}Service {
|
||||
{{#operation}}
|
||||
|
||||
override {{#reactive}}{{^isArray}}suspend {{/isArray}}{{/reactive}}fun {{operationId}}({{#allParams}}{{paramName}}: {{^isBodyParam}}{{>optionalDataType}}{{/isBodyParam}}{{#isBodyParam}}{{^reactive}}{{>optionalDataType}}{{/reactive}}{{#reactive}}{{^isArray}}{{>optionalDataType}}{{/isArray}}{{#isArray}}Flow<{{{baseType}}}>{{/isArray}}{{/reactive}}{{/isBodyParam}}{{^-last}}, {{/-last}}{{/allParams}}): {{>returnTypes}} {
|
||||
TODO("Implement me")
|
||||
}
|
||||
{{/operation}}
|
||||
}
|
||||
{{/operations}}
|
|
@ -0,0 +1,53 @@
|
|||
package {{basePackage}}
|
||||
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.Configuration
|
||||
|
||||
import io.swagger.v3.oas.models.OpenAPI
|
||||
import io.swagger.v3.oas.models.info.Info
|
||||
import io.swagger.v3.oas.models.info.Contact
|
||||
import io.swagger.v3.oas.models.info.License
|
||||
import io.swagger.v3.oas.models.Components
|
||||
import io.swagger.v3.oas.models.security.SecurityScheme
|
||||
|
||||
@Configuration
|
||||
class SpringDocConfiguration {
|
||||
|
||||
@Bean
|
||||
fun apiInfo(): OpenAPI {
|
||||
return OpenAPI()
|
||||
.info(
|
||||
Info(){{#appName}}
|
||||
.title("{{appName}}"){{/appName}}
|
||||
.description("{{{appDescription}}}"){{#termsOfService}}
|
||||
.termsOfService("{{termsOfService}}"){{/termsOfService}}{{#openAPI}}{{#info}}{{#contact}}
|
||||
.contact(
|
||||
Contact(){{#infoName}}
|
||||
.name("{{infoName}}"){{/infoName}}{{#infoUrl}}
|
||||
.url("{{infoUrl}}"){{/infoUrl}}{{#infoEmail}}
|
||||
.email("{{infoEmail}}"){{/infoEmail}}
|
||||
){{/contact}}{{#license}}
|
||||
.license(
|
||||
License()
|
||||
{{#licenseInfo}}.name("{{licenseInfo}}")
|
||||
{{/licenseInfo}}{{#licenseUrl}}.url("{{licenseUrl}}")
|
||||
{{/licenseUrl}}
|
||||
){{/license}}{{/info}}{{/openAPI}}
|
||||
.version("{{appVersion}}")
|
||||
){{#hasAuthMethods}}
|
||||
.components(
|
||||
Components(){{#authMethods}}
|
||||
.addSecuritySchemes("{{name}}", SecurityScheme(){{#isBasic}}
|
||||
.type(SecurityScheme.Type.HTTP)
|
||||
.scheme("{{scheme}}"){{#bearerFormat}}
|
||||
.bearerFormat("{{bearerFormat}}"){{/bearerFormat}}{{/isBasic}}{{#isApiKey}}
|
||||
.type(SecurityScheme.Type.APIKEY){{#isKeyInHeader}}
|
||||
.`in`(SecurityScheme.In.HEADER){{/isKeyInHeader}}{{#isKeyInQuery}}
|
||||
.`in`(SecurityScheme.In.QUERY){{/isKeyInQuery}}{{#isKeyInCookie}}
|
||||
.`in`(SecurityScheme.In.COOKIE){{/isKeyInCookie}}
|
||||
.name("{{keyParamName}}"){{/isApiKey}}{{#isOAuth}}
|
||||
.type(SecurityScheme.Type.OAUTH2){{/isOAuth}}
|
||||
){{/authMethods}}
|
||||
){{/hasAuthMethods}}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
package {{basePackage}}
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.Configuration
|
||||
import org.springframework.web.util.UriComponentsBuilder
|
||||
import springfox.documentation.builders.ApiInfoBuilder
|
||||
import springfox.documentation.builders.RequestHandlerSelectors
|
||||
import springfox.documentation.service.ApiInfo
|
||||
import springfox.documentation.service.Contact
|
||||
import springfox.documentation.spi.DocumentationType
|
||||
import springfox.documentation.spring.web.paths.Paths
|
||||
import springfox.documentation.spring.web.paths.RelativePathProvider
|
||||
import springfox.documentation.spring.web.plugins.Docket
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2
|
||||
import {{javaxPackage}}.servlet.ServletContext
|
||||
|
||||
|
||||
{{>generatedAnnotation}}
|
||||
@Configuration
|
||||
@EnableSwagger2
|
||||
class SpringFoxConfiguration {
|
||||
|
||||
fun apiInfo(): ApiInfo {
|
||||
return ApiInfoBuilder()
|
||||
.title("{{appName}}")
|
||||
.description("{{{appDescription}}}")
|
||||
.license("{{licenseInfo}}")
|
||||
.licenseUrl("{{licenseUrl}}")
|
||||
.termsOfServiceUrl("{{infoUrl}}")
|
||||
.version("{{appVersion}}")
|
||||
.contact(Contact("", "", "{{infoEmail}}"))
|
||||
.build()
|
||||
}
|
||||
|
||||
@Bean
|
||||
{{=<% %>=}}
|
||||
fun customImplementation(servletContext: ServletContext, @Value("\${openapi.<%title%>.base-path:<%>defaultBasePath%>}") basePath: String): Docket {
|
||||
<%={{ }}=%>
|
||||
return Docket(DocumentationType.SWAGGER_2)
|
||||
.select()
|
||||
.apis(RequestHandlerSelectors.basePackage("{{apiPackage}}"))
|
||||
.build()
|
||||
.pathProvider(BasePathAwareRelativePathProvider(servletContext, basePath))
|
||||
.directModelSubstitute(java.time.LocalDate::class.java, java.sql.Date::class.java)
|
||||
.directModelSubstitute(java.time.OffsetDateTime::class.java, java.util.Date::class.java)
|
||||
.apiInfo(apiInfo())
|
||||
}
|
||||
|
||||
class BasePathAwareRelativePathProvider(servletContext: ServletContext, private val basePath: String) :
|
||||
RelativePathProvider(servletContext) {
|
||||
|
||||
override fun applicationPath(): String {
|
||||
return Paths.removeAdjacentForwardSlashes(
|
||||
UriComponentsBuilder.fromPath(super.applicationPath()).path(basePath).build().toString()
|
||||
)
|
||||
}
|
||||
|
||||
override fun getOperationPath(operationPath: String): String {
|
||||
val uriComponentsBuilder = UriComponentsBuilder.fromPath("/")
|
||||
return Paths.removeAdjacentForwardSlashes(
|
||||
uriComponentsBuilder.path(operationPath.replaceFirst("^$basePath", "")).build().toString()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
{{#jackson}}
|
||||
|
||||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "{{{discriminator.propertyBaseName}}}", visible = true)
|
||||
@JsonSubTypes(
|
||||
{{#discriminator.mappedModels}}
|
||||
JsonSubTypes.Type(value = {{modelName}}::class, name = "{{^vendorExtensions.x-discriminator-value}}{{mappingName}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{vendorExtensions.x-discriminator-value}}}{{/vendorExtensions.x-discriminator-value}}"){{^-last}},{{/-last}}
|
||||
{{/discriminator.mappedModels}}
|
||||
){{/jackson}}
|
Loading…
Reference in New Issue