Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add deprecated annotation in kotlin-spring #5090

Merged
merged 7 commits into from
Jan 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 &&
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -5459,4 +5463,4 @@ public FeatureSet getFeatureSet() {
public void setFeatureSet(final FeatureSet featureSet) {
this.featureSet = featureSet == null ? DefaultFeatureSet : featureSet;
}
}
}
Original file line number Diff line number Diff line change
@@ -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}}
yutaka0m marked this conversation as resolved.
Show resolved Hide resolved
@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}}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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'
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.2.1-SNAPSHOT
4.2.3-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down