-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Description
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