Swashbuckle.aspnetcore: Schema Metadata for C# 9 Records

Created on 4 Dec 2020  路  1Comment  路  Source: domaindrivendev/Swashbuckle.AspNetCore

C# 9 Positional Records & XML Comments

We can't use positional records with XML comments because there is no way to provide comments for the properties. There is a Roslyn bug open for this at https://github.com/dotnet/roslyn/issues/44571. This would be the ideal solution.

C# 9 Records & XML Comments

We can create init properties instead and comment them as usual. This works.

/// <summary>A product.</summary>
public record Product
{
    /// <summary>Gets or sets the unique identifier.</summary>
    public int Id { get; init; }
}

C# 9 Positional Records & Swagger Annotations

Using the [SwaggerSchema] attribute in a positional record doesn't seem to work. Please can support for this be added?

public record Product([SwaggerSchema("The product identifier")] int Id);
p2

Most helpful comment

@RehanSaeed You should be able to target the backing property by doing something like this:

public record Product([property: SwaggerSchema("The product identifier")] int Id);

The corresponding documentation for Positional Record Members can be found here: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-9.0/records#positional-record-members

>All comments

@RehanSaeed You should be able to target the backing property by doing something like this:

public record Product([property: SwaggerSchema("The product identifier")] int Id);

The corresponding documentation for Positional Record Members can be found here: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-9.0/records#positional-record-members

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JoelAdamWeiss picture JoelAdamWeiss  路  4Comments

alasvant picture alasvant  路  3Comments

TimmyGilissen picture TimmyGilissen  路  3Comments

jluqueba picture jluqueba  路  4Comments

mrmartan picture mrmartan  路  3Comments