-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
kotlin-server: Add support for Javalin #17596
Merged
wing328
merged 5 commits into
OpenAPITools:master
from
dennisameling:add-kotlin-server-javalin
Jan 15, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2e771c1
kotlin-server: Add support for Javalin
dennisameling f17af09
kotlin-server: Add Javalin generated sample code
dennisameling a1f7a88
Add output from build scripts
dennisameling 18a2dc5
Address MR feedback
dennisameling c8f95ec
Update CI to include new Javalin sample
dennisameling File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you please update the kotlin server github workflow with the new sample directory so that CI can test it moving forward?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion. Done! ✅
It looks like one of the Spring Boot-related tests is now failing. Looks like that sample is already broken on the
master
branch:openapi-generator/samples/server/petstore/kotlin-springboot-request/src/main/kotlin/org/openapitools/api/StoreApi.kt
Line 74 in 36e4e4f
Please let me know if there's anything else I can do within the scope of this PR 😊 thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed it's not related to this change