OpenAPITools / OpenAPITools/openapi-generator

[BUG][JAVA][SPRING] EnumConverterConfiguration does not use `modelNameSuffix`

Open
#14,302 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

OpenAPI generator generate the file EnumConverterConfiguration.java if the OA description includes at least one enum. The template does not take into account the generator configuration property modelNameSuffix, which is used to name the DTO models. The issue is then that the class EnumConverterConfiguration includes incorrect references to the DTO models.

openapi-generator version

6.2.1

OpenAPI declaration file content or url

See this OpenAPI description (note the use of enum)

Generation Details

Content of EnumConverterConfiguration.java (here the value of modelNameSuffix is not used to name the models):

package org.sagebionetworks.challenge.configuration;

import org.sagebionetworks.challenge.model.dto.ChallengeStatus;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.converter.Converter;

@Configuration
public class EnumConverterConfiguration {

  @Bean
  Converter<String, ChallengeStatus> challengeStatusConverter() {
    return new Converter<String, ChallengeStatus>() {
      @Override
      public ChallengeStatus convert(String source) {
        return ChallengeStatus.fromValue(source);
      }
    };
  }
}

List of DTO models generated (here the value of modelNameSuffix is correctly used to name the models):

$ ls -ahl apps/challenge-service/src/main/java/org/sagebionetworks/challenge/model/dto/
total 40K
drwxr-xr-x 2 vscode vscode  219 Dec 20 22:06 .
drwxr-xr-x 7 vscode vscode   75 Dec 19 19:36 ..
-rw-r--r-- 1 vscode vscode 3.8K Dec 20 20:15 BasicErrorDto.java
-rw-r--r-- 1 vscode vscode 3.3K Dec 20 20:15 ChallengeCreateRequestDto.java
-rw-r--r-- 1 vscode vscode 1.1K Dec 20 20:15 ChallengeDifficultyDto.java
-rw-r--r-- 1 vscode vscode 5.1K Dec 20 20:15 ChallengeDto.java
-rw-r--r-- 1 vscode vscode  986 Dec 20 20:15 ChallengeStatusDto.java
-rw-r--r-- 1 vscode vscode 6.4K Dec 20 20:15 ChallengesPageDto.java
-rw-r--r-- 1 vscode vscode 5.4K Dec 20 20:15 PageMetadataDto.java
Steps to reproduce
  1. Download the OA description (see above)
  2. Download the OA generator config file (see above)
  3. Run the OA generator: openapi-generator-cli generate
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

Reproduce the issue with the linked OpenAPI declaration, openapitools.json, and the openapi-generator-cli generate command. Start by locating the template or entry point that generates EnumConverterConfiguration.java; done means its model references use modelNameSuffix consistently with generated DTOs such as ChallengeStatusDto.java.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi, spring
Domain
api, backend, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.