Forum Discussion

lualover's avatar
Frequent Visitor
3 years ago

How to get generate ZonedDateTime from OpenApi?

I am trying get `ZonedDateTime` in my generated code from OpenApi.

There is a `If-Modified-Since` header that OpenApi generates on my endpoint but it's in the type of `LocalDateTime`. This is causing issues on my integration tests.


task buildEndpointsFromYAML(type:
org.openapitools.generator.gradle.plugin.tasks.GenerateTask) {
generatorName = "spring"
inputSpec = acquirerYML
outputDir = "$buildDir/generated".toString()

groupId = "$"
id = "$"
version = "$project.version"
apiPackage = ""
modelPackage = ""
enablePostProcessFile = true
skipOverwrite = false
typeMappings = [
OffsetDateTime: "ZonedDateTime"
importMappings = [
"java.time.OffsetDateTime" : "java.time.ZonedDateTime"
configOptions = [
configPackage : "",
java11 : "true",
dateLibrary : "java8-localdatetime",
serializationLibrary: "jackson",
library : "spring-boot",
useBeanValidation : "true",
interfaceOnly : "true",
serializableModel : "true",
useTags : "true"

I've tried to some of the suggestions here too:

but either it resulted in compilation errors or the type would go from `LocalDateTime` to `Object` as opposed to `ZonedDAteTime`.


This is part of the swagger.yaml:

- name: If-Modified-Since
in: header
description: If-Modified-Since
required: false
type: string
format: date-time


Thanks for any guidance!

No RepliesBe the first to reply