OpenAPITools / OpenAPITools/openapi-generator
[PHP] nullable attribute with value null gets removed
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
Given a nullable field in OpenAPI object
SomeObject:
type: object
properties:
someProperty:
type: string
nullable: true
When HTTP Request has the object and it includes someProperty=null.
Then the generated php client code does not include someProperty in the response.
openapi-generator version
master branch (version 3.3.4)
EDIT: also version 4.0.3
OpenAPI declaration file content or url
See the description
Command line used for generation
openapi-generator generate -g php
Steps to reproduce
Related issues/PRs
Suggest a fix/enhancement
Remove null-check if-block if ($value !== null) from https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/php/ObjectSerializer.mustache#L68
by changing this
if ($value !== null) {
$values[$data::attributeMap()[$property]] = self::sanitizeForSerialization($value, $openAPIType, $formats[$property]);
}
to this
$values[$data::attributeMap()[$property]] = self::sanitizeForSerialization($value, $openAPIType, $formats[$property]);
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 with modules/openapi-generator/src/main/resources/php/ObjectSerializer.mustache at the serialization block referenced in the issue. Generate a PHP client with openapi-generator generate -g php and verify that a nullable property whose request value is null remains in the serialized response; preserve the behavior for other properties.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, php
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100