[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'