Skip to content

/v3/api-docs json endpoint returns json api specs encoded in one string #900

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
ewirch opened this issue Oct 12, 2020 · 2 comments
Closed

Comments

@ewirch
Copy link

ewirch commented Oct 12, 2020

Version 1.4.8. Default configuration. Running:

curl http://localhost:8080/v3/api-docs

Returns:

"{\"openapi\":\"3.0.1\",\"info\":{\"title\":\"OpenAPI definition\",\"vers...

I replaced the remainder of the response by "...", because it is already clear, that this is not the spec in json, but: spec in json encoded in a json string. Response should be:

{"openapi":"3.0.1","info":{"title":"OpenAPI definition","vers...

The problem is the content type definition and the String return type:

	@GetMapping(value = API_DOCS_URL, produces = MediaType.APPLICATION_JSON_VALUE)
	public String openapiJson(HttpServletRequest request, @Value(API_DOCS_URL) String apiDocsUrl)
			throws JsonProcessingException {

If Spring "knows" how to convert to Json, it will convert the returned string value to a Json string (the observed result).

A plain text content type might help, or returning the actual object when Spring knows how to convert to Json.

@bnasslahsen
Copy link
Collaborator

@ewirch,

This is mostly related to your custom Json mapper configuration.

You can have a look at the discussion here, where you have sample code, if you want to change the return value: You can override the OpenApiResource as proposed.

You might be in one of the cases.

@jiangxiaoqiang
Copy link

jiangxiaoqiang commented Jun 4, 2022

@ewirch,

This is mostly related to your custom Json mapper configuration.

You can have a look at the discussion here, where you have sample code, if you want to change the return value: You can override the OpenApiResource as proposed.

You might be in one of the cases.

how about just return the OpenApiResource object, why serilize the object to json in specific place?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants