I have written a netcore middleware to log request and its response in my 
netcore service layer.
It uses the following workaround and performs quite well:
http://stackoverflow.com/questions/37855384/log-httpresponse-body-for-asp-net-core-1-0-rest-api

It works great but cannot be used from SwaggerUI :-(

This may be the reason:
-----------------------------------------------
If a middleware reads the context.Request.Body stream to the end then 
subsequent tasks in the pipeline won't get any context.Request.Body.
Therefore, the workaround above reads the body stream to the end and 
assigns a new stream to the context.Request.Body which is positioned at 
start.

When I look at the Swagger middleware it looks like it reads the 
context.Request.Body to the end and does not apply the workaround

        private void RespondWithSwaggerJson(HttpResponse response, 
SwaggerDocument swagger)
        {
            response.StatusCode = 200;
            response.ContentType = "application/json";

            using (var writer = new StreamWriter(response.Body))
            {
                _swaggerSerializer.Serialize(writer, swagger);
            }
        }

Has anyone tried to use SwaggerUI on a service layer that has a middleware 
that peeks at respone.body?

-- 
You received this message because you are subscribed to the Google Groups 
"Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to