OpenAPITools / OpenAPITools/openapi-generator

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

Open
#11,484 3 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

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

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 by running the documented openapi-generator-cli command with the supplied test.yaml and inspect the protobuf-schema output. Trace the generator path that handles enableEnumPrefixRemoval; done means setting it to false preserves the original enum prefixes in the generated .proto values.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.