Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc07093c

Browse files
committed
ModelResolver.enumAsRef = true result in invalid openapi with actuator using enum param#2905
1 parent4412fd0 commitc07093c

File tree

5 files changed

+1034
-21
lines changed

5 files changed

+1034
-21
lines changed

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
importorg.slf4j.LoggerFactory;
8787
importorg.springdoc.core.annotations.RouterOperations;
8888
importorg.springdoc.core.customizers.DataRestRouterOperationCustomizer;
89+
importorg.springdoc.core.customizers.GlobalOperationComponentsCustomizer;
8990
importorg.springdoc.core.customizers.OpenApiLocaleCustomizer;
9091
importorg.springdoc.core.customizers.OperationCustomizer;
9192
importorg.springdoc.core.customizers.RouterOperationCustomizer;
@@ -649,7 +650,7 @@ protected void calculatePath(HandlerMethod handlerMethod, RouterOperation router
649650
buildCallbacks(openAPI,methodAttributes,operation,apiCallbacks);
650651

651652
// allow for customisation
652-
operation =customizeOperation(operation,handlerMethod);
653+
operation =customizeOperation(operation,components,handlerMethod);
653654

654655
if (StringUtils.contains(operationPath,"*")) {
655656
Matchermatcher =pathPattern.matcher(operationPath);
@@ -1011,15 +1012,20 @@ protected Set<RequestMethod> getDefaultAllowedHttpMethods() {
10111012
* Customise operation.
10121013
*
10131014
* @param operation the operation
1015+
* @param components
10141016
* @param handlerMethod the handler method
10151017
* @return the operation
10161018
*/
1017-
protectedOperationcustomizeOperation(Operationoperation,HandlerMethodhandlerMethod) {
1019+
protectedOperationcustomizeOperation(Operationoperation,Componentscomponents,HandlerMethodhandlerMethod) {
10181020
Optional<Set<OperationCustomizer>>optionalOperationCustomizers =springDocCustomizers.getOperationCustomizers();
10191021
if (optionalOperationCustomizers.isPresent()) {
10201022
Set<OperationCustomizer>operationCustomizerList =optionalOperationCustomizers.get();
1021-
for (OperationCustomizeroperationCustomizer :operationCustomizerList)
1022-
operation =operationCustomizer.customize(operation,handlerMethod);
1023+
for (OperationCustomizeroperationCustomizer :operationCustomizerList) {
1024+
if (operationCustomizerinstanceofGlobalOperationComponentsCustomizerglobalOperationComponentsCustomizer)
1025+
operation =globalOperationComponentsCustomizer.customize(operation,components,handlerMethod);
1026+
else
1027+
operation =operationCustomizer.customize(operation,handlerMethod);
1028+
}
10231029
}
10241030
returnoperation;
10251031
}

‎springdoc-openapi-starter-common/src/main/java/org/springdoc/core/customizers/ActuatorOperationCustomizer.java

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* * * *
2222
* * *
2323
* *
24-
*
24+
*
2525
*/
2626

2727
packageorg.springdoc.core.customizers;
@@ -31,6 +31,7 @@
3131

3232
importio.swagger.v3.core.util.AnnotationsUtils;
3333
importio.swagger.v3.oas.annotations.enums.ParameterIn;
34+
importio.swagger.v3.oas.models.Components;
3435
importio.swagger.v3.oas.models.Operation;
3536
importio.swagger.v3.oas.models.media.Content;
3637
importio.swagger.v3.oas.models.media.MediaType;
@@ -61,7 +62,7 @@
6162
*
6263
* @author bnasslahsen
6364
*/
64-
publicclassActuatorOperationCustomizerimplementsGlobalOperationCustomizer {
65+
publicclassActuatorOperationCustomizerimplementsGlobalOperationComponentsCustomizer {
6566

6667
/**
6768
* The constant OPERATION.
@@ -94,11 +95,11 @@ public ActuatorOperationCustomizer(SpringDocConfigProperties springDocConfigProp
9495
}
9596

9697
@Override
97-
publicOperationcustomize(Operationoperation,HandlerMethodhandlerMethod) {
98+
publicOperationcustomize(Operationoperation,Componentscomponents,HandlerMethodhandlerMethod) {
9899
if (operationHasValidTag(operation)) {
99100
FieldoperationField =FieldUtils.getDeclaredField(handlerMethod.getBean().getClass(),OPERATION,true);
100101
if (operationField !=null) {
101-
processOperationField(handlerMethod,operation,operationField);
102+
processOperationField(handlerMethod,operation,components,operationField);
102103
}
103104
setOperationSummary(operation,handlerMethod);
104105
}
@@ -120,16 +121,17 @@ private boolean operationHasValidTag(Operation operation) {
120121
*
121122
* @param handlerMethod the handler method
122123
* @param operation the operation
124+
* @param components the components
123125
* @param operationField the operation field
124126
*/
125-
privatevoidprocessOperationField(HandlerMethodhandlerMethod,Operationoperation,FieldoperationField) {
127+
privatevoidprocessOperationField(HandlerMethodhandlerMethod,Operationoperation,Componentscomponents,FieldoperationField) {
126128
try {
127129
ObjectactuatorOperation =operationField.get(handlerMethod.getBean());
128130
FieldactuatorOperationField =FieldUtils.getDeclaredField(actuatorOperation.getClass(),OPERATION,true);
129131
if (actuatorOperationField !=null) {
130132
AbstractDiscoveredOperationdiscoveredOperation =
131133
(AbstractDiscoveredOperation)actuatorOperationField.get(actuatorOperation);
132-
handleOperationMethod(discoveredOperation.getOperationMethod(),operation);
134+
handleOperationMethod(discoveredOperation.getOperationMethod(),components,operation);
133135
}
134136
}
135137
catch (IllegalAccessExceptione) {
@@ -141,25 +143,26 @@ private void processOperationField(HandlerMethod handlerMethod, Operation operat
141143
* Handle operation method.
142144
*
143145
* @param operationMethod the operation method
146+
* @param components the components
144147
* @param operation the operation
145148
*/
146-
privatevoidhandleOperationMethod(OperationMethodoperationMethod,Operationoperation) {
149+
privatevoidhandleOperationMethod(OperationMethodoperationMethod,Componentscomponents,Operationoperation) {
147150
StringoperationId =operationMethod.getMethod().getName();
148151
operation.setOperationId(operationId);
149152

150153
switch (operationMethod.getOperationType()) {
151154
caseREAD:
152-
addParameters(operationMethod,operation,ParameterIn.QUERY);
155+
addParameters(operationMethod,operation,components,ParameterIn.QUERY);
153156
break;
154157
caseWRITE:
155-
addWriteParameters(operationMethod,operation);
158+
addWriteParameters(operationMethod,components,operation);
156159
operation.setResponses(newApiResponses()
157160
.addApiResponse(String.valueOf(HttpStatus.NO_CONTENT.value()),newApiResponse().description(HttpStatus.NO_CONTENT.getReasonPhrase()))
158161
.addApiResponse(String.valueOf(HttpStatus.BAD_REQUEST.value()),newApiResponse().description(HttpStatus.BAD_REQUEST.getReasonPhrase())));
159162
break;
160163
caseDELETE:
161164
operation.setResponses(newApiResponses().addApiResponse(String.valueOf(HttpStatus.NO_CONTENT.value()),newApiResponse().description(HttpStatus.NO_CONTENT.getReasonPhrase())));
162-
addParameters(operationMethod,operation,ParameterIn.QUERY);
165+
addParameters(operationMethod,operation,components,ParameterIn.QUERY);
163166
break;
164167
default:
165168
break;
@@ -171,13 +174,14 @@ private void handleOperationMethod(OperationMethod operationMethod, Operation op
171174
*
172175
* @param operationMethod the operation method
173176
* @param operation the operation
177+
* @param components the components
174178
* @param parameterIn the parameter in
175179
*/
176-
privatevoidaddParameters(OperationMethodoperationMethod,Operationoperation,ParameterInparameterIn) {
180+
privatevoidaddParameters(OperationMethodoperationMethod,Operationoperation,Componentscomponents,ParameterInparameterIn) {
177181
for (OperationParameteroperationParameter :operationMethod.getParameters()) {
178182
Parameterparameter =getParameterFromField(operationParameter);
179183
if(parameter ==null)continue;
180-
Schema<?>schema =resolveSchema(parameter);
184+
Schema<?>schema =resolveSchema(parameter,components);
181185
if (parameter.getAnnotation(Selector.class) !=null) {
182186
operation.addParametersItem(newio.swagger.v3.oas.models.parameters.PathParameter()
183187
.name(parameter.getName())
@@ -197,13 +201,14 @@ else if (isValidParameterType(parameter)) {
197201
* Add write parameters.
198202
*
199203
* @param operationMethod the operation method
204+
* @param components the components
200205
* @param operation the operation
201206
*/
202-
privatevoidaddWriteParameters(OperationMethodoperationMethod,Operationoperation) {
207+
privatevoidaddWriteParameters(OperationMethodoperationMethod,Componentscomponents,Operationoperation) {
203208
for (OperationParameteroperationParameter :operationMethod.getParameters()) {
204209
Parameterparameter =getParameterFromField(operationParameter);
205210
if(parameter ==null)continue;
206-
Schema<?>schema =resolveSchema(parameter);
211+
Schema<?>schema =resolveSchema(parameter,components);
207212
if (parameter.getAnnotation(Selector.class) !=null) {
208213
operation.addParametersItem(newio.swagger.v3.oas.models.parameters.PathParameter()
209214
.name(parameter.getName())
@@ -237,11 +242,12 @@ private Parameter getParameterFromField(OperationParameter operationParameter) {
237242
/**
238243
* Resolve schema schema.
239244
*
240-
* @param parameter the parameter
245+
* @param parameter the parameter
246+
* @param components
241247
* @return the schema
242248
*/
243-
privateSchema<?>resolveSchema(Parameterparameter) {
244-
Schemaschema =AnnotationsUtils.resolveSchemaFromType(parameter.getType(),null,null,springDocConfigProperties.isOpenapi31());
249+
privateSchema<?>resolveSchema(Parameterparameter,Componentscomponents) {
250+
Schemaschema =AnnotationsUtils.resolveSchemaFromType(parameter.getType(),components,null,springDocConfigProperties.isOpenapi31());
245251
if(springDocConfigProperties.isOpenapi31())handleSchemaTypes(schema);
246252
returnschema;
247253
}
@@ -271,4 +277,8 @@ private void setOperationSummary(Operation operation, HandlerMethod handlerMetho
271277
}
272278
}
273279

280+
@Override
281+
publicOperationcustomize(Operationoperation,HandlerMethodhandlerMethod) {
282+
returnthis.customize(operation,null,handlerMethod);
283+
}
274284
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
*
3+
* *
4+
* * *
5+
* * * *
6+
* * * * *
7+
* * * * * * Copyright 2019-2025 the original author or authors.
8+
* * * * * *
9+
* * * * * * Licensed under the Apache License, Version 2.0 (the "License");
10+
* * * * * * you may not use this file except in compliance with the License.
11+
* * * * * * You may obtain a copy of the License at
12+
* * * * * *
13+
* * * * * * https://www.apache.org/licenses/LICENSE-2.0
14+
* * * * * *
15+
* * * * * * Unless required by applicable law or agreed to in writing, software
16+
* * * * * * distributed under the License is distributed on an "AS IS" BASIS,
17+
* * * * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
* * * * * * See the License for the specific language governing permissions and
19+
* * * * * * limitations under the License.
20+
* * * * *
21+
* * * *
22+
* * *
23+
* *
24+
*
25+
*/
26+
27+
packageorg.springdoc.core.customizers;
28+
29+
importio.swagger.v3.oas.models.Components;
30+
importio.swagger.v3.oas.models.Operation;
31+
32+
importorg.springframework.web.method.HandlerMethod;
33+
34+
/**
35+
* Implement and register a bean of type {@link GlobalOperationComponentsCustomizer} to
36+
* customize an operation based on the components and handler method input on default OpenAPI
37+
* description and groups
38+
*
39+
* @author christophejan
40+
* @see OperationCustomizer operations on default OpenAPI description but not groups
41+
*/
42+
publicinterfaceGlobalOperationComponentsCustomizerextendsGlobalOperationCustomizer {
43+
44+
/**
45+
* Customize operation.
46+
*
47+
* @param operation input operation
48+
* @param handlerMethod original handler method
49+
* @return customized operation
50+
*/
51+
Operationcustomize(Operationoperation,Componentscomponents,HandlerMethodhandlerMethod);
52+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
*
3+
* *
4+
* * *
5+
* * * *
6+
* * * * * Copyright 2019-2024 the original author or authors.
7+
* * * * *
8+
* * * * * Licensed under the Apache License, Version 2.0 (the "License");
9+
* * * * * you may not use this file except in compliance with the License.
10+
* * * * * You may obtain a copy of the License at
11+
* * * * *
12+
* * * * * https://www.apache.org/licenses/LICENSE-2.0
13+
* * * * *
14+
* * * * * Unless required by applicable law or agreed to in writing, software
15+
* * * * * distributed under the License is distributed on an "AS IS" BASIS,
16+
* * * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* * * * * See the License for the specific language governing permissions and
18+
* * * * * limitations under the License.
19+
* * * *
20+
* * *
21+
* *
22+
*
23+
*/
24+
25+
packagetest.org.springdoc.api.v30.app187;
26+
27+
importorg.junit.jupiter.api.AfterAll;
28+
importtest.org.springdoc.api.v30.AbstractSpringDocTest;
29+
30+
importorg.springframework.boot.autoconfigure.SpringBootApplication;
31+
importorg.springframework.test.context.TestPropertySource;
32+
33+
@TestPropertySource(properties = {"springdoc.show-actuator=true",
34+
"management.endpoints.web.exposure.include=*",
35+
"management.endpoints.enabled-by-default=true",
36+
"management.endpoints.web.exposure.exclude=functions, shutdown" })
37+
publicclassSpringDocApp187TestextendsAbstractSpringDocTest {
38+
39+
static {
40+
io.swagger.v3.core.jackson.ModelResolver.enumsAsRef =true;
41+
}
42+
43+
@AfterAll
44+
staticvoidrestore() {
45+
io.swagger.v3.core.jackson.ModelResolver.enumsAsRef =false;
46+
}
47+
48+
@SpringBootApplication
49+
staticclassSpringDocTestApp {}
50+
51+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp