diff --git a/openapi-generator/src/main/java/io/micronaut/openapi/generator/AbstractMicronautJavaCodegen.java b/openapi-generator/src/main/java/io/micronaut/openapi/generator/AbstractMicronautJavaCodegen.java index 15c399b0ba..6be7095938 100644 --- a/openapi-generator/src/main/java/io/micronaut/openapi/generator/AbstractMicronautJavaCodegen.java +++ b/openapi-generator/src/main/java/io/micronaut/openapi/generator/AbstractMicronautJavaCodegen.java @@ -44,6 +44,7 @@ import org.openapitools.codegen.CodegenResponse; import org.openapitools.codegen.IJsonSchemaValidationProperties; import org.openapitools.codegen.SupportingFile; +import org.openapitools.codegen.VendorExtension; import org.openapitools.codegen.config.GlobalSettings; import org.openapitools.codegen.languages.AbstractJavaCodegen; import org.openapitools.codegen.languages.features.BeanValidationFeatures; @@ -148,7 +149,6 @@ public abstract class AbstractMicronautJavaCodegen(); - generateSwaggerAnnotationsOptionMap.put(OPT_GENERATE_SWAGGER_ANNOTATIONS_SWAGGER_1, "Use io.swagger:swagger-annotations for annotating operations and schemas"); generateSwaggerAnnotationsOptionMap.put(OPT_GENERATE_SWAGGER_ANNOTATIONS_SWAGGER_2, "Use io.swagger.core.v3:swagger-annotations for annotating operations and schemas"); generateSwaggerAnnotationsOptionMap.put(OPT_GENERATE_SWAGGER_ANNOTATIONS_TRUE, "Equivalent to \"" + OPT_GENERATE_SWAGGER_ANNOTATIONS_SWAGGER_2 + "\""); generateSwaggerAnnotationsOptionMap.put(OPT_GENERATE_SWAGGER_ANNOTATIONS_FALSE, "Do not generate swagger annotations"); @@ -560,9 +559,7 @@ public void processOpts() { } maybeSetSwagger(); - if (OPT_GENERATE_SWAGGER_ANNOTATIONS_SWAGGER_1.equals(generateSwaggerAnnotations)) { - additionalProperties.put("generateSwagger1Annotations", true); - } else if (OPT_GENERATE_SWAGGER_ANNOTATIONS_SWAGGER_2.equals(generateSwaggerAnnotations)) { + if (OPT_GENERATE_SWAGGER_ANNOTATIONS_SWAGGER_2.equals(generateSwaggerAnnotations)) { additionalProperties.put("generateSwagger2Annotations", true); } @@ -677,8 +674,7 @@ private void maybeSetSwagger() { if (additionalProperties.containsKey(OPT_GENERATE_SWAGGER_ANNOTATIONS)) { String value = String.valueOf(additionalProperties.get(OPT_GENERATE_SWAGGER_ANNOTATIONS)); switch (value) { - case OPT_GENERATE_SWAGGER_ANNOTATIONS_SWAGGER_1 -> generateSwaggerAnnotations = OPT_GENERATE_SWAGGER_ANNOTATIONS_SWAGGER_1; - case OPT_GENERATE_SWAGGER_ANNOTATIONS_SWAGGER_2, OPT_GENERATE_SWAGGER_ANNOTATIONS_TRUE -> generateSwaggerAnnotations = OPT_GENERATE_SWAGGER_ANNOTATIONS_SWAGGER_2; + case OPT_GENERATE_SWAGGER_ANNOTATIONS_SWAGGER_1, OPT_GENERATE_SWAGGER_ANNOTATIONS_SWAGGER_2, OPT_GENERATE_SWAGGER_ANNOTATIONS_TRUE -> generateSwaggerAnnotations = OPT_GENERATE_SWAGGER_ANNOTATIONS_SWAGGER_2; case OPT_GENERATE_SWAGGER_ANNOTATIONS_FALSE -> generateSwaggerAnnotations = OPT_GENERATE_SWAGGER_ANNOTATIONS_FALSE; default -> throw new RuntimeException("Value \"" + value + "\" for the " + OPT_GENERATE_SWAGGER_ANNOTATIONS + " parameter is unsupported or misspelled"); } @@ -1314,8 +1310,8 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List !CONTENT_TYPE_ANY.equals(contentType.get("mediaType"))) @@ -1340,14 +1336,14 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List { p.isBodyParam = false; p.isFormParam = true; }); op.bodyParams.clear(); - } else if (CONTENT_TYPE_MULTIPART_FORM_DATA.equals(op.vendorExtensions.get(EXT_CONTENT_TYPE))) { + } else if (CONTENT_TYPE_MULTIPART_FORM_DATA.equals(op.vendorExtensions.get(VendorExtension.X_CONTENT_TYPE.getName()))) { op.bodyParams.addAll(op.formParams); for (var param : op.allParams) { if (param.isFormParam) { diff --git a/openapi-generator/src/main/java/io/micronaut/openapi/generator/AbstractMicronautKotlinCodegen.java b/openapi-generator/src/main/java/io/micronaut/openapi/generator/AbstractMicronautKotlinCodegen.java index 9bc824c366..87538bf248 100644 --- a/openapi-generator/src/main/java/io/micronaut/openapi/generator/AbstractMicronautKotlinCodegen.java +++ b/openapi-generator/src/main/java/io/micronaut/openapi/generator/AbstractMicronautKotlinCodegen.java @@ -47,6 +47,7 @@ import org.openapitools.codegen.DefaultCodegen; import org.openapitools.codegen.IJsonSchemaValidationProperties; import org.openapitools.codegen.SupportingFile; +import org.openapitools.codegen.VendorExtension; import org.openapitools.codegen.config.GlobalSettings; import org.openapitools.codegen.languages.AbstractKotlinCodegen; import org.openapitools.codegen.languages.features.BeanValidationFeatures; @@ -156,7 +157,6 @@ public abstract class AbstractMicronautKotlinCodegen openAPIGetPathsEntry : openApi.getPaths().entrySet()) { - String pathname = openAPIGetPathsEntry.getKey(); PathItem path = openAPIGetPathsEntry.getValue(); - if (path.readOperations() == null) { + var ops = path.readOperations(); + if (ops == null || ops.isEmpty()) { continue; } - for (Operation operation : path.readOperations()) { + for (Operation operation : ops) { log.info("Processing operation {}", operation.getOperationId()); if (hasBodyParameter(operation) || hasFormParameter(operation)) { var defaultContentType = hasFormParameter(operation) ? CONTENT_TYPE_APPLICATION_FORM_URLENCODED : CONTENT_TYPE_APPLICATION_JSON; var consumes = new ArrayList<>(getConsumesInfo(openApi, operation)); String contentType = consumes.isEmpty() ? defaultContentType : consumes.get(0); - operation.addExtension(EXT_CONTENT_TYPE, contentType); + operation.addExtension(VendorExtension.X_CONTENT_TYPE.getName(), contentType); } - String[] accepts = getAccepts(openAPI, operation); - operation.addExtension("x-accepts", accepts); + String[] accepts = getAccepts(openApi, operation); + operation.addExtension(VendorExtension.X_ACCEPTS.getName(), accepts); } } } @@ -1011,8 +1011,8 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List !CONTENT_TYPE_ANY.equals(contentType.get("mediaType"))) @@ -1037,14 +1037,14 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List { p.isBodyParam = false; p.isFormParam = true; }); op.bodyParams.clear(); - } else if (CONTENT_TYPE_MULTIPART_FORM_DATA.equals(op.vendorExtensions.get(EXT_CONTENT_TYPE))) { + } else if (CONTENT_TYPE_MULTIPART_FORM_DATA.equals(op.vendorExtensions.get(VendorExtension.X_CONTENT_TYPE.getName()))) { op.bodyParams.addAll(op.formParams); for (var param : op.allParams) { if (param.isFormParam) { diff --git a/openapi-generator/src/main/java/io/micronaut/openapi/generator/Utils.java b/openapi-generator/src/main/java/io/micronaut/openapi/generator/Utils.java index 9f7daca204..cbb5ae1217 100644 --- a/openapi-generator/src/main/java/io/micronaut/openapi/generator/Utils.java +++ b/openapi-generator/src/main/java/io/micronaut/openapi/generator/Utils.java @@ -157,7 +157,7 @@ private static String genericAnnotations(CodegenProperty prop, boolean isGenerat } if (StringUtils.isNotEmpty(prop.pattern) && !prop.isDate && !prop.isDateTime) { - if ("email".equals(type)) { + if (prop.isEmail) { result.append("@Email(regexp = \""); } else { result.append("@Pattern(regexp = \""); @@ -274,7 +274,7 @@ private static boolean isPrimitive(String type) { } return switch (type) { case "array", "char", "character", "string", "boolean", "byte", "short", "int", "integer", "long", "uri", "url", "uuid", "email", "float", - "double", "number", "partial-time", "date", "date-time", "bigdecimal", "biginteger" -> true; + "double", "number", "partial-time", "date", "date-time", "bigdecimal", "decimal", "biginteger" -> true; default -> false; }; } diff --git a/openapi-generator/src/main/resources/templates/java-micronaut/client/api.mustache b/openapi-generator/src/main/resources/templates/java-micronaut/client/api.mustache index 988cc3372e..225258da44 100644 --- a/openapi-generator/src/main/resources/templates/java-micronaut/client/api.mustache +++ b/openapi-generator/src/main/resources/templates/java-micronaut/client/api.mustache @@ -29,9 +29,6 @@ import java.util.Map; import {{javaxPackage}}.validation.Valid; import {{javaxPackage}}.validation.constraints.*; {{/useBeanValidation}} -{{#generateSwagger1Annotations}} -import io.swagger.annotations.*; -{{/generateSwagger1Annotations}} {{#generateSwagger2Annotations}} import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; diff --git a/openapi-generator/src/main/resources/templates/java-micronaut/client/params/type.mustache b/openapi-generator/src/main/resources/templates/java-micronaut/client/params/type.mustache index dc8f5ddf0d..0dc4bdea8b 100644 --- a/openapi-generator/src/main/resources/templates/java-micronaut/client/params/type.mustache +++ b/openapi-generator/src/main/resources/templates/java-micronaut/client/params/type.mustache @@ -1,3 +1,4 @@ +{{#isDeprecated}}@Deprecated{{/isDeprecated}} {{^isDate}}{{^isDateTime}}{{{vendorExtensions.typeWithEnumWithGenericAnnotations}}}{{/isDateTime}}{{/isDate}} {{#isDateTime}}{{#vendorExtensions.formatPattern}}@Format("{{{vendorExtensions.formatPattern}}}"){{/vendorExtensions.formatPattern}}{{^vendorExtensions.formatPattern}}{{#dateTimeFormat}}@Format("{{{dateTimeFormat}}}"){{/dateTimeFormat}}{{/vendorExtensions.formatPattern}} {{{vendorExtensions.baseType}}} {{/isDateTime}} {{#isDate}}{{#vendorExtensions.formatPattern}}@Format("{{{vendorExtensions.formatPattern}}}"){{/vendorExtensions.formatPattern}}{{^vendorExtensions.formatPattern}}{{#dateFormat}}@Format("{{{dateFormat}}}"){{/dateFormat}}{{/vendorExtensions.formatPattern}} {{{vendorExtensions.baseType}}} {{/isDate}} \ No newline at end of file diff --git a/openapi-generator/src/main/resources/templates/java-micronaut/common/model/enum.mustache b/openapi-generator/src/main/resources/templates/java-micronaut/common/model/enum.mustache index 1be64f084e..24df02090e 100644 --- a/openapi-generator/src/main/resources/templates/java-micronaut/common/model/enum.mustache +++ b/openapi-generator/src/main/resources/templates/java-micronaut/common/model/enum.mustache @@ -1,6 +1,13 @@ /** * {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{{.}}}{{/description}} +{{#isDeprecated}} + * + * @deprecated{{#vendorExtensions.x-deprecated-message}} {{{.}}}{{/vendorExtensions.x-deprecated-message}} +{{/isDeprecated}} */ +{{#isDeprecated}} +@Deprecated +{{/isDeprecated}} {{#withXml}} @XmlType(name="{{datatypeWithEnum}}") @XmlEnum({{vendorExtensions.baseType}}.class) diff --git a/openapi-generator/src/main/resources/templates/java-micronaut/common/model/model.mustache b/openapi-generator/src/main/resources/templates/java-micronaut/common/model/model.mustache index 5774441f32..fa909a10cb 100644 --- a/openapi-generator/src/main/resources/templates/java-micronaut/common/model/model.mustache +++ b/openapi-generator/src/main/resources/templates/java-micronaut/common/model/model.mustache @@ -67,10 +67,6 @@ import io.micronaut.core.annotation.Nullable; {{#generatedAnnotation}} import {{javaxPackage}}.annotation.Generated; {{/generatedAnnotation}} -{{#generateSwagger1Annotations}} -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -{{/generateSwagger1Annotations}} {{#generateSwagger2Annotations}} import io.swagger.v3.oas.annotations.media.Schema; {{/generateSwagger2Annotations}} diff --git a/openapi-generator/src/main/resources/templates/java-micronaut/common/model/pojo.mustache b/openapi-generator/src/main/resources/templates/java-micronaut/common/model/pojo.mustache index 5e02bd6b51..5a77e46858 100644 --- a/openapi-generator/src/main/resources/templates/java-micronaut/common/model/pojo.mustache +++ b/openapi-generator/src/main/resources/templates/java-micronaut/common/model/pojo.mustache @@ -1,13 +1,17 @@ {{#formatNoEmptyLines}} /** * {{#description}}{{.}}{{/description}}{{^description}}{{classname}}{{/description}} +{{#isDeprecated}} + * + * @deprecated{{#vendorExtensions.x-deprecated-message}} {{{.}}}{{/vendorExtensions.x-deprecated-message}} +{{/isDeprecated}} */ +{{#isDeprecated}} +@Deprecated +{{/isDeprecated}} {{#description}} - {{#generateSwagger1Annotations}} -@ApiModel(description = "{{{description}}}") - {{/generateSwagger1Annotations}} {{#generateSwagger2Annotations}} -@Schema({{#name}}name = "{{name}}", {{/name}}description = "{{{description}}}") +@Schema({{#name}}name = "{{name}}", {{/name}}description = "{{{description}}}"{{#isDeprecated}}, deprecated = true{{/isDeprecated}}) {{/generateSwagger2Annotations}} {{/description}} {{#lombok}} @@ -87,8 +91,22 @@ public class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{{#vendorE {{#description}} /** * {{description}} + {{#deprecated}} + * + * @deprecated{{#vendorExtensions.x-deprecated-message}} {{{.}}}{{/vendorExtensions.x-deprecated-message}} + {{/deprecated}} */ {{/description}} + {{^description}} + {{#deprecated}} + /** + * @deprecated{{#vendorExtensions.x-deprecated-message}} {{{.}}}{{/vendorExtensions.x-deprecated-message}} + */ + {{/deprecated}} + {{/description}} + {{#deprecated}} + @Deprecated + {{/deprecated}} {{>common/params/validation}} {{#withXml}} {{#isXmlAttribute}} @@ -111,11 +129,8 @@ public class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{{#vendorE {{/isContainer}} {{/isXmlAttribute}} {{/withXml}} - {{#generateSwagger1Annotations}} - @ApiModelProperty({{#example}}example = "{{{example}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}value = "{{{description}}}") - {{/generateSwagger1Annotations}} {{#generateSwagger2Annotations}} - @Schema(name = "{{{baseName}}}"{{#isReadOnly}}, accessMode = Schema.AccessMode.READ_ONLY{{/isReadOnly}}{{#example}}, example = "{{{.}}}"{{/example}}{{#description}}, description = "{{{.}}}"{{/description}}, requiredMode = {{#required}}Schema.RequiredMode.REQUIRED{{/required}}{{^required}}Schema.RequiredMode.NOT_REQUIRED{{/required}}) + @Schema(name = "{{{baseName}}}"{{#isReadOnly}}, accessMode = Schema.AccessMode.READ_ONLY{{/isReadOnly}}{{#example}}, example = "{{{.}}}"{{/example}}{{#description}}, description = "{{{.}}}"{{/description}}, requiredMode = {{#required}}Schema.RequiredMode.REQUIRED{{/required}}{{^required}}Schema.RequiredMode.NOT_REQUIRED{{/required}}{{#deprecated}}, deprecated = true{{/deprecated}}) {{/generateSwagger2Annotations}} {{#vendorExtensions.x-is-jackson-optional-nullable}} {{!Unannotated, Jackson would pick this up automatically and add it *in addition* to the _JsonNullable getter field}} @@ -195,10 +210,17 @@ public class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{{#vendorE * {{/description}} * @return the {{name}} property value + {{#deprecated}} + * + * @deprecated{{#vendorExtensions.x-deprecated-message}} {{{.}}}{{/vendorExtensions.x-deprecated-message}} + {{/deprecated}} */ {{#vendorExtensions.x-extra-annotation}} {{{.}}} {{/vendorExtensions.x-extra-annotation}} + {{#deprecated}} + @Deprecated + {{/deprecated}} {{#isDiscriminator}} {{#parent}} @Override @@ -233,10 +255,17 @@ public class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{{#vendorE * {{/description}} * @return the {{name}} property value wrapped in an optional + {{#deprecated}} + * + * @deprecated{{#vendorExtensions.x-deprecated-message}} {{{.}}}{{/vendorExtensions.x-deprecated-message}} + {{/deprecated}} */ {{#jackson}} @JsonIgnore {{/jackson}} + {{#deprecated}} + @Deprecated + {{/deprecated}} public Optional<{{{vendorExtensions.typeWithEnumWithGenericAnnotations}}}> {{getter}}Optional() { {{^vendorExtensions.x-is-jackson-optional-nullable}} return Optional.ofNullable({{name}}); @@ -251,10 +280,19 @@ public class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{{#vendorE {{^vendorExtensions.lombok}} /** * Set the {{name}} property value + * + * @param {{name}} property value to set + {{#deprecated}} + * + * @deprecated{{#vendorExtensions.x-deprecated-message}} {{{.}}}{{/vendorExtensions.x-deprecated-message}} + {{/deprecated}} */ {{#vendorExtensions.x-setter-extra-annotation}} {{{.}}} {{/vendorExtensions.x-setter-extra-annotation}} + {{#deprecated}} + @Deprecated + {{/deprecated}} public void {{setter}}({{{vendorExtensions.typeWithEnumWithGenericAnnotations}}} {{name}}) { {{#vendorExtensions.x-is-jackson-optional-nullable}} this.{{name}} = JsonNullable.<{{{vendorExtensions.typeWithEnumWithGenericAnnotations}}}>of({{name}}); @@ -288,7 +326,14 @@ public class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{{#vendorE * Set {{name}} in a chainable fashion. * * @return The same instance of {{classname}} for chaining. + {{#deprecated}} + * + * @deprecated{{#vendorExtensions.x-deprecated-message}} {{{.}}}{{/vendorExtensions.x-deprecated-message}} + {{/deprecated}} */ + {{#deprecated}} + @Deprecated + {{/deprecated}} public {{classname}} {{name}}({{{vendorExtensions.typeWithEnumWithGenericAnnotations}}} {{name}}) { {{#vendorExtensions.x-is-jackson-optional-nullable}} this.{{name}} = JsonNullable.<{{{vendorExtensions.typeWithEnumWithGenericAnnotations}}}>of({{name}}); diff --git a/openapi-generator/src/main/resources/templates/java-micronaut/common/operationAnnotations.mustache b/openapi-generator/src/main/resources/templates/java-micronaut/common/operationAnnotations.mustache index edeeed4acf..ca835d3d02 100644 --- a/openapi-generator/src/main/resources/templates/java-micronaut/common/operationAnnotations.mustache +++ b/openapi-generator/src/main/resources/templates/java-micronaut/common/operationAnnotations.mustache @@ -3,7 +3,7 @@ * {{openbrace}}@summary {{summary}}{{closebrace}} {{/summary}} {{#notes}} - * {{notes}} + * {{.}} {{/notes}} {{^summary}} {{^notes}} @@ -14,52 +14,29 @@ {{#-first}} * {{/-first}} - * @param {{paramName}}{{#description}} {{description}}{{/description}}{{#required}} (required){{/required}}{{^required}} (optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}} + * @param {{paramName}}{{#description}} {{description}}{{/description}}{{#required}} (required){{/required}}{{^required}} (optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}{{#vendorExtensions.x-deprecated-message}} + * Deprecated: {{{.}}}{{/vendorExtensions.x-deprecated-message}} {{/vendorExtensions.originalParams}} {{#returnType}} {{^vendorExtensions.originalParams.0}} * {{/vendorExtensions.originalParams.0}} - * @return {{returnType}} + * @return {{#responses}}{{message}} (status code {{code}}){{^-last}} + * or {{/-last}}{{/responses}} {{/returnType}} + {{#isDeprecated}} + * @deprecated{{#vendorExtensions.x-deprecated-message}} {{{.}}}{{/vendorExtensions.x-deprecated-message}} + {{/isDeprecated}} {{#externalDocs}} * {{description}} * * @see {{summary}} Documentation {{/externalDocs}} */ - {{!openapi annotations for info}} - {{#generateSwagger1Annotations}} - @ApiOperation( - value = "{{{summary}}}", - nickname = "{{{operationId}}}"{{#notes}}, - notes = "{{{notes}}}"{{/notes}}{{#returnBaseType}}, - response = {{{returnBaseType}}}.class{{/returnBaseType}}{{#returnContainer}}, - responseContainer = "{{{returnContainer}}}"{{/returnContainer}}, - {{#hasAuthMethods}} - authorizations = {{#authMethods.1}}{{openbrace}}{{/authMethods.1}} - {{#authMethods}} - {{#isOAuth}} - @Authorization(value = "{{name}}"{{#scopes.0}}, scopes = {{#scopes.1}}{{openbrace}} - {{/scopes.1}} - {{#scopes}} - @AuthorizationScope(scope = "{{scope}}", description = "{{description}}"){{^-last}},{{/-last}} - {{/scopes}}{{#scopes.1}} - {{closebrace}}{{/scopes.1}}{{/scopes.0}}){{^-last}},{{/-last}} - {{/isOAuth}} - {{^isOAuth}} - @Authorization(value = "{{name}}"){{^-last}},{{/-last}} - {{/isOAuth}} - {{/authMethods}} - {{#authMethods.1}}{{closebrace}}{{/authMethods.1}} - {{/hasAuthMethods}}, - tags = { {{#vendorExtensions.x-tags}}"{{tag}}"{{^-last}}, {{/-last}}{{/vendorExtensions.x-tags}} } - ) - @ApiResponses(value = {{openbrace}}{{#responses}} - @ApiResponse(code = {{{code}}}, message = "{{{message}}}"{{#baseType}}, response = {{{baseType}}}.class{{/baseType}}{{#containerType}}, responseContainer = "{{{containerType}}}"{{/containerType}}){{^-last}},{{/-last}}{{/responses}} - {{closebrace}}) - {{/generateSwagger1Annotations}} {{#generateSwagger2Annotations}} + {{#isDeprecated}} + @Deprecated + {{/isDeprecated}} @Operation( operationId = "{{{operationId}}}", {{#summary}} @@ -68,6 +45,9 @@ {{#notes}} description = "{{{.}}}", {{/notes}} + {{#isDeprecated}} + deprecated = true, + {{/isDeprecated}} {{#tags.1}} {{!generate only when at least 2 tags}} tags = {{openbrace}} {{#tags}}"{{name}}"{{^-last}}, {{/-last}}{{/tags}} {{closebrace}}, @@ -76,20 +56,21 @@ {{/responses.1}}{{#responses}}{{#responses.1}} {{/responses.1}}@ApiResponse(responseCode = "{{{code}}}", description = "{{{message}}}"{{#baseType}}, content = {{#produces.1}}{{openbrace}} {{#produces}} - @Content(mediaType = "{{{mediaType}}}", schema = @Schema(implementation = {{{baseType}}}.class)){{^-last}},{{/-last}} + @Content(mediaType = "{{{mediaType}}}", {{#isArray}}array = @ArraySchema({{/isArray}}schema = @Schema(implementation = {{{baseType}}}.class)){{#isArray}}){{/isArray}}){{^-last}},{{/-last}} {{/produces}} - {{closebrace}}{{/produces.1}}{{^produces.1}}{{#produces}}@Content(mediaType = "{{{mediaType}}}", schema = @Schema(implementation = {{{baseType}}}.class)){{/produces}}{{/produces.1}}{{/baseType}}){{^-last}},{{/-last}}{{#responses.1}} + {{closebrace}}{{/produces.1}}{{^produces.1}}{{#produces}}@Content(mediaType = "{{{mediaType}}}", {{#isArray}}array = @ArraySchema({{/isArray}}schema = @Schema(implementation = {{{baseType}}}.class)){{#isArray}}){{/isArray}}{{/produces}}{{/produces.1}}{{/baseType}}){{^-last}},{{/-last}}{{#responses.1}} {{/responses.1}}{{/responses}}{{#responses.1}} {{closebrace}}{{/responses.1}}{{#vendorExtensions.hasNotBodyParam}}, parameters = {{#vendorExtensions.swaggerParams.1}}{{openbrace}} {{/vendorExtensions.swaggerParams.1}}{{#vendorExtensions.swaggerParams}}{{#vendorExtensions.swaggerParams.1}} - {{/vendorExtensions.swaggerParams.1}}@Parameter(name = "{{baseName}}"{{#description}}, description = "{{{description}}}"{{/description}}{{#required}}, required = true{{/required}}, in = ParameterIn.{{#isCookieParam}}COOKIE{{/isCookieParam}}{{#isHeaderParam}}HEADER{{/isHeaderParam}}{{#isQueryParam}}QUERY{{/isQueryParam}}{{#isPathParam}}PATH{{/isPathParam}}){{^-last}},{{/-last}}{{#vendorExtensions.hasMultipleParams}} + {{/vendorExtensions.swaggerParams.1}}@Parameter(name = "{{baseName}}"{{#isDeprecated}}, deprecated = true{{/isDeprecated}}{{#description}}, description = "{{{description}}}"{{/description}}{{#required}}, required = true{{/required}}, in = ParameterIn.{{#isCookieParam}}COOKIE{{/isCookieParam}}{{#isHeaderParam}}HEADER{{/isHeaderParam}}{{#isQueryParam}}QUERY{{/isQueryParam}}{{#isPathParam}}PATH{{/isPathParam}}){{^-last}},{{/-last}}{{#vendorExtensions.hasMultipleParams}} {{/vendorExtensions.hasMultipleParams}}{{/vendorExtensions.swaggerParams}}{{#vendorExtensions.swaggerParams.1}} {{closebrace}}{{/vendorExtensions.swaggerParams.1}}{{/vendorExtensions.hasNotBodyParam}}{{#hasAuthMethods}}, security = {{#authMethods.1}}{{openbrace}} {{/authMethods.1}}{{#authMethods}}{{#authMethods.1}} {{/authMethods.1}}@SecurityRequirement(name = "{{name}}"{{#isOAuth}}{{#scopes.1}}, scopes = {{openbrace}}{{#scopes}}"{{scope}}"{{^-last}}, {{/-last}}{{/scopes}}{{closebrace}}{{/scopes.1}}{{/isOAuth}}){{^-last}},{{/-last}} {{/authMethods}}{{#authMethods.1}} - {{closebrace}}{{/authMethods.1}}{{/hasAuthMethods}} + {{closebrace}}{{/authMethods.1}}{{/hasAuthMethods}}{{#externalDocs}}, + externalDocs = @ExternalDocumentation(description = "{{externalDocs.description}}", url = "{{externalDocs.url}}"){{/externalDocs}} ) {{/generateSwagger2Annotations}} diff --git a/openapi-generator/src/main/resources/templates/java-micronaut/common/params/validation.mustache b/openapi-generator/src/main/resources/templates/java-micronaut/common/params/validation.mustache index 29e017b88c..c444e128f2 100644 --- a/openapi-generator/src/main/resources/templates/java-micronaut/common/params/validation.mustache +++ b/openapi-generator/src/main/resources/templates/java-micronaut/common/params/validation.mustache @@ -50,9 +50,9 @@ {{/isContainer}} {{!Pattern}} {{#pattern}} - {{^isByteArray}}{{^isDate}}{{^isDateTime}} + {{^isByteArray}}{{^isDate}}{{^isDateTime}}{{^isEmail}} @Pattern(regexp = "{{{pattern}}}") - {{/isDateTime}}{{/isDate}}{{/isByteArray}} + {{/isEmail}}{{/isDateTime}}{{/isDate}}{{/isByteArray}} {{/pattern}} {{!Min length && max length}} {{#minLength}} @@ -78,7 +78,7 @@ {{/maxItems}}{{/minItems}} {{!Email}} {{#isEmail}} - @Email + @Email{{#pattern}}(pattern = "{{{pattern}}}"){{/pattern}} {{/isEmail}} {{!check for integer or long / all others=decimal type with @Decimal isInteger set}} {{#isInteger}} diff --git a/openapi-generator/src/main/resources/templates/java-micronaut/server/controller-interface.mustache b/openapi-generator/src/main/resources/templates/java-micronaut/server/controller-interface.mustache index 0e28635342..11547ab9a6 100644 --- a/openapi-generator/src/main/resources/templates/java-micronaut/server/controller-interface.mustache +++ b/openapi-generator/src/main/resources/templates/java-micronaut/server/controller-interface.mustache @@ -29,9 +29,6 @@ import java.util.Map; import {{javaxPackage}}.validation.Valid; import {{javaxPackage}}.validation.constraints.*; {{/useBeanValidation}} -{{#generateSwagger1Annotations}} -import io.swagger.annotations.*; -{{/generateSwagger1Annotations}} {{#generateSwagger2Annotations}} import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; diff --git a/openapi-generator/src/main/resources/templates/java-micronaut/server/params/type.mustache b/openapi-generator/src/main/resources/templates/java-micronaut/server/params/type.mustache index a94ab25eb3..4525df0772 100644 --- a/openapi-generator/src/main/resources/templates/java-micronaut/server/params/type.mustache +++ b/openapi-generator/src/main/resources/templates/java-micronaut/server/params/type.mustache @@ -1,3 +1,4 @@ +{{#isDeprecated}}@Deprecated{{/isDeprecated}} {{^isEnum}}{{^isDateTime}}{{^isDate}} {{{vendorExtensions.typeWithGenericAnnotations}}} {{/isDate}}{{/isDateTime}}{{/isEnum}} diff --git a/openapi-generator/src/main/resources/templates/kotlin-micronaut/client/api.mustache b/openapi-generator/src/main/resources/templates/kotlin-micronaut/client/api.mustache index 830e3a7e2e..643185af74 100644 --- a/openapi-generator/src/main/resources/templates/kotlin-micronaut/client/api.mustache +++ b/openapi-generator/src/main/resources/templates/kotlin-micronaut/client/api.mustache @@ -21,9 +21,6 @@ import {{javaxPackage}}.annotation.Generated import {{javaxPackage}}.validation.Valid import {{javaxPackage}}.validation.constraints.* {{/useBeanValidation}} -{{#generateSwagger1Annotations}} -import io.swagger.annotations.* -{{/generateSwagger1Annotations}} {{#generateSwagger2Annotations}} import io.swagger.v3.oas.annotations.Operation import io.swagger.v3.oas.annotations.Parameter diff --git a/openapi-generator/src/main/resources/templates/kotlin-micronaut/client/params/type.mustache b/openapi-generator/src/main/resources/templates/kotlin-micronaut/client/params/type.mustache index c1a8e8541f..02db3f4d0b 100644 --- a/openapi-generator/src/main/resources/templates/kotlin-micronaut/client/params/type.mustache +++ b/openapi-generator/src/main/resources/templates/kotlin-micronaut/client/params/type.mustache @@ -1,2 +1,3 @@ +{{#isDeprecated}}@java.lang.Deprecated{{/isDeprecated}} {{#isDateTime}}{{#vendorExtensions.formatPattern}}@Format("{{{vendorExtensions.formatPattern}}}"){{/vendorExtensions.formatPattern}}{{^vendorExtensions.formatPattern}}{{#dateTimeFormat}}@Format("{{{dateTimeFormat}}}"){{/dateTimeFormat}}{{/vendorExtensions.formatPattern}} {{/isDateTime}} {{#isDate}}{{#vendorExtensions.formatPattern}}@Format("{{{vendorExtensions.formatPattern}}}"){{/vendorExtensions.formatPattern}}{{^vendorExtensions.formatPattern}}{{#dateFormat}}@Format("{{{dateFormat}}}"){{/dateFormat}}{{/vendorExtensions.formatPattern}} {{/isDate}} \ No newline at end of file diff --git a/openapi-generator/src/main/resources/templates/kotlin-micronaut/common/model/enum.mustache b/openapi-generator/src/main/resources/templates/kotlin-micronaut/common/model/enum.mustache index 15e270968f..50824bfa06 100644 --- a/openapi-generator/src/main/resources/templates/kotlin-micronaut/common/model/enum.mustache +++ b/openapi-generator/src/main/resources/templates/kotlin-micronaut/common/model/enum.mustache @@ -2,7 +2,14 @@ * {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{description}}{{/description}} * * @param value The value represented by this enum +{{#isDeprecated}} + * + * @deprecated {{#vendorExtensions.x-deprecated-message}} {{{.}}}{{/vendorExtensions.x-deprecated-message}} +{{/isDeprecated}} */ +{{#isDeprecated}} +@Deprecated("{{#vendorExtensions.x-deprecated-message}}{{{.}}}{{/vendorExtensions.x-deprecated-message}}") +{{/isDeprecated}} {{#withXml}} @XmlType(name="{{datatypeWithEnum}}") @XmlEnum({{dataType}}.class) diff --git a/openapi-generator/src/main/resources/templates/kotlin-micronaut/common/model/field_annotations.mustache b/openapi-generator/src/main/resources/templates/kotlin-micronaut/common/model/field_annotations.mustache index 530b728d23..a3611d5a2c 100644 --- a/openapi-generator/src/main/resources/templates/kotlin-micronaut/common/model/field_annotations.mustache +++ b/openapi-generator/src/main/resources/templates/kotlin-micronaut/common/model/field_annotations.mustache @@ -1,3 +1,6 @@ +{{#deprecated}} +@Deprecated("{{#vendorExtensions.x-deprecated-message}}{{{.}}}{{/vendorExtensions.x-deprecated-message}}") +{{/deprecated}} {{>common/params/validation_field}} {{#withXml}} {{#isXmlAttribute}} @@ -21,7 +24,7 @@ {{/isXmlAttribute}} {{/withXml}} {{#generateSwagger2Annotations}} - @{{{vendorExtensions.fieldAnnPrefix}}}Schema(name = "{{{baseName}}}"{{#isReadOnly}}, accessMode = Schema.AccessMode.READ_ONLY{{/isReadOnly}}{{#example}}, example = "{{{.}}}"{{/example}}{{#description}}, description = "{{{.}}}"{{/description}}, requiredMode = {{#required}}Schema.RequiredMode.REQUIRED{{/required}}{{^required}}Schema.RequiredMode.NOT_REQUIRED{{/required}}) + @{{{vendorExtensions.fieldAnnPrefix}}}Schema(name = "{{{baseName}}}"{{#isReadOnly}}, accessMode = Schema.AccessMode.READ_ONLY{{/isReadOnly}}{{#example}}, example = "{{{.}}}"{{/example}}{{#description}}, description = "{{{.}}}"{{/description}}, requiredMode = {{#required}}Schema.RequiredMode.REQUIRED{{/required}}{{^required}}Schema.RequiredMode.NOT_REQUIRED{{/required}}{{#deprecated}}, deprecated = true{{/deprecated}}) {{/generateSwagger2Annotations}} {{#vendorExtensions.x-is-jackson-optional-nullable}} {{!Unannotated, Jackson would pick this up automatically and add it *in addition* to the _JsonNullable getter field}} diff --git a/openapi-generator/src/main/resources/templates/kotlin-micronaut/common/model/pojo.mustache b/openapi-generator/src/main/resources/templates/kotlin-micronaut/common/model/pojo.mustache index fa7037d3c3..c167e03f86 100644 --- a/openapi-generator/src/main/resources/templates/kotlin-micronaut/common/model/pojo.mustache +++ b/openapi-generator/src/main/resources/templates/kotlin-micronaut/common/model/pojo.mustache @@ -2,19 +2,17 @@ {{#formatNoEmptyLines}} /** * {{#description}}{{.}}{{/description}}{{^description}}{{classname}}{{/description}} -{{#vendorExtensions.withRequiredOrOptionalVars}} +{{#isDeprecated}} * -{{/vendorExtensions.withRequiredOrOptionalVars}} -{{#vendorExtensions.requiredVarsWithoutDiscriminator}} - * @param {{vendorExtensions.realName}} {{description}} -{{/vendorExtensions.requiredVarsWithoutDiscriminator}} -{{#vendorExtensions.optionalVars}} - * @param {{vendorExtensions.realName}} {{description}} -{{/vendorExtensions.optionalVars}} + * @deprecated{{#vendorExtensions.x-deprecated-message}} {{{.}}}{{/vendorExtensions.x-deprecated-message}} +{{/isDeprecated}} */ +{{#isDeprecated}} +@Deprecated("{{#vendorExtensions.x-deprecated-message}}{{{.}}}{{/vendorExtensions.x-deprecated-message}}") +{{/isDeprecated}} {{#description}} {{#generateSwagger2Annotations}} -@Schema({{#vendorExtensions.realName}}name = "{{{vendorExtensions.realName}}}", {{/vendorExtensions.realName}}description = "{{{description}}}") +@Schema({{#vendorExtensions.realName}}name = "{{{vendorExtensions.realName}}}", {{/vendorExtensions.realName}}description = "{{{description}}}"{{#isDeprecated}}, deprecated = true{{/isDeprecated}}) {{/generateSwagger2Annotations}} {{/description}} {{#micronaut_serde_jackson}} @@ -45,18 +43,56 @@ {{/vendorExtensions.x-class-extra-annotation}} {{/formatNoEmptyLines}} {{!Declare the class with extends and implements}} -{{#nonPublicApi}}internal {{/nonPublicApi}}{{#hasChildren}}open{{/hasChildren}}{{^hasChildren}}data{{/hasChildren}} class {{classname}}({{#formatNoEmptyLines}} +{{#nonPublicApi}}internal {{/nonPublicApi}}{{#hasChildren}}open{{/hasChildren}}{{^hasChildren}}data{{/hasChildren}} class {{classname}}( {{#vendorExtensions.requiredVarsWithoutDiscriminator}} + + {{#formatNoEmptyLines}} + {{#description}} + /** + * {{description}} + {{#deprecated}} + * + * @deprecated{{#vendorExtensions.x-deprecated-message}} {{{.}}}{{/vendorExtensions.x-deprecated-message}} + {{/deprecated}} + */ + {{/description}} + {{^description}} + {{#deprecated}} + /** + * @deprecated{{#vendorExtensions.x-deprecated-message}} {{{.}}}{{/vendorExtensions.x-deprecated-message}} + */ + {{/deprecated}} + {{/description}} {{>common/model/field_annotations}} {{#vendorExtensions.overridden}}override {{/vendorExtensions.overridden}}{{^vendorExtensions.overridden}}{{#hasChildren}}open {{/hasChildren}}{{/vendorExtensions.overridden}}var {{{name}}}: {{{vendorExtensions.typeWithEnumWithGenericAnnotations}}}{{#vendorExtensions.defaultValueInit}} = {{{.}}}{{/vendorExtensions.defaultValueInit}}{{^vendorExtensions.defaultValueInit}}{{#isNullable}} = null{{/isNullable}}{{/vendorExtensions.defaultValueInit}}, + {{/formatNoEmptyLines}} {{/vendorExtensions.requiredVarsWithoutDiscriminator}} {{#vendorExtensions.withInheritance}} {{#vendorExtensions.optionalVars}} + + {{#formatNoEmptyLines}} + {{#description}} + /** + * {{description}} + {{#deprecated}} + * + * @deprecated{{#vendorExtensions.x-deprecated-message}} {{{.}}}{{/vendorExtensions.x-deprecated-message}} + {{/deprecated}} + */ + {{/description}} + {{^description}} + {{#deprecated}} + /** + * @deprecated{{#vendorExtensions.x-deprecated-message}} {{{.}}}{{/vendorExtensions.x-deprecated-message}} + */ + {{/deprecated}} + {{/description}} {{>common/model/field_annotations}} {{#vendorExtensions.overridden}}override {{/vendorExtensions.overridden}}{{^vendorExtensions.overridden}}{{#vendorExtensions.hasChildren}}open {{/vendorExtensions.hasChildren}}{{/vendorExtensions.overridden}}var {{{name}}}: {{{vendorExtensions.typeWithEnumWithGenericAnnotations}}} = {{#vendorExtensions.defaultValueInit}}{{{.}}}{{/vendorExtensions.defaultValueInit}}{{^vendorExtensions.defaultValueInit}}null{{/vendorExtensions.defaultValueInit}}, + {{/formatNoEmptyLines}} {{/vendorExtensions.optionalVars}} {{/vendorExtensions.withInheritance}} -{{/formatNoEmptyLines}}){{#parent}}: {{{parent}}}({{#vendorExtensions.requiredParentVarsWithoutDiscriminator}}{{{name}}}{{^-last}}, {{/-last}}{{/vendorExtensions.requiredParentVarsWithoutDiscriminator}}) {{/parent}}{{#vendorExtensions.x-implements}}{{#parent}}, {{/parent}}{{^parent}}: {{/parent}}{{^-first}}, {{/-first}}{{{.}}}{{/vendorExtensions.x-implements}} {{openbrace}} +){{#parent}}: {{{parent}}}({{#vendorExtensions.requiredParentVarsWithoutDiscriminator}}{{{name}}}{{^-last}}, {{/-last}}{{/vendorExtensions.requiredParentVarsWithoutDiscriminator}}) {{/parent}}{{#vendorExtensions.x-implements}}{{#parent}}, {{/parent}}{{^parent}}: {{/parent}}{{^-first}}, {{/-first}}{{{.}}}{{/vendorExtensions.x-implements}} {{openbrace}} {{#vendorExtensions.withInheritance}} diff --git a/openapi-generator/src/main/resources/templates/kotlin-micronaut/common/operationAnnotations.mustache b/openapi-generator/src/main/resources/templates/kotlin-micronaut/common/operationAnnotations.mustache index c19500e8ed..a354ebf256 100644 --- a/openapi-generator/src/main/resources/templates/kotlin-micronaut/common/operationAnnotations.mustache +++ b/openapi-generator/src/main/resources/templates/kotlin-micronaut/common/operationAnnotations.mustache @@ -14,7 +14,8 @@ {{#-first}} * {{/-first}} - * @param {{vendorExtensions.realName}}{{#description}} {{description}}{{/description}}{{#required}} (required){{/required}}{{^required}} (optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}} + * @param {{paramName}}{{#description}} {{description}}{{/description}}{{#required}} (required){{/required}}{{^required}} (optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}{{#vendorExtensions.x-deprecated-message}} + * Deprecated: {{{.}}}{{/vendorExtensions.x-deprecated-message}} {{/vendorExtensions.originalParams}} {{#returnType}} {{^allParams.0}} @@ -22,6 +23,10 @@ {{/allParams.0}} * @return {{returnType}} {{/returnType}} + {{#isDeprecated}} + * + * @deprecated{{#vendorExtensions.x-deprecated-message}} {{{.}}}{{/vendorExtensions.x-deprecated-message}} + {{/isDeprecated}} {{#externalDocs}} * {{description}} * @@ -29,6 +34,10 @@ {{/externalDocs}} */ {{#generateSwagger2Annotations}} + @Suppress("DEPRECATED_JAVA_ANNOTATION") + {{#isDeprecated}} + @Deprecated("{{#vendorExtensions.x-deprecated-message}}{{{.}}}{{/vendorExtensions.x-deprecated-message}}") + {{/isDeprecated}} @Operation( operationId = "{{{operationId}}}", {{#summary}} @@ -52,7 +61,7 @@ ]{{#vendorExtensions.hasNotBodyParam}}, parameters = [ {{#vendorExtensions.swaggerParams}} - Parameter(name = "{{baseName}}"{{#description}}, description = "{{{description}}}"{{/description}}{{#required}}, required = true{{/required}}, `in` = ParameterIn.{{#isCookieParam}}COOKIE{{/isCookieParam}}{{#isHeaderParam}}HEADER{{/isHeaderParam}}{{#isQueryParam}}QUERY{{/isQueryParam}}{{#isPathParam}}PATH{{/isPathParam}}){{^-last}},{{/-last}} + Parameter(name = "{{baseName}}"{{#isDeprecated}}, deprecated = true{{/isDeprecated}}{{#description}}, description = "{{{description}}}"{{/description}}{{#required}}, required = true{{/required}}, `in` = ParameterIn.{{#isCookieParam}}COOKIE{{/isCookieParam}}{{#isHeaderParam}}HEADER{{/isHeaderParam}}{{#isQueryParam}}QUERY{{/isQueryParam}}{{#isPathParam}}PATH{{/isPathParam}}){{^-last}},{{/-last}} {{/vendorExtensions.swaggerParams}} ]{{/vendorExtensions.hasNotBodyParam}}{{#hasAuthMethods}}, security = [ diff --git a/openapi-generator/src/main/resources/templates/kotlin-micronaut/server/controller-interface.mustache b/openapi-generator/src/main/resources/templates/kotlin-micronaut/server/controller-interface.mustache index 67756a7167..0611df7ab8 100644 --- a/openapi-generator/src/main/resources/templates/kotlin-micronaut/server/controller-interface.mustache +++ b/openapi-generator/src/main/resources/templates/kotlin-micronaut/server/controller-interface.mustache @@ -74,6 +74,9 @@ interface {{classname}} { {{#isDateTime}}{{#dateTimeFormat}}@Format("{{{dateTimeFormat}}}"){{/dateTimeFormat}}{{/isDateTime}} {{#isDate}}{{#dateFormat}}@Format("{{{dateFormat}}}"){{/dateFormat}}{{/isDate}} {{/vendorExtensions.formatPattern}} + {{#isDeprecated}} + @java.lang.Deprecated + {{/isDeprecated}} {{{paramName}}}: {{#isEnum}}{{{vendorExtensions.typeWithEnumWithGenericAnnotations}}}{{/isEnum}}{{^isEnum}}{{{vendorExtensions.typeWithGenericAnnotations}}}{{/isEnum}}{{^-last}},{{/-last}}{{/formatSingleLine}} {{/allParams}}){{#returnType}}: {{{returnType}}}{{/returnType}} {{/formatNoEmptyLines}} diff --git a/openapi-generator/src/test/java/io/micronaut/openapi/generator/JavaMicronautClientCodegenTest.java b/openapi-generator/src/test/java/io/micronaut/openapi/generator/JavaMicronautClientCodegenTest.java index be4cf3d08c..141c087099 100644 --- a/openapi-generator/src/test/java/io/micronaut/openapi/generator/JavaMicronautClientCodegenTest.java +++ b/openapi-generator/src/test/java/io/micronaut/openapi/generator/JavaMicronautClientCodegenTest.java @@ -1040,4 +1040,123 @@ void testPrimitives() { "private List<@NotNull Long> longTypes" ); } + + @Test + void testDeprecated() { + + var codegen = new JavaMicronautClientCodegen(); + codegen.setGenerateSwaggerAnnotations(true); + String outputPath = generateFiles(codegen, "src/test/resources/3_0/deprecated.yml", CodegenConstants.APIS, CodegenConstants.MODELS); + String path = outputPath + "src/main/java/org/openapitools/"; + + assertFileContains(path + "api/ParametersApi.java", + """ + /** + * A method to send primitives as request parameters + * + * @param name (required) + * Deprecated: Deprecated message2 + * @param age (required) + * @param height (required) + * Deprecated: Deprecated message4 + * @return Success (status code 200) + * or An unexpected error has occurred (status code default) + * @deprecated Deprecated message1 + */ + @Deprecated + @Operation( + operationId = "sendPrimitives", + description = "A method to send primitives as request parameters", + deprecated = true, + responses = { + @ApiResponse(responseCode = "200", description = "Success", content = @Content(mediaType = "application/json", schema = @Schema(implementation = SendPrimitivesResponse.class))), + @ApiResponse(responseCode = "default", description = "An unexpected error has occurred") + }, + parameters = { + @Parameter(name = "name", deprecated = true, required = true, in = ParameterIn.PATH), + @Parameter(name = "age", required = true, in = ParameterIn.QUERY), + @Parameter(name = "height", deprecated = true, required = true, in = ParameterIn.HEADER) + } + ) + @Get("/sendPrimitives/{name}") + Mono<@Valid SendPrimitivesResponse> sendPrimitives( + @PathVariable("name") @NotNull @Deprecated String name, + @QueryValue("age") @NotNull BigDecimal age, + @Header("height") @NotNull @Deprecated Float height + ); + """); + + assertFileContains(path + "model/SendPrimitivesResponse.java", + """ + /** + * SendPrimitivesResponse + * + * @deprecated Deprecated message5 + */ + @Deprecated + """, + """ + /** + * @deprecated Deprecated message6 + */ + @Deprecated + @Nullable + @Schema(name = "name", requiredMode = Schema.RequiredMode.NOT_REQUIRED, deprecated = true) + @JsonProperty(JSON_PROPERTY_NAME) + @JsonInclude(JsonInclude.Include.USE_DEFAULTS) + private String name; + """, + """ + /** + * @return the name property value + * + * @deprecated Deprecated message6 + */ + @Deprecated + public String getName() { + return name; + } + """, + """ + /** + * Set the name property value + * + * @param name property value to set + * + * @deprecated Deprecated message6 + */ + @Deprecated + public void setName(String name) { + this.name = name; + } + """, + """ + /** + * Set name in a chainable fashion. + * + * @return The same instance of SendPrimitivesResponse for chaining. + * + * @deprecated Deprecated message6 + */ + @Deprecated + public SendPrimitivesResponse name(String name) { + this.name = name; + return this; + } + """); + + assertFileContains(path + "model/StateEnum.java", + """ + /** + * Gets or Sets StateEnum + * + * @deprecated Deprecated message9 + */ + @Deprecated + @Serdeable + @Generated("io.micronaut.openapi.generator.JavaMicronautClientCodegen") + public enum StateEnum { + """ + ); + } } diff --git a/openapi-generator/src/test/java/io/micronaut/openapi/generator/JavaMicronautServerCodegenTest.java b/openapi-generator/src/test/java/io/micronaut/openapi/generator/JavaMicronautServerCodegenTest.java index 99d91ca650..d433da3c7c 100644 --- a/openapi-generator/src/test/java/io/micronaut/openapi/generator/JavaMicronautServerCodegenTest.java +++ b/openapi-generator/src/test/java/io/micronaut/openapi/generator/JavaMicronautServerCodegenTest.java @@ -593,4 +593,51 @@ public CurrencyInvoiceCreateDto sellerVatId(String sellerVatId) { """ ); } + + @Test + void testDeprecated() { + + var codegen = new JavaMicronautServerCodegen(); + codegen.setGenerateSwaggerAnnotations(true); + String outputPath = generateFiles(codegen, "src/test/resources/3_0/deprecated.yml", CodegenConstants.APIS, CodegenConstants.MODELS); + String path = outputPath + "src/main/java/org/openapitools/"; + + assertFileContains(path + "api/ParametersApi.java", + """ + /** + * A method to send primitives as request parameters + * + * @param name (required) + * Deprecated: Deprecated message2 + * @param age (required) + * @param height (required) + * Deprecated: Deprecated message4 + * @return Success (status code 200) + * or An unexpected error has occurred (status code default) + * @deprecated Deprecated message1 + */ + @Deprecated + @Operation( + operationId = "sendPrimitives", + description = "A method to send primitives as request parameters", + deprecated = true, + responses = { + @ApiResponse(responseCode = "200", description = "Success", content = @Content(mediaType = "application/json", schema = @Schema(implementation = SendPrimitivesResponse.class))), + @ApiResponse(responseCode = "default", description = "An unexpected error has occurred") + }, + parameters = { + @Parameter(name = "name", deprecated = true, required = true, in = ParameterIn.PATH), + @Parameter(name = "age", required = true, in = ParameterIn.QUERY), + @Parameter(name = "height", deprecated = true, required = true, in = ParameterIn.HEADER) + } + ) + @Get("/sendPrimitives/{name}") + @Secured(SecurityRule.IS_ANONYMOUS) + Mono<@Valid SendPrimitivesResponse> sendPrimitives( + @PathVariable("name") @NotNull @Deprecated String name, + @QueryValue("age") @NotNull BigDecimal age, + @Header("height") @NotNull @Deprecated Float height + ); + """); + } } diff --git a/openapi-generator/src/test/java/io/micronaut/openapi/generator/KotlinMicronautClientCodegenTest.java b/openapi-generator/src/test/java/io/micronaut/openapi/generator/KotlinMicronautClientCodegenTest.java index 70de70ab9a..eb173fd0a6 100644 --- a/openapi-generator/src/test/java/io/micronaut/openapi/generator/KotlinMicronautClientCodegenTest.java +++ b/openapi-generator/src/test/java/io/micronaut/openapi/generator/KotlinMicronautClientCodegenTest.java @@ -777,10 +777,15 @@ fun uploadFile( assertFileContains(path + "model/FileCreateDto.kt", """ data class FileCreateDto( + + /** + * Customer type ORG + */ @field:NotNull @field:Pattern(regexp = "^ORG$") @field:JsonProperty(JSON_PROPERTY_TYPE_CODE) var typeCode: String = "ORG", + @field:NotNull @field:JsonProperty(JSON_PROPERTY_ORG_NAME) var orgName: String, @@ -1042,4 +1047,89 @@ void testPrimitives() { "longTypes: List<@NotNull Long>" ); } + + @Test + void testDeprecated() { + + var codegen = new KotlinMicronautClientCodegen(); + codegen.setGenerateSwaggerAnnotations(true); + String outputPath = generateFiles(codegen, "src/test/resources/3_0/deprecated.yml", CodegenConstants.APIS, CodegenConstants.MODELS); + String path = outputPath + "src/main/kotlin/org/openapitools/"; + + assertFileContains(path + "api/ParametersApi.kt", + """ + /** + * A method to send primitives as request parameters + * + * @param name (required) + * Deprecated: Deprecated message2 + * @param age (required) + * @param height (required) + * Deprecated: Deprecated message4 + * @return Mono<SendPrimitivesResponse> + * + * @deprecated Deprecated message1 + */ + @Suppress("DEPRECATED_JAVA_ANNOTATION") + @Deprecated("Deprecated message1") + @Operation( + operationId = "sendPrimitives", + description = "A method to send primitives as request parameters", + responses = [ + ApiResponse(responseCode = "200", description = "Success", content = [ + Content(mediaType = "application/json", schema = Schema(implementation = SendPrimitivesResponse::class)) + ]), + ApiResponse(responseCode = "default", description = "An unexpected error has occurred") + ], + parameters = [ + Parameter(name = "name", deprecated = true, required = true, `in` = ParameterIn.PATH), + Parameter(name = "age", required = true, `in` = ParameterIn.QUERY), + Parameter(name = "height", deprecated = true, required = true, `in` = ParameterIn.HEADER) + ] + ) + @Get("/sendPrimitives/{name}") + fun sendPrimitives( + @PathVariable("name") @NotNull @java.lang.Deprecated name: String, + @QueryValue("age") @NotNull age: BigDecimal, + @Header("height") @NotNull @java.lang.Deprecated height: Float + ): Mono + """); + + assertFileContains(path + "model/SendPrimitivesResponse.kt", + """ + /** + * SendPrimitivesResponse + * + * @deprecated Deprecated message5 + */ + @Deprecated("Deprecated message5") + """, + """ + /** + * @deprecated Deprecated message6 + */ + @Deprecated("Deprecated message6") + @field:Nullable + @field:Schema(name = "name", requiredMode = Schema.RequiredMode.NOT_REQUIRED, deprecated = true) + @field:JsonProperty(JSON_PROPERTY_NAME) + @field:JsonInclude(JsonInclude.Include.USE_DEFAULTS) + var name: String? = null, + """); + + assertFileContains(path + "model/StateEnum.kt", + """ + /** + * Gets or Sets StateEnum + * + * @param value The value represented by this enum + * + * @deprecated Deprecated message9 + */ + @Deprecated("Deprecated message9") + @Serdeable + @Generated("io.micronaut.openapi.generator.KotlinMicronautClientCodegen") + enum class StateEnum( + """ + ); + } } diff --git a/openapi-generator/src/test/java/io/micronaut/openapi/generator/KotlinMicronautServerCodegenTest.java b/openapi-generator/src/test/java/io/micronaut/openapi/generator/KotlinMicronautServerCodegenTest.java index 98409f6d0f..0a2e9bad54 100644 --- a/openapi-generator/src/test/java/io/micronaut/openapi/generator/KotlinMicronautServerCodegenTest.java +++ b/openapi-generator/src/test/java/io/micronaut/openapi/generator/KotlinMicronautServerCodegenTest.java @@ -665,4 +665,53 @@ void testPolymorphism() { """ ); } + + @Test + void testDeprecated() { + + var codegen = new KotlinMicronautServerCodegen(); + codegen.setGenerateSwaggerAnnotations(true); + String outputPath = generateFiles(codegen, "src/test/resources/3_0/deprecated.yml", CodegenConstants.APIS, CodegenConstants.MODELS); + String path = outputPath + "src/main/kotlin/org/openapitools/"; + + assertFileContains(path + "api/ParametersApi.kt", + """ + /** + * A method to send primitives as request parameters + * + * @param name (required) + * Deprecated: Deprecated message2 + * @param age (required) + * @param height (required) + * Deprecated: Deprecated message4 + * @return Mono<SendPrimitivesResponse> + * + * @deprecated Deprecated message1 + */ + @Suppress("DEPRECATED_JAVA_ANNOTATION") + @Deprecated("Deprecated message1") + @Operation( + operationId = "sendPrimitives", + description = "A method to send primitives as request parameters", + responses = [ + ApiResponse(responseCode = "200", description = "Success", content = [ + Content(mediaType = "application/json", schema = Schema(implementation = SendPrimitivesResponse::class)) + ]), + ApiResponse(responseCode = "default", description = "An unexpected error has occurred") + ], + parameters = [ + Parameter(name = "name", deprecated = true, required = true, `in` = ParameterIn.PATH), + Parameter(name = "age", required = true, `in` = ParameterIn.QUERY), + Parameter(name = "height", deprecated = true, required = true, `in` = ParameterIn.HEADER) + ] + ) + @Get("/sendPrimitives/{name}") + @Secured(SecurityRule.IS_ANONYMOUS) + fun sendPrimitives( + @PathVariable("name") @NotNull @java.lang.Deprecated name: String, + @QueryValue("age") @NotNull age: BigDecimal, + @Header("height") @NotNull @java.lang.Deprecated height: Float + ): Mono + """); + } } diff --git a/openapi-generator/src/test/resources/3_0/deprecated.yml b/openapi-generator/src/test/resources/3_0/deprecated.yml new file mode 100644 index 0000000000..ed298f75e0 --- /dev/null +++ b/openapi-generator/src/test/resources/3_0/deprecated.yml @@ -0,0 +1,81 @@ +openapi: "3.0.0" +info: + version: 1.0.0 + title: Compute API + description: API for the Compute Service +servers: + - url: localhost:8000/api + description: The api server + +paths: + /sendPrimitives/{name}: + get: + deprecated: true + x-deprecated-message: Deprecated message1 + operationId: sendPrimitives + tags: [ parameters ] + description: A method to send primitives as request parameters + parameters: + - name: name + in: path + deprecated: true + x-deprecated-message: Deprecated message2 + required: true + schema: + type: string + - name: age + in: query + required: true + schema: + type: number + - name: height + in: header + deprecated: true + x-deprecated-message: Deprecated message4 + required: true + schema: + type: number + format: float + responses: + 200: + description: Success + content: + application/json: + schema: + $ref: '#/components/schemas/SendPrimitivesResponse' + default: + $ref: '#/components/responses/Error' +components: + schemas: + SendPrimitivesResponse: + type: object + deprecated: true + x-deprecated-message: Deprecated message5 + properties: + name: + type: string + deprecated: true + x-deprecated-message: Deprecated message6 + age: + type: number + SimpleModel: + type: object + properties: + color: + type: string + minLength: 2 + size: + type: string + minLength: 2 + deprecated: true + x-deprecated-message: Deprecated message8 + state: + $ref: '#/components/schemas/StateEnum' + StateEnum: + type: string + deprecated: true + x-deprecated-message: Deprecated message9 + enum: ['starting', 'running', 'stopped', 'deleted'] + responses: + Error: + description: An unexpected error has occurred