swagger-api / swagger-api/swagger-codegen

[PHP] Can't deserialize enums

Open
#4,032 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: PHP help wanted Issue: Bug
Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

--Enum here refers to an enum declared in swagger, which turns into a php class.--

My generated php client api can't get an object that includes an enum property.
I haven't checked serialization.
Didn't find any related issued when I looked.

Swagger-codegen version

2.2.1

Swagger

Minimal json of the enclosing object (which is of course enclosed in a response)

"MyObj": {
  "type": "object",
  "properties" : {
    "MyEnum": {
      "type": "string",
      "enum": [
        "VALUE1",
        "VALUE2",
        "VALUE3"
      ]
    }
  }
}
Command line used for generation

bash, some variables omitted

java -jar $SWAGGERJAR generate -i $INPUT -l php -o $PHPDIR \
      --invoker-package My\\Client \
      --api-package My\\Client\\Api \
      --model-package My\\Client\\Model \
      --additional-properties packagePath=MyClient \
      || exit 1
Steps to reproduce
  1. Run codegen, make sure you've got an enum in there
  2. Make a get request whose response includes the object
  3. Be unhappy
  4. Hope that you're making a silly mistake
Suggest a Fix

ObjectSerializer in php looks like it assumes that all classes have a swaggerType method, but model_enum.mustache don't got one. This causes unhapiness.

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.

Research direction

Start with the PHP ObjectSerializer and the model_enum.mustache template mentioned in the report. Reproduce the issue using the minimal Swagger definition and the provided generation command, then inspect deserialization of a response object containing the enum. Done means that object can be deserialized without the missing swaggerType failure.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.