diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenProperty.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenProperty.java index da32ae09c538..53b9458d2ead 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenProperty.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenProperty.java @@ -54,6 +54,7 @@ public class CodegenProperty implements Cloneable, IJsonSchemaValidationProperti public boolean exclusiveMaximum; public boolean hasMore; public boolean required; + public boolean deprecated; public boolean secondaryParam; public boolean hasMoreNonReadOnly; // for model constructor, true if next property is not readonly public boolean isPrimitiveType; @@ -554,6 +555,7 @@ public String toString() { sb.append(", exclusiveMaximum=").append(exclusiveMaximum); sb.append(", hasMore=").append(hasMore); sb.append(", required=").append(required); + sb.append(", deprecated=").append(deprecated); sb.append(", secondaryParam=").append(secondaryParam); sb.append(", hasMoreNonReadOnly=").append(hasMoreNonReadOnly); sb.append(", isPrimitiveType=").append(isPrimitiveType); @@ -619,6 +621,7 @@ public boolean equals(Object o) { exclusiveMaximum == that.exclusiveMaximum && hasMore == that.hasMore && required == that.required && + deprecated == this.deprecated && secondaryParam == that.secondaryParam && hasMoreNonReadOnly == that.hasMoreNonReadOnly && isPrimitiveType == that.isPrimitiveType && @@ -698,16 +701,18 @@ public boolean equals(Object o) { @Override public int hashCode() { - return Objects.hash(openApiType, baseName, complexType, getter, setter, description, dataType, - datatypeWithEnum, dataFormat, name, min, max, defaultValue, defaultValueWithParam, baseType, - containerType, title, unescapedDescription, maxLength, minLength, pattern, example, jsonSchema, - minimum, maximum, exclusiveMinimum, exclusiveMaximum, hasMore, required, secondaryParam, - hasMoreNonReadOnly, isPrimitiveType, isModel, isContainer, isString, isNumeric, isInteger, - isLong, isNumber, isFloat, isDouble, isByteArray, isBinary, isFile, isBoolean, isDate, isDateTime, - isUuid, isUri, isEmail, isFreeFormObject, isListContainer, isMapContainer, isEnum, isReadOnly, - isWriteOnly, isNullable, isSelfReference, isCircularReference, _enum, allowableValues, items, - mostInnerItems, vendorExtensions, hasValidation, isInherited, discriminatorValue, nameInCamelCase, - nameInSnakeCase, enumName, maxItems, minItems, isXmlAttribute, xmlPrefix, xmlName, xmlNamespace, - isXmlWrapped, multipleOf); + return Objects.hash(openApiType, baseName, complexType, getter, setter, description, + dataType, datatypeWithEnum, dataFormat, name, min, max, defaultValue, + defaultValueWithParam, baseType, containerType, title, unescapedDescription, + maxLength, minLength, pattern, example, jsonSchema, minimum, maximum, + exclusiveMinimum, exclusiveMaximum, hasMore, required, deprecated, secondaryParam, + hasMoreNonReadOnly, isPrimitiveType, isModel, isContainer, isString, isNumeric, + isInteger, isLong, isNumber, isFloat, isDouble, isByteArray, isBinary, isFile, + isBoolean, isDate, isDateTime, isUuid, isUri, isEmail, isFreeFormObject, + isListContainer, isMapContainer, isEnum, isReadOnly, isWriteOnly, isNullable, + isSelfReference, isCircularReference, _enum, allowableValues, items, mostInnerItems, + vendorExtensions, hasValidation, isInherited, discriminatorValue, nameInCamelCase, + nameInSnakeCase, enumName, maxItems, minItems, isXmlAttribute, xmlPrefix, xmlName, + xmlNamespace, isXmlWrapped); } } 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 65b06022d29f..fcf606eb5f15 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 @@ -2246,6 +2246,10 @@ public CodegenProperty fromProperty(String name, Schema p) { property.defaultValue = toDefaultValue(p); property.defaultValueWithParam = toDefaultValueWithParam(name, p); property.jsonSchema = Json.pretty(p); + + if (p.getDeprecated() != null) { + property.deprecated = p.getDeprecated(); + } if (p.getReadOnly() != null) { property.isReadOnly = p.getReadOnly(); } @@ -5459,4 +5463,4 @@ public FeatureSet getFeatureSet() { public void setFeatureSet(final FeatureSet featureSet) { this.featureSet = featureSet == null ? DefaultFeatureSet : featureSet; } -} +} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/kotlin-spring/dataClassOptVar.mustache b/modules/openapi-generator/src/main/resources/kotlin-spring/dataClassOptVar.mustache index 5e801f735768..0f5001411af8 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-spring/dataClassOptVar.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/dataClassOptVar.mustache @@ -1,4 +1,5 @@ {{#useBeanValidation}}{{#required}} {{^isReadOnly}}@get:NotNull{{/isReadOnly}} {{/required}}{{>beanValidationModel}}{{/useBeanValidation}}{{#swaggerAnnotations}} - @ApiModelProperty({{#example}}example = "{{{example}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}{{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}value = "{{{description}}}"){{/swaggerAnnotations}} + @ApiModelProperty({{#example}}example = "{{{example}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}{{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}value = "{{{description}}}"){{/swaggerAnnotations}}{{#deprecated}} + @Deprecated(message=""){{/deprecated}} @JsonProperty("{{{baseName}}}"){{#isInherited}} override{{/isInherited}} {{>modelMutable}} {{{name}}}: {{#isEnum}}{{#isListContainer}}{{baseType}}<{{/isListContainer}}{{classname}}.{{nameInCamelCase}}{{#isListContainer}}>{{/isListContainer}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}? = {{#defaultvalue}}{{defaultvalue}}{{/defaultvalue}}{{^defaultvalue}}null{{/defaultvalue}} \ No newline at end of file diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java index 1c134dcb2d03..83dfc91ebd25 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java @@ -678,6 +678,22 @@ public void testNullableProperty() { Assert.assertTrue(property.isNullable); } + @Test + public void testDeprecatedProperty() { + final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/property-deplicated.yaml"); + new InlineModelResolver().flatten(openAPI); + final DefaultCodegen codegen = new DefaultCodegen(); + codegen.setOpenAPI(openAPI); + + final Map responseProperties = Collections.unmodifiableMap(openAPI.getComponents().getSchemas().get("Response").getProperties()); + final Map requestProperties = Collections.unmodifiableMap(openAPI.getComponents().getSchemas().get("Response").getProperties()); + + Assert.assertTrue(codegen.fromProperty("firstName",(Schema) responseProperties.get("firstName")).deprecated); + Assert.assertFalse(codegen.fromProperty("customerCode",(Schema) responseProperties.get("customerCode")).deprecated); + Assert.assertTrue(codegen.fromProperty("firstName",(Schema) requestProperties.get("firstName")).deprecated); + Assert.assertFalse(codegen.fromProperty("customerCode",(Schema) requestProperties.get("customerCode")).deprecated); + } + @Test public void integerSchemaPropertyAndModelTest() { OpenAPI openAPI = TestUtils.createOpenAPI(); diff --git a/modules/openapi-generator/src/test/resources/3_0/property-deplicated.yaml b/modules/openapi-generator/src/test/resources/3_0/property-deplicated.yaml new file mode 100644 index 000000000000..d4d8220c33ac --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_0/property-deplicated.yaml @@ -0,0 +1,46 @@ +openapi: 3.0.1 +info: + version: 1.0.0 + title: Example + license: + name: MIT +servers: + - url: http://api.example.xyz/v1 +paths: + /deprecated-test: + x-swagger-router-controller: /deprecated-test + post: + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/Request' + responses: + '200': + description: responses + content: + application/json: + schema: + $ref: '#/components/schemas/Response' +components: + schemas: + Request: + type: object + properties: + customerCode: + type: string + example: '0001' + firstName: + type: string + deprecated: true + example: 'first' + Response: + type: object + properties: + customerCode: + type: string + example: '0001' + firstName: + type: string + deprecated: true + example: 'first' diff --git a/samples/server/petstore/kotlin-springboot-modelMutable/.openapi-generator/VERSION b/samples/server/petstore/kotlin-springboot-modelMutable/.openapi-generator/VERSION index d168f1d8bdaa..58592f031f65 100644 --- a/samples/server/petstore/kotlin-springboot-modelMutable/.openapi-generator/VERSION +++ b/samples/server/petstore/kotlin-springboot-modelMutable/.openapi-generator/VERSION @@ -1 +1 @@ -4.2.1-SNAPSHOT \ No newline at end of file +4.2.3-SNAPSHOT \ No newline at end of file diff --git a/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/model/Pet.kt b/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/model/Pet.kt index f0ff8c00c1df..5868cb23e3ff 100644 --- a/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/model/Pet.kt +++ b/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/model/Pet.kt @@ -16,10 +16,10 @@ import io.swagger.annotations.ApiModelProperty /** * A pet for sale in the pet store - * @param id - * @param category * @param name * @param photoUrls + * @param id + * @param category * @param tags * @param status pet status in the store */