Skip to content

Commit bd1ae2b

Browse files
committed
add json-property-annotation option (openapi-processor/openapi-processor-spring#268)
1 parent bff3783 commit bd1ae2b

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

openapi-processor-core/src/main/kotlin/io/openapiprocessor/core/converter/JsonPropertyAnnotationMode.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,9 @@ enum class JsonPropertyAnnotationMode(private val mode: String) {
1616
* add @JsonProperty, if the java property name is NOT identical to the OpenAPI property name
1717
* or set to read/write only.
1818
*/
19-
Auto("auto")
19+
Auto("auto");
20+
21+
companion object {
22+
fun findBy(mode: String): JsonPropertyAnnotationMode = entries.first { it.mode == mode }
23+
}
2024
}

openapi-processor-core/src/main/kotlin/io/openapiprocessor/core/converter/OptionsConverter.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ class OptionsConverter(private val checkObsoleteProcessorOptions: Boolean = fals
7373
options.formatCode = mapping.options.formatCode
7474
options.generatedAnnotation = mapping.options.generatedAnnotation
7575
options.generatedDate = mapping.options.generatedDate
76+
options.jsonPropertyAnnotation = JsonPropertyAnnotationMode.findBy(
77+
mapping.options.jsonPropertyAnnotation)
7678

7779
with(mapping.compatibility) {
7880
options.beanValidationValidOnReactive = beanValidationValidOnReactive

openapi-processor-core/src/main/kotlin/io/openapiprocessor/core/processor/mapping/v2/Options.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,10 @@ data class Options(
7070
/**
7171
* enable/disable the @Generated date (optional)
7272
*/
73-
val generatedDate: Boolean = true
73+
val generatedDate: Boolean = true,
74+
75+
/**
76+
* generate @JsonProperty annotation always|auto (optional)
77+
*/
78+
val jsonPropertyAnnotation: String = "always"
7479
)

openapi-processor-core/src/test/kotlin/io/openapiprocessor/core/processor/mapping/v2/MappingReaderSpec.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,4 +201,21 @@ class MappingReaderSpec: StringSpec ({
201201
extList[0].type shouldBe "fooA @ custom.Annotation"
202202
extList[1].type shouldBe "fooB @ custom.Annotation"
203203
}
204+
205+
"reads json property annotation" {
206+
val yaml = """
207+
|openapi-processor-mapping: v8
208+
|options:
209+
| package-name: no.warning
210+
| json-property-annotation: auto
211+
""".trimMargin()
212+
213+
val reader = MappingReader()
214+
215+
// when:
216+
val mapping = reader.read (yaml) as Mapping
217+
218+
// then:
219+
mapping.options.jsonPropertyAnnotation shouldBe "auto"
220+
}
204221
})

0 commit comments

Comments
 (0)