Skip to content

[BUG][Protobuf-Schema] Can't convert enum strings #7168

Open
@ksato9700

Description

@ksato9700

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions