From 5e159be3d1169e0472f135df20fc94030167e2f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20Lepp=C3=A4?= Date: Wed, 10 Nov 2021 06:50:10 +0200 Subject: [PATCH 01/13] Added templates for Kotlin JAX-RS server --- .../additionalModelTypeAnnotations.mustache | 2 + .../libraries.jaxrs-spec/api.mustache | 30 ++++++++ .../apiInterface.mustache | 13 ++++ .../libraries.jaxrs-spec/apiMethod.mustache | 16 ++++ .../beanValidation.mustache | 5 ++ .../beanValidationCore.mustache | 20 +++++ .../beanValidationHeaderParams.mustache | 1 + .../beanValidationPathParams.mustache | 1 + .../beanValidationQueryParams.mustache | 1 + .../libraries.jaxrs-spec/bodyParams.mustache | 1 + .../build.gradle.mustache | 57 +++++++++++++++ .../cookieParams.mustache | 1 + .../libraries.jaxrs-spec/data_class.mustache | 73 +++++++++++++++++++ .../data_class_opt_var.mustache | 4 + .../data_class_req_var.mustache | 4 + .../libraries.jaxrs-spec/enum_class.mustache | 58 +++++++++++++++ .../libraries.jaxrs-spec/enum_doc.mustache | 7 ++ .../libraries.jaxrs-spec/formParams.mustache | 1 + .../generatedAnnotation.mustache | 1 + .../libraries.jaxrs-spec/gradle.properties | 1 + .../headerParams.mustache | 1 + .../libraries.jaxrs-spec/model.mustache | 14 ++++ .../libraries.jaxrs-spec/model_doc.mustache | 3 + .../libraries.jaxrs-spec/pathParams.mustache | 1 + .../libraries.jaxrs-spec/queryParams.mustache | 1 + 25 files changed, 317 insertions(+) create mode 100644 modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/additionalModelTypeAnnotations.mustache create mode 100644 modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/api.mustache create mode 100644 modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/apiInterface.mustache create mode 100644 modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/apiMethod.mustache create mode 100644 modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/beanValidation.mustache create mode 100644 modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/beanValidationCore.mustache create mode 100644 modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/beanValidationHeaderParams.mustache create mode 100644 modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/beanValidationPathParams.mustache create mode 100644 modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/beanValidationQueryParams.mustache create mode 100644 modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/bodyParams.mustache create mode 100644 modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/build.gradle.mustache create mode 100644 modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/cookieParams.mustache create mode 100644 modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/data_class.mustache create mode 100644 modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/data_class_opt_var.mustache create mode 100644 modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/data_class_req_var.mustache create mode 100644 modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/enum_class.mustache create mode 100644 modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/enum_doc.mustache create mode 100644 modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/formParams.mustache create mode 100644 modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/generatedAnnotation.mustache create mode 100644 modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/gradle.properties create mode 100644 modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/headerParams.mustache create mode 100644 modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/model.mustache create mode 100644 modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/model_doc.mustache create mode 100644 modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/pathParams.mustache create mode 100644 modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/queryParams.mustache diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/additionalModelTypeAnnotations.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/additionalModelTypeAnnotations.mustache new file mode 100644 index 000000000000..f4871c02cc2e --- /dev/null +++ b/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/additionalModelTypeAnnotations.mustache @@ -0,0 +1,2 @@ +{{#additionalModelTypeAnnotations}}{{{.}}} +{{/additionalModelTypeAnnotations}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/api.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/api.mustache new file mode 100644 index 000000000000..324fc735d348 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/api.mustache @@ -0,0 +1,30 @@ +package {{package}}; + +{{#imports}}import {{import}} +{{/imports}} + +import javax.ws.rs.* +import javax.ws.rs.core.Response + +{{#useSwaggerAnnotations}} +import io.swagger.annotations.* +{{/useSwaggerAnnotations}} + +import java.io.InputStream +import java.util.Map +import java.util.List +{{#useBeanValidation}}import javax.validation.constraints.* +import javax.validation.Valid{{/useBeanValidation}} + +{{#useSwaggerAnnotations}} +@Api(description = "the {{{baseName}}} API"){{/useSwaggerAnnotations}}{{#hasConsumes}} +@Consumes({ {{#consumes}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/consumes}} }){{/hasConsumes}}{{#hasProduces}} +@Produces({ {{#produces}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/produces}} }){{/hasProduces}} +{{>generatedAnnotation}}{{#interfaceOnly}}interface{{/interfaceOnly}}{{^interfaceOnly}}class{{/interfaceOnly}} {{classname}} { +{{#operations}} +{{#operation}} + +{{#interfaceOnly}}{{>apiInterface}}{{/interfaceOnly}}{{^interfaceOnly}}{{>apiMethod}}{{/interfaceOnly}} +{{/operation}} +} +{{/operations}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/apiInterface.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/apiInterface.mustache new file mode 100644 index 000000000000..4d93916d1166 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/apiInterface.mustache @@ -0,0 +1,13 @@ + @{{httpMethod}} + @Path("{{{path}}}"){{#hasConsumes}} + @Consumes({{#consumes}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/consumes}}){{/hasConsumes}}{{#hasProduces}} + @Produces({{#produces}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/produces}}){{/hasProduces}}{{#useSwaggerAnnotations}} + @ApiOperation(value = "{{{summary}}}", notes = "{{{notes}}}"{{#hasAuthMethods}}, authorizations = { + {{#authMethods}}{{#isOAuth}}@Authorization(value = "{{name}}", scopes = { + {{#scopes}}@AuthorizationScope(scope = "{{scope}}", description = "{{description}}"){{^-last}}, + {{/-last}}{{/scopes}} }){{^-last}},{{/-last}}{{/isOAuth}} + {{^isOAuth}}@Authorization(value = "{{name}}"){{^-last}},{{/-last}} + {{/isOAuth}}{{/authMethods}} }{{/hasAuthMethods}}, tags={ {{#vendorExtensions.x-tags}}"{{tag}}"{{^-last}}, {{/-last}}{{/vendorExtensions.x-tags}} }) + @ApiResponses(value = { {{#responses}} + @ApiResponse(code = {{{code}}}, message = "{{{message}}}", response = {{{baseType}}}.class{{#returnContainer}}, responseContainer = "{{{.}}}"{{/returnContainer}}){{^-last}},{{/-last}}{{/responses}} }){{/useSwaggerAnnotations}} + fun {{nickname}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{^-last}},{{/-last}}{{/allParams}}){{#returnResponse}}: Response{{/returnResponse}}{{^returnResponse}}{{#returnType}}: {{{returnType}}}{{/returnType}}{{/returnResponse}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/apiMethod.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/apiMethod.mustache new file mode 100644 index 000000000000..1063877aa9a1 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/apiMethod.mustache @@ -0,0 +1,16 @@ + @{{httpMethod}}{{#subresourceOperation}} + @Path("{{{path}}}"){{/subresourceOperation}}{{#hasConsumes}} + @Consumes({{#consumes}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/consumes}}){{/hasConsumes}}{{#hasProduces}} + @Produces({{#produces}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/produces}}){{/hasProduces}}{{#useSwaggerAnnotations}} + @ApiOperation(value = "{{{summary}}}", notes = "{{{notes}}}", response = {{{returnBaseType}}}.class{{#returnContainer}}, responseContainer = "{{{.}}}"{{/returnContainer}}{{#hasAuthMethods}}, authorizations = { + {{#authMethods}}{{#isOAuth}}@Authorization(value = "{{name}}", scopes = { + {{#scopes}}@AuthorizationScope(scope = "{{scope}}", description = "{{description}}"){{^-last}}, + {{/-last}}{{/scopes}} }){{^-last}},{{/-last}}{{/isOAuth}} + {{^isOAuth}}@Authorization(value = "{{name}}"){{^-last}},{{/-last}} + {{/isOAuth}}{{/authMethods}} }{{/hasAuthMethods}}, tags={ {{#vendorExtensions.x-tags}}"{{tag}}"{{^-last}}, {{/-last}}{{/vendorExtensions.x-tags}} }) + @ApiResponses(value = { {{#responses}} + @ApiResponse(code = {{{code}}}, message = "{{{message}}}", response = {{{baseType}}}.class{{#containerType}}, responseContainer = "{{{.}}}"{{/containerType}}){{^-last}},{{/-last}}{{/responses}} + }){{/useSwaggerAnnotations}} + fun {{nickname}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>cookieParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{^-last}},{{/-last}}{{/allParams}}): Response { + return Response.ok().entity("magic!").build(); + } \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/beanValidation.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/beanValidation.mustache new file mode 100644 index 000000000000..ef7ab3fb7a9f --- /dev/null +++ b/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/beanValidation.mustache @@ -0,0 +1,5 @@ + @Valid +{{#required}} + @NotNull +{{/required}} +{{>beanValidationCore}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/beanValidationCore.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/beanValidationCore.mustache new file mode 100644 index 000000000000..d6e2f13b457c --- /dev/null +++ b/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/beanValidationCore.mustache @@ -0,0 +1,20 @@ +{{#pattern}} @Pattern(regexp="{{{.}}}"){{/pattern}}{{! +minLength && maxLength set +}}{{#minLength}}{{#maxLength}} @Size(min={{minLength}},max={{maxLength}}){{/maxLength}}{{/minLength}}{{! +minLength set, maxLength not +}}{{#minLength}}{{^maxLength}} @Size(min={{minLength}}){{/maxLength}}{{/minLength}}{{! +minLength not set, maxLength set +}}{{^minLength}}{{#maxLength}} @Size(max={{.}}){{/maxLength}}{{/minLength}}{{! +@Size: minItems && maxItems set +}}{{#minItems}}{{#maxItems}} @Size(min={{minItems}},max={{maxItems}}){{/maxItems}}{{/minItems}}{{! +@Size: minItems set, maxItems not +}}{{#minItems}}{{^maxItems}} @Size(min={{minItems}}){{/maxItems}}{{/minItems}}{{! +@Size: minItems not set && maxItems set +}}{{^minItems}}{{#maxItems}} @Size(max={{.}}){{/maxItems}}{{/minItems}}{{! +check for integer or long / all others=decimal type with @Decimal* +isInteger set +}}{{#isInteger}}{{#minimum}} @Min({{.}}){{/minimum}}{{#maximum}} @Max({{.}}){{/maximum}}{{/isInteger}}{{! +isLong set +}}{{#isLong}}{{#minimum}} @Min({{.}}L){{/minimum}}{{#maximum}} @Max({{.}}L){{/maximum}}{{/isLong}}{{! +Not Integer, not Long => we have a decimal value! +}}{{^isInteger}}{{^isLong}}{{#minimum}} @DecimalMin({{#exclusiveMinimum}}value={{/exclusiveMinimum}}"{{minimum}}"{{#exclusiveMinimum}},inclusive=false{{/exclusiveMinimum}}){{/minimum}}{{#maximum}} @DecimalMax({{#exclusiveMaximum}}value={{/exclusiveMaximum}}"{{maximum}}"{{#exclusiveMaximum}},inclusive=false{{/exclusiveMaximum}}){{/maximum}}{{/isLong}}{{/isInteger}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/beanValidationHeaderParams.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/beanValidationHeaderParams.mustache new file mode 100644 index 000000000000..c4ff01d7e552 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/beanValidationHeaderParams.mustache @@ -0,0 +1 @@ +{{#required}} @NotNull{{/required}}{{>beanValidationCore}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/beanValidationPathParams.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/beanValidationPathParams.mustache new file mode 100644 index 000000000000..051bd53c0a58 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/beanValidationPathParams.mustache @@ -0,0 +1 @@ +{{! PathParam is always required, no @NotNull necessary }}{{>beanValidationCore}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/beanValidationQueryParams.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/beanValidationQueryParams.mustache new file mode 100644 index 000000000000..c4ff01d7e552 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/beanValidationQueryParams.mustache @@ -0,0 +1 @@ +{{#required}} @NotNull{{/required}}{{>beanValidationCore}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/bodyParams.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/bodyParams.mustache new file mode 100644 index 000000000000..8f84440fdb2c --- /dev/null +++ b/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/bodyParams.mustache @@ -0,0 +1 @@ +{{#isBodyParam}}{{#useBeanValidation}}@Valid {{#required}}{{^isNullable}}@NotNull {{/isNullable}}{{/required}}{{/useBeanValidation}} {{paramName}}: {{{dataType}}}{{/isBodyParam}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/build.gradle.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/build.gradle.mustache new file mode 100644 index 000000000000..639084ec35b0 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/build.gradle.mustache @@ -0,0 +1,57 @@ +group "{{groupId}}" +version "{{artifactVersion}}" + +wrapper { + gradleVersion = "6.9" + distributionUrl = "https://services.gradle.org/distributions/gradle-$gradleVersion-all.zip" +} + +buildscript { + ext.kotlin_version = "1.4.32" + ext.jakarta_ws_rs_version = "2.1.6" + ext.swagger_annotations_version = "1.5.3" + ext.jakarta_annotations_version = "1.3.5" + ext.jackson_version = "2.9.9" +{{#useBeanValidation}} + ext.beanvalidation_version = "2.0.2" +{{/useBeanValidation}} + repositories { + maven { url "https://repo1.maven.org/maven2" } + maven { url "https://plugins.gradle.org/m2/" } + } + dependencies { + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version") + } +} + +apply plugin: "java" +apply plugin: "kotlin" +apply plugin: "application" + +sourceCompatibility = 1.8 + +compileKotlin { + kotlinOptions.jvmTarget = "1.8" +} + +compileTestKotlin { + kotlinOptions.jvmTarget = "1.8" +} + +repositories { + maven { setUrl("https://repo1.maven.org/maven2") } +} + +dependencies { + implementation("org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version") + implementation("ch.qos.logback:logback-classic:1.2.1") + implementation("jakarta.ws.rs:jakarta.ws.rs-api:$jakarta_ws_rs_version") + implementation("jakarta.annotation:jakarta.annotation-api:$jakarta_annotations_version") + implementation("io.swagger:swagger-annotations:$swagger_annotations_version") + implementation("com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:$jackson_version") + implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jackson_version") +{{#useBeanValidation}} + implementation("jakarta.validation:jakarta.validation-api:$beanvalidation_version") +{{/useBeanValidation}} + testImplementation("junit:junit:4.13.2") +} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/cookieParams.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/cookieParams.mustache new file mode 100644 index 000000000000..0d015d6cf68f --- /dev/null +++ b/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/cookieParams.mustache @@ -0,0 +1 @@ +{{#isCookieParam}}@CookieParam("{{baseName}}"){{#useBeanValidation}}{{>beanValidationQueryParams}}{{/useBeanValidation}}{{^isContainer}}{{#defaultValue}} @DefaultValue("{{{.}}}"){{/defaultValue}}{{/isContainer}} {{#useSwaggerAnnotations}}{{#description}} @ApiParam("{{.}}"){{/description}}{{/useSwaggerAnnotations}} {{{dataType}}} {{paramName}}{{/isCookieParam}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/data_class.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/data_class.mustache new file mode 100644 index 000000000000..c0fdd457ba7b --- /dev/null +++ b/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/data_class.mustache @@ -0,0 +1,73 @@ +import com.fasterxml.jackson.annotation.JsonProperty +{{#kotlinx_serialization}} +import {{#serializableModel}}kotlinx.serialization.Serializable as KSerializable{{/serializableModel}}{{^serializableModel}}kotlinx.serialization.Serializable{{/serializableModel}} +import kotlinx.serialization.SerialName +import kotlinx.serialization.Contextual +{{#hasEnums}} +{{/hasEnums}} +{{/kotlinx_serialization}} +{{#parcelizeModels}} +import android.os.Parcelable +import kotlinx.parcelize.Parcelize +{{/parcelizeModels}} +{{#serializableModel}} +import java.io.Serializable +{{/serializableModel}} +/** + * {{{description}}} + * +{{#allVars}} + * @param {{{name}}} {{{description}}} +{{/allVars}} + */ +{{#parcelizeModels}} +@Parcelize +{{/parcelizeModels}} +{{#multiplatform}}{{^discriminator}}@Serializable{{/discriminator}}{{/multiplatform}}{{#kotlinx_serialization}}{{#serializableModel}}@KSerializable{{/serializableModel}}{{^serializableModel}}@Serializable{{/serializableModel}}{{/kotlinx_serialization}}{{#moshi}}{{#moshiCodeGen}}@JsonClass(generateAdapter = true){{/moshiCodeGen}}{{/moshi}}{{#jackson}}{{#discriminator}}{{>typeInfoAnnotation}}{{/discriminator}}{{/jackson}} +{{#isDeprecated}} +@Deprecated(message = "This schema is deprecated.") +{{/isDeprecated}} +{{>additionalModelTypeAnnotations}} +{{#nonPublicApi}}internal {{/nonPublicApi}}{{#discriminator}}interface{{/discriminator}}{{^discriminator}}data class{{/discriminator}} {{classname}}{{^discriminator}} ( + +{{#allVars}} +{{#required}}{{>data_class_req_var}}{{/required}}{{^required}}{{>data_class_opt_var}}{{/required}}{{^-last}},{{/-last}} + +{{/allVars}} +){{/discriminator}}{{#parent}}{{^serializableModel}}{{^parcelizeModels}} : {{{parent}}}{{#isMap}}(){{/isMap}}{{#isArray}}(){{/isArray}}{{/parcelizeModels}}{{/serializableModel}}{{/parent}}{{#parent}}{{#serializableModel}}{{^parcelizeModels}} : {{{parent}}}{{#isMap}}(){{/isMap}}{{#isArray}}(){{/isArray}}, Serializable{{/parcelizeModels}}{{/serializableModel}}{{/parent}}{{#parent}}{{^serializableModel}}{{#parcelizeModels}} : {{{parent}}}{{#isMap}}(){{/isMap}}{{#isArray}}(){{/isArray}}, Parcelable{{/parcelizeModels}}{{/serializableModel}}{{/parent}}{{#parent}}{{#serializableModel}}{{#parcelizeModels}} : {{{parent}}}{{#isMap}}(){{/isMap}}{{#isArray}}(){{/isArray}}, Serializable, Parcelable{{/parcelizeModels}}{{/serializableModel}}{{/parent}}{{^parent}}{{#serializableModel}}{{^parcelizeModels}} : Serializable{{/parcelizeModels}}{{/serializableModel}}{{/parent}}{{^parent}}{{^serializableModel}}{{#parcelizeModels}} : Parcelable{{/parcelizeModels}}{{/serializableModel}}{{/parent}}{{^parent}}{{#serializableModel}}{{#parcelizeModels}} : Serializable, Parcelable{{/parcelizeModels}}{{/serializableModel}}{{/parent}}{{#vendorExtensions.x-has-data-class-body}} { +{{/vendorExtensions.x-has-data-class-body}} +{{#serializableModel}} + {{#nonPublicApi}}internal {{/nonPublicApi}}companion object { + private const val serialVersionUID: Long = 123 + } +{{/serializableModel}} +{{#discriminator}}{{#vars}}{{#required}} +{{>interface_req_var}}{{/required}}{{^required}} +{{>interface_opt_var}}{{/required}}{{/vars}}{{/discriminator}} +{{#hasEnums}} +{{#vars}} +{{#isEnum}} + /** + * {{{description}}} + * + * Values: {{#allowableValues}}{{#enumVars}}{{&name}}{{^-last}},{{/-last}}{{/enumVars}}{{/allowableValues}} + */ + {{#kotlinx_serialization}} + {{#serializableModel}}@KSerializable{{/serializableModel}}{{^serializableModel}}@Serializable{{/serializableModel}} + {{/kotlinx_serialization}} + {{#nonPublicApi}}internal {{/nonPublicApi}}enum class {{{nameInCamelCase}}}(val value: {{^isContainer}}{{dataType}}{{/isContainer}}{{#isContainer}}kotlin.String{{/isContainer}}) { + {{#allowableValues}} + {{#enumVars}} + @JsonProperty(value = {{^isString}}"{{/isString}}{{{value}}}{{^isString}}"{{/isString}}) {{&name}}({{{value}}}){{^-last}},{{/-last}}{{#-last}};{{/-last}} + {{#kotlinx_serialization}} + @SerialName(value = {{^isString}}"{{/isString}}{{{value}}}{{^isString}}"{{/isString}}) {{&name}}({{{value}}}){{^-last}},{{/-last}}{{#-last}};{{/-last}} + {{/kotlinx_serialization}} + {{/enumVars}} + {{/allowableValues}} + } +{{/isEnum}} +{{/vars}} +{{/hasEnums}} +{{#vendorExtensions.x-has-data-class-body}} +} +{{/vendorExtensions.x-has-data-class-body}} diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/data_class_opt_var.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/data_class_opt_var.mustache new file mode 100644 index 000000000000..a630d086e44e --- /dev/null +++ b/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/data_class_opt_var.mustache @@ -0,0 +1,4 @@ +{{#description}} + /* {{{.}}} */ +{{/description}} +{{#useBeanValidation}}{{>beanValidation}}{{/useBeanValidation}} {{>modelMutable}} {{{name}}}: {{#isEnum}}{{classname}}.{{nameInCamelCase}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}? = {{{defaultValue}}}{{^defaultValue}}null{{/defaultValue}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/data_class_req_var.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/data_class_req_var.mustache new file mode 100644 index 000000000000..7845eb3000a5 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/data_class_req_var.mustache @@ -0,0 +1,4 @@ +{{#description}} + /* {{{.}}} */ +{{/description}} +{{#useBeanValidation}}{{>beanValidation}}{{/useBeanValidation}} {{>modelMutable}} {{{name}}}: {{#isEnum}}{{classname}}.{{nameInCamelCase}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/enum_class.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/enum_class.mustache new file mode 100644 index 000000000000..005b9daa5965 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/enum_class.mustache @@ -0,0 +1,58 @@ +import com.fasterxml.jackson.annotation.JsonProperty +{{#kotlinx_serialization}} +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable +{{/kotlinx_serialization}} + +/** + * {{{description}}} + * + * Values: {{#allowableValues}}{{#enumVars}}{{&name}}{{^-last}},{{/-last}}{{/enumVars}}{{/allowableValues}} + */ +{{#kotlinx_serialization}}@Serializable{{/kotlinx_serialization}} +{{>additionalModelTypeAnnotations}} +{{#nonPublicApi}}internal {{/nonPublicApi}}enum class {{classname}}(val value: {{{dataType}}}) { +{{#allowableValues}}{{#enumVars}} + @JsonProperty(value = {{^isString}}"{{/isString}}{{{value}}}{{^isString}}"{{/isString}}) + {{#kotlinx_serialization}} + @SerialName(value = {{^isString}}"{{/isString}}{{{value}}}{{^isString}}"{{/isString}}) + {{/kotlinx_serialization}} + {{#isArray}} + {{#isList}} + {{&name}}(listOf({{{value}}})){{^-last}},{{/-last}}{{#-last}};{{/-last}} + {{/isList}} + {{^isList}} + {{&name}}(arrayOf({{{value}}})){{^-last}},{{/-last}}{{#-last}};{{/-last}} + {{/isList}} + {{/isArray}} + {{^isArray}} + {{&name}}({{{value}}}){{^-last}},{{/-last}}{{#-last}};{{/-last}} + {{/isArray}} +{{/enumVars}}{{/allowableValues}} + /** + * Override toString() to avoid using the enum variable name as the value, and instead use + * the actual value defined in the API spec file. + * + * This solves a problem when the variable name and its value are different, and ensures that + * the client sends the correct enum values to the server always. + */ + override fun toString(): String = value{{^isString}}.toString(){{/isString}} + + companion object { + /** + * Converts the provided [data] to a [String] on success, null otherwise. + */ + fun encode(data: Any?): kotlin.String? = if (data is {{classname}}) "$data" else null + + /** + * Returns a valid [{{classname}}] for [data], null otherwise. + */ + @OptIn(ExperimentalStdlibApi::class) + fun decode(data: Any?): {{classname}}? = data?.let { + val normalizedData = "$it".lowercase() + values().firstOrNull { value -> + it == value || normalizedData == "$value".lowercase() + } + } + } +} diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/enum_doc.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/enum_doc.mustache new file mode 100644 index 000000000000..fcb3d7e61aa6 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/enum_doc.mustache @@ -0,0 +1,7 @@ +# {{classname}} + +## Enum + +{{#allowableValues}}{{#enumVars}} + * `{{name}}` (value: `{{{value}}}`) +{{/enumVars}}{{/allowableValues}} diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/formParams.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/formParams.mustache new file mode 100644 index 000000000000..aaac9d8dce23 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/formParams.mustache @@ -0,0 +1 @@ +{{#isFormParam}}{{^isFile}}@FormParam(value = "{{baseName}}") {{paramName}}: {{{dataType}}}{{/isFile}}{{#isFile}} @FormParam(value = "{{baseName}}") {{paramName}}InputStream: InputStream{{/isFile}}{{/isFormParam}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/generatedAnnotation.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/generatedAnnotation.mustache new file mode 100644 index 000000000000..624b44019ad7 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/generatedAnnotation.mustache @@ -0,0 +1 @@ +@javax.annotation.Generated(value = arrayOf("{{generatorClass}}"){{^hideGenerationTimestamp}}, date = "{{generatedDate}}"{{/hideGenerationTimestamp}}) \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/gradle.properties b/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/gradle.properties new file mode 100644 index 000000000000..5f1ed7bbe024 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/gradle.properties @@ -0,0 +1 @@ +org.gradle.caching=true \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/headerParams.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/headerParams.mustache new file mode 100644 index 000000000000..c5ded586f7f6 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/headerParams.mustache @@ -0,0 +1 @@ +{{#isHeaderParam}}@HeaderParam("{{baseName}}"){{#useBeanValidation}}{{>beanValidationHeaderParams}}{{/useBeanValidation}} {{#defaultValue}} @DefaultValue("{{{.}}}"){{/defaultValue}} {{#useSwaggerAnnotations}}{{#description}} @ApiParam("{{.}}"){{/description}}{{/useSwaggerAnnotations}} {{paramName}}: {{{dataType}}}{{/isHeaderParam}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/model.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/model.mustache new file mode 100644 index 000000000000..f0c59426d3a0 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/model.mustache @@ -0,0 +1,14 @@ +{{>licenseInfo}} +package {{modelPackage}} + +{{#imports}}import {{import}} +{{/imports}} +{{#useBeanValidation}} +import javax.validation.constraints.* +import javax.validation.Valid +{{/useBeanValidation}} +{{#models}} +{{#model}} +{{#isEnum}}{{>enum_class}}{{/isEnum}}{{^isEnum}}{{#isAlias}}typealias {{classname}} = {{{dataType}}}{{/isAlias}}{{^isAlias}}{{>data_class}}{{/isAlias}}{{/isEnum}} +{{/model}} +{{/models}} diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/model_doc.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/model_doc.mustache new file mode 100644 index 000000000000..e3b718421188 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/model_doc.mustache @@ -0,0 +1,3 @@ +{{#models}}{{#model}} +{{#isEnum}}{{>enum_doc}}{{/isEnum}}{{^isEnum}}{{>class_doc}}{{/isEnum}} +{{/model}}{{/models}} diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/pathParams.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/pathParams.mustache new file mode 100644 index 000000000000..7839f91302bb --- /dev/null +++ b/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/pathParams.mustache @@ -0,0 +1 @@ +{{#isPathParam}}@PathParam("{{baseName}}"){{#useBeanValidation}}{{>beanValidationPathParams}}{{/useBeanValidation}}{{#useSwaggerAnnotations}}{{#description}} @ApiParam("{{.}}"){{/description}}{{/useSwaggerAnnotations}} {{paramName}}: {{{dataType}}}{{/isPathParam}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/queryParams.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/queryParams.mustache new file mode 100644 index 000000000000..bc173cb68a2e --- /dev/null +++ b/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/queryParams.mustache @@ -0,0 +1 @@ +{{#isQueryParam}}@QueryParam("{{baseName}}"){{#useBeanValidation}}{{>beanValidationQueryParams}}{{/useBeanValidation}}{{^isContainer}}{{#defaultValue}} @DefaultValue("{{{.}}}"){{/defaultValue}}{{/isContainer}} {{#useSwaggerAnnotations}}{{#description}} @ApiParam("{{.}}"){{/description}}{{/useSwaggerAnnotations}} {{paramName}}: {{{dataType}}}{{/isQueryParam}} \ No newline at end of file From ecfb5a2d2adef2263c79f51b84efee1388a608bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20Lepp=C3=A4?= Date: Wed, 10 Nov 2021 07:14:55 +0200 Subject: [PATCH 02/13] Fixed Kotlin Server JAX-RS template directory --- .../jaxrs-spec}/additionalModelTypeAnnotations.mustache | 0 .../{libraries.jaxrs-spec => libraries/jaxrs-spec}/api.mustache | 0 .../jaxrs-spec}/apiInterface.mustache | 0 .../jaxrs-spec}/apiMethod.mustache | 0 .../jaxrs-spec}/beanValidation.mustache | 0 .../jaxrs-spec}/beanValidationCore.mustache | 0 .../jaxrs-spec}/beanValidationHeaderParams.mustache | 0 .../jaxrs-spec}/beanValidationPathParams.mustache | 0 .../jaxrs-spec}/beanValidationQueryParams.mustache | 0 .../jaxrs-spec}/bodyParams.mustache | 0 .../jaxrs-spec}/build.gradle.mustache | 0 .../jaxrs-spec}/cookieParams.mustache | 0 .../jaxrs-spec}/data_class.mustache | 0 .../jaxrs-spec}/data_class_opt_var.mustache | 0 .../jaxrs-spec}/data_class_req_var.mustache | 0 .../jaxrs-spec}/enum_class.mustache | 0 .../jaxrs-spec}/enum_doc.mustache | 0 .../jaxrs-spec}/formParams.mustache | 0 .../jaxrs-spec}/generatedAnnotation.mustache | 0 .../jaxrs-spec}/gradle.properties | 0 .../jaxrs-spec}/headerParams.mustache | 0 .../{libraries.jaxrs-spec => libraries/jaxrs-spec}/model.mustache | 0 .../jaxrs-spec}/model_doc.mustache | 0 .../jaxrs-spec}/pathParams.mustache | 0 .../jaxrs-spec}/queryParams.mustache | 0 25 files changed, 0 insertions(+), 0 deletions(-) rename modules/openapi-generator/src/main/resources/kotlin-server/{libraries.jaxrs-spec => libraries/jaxrs-spec}/additionalModelTypeAnnotations.mustache (100%) rename modules/openapi-generator/src/main/resources/kotlin-server/{libraries.jaxrs-spec => libraries/jaxrs-spec}/api.mustache (100%) rename modules/openapi-generator/src/main/resources/kotlin-server/{libraries.jaxrs-spec => libraries/jaxrs-spec}/apiInterface.mustache (100%) rename modules/openapi-generator/src/main/resources/kotlin-server/{libraries.jaxrs-spec => libraries/jaxrs-spec}/apiMethod.mustache (100%) rename modules/openapi-generator/src/main/resources/kotlin-server/{libraries.jaxrs-spec => libraries/jaxrs-spec}/beanValidation.mustache (100%) rename modules/openapi-generator/src/main/resources/kotlin-server/{libraries.jaxrs-spec => libraries/jaxrs-spec}/beanValidationCore.mustache (100%) rename modules/openapi-generator/src/main/resources/kotlin-server/{libraries.jaxrs-spec => libraries/jaxrs-spec}/beanValidationHeaderParams.mustache (100%) rename modules/openapi-generator/src/main/resources/kotlin-server/{libraries.jaxrs-spec => libraries/jaxrs-spec}/beanValidationPathParams.mustache (100%) rename modules/openapi-generator/src/main/resources/kotlin-server/{libraries.jaxrs-spec => libraries/jaxrs-spec}/beanValidationQueryParams.mustache (100%) rename modules/openapi-generator/src/main/resources/kotlin-server/{libraries.jaxrs-spec => libraries/jaxrs-spec}/bodyParams.mustache (100%) rename modules/openapi-generator/src/main/resources/kotlin-server/{libraries.jaxrs-spec => libraries/jaxrs-spec}/build.gradle.mustache (100%) rename modules/openapi-generator/src/main/resources/kotlin-server/{libraries.jaxrs-spec => libraries/jaxrs-spec}/cookieParams.mustache (100%) rename modules/openapi-generator/src/main/resources/kotlin-server/{libraries.jaxrs-spec => libraries/jaxrs-spec}/data_class.mustache (100%) rename modules/openapi-generator/src/main/resources/kotlin-server/{libraries.jaxrs-spec => libraries/jaxrs-spec}/data_class_opt_var.mustache (100%) rename modules/openapi-generator/src/main/resources/kotlin-server/{libraries.jaxrs-spec => libraries/jaxrs-spec}/data_class_req_var.mustache (100%) rename modules/openapi-generator/src/main/resources/kotlin-server/{libraries.jaxrs-spec => libraries/jaxrs-spec}/enum_class.mustache (100%) rename modules/openapi-generator/src/main/resources/kotlin-server/{libraries.jaxrs-spec => libraries/jaxrs-spec}/enum_doc.mustache (100%) rename modules/openapi-generator/src/main/resources/kotlin-server/{libraries.jaxrs-spec => libraries/jaxrs-spec}/formParams.mustache (100%) rename modules/openapi-generator/src/main/resources/kotlin-server/{libraries.jaxrs-spec => libraries/jaxrs-spec}/generatedAnnotation.mustache (100%) rename modules/openapi-generator/src/main/resources/kotlin-server/{libraries.jaxrs-spec => libraries/jaxrs-spec}/gradle.properties (100%) rename modules/openapi-generator/src/main/resources/kotlin-server/{libraries.jaxrs-spec => libraries/jaxrs-spec}/headerParams.mustache (100%) rename modules/openapi-generator/src/main/resources/kotlin-server/{libraries.jaxrs-spec => libraries/jaxrs-spec}/model.mustache (100%) rename modules/openapi-generator/src/main/resources/kotlin-server/{libraries.jaxrs-spec => libraries/jaxrs-spec}/model_doc.mustache (100%) rename modules/openapi-generator/src/main/resources/kotlin-server/{libraries.jaxrs-spec => libraries/jaxrs-spec}/pathParams.mustache (100%) rename modules/openapi-generator/src/main/resources/kotlin-server/{libraries.jaxrs-spec => libraries/jaxrs-spec}/queryParams.mustache (100%) diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/additionalModelTypeAnnotations.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/additionalModelTypeAnnotations.mustache similarity index 100% rename from modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/additionalModelTypeAnnotations.mustache rename to modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/additionalModelTypeAnnotations.mustache diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/api.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/api.mustache similarity index 100% rename from modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/api.mustache rename to modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/api.mustache diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/apiInterface.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/apiInterface.mustache similarity index 100% rename from modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/apiInterface.mustache rename to modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/apiInterface.mustache diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/apiMethod.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/apiMethod.mustache similarity index 100% rename from modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/apiMethod.mustache rename to modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/apiMethod.mustache diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/beanValidation.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/beanValidation.mustache similarity index 100% rename from modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/beanValidation.mustache rename to modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/beanValidation.mustache diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/beanValidationCore.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/beanValidationCore.mustache similarity index 100% rename from modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/beanValidationCore.mustache rename to modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/beanValidationCore.mustache diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/beanValidationHeaderParams.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/beanValidationHeaderParams.mustache similarity index 100% rename from modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/beanValidationHeaderParams.mustache rename to modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/beanValidationHeaderParams.mustache diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/beanValidationPathParams.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/beanValidationPathParams.mustache similarity index 100% rename from modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/beanValidationPathParams.mustache rename to modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/beanValidationPathParams.mustache diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/beanValidationQueryParams.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/beanValidationQueryParams.mustache similarity index 100% rename from modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/beanValidationQueryParams.mustache rename to modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/beanValidationQueryParams.mustache diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/bodyParams.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/bodyParams.mustache similarity index 100% rename from modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/bodyParams.mustache rename to modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/bodyParams.mustache diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/build.gradle.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/build.gradle.mustache similarity index 100% rename from modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/build.gradle.mustache rename to modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/build.gradle.mustache diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/cookieParams.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/cookieParams.mustache similarity index 100% rename from modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/cookieParams.mustache rename to modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/cookieParams.mustache diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/data_class.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/data_class.mustache similarity index 100% rename from modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/data_class.mustache rename to modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/data_class.mustache diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/data_class_opt_var.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/data_class_opt_var.mustache similarity index 100% rename from modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/data_class_opt_var.mustache rename to modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/data_class_opt_var.mustache diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/data_class_req_var.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/data_class_req_var.mustache similarity index 100% rename from modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/data_class_req_var.mustache rename to modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/data_class_req_var.mustache diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/enum_class.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/enum_class.mustache similarity index 100% rename from modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/enum_class.mustache rename to modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/enum_class.mustache diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/enum_doc.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/enum_doc.mustache similarity index 100% rename from modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/enum_doc.mustache rename to modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/enum_doc.mustache diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/formParams.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/formParams.mustache similarity index 100% rename from modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/formParams.mustache rename to modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/formParams.mustache diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/generatedAnnotation.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/generatedAnnotation.mustache similarity index 100% rename from modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/generatedAnnotation.mustache rename to modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/generatedAnnotation.mustache diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/gradle.properties b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/gradle.properties similarity index 100% rename from modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/gradle.properties rename to modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/gradle.properties diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/headerParams.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/headerParams.mustache similarity index 100% rename from modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/headerParams.mustache rename to modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/headerParams.mustache diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/model.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/model.mustache similarity index 100% rename from modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/model.mustache rename to modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/model.mustache diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/model_doc.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/model_doc.mustache similarity index 100% rename from modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/model_doc.mustache rename to modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/model_doc.mustache diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/pathParams.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/pathParams.mustache similarity index 100% rename from modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/pathParams.mustache rename to modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/pathParams.mustache diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/queryParams.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/queryParams.mustache similarity index 100% rename from modules/openapi-generator/src/main/resources/kotlin-server/libraries.jaxrs-spec/queryParams.mustache rename to modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/queryParams.mustache From c2767bf9a7b1749bf77dfbb8a190c239dd735181 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20Lepp=C3=A4?= Date: Wed, 10 Nov 2021 07:15:44 +0200 Subject: [PATCH 03/13] Added support for Kotlin Server JAX-RS library --- .../languages/KotlinServerCodegen.java | 56 +++++++++++++++---- 1 file changed, 45 insertions(+), 11 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinServerCodegen.java index 3ad47e68fee3..74dc1282cf4f 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinServerCodegen.java @@ -23,6 +23,7 @@ import org.openapitools.codegen.CodegenConstants; import org.openapitools.codegen.CodegenType; import org.openapitools.codegen.SupportingFile; +import org.openapitools.codegen.languages.features.BeanValidationFeatures; import org.openapitools.codegen.meta.features.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -33,9 +34,12 @@ import java.util.List; import java.util.Map; -public class KotlinServerCodegen extends AbstractKotlinCodegen { +public class KotlinServerCodegen extends AbstractKotlinCodegen implements BeanValidationFeatures { + + public static final String INTERFACE_ONLY = "interfaceOnly"; public static final String DEFAULT_LIBRARY = Constants.KTOR; private final Logger LOGGER = LoggerFactory.getLogger(KotlinServerCodegen.class); + private Boolean autoHeadFeatureEnabled = true; private Boolean conditionalHeadersFeatureEnabled = false; private Boolean hstsFeatureEnabled = true; @@ -43,6 +47,8 @@ public class KotlinServerCodegen extends AbstractKotlinCodegen { private Boolean compressionFeatureEnabled = true; private Boolean locationsFeatureEnabled = true; private Boolean metricsFeatureEnabled = true; + private boolean interfaceOnly = false; + private boolean useBeanValidation = false; // This is here to potentially warn the user when an option is not supported by the target framework. private Map> optionsSupportedPerFramework = new ImmutableMap.Builder>() @@ -102,6 +108,7 @@ public KotlinServerCodegen() { modelPackage = packageName + ".models"; supportedLibraries.put(Constants.KTOR, "ktor framework"); + supportedLibraries.put(Constants.JAXRS_SPEC, "JAX-RS spec only"); // TODO: Configurable server engine. Defaults to netty in build.gradle. CliOption library = new CliOption(CodegenConstants.LIBRARY, CodegenConstants.LIBRARY_DESC); @@ -117,6 +124,9 @@ public KotlinServerCodegen() { addSwitch(Constants.COMPRESSION, Constants.COMPRESSION_DESC, getCompressionFeatureEnabled()); addSwitch(Constants.LOCATIONS, Constants.LOCATIONS_DESC, getLocationsFeatureEnabled()); addSwitch(Constants.METRICS, Constants.METRICS_DESC, getMetricsFeatureEnabled()); + + cliOptions.add(CliOption.newBoolean(INTERFACE_ONLY, "Whether to generate only API interface stubs without the server files.").defaultValue(String.valueOf(interfaceOnly))); + cliOptions.add(CliOption.newBoolean(USE_BEANVALIDATION, "Use BeanValidation API annotations",useBeanValidation)); } public Boolean getAutoHeadFeatureEnabled() { @@ -195,6 +205,19 @@ public void processOpts() { this.setLibrary((String) additionalProperties.get(CodegenConstants.LIBRARY)); } + if (additionalProperties.containsKey(INTERFACE_ONLY)) { + interfaceOnly = Boolean.parseBoolean(additionalProperties.get(INTERFACE_ONLY).toString()); + if (!interfaceOnly) { + additionalProperties.remove(INTERFACE_ONLY); + } + } + + if (additionalProperties.containsKey(USE_BEANVALIDATION)) { + setUseBeanValidation(convertPropertyToBoolean(USE_BEANVALIDATION)); + } + + writePropertyBack(USE_BEANVALIDATION, useBeanValidation); + // set default library to "ktor" if (StringUtils.isEmpty(library)) { this.setLibrary(DEFAULT_LIBRARY); @@ -249,29 +272,40 @@ public void processOpts() { String resourcesFolder = "src/main/resources"; // not sure this can be user configurable. supportingFiles.add(new SupportingFile("README.mustache", "", "README.md")); - supportingFiles.add(new SupportingFile("Dockerfile.mustache", "", "Dockerfile")); + + if (library.equals(Constants.KTOR)) { + supportingFiles.add(new SupportingFile("Dockerfile.mustache", "", "Dockerfile")); + } supportingFiles.add(new SupportingFile("build.gradle.mustache", "", "build.gradle")); supportingFiles.add(new SupportingFile("settings.gradle.mustache", "", "settings.gradle")); supportingFiles.add(new SupportingFile("gradle.properties", "", "gradle.properties")); - supportingFiles.add(new SupportingFile("AppMain.kt.mustache", packageFolder, "AppMain.kt")); - supportingFiles.add(new SupportingFile("Configuration.kt.mustache", packageFolder, "Configuration.kt")); + if (library.equals(Constants.KTOR)) { + supportingFiles.add(new SupportingFile("AppMain.kt.mustache", packageFolder, "AppMain.kt")); + supportingFiles.add(new SupportingFile("Configuration.kt.mustache", packageFolder, "Configuration.kt")); - if (generateApis && locationsFeatureEnabled) { - supportingFiles.add(new SupportingFile("Paths.kt.mustache", packageFolder, "Paths.kt")); - } + if (generateApis && locationsFeatureEnabled) { + supportingFiles.add(new SupportingFile("Paths.kt.mustache", packageFolder, "Paths.kt")); + } - supportingFiles.add(new SupportingFile("application.conf.mustache", resourcesFolder, "application.conf")); - supportingFiles.add(new SupportingFile("logback.xml", resourcesFolder, "logback.xml")); + supportingFiles.add(new SupportingFile("application.conf.mustache", resourcesFolder, "application.conf")); + supportingFiles.add(new SupportingFile("logback.xml", resourcesFolder, "logback.xml")); - final String infrastructureFolder = (sourceFolder + File.separator + packageName + File.separator + "infrastructure").replace(".", File.separator); + final String infrastructureFolder = (sourceFolder + File.separator + packageName + File.separator + "infrastructure").replace(".", File.separator); - supportingFiles.add(new SupportingFile("ApiKeyAuth.kt.mustache", infrastructureFolder, "ApiKeyAuth.kt")); + supportingFiles.add(new SupportingFile("ApiKeyAuth.kt.mustache", infrastructureFolder, "ApiKeyAuth.kt")); + } + } + + @Override + public void setUseBeanValidation(boolean useBeanValidation) { + this.useBeanValidation = useBeanValidation; } public static class Constants { public final static String KTOR = "ktor"; + public final static String JAXRS_SPEC = "jaxrs-spec"; 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"; From 7083116f43b476af79faa5e3c1f790e8b3698cc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20Lepp=C3=A4?= Date: Wed, 10 Nov 2021 07:30:48 +0200 Subject: [PATCH 04/13] Added support using coroutines with Kotlin server JAX-RS library --- .../codegen/languages/KotlinServerCodegen.java | 10 ++++++++++ .../libraries/jaxrs-spec/apiInterface.mustache | 2 +- .../libraries/jaxrs-spec/apiMethod.mustache | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinServerCodegen.java index 74dc1282cf4f..fcf8049c7900 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinServerCodegen.java @@ -37,6 +37,7 @@ public class KotlinServerCodegen extends AbstractKotlinCodegen implements BeanValidationFeatures { public static final String INTERFACE_ONLY = "interfaceOnly"; + public static final String USE_COROUTINES = "useCoroutines"; public static final String DEFAULT_LIBRARY = Constants.KTOR; private final Logger LOGGER = LoggerFactory.getLogger(KotlinServerCodegen.class); @@ -49,6 +50,7 @@ public class KotlinServerCodegen extends AbstractKotlinCodegen implements BeanVa private Boolean metricsFeatureEnabled = true; private boolean interfaceOnly = false; private boolean useBeanValidation = false; + private boolean useCoroutines = false; // This is here to potentially warn the user when an option is not supported by the target framework. private Map> optionsSupportedPerFramework = new ImmutableMap.Builder>() @@ -127,6 +129,7 @@ public KotlinServerCodegen() { cliOptions.add(CliOption.newBoolean(INTERFACE_ONLY, "Whether to generate only API interface stubs without the server files.").defaultValue(String.valueOf(interfaceOnly))); cliOptions.add(CliOption.newBoolean(USE_BEANVALIDATION, "Use BeanValidation API annotations",useBeanValidation)); + cliOptions.add(CliOption.newBoolean(USE_COROUTINES, "Whether to use the Coroutines with the JAX-RS library.")); } public Boolean getAutoHeadFeatureEnabled() { @@ -212,6 +215,13 @@ public void processOpts() { } } + if (additionalProperties.containsKey(USE_COROUTINES)) { + useCoroutines = Boolean.parseBoolean(additionalProperties.get(USE_COROUTINES).toString()); + if (!useCoroutines) { + additionalProperties.remove(USE_COROUTINES); + } + } + if (additionalProperties.containsKey(USE_BEANVALIDATION)) { setUseBeanValidation(convertPropertyToBoolean(USE_BEANVALIDATION)); } diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/apiInterface.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/apiInterface.mustache index 4d93916d1166..d64ab7579383 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/apiInterface.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/apiInterface.mustache @@ -10,4 +10,4 @@ {{/isOAuth}}{{/authMethods}} }{{/hasAuthMethods}}, tags={ {{#vendorExtensions.x-tags}}"{{tag}}"{{^-last}}, {{/-last}}{{/vendorExtensions.x-tags}} }) @ApiResponses(value = { {{#responses}} @ApiResponse(code = {{{code}}}, message = "{{{message}}}", response = {{{baseType}}}.class{{#returnContainer}}, responseContainer = "{{{.}}}"{{/returnContainer}}){{^-last}},{{/-last}}{{/responses}} }){{/useSwaggerAnnotations}} - fun {{nickname}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{^-last}},{{/-last}}{{/allParams}}){{#returnResponse}}: Response{{/returnResponse}}{{^returnResponse}}{{#returnType}}: {{{returnType}}}{{/returnType}}{{/returnResponse}} \ No newline at end of file + {{#useCoroutines}}suspend {{/useCoroutines}}fun {{nickname}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{^-last}},{{/-last}}{{/allParams}}){{#returnResponse}}: Response{{/returnResponse}}{{^returnResponse}}{{#returnType}}: {{{returnType}}}{{/returnType}}{{/returnResponse}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/apiMethod.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/apiMethod.mustache index 1063877aa9a1..bfe70607f176 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/apiMethod.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/apiMethod.mustache @@ -11,6 +11,6 @@ @ApiResponses(value = { {{#responses}} @ApiResponse(code = {{{code}}}, message = "{{{message}}}", response = {{{baseType}}}.class{{#containerType}}, responseContainer = "{{{.}}}"{{/containerType}}){{^-last}},{{/-last}}{{/responses}} }){{/useSwaggerAnnotations}} - fun {{nickname}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>cookieParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{^-last}},{{/-last}}{{/allParams}}): Response { + {{#useCoroutines}}suspend {{/useCoroutines}}fun {{nickname}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>cookieParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{^-last}},{{/-last}}{{/allParams}}): Response { return Response.ok().entity("magic!").build(); } \ No newline at end of file From 643cc0c79f1608c2664f07616437dd9f7ecf6ea4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20Lepp=C3=A4?= Date: Wed, 10 Nov 2021 09:32:43 +0200 Subject: [PATCH 05/13] Added sample for Kotlin server JAX-RS library --- bin/configs/kotlin-server-jaxrs-spec.yaml | 7 ++ .../jaxrs-spec/.openapi-generator-ignore | 23 +++++ .../jaxrs-spec/.openapi-generator/FILES | 14 +++ .../jaxrs-spec/.openapi-generator/VERSION | 1 + .../kotlin-server/jaxrs-spec/README.md | 89 +++++++++++++++++++ .../kotlin-server/jaxrs-spec/build.gradle | 51 +++++++++++ .../jaxrs-spec/gradle.properties | 1 + .../kotlin-server/jaxrs-spec/settings.gradle | 1 + .../org/openapitools/server/apis/PetApi.kt | 65 ++++++++++++++ .../org/openapitools/server/apis/StoreApi.kt | 39 ++++++++ .../org/openapitools/server/apis/UserApi.kt | 58 ++++++++++++ .../openapitools/server/models/ApiResponse.kt | 33 +++++++ .../openapitools/server/models/Category.kt | 30 +++++++ .../org/openapitools/server/models/Order.kt | 55 ++++++++++++ .../org/openapitools/server/models/Pet.kt | 57 ++++++++++++ .../org/openapitools/server/models/Tag.kt | 30 +++++++ .../org/openapitools/server/models/User.kt | 49 ++++++++++ 17 files changed, 603 insertions(+) create mode 100644 bin/configs/kotlin-server-jaxrs-spec.yaml create mode 100644 samples/server/petstore/kotlin-server/jaxrs-spec/.openapi-generator-ignore create mode 100644 samples/server/petstore/kotlin-server/jaxrs-spec/.openapi-generator/FILES create mode 100644 samples/server/petstore/kotlin-server/jaxrs-spec/.openapi-generator/VERSION create mode 100644 samples/server/petstore/kotlin-server/jaxrs-spec/README.md create mode 100644 samples/server/petstore/kotlin-server/jaxrs-spec/build.gradle create mode 100644 samples/server/petstore/kotlin-server/jaxrs-spec/gradle.properties create mode 100644 samples/server/petstore/kotlin-server/jaxrs-spec/settings.gradle create mode 100644 samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/apis/PetApi.kt create mode 100644 samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/apis/StoreApi.kt create mode 100644 samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/apis/UserApi.kt create mode 100644 samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/models/ApiResponse.kt create mode 100644 samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/models/Category.kt create mode 100644 samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/models/Order.kt create mode 100644 samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/models/Pet.kt create mode 100644 samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/models/Tag.kt create mode 100644 samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/models/User.kt diff --git a/bin/configs/kotlin-server-jaxrs-spec.yaml b/bin/configs/kotlin-server-jaxrs-spec.yaml new file mode 100644 index 000000000000..11d4fcec7a8d --- /dev/null +++ b/bin/configs/kotlin-server-jaxrs-spec.yaml @@ -0,0 +1,7 @@ +generatorName: kotlin-server +outputDir: samples/server/petstore/kotlin-server/jaxrs-spec +library: jaxrs-spec +inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore.yaml +templateDir: modules/openapi-generator/src/main/resources/kotlin-server +additionalProperties: + useCoroutines: "true" diff --git a/samples/server/petstore/kotlin-server/jaxrs-spec/.openapi-generator-ignore b/samples/server/petstore/kotlin-server/jaxrs-spec/.openapi-generator-ignore new file mode 100644 index 000000000000..7484ee590a38 --- /dev/null +++ b/samples/server/petstore/kotlin-server/jaxrs-spec/.openapi-generator-ignore @@ -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 diff --git a/samples/server/petstore/kotlin-server/jaxrs-spec/.openapi-generator/FILES b/samples/server/petstore/kotlin-server/jaxrs-spec/.openapi-generator/FILES new file mode 100644 index 000000000000..97abbaa93ca4 --- /dev/null +++ b/samples/server/petstore/kotlin-server/jaxrs-spec/.openapi-generator/FILES @@ -0,0 +1,14 @@ +.openapi-generator-ignore +README.md +build.gradle +gradle.properties +settings.gradle +src/main/kotlin/org/openapitools/server/apis/PetApi.kt +src/main/kotlin/org/openapitools/server/apis/StoreApi.kt +src/main/kotlin/org/openapitools/server/apis/UserApi.kt +src/main/kotlin/org/openapitools/server/models/ApiResponse.kt +src/main/kotlin/org/openapitools/server/models/Category.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 diff --git a/samples/server/petstore/kotlin-server/jaxrs-spec/.openapi-generator/VERSION b/samples/server/petstore/kotlin-server/jaxrs-spec/.openapi-generator/VERSION new file mode 100644 index 000000000000..4077803655c0 --- /dev/null +++ b/samples/server/petstore/kotlin-server/jaxrs-spec/.openapi-generator/VERSION @@ -0,0 +1 @@ +5.3.1-SNAPSHOT \ No newline at end of file diff --git a/samples/server/petstore/kotlin-server/jaxrs-spec/README.md b/samples/server/petstore/kotlin-server/jaxrs-spec/README.md new file mode 100644 index 000000000000..00e0630dd75f --- /dev/null +++ b/samples/server/petstore/kotlin-server/jaxrs-spec/README.md @@ -0,0 +1,89 @@ +# org.openapitools.server - Kotlin Server library for OpenAPI Petstore + +## Requires + +* Kotlin 1.4.31 +* Gradle 6.8.2 + +## Build + +First, create the gradle wrapper script: + +``` +gradle wrapper +``` + +Then, run: + +``` +./gradlew check assemble +``` + +This runs all tests and packages the library. + +## Features/Implementation Notes + +* Supports JSON inputs/outputs, File inputs, 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. + + +## 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 + + + +## Documentation for Models + + - [org.openapitools.server.models.ApiResponse](docs/ApiResponse.md) + - [org.openapitools.server.models.Category](docs/Category.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) + + + +## Documentation for Authorization + + +### api_key + +- **Type**: API key +- **API key parameter name**: api_key +- **Location**: HTTP header + + +### 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 + diff --git a/samples/server/petstore/kotlin-server/jaxrs-spec/build.gradle b/samples/server/petstore/kotlin-server/jaxrs-spec/build.gradle new file mode 100644 index 000000000000..b85cf7303677 --- /dev/null +++ b/samples/server/petstore/kotlin-server/jaxrs-spec/build.gradle @@ -0,0 +1,51 @@ +group "org.openapitools" +version "1.0.0" + +wrapper { + gradleVersion = "6.9" + distributionUrl = "https://services.gradle.org/distributions/gradle-$gradleVersion-all.zip" +} + +buildscript { + ext.kotlin_version = "1.4.32" + ext.jakarta_ws_rs_version = "2.1.6" + ext.swagger_annotations_version = "1.5.3" + ext.jakarta_annotations_version = "1.3.5" + ext.jackson_version = "2.9.9" + repositories { + maven { url "https://repo1.maven.org/maven2" } + maven { url "https://plugins.gradle.org/m2/" } + } + dependencies { + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version") + } +} + +apply plugin: "java" +apply plugin: "kotlin" +apply plugin: "application" + +sourceCompatibility = 1.8 + +compileKotlin { + kotlinOptions.jvmTarget = "1.8" +} + +compileTestKotlin { + kotlinOptions.jvmTarget = "1.8" +} + +repositories { + maven { setUrl("https://repo1.maven.org/maven2") } +} + +dependencies { + implementation("org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version") + implementation("ch.qos.logback:logback-classic:1.2.1") + implementation("jakarta.ws.rs:jakarta.ws.rs-api:$jakarta_ws_rs_version") + implementation("jakarta.annotation:jakarta.annotation-api:$jakarta_annotations_version") + implementation("io.swagger:swagger-annotations:$swagger_annotations_version") + implementation("com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:$jackson_version") + implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jackson_version") + testImplementation("junit:junit:4.13.2") +} \ No newline at end of file diff --git a/samples/server/petstore/kotlin-server/jaxrs-spec/gradle.properties b/samples/server/petstore/kotlin-server/jaxrs-spec/gradle.properties new file mode 100644 index 000000000000..5f1ed7bbe024 --- /dev/null +++ b/samples/server/petstore/kotlin-server/jaxrs-spec/gradle.properties @@ -0,0 +1 @@ +org.gradle.caching=true \ No newline at end of file diff --git a/samples/server/petstore/kotlin-server/jaxrs-spec/settings.gradle b/samples/server/petstore/kotlin-server/jaxrs-spec/settings.gradle new file mode 100644 index 000000000000..a09a58efab11 --- /dev/null +++ b/samples/server/petstore/kotlin-server/jaxrs-spec/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'kotlin-server' \ No newline at end of file diff --git a/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/apis/PetApi.kt b/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/apis/PetApi.kt new file mode 100644 index 000000000000..08d04534666d --- /dev/null +++ b/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/apis/PetApi.kt @@ -0,0 +1,65 @@ +package org.openapitools.server.apis; + +import org.openapitools.server.models.ApiResponse +import org.openapitools.server.models.Pet + +import javax.ws.rs.* +import javax.ws.rs.core.Response + + +import java.io.InputStream +import java.util.Map +import java.util.List + + + +@javax.annotation.Generated(value = arrayOf("org.openapitools.codegen.languages.KotlinServerCodegen"))class PetApi { + + @POST + @Consumes("application/json", "application/xml") + suspend fun addPet( body: Pet): Response { + return Response.ok().entity("magic!").build(); + } + + @DELETE + suspend fun deletePet(@PathParam("petId") petId: kotlin.Long,@HeaderParam("api_key") apiKey: kotlin.String): Response { + return Response.ok().entity("magic!").build(); + } + + @GET + @Produces("application/xml", "application/json") + suspend fun findPetsByStatus(@QueryParam("status") status: kotlin.collections.List): Response { + return Response.ok().entity("magic!").build(); + } + + @GET + @Produces("application/xml", "application/json") + suspend fun findPetsByTags(@QueryParam("tags") tags: kotlin.collections.List): Response { + return Response.ok().entity("magic!").build(); + } + + @GET + @Produces("application/xml", "application/json") + suspend fun getPetById(@PathParam("petId") petId: kotlin.Long): Response { + return Response.ok().entity("magic!").build(); + } + + @PUT + @Consumes("application/json", "application/xml") + suspend fun updatePet( body: Pet): Response { + return Response.ok().entity("magic!").build(); + } + + @POST + @Consumes("application/x-www-form-urlencoded") + suspend fun updatePetWithForm(@PathParam("petId") petId: kotlin.Long,@FormParam(value = "name") name: kotlin.String,@FormParam(value = "status") status: kotlin.String): Response { + return Response.ok().entity("magic!").build(); + } + + @POST + @Consumes("multipart/form-data") + @Produces("application/json") + suspend fun uploadFile(@PathParam("petId") petId: kotlin.Long,@FormParam(value = "additionalMetadata") additionalMetadata: kotlin.String, @FormParam(value = "file") fileInputStream: InputStream): Response { + return Response.ok().entity("magic!").build(); + } +} diff --git a/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/apis/StoreApi.kt b/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/apis/StoreApi.kt new file mode 100644 index 000000000000..7360d6729e35 --- /dev/null +++ b/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/apis/StoreApi.kt @@ -0,0 +1,39 @@ +package org.openapitools.server.apis; + +import org.openapitools.server.models.Order + +import javax.ws.rs.* +import javax.ws.rs.core.Response + + +import java.io.InputStream +import java.util.Map +import java.util.List + + + +@javax.annotation.Generated(value = arrayOf("org.openapitools.codegen.languages.KotlinServerCodegen"))class StoreApi { + + @DELETE + suspend fun deleteOrder(@PathParam("orderId") orderId: kotlin.String): Response { + return Response.ok().entity("magic!").build(); + } + + @GET + @Produces("application/json") + suspend fun getInventory(): Response { + return Response.ok().entity("magic!").build(); + } + + @GET + @Produces("application/xml", "application/json") + suspend fun getOrderById(@PathParam("orderId") orderId: kotlin.Long): Response { + return Response.ok().entity("magic!").build(); + } + + @POST + @Produces("application/xml", "application/json") + suspend fun placeOrder( body: Order): Response { + return Response.ok().entity("magic!").build(); + } +} diff --git a/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/apis/UserApi.kt b/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/apis/UserApi.kt new file mode 100644 index 000000000000..f906dca949e7 --- /dev/null +++ b/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/apis/UserApi.kt @@ -0,0 +1,58 @@ +package org.openapitools.server.apis; + +import org.openapitools.server.models.User + +import javax.ws.rs.* +import javax.ws.rs.core.Response + + +import java.io.InputStream +import java.util.Map +import java.util.List + + + +@javax.annotation.Generated(value = arrayOf("org.openapitools.codegen.languages.KotlinServerCodegen"))class UserApi { + + @POST + suspend fun createUser( body: User): Response { + return Response.ok().entity("magic!").build(); + } + + @POST + suspend fun createUsersWithArrayInput( body: kotlin.collections.List): Response { + return Response.ok().entity("magic!").build(); + } + + @POST + suspend fun createUsersWithListInput( body: kotlin.collections.List): Response { + return Response.ok().entity("magic!").build(); + } + + @DELETE + suspend fun deleteUser(@PathParam("username") username: kotlin.String): Response { + return Response.ok().entity("magic!").build(); + } + + @GET + @Produces("application/xml", "application/json") + suspend fun getUserByName(@PathParam("username") username: kotlin.String): Response { + return Response.ok().entity("magic!").build(); + } + + @GET + @Produces("application/xml", "application/json") + suspend fun loginUser(@QueryParam("username") username: kotlin.String,@QueryParam("password") password: kotlin.String): Response { + return Response.ok().entity("magic!").build(); + } + + @GET + suspend fun logoutUser(): Response { + return Response.ok().entity("magic!").build(); + } + + @PUT + suspend fun updateUser(@PathParam("username") username: kotlin.String, body: User): Response { + return Response.ok().entity("magic!").build(); + } +} diff --git a/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/models/ApiResponse.kt b/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/models/ApiResponse.kt new file mode 100644 index 000000000000..974c9589a7f6 --- /dev/null +++ b/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/models/ApiResponse.kt @@ -0,0 +1,33 @@ +/** + * 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 com.fasterxml.jackson.annotation.JsonProperty +/** + * Describes the result of uploading an image resource + * + * @param code + * @param type + * @param message + */ + + +data class ApiResponse ( + + val code: kotlin.Int? = null, + + val type: kotlin.String? = null, + + val message: kotlin.String? = null + +) + diff --git a/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/models/Category.kt b/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/models/Category.kt new file mode 100644 index 000000000000..6143a74b758a --- /dev/null +++ b/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/models/Category.kt @@ -0,0 +1,30 @@ +/** + * 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 com.fasterxml.jackson.annotation.JsonProperty +/** + * A category for a pet + * + * @param id + * @param name + */ + + +data class Category ( + + val id: kotlin.Long? = null, + + val name: kotlin.String? = null + +) + diff --git a/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/models/Order.kt b/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/models/Order.kt new file mode 100644 index 000000000000..09fb77526390 --- /dev/null +++ b/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/models/Order.kt @@ -0,0 +1,55 @@ +/** + * 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 com.fasterxml.jackson.annotation.JsonProperty +/** + * 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) { + @JsonProperty(value = "placed") placed("placed"), + @JsonProperty(value = "approved") approved("approved"), + @JsonProperty(value = "delivered") delivered("delivered"); + } +} + diff --git a/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/models/Pet.kt b/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/models/Pet.kt new file mode 100644 index 000000000000..42f0f474ca09 --- /dev/null +++ b/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/models/Pet.kt @@ -0,0 +1,57 @@ +/** + * 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 +import com.fasterxml.jackson.annotation.JsonProperty +/** + * 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, + + val id: kotlin.Long? = null, + + val category: Category? = null, + + val tags: kotlin.collections.List? = 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) { + @JsonProperty(value = "available") available("available"), + @JsonProperty(value = "pending") pending("pending"), + @JsonProperty(value = "sold") sold("sold"); + } +} + diff --git a/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/models/Tag.kt b/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/models/Tag.kt new file mode 100644 index 000000000000..5d18ba3b9469 --- /dev/null +++ b/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/models/Tag.kt @@ -0,0 +1,30 @@ +/** + * 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 com.fasterxml.jackson.annotation.JsonProperty +/** + * A tag for a pet + * + * @param id + * @param name + */ + + +data class Tag ( + + val id: kotlin.Long? = null, + + val name: kotlin.String? = null + +) + diff --git a/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/models/User.kt b/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/models/User.kt new file mode 100644 index 000000000000..d4ade77c3a54 --- /dev/null +++ b/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/models/User.kt @@ -0,0 +1,49 @@ +/** + * 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 com.fasterxml.jackson.annotation.JsonProperty +/** + * 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 + +) + From 7aefbfdc2016c7855f1509a08baae9310eb42e82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20Lepp=C3=A4?= Date: Wed, 10 Nov 2021 09:33:47 +0200 Subject: [PATCH 06/13] Added support for returnResponse option into Kotlin server JAX-RS library --- .../codegen/languages/KotlinServerCodegen.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinServerCodegen.java index fcf8049c7900..b7a5ff85e541 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinServerCodegen.java @@ -38,6 +38,7 @@ public class KotlinServerCodegen extends AbstractKotlinCodegen implements BeanVa public static final String INTERFACE_ONLY = "interfaceOnly"; public static final String USE_COROUTINES = "useCoroutines"; + public static final String RETURN_RESPONSE = "returnResponse"; public static final String DEFAULT_LIBRARY = Constants.KTOR; private final Logger LOGGER = LoggerFactory.getLogger(KotlinServerCodegen.class); @@ -51,6 +52,7 @@ public class KotlinServerCodegen extends AbstractKotlinCodegen implements BeanVa private boolean interfaceOnly = false; private boolean useBeanValidation = false; private boolean useCoroutines = false; + private boolean returnResponse = false; // This is here to potentially warn the user when an option is not supported by the target framework. private Map> optionsSupportedPerFramework = new ImmutableMap.Builder>() @@ -130,6 +132,7 @@ public KotlinServerCodegen() { cliOptions.add(CliOption.newBoolean(INTERFACE_ONLY, "Whether to generate only API interface stubs without the server files.").defaultValue(String.valueOf(interfaceOnly))); cliOptions.add(CliOption.newBoolean(USE_BEANVALIDATION, "Use BeanValidation API annotations",useBeanValidation)); cliOptions.add(CliOption.newBoolean(USE_COROUTINES, "Whether to use the Coroutines with the JAX-RS library.")); + cliOptions.add(CliOption.newBoolean(RETURN_RESPONSE, "Whether generate API interface should return javax.ws.rs.core.Response instead of a deserialized entity. Only useful if interfaceOnly is true.").defaultValue(String.valueOf(returnResponse))); } public Boolean getAutoHeadFeatureEnabled() { @@ -222,6 +225,13 @@ public void processOpts() { } } + if (additionalProperties.containsKey(RETURN_RESPONSE)) { + returnResponse = Boolean.parseBoolean(additionalProperties.get(RETURN_RESPONSE).toString()); + if (!returnResponse) { + additionalProperties.remove(RETURN_RESPONSE); + } + } + if (additionalProperties.containsKey(USE_BEANVALIDATION)) { setUseBeanValidation(convertPropertyToBoolean(USE_BEANVALIDATION)); } From 75fe65d8a60621dee66ba8c01306c280efc2eebd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20Lepp=C3=A4?= Date: Sat, 20 Nov 2021 13:01:31 +0200 Subject: [PATCH 07/13] Fixed issue with optional parameters in Kotlin JAX-RS spec --- .../resources/kotlin-server/libraries/jaxrs-spec/api.mustache | 1 + .../kotlin-server/libraries/jaxrs-spec/bodyParams.mustache | 2 +- .../kotlin-server/libraries/jaxrs-spec/cookieParams.mustache | 2 +- .../kotlin-server/libraries/jaxrs-spec/formParams.mustache | 2 +- .../kotlin-server/libraries/jaxrs-spec/headerParams.mustache | 2 +- .../kotlin-server/libraries/jaxrs-spec/queryParams.mustache | 2 +- 6 files changed, 6 insertions(+), 5 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/api.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/api.mustache index 324fc735d348..2d716bd7fdfd 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/api.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/api.mustache @@ -20,6 +20,7 @@ import javax.validation.Valid{{/useBeanValidation}} @Api(description = "the {{{baseName}}} API"){{/useSwaggerAnnotations}}{{#hasConsumes}} @Consumes({ {{#consumes}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/consumes}} }){{/hasConsumes}}{{#hasProduces}} @Produces({ {{#produces}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/produces}} }){{/hasProduces}} +@Path("/") {{>generatedAnnotation}}{{#interfaceOnly}}interface{{/interfaceOnly}}{{^interfaceOnly}}class{{/interfaceOnly}} {{classname}} { {{#operations}} {{#operation}} diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/bodyParams.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/bodyParams.mustache index 8f84440fdb2c..ba9197f35a49 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/bodyParams.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/bodyParams.mustache @@ -1 +1 @@ -{{#isBodyParam}}{{#useBeanValidation}}@Valid {{#required}}{{^isNullable}}@NotNull {{/isNullable}}{{/required}}{{/useBeanValidation}} {{paramName}}: {{{dataType}}}{{/isBodyParam}} \ No newline at end of file +{{#isBodyParam}}{{#useBeanValidation}}@Valid {{#required}}{{^isNullable}}@NotNull {{/isNullable}}{{/required}}{{/useBeanValidation}} {{paramName}}: {{{dataType}}}{{^required}}?{{/required}}{{/isBodyParam}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/cookieParams.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/cookieParams.mustache index 0d015d6cf68f..eda2d526ebd4 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/cookieParams.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/cookieParams.mustache @@ -1 +1 @@ -{{#isCookieParam}}@CookieParam("{{baseName}}"){{#useBeanValidation}}{{>beanValidationQueryParams}}{{/useBeanValidation}}{{^isContainer}}{{#defaultValue}} @DefaultValue("{{{.}}}"){{/defaultValue}}{{/isContainer}} {{#useSwaggerAnnotations}}{{#description}} @ApiParam("{{.}}"){{/description}}{{/useSwaggerAnnotations}} {{{dataType}}} {{paramName}}{{/isCookieParam}} \ No newline at end of file +{{#isCookieParam}}@CookieParam("{{baseName}}"){{#useBeanValidation}}{{>beanValidationQueryParams}}{{/useBeanValidation}}{{^isContainer}}{{#defaultValue}} @DefaultValue("{{{.}}}"){{/defaultValue}}{{/isContainer}} {{#useSwaggerAnnotations}}{{#description}} @ApiParam("{{.}}"){{/description}}{{/useSwaggerAnnotations}} {{paramName}}: {{{dataType}}}{{^required}}?{{/required}}{{/isCookieParam}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/formParams.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/formParams.mustache index aaac9d8dce23..5427f037ae0b 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/formParams.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/formParams.mustache @@ -1 +1 @@ -{{#isFormParam}}{{^isFile}}@FormParam(value = "{{baseName}}") {{paramName}}: {{{dataType}}}{{/isFile}}{{#isFile}} @FormParam(value = "{{baseName}}") {{paramName}}InputStream: InputStream{{/isFile}}{{/isFormParam}} \ No newline at end of file +{{#isFormParam}}{{^isFile}}@FormParam(value = "{{baseName}}") {{paramName}}: {{{dataType}}}{{^required}}?{{/required}}{{/isFile}}{{#isFile}} @FormParam(value = "{{baseName}}") {{paramName}}InputStream: InputStream{{^required}}?{{/required}}{{/isFile}}{{/isFormParam}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/headerParams.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/headerParams.mustache index c5ded586f7f6..980d55c7e51c 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/headerParams.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/headerParams.mustache @@ -1 +1 @@ -{{#isHeaderParam}}@HeaderParam("{{baseName}}"){{#useBeanValidation}}{{>beanValidationHeaderParams}}{{/useBeanValidation}} {{#defaultValue}} @DefaultValue("{{{.}}}"){{/defaultValue}} {{#useSwaggerAnnotations}}{{#description}} @ApiParam("{{.}}"){{/description}}{{/useSwaggerAnnotations}} {{paramName}}: {{{dataType}}}{{/isHeaderParam}} \ No newline at end of file +{{#isHeaderParam}}@HeaderParam("{{baseName}}"){{#useBeanValidation}}{{>beanValidationHeaderParams}}{{/useBeanValidation}} {{#defaultValue}} @DefaultValue("{{{.}}}"){{/defaultValue}} {{#useSwaggerAnnotations}}{{#description}} @ApiParam("{{.}}"){{/description}}{{/useSwaggerAnnotations}} {{paramName}}: {{{dataType}}}{{^required}}?{{/required}}{{/isHeaderParam}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/queryParams.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/queryParams.mustache index bc173cb68a2e..91a0dfdb6644 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/queryParams.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/queryParams.mustache @@ -1 +1 @@ -{{#isQueryParam}}@QueryParam("{{baseName}}"){{#useBeanValidation}}{{>beanValidationQueryParams}}{{/useBeanValidation}}{{^isContainer}}{{#defaultValue}} @DefaultValue("{{{.}}}"){{/defaultValue}}{{/isContainer}} {{#useSwaggerAnnotations}}{{#description}} @ApiParam("{{.}}"){{/description}}{{/useSwaggerAnnotations}} {{paramName}}: {{{dataType}}}{{/isQueryParam}} \ No newline at end of file +{{#isQueryParam}}@QueryParam("{{baseName}}"){{#useBeanValidation}}{{>beanValidationQueryParams}}{{/useBeanValidation}}{{^isContainer}}{{#defaultValue}} @DefaultValue("{{{.}}}"){{/defaultValue}}{{/isContainer}} {{#useSwaggerAnnotations}}{{#description}} @ApiParam("{{.}}"){{/description}}{{/useSwaggerAnnotations}} {{paramName}}: {{{dataType}}}{{^required}}?{{/required}}{{/isQueryParam}} \ No newline at end of file From 8956747c21f2f73a3ba5345741e07cf05ee02bc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20Lepp=C3=A4?= Date: Tue, 18 Jan 2022 20:29:10 +0200 Subject: [PATCH 08/13] Fixed oneOf issue in Kotlin jaxrs-spec generator --- .../kotlin-server/libraries/jaxrs-spec/model.mustache | 2 +- .../kotlin-server/libraries/jaxrs-spec/oneof_model.mustache | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/oneof_model.mustache diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/model.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/model.mustache index f0c59426d3a0..03eecdc64ac9 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/model.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/model.mustache @@ -9,6 +9,6 @@ import javax.validation.Valid {{/useBeanValidation}} {{#models}} {{#model}} -{{#isEnum}}{{>enum_class}}{{/isEnum}}{{^isEnum}}{{#isAlias}}typealias {{classname}} = {{{dataType}}}{{/isAlias}}{{^isAlias}}{{>data_class}}{{/isAlias}}{{/isEnum}} +{{#isEnum}}{{>enum_class}}{{/isEnum}}{{^isEnum}}{{#oneOf}}{{>oneof_model}}{{/oneOf}}{{^oneOf}}{{#isAlias}}typealias {{classname}} = {{{dataType}}}{{/isAlias}}{{^isAlias}}{{>data_class}}{{/isAlias}}{{/oneOf}}{{/isEnum}} {{/model}} {{/models}} diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/oneof_model.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/oneof_model.mustache new file mode 100644 index 000000000000..83c841f56001 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/oneof_model.mustache @@ -0,0 +1,3 @@ +{{#-first}} +typealias {{classname}} = Any +{{/-first}} \ No newline at end of file From 6406c6ee502691bac1af0f45f22e3254a942367f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20Lepp=C3=A4?= Date: Wed, 19 Jan 2022 16:14:29 +0200 Subject: [PATCH 09/13] Added better documentation to Kotlin Server JAX-RS options --- .../codegen/languages/KotlinServerCodegen.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinServerCodegen.java index b7a5ff85e541..d1b1d1d57fb6 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinServerCodegen.java @@ -129,10 +129,10 @@ public KotlinServerCodegen() { addSwitch(Constants.LOCATIONS, Constants.LOCATIONS_DESC, getLocationsFeatureEnabled()); addSwitch(Constants.METRICS, Constants.METRICS_DESC, getMetricsFeatureEnabled()); - cliOptions.add(CliOption.newBoolean(INTERFACE_ONLY, "Whether to generate only API interface stubs without the server files.").defaultValue(String.valueOf(interfaceOnly))); - cliOptions.add(CliOption.newBoolean(USE_BEANVALIDATION, "Use BeanValidation API annotations",useBeanValidation)); - cliOptions.add(CliOption.newBoolean(USE_COROUTINES, "Whether to use the Coroutines with the JAX-RS library.")); - cliOptions.add(CliOption.newBoolean(RETURN_RESPONSE, "Whether generate API interface should return javax.ws.rs.core.Response instead of a deserialized entity. Only useful if interfaceOnly is true.").defaultValue(String.valueOf(returnResponse))); + cliOptions.add(CliOption.newBoolean(INTERFACE_ONLY, "Whether to generate only API interface stubs without the server files. This option is currently supported only when using jaxrs-spec library.").defaultValue(String.valueOf(interfaceOnly))); + cliOptions.add(CliOption.newBoolean(USE_BEANVALIDATION, "Use BeanValidation API annotations. This option is currently supported only when using jaxrs-spec library.", useBeanValidation)); + cliOptions.add(CliOption.newBoolean(USE_COROUTINES, "Whether to use the Coroutines. This option is currently supported only when using jaxrs-spec library.")); + cliOptions.add(CliOption.newBoolean(RETURN_RESPONSE, "Whether generate API interface should return javax.ws.rs.core.Response instead of a deserialized entity. Only useful if interfaceOnly is true. This option is currently supported only when using jaxrs-spec library.").defaultValue(String.valueOf(returnResponse))); } public Boolean getAutoHeadFeatureEnabled() { From 8bb9a564d8c134bf90c778f18ce1a126e0a74f0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20Lepp=C3=A4?= Date: Wed, 19 Jan 2022 16:29:55 +0200 Subject: [PATCH 10/13] Updated kotlin-server.md --- docs/generators/kotlin-server.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/generators/kotlin-server.md b/docs/generators/kotlin-server.md index 8e48bda46da6..6d9ac50f28de 100644 --- a/docs/generators/kotlin-server.md +++ b/docs/generators/kotlin-server.md @@ -29,15 +29,19 @@ These options may be applied as additional-properties (cli) or configOptions (pl |featureLocations|Generates routes in a typed way, for both: constructing URLs and reading the parameters.| |true| |featureMetrics|Enables metrics feature.| |true| |groupId|Generated artifact package's organization (i.e. maven groupId).| |org.openapitools| -|library|library template (sub-template)|
**ktor**
ktor framework
|ktor| +|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)|
**ktor**
ktor framework
**jaxrs-spec**
JAX-RS spec only
|ktor| |modelMutable|Create mutable models| |false| |packageName|Generated artifact package name.| |org.openapitools.server| |parcelizeModels|toggle "@Parcelize" for generated models| |null| +|returnResponse|Whether generate API interface should return javax.ws.rs.core.Response instead of a deserialized entity. Only useful if interfaceOnly is true. This option is currently supported only when using jaxrs-spec library.| |false| |serializableModel|boolean - toggle "implements Serializable" for generated models| |null| |serializationLibrary|What serialization library to use: 'moshi' (default), or 'gson' or 'jackson'| |moshi| |sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |null| |sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |null| |sourceFolder|source folder for generated code| |src/main/kotlin| +|useBeanValidation|Use BeanValidation API annotations. This option is currently supported only when using jaxrs-spec library.| |false| +|useCoroutines|Whether to use the Coroutines. This option is currently supported only when using jaxrs-spec library.| |false| ## IMPORT MAPPING From 643019fb4cc171553648e1cc4ae3d6950aa6520d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20Lepp=C3=A4?= Date: Wed, 19 Jan 2022 16:34:05 +0200 Subject: [PATCH 11/13] Updated kotlin-server jaxrs-spec samples --- .../jaxrs-spec/.openapi-generator/FILES | 3 +- .../jaxrs-spec/.openapi-generator/VERSION | 2 +- .../kotlin-server/jaxrs-spec/README.md | 2 +- .../org/openapitools/server/apis/PetApi.kt | 9 ++--- .../org/openapitools/server/apis/StoreApi.kt | 1 + .../org/openapitools/server/apis/UserApi.kt | 1 + .../server/models/ModelApiResponse.kt | 33 +++++++++++++++++++ 7 files changed, 43 insertions(+), 8 deletions(-) create mode 100644 samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/models/ModelApiResponse.kt diff --git a/samples/server/petstore/kotlin-server/jaxrs-spec/.openapi-generator/FILES b/samples/server/petstore/kotlin-server/jaxrs-spec/.openapi-generator/FILES index 97abbaa93ca4..8311b1e0d0af 100644 --- a/samples/server/petstore/kotlin-server/jaxrs-spec/.openapi-generator/FILES +++ b/samples/server/petstore/kotlin-server/jaxrs-spec/.openapi-generator/FILES @@ -1,4 +1,3 @@ -.openapi-generator-ignore README.md build.gradle gradle.properties @@ -6,8 +5,8 @@ settings.gradle src/main/kotlin/org/openapitools/server/apis/PetApi.kt src/main/kotlin/org/openapitools/server/apis/StoreApi.kt src/main/kotlin/org/openapitools/server/apis/UserApi.kt -src/main/kotlin/org/openapitools/server/models/ApiResponse.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 diff --git a/samples/server/petstore/kotlin-server/jaxrs-spec/.openapi-generator/VERSION b/samples/server/petstore/kotlin-server/jaxrs-spec/.openapi-generator/VERSION index 4077803655c0..0984c4c1ad21 100644 --- a/samples/server/petstore/kotlin-server/jaxrs-spec/.openapi-generator/VERSION +++ b/samples/server/petstore/kotlin-server/jaxrs-spec/.openapi-generator/VERSION @@ -1 +1 @@ -5.3.1-SNAPSHOT \ No newline at end of file +5.4.0-SNAPSHOT \ No newline at end of file diff --git a/samples/server/petstore/kotlin-server/jaxrs-spec/README.md b/samples/server/petstore/kotlin-server/jaxrs-spec/README.md index 00e0630dd75f..d5e7ab18e685 100644 --- a/samples/server/petstore/kotlin-server/jaxrs-spec/README.md +++ b/samples/server/petstore/kotlin-server/jaxrs-spec/README.md @@ -59,8 +59,8 @@ Class | Method | HTTP request | Description ## Documentation for Models - - [org.openapitools.server.models.ApiResponse](docs/ApiResponse.md) - [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) diff --git a/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/apis/PetApi.kt b/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/apis/PetApi.kt index 08d04534666d..eb94d6065e61 100644 --- a/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/apis/PetApi.kt +++ b/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/apis/PetApi.kt @@ -1,6 +1,6 @@ package org.openapitools.server.apis; -import org.openapitools.server.models.ApiResponse +import org.openapitools.server.models.ModelApiResponse import org.openapitools.server.models.Pet import javax.ws.rs.* @@ -13,6 +13,7 @@ import java.util.List +@Path("/") @javax.annotation.Generated(value = arrayOf("org.openapitools.codegen.languages.KotlinServerCodegen"))class PetApi { @POST @@ -22,7 +23,7 @@ import java.util.List } @DELETE - suspend fun deletePet(@PathParam("petId") petId: kotlin.Long,@HeaderParam("api_key") apiKey: kotlin.String): Response { + suspend fun deletePet(@PathParam("petId") petId: kotlin.Long,@HeaderParam("api_key") apiKey: kotlin.String?): Response { return Response.ok().entity("magic!").build(); } @@ -52,14 +53,14 @@ import java.util.List @POST @Consumes("application/x-www-form-urlencoded") - suspend fun updatePetWithForm(@PathParam("petId") petId: kotlin.Long,@FormParam(value = "name") name: kotlin.String,@FormParam(value = "status") status: kotlin.String): Response { + suspend fun updatePetWithForm(@PathParam("petId") petId: kotlin.Long,@FormParam(value = "name") name: kotlin.String?,@FormParam(value = "status") status: kotlin.String?): Response { return Response.ok().entity("magic!").build(); } @POST @Consumes("multipart/form-data") @Produces("application/json") - suspend fun uploadFile(@PathParam("petId") petId: kotlin.Long,@FormParam(value = "additionalMetadata") additionalMetadata: kotlin.String, @FormParam(value = "file") fileInputStream: InputStream): Response { + suspend fun uploadFile(@PathParam("petId") petId: kotlin.Long,@FormParam(value = "additionalMetadata") additionalMetadata: kotlin.String?, @FormParam(value = "file") fileInputStream: InputStream?): Response { return Response.ok().entity("magic!").build(); } } diff --git a/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/apis/StoreApi.kt b/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/apis/StoreApi.kt index 7360d6729e35..f297a11661db 100644 --- a/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/apis/StoreApi.kt +++ b/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/apis/StoreApi.kt @@ -12,6 +12,7 @@ import java.util.List +@Path("/") @javax.annotation.Generated(value = arrayOf("org.openapitools.codegen.languages.KotlinServerCodegen"))class StoreApi { @DELETE diff --git a/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/apis/UserApi.kt b/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/apis/UserApi.kt index f906dca949e7..f824ebc217ab 100644 --- a/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/apis/UserApi.kt +++ b/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/apis/UserApi.kt @@ -12,6 +12,7 @@ import java.util.List +@Path("/") @javax.annotation.Generated(value = arrayOf("org.openapitools.codegen.languages.KotlinServerCodegen"))class UserApi { @POST diff --git a/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/models/ModelApiResponse.kt b/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/models/ModelApiResponse.kt new file mode 100644 index 000000000000..c331ab095162 --- /dev/null +++ b/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/models/ModelApiResponse.kt @@ -0,0 +1,33 @@ +/** + * 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 com.fasterxml.jackson.annotation.JsonProperty +/** + * 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 + +) + From 05c73652a53e066dc79077f6951c3c96c1c1c339 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20Lepp=C3=A4?= Date: Thu, 27 Jan 2022 12:05:43 +0200 Subject: [PATCH 12/13] Fixed issue with Kotlin JAX-RS spec and reserved names --- .../libraries/jaxrs-spec/data_class_opt_var.mustache | 2 ++ .../libraries/jaxrs-spec/data_class_req_var.mustache | 2 ++ 2 files changed, 4 insertions(+) diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/data_class_opt_var.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/data_class_opt_var.mustache index a630d086e44e..8d0e7b3f027e 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/data_class_opt_var.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/data_class_opt_var.mustache @@ -1,4 +1,6 @@ {{#description}} /* {{{.}}} */ {{/description}} + +@JsonProperty("{{{baseName}}}") {{#useBeanValidation}}{{>beanValidation}}{{/useBeanValidation}} {{>modelMutable}} {{{name}}}: {{#isEnum}}{{classname}}.{{nameInCamelCase}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}? = {{{defaultValue}}}{{^defaultValue}}null{{/defaultValue}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/data_class_req_var.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/data_class_req_var.mustache index 7845eb3000a5..42f013d34b4e 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/data_class_req_var.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/data_class_req_var.mustache @@ -1,4 +1,6 @@ {{#description}} /* {{{.}}} */ {{/description}} + +@JsonProperty("{{{baseName}}}") {{#useBeanValidation}}{{>beanValidation}}{{/useBeanValidation}} {{>modelMutable}} {{{name}}}: {{#isEnum}}{{classname}}.{{nameInCamelCase}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}} \ No newline at end of file From 083e4e61fb4621bdae055f6c62e9495b8cc213bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20Lepp=C3=A4?= Date: Thu, 27 Jan 2022 12:33:29 +0200 Subject: [PATCH 13/13] Regenerated samples --- .../jaxrs-spec/data_class_opt_var.mustache | 2 +- .../jaxrs-spec/data_class_req_var.mustache | 2 +- .../org/openapitools/server/models/Category.kt | 4 ++++ .../server/models/ModelApiResponse.kt | 6 ++++++ .../org/openapitools/server/models/Order.kt | 12 ++++++++++++ .../kotlin/org/openapitools/server/models/Pet.kt | 12 ++++++++++++ .../kotlin/org/openapitools/server/models/Tag.kt | 4 ++++ .../org/openapitools/server/models/User.kt | 16 ++++++++++++++++ 8 files changed, 56 insertions(+), 2 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/data_class_opt_var.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/data_class_opt_var.mustache index 8d0e7b3f027e..d99ccd902fa3 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/data_class_opt_var.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/data_class_opt_var.mustache @@ -2,5 +2,5 @@ /* {{{.}}} */ {{/description}} -@JsonProperty("{{{baseName}}}") + @JsonProperty("{{{baseName}}}") {{#useBeanValidation}}{{>beanValidation}}{{/useBeanValidation}} {{>modelMutable}} {{{name}}}: {{#isEnum}}{{classname}}.{{nameInCamelCase}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}? = {{{defaultValue}}}{{^defaultValue}}null{{/defaultValue}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/data_class_req_var.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/data_class_req_var.mustache index 42f013d34b4e..5c69ae13e510 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/data_class_req_var.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/data_class_req_var.mustache @@ -2,5 +2,5 @@ /* {{{.}}} */ {{/description}} -@JsonProperty("{{{baseName}}}") + @JsonProperty("{{{baseName}}}") {{#useBeanValidation}}{{>beanValidation}}{{/useBeanValidation}} {{>modelMutable}} {{{name}}}: {{#isEnum}}{{classname}}.{{nameInCamelCase}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}} \ No newline at end of file diff --git a/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/models/Category.kt b/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/models/Category.kt index 6143a74b758a..9a39acd8aea7 100644 --- a/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/models/Category.kt +++ b/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/models/Category.kt @@ -22,8 +22,12 @@ import com.fasterxml.jackson.annotation.JsonProperty data class Category ( + + @JsonProperty("id") val id: kotlin.Long? = null, + + @JsonProperty("name") val name: kotlin.String? = null ) diff --git a/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/models/ModelApiResponse.kt b/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/models/ModelApiResponse.kt index c331ab095162..531f364e2f72 100644 --- a/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/models/ModelApiResponse.kt +++ b/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/models/ModelApiResponse.kt @@ -23,10 +23,16 @@ import com.fasterxml.jackson.annotation.JsonProperty data class ModelApiResponse ( + + @JsonProperty("code") val code: kotlin.Int? = null, + + @JsonProperty("type") val type: kotlin.String? = null, + + @JsonProperty("message") val message: kotlin.String? = null ) diff --git a/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/models/Order.kt b/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/models/Order.kt index 09fb77526390..d4a39a2c2bb2 100644 --- a/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/models/Order.kt +++ b/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/models/Order.kt @@ -26,17 +26,29 @@ import com.fasterxml.jackson.annotation.JsonProperty data class Order ( + + @JsonProperty("id") val id: kotlin.Long? = null, + + @JsonProperty("petId") val petId: kotlin.Long? = null, + + @JsonProperty("quantity") val quantity: kotlin.Int? = null, + + @JsonProperty("shipDate") val shipDate: java.time.OffsetDateTime? = null, /* Order Status */ + + @JsonProperty("status") val status: Order.Status? = null, + + @JsonProperty("complete") val complete: kotlin.Boolean? = false ) { diff --git a/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/models/Pet.kt b/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/models/Pet.kt index 42f0f474ca09..826d87a73031 100644 --- a/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/models/Pet.kt +++ b/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/models/Pet.kt @@ -28,17 +28,29 @@ import com.fasterxml.jackson.annotation.JsonProperty data class Pet ( + + @JsonProperty("name") val name: kotlin.String, + + @JsonProperty("photoUrls") val photoUrls: kotlin.collections.List, + + @JsonProperty("id") val id: kotlin.Long? = null, + + @JsonProperty("category") val category: Category? = null, + + @JsonProperty("tags") val tags: kotlin.collections.List? = null, /* pet status in the store */ + + @JsonProperty("status") val status: Pet.Status? = null ) { diff --git a/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/models/Tag.kt b/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/models/Tag.kt index 5d18ba3b9469..ded0e6fab036 100644 --- a/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/models/Tag.kt +++ b/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/models/Tag.kt @@ -22,8 +22,12 @@ import com.fasterxml.jackson.annotation.JsonProperty data class Tag ( + + @JsonProperty("id") val id: kotlin.Long? = null, + + @JsonProperty("name") val name: kotlin.String? = null ) diff --git a/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/models/User.kt b/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/models/User.kt index d4ade77c3a54..4d0dcec66911 100644 --- a/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/models/User.kt +++ b/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/models/User.kt @@ -28,21 +28,37 @@ import com.fasterxml.jackson.annotation.JsonProperty data class User ( + + @JsonProperty("id") val id: kotlin.Long? = null, + + @JsonProperty("username") val username: kotlin.String? = null, + + @JsonProperty("firstName") val firstName: kotlin.String? = null, + + @JsonProperty("lastName") val lastName: kotlin.String? = null, + + @JsonProperty("email") val email: kotlin.String? = null, + + @JsonProperty("password") val password: kotlin.String? = null, + + @JsonProperty("phone") val phone: kotlin.String? = null, /* User Status */ + + @JsonProperty("userStatus") val userStatus: kotlin.Int? = null )