diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenOperation.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenOperation.java index 90a88df5fa7..a5fd7ebc7e8 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenOperation.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenOperation.java @@ -17,7 +17,7 @@ public class CodegenOperation { isListContainer, isMultipart, hasMore = true, isResponseBinary = false, isResponseFile = false, hasReference = false, isRestfulIndex, isRestfulShow, isRestfulCreate, isRestfulUpdate, isRestfulDestroy, - isRestful; + isRestful, isDeprecated; public String path, operationId, returnType, httpMethod, returnBaseType, returnContainer, summary, unescapedNotes, notes, baseName, defaultResponse, discriminator; public List> consumes, produces, prioritizedContentTypes; @@ -221,6 +221,8 @@ public boolean equals(Object o) { return false; if (isResponseFile != that.isResponseFile) return false; + if (isDeprecated != that.isDeprecated) + return false; if (path != null ? !path.equals(that.path) : that.path != null) return false; if (operationId != null ? !operationId.equals(that.operationId) : that.operationId != null) @@ -305,6 +307,7 @@ public int hashCode() { result = 31 * result + (isResponseBinary ? 13:31); result = 31 * result + (isResponseFile ? 13:31); result = 31 * result + (hasReference ? 13:31); + result = 31 * result + (isDeprecated ? 13:31); result = 31 * result + (path != null ? path.hashCode() : 0); result = 31 * result + (operationId != null ? operationId.hashCode() : 0); result = 31 * result + (returnType != null ? returnType.hashCode() : 0); diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java index 92f1a483c0f..03bc6d10f00 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java @@ -2024,6 +2024,9 @@ public CodegenOperation fromOperation(String path, op.notes = escapeText(operation.getDescription()); op.hasConsumes = false; op.hasProduces = false; + if (operation.isDeprecated() != null) { + op.isDeprecated = operation.isDeprecated(); + } List consumes = new ArrayList(); if (operation.getConsumes() != null) { diff --git a/modules/swagger-codegen/src/main/resources/Java/api.mustache b/modules/swagger-codegen/src/main/resources/Java/api.mustache index aee7a27cfe5..95893949e1e 100644 --- a/modules/swagger-codegen/src/main/resources/Java/api.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/api.mustache @@ -52,6 +52,9 @@ public class {{classname}} { * @return {{returnType}} {{/returnType}} * @throws ApiException if fails to make API call + {{#isDeprecated}} + * @Deprecated + {{/isDeprecated}} */ public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}}{{operationId}}({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws ApiException { Object {{localVariablePrefix}}localVarPostBody = {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}}; diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/api.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/api.mustache index 63df83ee24b..5363559728c 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/api.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/api.mustache @@ -49,6 +49,9 @@ public class {{classname}} { * @return {{returnType}} {{/returnType}} * @throws ApiException if fails to make API call + {{#isDeprecated}} + * @Deprecated + {{/isDeprecated}} */ public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}}{{operationId}}({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws ApiException { Object {{localVariablePrefix}}localVarPostBody = {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}}; diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/resteasy/api.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/resteasy/api.mustache index 26cb9d7d946..a4576c8cda2 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/resteasy/api.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/resteasy/api.mustache @@ -45,6 +45,9 @@ public class {{classname}} { * @param {{paramName}} {{description}}{{#required}} (required){{/required}}{{^required}} (optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}{{/allParams}}{{#returnType}} * @return {{{returnType}}}{{/returnType}} * @throws ApiException if fails to make API call + {{#isDeprecated}} + * @Deprecated + {{/isDeprecated}} */ public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}}{{operationId}}({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws ApiException { Object {{localVariablePrefix}}localVarPostBody = {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}}; diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/CodegenTest.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/CodegenTest.java index b5079ead853..91fa6ffc7ff 100644 --- a/modules/swagger-codegen/src/test/java/io/swagger/codegen/CodegenTest.java +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/CodegenTest.java @@ -403,4 +403,15 @@ private static Swagger parseAndPrepareSwagger(String path) { new InlineModelResolver().flatten(swagger); return swagger; } + + @Test(description = "isDeprecated is present") + public void deprecatedParamTest() { + final Swagger model = parseAndPrepareSwagger("src/test/resources/2_0/petstore.json"); + final DefaultCodegen codegen = new DefaultCodegen(); + final String path = "/pet/findByTags"; + final Operation p = model.getPaths().get(path).getGet(); + final CodegenOperation op = codegen.fromOperation(path, "get", p, model.getDefinitions()); + + Assert.assertTrue(op.isDeprecated); + } } diff --git a/modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml b/modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml index f6998119c30..6245293d798 100644 --- a/modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml +++ b/modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml @@ -153,6 +153,7 @@ paths: - petstore_auth: - 'write:pets' - 'read:pets' + deprecated: true '/pet/{petId}': get: tags: diff --git a/modules/swagger-codegen/src/test/resources/2_0/petstore.json b/modules/swagger-codegen/src/test/resources/2_0/petstore.json index f498d308ba2..114d0e18f05 100644 --- a/modules/swagger-codegen/src/test/resources/2_0/petstore.json +++ b/modules/swagger-codegen/src/test/resources/2_0/petstore.json @@ -213,7 +213,8 @@ "read:pets" ] } - ] + ], + "deprecated": "true" } }, "/pet/{petId}": { diff --git a/modules/swagger-codegen/src/test/resources/2_0/petstore.yaml b/modules/swagger-codegen/src/test/resources/2_0/petstore.yaml index e3ba184ea57..b0f52e7eb97 100644 --- a/modules/swagger-codegen/src/test/resources/2_0/petstore.yaml +++ b/modules/swagger-codegen/src/test/resources/2_0/petstore.yaml @@ -153,6 +153,7 @@ paths: - petstore_auth: - 'write:pets' - 'read:pets' + deprecated: true '/pet/{petId}': get: tags: diff --git a/samples/client/petstore/java/jersey1/src/main/java/io/swagger/client/api/PetApi.java b/samples/client/petstore/java/jersey1/src/main/java/io/swagger/client/api/PetApi.java index 87188269c17..797c9aaf563 100644 --- a/samples/client/petstore/java/jersey1/src/main/java/io/swagger/client/api/PetApi.java +++ b/samples/client/petstore/java/jersey1/src/main/java/io/swagger/client/api/PetApi.java @@ -185,6 +185,7 @@ public List findPetsByStatus(List status) throws ApiException { * @param tags Tags to filter by (required) * @return List<Pet> * @throws ApiException if fails to make API call + * @Deprecated */ public List findPetsByTags(List tags) throws ApiException { Object localVarPostBody = null; diff --git a/samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/api/PetApi.java b/samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/api/PetApi.java index c8f8b730ca5..abac5af4ad0 100644 --- a/samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/api/PetApi.java +++ b/samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/api/PetApi.java @@ -168,6 +168,7 @@ public List findPetsByStatus(List status) throws ApiException { * @param tags Tags to filter by (required) * @return List<Pet> * @throws ApiException if fails to make API call + * @Deprecated */ public List findPetsByTags(List tags) throws ApiException { Object localVarPostBody = null; diff --git a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/api/PetApi.java b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/api/PetApi.java index c8f8b730ca5..abac5af4ad0 100644 --- a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/api/PetApi.java +++ b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/api/PetApi.java @@ -168,6 +168,7 @@ public List findPetsByStatus(List status) throws ApiException { * @param tags Tags to filter by (required) * @return List<Pet> * @throws ApiException if fails to make API call + * @Deprecated */ public List findPetsByTags(List tags) throws ApiException { Object localVarPostBody = null; diff --git a/samples/client/petstore/java/resteasy/src/main/java/io/swagger/client/api/PetApi.java b/samples/client/petstore/java/resteasy/src/main/java/io/swagger/client/api/PetApi.java index 131088873d1..61eddf5eff9 100644 --- a/samples/client/petstore/java/resteasy/src/main/java/io/swagger/client/api/PetApi.java +++ b/samples/client/petstore/java/resteasy/src/main/java/io/swagger/client/api/PetApi.java @@ -168,6 +168,7 @@ public List findPetsByStatus(List status) throws ApiException { * @param tags Tags to filter by (required) * @return List * @throws ApiException if fails to make API call + * @Deprecated */ public List findPetsByTags(List tags) throws ApiException { Object localVarPostBody = null;