0

I'm trying to include a bad request (400) response schemas in the open api document for the web api I'm building in .NET 6. The problem is, the media type always defaults to application/octet-stream even though I explicitly set it to application/json.

My controller is decorated with the following attribute:

[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType(typeof(BadRequestResult), (int)HttpStatusCode.BadRequest, "application/json")]

But, the media type for the response 400 is incorrect in the generated open api document:

"200": {
  "description": "",
  "content": {
    "application/json": {
      "schema": {
        "$ref": "#/components/schemas/Foo"
      }
    }
  }
},
"400": {
  "description": "",
  "content": {
    "application/octet-stream": {
      "schema": {
        "type": "string",
        "format": "binary"
      }
    }
  }
}

Am I missing something or is this a bug in NSwag?

mafus1
  • 191
  • 1
  • 6

1 Answers1

1

So this is no bug, I was using ObjectResult as the response type instead of ProblemDetails. Apparently this class could not be serialized or something and that produced a different response media type. So no bug!

mafus1
  • 191
  • 1
  • 6