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
Hey @thinkal01! I'm here to help you with any bugs or questions you have. I can assist with solving issues, answering questions, and becoming a contributor. Let me know how I can assist you!
The Kratos framework uses a custom codec implementation that defaults to JSON encoding for marshaling and unmarshaling Protobuf messages. This implementation typically uses string representation for enums in HTTP responses. This approach is often preferred because it enhances readability and makes the API responses more understandable to humans, as the string representation provides context that numeric values do not.
While the default behavior is to use string representation, you can customize this by setting protojson.MarshalOptions with UseEnumNumbers: true if you prefer numeric representation. However, this might not be the default setting in Kratos, as the framework's customizations are designed to improve clarity and maintainability of API responses [1].
enum ConfigStatus {
CONFIG_STATUS_UNSPECIFIED = 0;
CONFIG_STATUS_ENABLE = 1; // 启用
CONFIG_STATUS_DISABLED = 2; // 禁用
}
message Response {
ConfigStatus status = 2 [(validate.rules).enum = {not_in: [0],defined_only: true}];
}
http response is: {"status":"CONFIG_STATUS_ENABLE"} not {"status:1}
why do not use protojson.MarshalOptions UseEnumNumbers:true
The text was updated successfully, but these errors were encountered: