Skip to content

Commit 30c387f

Browse files
committed
springdoc.model-and-view-allowed. Fixes #1892
1 parent d902ea6 commit 30c387f

File tree

5 files changed

+190
-1
lines changed

5 files changed

+190
-1
lines changed

springdoc-openapi-common/src/main/java/org/springdoc/api/AbstractOpenApiResource.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1269,7 +1269,7 @@ protected boolean isActuatorRestController(String operationPath, HandlerMethod h
12691269
boolean isActuatorRestController = false;
12701270
if (actuatorProviderOptional.isPresent())
12711271
isActuatorRestController = actuatorProviderOptional.get().isRestController(operationPath, handlerMethod);
1272-
return springDocConfigProperties.isShowActuator() && isActuatorRestController;
1272+
return springDocConfigProperties.isShowActuator() && isActuatorRestController && (modelAndViewClass == null || !modelAndViewClass.isAssignableFrom(handlerMethod.getMethod().getReturnType()));
12731273
}
12741274

12751275
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package test.org.springdoc.api.v30.app196;
2+
3+
import org.springframework.http.HttpStatus;
4+
import org.springframework.http.ResponseEntity;
5+
import org.springframework.validation.annotation.Validated;
6+
import org.springframework.web.bind.annotation.GetMapping;
7+
import org.springframework.web.bind.annotation.RequestMapping;
8+
import org.springframework.web.bind.annotation.RestController;
9+
10+
@RestController()
11+
@RequestMapping("/json")
12+
@Validated
13+
public class JSONController {
14+
15+
@GetMapping()
16+
public ResponseEntity<String> listTemplates() {
17+
return ResponseEntity.status(HttpStatus.OK).body("Hello World");
18+
}
19+
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package test.org.springdoc.api.v30.app196;
2+
3+
import org.springframework.http.MediaType;
4+
import org.springframework.web.bind.annotation.GetMapping;
5+
import org.springframework.web.bind.annotation.RequestMapping;
6+
import org.springframework.web.bind.annotation.ResponseBody;
7+
import org.springframework.web.bind.annotation.RestController;
8+
import org.springframework.web.servlet.ModelAndView;
9+
10+
@RestController
11+
@RequestMapping("/jsp")
12+
public class JSPController {
13+
14+
15+
@GetMapping(produces = MediaType.TEXT_HTML_VALUE)
16+
@ResponseBody
17+
public ModelAndView HelloJSP() {
18+
ModelAndView jsp = new ModelAndView();
19+
jsp.setViewName("index");
20+
21+
return jsp;
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
*
3+
* *
4+
* * *
5+
* * * * Copyright 2019-2022 the original author or authors.
6+
* * * *
7+
* * * * Licensed under the Apache License, Version 2.0 (the "License");
8+
* * * * you may not use this file except in compliance with the License.
9+
* * * * You may obtain a copy of the License at
10+
* * * *
11+
* * * * https://www.apache.org/licenses/LICENSE-2.0
12+
* * * *
13+
* * * * Unless required by applicable law or agreed to in writing, software
14+
* * * * distributed under the License is distributed on an "AS IS" BASIS,
15+
* * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* * * * See the License for the specific language governing permissions and
17+
* * * * limitations under the License.
18+
* * *
19+
* *
20+
*
21+
*/
22+
23+
package test.org.springdoc.api.v30.app196;
24+
25+
import test.org.springdoc.api.v30.AbstractSpringDocV30Test;
26+
27+
import org.springframework.boot.autoconfigure.SpringBootApplication;
28+
import org.springframework.test.context.TestPropertySource;
29+
30+
@TestPropertySource(properties = { "springdoc.show-actuator=true",
31+
"springdoc.model-and-view-allowed=false" })
32+
public class SpringDocApp196Test extends AbstractSpringDocV30Test {
33+
34+
@SpringBootApplication
35+
static class SpringDocTestApp {}
36+
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
{
2+
"openapi": "3.0.1",
3+
"info": {
4+
"title": "OpenAPI definition",
5+
"version": "v0"
6+
},
7+
"servers": [
8+
{
9+
"url": "http://localhost",
10+
"description": "Generated server url"
11+
}
12+
],
13+
"tags": [
14+
{
15+
"name": "Actuator",
16+
"description": "Monitor and interact",
17+
"externalDocs": {
18+
"description": "Spring Boot Actuator Web API Documentation",
19+
"url": "https://docs.spring.io/spring-boot/docs/current/actuator-api/html/"
20+
}
21+
}
22+
],
23+
"paths": {
24+
"/json": {
25+
"get": {
26+
"tags": [
27+
"json-controller"
28+
],
29+
"operationId": "listTemplates",
30+
"responses": {
31+
"200": {
32+
"description": "OK",
33+
"content": {
34+
"*/*": {
35+
"schema": {
36+
"type": "string"
37+
}
38+
}
39+
}
40+
}
41+
}
42+
}
43+
},
44+
"/actuator": {
45+
"get": {
46+
"tags": [
47+
"Actuator"
48+
],
49+
"summary": "Actuator root web endpoint",
50+
"operationId": "links",
51+
"responses": {
52+
"200": {
53+
"description": "OK",
54+
"content": {
55+
"application/vnd.spring-boot.actuator.v3+json": {
56+
"schema": {
57+
"type": "object",
58+
"additionalProperties": {
59+
"type": "object",
60+
"additionalProperties": {
61+
"$ref": "#/components/schemas/Link"
62+
}
63+
}
64+
}
65+
},
66+
"application/vnd.spring-boot.actuator.v2+json": {
67+
"schema": {
68+
"type": "object",
69+
"additionalProperties": {
70+
"type": "object",
71+
"additionalProperties": {
72+
"$ref": "#/components/schemas/Link"
73+
}
74+
}
75+
}
76+
},
77+
"application/json": {
78+
"schema": {
79+
"type": "object",
80+
"additionalProperties": {
81+
"type": "object",
82+
"additionalProperties": {
83+
"$ref": "#/components/schemas/Link"
84+
}
85+
}
86+
}
87+
}
88+
}
89+
}
90+
}
91+
}
92+
}
93+
},
94+
"components": {
95+
"schemas": {
96+
"Link": {
97+
"type": "object",
98+
"properties": {
99+
"href": {
100+
"type": "string"
101+
},
102+
"templated": {
103+
"type": "boolean"
104+
}
105+
}
106+
}
107+
}
108+
}
109+
}

0 commit comments

Comments
 (0)