Skip to content

[PHP] nullable attribute with value null gets removed #2199

@githubERIK

Description

@githubERIK
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]);

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions