forked from loafle/openapi-generator-original
Add deprecated annotation in kotlin-spring (#5090)
* add Deprecated in kotlin dataClass * add deprecated in CodegenProperty * format (Column limit: 100) * set property.deprecated * add test * run ./bin/kotlin-springboot-petstore-all.sh * trim space
This commit is contained in:
@@ -54,6 +54,7 @@ public class CodegenProperty implements Cloneable, IJsonSchemaValidationProperti
|
|||||||
public boolean exclusiveMaximum;
|
public boolean exclusiveMaximum;
|
||||||
public boolean hasMore;
|
public boolean hasMore;
|
||||||
public boolean required;
|
public boolean required;
|
||||||
|
public boolean deprecated;
|
||||||
public boolean secondaryParam;
|
public boolean secondaryParam;
|
||||||
public boolean hasMoreNonReadOnly; // for model constructor, true if next property is not readonly
|
public boolean hasMoreNonReadOnly; // for model constructor, true if next property is not readonly
|
||||||
public boolean isPrimitiveType;
|
public boolean isPrimitiveType;
|
||||||
@@ -554,6 +555,7 @@ public class CodegenProperty implements Cloneable, IJsonSchemaValidationProperti
|
|||||||
sb.append(", exclusiveMaximum=").append(exclusiveMaximum);
|
sb.append(", exclusiveMaximum=").append(exclusiveMaximum);
|
||||||
sb.append(", hasMore=").append(hasMore);
|
sb.append(", hasMore=").append(hasMore);
|
||||||
sb.append(", required=").append(required);
|
sb.append(", required=").append(required);
|
||||||
|
sb.append(", deprecated=").append(deprecated);
|
||||||
sb.append(", secondaryParam=").append(secondaryParam);
|
sb.append(", secondaryParam=").append(secondaryParam);
|
||||||
sb.append(", hasMoreNonReadOnly=").append(hasMoreNonReadOnly);
|
sb.append(", hasMoreNonReadOnly=").append(hasMoreNonReadOnly);
|
||||||
sb.append(", isPrimitiveType=").append(isPrimitiveType);
|
sb.append(", isPrimitiveType=").append(isPrimitiveType);
|
||||||
@@ -619,6 +621,7 @@ public class CodegenProperty implements Cloneable, IJsonSchemaValidationProperti
|
|||||||
exclusiveMaximum == that.exclusiveMaximum &&
|
exclusiveMaximum == that.exclusiveMaximum &&
|
||||||
hasMore == that.hasMore &&
|
hasMore == that.hasMore &&
|
||||||
required == that.required &&
|
required == that.required &&
|
||||||
|
deprecated == this.deprecated &&
|
||||||
secondaryParam == that.secondaryParam &&
|
secondaryParam == that.secondaryParam &&
|
||||||
hasMoreNonReadOnly == that.hasMoreNonReadOnly &&
|
hasMoreNonReadOnly == that.hasMoreNonReadOnly &&
|
||||||
isPrimitiveType == that.isPrimitiveType &&
|
isPrimitiveType == that.isPrimitiveType &&
|
||||||
@@ -698,16 +701,18 @@ public class CodegenProperty implements Cloneable, IJsonSchemaValidationProperti
|
|||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
|
|
||||||
return Objects.hash(openApiType, baseName, complexType, getter, setter, description, dataType,
|
return Objects.hash(openApiType, baseName, complexType, getter, setter, description,
|
||||||
datatypeWithEnum, dataFormat, name, min, max, defaultValue, defaultValueWithParam, baseType,
|
dataType, datatypeWithEnum, dataFormat, name, min, max, defaultValue,
|
||||||
containerType, title, unescapedDescription, maxLength, minLength, pattern, example, jsonSchema,
|
defaultValueWithParam, baseType, containerType, title, unescapedDescription,
|
||||||
minimum, maximum, exclusiveMinimum, exclusiveMaximum, hasMore, required, secondaryParam,
|
maxLength, minLength, pattern, example, jsonSchema, minimum, maximum,
|
||||||
hasMoreNonReadOnly, isPrimitiveType, isModel, isContainer, isString, isNumeric, isInteger,
|
exclusiveMinimum, exclusiveMaximum, hasMore, required, deprecated, secondaryParam,
|
||||||
isLong, isNumber, isFloat, isDouble, isByteArray, isBinary, isFile, isBoolean, isDate, isDateTime,
|
hasMoreNonReadOnly, isPrimitiveType, isModel, isContainer, isString, isNumeric,
|
||||||
isUuid, isUri, isEmail, isFreeFormObject, isListContainer, isMapContainer, isEnum, isReadOnly,
|
isInteger, isLong, isNumber, isFloat, isDouble, isByteArray, isBinary, isFile,
|
||||||
isWriteOnly, isNullable, isSelfReference, isCircularReference, _enum, allowableValues, items,
|
isBoolean, isDate, isDateTime, isUuid, isUri, isEmail, isFreeFormObject,
|
||||||
mostInnerItems, vendorExtensions, hasValidation, isInherited, discriminatorValue, nameInCamelCase,
|
isListContainer, isMapContainer, isEnum, isReadOnly, isWriteOnly, isNullable,
|
||||||
nameInSnakeCase, enumName, maxItems, minItems, isXmlAttribute, xmlPrefix, xmlName, xmlNamespace,
|
isSelfReference, isCircularReference, _enum, allowableValues, items, mostInnerItems,
|
||||||
isXmlWrapped, multipleOf);
|
vendorExtensions, hasValidation, isInherited, discriminatorValue, nameInCamelCase,
|
||||||
|
nameInSnakeCase, enumName, maxItems, minItems, isXmlAttribute, xmlPrefix, xmlName,
|
||||||
|
xmlNamespace, isXmlWrapped);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2255,6 +2255,10 @@ public class DefaultCodegen implements CodegenConfig {
|
|||||||
property.defaultValue = toDefaultValue(p);
|
property.defaultValue = toDefaultValue(p);
|
||||||
property.defaultValueWithParam = toDefaultValueWithParam(name, p);
|
property.defaultValueWithParam = toDefaultValueWithParam(name, p);
|
||||||
property.jsonSchema = Json.pretty(p);
|
property.jsonSchema = Json.pretty(p);
|
||||||
|
|
||||||
|
if (p.getDeprecated() != null) {
|
||||||
|
property.deprecated = p.getDeprecated();
|
||||||
|
}
|
||||||
if (p.getReadOnly() != null) {
|
if (p.getReadOnly() != null) {
|
||||||
property.isReadOnly = p.getReadOnly();
|
property.isReadOnly = p.getReadOnly();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
{{#useBeanValidation}}{{#required}}
|
{{#useBeanValidation}}{{#required}}
|
||||||
{{^isReadOnly}}@get:NotNull{{/isReadOnly}} {{/required}}{{>beanValidationModel}}{{/useBeanValidation}}{{#swaggerAnnotations}}
|
{{^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}}
|
@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}}
|
||||||
@@ -678,6 +678,22 @@ public class DefaultCodegenTest {
|
|||||||
Assert.assertTrue(property.isNullable);
|
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
|
@Test
|
||||||
public void integerSchemaPropertyAndModelTest() {
|
public void integerSchemaPropertyAndModelTest() {
|
||||||
OpenAPI openAPI = TestUtils.createOpenAPI();
|
OpenAPI openAPI = TestUtils.createOpenAPI();
|
||||||
|
|||||||
@@ -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'
|
||||||
@@ -1 +1 @@
|
|||||||
4.2.1-SNAPSHOT
|
4.2.3-SNAPSHOT
|
||||||
@@ -16,10 +16,10 @@ import io.swagger.annotations.ApiModelProperty
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* A pet for sale in the pet store
|
* A pet for sale in the pet store
|
||||||
* @param id
|
|
||||||
* @param category
|
|
||||||
* @param name
|
* @param name
|
||||||
* @param photoUrls
|
* @param photoUrls
|
||||||
|
* @param id
|
||||||
|
* @param category
|
||||||
* @param tags
|
* @param tags
|
||||||
* @param status pet status in the store
|
* @param status pet status in the store
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user