Skip to content

[Bug]: Issue/Regression related to nullable enums and reference types in v10 #3649

@zotanmew

Description

@zotanmew

Describe the bug

Before v10, I was configuring nullability as follows:

builder.Services.AddSwaggerGen(o =>
{
    options.SupportNonNullableReferenceTypes();
    options.UseAllOfToExtendReferenceSchemas();
    options.UseAllOfForInheritance();
}

This produced correct nullability annotations for enums as well as reference types (including other object schemas) using nullable: true.

v10 seems to have changed both how nullability is annotated, as well as how references work. The above setup now produces the nonsensical combination of type: "null" with allOf: [...], causing type definition source generators to go haywire (e.g. the typescript one produces an intersection of null and the referenced object type definition, which collapses into never).

I tried to fix this with a schema filter, however I came to the conclusion that this is not possible to model with the new way references are represented (as the Type property is passed through to the reference target, which is obviously not nullable in this context).

The Microsoft.AspNetCore.OpenApi generator does not have this issue, though it comes with a myriad of other problems for our codebase, so I'd love for this to get addressed / to get any leads for a possible workaround.

Thank you for this awesome project, and should I have missed anything obvious, apologies in advance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions