locked
Raw json returned response body with html tags RRS feed

  • Question

  • User-457790453 posted

    I've opened this issue with Swagger also, but please assist if you faced it before:

    https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/564

    I'm getting the below response with html tags like \r\n in Swagger UI:
    "{\r\n \"eventId\": \"6ab342c2-a06d-4595-82fb-91d9b9380f0d\",\r\n \"name\": \"string\",\r\n \"comment\": \"string\"}

    When having the following attribute on my action method:
    [ProducesResponseType(200)] [ProducesResponseType(typeof(JsonErrorResponse), 400)]
    If I remove the 400 response type, it works and returns clean formatted json.
    or if I write it like
    [ProducesResponseType(200)] [ProducesResponseType(400)]

    I'm using .net core 2.0 and SwachBackle.AspNetCore 1.0.0

    Tuesday, January 2, 2018 7:56 PM

Answers

  • User-457790453 posted

    setting the response type for the 200 status solved the issue. I was returning without specifying the type.
    This works:
    [ProducesResponseType(**typeof(MyDto)**,200)] [ProducesResponseType(typeof(JsonErrorResponse), 400)]

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 2, 2018 8:18 PM

All replies

  • User-457790453 posted

    setting the response type for the 200 status solved the issue. I was returning without specifying the type.
    This works:
    [ProducesResponseType(**typeof(MyDto)**,200)] [ProducesResponseType(typeof(JsonErrorResponse), 400)]

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 2, 2018 8:18 PM
  • User753101303 posted

    Hi,

    You have as specialized forum for ASP.NET Core. I'm still very green to it but it seems to return a single string that is itself a json payload (ie the json encoding happened twice). This is a relatively common error even in ASP.NET 4.x (and sometimes unnoticed if the same mistake is done on the client side).

    What is surprising is that it seems to happen with attributes that are supposed to allow documentating what is done without changing anything to the response ? Or do you have explicit Json encoding in your code ?

    Edit; saw you solved your issue meanwhile...

    Tuesday, January 2, 2018 8:27 PM
  • User-457790453 posted

    Yes had to change the attribute and specify the return type explicity.

    Thanks for the contribution.

    Wednesday, January 3, 2018 7:48 AM