OpenAPITools / OpenAPITools/openapi-generator
[BUG][Protobuf-Schema] Can't convert enum strings
Nobody has claimed this yet.
- 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)?
- What's the version of OpenAPI Generator used?
- Have you search for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Bounty to sponsor the fix (example)
Description
Enum string fields are not converted as I expected. Is there a configuration setting to make it work? It would be nice if you can suggest if if there is, please.
Case 1
input
PersonData:
type: object
properties:
name:
type: string
bloodType:
type: string
enum: [A, B, O, AB]
actual output
message PersonData {
string name = 1;
enum bloodType {
A = 0;
B = 1;
O = 2;
AB = 3;
}
}
expected output
message PersonData {
string name = 1;
enum BloodType {
A = 0;
B = 1;
O = 2;
AB = 3;
}
BloodType bloodType = 2;
}
Case2
input
PersonData2:
type: object
properties:
name:
type: string
bloodType:
$ref: "#/components/schemas/BloodType"
BloodType:
type: string
enum: [A, B, O, AB]
actual output
message BloodType {
}
message PersonData2 {
string name = 1;
BloodType bloodType = 2;
}
expected output
enum BloodType {
A = 0;
B = 1;
O = 2;
AB = 3;
}
message PersonData {
string name = 1;
BloodType bloodType = 2;
}
openapi-generator version
openapi-generator-cli:v4.3.
OpenAPI declaration file content or url
openapi: "3.0.0"
info:
version: 1.0.0
title: OpenAPI Sample
license:
name: MIT
servers:
- url: http://localhost/
paths:
/person:
get:
summary: Get Person Data
operationId: getPerson
responses:
"200":
description: Person Data
content:
application/json:
schema:
$ref: "#/components/schemas/PersonData"
/person2:
get:
summary: Get Person Data (2)
operationId: getPerson2
responses:
"200":
description: Person Data
content:
application/json:
schema:
$ref: "#/components/schemas/PersonData2"
components:
schemas:
PersonData:
type: object
properties:
name:
type: string
bloodType:
type: string
enum: [A, B, O, AB]
PersonData2:
type: object
properties:
name:
type: string
bloodType:
$ref: "#/components/schemas/BloodType"
BloodType:
type: string
enum: [A, B, O, AB]
Generation Details
docker run --rm -v /spec:/local openapitools/openapi-generator-cli:v4.3.1 generate \
-i /local/sample.yml \
-g protobuf-schema \
-o /local/sample
Steps to reproduce
run the above command
Related issues/PRs
Suggest a fix
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the docker generation command using the protobuf-schema generator and compare its output for both inline and referenced enum cases with the expected .proto examples. Done means enum declarations and fields are generated correctly for both cases; no specific source file or test is named in the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, java
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100