OpenAPITools / OpenAPITools/openapi-generator

[BUG][JAVA] Regression in v7.6.0 creating incorrect `generateName=spring` code

Open
#18,739 3 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

I've just upgrade from v6.2.1 to v7.6.0 and I've encountered a problem where a path parameter that is a string has generated code that is an Object (incorrect) when in v6.2.1 it was a String (correct).

openapi-generator version

v7.6.0, this is a regression.

OpenAPI declaration file content or url
  /v1/documents/{id}:
    get:
      summary: Get document
      description: Get a document by providing its unique ID in the path parameter.
      operationId: getDocument
      tags:
        - documents
      parameters:
        - description: The unique identifier of the document
          name: id
          required: true
          in: path
          schema:
            # IDs MUST be strings.
            type: string
            # 36 is the size of a RFC4122 UUID.
            maxLength: 36
          example: abc123

            <plugin>
                <groupId>org.openapitools</groupId>
                <artifactId>openapi-generator-maven-plugin</artifactId>
                <version>7.6.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <inputSpec>${project.basedir}/api/openapi/openapi.yaml</inputSpec>
                            <skipValidateSpec>true</skipValidateSpec>
                            <generatorName>spring</generatorName>
                            <generateApis>true</generateApis>
                            <generateApiDocumentation>false</generateApiDocumentation>
                            <generateModels>true</generateModels>
                            <generateModelDocumentation>false</generateModelDocumentation>
                            <supportingFilesToGenerate>false</supportingFilesToGenerate>
                            <configOptions>
                                <modelPackage>{{packageName}}.models</modelPackage>
                                <apiPackage>{{packageName}}.rest.controllers</apiPackage>
                                <!-- do not generate implementations -->
                                <interfaceOnly>true</interfaceOnly>
                                <!-- do not annotate with custom nullable annotation -->
                                <openApiNullable>false</openApiNullable>
                                <!-- don't generate stub implementations, you always must implement them -->
                                <skipDefaultInterface>true</skipDefaultInterface>
                                <!-- generate one interface per tag -->
                                <useTags>true</useTags>
                                <documentationProvider>none</documentationProvider>
                                <useSwaggerUI>false</useSwaggerUI>
                                <useJakartaEe>true</useJakartaEe>
                                <useSpringBoot3>true</useSpringBoot3>
                            </configOptions>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

The incorrect generated code (where id is Object not String:

    ResponseEntity<Void> updateDocument(
        @Size(max = 36)  @PathVariable("id") Object id,
         @Valid @RequestBody(required = false) Document document
    );
Generation Details
mvn generate-sources
Steps to reproduce

This is a internal code base. I'd have to create a new code base to test. This isn't my top priority right now, but I'm I can't be the only person affected.

Related issues/PRs

Old (2022) issue might be related:

https://github.com/OpenAPITools/openapi-generator/issues/9976

Suggest a fix

TODO

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 issue with the supplied OpenAPI YAML and Maven plugin configuration using the spring generator. Compare the generated signature under v7.6.0 with v6.2.1, focusing on the string path parameter and its maxLength constraint. Done means the generated Java method uses String for id without regressing related parameter cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, 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.