-
Notifications
You must be signed in to change notification settings - Fork 100
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
Support @deprecated directives without a reason attribute #711
base: master
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2780,23 +2780,37 @@ class KotlinCodeGenTest { | |
} | ||
|
||
@Test | ||
fun deprecateAnnotationWithNoMesssage() { | ||
fun deprecateAnnotationWithNoReason() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: since we're changing it anyway, can we change it to be correct (there is a reason in this test case). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will make it correct by removing the reason attribute so that its missing from both deprecated directives. And for consistency, I will also update the corresponding test in CodeGenTest to test for the same scenario. |
||
val schema = """ | ||
input Person @deprecated(message: "This is going bye bye") { | ||
input Person @deprecated { | ||
name: String @deprecated | ||
} | ||
""".trimIndent() | ||
|
||
assertThrows<IllegalArgumentException> { | ||
CodeGen( | ||
CodeGenConfig( | ||
schemas = setOf(schema), | ||
packageName = basePackageName, | ||
language = Language.KOTLIN, | ||
addDeprecatedAnnotation = true | ||
) | ||
).generate() | ||
} | ||
val dataTypes = CodeGen( | ||
CodeGenConfig( | ||
schemas = setOf(schema), | ||
packageName = basePackageName, | ||
language = Language.KOTLIN, | ||
addDeprecatedAnnotation = true | ||
) | ||
).generate().kotlinDataTypes | ||
|
||
assertThat(dataTypes).hasSize(1) | ||
assertThat(dataTypes[0].name).isEqualTo("Person") | ||
|
||
val annotationSpec = (dataTypes[0].members[0] as TypeSpec).annotations[0] | ||
assertThat((annotationSpec.typeName as ClassName).canonicalName).isEqualTo("kotlin.Deprecated") | ||
assertThat(annotationSpec.members).hasSize(1) | ||
assertThat(annotationSpec.members[0]).extracting("formatParts", "args").asList().contains(listOf("message = ", "%S"), listOf("Deprecated.")) | ||
|
||
val parameterSpec = (((dataTypes[0].members)[0] as TypeSpec).primaryConstructor as FunSpec).parameters[0] | ||
assertThat(parameterSpec.name).isEqualTo("name") | ||
assertThat(parameterSpec.annotations).hasSize(2) | ||
assertThat((parameterSpec.annotations[0].typeName as ClassName).canonicalName).isEqualTo("com.fasterxml.jackson.annotation.JsonProperty") | ||
assertThat((parameterSpec.annotations[1].typeName as ClassName).canonicalName).isEqualTo("kotlin.Deprecated") | ||
assertThat(parameterSpec.annotations[1].members).hasSize(1) | ||
assertThat(parameterSpec.annotations[1].members[0]).extracting("formatParts", "args").asList().contains(listOf("message = ", "%S"), listOf("Deprecated.")) | ||
} | ||
|
||
@Test | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a String like "Deprecated in GraphQL schema" might be a bit better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR updated.