@@ -8,6 +8,7 @@ package io.openapiprocessor.core.writer.java
88import io.kotest.core.spec.IsolationMode
99import io.kotest.core.spec.style.StringSpec
1010import io.kotest.matchers.collections.shouldContain
11+ import io.kotest.matchers.shouldBe
1112import io.kotest.matchers.string.shouldContain
1213import io.openapiprocessor.core.converter.ApiOptions
1314import io.openapiprocessor.core.converter.mapping.Annotation as MappingAnnotation
@@ -20,6 +21,7 @@ import io.openapiprocessor.core.support.datatypes.ListDataType
2021import io.openapiprocessor.core.support.datatypes.propertyDataType
2122import io.openapiprocessor.core.support.datatypes.propertyDataTypeString
2223import java.io.StringWriter
24+ import java.util.*
2325
2426class DataTypeWriterPojoSpec : StringSpec ({
2527 this.isolationMode = IsolationMode .InstancePerTest
@@ -387,5 +389,51 @@ class DataTypeWriterPojoSpec: StringSpec({
387389 """ .trimMargin()
388390 }
389391
392+ " skips additional annotation from annotation mapping for un-mapped object datatype property" {
393+ options.typeMappings = listOf(
394+ AnnotationTypeMapping (
395+ "Foo ", annotation = MappingAnnotation ("foo.Bar ", linkedMapOf())
396+ )
397+ )
398+
399+ writer = DataTypeWriterPojo (options, generatedWriter, BeanValidationFactory ())
400+
401+ val dataType = ObjectDataType ("Object ",
402+ "pkg", linkedMapOf(
403+ "foo" to propertyDataType(ObjectDataType ("Foo ", "model")))
404+ )
405+
406+ // when:
407+ writer.write(target, dataType)
408+
409+ // then:
410+ val t1 = target.toString()
411+ val t2 =
412+ """ package pkg;
413+ |
414+ |import com.fasterxml.jackson.annotation.JsonProperty;
415+ |import io.openapiprocessor.generated.support.Generated;
416+ |import model.Foo;
417+ |
418+ |@Generated
419+ |public class Object {
420+ |
421+ | @JsonProperty("foo")
422+ | private Foo foo;
423+ |
424+ | public Foo getFoo() {
425+ | return foo;
426+ | }
427+ |
428+ | public void setFoo(Foo foo) {
429+ | this.foo = foo;
430+ | }
431+ |
432+ |}
433+ |
434+ """ .trimMargin()
435+
436+ Arrays .mismatch(t1.toByteArray(), t2.toByteArray()).shouldBe(-1)
437+ }
390438
391439})
0 commit comments