Bug Report Checklist
Description
When OpenApi spec 3.0 OneOf is encountered by the protobuf-schema generator, an unneeded message with the field name of the oneOf is created in the output. If the field name coincides with the type name (except Uppercase starting letter) then the correct message gets overwritten with the redundant message leading to erroneous schema generation.
openapi-generator version
% openapi-generator version
6.4.0
OpenAPI declaration file content or url
test openapi spec: https://gist.github.com/dchinmaya/292097a632da30d1580542652cbfdf88
Excerpt below
"schemas": {
"AnalyzerSpecificData": {
"oneOf": [
{
"type": "object",
"title": "oneAnalyzerKey",
"properties": {
"oneAnalyzerKey": {
"$ref": "#/components/schemas/OneAnalyzerData"
}
},
"required": [
"oneAnalyzerKey"
]
},
{
"type": "object",
"title": "twoAnalyzerKey",
"properties": {
"twoAnalyzerKey": {
"$ref": "#/components/schemas/TwoAnalyzerData"
}
},
"required": [
"twoAnalyzerKey"
]
}
]
},
Generation Details
Execute
openapi-generator generate -i testapispec.json -g protobuf-schema -o genschemas
Steps to reproduce
- Run the above command with the linked test api spec
- View the created proto files
% ls -lrth genschemas/models/
total 48
-rw-r--r-- 1 chinmay wheel 612B Mar 6 17:00 analyzer_specific_data.proto
-rw-r--r-- 1 chinmay wheel 418B Mar 6 17:00 one_analyzer_data.proto
-rw-r--r-- 1 chinmay wheel 417B Mar 6 17:00 one_analyzer_key.proto
-rw-r--r-- 1 chinmay wheel 420B Mar 6 17:00 two_analyzer_data.proto
-rw-r--r-- 1 chinmay wheel 417B Mar 6 17:00 two_analyzer_key.proto
-rw-r--r-- 1 chinmay wheel 364B Mar 6 17:00 two_analyzer_metadata.proto
- The
one_analyzer_key.proto (and two_analyzer_key.proto) is the redundant proto that is generated. There is no type "OneAnalyzerKey" in the spec anywhere. It is the name of a field in the OneOf of type OneAnalyzerData. There should be OneAnalyzerData and AnalyzerSpecificData but there should not be a message with OneAnalyzerKey.
one_analyzer_key.proto
syntax = "proto3";
package openapitools;
import public "models/one_analyzer_data.proto";
message OneAnalyzerKey {
OneAnalyzerData oneAnalyzerKey = 299888019;
}
analyzer_specific_data.proto
syntax = "proto3";
package openapitools;
import public "models/one_analyzer_data.proto";
import public "models/one_analyzer_key.proto";
import public "models/two_analyzer_data.proto";
import public "models/two_analyzer_key.proto";
message AnalyzerSpecificData {
OneAnalyzerData oneAnalyzerKey = 299888019;
TwoAnalyzerData twoAnalyzerKey = 180391406;
}
one_analyzer_data.proto
syntax = "proto3";
package openapitools;
import public "models/todo_object_mapping.proto";
message OneAnalyzerData {
TODO_OBJECT_MAPPING metadata = 450004177;
}
Expected
one_analyzer_key.proto to not exist. message OneAnalyzerKey to not exist.
Actual
one_analyzer_key.proto wrongly generated. message OneAnalyzerKey exists. If the field name was the same as the type except the upper case starting letter, ie if we wanted to generate OneAnalyzerData oneAnalyzerData = 123 then the above generation leads to issues and the actual OneAnalyzerData message will be overwritten with the bad OneAnalyzerData.
Bug Report Checklist
Description
When OpenApi spec 3.0 OneOf is encountered by the protobuf-schema generator, an unneeded message with the field name of the oneOf is created in the output. If the field name coincides with the type name (except Uppercase starting letter) then the correct message gets overwritten with the redundant message leading to erroneous schema generation.
openapi-generator version
OpenAPI declaration file content or url
test openapi spec: https://gist.github.com/dchinmaya/292097a632da30d1580542652cbfdf88
Excerpt below
Generation Details
Execute
Steps to reproduce
one_analyzer_key.proto(andtwo_analyzer_key.proto) is the redundant proto that is generated. There is no type "OneAnalyzerKey" in the spec anywhere. It is the name of a field in the OneOf of typeOneAnalyzerData. There should beOneAnalyzerDataandAnalyzerSpecificDatabut there should not be a message withOneAnalyzerKey.one_analyzer_key.proto
analyzer_specific_data.proto
one_analyzer_data.proto
Expected
one_analyzer_key.prototo not exist.message OneAnalyzerKeyto not exist.Actual
one_analyzer_key.protowrongly generated.message OneAnalyzerKeyexists. If the field name was the same as the type except the upper case starting letter, ie if we wanted to generateOneAnalyzerData oneAnalyzerData = 123then the above generation leads to issues and the actual OneAnalyzerData message will be overwritten with the bad OneAnalyzerData.