Skip to content

Nullable refs #918

@raziel057

Description

@raziel057

Hello,

Using NelmioApiDocBundle I currently try to add a nullable property like that:

   /**
     * @var Status|null
     *
     * @OA\Property(ref=@Model(type=PTC\ApiBundle\TOEntity\Status::class), nullable=true)
     */
    private $status;

But when generating the API doc the resulting Json is

"status":{
    "$ref":"#\/components\/schemas\/Status"
}

This is comming from the following code fragment:

// $ref
if (isset($data->ref)) {
    // OAS 3.0 does not allow $ref to have siblings: http://spec.openapis.org/oas/v3.0.3#fixed-fields-18
    $data = (object) ['$ref' => $data->ref];
}

Added in the folowing commit:
113c00a#diff-96f680a8337541116efb908ea9d65df5fc092a068cce9b6935c638ecc4ee61ad

At this stage we loose the nullable property from $data. Is it expected? While I generate the REST API Client from .net app, I always need to add manually the nullable true like that, else the property is specified explicitly not nullable:

"status":{
    "$ref":"#\/components\/schemas\/Status",
    "nullable": true
}

From the http://spec.openapis.org/oas/v3.0.3#fixed-fields-18 spec it's not very clear how to define nullable refs but as it's taken into account by client generators, I think we should add the property. If good for you I can create a PR with the fix.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions