-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
kotlin-server: Add support for Javalin (#17596)
* kotlin-server: Add support for Javalin * kotlin-server: Add Javalin generated sample code * Add output from build scripts * Address MR feedback * Update CI to include new Javalin sample
- Loading branch information
1 parent
36e4e4f
commit 13edc5d
Showing
44 changed files
with
1,362 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
generatorName: kotlin-server | ||
outputDir: samples/server/petstore/kotlin-server/javalin | ||
library: javalin5 | ||
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml | ||
templateDir: modules/openapi-generator/src/main/resources/kotlin-server | ||
additionalProperties: | ||
hideGenerationTimestamp: "true" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...es/openapi-generator/src/main/resources/kotlin-server/libraries/javalin5/Main.kt.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package {{packageName}} | ||
|
||
import io.javalin.Javalin | ||
import io.javalin.community.routing.dsl.routing | ||
|
||
{{#apiInfo}} | ||
{{#apis}} | ||
{{#operations}}import {{apiPackage}}.{{classname}} | ||
import {{apiPackage}}.{{classname}}ServiceImpl | ||
{{/operations}} | ||
{{/apis}} | ||
|
||
fun main() { | ||
{{#apis}} | ||
{{#operations}} | ||
val {{classname}} = {{classname}}({{classname}}ServiceImpl()) | ||
{{/operations}} | ||
{{/apis}} | ||
|
||
val app = Javalin | ||
.create { config -> | ||
config.routing { | ||
{{#apis}} | ||
{{#operations}} | ||
{{#operation}} | ||
{{#lowercase}}{{httpMethod}}{{/lowercase}}("{{path}}", {{classname}}::{{operationId}}) | ||
{{/operation}} | ||
{{/operations}} | ||
|
||
{{/apis}} | ||
} | ||
} | ||
|
||
app.start({{serverPort}}) | ||
} | ||
{{/apiInfo}} |
94 changes: 94 additions & 0 deletions
94
...les/openapi-generator/src/main/resources/kotlin-server/libraries/javalin5/README.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}} |
Oops, something went wrong.