Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] [C] enum name collision with latest #19974

Open
4 tasks done
PeteFlugstad opened this issue Oct 25, 2024 · 4 comments
Open
4 tasks done

[BUG] [C] enum name collision with latest #19974

PeteFlugstad opened this issue Oct 25, 2024 · 4 comments

Comments

@PeteFlugstad
Copy link

PeteFlugstad commented Oct 25, 2024

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

#4293

Suggest a fix

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

@wing328

This comment was marked as off-topic.

@PeteFlugstad
Copy link
Author

my take is to create another library called "native-nextgen" with the breaking changes

I think you commented on the wrong bug?

@wing328
Copy link
Member

wing328 commented Nov 7, 2024

oh right. sorry

just replied to #12787 instead.

@wing328
Copy link
Member

wing328 commented Nov 7, 2024

@PeteFlugstad if the enum name can be customized with the enumNameMappings option, would that fix your issue?

ref: https://github.com/openapitools/openapi-generator/blob/master/docs/customization.md#name-mapping

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants