0

This is the definition added in clean1.csproj file based on NSwag's documentation

  <Target Name="AfterBuild">
<Exec Command="$(NSwagExe) webapi2swagger /assembly:$(OutDir)/Clean1.dll /referencepath: $(ProjectDir)  /output:$(ProjectDir)/clean1swagger.json" />   

The problem is that only 200 response code is being generated like:

        ],
    "responses": {
      "200": {
        "description": "",
        "schema": {
          "$ref": "#/definitions/Product"
        },
        "x-nullable": true
      }
    }

Here are the XML comments at the controller's demo call.

    /// <summary>
    /// Gets a product by Id
    /// </summary>
    /// <remarks>
    /// Remarks-description text.
    /// </remarks>
    /// <response code="200">test 200</response>
    /// <response code="201">test 201/response>
    /// <response code="400">test 400</response></response>
    [HttpGet]
    [ResponseType(typeof(Product))]
    public IHttpActionResult GetProduct(int id)
    {
        var product = products.FirstOrDefault((p) => p.Id == id);
        if (product == null)
        {
            return NotFound();
        }
        return Ok(product);
    }

The json should include and generate automatically the other responses.

4

1 回答 1

3

This is currently not possible. We considered adding this feature but in most cases you need to specify the type and this cannot be done via xml comments. For now you have to use the SwaggerResponseAttribute for that. But please create an issue on Github so that the feature is considered to be added in the future...

于 2017-07-11T16:31:45.943 回答