swagger-api / swagger-api/swagger-codegen

EnumJsonAdapter Error

Open
#11,802 0 comments 0 reactions 1 assignee View on GitHub

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:

  1. Use the code generator to create ApiStore client classes
  2. 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:
image
Code Issue:
image

Code correction:
image

Expected output
image

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.