Skip to content

Commit 9fc0641

Browse files
committed
test(kotlin-spring): add tests for Jackson datetime property path
Add tests to verify that: - Spring Boot 4 generates application.yaml with spring.jackson.datatype.datetime.WRITE_DATES_AS_TIMESTAMPS - Spring Boot 3 generates application.yaml with spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS
1 parent f9d497d commit 9fc0641

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/spring/KotlinSpringServerCodegenTest.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,53 @@ public void useSpringBoot3() throws Exception {
676676
);
677677
}
678678

679+
@Test(description = "Spring Boot 4 should use Jackson 3 datetime property path")
680+
public void useSpringBoot4JacksonDateTimeProperty() throws Exception {
681+
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
682+
output.deleteOnExit();
683+
String outputPath = output.getAbsolutePath().replace('\\', '/');
684+
685+
KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen();
686+
codegen.setOutputDir(output.getAbsolutePath());
687+
codegen.additionalProperties().put(KotlinSpringServerCodegen.USE_SPRING_BOOT4, true);
688+
689+
new DefaultGenerator().opts(new ClientOptInput()
690+
.openAPI(TestUtils.parseSpec("src/test/resources/3_0/petstore.yaml"))
691+
.config(codegen))
692+
.generate();
693+
694+
// Spring Boot 4 uses Jackson 3, which moved WRITE_DATES_AS_TIMESTAMPS to
695+
// spring.jackson.datatype.datetime instead of spring.jackson.serialization
696+
Path applicationYaml = Paths.get(outputPath + "/src/main/resources/application.yaml");
697+
assertFileContains(applicationYaml, "datatype:");
698+
assertFileContains(applicationYaml, "datetime:");
699+
assertFileContains(applicationYaml, "WRITE_DATES_AS_TIMESTAMPS: false");
700+
assertFileNotContains(applicationYaml, "serialization:");
701+
}
702+
703+
@Test(description = "Spring Boot 3 should use Jackson 2 serialization property path")
704+
public void useSpringBoot3JacksonSerializationProperty() throws Exception {
705+
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
706+
output.deleteOnExit();
707+
String outputPath = output.getAbsolutePath().replace('\\', '/');
708+
709+
KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen();
710+
codegen.setOutputDir(output.getAbsolutePath());
711+
codegen.additionalProperties().put(KotlinSpringServerCodegen.USE_SPRING_BOOT3, true);
712+
713+
new DefaultGenerator().opts(new ClientOptInput()
714+
.openAPI(TestUtils.parseSpec("src/test/resources/3_0/petstore.yaml"))
715+
.config(codegen))
716+
.generate();
717+
718+
// Spring Boot 3 uses Jackson 2, which has WRITE_DATES_AS_TIMESTAMPS under
719+
// spring.jackson.serialization
720+
Path applicationYaml = Paths.get(outputPath + "/src/main/resources/application.yaml");
721+
assertFileContains(applicationYaml, "serialization:");
722+
assertFileContains(applicationYaml, "WRITE_DATES_AS_TIMESTAMPS: false");
723+
assertFileNotContains(applicationYaml, "datatype:");
724+
}
725+
679726
@Test(description = "multi-line descriptions should be supported for operations")
680727
public void multiLineOperationDescription() throws IOException {
681728
testMultiLineOperationDescription(false);

0 commit comments

Comments
 (0)