OpenAPITools / OpenAPITools/openapi-generator

[BUG] Protobuf generates empty enum messages

Open
#12,443 0 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

Related with #7168. Enums are not converted as expected. Instead of generating a protobuf enum, it generates an empty message. It was supposed to be solved in v5.3.1, but problem is still there with 5.4.0.

Open API definition:

BusinessesActionsRequest:
      type: object
      properties:
        actions:
          type: array
          items:
            $ref: '#/components/schemas/BusinessesActionEnum'
        name:
          type: string
        classification:
          type: string
        sourceYears:
          $ref: '#/components/schemas/SourceYears'
      description: Describes the input criteria to match a person or a person at an address.

    BusinessesActionEnum:
      type: string
      enum: [ACTIONS_LIST, COMPANY_COUNTY_COURT_JUDGEMENT, BUSINESS_MATCH, DIRECTORSHIPS]
      default: ACTIONS_LIST

Protobuf files generated:

// business_actions_request.proto

syntax = "proto3";

package ***;

import public "models/businesses_action_enum.proto";

message BusinessesActionsRequest {

  repeated BusinessesActionEnum actions = 88061701;

  string name = 3373707;

  string classification = 382350310;

  // Years when the underlying dataset were issued. This could support compliance requirements.
  repeated int32 sourceYears = 90636165;

}
// business_action_enum.proto

syntax = "proto3";

package ***;


message BusinessesActionEnum {

}

Expected protobuf file for enum:

syntax = "proto3";

package ***;

enum BusinessesActionEnum {
    ACTIONS_LIST = 0;
    COMPANY_COUNTY_COURT_JUDGEMENT = 1;
    BUSINESS_MATCH = 2;
    DIRECTORSHIPS = 3;
}
openapi-generator version

openapi-generator-cli:5.4.0

OpenAPI declaration file content or url
BusinessesActionsRequest:
      type: object
      properties:
        actions:
          type: array
          items:
            $ref: '#/components/schemas/BusinessesActionEnum'
        name:
          type: string
        classification:
          type: string
        sourceYears:
          $ref: '#/components/schemas/SourceYears'
      description: Describes the input criteria to match a person or a person at an address.

    BusinessesActionEnum:
      type: string
      enum: [ACTIONS_LIST, COMPANY_COUNTY_COURT_JUDGEMENT, BUSINESS_MATCH, DIRECTORSHIPS]
      default: ACTIONS_LIST
Generation Details
Steps to reproduce
  • Declare an string enum in openapi
  • Generate protobuf files
  • Check that enum is an empty message
Related issues/PRs
  • #7168

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 reproducing the issue with the provided OpenAPI definition and the protobuf generation steps, then trace the protobuf generator entry point that handles string enums. Done means the generated BusinessesActionEnum is a protobuf enum containing all four listed values instead of an empty message; verify the generated files against the expected output.

Written by the indexing model from the issue text.

Assessment

Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.