Skip to content

Commit

Permalink
Merge pull request #461 from Netflix/fix-deprecated-usage
Browse files Browse the repository at this point in the history
Add a config option for adding the deprecated annotation.
  • Loading branch information
srinivasankavitha authored Sep 1, 2022
2 parents c3f6cd3 + 20c56a6 commit 197ba5e
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,8 @@ data class CodeGenConfig(
val generateCustomAnnotations: Boolean = false,
var javaGenerateAllConstructor: Boolean = true,
val implementSerializable: Boolean = false,
val addGeneratedAnnotation: Boolean = false
val addGeneratedAnnotation: Boolean = false,
val addDeprecatedAnnotation: Boolean = false
) {
val packageNameClient: String = "$packageName.$subPackageNameClient"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ abstract class BaseDataTypeGenerator(
if (directive.name == ParserConstants.CUSTOM_ANNOTATION && config.generateCustomAnnotations) {
annotations.add(customAnnotation(argumentMap, config))
}
if (directive.name == ParserConstants.DEPRECATED) {
if (directive.name == ParserConstants.DEPRECATED && config.addDeprecatedAnnotation) {
annotations.add(deprecatedAnnotation())
if (argumentMap.containsKey(ParserConstants.REASON)) {
val reason: String = (argumentMap[ParserConstants.REASON] as StringValue).value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ abstract class AbstractKotlinDataTypeGenerator(
if (directive.name == ParserConstants.CUSTOM_ANNOTATION && config.generateCustomAnnotations) {
annotations.add(customAnnotation(argumentMap, config))
}
if (directive.name == ParserConstants.DEPRECATED) {
if (directive.name == ParserConstants.DEPRECATED && config.addDeprecatedAnnotation) {
if (argumentMap.containsKey(ParserConstants.REASON)) {
annotations.add(deprecatedAnnotation((argumentMap[ParserConstants.REASON] as StringValue).value))
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2963,7 +2963,8 @@ It takes a title and such.
packageName = basePackageName,
includeImports = mapOf(Pair("validator", "com.test.validator")),
includeEnumImports = mapOf("ValidPerson" to mapOf("types" to "com.enums")),
generateCustomAnnotations = true
generateCustomAnnotations = true,
addDeprecatedAnnotation = true
)
).generate()

Expand Down Expand Up @@ -3362,7 +3363,8 @@ It takes a title and such.
packageName = basePackageName,
includeImports = mapOf(Pair("validator", "com.test.validator")),
includeEnumImports = mapOf("ValidPerson" to mapOf("types" to "com.enums")),
generateCustomAnnotations = true
generateCustomAnnotations = true,
addDeprecatedAnnotation = true
)
).generate()
}
Expand All @@ -3382,7 +3384,8 @@ It takes a title and such.
packageName = basePackageName,
includeImports = mapOf(Pair("validator", "com.test.validator")),
includeEnumImports = mapOf("ValidPerson" to mapOf("types" to "com.enums")),
generateCustomAnnotations = false
generateCustomAnnotations = false,
addDeprecatedAnnotation = true
)
).generate()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1887,7 +1887,8 @@ class KotlinCodeGenTest {
CodeGenConfig(
schemas = setOf(schema),
packageName = basePackageName,
language = Language.KOTLIN
language = Language.KOTLIN,
addDeprecatedAnnotation = true
)
).generate().kotlinDataTypes

Expand Down Expand Up @@ -2340,7 +2341,8 @@ class KotlinCodeGenTest {
CodeGenConfig(
schemas = setOf(schema),
packageName = basePackageName,
language = Language.KOTLIN
language = Language.KOTLIN,
addDeprecatedAnnotation = true
)
).generate()
}
Expand Down Expand Up @@ -3241,7 +3243,8 @@ It takes a title and such.
includeImports = mapOf(Pair("validator", "com.test.validator")),
includeEnumImports = mapOf("ValidPerson" to mapOf("types" to "com.enums")),
generateCustomAnnotations = false,
generateClientApi = true
generateClientApi = true,
addDeprecatedAnnotation = true
)
).generate()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ open class GenerateJavaTask : DefaultTask() {
@Input
var addGeneratedAnnotation = false

@Input
var addDeprecatedAnnotation = false

@Input
var generateCustomAnnotations = false

Expand Down Expand Up @@ -182,6 +185,7 @@ open class GenerateJavaTask : DefaultTask() {
snakeCaseConstantNames = snakeCaseConstantNames,
implementSerializable = implementSerializable,
addGeneratedAnnotation = addGeneratedAnnotation,
addDeprecatedAnnotation = addDeprecatedAnnotation,
includeImports = includeImports,
includeEnumImports = includeEnumImports,
generateCustomAnnotations = generateCustomAnnotations
Expand Down

0 comments on commit 197ba5e

Please sign in to comment.