Skip to content

Add nullable for ResponseFields in OpenAPI export #1032

@rene-marth

Description

@rene-marth

Scribe version

5.4.0

PHP version

8.4

Laravel version

12.35.0

Scribe config

n/a

What happened?

Currently the OpenAPI generation ignores the nullable parameter for ResponseFields. (which is valid for OpenAPI 3.0)

After digging the sources a naive "fix" would be:

  1. Add public $nullable; to camel/Extraction/ResponseField.php
  2. Under generateSchemaForResponseValue() in src/Writing/OpenApiSpecGenerators/BaseGenerator.php add

L568

$this->setDescription($schema, $endpoint, $path);

//either it's explicitly nullable or the value is null (don't know if this is legit?)
if ((isset($endpoint->responseFields[$path]->nullable) && $endpoint->responseFields[$path]->nullable) || $value === null) {
            $schema['nullable'] = true;
        }

However I also stumbled over you comment here https://scribe.knuckles.wtf/laravel/migrating#more-configurable-openapi-generation - would it be possible and do you recommend to use this approach to add the nullable parameter to responseField? Or do you prefer an enhancement like the above code?

Docs

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtriage

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions