Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #4293
Closed
Open
Issue created Oct 28, 2019 by Administrator@rootContributor0 of 1 checklist item completed0/1 checklist item

[BUG][C] support for enumerators

Created by: michelealbano

Bug Report Checklist

  • [ X ] Have you provided a full/minimal spec to reproduce the issue?
  • [ X ] Have you validated the input using an OpenAPI validator (example)?
  • [ X ] What's the version of OpenAPI Generator used?
  • [ X ] Have you search for related issues/PRs?
  • [ X ] What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

I tried to compile the code generated from the first declaration I report below, and the result was:

In file included from /mnt/hgfs/shared/clientC/api/DefaultAPI.h:8,
                 from /mnt/hgfs/shared/clientC/api/DefaultAPI.c:4:
/mnt/hgfs/shared/clientC/api/../model/service_registry_response_dto.h:15:34: error: redeclaration of enumerator ‘NOT_SECURE’
                 typedef enum  {  NOT_SECURE, CERTIFICATE, TOKEN } secure_e;
                                  ^~~~~~~~~~

In C the namespace of the enums is global, thus I tried the second OpenAPI declaration I report, where I don't repeat enums' names. The result was:

In file included from /mnt/hgfs/shared/clientC/api/DefaultAPI.h:8,
                 from /mnt/hgfs/shared/clientC/api/DefaultAPI.c:4:
/mnt/hgfs/shared/clientC/api/../model/service_registry_response_dto.h:15:67: error: conflicting types for ‘secure_e’
                 typedef enum  {  NOT_SECURE, CERTIFICATE, TOKEN } secure_e;
                                                                   ^~~~~~~~
openapi-generator version

commit 4543c210 (grafted, HEAD -> master, origin/master, origin/HEAD) Author: sullis github@seansullivan.com Date: Sat Oct 26 21:10:55 2019 -0700

OpenAPI declaration file content or url

Repeated enum names: https://gist.github.com/michelealbano/77f9795d84206c57676cd93c22cf8308

Multiple enums: https://gist.github.com/michelealbano/60d912e034d2ec2307226e7ccc50c409

Command line used for generation

java -jar openapi-generator/modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -g c -i cproblem2.json -o clientC --additional-properties=swaggerDocketConfig=true

Steps to reproduce

java -jar openapi-generator/modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -g c -i cproblems.json -o clientC --additional-properties=swaggerDocketConfig=true cd clientC mkdir build cd build cmake .. make

Related issues/PRs

N/A

Suggest a fix

I suggest to decorate the enum names. See for example: https://stackoverflow.com/questions/2161940/two-enums-have-some-elements-in-common-why-does-this-produce-an-error In the case of my code, this:

                typedef enum  {  NOT_SECURE, CERTIFICATE, TOKEN } secure_e;

should become this:

                typedef enum  {  NOT_SECURE, CERTIFICATE, TOKEN } service_registry_response_dto_secure_e;

and this:

                typedef enum  {  NOT_SECURE, CERTIFICATE, TOKEN } service_registry_response_dto_secure_e;
Assignee
Assign to
Time tracking