OpenAPI.NET.CSharpAnnotations icon indicating copy to clipboard operation
OpenAPI.NET.CSharpAnnotations copied to clipboard

Extract cref primitive/enum values and place them into descriptions

Open scott-lin opened this issue 6 years ago • 0 comments

Take for example the following code and comments.

public enum DayOfWeek
{
    Monday,
    Tuesday,
    ...
    Sunday
}

public class FooController : Controller
{
    public const string DefaultValue = "Default";
    public const int DefaultValue2 = 10;

    /// <param name="stringCriteria" required="false" cref="string" in="query">
    /// Optional string criteria of resource to query. Default is <see cref="DefaultValue"/>.
    /// </param>
    /// <param name="dayOfWeek" required="false" cref="DayOfWeek" in="query">
    /// Optional day of week of resource to query. Default is <see cref="DayOfWeek.Tuesday"/>.
    /// </param>
    /// <param name="numberCriteria" required="false" cref="int" in="query">
    /// Optional number criteria of resource to query. Default is <see cref="DefaultValue2"/>.
    /// </param>
    public void Get(
        string stringCriteria = DefaultValue,
        DayOfWeek dayOfWeek = DayOfWeek.Tuesday,
        int numberCriteria = DefaultValue2 )
    {
        ...
    }
}

I would love to see the descriptions in the resulting OpenAPI document to be:

Optional string criteria of resource to query. Default is 'Default'.
Optional day of week of resource to query. Default is 'Tuesday'.
Optional number criteria of resource to query. Default is '10'.

Today, the descriptions are filled with the literal cref text, so for the examples above, they would be something like:

Optional string criteria of resource to query. Default is 'DefaultValue'.
Optional day of week of resource to query. Default is 'DayOfWeek.Tuesday'.
Optional number criteria of resource to query. Default is 'DefaultValue2'.

Naturally, we cannot do this convenience for complex referenced types, but for simple types like primitives and enums, we should be able to. It would keep documentation in sync with the code values, which is a plus for readers of the OpenAPI documents since they don't have to refer back to code.

scott-lin avatar Mar 17 '18 06:03 scott-lin