Skip to content

Commit ee08333

Browse files
author
bnasslahsen
committed
Malformed api-dics JSON when custom HttpMessageConverter is used. Fixes #624
1 parent 3621bbe commit ee08333

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

springdoc-openapi-webflux-core/src/main/java/org/springdoc/webflux/api/MultipleOpenApiResource.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public void afterPropertiesSet() throws Exception {
103103
}
104104

105105
@Operation(hidden = true)
106-
@GetMapping(value = API_DOCS_URL + "/{group}", produces = MediaType.APPLICATION_JSON_VALUE)
106+
@GetMapping(value = API_DOCS_URL + "/{group}", produces = MediaType.TEXT_PLAIN_VALUE)
107107
public Mono<String> openapiJson(ServerHttpRequest
108108
serverHttpRequest, @Value(API_DOCS_URL) String apiDocsUrl, @PathVariable String
109109
group)

springdoc-openapi-webflux-core/src/main/java/org/springdoc/webflux/api/OpenApiResource.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public OpenApiResource(OpenAPIBuilder openAPIBuilder, AbstractRequestBuilder req
8181
}
8282

8383
@Operation(hidden = true)
84-
@GetMapping(value = API_DOCS_URL, produces = MediaType.APPLICATION_JSON_VALUE)
84+
@GetMapping(value = API_DOCS_URL, produces = MediaType.TEXT_PLAIN_VALUE)
8585
public Mono<String> openapiJson(ServerHttpRequest serverHttpRequest, @Value(API_DOCS_URL) String apiDocsUrl)
8686
throws JsonProcessingException {
8787
calculateServerUrl(serverHttpRequest, apiDocsUrl);
@@ -122,7 +122,7 @@ protected void getPaths(Map<String, Object> restControllers) {
122122
}
123123
}
124124

125-
private void calculateServerUrl(ServerHttpRequest serverHttpRequest, String apiDocsUrl) {
125+
protected void calculateServerUrl(ServerHttpRequest serverHttpRequest, String apiDocsUrl) {
126126
String requestUrl = decode(serverHttpRequest.getURI().toString());
127127
String serverBaseUrl = requestUrl.substring(0, requestUrl.length() - apiDocsUrl.length());
128128
openAPIBuilder.setServerBaseUrl(serverBaseUrl);

springdoc-openapi-webmvc-core/src/main/java/org/springdoc/webmvc/api/MultipleOpenApiResource.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public void afterPropertiesSet() throws Exception {
113113
}
114114

115115
@Operation(hidden = true)
116-
@GetMapping(value = API_DOCS_URL + "/{group}", produces = MediaType.APPLICATION_JSON_VALUE)
116+
@GetMapping(value = API_DOCS_URL + "/{group}", produces = MediaType.TEXT_PLAIN_VALUE)
117117
public String openapiJson(HttpServletRequest request, @Value(API_DOCS_URL) String apiDocsUrl,
118118
@PathVariable String group)
119119
throws JsonProcessingException {

springdoc-openapi-webmvc-core/src/main/java/org/springdoc/webmvc/api/OpenApiResource.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public OpenApiResource( OpenAPIBuilder openAPIBuilder, AbstractRequestBuilder re
9999
}
100100

101101
@Operation(hidden = true)
102-
@GetMapping(value = API_DOCS_URL, produces = MediaType.APPLICATION_JSON_VALUE)
102+
@GetMapping(value = API_DOCS_URL, produces = MediaType.TEXT_PLAIN_VALUE)
103103
public String openapiJson(HttpServletRequest request, @Value(API_DOCS_URL) String apiDocsUrl)
104104
throws JsonProcessingException {
105105
calculateServerUrl(request, apiDocsUrl);
@@ -159,7 +159,7 @@ && isPathToMatch(operationPath)) {
159159
}
160160
}
161161

162-
private boolean isRestController(Map<String, Object> restControllers, HandlerMethod handlerMethod,
162+
protected boolean isRestController(Map<String, Object> restControllers, HandlerMethod handlerMethod,
163163
String operationPath) {
164164
ResponseBody responseBodyAnnotation = AnnotationUtils.findAnnotation(handlerMethod.getBeanType(), ResponseBody.class);
165165
if (responseBodyAnnotation == null)
@@ -170,7 +170,7 @@ private boolean isRestController(Map<String, Object> restControllers, HandlerMet
170170
&& (springDocConfigProperties.isModelAndViewAllowed() || !ModelAndView.class.isAssignableFrom(handlerMethod.getMethod().getReturnType()));
171171
}
172172

173-
private void calculateServerUrl(HttpServletRequest request, String apiDocsUrl) {
173+
protected void calculateServerUrl(HttpServletRequest request, String apiDocsUrl) {
174174
String requestUrl = decode(request.getRequestURL().toString());
175175
String calculatedUrl = requestUrl.substring(0, requestUrl.length() - apiDocsUrl.length());
176176
openAPIBuilder.setServerBaseUrl(calculatedUrl);

0 commit comments

Comments
 (0)