_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.
master branch (version 3.3.4)
EDIT: also version 4.0.3
See the description
openapi-generator generate -g php
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]);
@githubERIK thanks for reporting the issue and sharing the workaround.
But I think in certain use cases, the workaround may introduce additional null values in the payload, which are not present before.
I think we may need to maintain another associative array similar to openAPITypes to indicate if the property is nullable
I think we may need to maintain another associative array similar to openAPITypes to indicate if the property is nullable
@githubERIK does my comment earlier make sense to you?
The comment makes sense.
For nullables in model_generic.mustache,
protected static $openAPINullables = [
{{#vars}}'{{name}}' => {{#isNullable}}true{{/isNullable}}{{^isNullable}}false{{/isNullable}}{{#hasMore}},
{{/hasMore}}{{/vars}}
];
could be added and then accessed.
Things to keep in mind.
When a request goes out
When a response comes in
echo $response should show all null values.API platform supports partial PUT operations: omitting a field in the request does not clear the value on PUT operations. So I'm wondering, the change discussed here, how would the client distinguish nullable fields explicitly set to null versus fields omitted in the payload?
I believe this question is especially important because the client does not support PATCH requests.
Most helpful comment
API platform supports partial PUT operations: omitting a field in the request does not clear the value on PUT operations. So I'm wondering, the change discussed here, how would the client distinguish nullable fields explicitly set to null versus fields omitted in the payload?
I believe this question is especially important because the client does not support PATCH requests.