Skip to content

"import java.time.OffsetDateTime" is not an import statement when date-time is in a "body" parameter #4759

@jeff9finger

Description

@jeff9finger
Description

When a date-time is specified as a type on a body parameter, java.time.OffsetDateTime is not imported into Java code.

Swagger-codegen version

2.2.2-SNAPSHOT

Swagger declaration file content or url
paths:
  /items/{id}/approve:
    post:
      parameters:
        - $ref: '../models/entity.yaml#/parameters/id'
        - $ref: '../models/item.yaml#/parameters/b_approval_date'
      responses:
        204:
          description: Successful request. No Content returned

parameters:
  b_approval_date:
    name: approval_date
    in: body
    required: true
    schema: 
      title: approval_date
      type: string
      format: date-time
Command line used for generation
                    <plugin>
                        <groupId>io.swagger</groupId>
                        <artifactId>swagger-codegen-maven-plugin</artifactId>
                        <version>2.2.2-SNAPSHOT</version>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>generate</goal>
                                </goals>
                                <phase>generate-sources</phase>
                                <configuration>
                                    <verbose>false</verbose>
                                    <environmentVariables>
                                    </environmentVariables>
                                 <inputSpec>test.yaml</inputSpec>
                                    <output>${project.build.directory}/generated/java-client</output>
                                    <language>java</language>
                                    <library>jersey2</library>
                                    <configOptions>
                                        <sourceFolder>src/main/java</sourceFolder>
                                        <artifactId>api-java-client</artifactId>
                                        <artifactVersion>${project.version}</artifactVersion>
                                        <dateLibrary>java8</dateLibrary>
                                        <hideGenerationTimestamp>false</hideGenerationTimestamp>
                                    </configOptions>
                                    <addCompileSourceRoot>true</addCompileSourceRoot>
                                    <bigDecimalAsString>true</bigDecimalAsString>
                                    <generateApiTests>true</generateApiTests>
                                    <generateModelTests>true</generateModelTests>
                                    <modelPackage>api.model</modelPackage>
                                    <apiPackage>api</apiPackage>
                                    <invokerPackage>api.client</invokerPackage>
                                </configuration>
                            </execution>
                        </executions>
                     </plugin>
Steps to reproduce

This generates client and test code that does not import java.time.OffsetDateTime. Not that other places in my spec, I have query parameters defined as format date-time, and the import statement is included correctly in the java classes.

The method signatures are generated correctly. The problem is that the import statement is not added, so the compile fails.

Here are the methods:
Client

// no import statement for java.time.OffsetDateTime
  public void approveItem(String id, OffsetDateTime approvalDate) throws ApiException {
     ...
  }

Test

// no import statement for java.time.OffsetDateTime
    public void approveItemTest() throws ApiException {
        String id = null;
        OffsetDateTime approvalDate = null;
        api.approveItem(id, approvalDate);

        // TODO: test validations
    }

Is there a workaround?

Related issues
Suggest a Fix

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions