Skip to content

Malformed api-docs JSON when StringHttpMessageConverter is not active #2051

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
micw opened this issue Jan 23, 2023 · 3 comments
Closed

Malformed api-docs JSON when StringHttpMessageConverter is not active #2051

micw opened this issue Jan 23, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@micw
Copy link

micw commented Jan 23, 2023

Describe the bug

StringHttpMessageConverter unwraps a JSON string and delivers it's content a string. This may have some uses but it breaks JSON compatibility. If StringHttpMessageConverter is disabled, a JSON string is quoted properly.

In #624 the issue was already partially discussed. The only working solution is to use StringHttpMessageConverter. A real solution that works without StringHttpMessageConverter is needed, so that it works along with fully JSON compatible applications.

To Reproduce

Create an app with a WebMvcConfigurer with the following code:

	@Override
	public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
		converters.removeIf(c -> c instanceof StringHttpMessageConverter);
	}

Query for spec/v1.

Expected behavior

A Json should be returned. Instead a JSON quoted as JSON string is returned.

Edit:

The fix is trivial, see my comment in #624 (comment)

@bnasslahsen
Copy link
Collaborator

@micw,

The problem with the fix, is the potential regressions.
I am adding it to the master.

Please do not hesitate to propose a PR for your proposals

@bnasslahsen bnasslahsen added the enhancement New feature or request label Feb 5, 2023
@micw
Copy link
Author

micw commented Feb 5, 2023

@bnasslahsen Thank you for making me happy :-)

Edit: what do you mean with regressions? The fix changes from "works sometimes under certain conditions" to "works always" - regressions are very unlikely.

@bnasslahsen
Copy link
Collaborator

@micw,

It means that you might find developers that were using a use-case that you haven't thought about it.
For this case, changing the return type will be with impacts for people not relying on the response type only! And who have chosen to override the springdoc-openapi controllers.
Let's see if there so many people complaining about the change, or maybe more people getting happy.
Only the futur will let us know.

@springdoc springdoc deleted a comment from sibidominic Apr 6, 2023
@springdoc springdoc locked as resolved and limited conversation to collaborators Apr 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants