tryAGI / AutoSDK

Automated .NET SDKs for your APIs
https://autosdk.net
Other
15 stars 2 forks source link

Feature: Validation using System.ComponentModel.Annotations #34

Open HavenDV opened 2 months ago

HavenDV commented 2 months ago

System.ComponentModel.Annotations provides attributes and classes for adding metadata to your data models. Common uses include:

1.  Validation: Attributes like [Required], [StringLength], and [Range] for data validation.
2.  Display: Attributes like [Display] to specify display names and formats.
3.  Metadata: Attributes like [MetadataType] for associating metadata with types.

https://swagger.io/docs/specification/data-models/data-types/ -> Minimum and Maximum

using System.ComponentModel.DataAnnotations;

public class Person
{
    [Required] // Marks this property as required
    [StringLength(100)] // Sets the maximum length
    public string Name { get; set; }

    [Range(0, 120)] // Specifies acceptable range for the age
    public int Age { get; set; }
}