OpenAPITools / OpenAPITools/openapi-generator

[BUG] [JAVA | JAXRS-Spec] Default value of date-time parameter causes exception

Open
#2,907 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

Description

When I use maven plugin 4.0.0 to generate following yaml the generator give me one unexpected error.

unexpected error in Open-API generation
java.lang.RuntimeException: Could not process operation:
  Exception: java.base/java.util.Date cannot be cast to java.base/java.lang.String
    at org.openapitools.codegen.DefaultGenerator.processOperation (DefaultGenerator.java:1078)
    at org.openapitools.codegen.DefaultGenerator.processPaths (DefaultGenerator.java:969)
    at org.openapitools.codegen.DefaultGenerator.generateApis (DefaultGenerator.java:528)
    at org.openapitools.codegen.DefaultGenerator.generate (DefaultGenerator.java:922)
    at org.openapitools.codegen.plugin.CodeGenMojo.execute (CodeGenMojo.java:682)

openapi-generator version

I am using openapi-generator-maven-plugin 4.0.0 to generate the code.

OpenAPI declaration file content or url
    get:
      tags: 
        - email
      summary: list all scheduled email
      operationId: list all scheduled email 
      parameters:
        - in: query
          name: beginTime
          required: false
          schema:
            type: string
            format: date-time
            default: "1970-01-01T00:00:00Z"
        - in: query
          name: endTime
          required: false
          schema:
            type: string
            format: date-time
            default: "1970-01-01T00:00:00Z"
Command line used for generation
			<plugin>
				<groupId>org.openapitools</groupId>
				<artifactId>openapi-generator-maven-plugin</artifactId>
				<version>4.0.0</version>
				<executions>
					<execution>
						<goals>
							<goal>generate</goal>
						</goals>
						<configuration>
							<inputSpec>${project.basedir}/src/main/resources/email-api.yaml</inputSpec>
							<generatorName>jaxrs-spec</generatorName>
							<configOptions>
								<java8>true</java8>
								<dateLibrary>java8</dateLibrary>
								<interfaceOnly>true</interfaceOnly>
								<useSwaggerAnnotations>false</useSwaggerAnnotations>
								<generatPom>false</generatPom>
							</configOptions>
							<output>${project.basedir}</output>
							<apiPackage>...</apiPackage>
							<modelPackage>...</modelPackage>
						</configuration>
					</execution>
				</executions>
			</plugin>
Steps to reproduce

I were using maven to trigger the code generation and the exception will appear every time. When removed the default declaration from yaml, the exception disappear. It doesn't seem like to be an issue of maven plug-in but the generator itself.

Related issues/PRs

Did not find related issues for JAX-RS spec generation after searching.

Suggest a fix

@DefaultValue in JAX-RS interfaces shall be generated well according the yaml configuration.

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 by reproducing the failure with the shown OpenAPI YAML and the jaxrs-spec generator. Trace the operation processing reported in DefaultGenerator.java:1078 and the Maven entry point in CodeGenMojo.java:682. Done means date-time defaults no longer cause the generation exception and the JAX-RS interface emits the configured @DefaultValue.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.