-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
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:
-
protobuf message name and field naming convention
- 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.
- Enum:. The zero value enum should have the suffix UNSPECIFIED instead of UNKNOWN.
-
oneOf support
OpenAPI oneOf should map to Protobuf oneof types, as Protobuf has native support for this feature. -
anyOf support:
OpenAPI anyOf constructs should generate Protobuf message that includes all possible schemas as fields. -
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
-
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;
}
-
oneOf support:
message SampleMessage { oneof sample_massage { string name = 1; SubMessage sub_message = 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;
}