Skip to content
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

Feature: Validation using System.ComponentModel.Annotations #34

Open
HavenDV opened this issue Jul 22, 2024 · 0 comments
Open

Feature: Validation using System.ComponentModel.Annotations #34

HavenDV opened this issue Jul 22, 2024 · 0 comments

Comments

@HavenDV
Copy link
Collaborator

HavenDV commented Jul 22, 2024

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; }
}
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

No branches or pull requests

1 participant