OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.94k stars 6.59k forks source link

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

Open PeteFlugstad opened 4 weeks ago

PeteFlugstad commented 4 weeks ago

Bug Report Checklist

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.

wing328 commented 3 weeks ago

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

and later we will do a swap

native => native-deprecated native-nextgen => native

that way users can fallback easily for easier, smoother migration.

we did this before for jersey2 and okhttp-gson to allow breaking changes with fallback by adding another library option.

PeteFlugstad commented 2 weeks ago

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

I think you commented on the wrong bug?

wing328 commented 2 weeks ago

oh right. sorry

just replied to https://github.com/OpenAPITools/openapi-generator/issues/12787 instead.

wing328 commented 2 weeks ago

@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