swagger-api / swagger-api/swagger-codegen

[PHP] getContents returns empty string after middleware

Open
#11,651 2 comments 0 reactions 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 use swagger-codegen version 2.4.25 for PHP client.

When I use client with logger middleware getContents returns empty string.
And I know why. Because method getContents returns the remaining contents in a string.
If you use logger pointer set to end of body. And getContents returns empty string.

instead of $content = $responseBody->getContents(); you need to $content = $responseBody->__toString();

https://github.com/swagger-api/swagger-codegen/blob/216a4529b51547b328ba722399575f54fb7bfa8a/modules/swagger-codegen/src/main/resources/php/api.mustache#L163

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 modules/swagger-codegen/src/main/resources/php/api.mustache at the response-body handling around line 163. Reproduce the generated PHP client's behavior with logger middleware, then verify that response content is still returned after the middleware has read the body. Done means the generated client no longer returns an empty string in that case.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.