swagger-api / swagger-api/swagger-codegen
EnumJsonAdapter Error
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
@franramvel commented on Wed Apr 06 2022
Q&A (please complete the following information)
- OS: Windows
- Environment: Android Studio Arctic Fox 2020.3.1 Patch 4
- Method of installation: Maven
- Swagger-Client version: 3.0.34-SNAPSHOT
- Swagger/OpenAPI version: 3.0
Content & configuration
Simple implementation of Kotlin-Client Classes based on Pet Store Example
Swagger/OpenAPI definition:
Pet Store Example
Swagger-Client usage:
private fun callWs() {
lifecycleScope.launch()//
{
var api = PetApi("https://petstore.swagger.io/v2")
var pet = api.getPetById(43)
binding.txtResponse.text= pet.name
}
}
Describe the bug you're encountering
In Kotlin, I was receiving the following error:
"com.squareup.moshi.JsonDataException: Expected one of [AVAILABLE, PENDING, SOLD] but was available at path $.status"
The problem is, the code generator is creating enum names in upper case, but EnumJsonAdapter uses the string name of the enum constant but no the enum value, the problem is fixed changing enum to lower case. Maybe this is a solution or using a custom adapter.
To reproduce...
Steps to reproduce the behavior:
- Use the code generator to create ApiStore client classes
- Implement the client calling the GetPet method
Expected behavior
It is expected to get the Pet object if it exists without changing the enum variables to lower case
Screenshots
Error:

Code Issue:

Code correction:

Expected output

Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.