mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-05-12 12:40:53 +00:00
[kotlin-server][javalin6] Add Javalin 6 support (#18928)
* [kotlin-server][javalin6] Add Javalin 6 support Javalin 5 support was added in 13edc5d. Javalin 6 has been released, with some breaking changes. Let's add a new supportedLibrary to not break existing users of Javalin 5. https://javalin.io/migration-guide-javalin-5-to-6 * Fix Gradle config and don't include JVM 8 CI anymore (JVM 11 is the minimum for Javalin) * Update docs * Fix optional query parameter handling and turn into expected type
This commit is contained in:
parent
c806ea51b3
commit
793aba724a
@ -1,16 +1,18 @@
|
||||
name: Samples Kotlin server
|
||||
name: Samples Kotlin server (jdk17)
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- 'samples/server/petstore/kotlin-springboot-3*/**'
|
||||
- 'samples/server/petstore/kotlin-server/javalin/**'
|
||||
- 'samples/server/petstore/kotlin-server/javalin-6/**'
|
||||
# comment out due to gradle build failure
|
||||
# - samples/server/petstore/kotlin-spring-default/**
|
||||
pull_request:
|
||||
paths:
|
||||
- 'samples/server/petstore/kotlin-springboot-3*/**'
|
||||
- 'samples/server/petstore/kotlin-server/javalin/**'
|
||||
- 'samples/server/petstore/kotlin-server/javalin-6/**'
|
||||
# comment out due to gradle build failure
|
||||
# - samples/server/petstore/kotlin-spring-default/**
|
||||
|
||||
@ -30,6 +32,7 @@ jobs:
|
||||
- samples/server/petstore/kotlin-springboot-request
|
||||
- samples/server/petstore/kotlin-springboot-request-cookie
|
||||
- samples/server/petstore/kotlin-server/javalin
|
||||
- samples/server/petstore/kotlin-server/javalin-6
|
||||
# comment out due to gradle build failure
|
||||
# - samples/server/petstore/kotlin-spring-default/
|
||||
steps:
|
||||
|
45
.github/workflows/samples-kotlin-server-jdk21.yaml
vendored
Normal file
45
.github/workflows/samples-kotlin-server-jdk21.yaml
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
name: Samples Kotlin server (jdk21)
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- 'samples/server/petstore/kotlin-server/javalin-6/**'
|
||||
pull_request:
|
||||
paths:
|
||||
- 'samples/server/petstore/kotlin-server/javalin-6/**'
|
||||
|
||||
env:
|
||||
GRADLE_VERSION: 8.8
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Build Kotlin server
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
sample:
|
||||
- samples/server/petstore/kotlin-server/javalin-6
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-java@v4
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: 21
|
||||
- name: Cache maven dependencies
|
||||
uses: actions/cache@v4
|
||||
env:
|
||||
cache-name: maven-repository
|
||||
with:
|
||||
path: |
|
||||
~/.gradle
|
||||
key: ${{ runner.os }}-${{ github.job }}-${{ env.cache-name }}-${{ hashFiles('**/pom.xml') }}
|
||||
- name: Install Gradle wrapper
|
||||
uses: eskatos/gradle-command-action@v3
|
||||
with:
|
||||
gradle-version: ${{ env.GRADLE_VERSION }}
|
||||
build-root-directory: ${{ matrix.sample }}
|
||||
arguments: wrapper
|
||||
- name: Build
|
||||
working-directory: ${{ matrix.sample }}
|
||||
run: ./gradlew build -x test
|
7
bin/configs/kotlin-server-javalin-6.yaml
Normal file
7
bin/configs/kotlin-server-javalin-6.yaml
Normal file
@ -0,0 +1,7 @@
|
||||
generatorName: kotlin-server
|
||||
outputDir: samples/server/petstore/kotlin-server/javalin-6
|
||||
library: javalin6
|
||||
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml
|
||||
templateDir: modules/openapi-generator/src/main/resources/kotlin-server
|
||||
additionalProperties:
|
||||
hideGenerationTimestamp: "true"
|
@ -32,7 +32,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|featureResources|Generates routes in a typed way, for both: constructing URLs and reading the parameters.| |true|
|
||||
|groupId|Generated artifact package's organization (i.e. maven groupId).| |org.openapitools|
|
||||
|interfaceOnly|Whether to generate only API interface stubs without the server files. This option is currently supported only when using jaxrs-spec library.| |false|
|
||||
|library|library template (sub-template)|<dl><dt>**ktor**</dt><dd>ktor framework</dd><dt>**jaxrs-spec**</dt><dd>JAX-RS spec only</dd><dt>**javalin5**</dt><dd>Javalin 5</dd></dl>|ktor|
|
||||
|library|library template (sub-template)|<dl><dt>**ktor**</dt><dd>ktor framework</dd><dt>**jaxrs-spec**</dt><dd>JAX-RS spec only</dd><dt>**javalin5**</dt><dd>Javalin 5</dd><dt>**javalin6**</dt><dd>Javalin 6</dd></dl>|ktor|
|
||||
|modelMutable|Create mutable models| |false|
|
||||
|omitGradleWrapper|Whether to omit Gradle wrapper for creating a sub project.| |false|
|
||||
|packageName|Generated artifact package name.| |org.openapitools.server|
|
||||
|
@ -27,6 +27,7 @@ import org.openapitools.codegen.meta.features.*;
|
||||
import org.openapitools.codegen.model.ModelMap;
|
||||
import org.openapitools.codegen.model.OperationMap;
|
||||
import org.openapitools.codegen.model.OperationsMap;
|
||||
import org.openapitools.codegen.templating.mustache.CamelCaseLambda;
|
||||
import org.openapitools.codegen.templating.mustache.LowercaseLambda;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -128,6 +129,7 @@ public class KotlinServerCodegen extends AbstractKotlinCodegen implements BeanVa
|
||||
supportedLibraries.put(Constants.KTOR, "ktor framework");
|
||||
supportedLibraries.put(Constants.JAXRS_SPEC, "JAX-RS spec only");
|
||||
supportedLibraries.put(Constants.JAVALIN5, "Javalin 5");
|
||||
supportedLibraries.put(Constants.JAVALIN6, "Javalin 6");
|
||||
|
||||
// TODO: Configurable server engine. Defaults to netty in build.gradle.
|
||||
addOption(CodegenConstants.LIBRARY, CodegenConstants.LIBRARY_DESC, DEFAULT_LIBRARY, supportedLibraries);
|
||||
@ -276,7 +278,7 @@ public class KotlinServerCodegen extends AbstractKotlinCodegen implements BeanVa
|
||||
|
||||
String gradleBuildFile = "build.gradle";
|
||||
|
||||
if (library.equals(Constants.JAVALIN5)) {
|
||||
if (isJavalin()) {
|
||||
gradleBuildFile = "build.gradle.kts";
|
||||
}
|
||||
|
||||
@ -298,11 +300,12 @@ public class KotlinServerCodegen extends AbstractKotlinCodegen implements BeanVa
|
||||
final String infrastructureFolder = (sourceFolder + File.separator + packageName + File.separator + "infrastructure").replace(".", File.separator);
|
||||
|
||||
supportingFiles.add(new SupportingFile("ApiKeyAuth.kt.mustache", infrastructureFolder, "ApiKeyAuth.kt"));
|
||||
} else if (library.equals(Constants.JAVALIN5)) {
|
||||
} else if (isJavalin()) {
|
||||
supportingFiles.add(new SupportingFile("Main.kt.mustache", packageFolder, "Main.kt"));
|
||||
apiTemplateFiles.put("service.mustache", "Service.kt");
|
||||
apiTemplateFiles.put("serviceImpl.mustache", "ServiceImpl.kt");
|
||||
additionalProperties.put("lowercase", new LowercaseLambda());
|
||||
additionalProperties.put("camelcase", new CamelCaseLambda());
|
||||
typeMapping.put("file", "io.javalin.http.UploadedFile");
|
||||
importMapping.put("io.javalin.http.UploadedFile", "io.javalin.http.UploadedFile");
|
||||
}
|
||||
@ -318,6 +321,7 @@ public class KotlinServerCodegen extends AbstractKotlinCodegen implements BeanVa
|
||||
public final static String JAXRS_SPEC = "jaxrs-spec";
|
||||
|
||||
public final static String JAVALIN5 = "javalin5";
|
||||
public final static String JAVALIN6 = "javalin6";
|
||||
public final static String AUTOMATIC_HEAD_REQUESTS = "featureAutoHead";
|
||||
public final static String AUTOMATIC_HEAD_REQUESTS_DESC = "Automatically provide responses to HEAD requests for existing routes that have the GET verb defined.";
|
||||
public final static String CONDITIONAL_HEADERS = "featureConditionalHeaders";
|
||||
@ -404,4 +408,8 @@ public class KotlinServerCodegen extends AbstractKotlinCodegen implements BeanVa
|
||||
|
||||
return objs;
|
||||
}
|
||||
|
||||
private boolean isJavalin() {
|
||||
return Constants.JAVALIN5.equals(library) || Constants.JAVALIN6.equals(library);
|
||||
}
|
||||
}
|
||||
|
36
modules/openapi-generator/src/main/resources/kotlin-server/libraries/javalin6/Main.kt.mustache
vendored
Normal file
36
modules/openapi-generator/src/main/resources/kotlin-server/libraries/javalin6/Main.kt.mustache
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
package {{packageName}}
|
||||
|
||||
import io.javalin.Javalin
|
||||
import io.javalin.apibuilder.ApiBuilder.*
|
||||
|
||||
{{#apiInfo}}
|
||||
{{#apis}}
|
||||
{{#operations}}import {{apiPackage}}.{{classname}}
|
||||
import {{apiPackage}}.{{classname}}ServiceImpl
|
||||
{{/operations}}
|
||||
{{/apis}}
|
||||
|
||||
fun main() {
|
||||
{{#apis}}
|
||||
{{#operations}}
|
||||
val {{#camelcase}}{{classname}}{{/camelcase}} = {{classname}}({{classname}}ServiceImpl())
|
||||
{{/operations}}
|
||||
{{/apis}}
|
||||
|
||||
val app = Javalin
|
||||
.create { config ->
|
||||
config.router.apiBuilder {
|
||||
{{#apis}}
|
||||
{{#operations}}
|
||||
{{#operation}}
|
||||
path("{{path}}") { {{#lowercase}}{{httpMethod}}{{/lowercase}}({{#camelcase}}{{classname}}{{/camelcase}}::{{operationId}}) }
|
||||
{{/operation}}
|
||||
{{/operations}}
|
||||
|
||||
{{/apis}}
|
||||
}
|
||||
}
|
||||
|
||||
app.start({{serverPort}})
|
||||
}
|
||||
{{/apiInfo}}
|
94
modules/openapi-generator/src/main/resources/kotlin-server/libraries/javalin6/README.mustache
vendored
Normal file
94
modules/openapi-generator/src/main/resources/kotlin-server/libraries/javalin6/README.mustache
vendored
Normal file
@ -0,0 +1,94 @@
|
||||
# {{packageName}} - Kotlin Server library for {{appName}}
|
||||
|
||||
{{#unescapedAppDescription}}
|
||||
{{.}}
|
||||
{{/unescapedAppDescription}}
|
||||
|
||||
Generated by OpenAPI Generator {{generatorVersion}}{{^hideGenerationTimestamp}} ({{generatedDate}}){{/hideGenerationTimestamp}}.
|
||||
|
||||
## Build
|
||||
|
||||
First, create the gradle wrapper script:
|
||||
|
||||
```
|
||||
gradle wrapper
|
||||
```
|
||||
|
||||
Then, run:
|
||||
|
||||
```
|
||||
./gradlew check assemble
|
||||
```
|
||||
|
||||
This runs all tests and packages the library.
|
||||
|
||||
## Running
|
||||
|
||||
The server builds as a fat jar with a main entrypoint. To start the service, run `java -jar ./build/libs/{{artifactId}}.jar`.
|
||||
|
||||
You may also run in docker:
|
||||
|
||||
```
|
||||
docker build -t {{artifactId}} .
|
||||
docker run -p 8080:8080 {{artifactId}}
|
||||
```
|
||||
|
||||
## Features/Implementation Notes
|
||||
|
||||
* Supports JSON inputs/outputs, File inputs, and Form inputs (see ktor documentation for more info).
|
||||
* ~Supports collection formats for query parameters: csv, tsv, ssv, pipes.~
|
||||
* Some Kotlin and Java types are fully qualified to avoid conflicts with types defined in OpenAPI definitions.
|
||||
|
||||
{{#generateApiDocs}}
|
||||
<a id="documentation-for-api-endpoints"></a>
|
||||
## Documentation for API Endpoints
|
||||
|
||||
All URIs are relative to *{{{basePath}}}*
|
||||
|
||||
Class | Method | HTTP request | Description
|
||||
------------ | ------------- | ------------- | -------------
|
||||
{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}*{{classname}}* | [**{{operationId}}**]({{apiDocPath}}{{classname}}.md#{{operationIdLowerCase}}) | **{{httpMethod}}** {{path}} | {{{summary}}}
|
||||
{{/operation}}{{/operations}}{{/apis}}{{/apiInfo}}
|
||||
{{/generateApiDocs}}
|
||||
|
||||
{{#generateModelDocs}}
|
||||
<a id="documentation-for-models"></a>
|
||||
## Documentation for Models
|
||||
|
||||
{{#modelPackage}}
|
||||
{{#models}}{{#model}} - [{{{modelPackage}}}.{{{classname}}}]({{modelDocPath}}{{{classname}}}.md)
|
||||
{{/model}}{{/models}}
|
||||
{{/modelPackage}}
|
||||
{{^modelPackage}}
|
||||
No model defined in this package
|
||||
{{/modelPackage}}
|
||||
{{/generateModelDocs}}
|
||||
|
||||
<a id="documentation-for-authorization"></a>
|
||||
## Documentation for Authorization
|
||||
|
||||
{{^authMethods}}Endpoints do not require authorization.{{/authMethods}}
|
||||
{{#hasAuthMethods}}Authentication schemes defined for the API:{{/hasAuthMethods}}
|
||||
{{#authMethods}}
|
||||
<a id="{{name}}"></a>
|
||||
### {{name}}
|
||||
|
||||
{{#isApiKey}}- **Type**: API key
|
||||
- **API key parameter name**: {{keyParamName}}
|
||||
- **Location**: {{#isKeyInQuery}}URL query string{{/isKeyInQuery}}{{#isKeyInHeader}}HTTP header{{/isKeyInHeader}}
|
||||
{{/isApiKey}}
|
||||
{{#isBasicBasic}}- **Type**: HTTP basic authentication
|
||||
{{/isBasicBasic}}
|
||||
{{#isBasicBearer}}- **Type**: HTTP Bearer Token authentication{{#bearerFormat}} ({{{.}}}){{/bearerFormat}}
|
||||
{{/isBasicBearer}}
|
||||
{{#isHttpSignature}}- **Type**: HTTP signature authentication
|
||||
{{/isHttpSignature}}
|
||||
{{#isOAuth}}- **Type**: OAuth
|
||||
- **Flow**: {{flow}}
|
||||
- **Authorization URL**: {{authorizationUrl}}
|
||||
- **Scopes**: {{^scopes}}N/A{{/scopes}}
|
||||
{{#scopes}} - {{scope}}: {{description}}
|
||||
{{/scopes}}
|
||||
{{/isOAuth}}
|
||||
|
||||
{{/authMethods}}
|
26
modules/openapi-generator/src/main/resources/kotlin-server/libraries/javalin6/api.mustache
vendored
Normal file
26
modules/openapi-generator/src/main/resources/kotlin-server/libraries/javalin6/api.mustache
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
package {{apiPackage}}
|
||||
|
||||
import io.javalin.http.Context
|
||||
import io.javalin.http.bodyAsClass
|
||||
import io.javalin.http.pathParamAsClass
|
||||
import io.javalin.http.queryParamAsClass
|
||||
|
||||
{{#imports}}import {{import}}
|
||||
{{/imports}}
|
||||
|
||||
{{#operations}}
|
||||
class {{classname}}(private val service: {{classname}}Service) {
|
||||
{{#operation}}
|
||||
/**{{#summary}}
|
||||
* {{.}}{{/summary}}
|
||||
* {{unescapedNotes}}
|
||||
{{#allParams}}* @param {{paramName}} {{description}} {{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}
|
||||
{{/allParams}}*/
|
||||
fun {{operationId}}(ctx: Context) {
|
||||
val result = service.{{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{^-last}}, {{/-last}}{{/allParams}}{{#hasParams}}, {{/hasParams}}ctx)
|
||||
ctx.status({{#responses}}{{#-first}}{{code}}{{/-first}}{{/responses}}).json(result)
|
||||
}
|
||||
|
||||
{{/operation}}
|
||||
}
|
||||
{{/operations}}
|
@ -0,0 +1 @@
|
||||
{{#isBodyParam}}{{#isArray}}ctx.bodyAsClass<List<{{{baseType}}}>>(){{/isArray}}{{^isArray}}ctx.bodyAsClass<{{{baseType}}}>(){{/isArray}}{{/isBodyParam}}
|
@ -0,0 +1,33 @@
|
||||
plugins {
|
||||
kotlin("jvm") version "2.0.0"
|
||||
}
|
||||
|
||||
group = "{{groupId}}"
|
||||
version = "{{artifactVersion}}"
|
||||
|
||||
kotlin {
|
||||
jvmToolchain(21)
|
||||
}
|
||||
|
||||
java {
|
||||
toolchain {
|
||||
languageVersion.set(JavaLanguageVersion.of(21))
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("io.javalin:javalin:6.1.6")
|
||||
implementation("com.fasterxml.jackson.core:jackson-databind:2.17.1")
|
||||
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.17.1")
|
||||
implementation("org.slf4j:slf4j-simple:2.0.13")
|
||||
|
||||
testImplementation("org.jetbrains.kotlin:kotlin-test")
|
||||
}
|
||||
|
||||
tasks.test {
|
||||
useJUnitPlatform()
|
||||
}
|
@ -0,0 +1 @@
|
||||
{{#isFormParam}}{{^isFile}}ctx.formParam("{{baseName}}"){{/isFile}}{{#isFile}}ctx.uploadedFile("{{baseName}}"){{/isFile}}{{/isFormParam}}
|
@ -0,0 +1 @@
|
||||
org.gradle.caching=true
|
@ -0,0 +1 @@
|
||||
{{#isHeaderParam}}ctx.header("{{baseName}}"){{/isHeaderParam}}
|
@ -0,0 +1 @@
|
||||
{{#required}}{{{dataType}}}{{/required}}{{^required}}{{#defaultValue}}{{{dataType}}}{{/defaultValue}}{{^defaultValue}}{{{dataType}}}?{{/defaultValue}}{{/required}}
|
@ -0,0 +1 @@
|
||||
{{#isPathParam}}ctx.pathParamAsClass<{{{dataType}}}>("{{baseName}}").get(){{/isPathParam}}
|
@ -0,0 +1 @@
|
||||
{{#isQueryParam}}{{#isArray}}ctx.queryParams("{{baseName}}"){{/isArray}}{{^isArray}}ctx.queryParamAsClass<{{{dataType}}}>("{{baseName}}"){{^required}}.allowNullable(){{/required}}.get(){{/isArray}}{{/isQueryParam}}
|
@ -0,0 +1 @@
|
||||
{{#isMap}}Map<String, {{{returnType}}}>{{/isMap}}{{#isArray}}{{#reactive}}Flow{{/reactive}}{{^reactive}}{{{returnContainer}}}{{/reactive}}<{{{returnType}}}>{{/isArray}}{{^returnContainer}}{{{returnType}}}{{/returnContainer}}
|
35
modules/openapi-generator/src/main/resources/kotlin-server/libraries/javalin6/service.mustache
vendored
Normal file
35
modules/openapi-generator/src/main/resources/kotlin-server/libraries/javalin6/service.mustache
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
package {{package}}
|
||||
|
||||
{{#imports}}import {{import}}
|
||||
{{/imports}}
|
||||
import io.javalin.http.Context
|
||||
|
||||
{{#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}}
|
||||
* @param ctx The Javalin context. Especially handy if you need to access things like authentication headers in your service. (required)
|
||||
* @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}}{{#hasParams}}, {{/hasParams}}ctx: Context): {{>returnTypes}}
|
||||
{{/operation}}
|
||||
}
|
||||
{{/operations}}
|
@ -0,0 +1,19 @@
|
||||
package {{package}}
|
||||
|
||||
{{#imports}}import {{import}}
|
||||
{{/imports}}
|
||||
import io.javalin.http.Context
|
||||
{{#reactive}}
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
{{/reactive}}
|
||||
{{#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}}{{#hasParams}}, {{/hasParams}}ctx: Context): {{>returnTypes}} {
|
||||
TODO("Implement me")
|
||||
}
|
||||
{{/operation}}
|
||||
}
|
||||
{{/operations}}
|
@ -0,0 +1,23 @@
|
||||
# OpenAPI Generator Ignore
|
||||
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
|
||||
|
||||
# Use this file to prevent files from being overwritten by the generator.
|
||||
# The patterns follow closely to .gitignore or .dockerignore.
|
||||
|
||||
# As an example, the C# client generator defines ApiClient.cs.
|
||||
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
|
||||
#ApiClient.cs
|
||||
|
||||
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
|
||||
#foo/*/qux
|
||||
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
|
||||
|
||||
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
|
||||
#foo/**/qux
|
||||
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
|
||||
|
||||
# You can also negate patterns with an exclamation (!).
|
||||
# For example, you can ignore all files in a docs folder with the file extension .md:
|
||||
#docs/*.md
|
||||
# Then explicitly reverse the ignore rule for a single file:
|
||||
#!docs/README.md
|
@ -0,0 +1,20 @@
|
||||
README.md
|
||||
build.gradle.kts
|
||||
gradle.properties
|
||||
settings.gradle
|
||||
src/main/kotlin/org/openapitools/server/Main.kt
|
||||
src/main/kotlin/org/openapitools/server/apis/PetApi.kt
|
||||
src/main/kotlin/org/openapitools/server/apis/PetApiService.kt
|
||||
src/main/kotlin/org/openapitools/server/apis/PetApiServiceImpl.kt
|
||||
src/main/kotlin/org/openapitools/server/apis/StoreApi.kt
|
||||
src/main/kotlin/org/openapitools/server/apis/StoreApiService.kt
|
||||
src/main/kotlin/org/openapitools/server/apis/StoreApiServiceImpl.kt
|
||||
src/main/kotlin/org/openapitools/server/apis/UserApi.kt
|
||||
src/main/kotlin/org/openapitools/server/apis/UserApiService.kt
|
||||
src/main/kotlin/org/openapitools/server/apis/UserApiServiceImpl.kt
|
||||
src/main/kotlin/org/openapitools/server/models/Category.kt
|
||||
src/main/kotlin/org/openapitools/server/models/ModelApiResponse.kt
|
||||
src/main/kotlin/org/openapitools/server/models/Order.kt
|
||||
src/main/kotlin/org/openapitools/server/models/Pet.kt
|
||||
src/main/kotlin/org/openapitools/server/models/Tag.kt
|
||||
src/main/kotlin/org/openapitools/server/models/User.kt
|
@ -0,0 +1 @@
|
||||
7.7.0-SNAPSHOT
|
101
samples/server/petstore/kotlin-server/javalin-6/README.md
Normal file
101
samples/server/petstore/kotlin-server/javalin-6/README.md
Normal file
@ -0,0 +1,101 @@
|
||||
# org.openapitools.server - Kotlin Server library for OpenAPI Petstore
|
||||
|
||||
This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
|
||||
Generated by OpenAPI Generator 7.7.0-SNAPSHOT.
|
||||
|
||||
## Build
|
||||
|
||||
First, create the gradle wrapper script:
|
||||
|
||||
```
|
||||
gradle wrapper
|
||||
```
|
||||
|
||||
Then, run:
|
||||
|
||||
```
|
||||
./gradlew check assemble
|
||||
```
|
||||
|
||||
This runs all tests and packages the library.
|
||||
|
||||
## Running
|
||||
|
||||
The server builds as a fat jar with a main entrypoint. To start the service, run `java -jar ./build/libs/kotlin-server.jar`.
|
||||
|
||||
You may also run in docker:
|
||||
|
||||
```
|
||||
docker build -t kotlin-server .
|
||||
docker run -p 8080:8080 kotlin-server
|
||||
```
|
||||
|
||||
## Features/Implementation Notes
|
||||
|
||||
* Supports JSON inputs/outputs, File inputs, and Form inputs (see ktor documentation for more info).
|
||||
* ~Supports collection formats for query parameters: csv, tsv, ssv, pipes.~
|
||||
* Some Kotlin and Java types are fully qualified to avoid conflicts with types defined in OpenAPI definitions.
|
||||
|
||||
<a id="documentation-for-api-endpoints"></a>
|
||||
## Documentation for API Endpoints
|
||||
|
||||
All URIs are relative to *http://petstore.swagger.io/v2*
|
||||
|
||||
Class | Method | HTTP request | Description
|
||||
------------ | ------------- | ------------- | -------------
|
||||
*PetApi* | [**addPet**](docs/PetApi.md#addpet) | **POST** /pet | Add a new pet to the store
|
||||
*PetApi* | [**deletePet**](docs/PetApi.md#deletepet) | **DELETE** /pet/{petId} | Deletes a pet
|
||||
*PetApi* | [**findPetsByStatus**](docs/PetApi.md#findpetsbystatus) | **GET** /pet/findByStatus | Finds Pets by status
|
||||
*PetApi* | [**findPetsByTags**](docs/PetApi.md#findpetsbytags) | **GET** /pet/findByTags | Finds Pets by tags
|
||||
*PetApi* | [**getPetById**](docs/PetApi.md#getpetbyid) | **GET** /pet/{petId} | Find pet by ID
|
||||
*PetApi* | [**updatePet**](docs/PetApi.md#updatepet) | **PUT** /pet | Update an existing pet
|
||||
*PetApi* | [**updatePetWithForm**](docs/PetApi.md#updatepetwithform) | **POST** /pet/{petId} | Updates a pet in the store with form data
|
||||
*PetApi* | [**uploadFile**](docs/PetApi.md#uploadfile) | **POST** /pet/{petId}/uploadImage | uploads an image
|
||||
*StoreApi* | [**deleteOrder**](docs/StoreApi.md#deleteorder) | **DELETE** /store/order/{orderId} | Delete purchase order by ID
|
||||
*StoreApi* | [**getInventory**](docs/StoreApi.md#getinventory) | **GET** /store/inventory | Returns pet inventories by status
|
||||
*StoreApi* | [**getOrderById**](docs/StoreApi.md#getorderbyid) | **GET** /store/order/{orderId} | Find purchase order by ID
|
||||
*StoreApi* | [**placeOrder**](docs/StoreApi.md#placeorder) | **POST** /store/order | Place an order for a pet
|
||||
*UserApi* | [**createUser**](docs/UserApi.md#createuser) | **POST** /user | Create user
|
||||
*UserApi* | [**createUsersWithArrayInput**](docs/UserApi.md#createuserswitharrayinput) | **POST** /user/createWithArray | Creates list of users with given input array
|
||||
*UserApi* | [**createUsersWithListInput**](docs/UserApi.md#createuserswithlistinput) | **POST** /user/createWithList | Creates list of users with given input array
|
||||
*UserApi* | [**deleteUser**](docs/UserApi.md#deleteuser) | **DELETE** /user/{username} | Delete user
|
||||
*UserApi* | [**getUserByName**](docs/UserApi.md#getuserbyname) | **GET** /user/{username} | Get user by user name
|
||||
*UserApi* | [**loginUser**](docs/UserApi.md#loginuser) | **GET** /user/login | Logs user into the system
|
||||
*UserApi* | [**logoutUser**](docs/UserApi.md#logoutuser) | **GET** /user/logout | Logs out current logged in user session
|
||||
*UserApi* | [**updateUser**](docs/UserApi.md#updateuser) | **PUT** /user/{username} | Updated user
|
||||
|
||||
|
||||
<a id="documentation-for-models"></a>
|
||||
## Documentation for Models
|
||||
|
||||
- [org.openapitools.server.models.Category](docs/Category.md)
|
||||
- [org.openapitools.server.models.ModelApiResponse](docs/ModelApiResponse.md)
|
||||
- [org.openapitools.server.models.Order](docs/Order.md)
|
||||
- [org.openapitools.server.models.Pet](docs/Pet.md)
|
||||
- [org.openapitools.server.models.Tag](docs/Tag.md)
|
||||
- [org.openapitools.server.models.User](docs/User.md)
|
||||
|
||||
|
||||
<a id="documentation-for-authorization"></a>
|
||||
## Documentation for Authorization
|
||||
|
||||
|
||||
Authentication schemes defined for the API:
|
||||
<a id="petstore_auth"></a>
|
||||
### petstore_auth
|
||||
|
||||
- **Type**: OAuth
|
||||
- **Flow**: implicit
|
||||
- **Authorization URL**: http://petstore.swagger.io/api/oauth/dialog
|
||||
- **Scopes**:
|
||||
- write:pets: modify pets in your account
|
||||
- read:pets: read your pets
|
||||
|
||||
<a id="api_key"></a>
|
||||
### api_key
|
||||
|
||||
- **Type**: API key
|
||||
- **API key parameter name**: api_key
|
||||
- **Location**: HTTP header
|
||||
|
@ -0,0 +1,33 @@
|
||||
plugins {
|
||||
kotlin("jvm") version "2.0.0"
|
||||
}
|
||||
|
||||
group = "org.openapitools"
|
||||
version = "1.0.0"
|
||||
|
||||
kotlin {
|
||||
jvmToolchain(21)
|
||||
}
|
||||
|
||||
java {
|
||||
toolchain {
|
||||
languageVersion.set(JavaLanguageVersion.of(21))
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("io.javalin:javalin:6.1.6")
|
||||
implementation("com.fasterxml.jackson.core:jackson-databind:2.17.1")
|
||||
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.17.1")
|
||||
implementation("org.slf4j:slf4j-simple:2.0.13")
|
||||
|
||||
testImplementation("org.jetbrains.kotlin:kotlin-test")
|
||||
}
|
||||
|
||||
tasks.test {
|
||||
useJUnitPlatform()
|
||||
}
|
@ -0,0 +1 @@
|
||||
org.gradle.caching=true
|
@ -0,0 +1 @@
|
||||
rootProject.name = 'kotlin-server'
|
@ -0,0 +1,48 @@
|
||||
package org.openapitools.server
|
||||
|
||||
import io.javalin.Javalin
|
||||
import io.javalin.apibuilder.ApiBuilder.*
|
||||
|
||||
import org.openapitools.server.apis.PetApi
|
||||
import org.openapitools.server.apis.PetApiServiceImpl
|
||||
import org.openapitools.server.apis.StoreApi
|
||||
import org.openapitools.server.apis.StoreApiServiceImpl
|
||||
import org.openapitools.server.apis.UserApi
|
||||
import org.openapitools.server.apis.UserApiServiceImpl
|
||||
|
||||
fun main() {
|
||||
val petApi = PetApi(PetApiServiceImpl())
|
||||
val storeApi = StoreApi(StoreApiServiceImpl())
|
||||
val userApi = UserApi(UserApiServiceImpl())
|
||||
|
||||
val app = Javalin
|
||||
.create { config ->
|
||||
config.router.apiBuilder {
|
||||
path("/pet") { post(petApi::addPet) }
|
||||
path("/pet/{petId}") { delete(petApi::deletePet) }
|
||||
path("/pet/findByStatus") { get(petApi::findPetsByStatus) }
|
||||
path("/pet/findByTags") { get(petApi::findPetsByTags) }
|
||||
path("/pet/{petId}") { get(petApi::getPetById) }
|
||||
path("/pet") { put(petApi::updatePet) }
|
||||
path("/pet/{petId}") { post(petApi::updatePetWithForm) }
|
||||
path("/pet/{petId}/uploadImage") { post(petApi::uploadFile) }
|
||||
|
||||
path("/store/order/{orderId}") { delete(storeApi::deleteOrder) }
|
||||
path("/store/inventory") { get(storeApi::getInventory) }
|
||||
path("/store/order/{orderId}") { get(storeApi::getOrderById) }
|
||||
path("/store/order") { post(storeApi::placeOrder) }
|
||||
|
||||
path("/user") { post(userApi::createUser) }
|
||||
path("/user/createWithArray") { post(userApi::createUsersWithArrayInput) }
|
||||
path("/user/createWithList") { post(userApi::createUsersWithListInput) }
|
||||
path("/user/{username}") { delete(userApi::deleteUser) }
|
||||
path("/user/{username}") { get(userApi::getUserByName) }
|
||||
path("/user/login") { get(userApi::loginUser) }
|
||||
path("/user/logout") { get(userApi::logoutUser) }
|
||||
path("/user/{username}") { put(userApi::updateUser) }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
app.start()
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
package org.openapitools.server.apis
|
||||
|
||||
import io.javalin.http.Context
|
||||
import io.javalin.http.bodyAsClass
|
||||
import io.javalin.http.pathParamAsClass
|
||||
import io.javalin.http.queryParamAsClass
|
||||
|
||||
import org.openapitools.server.models.ModelApiResponse
|
||||
import org.openapitools.server.models.Pet
|
||||
|
||||
class PetApi(private val service: PetApiService) {
|
||||
/**
|
||||
* Add a new pet to the store
|
||||
*
|
||||
* @param pet Pet object that needs to be added to the store
|
||||
*/
|
||||
fun addPet(ctx: Context) {
|
||||
val result = service.addPet(ctx.bodyAsClass<Pet>(), ctx)
|
||||
ctx.status(200).json(result)
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a pet
|
||||
*
|
||||
* @param petId Pet id to delete
|
||||
* @param apiKey (optional)
|
||||
*/
|
||||
fun deletePet(ctx: Context) {
|
||||
val result = service.deletePet(ctx.pathParamAsClass<kotlin.Long>("petId").get(), ctx.header("api_key"), ctx)
|
||||
ctx.status(400).json(result)
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds Pets by status
|
||||
* Multiple status values can be provided with comma separated strings
|
||||
* @param status Status values that need to be considered for filter
|
||||
*/
|
||||
fun findPetsByStatus(ctx: Context) {
|
||||
val result = service.findPetsByStatus(ctx.queryParams("status"), ctx)
|
||||
ctx.status(200).json(result)
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds Pets by tags
|
||||
* Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
||||
* @param tags Tags to filter by
|
||||
*/
|
||||
fun findPetsByTags(ctx: Context) {
|
||||
val result = service.findPetsByTags(ctx.queryParams("tags"), ctx)
|
||||
ctx.status(200).json(result)
|
||||
}
|
||||
|
||||
/**
|
||||
* Find pet by ID
|
||||
* Returns a single pet
|
||||
* @param petId ID of pet to return
|
||||
*/
|
||||
fun getPetById(ctx: Context) {
|
||||
val result = service.getPetById(ctx.pathParamAsClass<kotlin.Long>("petId").get(), ctx)
|
||||
ctx.status(200).json(result)
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an existing pet
|
||||
*
|
||||
* @param pet Pet object that needs to be added to the store
|
||||
*/
|
||||
fun updatePet(ctx: Context) {
|
||||
val result = service.updatePet(ctx.bodyAsClass<Pet>(), ctx)
|
||||
ctx.status(200).json(result)
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a pet in the store with form data
|
||||
*
|
||||
* @param petId ID of pet that needs to be updated
|
||||
* @param name Updated name of the pet (optional)
|
||||
* @param status Updated status of the pet (optional)
|
||||
*/
|
||||
fun updatePetWithForm(ctx: Context) {
|
||||
val result = service.updatePetWithForm(ctx.pathParamAsClass<kotlin.Long>("petId").get(), ctx.formParam("name"), ctx.formParam("status"), ctx)
|
||||
ctx.status(405).json(result)
|
||||
}
|
||||
|
||||
/**
|
||||
* uploads an image
|
||||
*
|
||||
* @param petId ID of pet to update
|
||||
* @param additionalMetadata Additional data to pass to server (optional)
|
||||
* @param file file to upload (optional)
|
||||
*/
|
||||
fun uploadFile(ctx: Context) {
|
||||
val result = service.uploadFile(ctx.pathParamAsClass<kotlin.Long>("petId").get(), ctx.formParam("additionalMetadata"), ctx.uploadedFile("file"), ctx)
|
||||
ctx.status(200).json(result)
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,112 @@
|
||||
package org.openapitools.server.apis
|
||||
|
||||
import org.openapitools.server.models.ModelApiResponse
|
||||
import org.openapitools.server.models.Pet
|
||||
import io.javalin.http.Context
|
||||
|
||||
interface PetApiService {
|
||||
|
||||
/**
|
||||
* POST /pet : Add a new pet to the store
|
||||
*
|
||||
*
|
||||
* @param pet Pet object that needs to be added to the store (required)
|
||||
* @param ctx The Javalin context. Especially handy if you need to access things like authentication headers in your service. (required)
|
||||
* @return successful operation (status code 200)
|
||||
* or Invalid input (status code 405)
|
||||
* @see PetApi#addPet
|
||||
*/
|
||||
fun addPet(pet: Pet, ctx: Context): Pet
|
||||
|
||||
/**
|
||||
* DELETE /pet/{petId} : Deletes a pet
|
||||
*
|
||||
*
|
||||
* @param petId Pet id to delete (required)
|
||||
* @param apiKey (optional)
|
||||
* @param ctx The Javalin context. Especially handy if you need to access things like authentication headers in your service. (required)
|
||||
* @return Invalid pet value (status code 400)
|
||||
* @see PetApi#deletePet
|
||||
*/
|
||||
fun deletePet(petId: kotlin.Long, apiKey: kotlin.String?, ctx: Context): Unit
|
||||
|
||||
/**
|
||||
* GET /pet/findByStatus : Finds Pets by status
|
||||
* Multiple status values can be provided with comma separated strings
|
||||
*
|
||||
* @param status Status values that need to be considered for filter (required)
|
||||
* @param ctx The Javalin context. Especially handy if you need to access things like authentication headers in your service. (required)
|
||||
* @return successful operation (status code 200)
|
||||
* or Invalid status value (status code 400)
|
||||
* @see PetApi#findPetsByStatus
|
||||
*/
|
||||
fun findPetsByStatus(status: kotlin.collections.List<kotlin.String>, ctx: Context): List<Pet>
|
||||
|
||||
/**
|
||||
* GET /pet/findByTags : Finds Pets by tags
|
||||
* Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
||||
*
|
||||
* @param tags Tags to filter by (required)
|
||||
* @param ctx The Javalin context. Especially handy if you need to access things like authentication headers in your service. (required)
|
||||
* @return successful operation (status code 200)
|
||||
* or Invalid tag value (status code 400)
|
||||
* @deprecated
|
||||
* @see PetApi#findPetsByTags
|
||||
*/
|
||||
fun findPetsByTags(tags: kotlin.collections.List<kotlin.String>, ctx: Context): List<Pet>
|
||||
|
||||
/**
|
||||
* GET /pet/{petId} : Find pet by ID
|
||||
* Returns a single pet
|
||||
*
|
||||
* @param petId ID of pet to return (required)
|
||||
* @param ctx The Javalin context. Especially handy if you need to access things like authentication headers in your service. (required)
|
||||
* @return successful operation (status code 200)
|
||||
* or Invalid ID supplied (status code 400)
|
||||
* or Pet not found (status code 404)
|
||||
* @see PetApi#getPetById
|
||||
*/
|
||||
fun getPetById(petId: kotlin.Long, ctx: Context): Pet
|
||||
|
||||
/**
|
||||
* PUT /pet : Update an existing pet
|
||||
*
|
||||
*
|
||||
* @param pet Pet object that needs to be added to the store (required)
|
||||
* @param ctx The Javalin context. Especially handy if you need to access things like authentication headers in your service. (required)
|
||||
* @return successful operation (status code 200)
|
||||
* or Invalid ID supplied (status code 400)
|
||||
* or Pet not found (status code 404)
|
||||
* or Validation exception (status code 405)
|
||||
* API documentation for the updatePet operation
|
||||
* @see <a href="http://petstore.swagger.io/v2/doc/updatePet">Update an existing pet Documentation</a>
|
||||
* @see PetApi#updatePet
|
||||
*/
|
||||
fun updatePet(pet: Pet, ctx: Context): Pet
|
||||
|
||||
/**
|
||||
* POST /pet/{petId} : Updates a pet in the store with form data
|
||||
*
|
||||
*
|
||||
* @param petId ID of pet that needs to be updated (required)
|
||||
* @param name Updated name of the pet (optional)
|
||||
* @param status Updated status of the pet (optional)
|
||||
* @param ctx The Javalin context. Especially handy if you need to access things like authentication headers in your service. (required)
|
||||
* @return Invalid input (status code 405)
|
||||
* @see PetApi#updatePetWithForm
|
||||
*/
|
||||
fun updatePetWithForm(petId: kotlin.Long, name: kotlin.String?, status: kotlin.String?, ctx: Context): Unit
|
||||
|
||||
/**
|
||||
* POST /pet/{petId}/uploadImage : uploads an image
|
||||
*
|
||||
*
|
||||
* @param petId ID of pet to update (required)
|
||||
* @param additionalMetadata Additional data to pass to server (optional)
|
||||
* @param file file to upload (optional)
|
||||
* @param ctx The Javalin context. Especially handy if you need to access things like authentication headers in your service. (required)
|
||||
* @return successful operation (status code 200)
|
||||
* @see PetApi#uploadFile
|
||||
*/
|
||||
fun uploadFile(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: io.javalin.http.UploadedFile?, ctx: Context): ModelApiResponse
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package org.openapitools.server.apis
|
||||
|
||||
import org.openapitools.server.models.ModelApiResponse
|
||||
import org.openapitools.server.models.Pet
|
||||
import io.javalin.http.Context
|
||||
|
||||
class PetApiServiceImpl : PetApiService {
|
||||
|
||||
override fun addPet(pet: Pet, ctx: Context): Pet {
|
||||
TODO("Implement me")
|
||||
}
|
||||
|
||||
override fun deletePet(petId: kotlin.Long, apiKey: kotlin.String?, ctx: Context): Unit {
|
||||
TODO("Implement me")
|
||||
}
|
||||
|
||||
override fun findPetsByStatus(status: kotlin.collections.List<kotlin.String>, ctx: Context): List<Pet> {
|
||||
TODO("Implement me")
|
||||
}
|
||||
|
||||
override fun findPetsByTags(tags: kotlin.collections.List<kotlin.String>, ctx: Context): List<Pet> {
|
||||
TODO("Implement me")
|
||||
}
|
||||
|
||||
override fun getPetById(petId: kotlin.Long, ctx: Context): Pet {
|
||||
TODO("Implement me")
|
||||
}
|
||||
|
||||
override fun updatePet(pet: Pet, ctx: Context): Pet {
|
||||
TODO("Implement me")
|
||||
}
|
||||
|
||||
override fun updatePetWithForm(petId: kotlin.Long, name: kotlin.String?, status: kotlin.String?, ctx: Context): Unit {
|
||||
TODO("Implement me")
|
||||
}
|
||||
|
||||
override fun uploadFile(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: io.javalin.http.UploadedFile?, ctx: Context): ModelApiResponse {
|
||||
TODO("Implement me")
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package org.openapitools.server.apis
|
||||
|
||||
import io.javalin.http.Context
|
||||
import io.javalin.http.bodyAsClass
|
||||
import io.javalin.http.pathParamAsClass
|
||||
import io.javalin.http.queryParamAsClass
|
||||
|
||||
import org.openapitools.server.models.Order
|
||||
|
||||
class StoreApi(private val service: StoreApiService) {
|
||||
/**
|
||||
* Delete purchase order by ID
|
||||
* For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
||||
* @param orderId ID of the order that needs to be deleted
|
||||
*/
|
||||
fun deleteOrder(ctx: Context) {
|
||||
val result = service.deleteOrder(ctx.pathParamAsClass<kotlin.String>("orderId").get(), ctx)
|
||||
ctx.status(400).json(result)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns pet inventories by status
|
||||
* Returns a map of status codes to quantities
|
||||
*/
|
||||
fun getInventory(ctx: Context) {
|
||||
val result = service.getInventory(ctx)
|
||||
ctx.status(200).json(result)
|
||||
}
|
||||
|
||||
/**
|
||||
* Find purchase order by ID
|
||||
* For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions
|
||||
* @param orderId ID of pet that needs to be fetched
|
||||
*/
|
||||
fun getOrderById(ctx: Context) {
|
||||
val result = service.getOrderById(ctx.pathParamAsClass<kotlin.Long>("orderId").get(), ctx)
|
||||
ctx.status(200).json(result)
|
||||
}
|
||||
|
||||
/**
|
||||
* Place an order for a pet
|
||||
*
|
||||
* @param order order placed for purchasing the pet
|
||||
*/
|
||||
fun placeOrder(ctx: Context) {
|
||||
val result = service.placeOrder(ctx.bodyAsClass<Order>(), ctx)
|
||||
ctx.status(200).json(result)
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
package org.openapitools.server.apis
|
||||
|
||||
import org.openapitools.server.models.Order
|
||||
import io.javalin.http.Context
|
||||
|
||||
interface StoreApiService {
|
||||
|
||||
/**
|
||||
* DELETE /store/order/{orderId} : Delete purchase order by ID
|
||||
* For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
||||
*
|
||||
* @param orderId ID of the order that needs to be deleted (required)
|
||||
* @param ctx The Javalin context. Especially handy if you need to access things like authentication headers in your service. (required)
|
||||
* @return Invalid ID supplied (status code 400)
|
||||
* or Order not found (status code 404)
|
||||
* @see StoreApi#deleteOrder
|
||||
*/
|
||||
fun deleteOrder(orderId: kotlin.String, ctx: Context): Unit
|
||||
|
||||
/**
|
||||
* GET /store/inventory : Returns pet inventories by status
|
||||
* Returns a map of status codes to quantities
|
||||
*
|
||||
* @param ctx The Javalin context. Especially handy if you need to access things like authentication headers in your service. (required)
|
||||
* @return successful operation (status code 200)
|
||||
* @see StoreApi#getInventory
|
||||
*/
|
||||
fun getInventory(ctx: Context): Map<String, kotlin.Int>
|
||||
|
||||
/**
|
||||
* GET /store/order/{orderId} : Find purchase order by ID
|
||||
* For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions
|
||||
*
|
||||
* @param orderId ID of pet that needs to be fetched (required)
|
||||
* @param ctx The Javalin context. Especially handy if you need to access things like authentication headers in your service. (required)
|
||||
* @return successful operation (status code 200)
|
||||
* or Invalid ID supplied (status code 400)
|
||||
* or Order not found (status code 404)
|
||||
* @see StoreApi#getOrderById
|
||||
*/
|
||||
fun getOrderById(orderId: kotlin.Long, ctx: Context): Order
|
||||
|
||||
/**
|
||||
* POST /store/order : Place an order for a pet
|
||||
*
|
||||
*
|
||||
* @param order order placed for purchasing the pet (required)
|
||||
* @param ctx The Javalin context. Especially handy if you need to access things like authentication headers in your service. (required)
|
||||
* @return successful operation (status code 200)
|
||||
* or Invalid Order (status code 400)
|
||||
* @see StoreApi#placeOrder
|
||||
*/
|
||||
fun placeOrder(order: Order, ctx: Context): Order
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package org.openapitools.server.apis
|
||||
|
||||
import org.openapitools.server.models.Order
|
||||
import io.javalin.http.Context
|
||||
|
||||
class StoreApiServiceImpl : StoreApiService {
|
||||
|
||||
override fun deleteOrder(orderId: kotlin.String, ctx: Context): Unit {
|
||||
TODO("Implement me")
|
||||
}
|
||||
|
||||
override fun getInventory(ctx: Context): Map<String, kotlin.Int> {
|
||||
TODO("Implement me")
|
||||
}
|
||||
|
||||
override fun getOrderById(orderId: kotlin.Long, ctx: Context): Order {
|
||||
TODO("Implement me")
|
||||
}
|
||||
|
||||
override fun placeOrder(order: Order, ctx: Context): Order {
|
||||
TODO("Implement me")
|
||||
}
|
||||
}
|
@ -0,0 +1,92 @@
|
||||
package org.openapitools.server.apis
|
||||
|
||||
import io.javalin.http.Context
|
||||
import io.javalin.http.bodyAsClass
|
||||
import io.javalin.http.pathParamAsClass
|
||||
import io.javalin.http.queryParamAsClass
|
||||
|
||||
import org.openapitools.server.models.User
|
||||
|
||||
class UserApi(private val service: UserApiService) {
|
||||
/**
|
||||
* Create user
|
||||
* This can only be done by the logged in user.
|
||||
* @param user Created user object
|
||||
*/
|
||||
fun createUser(ctx: Context) {
|
||||
val result = service.createUser(ctx.bodyAsClass<User>(), ctx)
|
||||
ctx.status(200).json(result)
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates list of users with given input array
|
||||
*
|
||||
* @param user List of user object
|
||||
*/
|
||||
fun createUsersWithArrayInput(ctx: Context) {
|
||||
val result = service.createUsersWithArrayInput(ctx.bodyAsClass<List<User>>(), ctx)
|
||||
ctx.status(200).json(result)
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates list of users with given input array
|
||||
*
|
||||
* @param user List of user object
|
||||
*/
|
||||
fun createUsersWithListInput(ctx: Context) {
|
||||
val result = service.createUsersWithListInput(ctx.bodyAsClass<List<User>>(), ctx)
|
||||
ctx.status(200).json(result)
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete user
|
||||
* This can only be done by the logged in user.
|
||||
* @param username The name that needs to be deleted
|
||||
*/
|
||||
fun deleteUser(ctx: Context) {
|
||||
val result = service.deleteUser(ctx.pathParamAsClass<kotlin.String>("username").get(), ctx)
|
||||
ctx.status(400).json(result)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user by user name
|
||||
*
|
||||
* @param username The name that needs to be fetched. Use user1 for testing.
|
||||
*/
|
||||
fun getUserByName(ctx: Context) {
|
||||
val result = service.getUserByName(ctx.pathParamAsClass<kotlin.String>("username").get(), ctx)
|
||||
ctx.status(200).json(result)
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs user into the system
|
||||
*
|
||||
* @param username The user name for login
|
||||
* @param password The password for login in clear text
|
||||
*/
|
||||
fun loginUser(ctx: Context) {
|
||||
val result = service.loginUser(ctx.queryParamAsClass<kotlin.String>("username").get(), ctx.queryParamAsClass<kotlin.String>("password").get(), ctx)
|
||||
ctx.status(200).json(result)
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs out current logged in user session
|
||||
*
|
||||
*/
|
||||
fun logoutUser(ctx: Context) {
|
||||
val result = service.logoutUser(ctx)
|
||||
ctx.status(200).json(result)
|
||||
}
|
||||
|
||||
/**
|
||||
* Updated user
|
||||
* This can only be done by the logged in user.
|
||||
* @param username name that need to be deleted
|
||||
* @param user Updated user object
|
||||
*/
|
||||
fun updateUser(ctx: Context) {
|
||||
val result = service.updateUser(ctx.pathParamAsClass<kotlin.String>("username").get(), ctx.bodyAsClass<User>(), ctx)
|
||||
ctx.status(400).json(result)
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,101 @@
|
||||
package org.openapitools.server.apis
|
||||
|
||||
import org.openapitools.server.models.User
|
||||
import io.javalin.http.Context
|
||||
|
||||
interface UserApiService {
|
||||
|
||||
/**
|
||||
* POST /user : Create user
|
||||
* This can only be done by the logged in user.
|
||||
*
|
||||
* @param user Created user object (required)
|
||||
* @param ctx The Javalin context. Especially handy if you need to access things like authentication headers in your service. (required)
|
||||
* @return successful operation (status code 200)
|
||||
* @see UserApi#createUser
|
||||
*/
|
||||
fun createUser(user: User, ctx: Context): Unit
|
||||
|
||||
/**
|
||||
* POST /user/createWithArray : Creates list of users with given input array
|
||||
*
|
||||
*
|
||||
* @param user List of user object (required)
|
||||
* @param ctx The Javalin context. Especially handy if you need to access things like authentication headers in your service. (required)
|
||||
* @return successful operation (status code 200)
|
||||
* @see UserApi#createUsersWithArrayInput
|
||||
*/
|
||||
fun createUsersWithArrayInput(user: kotlin.collections.List<User>, ctx: Context): Unit
|
||||
|
||||
/**
|
||||
* POST /user/createWithList : Creates list of users with given input array
|
||||
*
|
||||
*
|
||||
* @param user List of user object (required)
|
||||
* @param ctx The Javalin context. Especially handy if you need to access things like authentication headers in your service. (required)
|
||||
* @return successful operation (status code 200)
|
||||
* @see UserApi#createUsersWithListInput
|
||||
*/
|
||||
fun createUsersWithListInput(user: kotlin.collections.List<User>, ctx: Context): Unit
|
||||
|
||||
/**
|
||||
* DELETE /user/{username} : Delete user
|
||||
* This can only be done by the logged in user.
|
||||
*
|
||||
* @param username The name that needs to be deleted (required)
|
||||
* @param ctx The Javalin context. Especially handy if you need to access things like authentication headers in your service. (required)
|
||||
* @return Invalid username supplied (status code 400)
|
||||
* or User not found (status code 404)
|
||||
* @see UserApi#deleteUser
|
||||
*/
|
||||
fun deleteUser(username: kotlin.String, ctx: Context): Unit
|
||||
|
||||
/**
|
||||
* GET /user/{username} : Get user by user name
|
||||
*
|
||||
*
|
||||
* @param username The name that needs to be fetched. Use user1 for testing. (required)
|
||||
* @param ctx The Javalin context. Especially handy if you need to access things like authentication headers in your service. (required)
|
||||
* @return successful operation (status code 200)
|
||||
* or Invalid username supplied (status code 400)
|
||||
* or User not found (status code 404)
|
||||
* @see UserApi#getUserByName
|
||||
*/
|
||||
fun getUserByName(username: kotlin.String, ctx: Context): User
|
||||
|
||||
/**
|
||||
* GET /user/login : Logs user into the system
|
||||
*
|
||||
*
|
||||
* @param username The user name for login (required)
|
||||
* @param password The password for login in clear text (required)
|
||||
* @param ctx The Javalin context. Especially handy if you need to access things like authentication headers in your service. (required)
|
||||
* @return successful operation (status code 200)
|
||||
* or Invalid username/password supplied (status code 400)
|
||||
* @see UserApi#loginUser
|
||||
*/
|
||||
fun loginUser(username: kotlin.String, password: kotlin.String, ctx: Context): kotlin.String
|
||||
|
||||
/**
|
||||
* GET /user/logout : Logs out current logged in user session
|
||||
*
|
||||
*
|
||||
* @param ctx The Javalin context. Especially handy if you need to access things like authentication headers in your service. (required)
|
||||
* @return successful operation (status code 200)
|
||||
* @see UserApi#logoutUser
|
||||
*/
|
||||
fun logoutUser(ctx: Context): Unit
|
||||
|
||||
/**
|
||||
* PUT /user/{username} : Updated user
|
||||
* This can only be done by the logged in user.
|
||||
*
|
||||
* @param username name that need to be deleted (required)
|
||||
* @param user Updated user object (required)
|
||||
* @param ctx The Javalin context. Especially handy if you need to access things like authentication headers in your service. (required)
|
||||
* @return Invalid user supplied (status code 400)
|
||||
* or User not found (status code 404)
|
||||
* @see UserApi#updateUser
|
||||
*/
|
||||
fun updateUser(username: kotlin.String, user: User, ctx: Context): Unit
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package org.openapitools.server.apis
|
||||
|
||||
import org.openapitools.server.models.User
|
||||
import io.javalin.http.Context
|
||||
|
||||
class UserApiServiceImpl : UserApiService {
|
||||
|
||||
override fun createUser(user: User, ctx: Context): Unit {
|
||||
TODO("Implement me")
|
||||
}
|
||||
|
||||
override fun createUsersWithArrayInput(user: kotlin.collections.List<User>, ctx: Context): Unit {
|
||||
TODO("Implement me")
|
||||
}
|
||||
|
||||
override fun createUsersWithListInput(user: kotlin.collections.List<User>, ctx: Context): Unit {
|
||||
TODO("Implement me")
|
||||
}
|
||||
|
||||
override fun deleteUser(username: kotlin.String, ctx: Context): Unit {
|
||||
TODO("Implement me")
|
||||
}
|
||||
|
||||
override fun getUserByName(username: kotlin.String, ctx: Context): User {
|
||||
TODO("Implement me")
|
||||
}
|
||||
|
||||
override fun loginUser(username: kotlin.String, password: kotlin.String, ctx: Context): kotlin.String {
|
||||
TODO("Implement me")
|
||||
}
|
||||
|
||||
override fun logoutUser(ctx: Context): Unit {
|
||||
TODO("Implement me")
|
||||
}
|
||||
|
||||
override fun updateUser(username: kotlin.String, user: User, ctx: Context): Unit {
|
||||
TODO("Implement me")
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
package org.openapitools.server.models
|
||||
|
||||
|
||||
/**
|
||||
* A category for a pet
|
||||
* @param id
|
||||
* @param name
|
||||
*/
|
||||
data class Category(
|
||||
val id: kotlin.Long? = null,
|
||||
val name: kotlin.String? = null
|
||||
)
|
||||
|
@ -0,0 +1,26 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
package org.openapitools.server.models
|
||||
|
||||
|
||||
/**
|
||||
* Describes the result of uploading an image resource
|
||||
* @param code
|
||||
* @param type
|
||||
* @param message
|
||||
*/
|
||||
data class ModelApiResponse(
|
||||
val code: kotlin.Int? = null,
|
||||
val type: kotlin.String? = null,
|
||||
val message: kotlin.String? = null
|
||||
)
|
||||
|
@ -0,0 +1,44 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
package org.openapitools.server.models
|
||||
|
||||
|
||||
/**
|
||||
* An order for a pets from the pet store
|
||||
* @param id
|
||||
* @param petId
|
||||
* @param quantity
|
||||
* @param shipDate
|
||||
* @param status Order Status
|
||||
* @param complete
|
||||
*/
|
||||
data class Order(
|
||||
val id: kotlin.Long? = null,
|
||||
val petId: kotlin.Long? = null,
|
||||
val quantity: kotlin.Int? = null,
|
||||
val shipDate: java.time.OffsetDateTime? = null,
|
||||
/* Order Status */
|
||||
val status: Order.Status? = null,
|
||||
val complete: kotlin.Boolean? = false
|
||||
)
|
||||
{
|
||||
/**
|
||||
* Order Status
|
||||
* Values: placed,approved,delivered
|
||||
*/
|
||||
enum class Status(val value: kotlin.String){
|
||||
placed("placed"),
|
||||
approved("approved"),
|
||||
delivered("delivered");
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,46 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
package org.openapitools.server.models
|
||||
|
||||
import org.openapitools.server.models.Category
|
||||
import org.openapitools.server.models.Tag
|
||||
|
||||
/**
|
||||
* A pet for sale in the pet store
|
||||
* @param name
|
||||
* @param photoUrls
|
||||
* @param id
|
||||
* @param category
|
||||
* @param tags
|
||||
* @param status pet status in the store
|
||||
*/
|
||||
data class Pet(
|
||||
val name: kotlin.String,
|
||||
val photoUrls: kotlin.collections.List<kotlin.String>,
|
||||
val id: kotlin.Long? = null,
|
||||
val category: Category? = null,
|
||||
val tags: kotlin.collections.List<Tag>? = null,
|
||||
/* pet status in the store */
|
||||
val status: Pet.Status? = null
|
||||
)
|
||||
{
|
||||
/**
|
||||
* pet status in the store
|
||||
* Values: available,pending,sold
|
||||
*/
|
||||
enum class Status(val value: kotlin.String){
|
||||
available("available"),
|
||||
pending("pending"),
|
||||
sold("sold");
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,24 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
package org.openapitools.server.models
|
||||
|
||||
|
||||
/**
|
||||
* A tag for a pet
|
||||
* @param id
|
||||
* @param name
|
||||
*/
|
||||
data class Tag(
|
||||
val id: kotlin.Long? = null,
|
||||
val name: kotlin.String? = null
|
||||
)
|
||||
|
@ -0,0 +1,37 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
package org.openapitools.server.models
|
||||
|
||||
|
||||
/**
|
||||
* A User who is purchasing from the pet store
|
||||
* @param id
|
||||
* @param username
|
||||
* @param firstName
|
||||
* @param lastName
|
||||
* @param email
|
||||
* @param password
|
||||
* @param phone
|
||||
* @param userStatus User Status
|
||||
*/
|
||||
data class User(
|
||||
val id: kotlin.Long? = null,
|
||||
val username: kotlin.String? = null,
|
||||
val firstName: kotlin.String? = null,
|
||||
val lastName: kotlin.String? = null,
|
||||
val email: kotlin.String? = null,
|
||||
val password: kotlin.String? = null,
|
||||
val phone: kotlin.String? = null,
|
||||
/* User Status */
|
||||
val userStatus: kotlin.Int? = null
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user