Nswag: response schema of "file" is not valid in OpenApi v3

Created on 12 Mar 2019  路  3Comments  路  Source: RicoSuter/NSwag

We have an endpoint that NSwag is generating schema like this for:

"responses": {
          "200": {
            "description": "",
            "content": {
              "application/octet-stream": {
                "schema": {
                  "type": "file"
                }
              }
            }
          }

The method signature is

[HttpPost]
public async Task<IHttpActionResult> Callback(
    string trackingId, [FromBody] CallbackRequest body)

According to speccy and the spec here, the "type": "file" is not valid. The type should be string.

Speccy gives error:

Specification schema is invalid.

expected 'file' to be equals one of Array [ 'integer', 'number', 'string', 'boolean', 'object', 'array' ]
OpenAPI 3 high NSwag.SwaggerGeneration bug

Most helpful comment

Thanks for reporting, should be high prio and easy to fix

All 3 comments

Thanks for reporting, should be high prio and easy to fix

Will be in v12.0.16 soon

The "workaround" is to do what you should do anyway, and add some metadata to the action method, e.g.

[SwaggerResponse(HttpStatusCode.OK, typeof(void))]
[SwaggerResponse(HttpStatusCode.BadRequest, typeof(string))]
Was this page helpful?
0 / 5 - 0 ratings