Skip to content

OpenAPI equivalent to Swagger's NonNullableReferenceTypesAsRequired #64904

@IGx89

Description

@IGx89

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

I have APIs that are mostly providing data to frontends written in TypeScript (mostly GETs). I generate TypeScript types from the OpenAPI specs. Properties that aren't nullable I'd expect to be modeled as required in the spec since the fields will always be present. When using Swashbuckle.AspNetCore's generator with its NonNullableReferenceTypesAsRequired option set to true that happened, but there's no equivalent setting using the Microsoft.OpenAPI generator here.

As an example, I'd like both properties here to be listed as required:

public class Foo
{
	public int Bar { get; set; }
	public List<string> MyList { get; set; } = [];
}

Presently both are optional, and additionally MyList is nullable (due to a different issue, documented in #58192)

Describe the solution you'd like

It would be helpful to have an equivalent setting in OpenAPI to Swashbuckle.AspNetCore's NonNullableReferenceTypesAsRequired. See domaindrivendev/Swashbuckle.AspNetCore#2036 for details about the problem and solution done there.

Of course an alternative solution is marking everything as required/[JsonRequired]/[Required], which I've done in some places, but that's a lot of work when you have a lot of existing DTOs.

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etc

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions