-
Notifications
You must be signed in to change notification settings - Fork 6k
Description
Description
When deserializing a response, if enums are used, and the enum value doesn't match with the enum name, an exception is thrown by moshi stating that the enum doesn't match expected values.
E.g.:
status: {
type: "string",
description: "Order Status",
enum: [
"Placed",
"Approved",
"Delivered"
]
}
When deserializing, it fails with: expected one of [placed, approved, delivered] but was Placed at path $.status
This happens because moshi's EnumJsonAdapter doesn't use the enum's getValue and instead either uses a Json annotation or name().
Swagger-codegen version
2.3.1
Command line used for generation
swagger-codegen generate -l kotlin -i swagger.yaml -o tmp
Steps to reproduce
Change on Petstore swagger spec any enum from lowercase to capitalized.
Suggest a fix/enhancement
A solution would be to add the Json annotation to each enum value. Another one to override the name method to return the value instead. One more is to provide a EnumJsonAdapter to moshi that can correctly decode the generated enums.