OpenAPITools / OpenAPITools/openapi-generator

How to get generate ZonedDateTime from OpenApi? instead of ZonedDateTime its importing localDateTime

Open
#17,062 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

This is the plugin I am using. The code is breaking due to localTimeZone is being generated. I want to generate ZonedDateTime

org.openapitools
openapi-generator-maven-plugin
7.0.1

    <executions>
      <execution>
        <id>generate-service-api</id>
        <goals>
          <goal>generate</goal>
        </goals>
        <configuration>
          <inputSpec>${project.basedir}/target/download/${swaggerApiName}-${swaggerApiVersion}.json
          </inputSpec>
          <generatorName>spring</generatorName>

          <!-- Specify the package names for api and model-->
          <apiPackage>com.convera.generated.execution.date.service.api</apiPackage>
          <modelPackage>com.convera.generated.execution.date.service.model</modelPackage>
          <invokerPackage>com.convera.generated.execution.date.service.api</invokerPackage>

          <!-- Selective generation for model classes and supporting files -->
          <!--                            <modelsToGenerate>Pet</modelsToGenerate>-->

          <!-- Replace imports in generated classes to the maven local sdk model class (see libs/common-components-model-1.0-SNAPSHOT.jar)-->
          <importMappings>
            CommonResponse=com.convera.common.template.CommonResponse,
            ResponseError=com.convera.common.template.response.error.ResponseError,
            ResponseMetadata=com.convera.common.template.response.ResponseMetadata,
            ZonedDateTime=java.time.ZonedDateTime
          </importMappings>
          <!-- Ignore tests creation is generated sources -->
          <generateModelTests>false</generateModelTests>
          <generateApiTests>false</generateApiTests>

          <configOptions>
            <sourceFolder>src/main/java</sourceFolder>
            <interfaceOnly>true</interfaceOnly>
            <useBeanValidation>true</useBeanValidation>
            <dateLibrary>java8-localdatetime</dateLibrary>
            <useTags>true</useTags>
            <!-- Apply additional class level annotations -->
            <additionalModelTypeAnnotations>
              @lombok.NoArgsConstructor
              @lombok.AllArgsConstructor
              @lombok.Builder
            </additionalModelTypeAnnotations>
            <useJakartaEe>true</useJakartaEe>
            <generatedConstructorWithRequiredArgs>false</generatedConstructorWithRequiredArgs>
            <typeMappings>LocalDateTime=ZonedDateTime</typeMappings>
          </configOptions>
        </configuration>
      </execution>
    </executions>
  </plugin>

///////////////////
Thiss is my generated classes.

@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", date = "2023-11-13T14:49:36.518552500-06:00[America/Chicago]")
public class ExecutionDateResponse {

@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
private ** @LocalDateTime** achievableExecutionDate; // This converting to LocalDateTime instead of ZonedDateTime

public ExecutionDateResponse achievableExecutionDate(LocalDateTime achievableExecutionDate) {
this.achievableExecutionDate = achievableExecutionDate;
return this;
}

openapi-generator version

org.openapitools
openapi-generator-maven-plugin
7.0.1

OpenAPI declaration file content or url
Generation Details
Steps to reproduce
Related issues/PRs
Suggest a fix

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start from the supplied Maven plugin configuration and the generated ExecutionDateResponse class, focusing on dateLibrary, typeMappings, and importMappings. Reproduce generation with the stated OpenAPI Generator version and configuration; done means the generated field and accessor use the expected ZonedDateTime type, with the cause and required configuration behavior documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi, spring
Domain
backend-api-design, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.