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
  • #11484
Closed
Open
Issue created Feb 01, 2022 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[BUG][protobuf-schema] Protobuf generator does not respect enableEnumPrefixRemoval

Created by: JulianGmp

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

When setting enableEnumPrefixRemoval=false, the protobuf-schema generator does not respect the flag and removes the enum value prefixes anyway.

openapi-generator version
openapi-generator-cli 6.0.0-SNAPSHOT
  commit : 8a2131f
  built  : 2022-02-01T15:07:00+01:00
  source : https://github.com/openapitools/openapi-generator
  docs   : https://openapi-generator.tech/
OpenAPI declaration file content or url

test.yaml

openapi: 3.0.0
info:
  title: Sample API
  description: Optional multiline or single-line description in [CommonMark](http://commonmark.org/help/) or HTML.
  version: 0.1.9

servers:
  - url: http://api.example.com/v1
    description: Optional server description, e.g. Main (production) server

components:
  schemas:
    userinfo:
      properties:
        something:
          type: string
          format: enum
          enum:
          - MY_ENUM_a
          - MY_ENUM_b
        somethingElse:
          type: string
          format: enum
          enum:
          - MY_OTHER_ENUM_a
          - MY_OTHER_ENUM_bla

paths:
  /users:
    get:
      summary: Returns a list of users.
      description: Optional extended description in CommonMark or HTML.
      responses:
        '200':
          description: A JSON array of user names
          content:
            application/json:
              schema:
                $ref: '#components/schemas/userinfo'
Generation Details

Generated output:

syntax = "proto3";

package openapitools;


message Userinfo {

  enum SomethingEnum {
    A = 0;
    B = 1;
  }

  SomethingEnum something = 28014471;

  enum SomethingElseEnum {
    A = 0;
    BLA = 1;
  }

  SomethingElseEnum somethingElse = 396934355;

}

Expected:

syntax = "proto3";

package openapitools;


message Userinfo {

  enum SomethingEnum {
    MY_ENUM_A = 0;
    MY_ENUM_B = 1;
  }

  SomethingEnum something = 28014471;

  enum SomethingElseEnum {
    MY_OTHER_ENUM_A = 0;
    MY_OTHER_ENUM_BLA = 1;
  }

  SomethingElseEnum somethingElse = 396934355;

}

NOTE: This is especially a problem with protobuf, because enum values have to be globally unique (imagine C enums instead of Java enums). This is a general issue of translating openapi to protobuf, but that's out of scope for this bug report.

I added a prefix to the values in my project, specifically to prevent this, but the generator removes it despite the option set.

Note that I tried the java generator too, which respected the setting.

Steps to reproduce
java -jar ./openapi-generator-cli-master.jar generate -g protobuf-schema -i test.yaml -o testout/ --additional-properties 'enableEnumPrefixRemoval=false'
Related issues/PRs
Suggest a fix
Assignee
Assign to
Time tracking