OpenAPITools / OpenAPITools/openapi-generator
[BUG][PHP] Fix declaration parsing <array(type, type)> in description
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Wrong substr number in case of array<....>. There could be or 4 (map[) or 6 (array<) depending which keyword is used in $class.
Additionally, if space is used between key and type (e.g. <array(string, int)>), the $subClass should be trimmed.
Here is how to do it without calling substr:
if (preg_match('/^(?:array|map)[<\[](.*)[>\]]$/', $class, $matchedValues)) { // for associative array e.g. array<string,int>
$data = is_string($data) ? json_decode($data) : $data;
settype($data, 'array');
$inner = $matchedValues[1];
$deserialized = [];
if (false !== strpos($inner, ',')) {
$subClass_array = explode(',', $inner, 2);
$subClass = trim($subClass_array[1]);
foreach ($data as $key => $value) {
$deserialized[$key] = self::deserialize($value, $subClass, null);
}
}
return $deserialized;
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at modules/openapi-generator/src/main/resources/php/ObjectSerializer.mustache#L281 and inspect how declaration strings are parsed for map[...] and array<...>. Check the existing deserialization flow against array(string, int) and spacing around the inner type. Done means both declaration forms parse the intended subtype without leaving surrounding whitespace.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, php
- Domain
- api
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100