Skip to content

Commit 8045f9a

Browse files
committed
springdoc.model-and-view-allowed. Fixes #1892
1 parent ad0ddc7 commit 8045f9a

File tree

5 files changed

+252
-1
lines changed

5 files changed

+252
-1
lines changed

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

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

12711271
/**
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,171 @@
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+
"/actuator/health": {
94+
"get": {
95+
"tags": [
96+
"Actuator"
97+
],
98+
"summary": "Actuator web endpoint 'health'",
99+
"operationId": "health",
100+
"responses": {
101+
"200": {
102+
"description": "OK",
103+
"content": {
104+
"application/vnd.spring-boot.actuator.v3+json": {
105+
"schema": {
106+
"type": "object"
107+
}
108+
},
109+
"application/vnd.spring-boot.actuator.v2+json": {
110+
"schema": {
111+
"type": "object"
112+
}
113+
},
114+
"application/json": {
115+
"schema": {
116+
"type": "object"
117+
}
118+
}
119+
}
120+
}
121+
}
122+
}
123+
},
124+
"/actuator/health/**": {
125+
"get": {
126+
"tags": [
127+
"Actuator"
128+
],
129+
"summary": "Actuator web endpoint 'health-path'",
130+
"operationId": "health-path",
131+
"responses": {
132+
"200": {
133+
"description": "OK",
134+
"content": {
135+
"application/vnd.spring-boot.actuator.v3+json": {
136+
"schema": {
137+
"type": "object"
138+
}
139+
},
140+
"application/vnd.spring-boot.actuator.v2+json": {
141+
"schema": {
142+
"type": "object"
143+
}
144+
},
145+
"application/json": {
146+
"schema": {
147+
"type": "object"
148+
}
149+
}
150+
}
151+
}
152+
}
153+
}
154+
}
155+
},
156+
"components": {
157+
"schemas": {
158+
"Link": {
159+
"type": "object",
160+
"properties": {
161+
"href": {
162+
"type": "string"
163+
},
164+
"templated": {
165+
"type": "boolean"
166+
}
167+
}
168+
}
169+
}
170+
}
171+
}

0 commit comments

Comments
 (0)