I have a set of DTOs, that can be either submitted or received by the client in an api call.
The way, that we synchronize between client<-> server DTOs is using NSwag, which generates a client.ts
file, containing all of the types and actions.
It already parses xml documentation and includes them in the appropriate places.
I've added the following RequiredAttribute
[AttributeUsage(AttributeTargets.Property)]
public class RequiredAttribute : Attribute
{
public RequiredAttribute(RequiredFlag flags)
{
Flags = flags;
}
public RequiredFlag Flags { get; }
}
this attribute is used like this:
public class SomeDTO
{
[Required(RequiredFlag.Get)]
public int Id { get; set; }
[Required(RequiredFlag.Get)]
public string? Name { get; set; }
}
Now I'd like to inform NSwag that it should basically take this [Required(RequiredFlag.Get)]
and place it over the generated api endpoint, to get something like this in the generated typescript
/**
* @param id
* @return SomeDTO
* @required<SomeDTO, Id | Name>
*/
someDTOGet(id: number): Promise<SomeDTO> {
I'm somewhat experienced in dotnet, but unfamiliar with NSwag.
Diving the NSwag docs to find an existing pattern, but there does not seem to be one