swagger-api/swagger-codegen

[PHP] Can't deserialize enums

Open

#4 032 ouverte le 18 oct. 2016

Voir sur GitHub
 (4 commentaires) (0 réactions) (0 assignés)HTML (5 474 forks)batch import
Client: PHPIssue: Bughelp wanted

Métriques du dépôt

Stars
 (12 701 stars)
Métriques de merge PR
 (Aucune PR mergée en 30 j)

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.

Guide contributeur