-
-
Notifications
You must be signed in to change notification settings - Fork 7k
[Kotlin][server] Add kotlin-vertx-server #3031
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
ed1ec9d
add kotlin-vertx
Wooyme fcdc051
add kotlin-vertx
Wooyme 7225bad
update kotlin server
Wooyme aaf63bf
update
Wooyme 56ffbc2
move Fsharp... in Config
Wooyme 42aafa4
replace java model to kotlin model. delete useless code
Wooyme 8a4de49
add kotlin-vertx readme.md
Wooyme 031bc9c
add kotlin-vertx
Wooyme a80ef7a
add model null safety
Wooyme e49776f
change to vert.x offical web api
Wooyme bd4dc66
Merge branch 'master' into kotlin-vertx
jimschubert d923efa
fix date and datetime missing
Wooyme 610cf72
Merge branch 'kotlin-vertx' of https://github.com/Wooyme/openapi-gene…
Wooyme bfee5b8
fix fileupload
Wooyme 2f98aee
Merge branch 'master' into kotlin-vertx
wing328 36a1fec
Merge branch 'master' into kotlin-vertx
wing328 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 hidden or 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,31 @@ | ||
#!/bin/sh | ||
|
||
SCRIPT="$0" | ||
|
||
while [ -h "$SCRIPT" ] ; do | ||
ls=$(ls -ld "$SCRIPT") | ||
link=$(expr "$ls" : '.*-> \(.*\)$') | ||
if expr "$link" : '/.*' > /dev/null; then | ||
SCRIPT="$link" | ||
else | ||
SCRIPT=$(dirname "$SCRIPT")/"$link" | ||
fi | ||
done | ||
|
||
if [ ! -d "${APP_DIR}" ]; then | ||
APP_DIR=$(dirname "$SCRIPT")/.. | ||
APP_DIR=$(cd "${APP_DIR}"; pwd) | ||
fi | ||
|
||
executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar" | ||
|
||
if [ ! -f "$executable" ] | ||
then | ||
mvn clean package | ||
fi | ||
|
||
# if you've executed sbt assembly previously it will use that instead. | ||
export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties" | ||
ags="$@ generate -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g kotlin-vertx -o samples/server/petstore/kotlin/vertx" | ||
|
||
java ${JAVA_OPTS} -jar ${executable} ${ags} |
This file contains hidden or 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,10 @@ | ||
set executable=.\modules\openapi-generator-cli\target\openapi-generator-cli.jar | ||
|
||
If Not Exist %executable% ( | ||
mvn clean package | ||
) | ||
|
||
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M -DloggerPath=conf/log4j.properties | ||
set ags=generate --artifact-id "kotlin-vertx-petstore-server" -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g kotlin-vertx -o samples\server\petstore\kotlin\vertx | ||
|
||
java %JAVA_OPTS% -jar %executable% %ags% |
This file contains hidden or 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 hidden or 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,18 @@ | ||
|
||
--- | ||
id: generator-opts-server-kotlin-vertx | ||
title: Config Options for kotlin-vertx | ||
sidebar_label: kotlin-vertx | ||
--- | ||
|
||
| Option | Description | Values | Default | | ||
| ------ | ----------- | ------ | ------- | | ||
|sourceFolder|source folder for generated code| |src/main/kotlin| | ||
|modelPackage|package for generated models| |org.openapitools.server.api.model| | ||
|apiPackage|package for generated api classes| |org.openapitools.server.api.verticle| | ||
|apiSuffix|suffix for api classes| |Api| | ||
|groupId|Generated artifact package's organization (i.e. maven groupId).| |org.openapitools| | ||
|artifactId|Generated artifact id (name of jar).| |kotlin-server| | ||
|artifactVersion|Generated artifact's package version.| |1.0.0| | ||
|enumPropertyNaming|Naming convention for enum properties: 'camelCase', 'PascalCase', 'snake_case', 'UPPERCASE', and 'original'| |camelCase| | ||
|parcelizeModels|toggle "@Parcelize" for generated models| |null| |
85 changes: 85 additions & 0 deletions
85
...-generator/src/main/java/org/openapitools/codegen/languages/KotlinVertxServerCodegen.java
This file contains hidden or 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,85 @@ | ||
/* | ||
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.openapitools.codegen.languages; | ||
|
||
import org.openapitools.codegen.CodegenConstants; | ||
import org.openapitools.codegen.CodegenType; | ||
import org.openapitools.codegen.SupportingFile; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.File; | ||
import java.util.Locale; | ||
|
||
public class KotlinVertxServerCodegen extends AbstractKotlinCodegen { | ||
|
||
protected String rootPackage = "org.openapitools.server.api"; | ||
protected String apiVersion = "1.0.0-SNAPSHOT"; | ||
|
||
public static final String ROOT_PACKAGE = "rootPackage"; | ||
|
||
public static final String PROJECT_NAME = "projectName"; | ||
|
||
static Logger LOGGER = LoggerFactory.getLogger(KotlinVertxServerCodegen.class); | ||
|
||
public CodegenType getTag() { | ||
return CodegenType.SERVER; | ||
} | ||
|
||
public String getName() { | ||
return "kotlin-vertx"; | ||
} | ||
|
||
public String getHelp() { | ||
return "Generates a kotlin-vertx server."; | ||
} | ||
|
||
public KotlinVertxServerCodegen() { | ||
super(); | ||
|
||
outputFolder = "generated-code" + File.separator + "kotlin-vertx"; | ||
modelTemplateFiles.put("model.mustache", ".kt"); | ||
|
||
apiTestTemplateFiles.clear(); | ||
modelDocTemplateFiles.clear(); | ||
supportingFiles.clear(); | ||
|
||
apiTemplateFiles.clear(); | ||
apiTemplateFiles.put("api.mustache", ".kt"); | ||
apiTemplateFiles.put("apiProxy.mustache", "VertxProxyHandler.kt"); | ||
apiTemplateFiles.put("api_verticle.mustache","Verticle.kt"); | ||
|
||
embeddedTemplateDir = templateDir = "kotlin-vertx-server"; | ||
apiPackage = rootPackage + ".verticle"; | ||
modelPackage = rootPackage + ".model"; | ||
artifactId = "openapi-kotlin-vertx-server"; | ||
artifactVersion = apiVersion; | ||
|
||
updateOption(CodegenConstants.API_PACKAGE, apiPackage); | ||
updateOption(CodegenConstants.MODEL_PACKAGE, modelPackage); | ||
additionalProperties.put(ROOT_PACKAGE, rootPackage); | ||
|
||
supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml")); | ||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md")); | ||
|
||
} | ||
|
||
@Override | ||
public String escapeReservedWord(String name) { | ||
return name; | ||
} | ||
} |
This file contains hidden or 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
76 changes: 76 additions & 0 deletions
76
modules/openapi-generator/src/main/resources/kotlin-vertx-server/README.mustache
This file contains hidden or 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,76 @@ | ||
# {{packageName}} - Kotlin Server library for {{appName}} | ||
|
||
## Requires | ||
|
||
* Kotlin 1.3.10 | ||
* Maven 3.3 | ||
|
||
## Build | ||
|
||
``` | ||
mvn clean package | ||
``` | ||
|
||
This runs all tests and packages the library. | ||
|
||
## Features/Implementation Notes | ||
|
||
* Supports JSON inputs/outputs and Form inputs. | ||
* 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 name="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}}{{{summary}}}{{/summary}} | ||
{{/operation}}{{/operations}}{{/apis}}{{/apiInfo}} | ||
{{/generateApiDocs}} | ||
|
||
{{#generateModelDocs}} | ||
<a name="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 name="documentation-for-authorization"></a>{{! TODO: optional documentation for authorization? }} | ||
## Documentation for Authorization | ||
|
||
{{^authMethods}} | ||
All endpoints do not require authorization. | ||
{{/authMethods}} | ||
{{#authMethods}} | ||
{{#last}} | ||
Authentication schemes defined for the API: | ||
{{/last}} | ||
{{/authMethods}} | ||
{{#authMethods}} | ||
<a name="{{name}}"></a> | ||
### {{name}} | ||
|
||
{{#isApiKey}}- **Type**: API key | ||
- **API key parameter name**: {{keyParamName}} | ||
- **Location**: {{#isKeyInQuery}}URL query string{{/isKeyInQuery}}{{#isKeyInHeader}}HTTP header{{/isKeyInHeader}} | ||
{{/isApiKey}} | ||
{{#isBasic}}- **Type**: HTTP basic authentication | ||
{{/isBasic}} | ||
{{#isOAuth}}- **Type**: OAuth | ||
- **Flow**: {{flow}} | ||
- **Authorization URL**: {{authorizationUrl}} | ||
- **Scopes**: {{^scopes}}N/A{{/scopes}} | ||
{{#scopes}} - {{scope}}: {{description}} | ||
{{/scopes}} | ||
{{/isOAuth}} | ||
|
||
{{/authMethods}} |
53 changes: 53 additions & 0 deletions
53
modules/openapi-generator/src/main/resources/kotlin-vertx-server/api.mustache
This file contains hidden or 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,53 @@ | ||
package {{package}} | ||
|
||
{{#imports}}import {{import}} | ||
{{/imports}} | ||
import io.vertx.core.Vertx | ||
import io.vertx.core.json.JsonObject | ||
import io.vertx.core.json.JsonArray | ||
import com.github.wooyme.openapi.Response | ||
import io.vertx.ext.web.api.OperationRequest | ||
import io.vertx.kotlin.ext.web.api.contract.openapi3.OpenAPI3RouterFactory | ||
import io.vertx.serviceproxy.ServiceBinder | ||
import io.vertx.ext.web.handler.CookieHandler | ||
import io.vertx.ext.web.handler.SessionHandler | ||
import io.vertx.ext.web.sstore.LocalSessionStore | ||
import java.util.List | ||
import java.util.Map | ||
|
||
|
||
interface {{classname}} { | ||
fun init(vertx:Vertx,config:JsonObject) | ||
{{#operations}} | ||
{{#operation}} | ||
/* {{operationId}} | ||
* {{summary}} */ | ||
suspend fun {{operationId}}({{#allParams}}{{paramName}}:{{^isFile}}{{{dataType}}}{{/isFile}}{{#isFile}}kotlin.collections.List<java.io.File>{{/isFile}}{{^isRequired}}?{{/isRequired}},{{/allParams}}context:OperationRequest):Response<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Void{{/returnType}}> | ||
{{/operation}} | ||
{{/operations}} | ||
companion object { | ||
const val address = "{{classname}}-service" | ||
suspend fun createRouterFactory(vertx: Vertx,path:String): io.vertx.ext.web.api.contract.openapi3.OpenAPI3RouterFactory { | ||
val routerFactory = OpenAPI3RouterFactory.createAwait(vertx,path) | ||
routerFactory.addGlobalHandler(CookieHandler.create()) | ||
routerFactory.addGlobalHandler(SessionHandler.create(LocalSessionStore.create(vertx))) | ||
routerFactory.setExtraOperationContextPayloadMapper{ | ||
JsonObject().put("files",JsonArray(it.fileUploads().map { it.uploadedFileName() })) | ||
} | ||
val opf = routerFactory::class.java.getDeclaredField("operations") | ||
opf.isAccessible = true | ||
val operations = opf.get(routerFactory) as Map<String, Any> | ||
for (m in {{classname}}::class.java.methods) { | ||
val methodName = m.name | ||
val op = operations[methodName] | ||
if (op != null) { | ||
val method = op::class.java.getDeclaredMethod("mountRouteToService",String::class.java,String::class.java) | ||
method.isAccessible = true | ||
method.invoke(op,address,methodName) | ||
} | ||
} | ||
routerFactory.mountServiceInterface({{classname}}::class.java, address) | ||
return routerFactory | ||
} | ||
} | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.