Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,15 @@ spring:
name: {{title}}

jackson:
{{#useSpringBoot4}}
datatype:
datetime:
WRITE_DATES_AS_TIMESTAMPS: false
{{/useSpringBoot4}}
{{^useSpringBoot4}}
serialization:
WRITE_DATES_AS_TIMESTAMPS: false
{{/useSpringBoot4}}

server:
port: {{serverPort}}
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,53 @@ public void useSpringBoot3() throws Exception {
);
}

@Test(description = "Spring Boot 4 should use Jackson 3 datetime property path")
public void useSpringBoot4JacksonDateTimeProperty() throws Exception {
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
output.deleteOnExit();
String outputPath = output.getAbsolutePath().replace('\\', '/');

KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen();
codegen.setOutputDir(output.getAbsolutePath());
codegen.additionalProperties().put(KotlinSpringServerCodegen.USE_SPRING_BOOT4, true);

new DefaultGenerator().opts(new ClientOptInput()
.openAPI(TestUtils.parseSpec("src/test/resources/3_0/petstore.yaml"))
.config(codegen))
.generate();

// Spring Boot 4 uses Jackson 3, which moved WRITE_DATES_AS_TIMESTAMPS to
// spring.jackson.datatype.datetime instead of spring.jackson.serialization
Path applicationYaml = Paths.get(outputPath + "/src/main/resources/application.yaml");
assertFileContains(applicationYaml, "datatype:");
assertFileContains(applicationYaml, "datetime:");
assertFileContains(applicationYaml, "WRITE_DATES_AS_TIMESTAMPS: false");
assertFileNotContains(applicationYaml, "serialization:");
}

@Test(description = "Spring Boot 3 should use Jackson 2 serialization property path")
public void useSpringBoot3JacksonSerializationProperty() throws Exception {
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
output.deleteOnExit();
String outputPath = output.getAbsolutePath().replace('\\', '/');

KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen();
codegen.setOutputDir(output.getAbsolutePath());
codegen.additionalProperties().put(KotlinSpringServerCodegen.USE_SPRING_BOOT3, true);

new DefaultGenerator().opts(new ClientOptInput()
.openAPI(TestUtils.parseSpec("src/test/resources/3_0/petstore.yaml"))
.config(codegen))
.generate();

// Spring Boot 3 uses Jackson 2, which has WRITE_DATES_AS_TIMESTAMPS under
// spring.jackson.serialization
Path applicationYaml = Paths.get(outputPath + "/src/main/resources/application.yaml");
assertFileContains(applicationYaml, "serialization:");
assertFileContains(applicationYaml, "WRITE_DATES_AS_TIMESTAMPS: false");
assertFileNotContains(applicationYaml, "datatype:");
}

@Test(description = "multi-line descriptions should be supported for operations")
public void multiLineOperationDescription() throws IOException {
testMultiLineOperationDescription(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ spring:
name: openAPIPetstore

jackson:
serialization:
WRITE_DATES_AS_TIMESTAMPS: false
datatype:
datetime:
WRITE_DATES_AS_TIMESTAMPS: false

server:
port: 8080
Loading