OpenAPITools / OpenAPITools/openapi-generator

[BUG] Enum not generated properly, if there is a class + property with the same name

Open
#14,206 0 comments 4 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 version

6.2.1, don't know whether it is a regression. I am a new user.

OpenAPI declaration file content or url

Gist: https://gist.github.com/felixscheinost/dfdd51e75f665e676d79b70f9acea7e4

Generation Details
yarn init
yarn add -D @openapitools/openapi-generator-cli
yarn run openapi-generator-cli generate -i swagger-bug.json -g kotlin -o /tmp/test
Steps to reproduce
  • Generate using above steps.

  • ApiErrorGroup.kt is NOT a enum, as it should be. is an empty data class instead.

Changes to schema which change the bug:

  • Renaming ApiError#group => ApiError#group2, in this case a empty data class ApiErrorGroup2 is created, which also won't compile. But the enum ApiErrorGroup is generated correctly.

  • Removing the unnecessary oneOf. Yeah, the oneOf is unnecessary here but the schema is generated by another party which we don't have control over. It should also be valid so valid code should be generated regardless.

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 by reproducing the issue with the provided gist and the openapi-generator-cli Kotlin command. Inspect the generated ApiErrorGroup.kt and the related ApiError and enum output; done means the class/property name collision produces a valid enum and compiling generated Kotlin code, including with the unnecessary oneOf present.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin, openapi
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.