Ygor Alberto
Ygor Alberto

Reputation: 61

Document possible values for a string using Swagger/C#?

Is there a way that I can, on the method summary XML, list the possible values for a string parameter and document it on Swagger?

Like, on the method below, the possible values for myParam are Y and N, I want to get it to my Swagger documentation.

/// <summary>
/// My method.
/// </summary>
/// <param name="myParam">String parameter with predefined values.</param>
/// <returns>Something.</returns>
[HttpGet]
[ProducesResponseType(typeof(string), 200)]
public JsonResult MyMethod(string myParam)
{
   ...
}

Upvotes: 1

Views: 2299

Answers (1)

tom redfern
tom redfern

Reputation: 31770

Is there a way that I can, on the method summary XML, list the possible values for a string parameter and document it on Swagger?

No you cannot do that

However, swagger defines a description field which supports rich formatting, and which you can use to describe your parameters and therefore the allowed values which may be passed in. This will be visible to anyone consumiong the API definition.

Something like:

paths:
  /MyMethod/myParam:
    get:
      summary: Gets a user by ID.
      parameters:
        - in: path
          name: myParam
          type: string
          required: true
          description: Must be in the form of "X" or "Y"

Upvotes: 2

Related Questions