Skip to content

Add new schema filter to exclude nullable fields from required #23

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

Closed

Conversation

ivan-luxoft
Copy link
Contributor

@ivan-luxoft ivan-luxoft commented Mar 23, 2025

Swashbuckle.AspNetCore has a feature NonNullableReferenceTypesAsRequired, but specification has required flag for nullable and non nullable properties and doesn't any difference between them.

for example dto:

public record Dto
{
    public required Dto RequiredNonNull { get; init; }

    public required Dto? RequiredNull { get; init; }

    public Dto NonRequiredNonNull { get; init; } = null!;

    public Dto? NonRequiredNull { get; init; }
}

has component:

{
	"Dto": {
		"required": [
			"nonRequiredNonNull",
			"requiredNonNull",
			"requiredNull"
		],
		"properties": {
			"key": {
				"type": "string"
			},
			"requiredNonNull": {
				"$ref": "#/components/schemas/Dto"
			},
			"requiredNull": {
				"$ref": "#/components/schemas/Dto"
			},
			"nonRequiredNonNull": {
				"$ref": "#/components/schemas/Dto"
			},
			"nonRequiredNull": {
				"$ref": "#/components/schemas/Dto"
			}
		},
		"additionalProperties": false
	}
}

and swashbuckle (openapi?) cant add nullable flag together with $ref, so one of the way to avoid that - exclude nullable fields from required

@ivan-luxoft ivan-luxoft marked this pull request as ready for review March 23, 2025 22:24
@ivan-luxoft ivan-luxoft force-pushed the tasks/swagger-exclude-nullable-from-required branch from 067e5e1 to abefcce Compare March 25, 2025 16:22
@ivan-luxoft ivan-luxoft force-pushed the tasks/swagger-exclude-nullable-from-required branch from abefcce to 1144845 Compare March 25, 2025 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant