'Validate Requests in NSwag generated Client
I have a .NET 6 Webclient and REST Contract, that is generated from a YAML with NSwag. The contract contains some validation properties. Is there any way to validate my request on the client side? I don't want to write the validation code by hand. In the NSwag documentation I only found flags to generate validation attributes for generated controllers, but not for the web client.
YAML:
- name: anyField
in: query
description: Field with max value=20 and required
required: true
schema:
maximum: 20
type: integer
format: int32
Generated contract code:
/// <summary>
/// Field with max value=20 and required
/// </summary>
[Newtonsoft.Json.JsonProperty("anyField", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public int AnyField{ get; set; }
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|