-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
The [Required] attribute is not respected #523
Comments
I can't get anything to marked as required. Can anyone share some guidance? This seems like it should be pretty basic, but there's not a mention of anything in the readme. Sorta unacceptable to not have a way to indicate if a parameter is required or not. I'm trying to use the swagger doc to generate client libraries. Having everything |
Are we talking about required on input model for validation? Or data returned from Api calls? There's a difference between required and null-able as I have learned through my quest further down this page. |
@ThisNoName Required on the input model for validation. |
@vanillajonathan In my case, everything works fine with model Post FromBody. But not query parameters (Get w/ QueryString or Post w/o FromBody, core2 model binding will convert the latter into query parameters). There's another issue 480 floating around about Required not working on query string.
|
@ThisNoName Ah thanks. I didn't use |
Should be resolved as of v1.1.0 |
Tested this fix in v1.1.0, but the following .NET Core 2 endpoint:
only marks the DateTime properties as required in the Swagger file. serialNumber and productFamily remain optional. Almost there I guess? |
Same for me too. Doesn't work with v1.1.0 on query parameters. Why this is closed? |
Same for me.
Results in
|
I'm also getting this issue on v1.1.0 |
@domaindrivendev Ping! |
Same problem on v1.1.0 AspNetCore |
My workaround for this was to create a schema filter that will fill public class SchemaFilter : ISchemaFilter
{
public void Apply(Schema schema, SchemaFilterContext context)
{
var type = context.SystemType;
if (schema?.Properties == null || type == null)
return;
var required = type.GetProperties()
?.Where(t => t.GetCustomAttribute<RequiredAttribute>() != null);
if (required == null || !required.Any())
return;
schema.Required = required.Select(p => p.Name).ToList();
}
} |
@antoniaelek |
The
[Required]
(RequiredAttribute
) decorator has no effect.The text was updated successfully, but these errors were encountered: