From b3c9bc394da7d6ee6127c46974afa7da58be6b72 Mon Sep 17 00:00:00 2001 From: Yutaka MIyamae Date: Thu, 23 Jan 2020 19:58:25 +0900 Subject: [PATCH 1/7] add Deprecated in kotlin dataClass --- .../src/main/resources/kotlin-spring/dataClassOptVar.mustache | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 From 73e2ef348bc9fca2dda632b70e5507d9746c8a99 Mon Sep 17 00:00:00 2001 From: Yutaka MIyamae Date: Thu, 23 Jan 2020 20:00:49 +0900 Subject: [PATCH 2/7] add deprecated in CodegenProperty --- .../main/java/org/openapitools/codegen/CodegenProperty.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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..633534bb4b2b 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 && @@ -701,7 +704,7 @@ 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, + 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, From 663606ab9fc8570c665bea4d6daeb74cd21ccbf3 Mon Sep 17 00:00:00 2001 From: Yutaka MIyamae Date: Thu, 23 Jan 2020 20:02:06 +0900 Subject: [PATCH 3/7] format (Column limit: 100) --- .../openapitools/codegen/CodegenProperty.java | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) 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 633534bb4b2b..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 @@ -701,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, 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, 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); } } From 4ea8d3920057a7213e06c1dae1b04414cbf24ec9 Mon Sep 17 00:00:00 2001 From: Yutaka MIyamae Date: Thu, 23 Jan 2020 20:05:20 +0900 Subject: [PATCH 4/7] set property.deprecated --- .../main/java/org/openapitools/codegen/DefaultCodegen.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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..417e1399cba9 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 From 1463af52ee148fef67d1f8ab5b23be6847dc89e1 Mon Sep 17 00:00:00 2001 From: Yutaka MIyamae Date: Thu, 23 Jan 2020 20:07:34 +0900 Subject: [PATCH 5/7] add test --- .../codegen/DefaultCodegenTest.java | 16 +++++++ .../resources/3_0/property-deplicated.yaml | 46 +++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 modules/openapi-generator/src/test/resources/3_0/property-deplicated.yaml 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' From 5adbdcdf89b9d50069741b97c0347f7c8ce8e3a2 Mon Sep 17 00:00:00 2001 From: Yutaka MIyamae Date: Thu, 23 Jan 2020 20:09:39 +0900 Subject: [PATCH 6/7] run ./bin/kotlin-springboot-petstore-all.sh --- .../kotlin-springboot-modelMutable/.openapi-generator/VERSION | 2 +- .../src/main/kotlin/org/openapitools/model/Pet.kt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) 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 */ From aad631c15dad0a9540cd1fdc7c7d702e5b407199 Mon Sep 17 00:00:00 2001 From: Yutaka MIyamae Date: Mon, 27 Jan 2020 20:03:45 +0900 Subject: [PATCH 7/7] trim space --- .../src/main/java/org/openapitools/codegen/DefaultCodegen.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 417e1399cba9..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 @@ -2247,7 +2247,7 @@ public CodegenProperty fromProperty(String name, Schema p) { property.defaultValueWithParam = toDefaultValueWithParam(name, p); property.jsonSchema = Json.pretty(p); - if ( p.getDeprecated() != null) { + if (p.getDeprecated() != null) { property.deprecated = p.getDeprecated(); } if (p.getReadOnly() != null) {