I’ve been using Swagger on Core MVC for a while but now we’re moving over to ServiceStack. I’m currently stuck on trying to document the response type from a POST endpoint while returning a 201 status code.
But I end up with the response model under “default” instead of my 201 response in Swagger.
Is it possible to remove “default” from a service that only returns a NoContent response? I am hoping I am missing some kind of magic sauce to remove it.
Can you please consolidate your last 3 posts into a single post? they’re all referencing the same issue, it’s much easier for everyone to follow if there was a single thread for this issue everyone can focus on.
The way to denote a Service has no response is to use the IReturnVoid interface marker, e.g:
public class DeleteSessionKey : IDelete, IReturnVoid
{
public string SessionKey { get; set; }
}
But how the Service is represented in Swagger UI is separate issue which @xplicit will take a look at once he wakes up. In the meantime can you add a link (e.g. in a gist or pastebin) to the Open API .json MVC generates for their API?
I guess my other posts look similar, I’ll continue with this one and if it solves the other two I’ll consolidate but I think it’s slightly different issues.
Anyway…
I have the correct marker interfaces on the DTO, just like you posted. The service responds accordingly with a 204 and no content but swagger doesn’t mimic that. When I remove [ApiResponse(HttpStatusCode.NoContent, "No Content")] I end up with this:
Just edit your original post to include all questions, which just looks like how to get the desired Swagger response from your Service that returns no content. You can just add additional comments if there are any remaining questions.
Services which return IReturnVoid now use empty responses in Swagger UI. Status code depends on Config.Return204NoContentForEmptyResponse setting. If this setting is set to true (default value) then 204 status is used in Open API specification, otherwise status code 200 is used.
[Route("/return-void")]
public class ReturnVoidDtoRequest : IReturn<IReturnVoid> {}