Open philrz opened 5 years ago
Yeah, seems like our JSON test is a little too broad.
@philrz, would rendering the response as plaintext work for you?
@shockey: Yes, plaintext would work for me. Thanks!
Hi, I'm also using the steaming json format content-type: application/x-ndjson In general it doesn't seem a great idea to modify response content. But at least in this special case would it be possible to not include the "can't parse JSON. Raw result:\n\n" in response?
Giving this a friendly bump, @shockey 👍 . We have an API platform that produces x-ndjson responses and see the same "can't parse JSON. Raw Result:"
Another bump from mid-2021 :) As of today, JSON still seems to be too broadly matched: https://github.com/swagger-api/swagger-ui/blob/92f1507408f442b9d450c986eba1d007352ec045/src/core/components/response-body.jsx#L96-L107
As per RFC 4627, the only content-type for JSON should be application/json
. Perhaps Swagger-UI should be more strict in this regard.
Our API platform also is adopting NDJSON more and more and we are also affected by this issue :(
Hello guys, any progress here, please?
Seems this is still the same in current master
. JSON (and XML) still seem to be too broadly matched:
In my opinion it would be great to get the "hack" above merged in. (https://github.com/swagger-api/swagger-ui/compare/master...theosanderson:swagger-ui:patch-1)
Happy to create a PR, depending on how much testing I would need to do.
Do we have any progress here? Thanks.
Content & configuration
Swagger/OpenAPI definition:
I've made no changes to the default Swagger-UI configuration. I'm just using the dist of v3.22.1 out-of-the-box.
Is your feature request related to a problem?
I've been trying to document an application that returns
content-type: application/x-ndjson
. The format is spec'ed here. An example response:When I render my spec in Swagger UI out-of-the-box and click Try It Out > Execute, Swagger UI seems to try and fail to treat the response data as JSON, giving an error message:
I can see by peeking in
swagger-ui-bundle.js
where it seem to be treating anycontent-type
that containsjson
as JSON:I'm no JavaScript pro, but I found that if I hack this to exclude my data type, now it silently renders it as text.
Describe the solution you'd like
It would be lovely if Swagger UI actually parsed
x-ndjson
according to its spec. But at minimum, it would be an improvement if it just didn't report an error message due to trying to parse it as JSON, similar to what I've done with my hack.