OpenAPITools / OpenAPITools/openapi-generator

[BUG] [C] enum name collision with latest

Open
#19,974 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

I'm trying to generate C code for an API with a model (task) that has two enums in it (TaskType and TaskStatus)

I'm seeing name collisions in the generated output, similar to an older (fixed) bug BUG: 4293

Here is the generated model header: (model/task.h):

// Enum  for task

typedef enum  { fastapi_task__NULL = 0, fastapi_task__NIL, fastapi_task__DO_A, fastapi_task__DO_B, fastapi_task__DO_C } fastapi_task__e;

// ...

// Enum  for task

typedef enum  { fastapi_task__NULL = 0, fastapi_task__NIL, fastapi_task__NOT_APPROVED, fastapi_task__NOT_READY, fastapi_task__NOT_ASSIGNED, fastapi_task__PENDING, fastapi_task__EXECUTING, fastapi_task__DONE } fastapi_task__e;

The two enums collide both the the NIL and NULL enum value and the name of of the typedef (fastapi_task__e).

Looking at the model-header.mustache, I see:

// Enum {{enumName}} for {{classVarName}}
...

I would expect to see the {{enumName}} ("TaskType" or "TaskStatus" ) embedded in the names, which would fix them for uniqueness.

Is my yaml missing something?

openapi-generator version

openapi-generator-cli-7.9.0.jar

OpenAPI declaration file content or url

https://gist.github.com/PeteFlugstad/8ca8bd25a7aed7015b6634ddd77560c4

Generation Details

openapi-generator-cli-7.9.0.jar

Steps to reproduce
$ java -jar openapi-generator-cli-7.9.0.jar generate -i task.yaml -g c -o output
$ mkdir output/build
$ cd output/build
$ cmake ..
$ make
Related issues/PRs

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

Suggest a fix

Seems like the {{enumName}} field is not being parsed or populated correctly from the yaml.

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 with model-header.mustache and the generated model/task.h shown in the report, then reproduce the issue using the openapi-generator-cli 7.9.0 command and the provided task.yaml. The work is done when TaskType and TaskStatus produce distinct enum values and typedef names, and the generated project passes cmake and make.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, cmake, java
Domain
build-system, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.