diff --git a/.gitignore b/.gitignore index 33731657c22..d632589eb6c 100644 --- a/.gitignore +++ b/.gitignore @@ -212,6 +212,7 @@ samples/server/petstore/kotlin-server/ktor/build samples/server/petstore/kotlin-springboot/build samples/client/petstore/kotlin*/src/main/kotlin/test/ samples/client/petstore/kotlin*/build/ +samples/server/others/kotlin-server/jaxrs-spec/build/ # haskell .stack-work diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java index cfe1b493216..3c58a95deea 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java @@ -449,6 +449,7 @@ public class DefaultCodegen implements CodegenConfig { .put("pascalcase", new CamelCaseLambda(false).generator(this)) .put("forwardslash", new ForwardSlashLambda()) .put("backslash", new BackSlashLambda()) + .put("doublequote", new DoubleQuoteLambda()) .put("indented", new IndentedLambda()) .put("indented_8", new IndentedLambda(8, " ", false)) .put("indented_12", new IndentedLambda(12, " ", false)) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/templating/mustache/DoubleQuoteLambda.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/templating/mustache/DoubleQuoteLambda.java new file mode 100644 index 00000000000..9979e0e817e --- /dev/null +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/templating/mustache/DoubleQuoteLambda.java @@ -0,0 +1,50 @@ +/* + * Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.openapitools.codegen.templating.mustache; + +import com.samskivert.mustache.Mustache; +import com.samskivert.mustache.Template; + +import java.io.IOException; +import java.io.Writer; + +import static org.openapitools.codegen.utils.StringUtils.underscore; + +/** + * Double quote the text if it's not already the case. + * + * Register: + *
+ * additionalProperties.put("doublequote", new DoubleQuoteLambda()); + *+ * + * Use: + *
+ * {{#doublequote}}{{summary}}{{/doublequote}} + *+ */ +public class DoubleQuoteLambda implements Mustache.Lambda { + @Override + public void execute(Template.Fragment fragment, Writer writer) throws IOException { + String input = fragment.execute(); + if (input.startsWith("\"") && input.endsWith("\"")) { + writer.write(input); + } else { + writer.write("\"" + input + "\""); + } + } +} diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/templating/mustache/ForwardSlashLambda.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/templating/mustache/ForwardSlashLambda.java index 56f903974aa..a9f39b59ae1 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/templating/mustache/ForwardSlashLambda.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/templating/mustache/ForwardSlashLambda.java @@ -34,7 +34,7 @@ import static org.openapitools.codegen.utils.StringUtils.underscore; * * Use: *
- * {{#fforwardslash}}{{summary}}{{/forwardslash}} + * {{#forwardslash}}{{summary}}{{/forwardslash}} **/ public class ForwardSlashLambda implements Mustache.Lambda { 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 40648eb494d..a2d0343c173 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("{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}"){{#useBeanValidation}}{{>beanValidationQueryParams}}{{/useBeanValidation}}{{^isContainer}}{{#defaultValue}} @DefaultValue({{{.}}}){{/defaultValue}}{{/isContainer}} {{#useSwaggerAnnotations}}{{#description}} @ApiParam("{{.}}"){{/description}}{{/useSwaggerAnnotations}} {{paramName}}: {{{dataType}}}{{#isNullable}}?{{/isNullable}}{{^isNullable}}{{^defaultValue}}{{^required}}?{{/required}}{{/defaultValue}}{{/isNullable}}{{/isCookieParam}} \ No newline at end of file +{{#isCookieParam}}@CookieParam("{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}"){{#useBeanValidation}}{{>beanValidationQueryParams}}{{/useBeanValidation}}{{^isContainer}}{{#defaultValue}} @DefaultValue({{#lambda.doublequote}}{{{.}}}{{/lambda.doublequote}}){{/defaultValue}}{{/isContainer}} {{#useSwaggerAnnotations}}{{#description}} @ApiParam("{{.}}"){{/description}}{{/useSwaggerAnnotations}} {{paramName}}: {{{dataType}}}{{#isNullable}}?{{/isNullable}}{{^isNullable}}{{^defaultValue}}{{^required}}?{{/required}}{{/defaultValue}}{{/isNullable}}{{/isCookieParam}} \ 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 e5b328fa200..b637f85e050 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}}}{{#isNullable}}?{{/isNullable}}{{^isNullable}}{{^defaultValue}}{{^required}}?{{/required}}{{/defaultValue}}{{/isNullable}}{{/isHeaderParam}} \ No newline at end of file +{{#isHeaderParam}}@HeaderParam("{{baseName}}"){{#useBeanValidation}}{{>beanValidationHeaderParams}}{{/useBeanValidation}} {{#defaultValue}} @DefaultValue({{#lambda.doublequote}}{{{.}}}{{/lambda.doublequote}}){{/defaultValue}} {{#useSwaggerAnnotations}}{{#description}} @ApiParam("{{.}}"){{/description}}{{/useSwaggerAnnotations}} {{paramName}}: {{{dataType}}}{{#isNullable}}?{{/isNullable}}{{^isNullable}}{{^defaultValue}}{{^required}}?{{/required}}{{/defaultValue}}{{/isNullable}}{{/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 fa6f1c583cb..690cef49eb4 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("{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}"){{#useBeanValidation}}{{>beanValidationQueryParams}}{{/useBeanValidation}}{{^isContainer}}{{#defaultValue}} @DefaultValue({{{.}}}){{/defaultValue}}{{/isContainer}} {{#useSwaggerAnnotations}}{{#description}} @ApiParam("{{.}}"){{/description}}{{/useSwaggerAnnotations}} {{paramName}}: {{{dataType}}}{{#isNullable}}?{{/isNullable}}{{^isNullable}}{{^defaultValue}}{{^required}}?{{/required}}{{/defaultValue}}{{/isNullable}}{{/isQueryParam}} \ No newline at end of file +{{#isQueryParam}}@QueryParam("{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}"){{#useBeanValidation}}{{>beanValidationQueryParams}}{{/useBeanValidation}}{{^isContainer}}{{#defaultValue}} @DefaultValue({{#lambda.doublequote}}{{{.}}}{{/lambda.doublequote}}){{/defaultValue}}{{/isContainer}} {{#useSwaggerAnnotations}}{{#description}} @ApiParam("{{.}}"){{/description}}{{/useSwaggerAnnotations}} {{paramName}}: {{{dataType}}}{{#isNullable}}?{{/isNullable}}{{^isNullable}}{{^defaultValue}}{{^required}}?{{/required}}{{/defaultValue}}{{/isNullable}}{{/isQueryParam}} \ No newline at end of file diff --git a/modules/openapi-generator/src/test/resources/3_0/parameter-test-spec.yaml b/modules/openapi-generator/src/test/resources/3_0/parameter-test-spec.yaml index 14d1b311ebf..db07e2d16eb 100644 --- a/modules/openapi-generator/src/test/resources/3_0/parameter-test-spec.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/parameter-test-spec.yaml @@ -24,12 +24,46 @@ paths: schema: type: string default: available + - name: query_default_enum + in: query + description: query default enum + schema: + type: string + enum: + - A + - B + - C + default: B + - name: query_default_int + in: query + description: query default int + schema: + type: number + format: int32 + default: 3 - name: header_default in: header description: header default schema: type: string default: available + - name: header_default_enum + in: header + description: header default enum + schema: + type: string + enum: + - A + - B + - C + default: B + - name: header_default_int + in: header + description: header default int + schema: + type: number + format: int32 + default: 3 - name: path_default in: path description: path default @@ -42,6 +76,23 @@ paths: schema: type: string default: available + - name: cookie_default_enum + in: cookie + description: cookie default enum + schema: + type: string + enum: + - A + - B + - C + default: B + - name: cookie_default_int + in: cookie + description: cookie default int + schema: + type: number + format: int32 + default: 3 - name: query_nullable in: query description: query nullable diff --git a/samples/client/others/kotlin-jvm-okhttp-parameter-tests/docs/DefaultApi.md b/samples/client/others/kotlin-jvm-okhttp-parameter-tests/docs/DefaultApi.md index 9082c6dd97d..4e81da579cb 100644 --- a/samples/client/others/kotlin-jvm-okhttp-parameter-tests/docs/DefaultApi.md +++ b/samples/client/others/kotlin-jvm-okhttp-parameter-tests/docs/DefaultApi.md @@ -9,7 +9,7 @@ Method | HTTP request | Description # **findPetsByStatus** -> findPetsByStatus(pathDefault, pathNullable, queryDefault, headerDefault, cookieDefault, queryNullable, headerNullable, cookieNullable, dollarQueryDollarDollarSign) +> findPetsByStatus(pathDefault, pathNullable, queryDefault, queryDefaultEnum, queryDefaultInt, headerDefault, headerDefaultEnum, headerDefaultInt, cookieDefault, cookieDefaultEnum, cookieDefaultInt, queryNullable, headerNullable, cookieNullable, dollarQueryDollarDollarSign) Finds Pets by status @@ -25,14 +25,20 @@ val apiInstance = DefaultApi() val pathDefault : kotlin.String = pathDefault_example // kotlin.String | path default val pathNullable : kotlin.String = pathNullable_example // kotlin.String | path_nullable val queryDefault : kotlin.String = queryDefault_example // kotlin.String | query default +val queryDefaultEnum : kotlin.String = queryDefaultEnum_example // kotlin.String | query default enum +val queryDefaultInt : java.math.BigDecimal = 8.14 // java.math.BigDecimal | query default int val headerDefault : kotlin.String = headerDefault_example // kotlin.String | header default +val headerDefaultEnum : kotlin.String = headerDefaultEnum_example // kotlin.String | header default enum +val headerDefaultInt : java.math.BigDecimal = 8.14 // java.math.BigDecimal | header default int val cookieDefault : kotlin.String = cookieDefault_example // kotlin.String | cookie default +val cookieDefaultEnum : kotlin.String = cookieDefaultEnum_example // kotlin.String | cookie default enum +val cookieDefaultInt : java.math.BigDecimal = 8.14 // java.math.BigDecimal | cookie default int val queryNullable : kotlin.String = queryNullable_example // kotlin.String | query nullable val headerNullable : kotlin.String = headerNullable_example // kotlin.String | header nullable val cookieNullable : kotlin.String = cookieNullable_example // kotlin.String | cookie_nullable val dollarQueryDollarDollarSign : kotlin.String = dollarQueryDollarDollarSign_example // kotlin.String | query parameter with dollar sign try { - apiInstance.findPetsByStatus(pathDefault, pathNullable, queryDefault, headerDefault, cookieDefault, queryNullable, headerNullable, cookieNullable, dollarQueryDollarDollarSign) + apiInstance.findPetsByStatus(pathDefault, pathNullable, queryDefault, queryDefaultEnum, queryDefaultInt, headerDefault, headerDefaultEnum, headerDefaultInt, cookieDefault, cookieDefaultEnum, cookieDefaultInt, queryNullable, headerNullable, cookieNullable, dollarQueryDollarDollarSign) } catch (e: ClientException) { println("4xx response calling DefaultApi#findPetsByStatus") e.printStackTrace() @@ -49,8 +55,14 @@ Name | Type | Description | Notes **pathDefault** | **kotlin.String**| path default | **pathNullable** | **kotlin.String**| path_nullable | **queryDefault** | **kotlin.String**| query default | [optional] [default to "available"] + **queryDefaultEnum** | **kotlin.String**| query default enum | [optional] [default to B] [enum: A, B, C] + **queryDefaultInt** | **java.math.BigDecimal**| query default int | [optional] [default to 3] **headerDefault** | **kotlin.String**| header default | [optional] [default to "available"] + **headerDefaultEnum** | **kotlin.String**| header default enum | [optional] [default to B] [enum: A, B, C] + **headerDefaultInt** | **java.math.BigDecimal**| header default int | [optional] [default to 3] **cookieDefault** | **kotlin.String**| cookie default | [optional] [default to "available"] + **cookieDefaultEnum** | **kotlin.String**| cookie default enum | [optional] [default to B] [enum: A, B, C] + **cookieDefaultInt** | **java.math.BigDecimal**| cookie default int | [optional] [default to 3] **queryNullable** | **kotlin.String**| query nullable | [optional] **headerNullable** | **kotlin.String**| header nullable | [optional] **cookieNullable** | **kotlin.String**| cookie_nullable | [optional] diff --git a/samples/client/others/kotlin-jvm-okhttp-parameter-tests/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt b/samples/client/others/kotlin-jvm-okhttp-parameter-tests/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt index 531aec837a9..751d87de781 100644 --- a/samples/client/others/kotlin-jvm-okhttp-parameter-tests/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt +++ b/samples/client/others/kotlin-jvm-okhttp-parameter-tests/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt @@ -44,14 +44,47 @@ class DefaultApi(basePath: kotlin.String = defaultBasePath, client: OkHttpClient } } + /** + * enum for parameter queryDefaultEnum + */ + enum class QueryDefaultEnumFindPetsByStatus(val value: kotlin.String) { + @Json(name = "A") a("A"), + @Json(name = "B") b("B"), + @Json(name = "C") c("C") + } + + /** + * enum for parameter headerDefaultEnum + */ + enum class HeaderDefaultEnumFindPetsByStatus(val value: kotlin.String) { + @Json(name = "A") a("A"), + @Json(name = "B") b("B"), + @Json(name = "C") c("C") + } + + /** + * enum for parameter cookieDefaultEnum + */ + enum class CookieDefaultEnumFindPetsByStatus(val value: kotlin.String) { + @Json(name = "A") a("A"), + @Json(name = "B") b("B"), + @Json(name = "C") c("C") + } + /** * Finds Pets by status * Multiple status values can be provided with comma separated strings * @param pathDefault path default * @param pathNullable path_nullable * @param queryDefault query default (optional, default to "available") + * @param queryDefaultEnum query default enum (optional, default to B) + * @param queryDefaultInt query default int (optional, default to 3) * @param headerDefault header default (optional, default to "available") + * @param headerDefaultEnum header default enum (optional, default to B) + * @param headerDefaultInt header default int (optional, default to 3) * @param cookieDefault cookie default (optional, default to "available") + * @param cookieDefaultEnum cookie default enum (optional, default to B) + * @param cookieDefaultInt cookie default int (optional, default to 3) * @param queryNullable query nullable (optional) * @param headerNullable header nullable (optional) * @param cookieNullable cookie_nullable (optional) @@ -64,8 +97,8 @@ class DefaultApi(basePath: kotlin.String = defaultBasePath, client: OkHttpClient * @throws ServerException If the API returns a server error response */ @Throws(IllegalStateException::class, IOException::class, UnsupportedOperationException::class, ClientException::class, ServerException::class) - fun findPetsByStatus(pathDefault: kotlin.String, pathNullable: kotlin.String, queryDefault: kotlin.String? = "available", headerDefault: kotlin.String? = "available", cookieDefault: kotlin.String? = "available", queryNullable: kotlin.String? = null, headerNullable: kotlin.String? = null, cookieNullable: kotlin.String? = null, dollarQueryDollarDollarSign: kotlin.String? = null) : Unit { - val localVarResponse = findPetsByStatusWithHttpInfo(pathDefault = pathDefault, pathNullable = pathNullable, queryDefault = queryDefault, headerDefault = headerDefault, cookieDefault = cookieDefault, queryNullable = queryNullable, headerNullable = headerNullable, cookieNullable = cookieNullable, dollarQueryDollarDollarSign = dollarQueryDollarDollarSign) + fun findPetsByStatus(pathDefault: kotlin.String, pathNullable: kotlin.String, queryDefault: kotlin.String? = "available", queryDefaultEnum: QueryDefaultEnumFindPetsByStatus? = QueryDefaultEnumFindPetsByStatus.b, queryDefaultInt: java.math.BigDecimal? = java.math.BigDecimal("3"), headerDefault: kotlin.String? = "available", headerDefaultEnum: HeaderDefaultEnumFindPetsByStatus? = HeaderDefaultEnumFindPetsByStatus.b, headerDefaultInt: java.math.BigDecimal? = java.math.BigDecimal("3"), cookieDefault: kotlin.String? = "available", cookieDefaultEnum: CookieDefaultEnumFindPetsByStatus? = CookieDefaultEnumFindPetsByStatus.b, cookieDefaultInt: java.math.BigDecimal? = java.math.BigDecimal("3"), queryNullable: kotlin.String? = null, headerNullable: kotlin.String? = null, cookieNullable: kotlin.String? = null, dollarQueryDollarDollarSign: kotlin.String? = null) : Unit { + val localVarResponse = findPetsByStatusWithHttpInfo(pathDefault = pathDefault, pathNullable = pathNullable, queryDefault = queryDefault, queryDefaultEnum = queryDefaultEnum, queryDefaultInt = queryDefaultInt, headerDefault = headerDefault, headerDefaultEnum = headerDefaultEnum, headerDefaultInt = headerDefaultInt, cookieDefault = cookieDefault, cookieDefaultEnum = cookieDefaultEnum, cookieDefaultInt = cookieDefaultInt, queryNullable = queryNullable, headerNullable = headerNullable, cookieNullable = cookieNullable, dollarQueryDollarDollarSign = dollarQueryDollarDollarSign) return when (localVarResponse.responseType) { ResponseType.Success -> Unit @@ -88,8 +121,14 @@ class DefaultApi(basePath: kotlin.String = defaultBasePath, client: OkHttpClient * @param pathDefault path default * @param pathNullable path_nullable * @param queryDefault query default (optional, default to "available") + * @param queryDefaultEnum query default enum (optional, default to B) + * @param queryDefaultInt query default int (optional, default to 3) * @param headerDefault header default (optional, default to "available") + * @param headerDefaultEnum header default enum (optional, default to B) + * @param headerDefaultInt header default int (optional, default to 3) * @param cookieDefault cookie default (optional, default to "available") + * @param cookieDefaultEnum cookie default enum (optional, default to B) + * @param cookieDefaultInt cookie default int (optional, default to 3) * @param queryNullable query nullable (optional) * @param headerNullable header nullable (optional) * @param cookieNullable cookie_nullable (optional) @@ -99,8 +138,8 @@ class DefaultApi(basePath: kotlin.String = defaultBasePath, client: OkHttpClient * @throws IOException Rethrows the OkHttp execute method exception */ @Throws(IllegalStateException::class, IOException::class) - fun findPetsByStatusWithHttpInfo(pathDefault: kotlin.String, pathNullable: kotlin.String, queryDefault: kotlin.String?, headerDefault: kotlin.String?, cookieDefault: kotlin.String?, queryNullable: kotlin.String?, headerNullable: kotlin.String?, cookieNullable: kotlin.String?, dollarQueryDollarDollarSign: kotlin.String?) : ApiResponse