OpenAPITools / OpenAPITools/openapi-generator

[REQ] [Protobuf-Schema] protobuf enhancement

Open
#20,472 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement: Feature
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Is your feature request related to a problem? Please describe.

we are using protobuf-schema Generator in order to convert OpenAPI Specification into protobuf. The generator is currently in BETA version and has limited support. We propose adding the following enhancements:

  1. protobuf message name and field naming convention

    1. Field name in API parameters are in camelCase, which does not align with the Protocol Buffers Documentation style guide. The field names should be in lower_snake_case. Apart from that, special characters or leading underscore in field names should be removed. If the field name differes from the original OpenAPI spec name, a json_name annotation could be added to preserve the original name.
    2. Enum:. The zero value enum should have the suffix UNSPECIFIED instead of UNKNOWN.
  2. oneOf support
    OpenAPI oneOf should map to Protobuf oneof types, as Protobuf has native support for this feature.

  3. anyOf support:
    OpenAPI anyOf constructs should generate Protobuf message that includes all possible schemas as fields.

  4. Handling Unsupported Protobuf Formats

    • Oneof cannot be repeated.
    • Oneof cannot be map.
    • Map value cannot be Arrays.
    • Array items cannot be maps

    To address these limitations, could introduce additional layers in the generated Protobuf schema.

5, Add support for aggregating protobuf schemas to resolve protoc compile issues caused by circular file imports

Describe the solution you'd like

  1. message name convention. Field name is lower_snake_case of original name. json_name refers to its original name.

     message Request {
              Cat cat = 1 [json_name="_cat"];
              Dog dog = 2 [json_name="_dog"];
              Animal animal_pet = 3 [json_name="animal.pet"];
     }
    

enum: Replace the configuration startEnumsWithUnknown to startEnumsWithUNSPECIFIED to configure the zero value suffix with
UNSPECIFIED

    enum Mode {
          MODE_UNSPECIFIED = 0;
          MODE_GET = 1;
          MODE_POST = 2;
          MODE_HEAD = 3;
        }
  1. oneOf support:

       message SampleMessage {
             oneof sample_massage {
               string name = 1;
               SubMessage sub_message = 2;
             }
     }
    
  2. anyOf support:
    spec:

     Animal:
         anyOf:
           - $ref: '#/components/schemas/Cat'
           - $ref: "#/components/schemas/Dog"
    

    protobuf:

     Message Animal {
       Cat cat = 1;
       Dog dog = 2;
     }
    

4, unsupported protobuf format

       message SampleMessage {
            oneof sample_massage {
                bool flag = 1;
                SampleMessageStringArray string_array = 2;
                SubMessage sub_message = 3;
            }
        }
        message SampleMessageStringArray {
          repeated string string_array= 1;
        }

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 with the protobuf-schema generator documentation linked in the issue, then locate its implementation and existing tests. The request spans naming, enum conventions, oneOf, anyOf, unsupported protobuf shapes, and schema aggregation; done would require the agreed enhancements to generate valid protobuf schemas and resolve the described compilation limitations.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.