Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nullable refs when documenting type manually #70

Closed
romalytvynenko opened this issue Nov 10, 2022 · 7 comments · Fixed by #74
Closed

Nullable refs when documenting type manually #70

romalytvynenko opened this issue Nov 10, 2022 · 7 comments · Fixed by #74
Assignees
Labels
bug Something isn't working

Comments

@romalytvynenko
Copy link
Member

When a type is documented via PHPDoc and future ref is used with null in union, information about null is lost:

/** @var User|null */
@alanstriglio
Copy link

I found a similar issue when documenting a nullable type via PHPdoc like this:

/** @var array<string, string> | null */

@romalytvynenko
Copy link
Member Author

@alanstriglio are you using the latest version (0.11.14)?

@alanstriglio
Copy link

I'm using 0.11.9

@romalytvynenko
Copy link
Member Author

@alanstriglio try the latest. If problem persists, reopen the issue.

@alanstriglio
Copy link

I'm experiencing the same result with the latest version (0.11.14). I can't reopen this issue myself, could you please reopen it?

@darkbasic
Copy link

darkbasic commented Sep 17, 2024

I would like to add my two cents to the issue: whenever you refer to a named object in the PHPDoc it ends up using anyOf in the generated json and information about null is not lost:

/** @var MappingItem|null */

"anyOf": [
    {
        "$ref": "#\/components\/schemas\/MappingItem"
    },
    {
        "type": "null"
    }
]

Instead whenever you use a built-in type it ends up using an array of types and information about null is lost:

/** @var array<string, string> | null */

"type": [
    "object",
    "null"
],
"additionalProperties": {
    "type": "string"
}

When I say "information about null is lost" is mean that openapi-generator-cli with the typescript generator doesn't add null to the union.

This is in sharp contrast with whatever Stoplight shows for the same type when it generates the APIs documentation via the same openapi json:

image

So there is a chance that the generated openapi JSON is correct and there could be a bug in the typescript openapi-generator. I don't know the OpenAPI 3.1 specs well enough to tell who's at fault.

@romalytvynenko
Copy link
Member Author

@darkbasic thanks for more explanation. Indeed, this is a valid JSON Schema and type generator should've handled it properly. So I'm closing the issue for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants