swagger-api / swagger-api/swagger-codegen

[PHP] deserializing objects with 400 response

Open
#9,100 4 comments 1 reaction 0 assignees 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

Hi!
I wanted to catch my ApiException, but in eventsGetWithHttpInfo() method I found bug.
When I try $e->getResponseObject() from my Error model, I will have empty fields in this model.
This code in generated Api class:

catch (ApiException $e) {
    switch ($e->getCode()) {
        case 200:
            $data = ObjectSerializer::deserialize(
                $e->getResponseBody(),
                '\afficheapiClient\Model\Events',
                $e->getResponseHeaders()
            );
            $e->setResponseObject($data);
            break;
        case 400:
            $data = ObjectSerializer::deserialize(
                $e->getResponseBody(),
                '\afficheapiClient\Model\Error',
                $e->getResponseHeaders()
            );
            $e->setResponseObject($data);
            break;
    }
    throw $e;
}

I get into case 400 and in ObjectSerializer::deserialize method $data argument with $e->getResponseHeaders() should have stbObject type, but it is string.

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 in the generated eventsGetWithHttpInfo() method and follow its 400 ApiException path into ObjectSerializer::deserialize(), using the Error model and response headers shown in the report. Reproduce the 400 response and verify that getResponseObject() contains populated Error fields rather than an empty model.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.