Skip to content

Commit fc170c4

Browse files
committed
provide the annotation text and imports
1 parent de95a9e commit fc170c4

5 files changed

Lines changed: 24 additions & 14 deletions

File tree

‎openapi-processor-core/src/main/kotlin/io/openapiprocessor/core/writer/java/JacksonAnnotations.kt‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ import io.openapiprocessor.core.model.datatypes.PropertyDataType
2323
class JacksonAnnotations(apiOptions: ApiOptions): JsonAnnotationFactory {
2424
private val jsonProperty: Annotation
2525
private val jsonCreator: Annotation
26-
@Deprecated("use methods")
27-
override val jsonValue: Annotation
26+
private val jsonValue: Annotation
2827

2928
init {
3029
when (getJacksonFormat(apiOptions)) {
@@ -63,6 +62,10 @@ class JacksonAnnotations(apiOptions: ApiOptions): JsonAnnotationFactory {
6362
return AnnotationData(jsonCreator.annotationName, jsonCreator.imports)
6463
}
6564

65+
override fun createValueAnnotation(): AnnotationData {
66+
return AnnotationData(jsonValue.annotationName, jsonValue.imports)
67+
}
68+
6669
private fun createPropertyParameter(propertyName: String, access: PropertyAccess?): Collection<String> {
6770
return if (access != null) {
6871
listOf(

‎openapi-processor-core/src/main/kotlin/io/openapiprocessor/core/writer/java/JsonAnnotationFactory.kt‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,9 @@
55

66
package io.openapiprocessor.core.writer.java
77

8-
import io.openapiprocessor.core.model.Annotation
98
import io.openapiprocessor.core.model.datatypes.PropertyDataType
109

1110
interface JsonAnnotationFactory {
12-
@Deprecated(message = "use methods")
13-
val jsonValue: Annotation
14-
1511
/** get property annotations imports */
1612
fun createPropertyImports(propDataType: PropertyDataType): Collection<String>
1713
/** get property annotations */
@@ -24,4 +20,6 @@ interface JsonAnnotationFactory {
2420
fun createPropertyAnnotation(propertyName: String, propDataType: PropertyDataType): AnnotationData
2521
/** get creator annotation */
2622
fun createCreatorAnnotation(): AnnotationData
23+
/** get value annotation */
24+
fun createValueAnnotation(): AnnotationData
2725
}

‎openapi-processor-core/src/main/kotlin/io/openapiprocessor/core/writer/java/StringEnumWriter.kt‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,12 @@ open class StringEnumWriter(
5858
|
5959
""".trimMargin())
6060

61+
val jsonValue = jacksonAnnotations.createValueAnnotation()
6162
if(isSupplier()) {
62-
collectedImports.addAll(jacksonAnnotations.jsonValue.imports)
63+
collectedImports.addAll(jsonValue.imports)
6364
content.write(
6465
"""
65-
| @JsonValue
66+
| ${jsonValue.text}
6667
| public String get() {
6768
| return this.value;
6869
| }
@@ -72,10 +73,10 @@ open class StringEnumWriter(
7273

7374
} else {
7475
// default
75-
collectedImports.addAll(jacksonAnnotations.jsonValue.imports)
76+
collectedImports.addAll(jsonValue.imports)
7677
content.write(
7778
"""
78-
| @JsonValue
79+
| ${jsonValue.text}
7980
| public String getValue() {
8081
| return this.value;
8182
| }

‎openapi-processor-core/src/test/kotlin/io/openapiprocessor/core/writer/java/JacksonAnnotationsSpec.kt‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ class JacksonAnnotationsSpec: StringSpec({
2323

2424
jackson.createPropertyImports(mockk<PropertyDataType>())
2525
.shouldContainExactly(setOf("com.fasterxml.jackson.annotation.JsonProperty"))
26-
27-
jackson.jsonValue.imports shouldContainExactly setOf("com.fasterxml.jackson.annotation.JsonValue")
2826
}
2927

3028
"creates jackson creator annotation data" {
@@ -37,6 +35,16 @@ class JacksonAnnotationsSpec: StringSpec({
3735
annotation.imports shouldContainExactly setOf("com.fasterxml.jackson.annotation.JsonCreator")
3836
}
3937

38+
"creates jackson value annotation data" {
39+
val options = ApiOptions()
40+
val jackson = JacksonAnnotations(options)
41+
42+
val annotation = jackson.createValueAnnotation()
43+
44+
annotation.text shouldBe "@JsonValue"
45+
annotation.imports shouldContainExactly setOf("com.fasterxml.jackson.annotation.JsonValue")
46+
}
47+
4048
"creates jackson property annotation data" {
4149
val options = ApiOptions()
4250
val jackson = JacksonAnnotations(options)
@@ -80,6 +88,6 @@ class JacksonAnnotationsSpec: StringSpec({
8088
.shouldContainExactly(setOf("tools.jackson.annotation.JsonProperty"))
8189

8290
jackson.createCreatorAnnotation().imports shouldContainExactly setOf("tools.jackson.annotation.JsonCreator")
83-
jackson.jsonValue.imports shouldContainExactly setOf("tools.jackson.annotation.JsonValue")
91+
jackson.createValueAnnotation().imports shouldContainExactly setOf("tools.jackson.annotation.JsonValue")
8492
}
8593
})

‎openapi-processor-core/src/test/kotlin/io/openapiprocessor/core/writer/java/StringEnumWriterSpec.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class StringEnumWriterSpec : StringSpec({
3939
writer.write(target, dataType)
4040

4141
verify { jackson.createCreatorAnnotation() }
42-
verify { jackson.jsonValue }
42+
verify { jackson.createValueAnnotation() }
4343
}
4444

4545
"writes enum" {

0 commit comments

Comments
 (0)