You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When the omit-enum-default-value option is enabled it will set the enum field for an enum with just just a single value to null which is invalid against swagger specification 2.0.
To Reproduce
I ran into this issue with a protobuf file that imports google/protobuf/struct.proto. The struct.proto file defines a NullValue type that has just a single value, NULL_VALUE and the generated Swagger definition for the field is invalid. The generated Swagger spec for the following example file will produce the invalid spec:
The generated spec for the NullValue type, with the invalid enum field, is:
"protobufNullValue": {
"type": "string",
"enum": null,
"description": "`NullValue` is a singleton enumeration to represent the null value for the\n`Value` type union.\n\n The JSON representation for `NullValue` is JSON `null`."
}
Expected behavior
To avoid generating an invalid spec the generator could omit the enum field or for types with just a single value. From what I can tell this was the behavior of the generator prior to #3167 but the refactoring in that commit changed the behavior because the Enum field was changed to an interface and when the omit-enum-default-value option removes the single value the field is a nil slice but not a nil interface since it is typed and therefore the omitempty option field does not omit it.
Alternatively, the omit-enum-default-value option could skip enum types with just a single (this is admittedly an edge case) or there could be a per-type option to configure omit-enum-default-value (I ran into this issue because for all other enums types in the proto file I'm using have more than a single value and for those the behavior of omit-enum-default-value is exactly what I need).
Actual Behavior
The Swagger spec generated is invalid because the enum field is set to nil.
Your Environment
I'm using grpc-gateway on Linux and MacOS with version v2.19.1 though as noted above I think this issue was introduced in 2.16.0 with #3167.
The text was updated successfully, but these errors were encountered:
🐛 Bug Report
When the
omit-enum-default-value
option is enabled it will set theenum
field for an enum with just just a single value tonull
which is invalid against swagger specification 2.0.To Reproduce
I ran into this issue with a protobuf file that imports
google/protobuf/struct.proto
. Thestruct.proto
file defines aNullValue
type that has just a single value,NULL_VALUE
and the generated Swagger definition for the field is invalid. The generated Swagger spec for the following example file will produce the invalid spec:The generated spec for the
NullValue
type, with the invalidenum
field, is:Expected behavior
To avoid generating an invalid spec the generator could omit the
enum
field or for types with just a single value. From what I can tell this was the behavior of the generator prior to #3167 but the refactoring in that commit changed the behavior because theEnum
field was changed to an interface and when theomit-enum-default-value
option removes the single value the field is a nil slice but not a nil interface since it is typed and therefore theomitempty
option field does not omit it.Alternatively, the
omit-enum-default-value
option could skip enum types with just a single (this is admittedly an edge case) or there could be a per-type option to configureomit-enum-default-value
(I ran into this issue because for all other enums types in the proto file I'm using have more than a single value and for those the behavior ofomit-enum-default-value
is exactly what I need).Actual Behavior
The Swagger spec generated is invalid because the
enum
field is set to nil.Your Environment
I'm using grpc-gateway on Linux and MacOS with version v2.19.1 though as noted above I think this issue was introduced in 2.16.0 with #3167.
The text was updated successfully, but these errors were encountered: