@@ -7,6 +7,7 @@ package io.openapiprocessor.core.writer.java
77
88import io.openapiprocessor.core.converter.ApiOptions
99import io.openapiprocessor.core.model.Annotation
10+ import io.openapiprocessor.core.model.datatypes.PropertyDataType
1011
1112/* *
1213 * TODO remove v3
@@ -15,16 +16,17 @@ import io.openapiprocessor.core.model.Annotation
1516 *
1617 * mapping jon schema definition to configure the jackson version.
1718 *
18- * "jackson": {
19- * "description": "jackson annotations version.",
20- * "default": "v2",
21- * "enum": ["v2", "v3"]
22- * },
19+ * "jackson": {
20+ * "description": "jackson annotations version.",
21+ * "default": "v2",
22+ * "enum": ["v2", "v3"]
23+ * }
2324 */
24- class JacksonAnnotations (apiOptions : ApiOptions ) {
25- val jsonProperty: Annotation
26- val jsonCreator: Annotation
27- val jsonValue: Annotation
25+ class JacksonAnnotations (apiOptions : ApiOptions ): JsonAnnotationFactory {
26+ @Deprecated(" use methods" )
27+ override val jsonProperty: Annotation // todo make private
28+ override val jsonCreator: Annotation
29+ override val jsonValue: Annotation
2830
2931 init {
3032 when (getJacksonFormat(apiOptions)) {
@@ -41,11 +43,42 @@ class JacksonAnnotations(apiOptions: ApiOptions) {
4143 }
4244 }
4345
46+ override fun createPropertyImports (propDataType : PropertyDataType ): Collection <String > {
47+ return jsonProperty.imports
48+ }
49+
50+ override fun createPropertyAnnotations (propertyName : String , propDataType : PropertyDataType ): Collection <String > {
51+ val params = createPropertyParameter(propertyName, getAccess(propDataType))
52+ val result = " ${jsonProperty.annotationName} (${params.joinToString(" , " )} )"
53+ return listOf (result)
54+ }
55+
56+ private fun createPropertyParameter (propertyName : String , access : PropertyAccess ? ): Collection <String > {
57+ return if (access != null ) {
58+ listOf (
59+ """ value = "$propertyName """" ,
60+ " access = JsonProperty.Access.${access.value} "
61+ )
62+ } else {
63+ listOf (""" "$propertyName """" )
64+ }
65+ }
66+
67+ private fun getAccess (propDataType : PropertyDataType ): PropertyAccess ? {
68+ return when {
69+ propDataType.readOnly -> PropertyAccess (" READ_ONLY" )
70+ propDataType.writeOnly -> PropertyAccess (" WRITE_ONLY" )
71+ else -> null
72+ }
73+ }
74+
4475 private fun getJacksonFormat (options : ApiOptions ): JacksonFormat {
4576 return when (options.jackson) {
4677 " v2" -> JacksonFormat .V2
47- " v3" -> JacksonFormat .V3
78+ " v3" -> JacksonFormat .V2 /* v3 is currently not needed */
4879 else -> JacksonFormat .V2
4980 }
5081 }
5182}
83+
84+ class PropertyAccess (val value : String )
0 commit comments