Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[PHP] Correctly format JSON in headers
`ObjectSerializer::toHeaderValue()` in the generated PHP code calls
`toString()` on the values, which formats JSON with the `JSON_PRETTY_PRINT`
option. This will result in a multi-line header which cannot be parsed
since linebreaks aren't allowed by RFC 7230.

In my case I have a header schema called `UpdateUser` which I had hoped
would be serialized as `{"type":"staff","id":123}`.

Every single `__toString()` in the generator does the same thing, so I
figured it's safe to change `toHeaderValue()` to convert to JSON directly,
without `JSON_PRETTY_PRINT`. This fix works for me.
  • Loading branch information
hinrik committed Oct 2, 2019
commit f409411a5a37abbfee4b4ec719384ae7fb736fbd
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class ObjectSerializer
*/
public static function toHeaderValue($value)
{
return self::toString($value);
return json_encode(ObjectSerializer::sanitizeForSerialization($value));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public static function toQueryValue($object)
*/
public static function toHeaderValue($value)
{
return self::toString($value);
return json_encode(ObjectSerializer::sanitizeForSerialization($value));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public static function toQueryValue($object)
*/
public static function toHeaderValue($value)
{
return self::toString($value);
return json_encode(ObjectSerializer::sanitizeForSerialization($value));
}

/**
Expand Down