ApiMember IsRequired

Hi.

To in the description of the query to specify that the field should definitely need [Apamember(IsRequired = true)]

[Authenticate]
    [Route("/DocumentCreate", "POST")]
    public class DocumentCreate : IReturn<IsOkResponce> {
        [ApiMember(IsRequired = true)]
        public string Uid { get; set; }
        [ApiMember(IsRequired = true)]
        public string UserName { get; set; }
        [ApiMember(IsRequired = true)]
...
}

when testing, the swagger-ui displays a message that the fields are not filled in despite the fact that they are filled in the request body:

  1. is there any way to turn it off?
  2. can IsRequired automatically fill out the validator?

You can’t submit both a Request Body and form url encoded parameters.

Can you change the parameter content type to JSON?

Otherwise this thread showing how to remove the body may help:

All [Api*] attributes are just metadata annotations, they do not have any impact to your Services implementation. You still need to do your own validation.

1 Like
Plugins.Add(new OpenApiFeature() {
    OperationFilter = (verb, op) =>
    {
        if (op.OperationId.StartsWith("DocumentCreate"))
        op.Parameters.RemoveAll(p => p.In != "body");
    }
});

[ApiMember(IsRequired = true)]

after making changes I got what I wanted, but now changed content-type before was json and therefore the request is not worked out, how to make so that content-type remained json?

Plugins.Add(new OpenApiFeature() {    
      OperationFilter = (verb, op) => {
            op.Consumes.Clear();
            op.Consumes.Add("application/json");
    
            op.Parameters.RemoveAll(p => p.In != "body");
       }
});

so it worked, thank you very much!