Skip to content

Commit 0f90239

Browse files
committed
Merge branch 'routerfunction-attributes2' for #891
2 parents c567f67 + 4d68351 commit 0f90239

File tree

113 files changed

+12603
-41
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+12603
-41
lines changed

pom.xml

+23
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,29 @@
244244
</profile>
245245
</profiles>
246246
<repositories>
247+
<repository>
248+
<id>central</id>
249+
<url>https://repo.maven.apache.org/maven2</url>
250+
<snapshots>
251+
<enabled>false</enabled>
252+
</snapshots>
253+
</repository>
254+
<repository>
255+
<id>spring-release</id>
256+
<name>Spring release</name>
257+
<url>https://repo.spring.io/release</url>
258+
<snapshots>
259+
<enabled>false</enabled>
260+
</snapshots>
261+
</repository>
262+
<repository>
263+
<id>spring-snapshot</id>
264+
<name>Spring Snapshots</name>
265+
<url>https://repo.spring.io/snapshot</url>
266+
<snapshots>
267+
<enabled>true</enabled>
268+
</snapshots>
269+
</repository>
247270
<repository>
248271
<id>spring-milestone</id>
249272
<name>Spring Milestone</name>

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

+23-14
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
import org.springframework.web.bind.annotation.RequestMethod;
9494
import org.springframework.web.method.HandlerMethod;
9595

96+
import static org.springdoc.core.Constants.OPERATION_ATTRIBUTE;
9697
import static org.springdoc.core.converters.SchemaPropertyDeprecatingConverter.isDeprecated;
9798

9899
/**
@@ -515,22 +516,30 @@ protected void calculatePath(HandlerMethod handlerMethod, String operationPath,
515516
* @param routerFunctionVisitor the router function visitor
516517
*/
517518
protected void getRouterFunctionPaths(String beanName, AbstractRouterFunctionVisitor routerFunctionVisitor) {
518-
List<org.springdoc.core.annotations.RouterOperation> routerOperationList = new ArrayList<>();
519-
ApplicationContext applicationContext = openAPIService.getContext();
520-
RouterOperations routerOperations = applicationContext.findAnnotationOnBean(beanName, RouterOperations.class);
521-
if (routerOperations == null) {
522-
org.springdoc.core.annotations.RouterOperation routerOperation = applicationContext.findAnnotationOnBean(beanName, org.springdoc.core.annotations.RouterOperation.class);
523-
if (routerOperation != null)
524-
routerOperationList.add(routerOperation);
519+
boolean withRouterOperation = routerFunctionVisitor.getRouterFunctionDatas().stream()
520+
.anyMatch(routerFunctionData -> routerFunctionData.getAttributes().containsKey(OPERATION_ATTRIBUTE));
521+
if (withRouterOperation) {
522+
List<RouterOperation> operationList = routerFunctionVisitor.getRouterFunctionDatas().stream().map(RouterOperation::new).collect(Collectors.toList());
523+
calculatePath(operationList);
525524
}
526-
else
527-
routerOperationList.addAll(Arrays.asList(routerOperations.value()));
528-
if (routerOperationList.size() == 1)
529-
calculatePath(routerOperationList.stream().map(routerOperation -> new RouterOperation(routerOperation, routerFunctionVisitor.getRouterFunctionDatas().get(0))).collect(Collectors.toList()));
530525
else {
531-
List<RouterOperation> operationList = routerOperationList.stream().map(RouterOperation::new).collect(Collectors.toList());
532-
mergeRouters(routerFunctionVisitor.getRouterFunctionDatas(), operationList);
533-
calculatePath(operationList);
526+
List<org.springdoc.core.annotations.RouterOperation> routerOperationList = new ArrayList<>();
527+
ApplicationContext applicationContext = openAPIService.getContext();
528+
RouterOperations routerOperations = applicationContext.findAnnotationOnBean(beanName, RouterOperations.class);
529+
if (routerOperations == null) {
530+
org.springdoc.core.annotations.RouterOperation routerOperation = applicationContext.findAnnotationOnBean(beanName, org.springdoc.core.annotations.RouterOperation.class);
531+
if (routerOperation != null)
532+
routerOperationList.add(routerOperation);
533+
}
534+
else
535+
routerOperationList.addAll(Arrays.asList(routerOperations.value()));
536+
if (routerOperationList.size() == 1)
537+
calculatePath(routerOperationList.stream().map(routerOperation -> new RouterOperation(routerOperation, routerFunctionVisitor.getRouterFunctionDatas().get(0))).collect(Collectors.toList()));
538+
else {
539+
List<RouterOperation> operationList = routerOperationList.stream().map(RouterOperation::new).collect(Collectors.toList());
540+
mergeRouters(routerFunctionVisitor.getRouterFunctionDatas(), operationList);
541+
calculatePath(operationList);
542+
}
534543
}
535544
}
536545

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

+23
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
/*
2+
*
3+
*
4+
* *
5+
* * *
6+
* * * * Copyright 2019-2020 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+
124
package org.springdoc.api;
225

326
/**

springdoc-openapi-common/src/main/java/org/springdoc/core/Constants.java

+5
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,11 @@ public final class Constants {
270270
*/
271271
public static final String CSRF_DEFAULT_HEADER_NAME= "X-XSRF-TOKEN";
272272

273+
/**
274+
* The constant OPERATION_ATTRIBUTE.
275+
*/
276+
public static final String OPERATION_ATTRIBUTE = Constants.class.getName() + ".operation";
277+
273278
/**
274279
* Instantiates a new Constants.
275280
*/

springdoc-openapi-common/src/main/java/org/springdoc/core/RepositoryRestResourceProvider.java

+23
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
/*
2+
*
3+
*
4+
* *
5+
* * *
6+
* * * * Copyright 2019-2020 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+
124
package org.springdoc.core;
225

326
import java.util.List;

springdoc-openapi-common/src/main/java/org/springdoc/core/customizers/ActuatorOpenApiCustomizer.java

+23
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
/*
2+
*
3+
*
4+
* *
5+
* * *
6+
* * * * Copyright 2019-2020 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+
124
package org.springdoc.core.customizers;
225

326
import java.util.List;

springdoc-openapi-common/src/main/java/org/springdoc/core/customizers/DelegatingMethodParameterCustomizer.java

+23
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
/*
2+
*
3+
*
4+
* *
5+
* * *
6+
* * * * Copyright 2019-2020 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+
124
package org.springdoc.core.customizers;
225

326
import org.springframework.core.MethodParameter;

springdoc-openapi-common/src/main/java/org/springdoc/core/fn/AbstractRouterFunctionVisitor.java

+28-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222

2323
import java.util.ArrayList;
2424
import java.util.Arrays;
25+
import java.util.LinkedHashMap;
2526
import java.util.List;
27+
import java.util.Map;
2628
import java.util.Set;
2729

2830
import org.apache.commons.lang3.StringUtils;
@@ -76,6 +78,11 @@ public class AbstractRouterFunctionVisitor {
7678
*/
7779
protected RouterFunctionData routerFunctionData;
7880

81+
/**
82+
* The Attributes.
83+
*/
84+
protected Map<String,Object> attributes = new LinkedHashMap<>();
85+
7986
/**
8087
* Method.
8188
*
@@ -223,18 +230,18 @@ protected void computeNested() {
223230
List<RouterFunctionData> routerFunctionDatasClone = new ArrayList<>();
224231
for (RouterFunctionData functionData : routerFunctionDatas) {
225232
for (String nestedOrPath : nestedOrPaths) {
226-
RouterFunctionData routerFunctionDataClone = new RouterFunctionData(nestedOrPath + functionData.getPath(), functionData.getConsumes(), functionData.getProduces(), functionData.getHeaders(), functionData.getQueryParams(), functionData.getMethods());
233+
RouterFunctionData routerFunctionDataClone = new RouterFunctionData(nestedOrPath , functionData);
227234
routerFunctionDatasClone.add(routerFunctionDataClone);
228235
}
229236
}
230237
this.routerFunctionDatas = routerFunctionDatasClone;
231238
nestedAndPaths.clear();
232239
}
233-
if (!nestedAcceptHeaders.isEmpty()){
240+
if (!nestedAcceptHeaders.isEmpty()) {
234241
routerFunctionDatas.forEach(existingRouterFunctionData -> existingRouterFunctionData.addProduces(nestedAcceptHeaders));
235242
nestedAcceptHeaders.clear();
236243
}
237-
if (!nestedContentTypeHeaders.isEmpty()){
244+
if (!nestedContentTypeHeaders.isEmpty()) {
238245
routerFunctionDatas.forEach(existingRouterFunctionData -> existingRouterFunctionData.addConsumes(nestedContentTypeHeaders));
239246
nestedContentTypeHeaders.clear();
240247
}
@@ -284,4 +291,22 @@ private void calculateAccept(String value) {
284291
}
285292
}
286293

294+
/**
295+
* Route.
296+
*/
297+
protected void route() {
298+
this.routerFunctionData = new RouterFunctionData();
299+
routerFunctionDatas.add(this.routerFunctionData);
300+
this.routerFunctionData.addAttributes(this.attributes);
301+
}
302+
303+
/**
304+
* Attributes.
305+
*
306+
* @param map the map
307+
*/
308+
public void attributes(Map<String, Object> map) {
309+
this.attributes = map;
310+
}
311+
287312
}

springdoc-openapi-common/src/main/java/org/springdoc/core/fn/RouterFunctionData.java

+35-15
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
import java.util.ArrayList;
2424
import java.util.Arrays;
25-
import java.util.HashMap;
25+
import java.util.LinkedHashMap;
2626
import java.util.List;
2727
import java.util.Map;
2828
import java.util.Set;
@@ -63,13 +63,18 @@ public class RouterFunctionData {
6363
/**
6464
* The Query params.
6565
*/
66-
private Map<String, String> queryParams = new HashMap<>();
66+
private Map<String, String> queryParams = new LinkedHashMap<>();
6767

6868
/**
6969
* The Methods.
7070
*/
7171
private RequestMethod[] methods;
7272

73+
/**
74+
* The Attributes.
75+
*/
76+
private Map<String,Object> attributes = new LinkedHashMap<>();
77+
7378
/**
7479
* Instantiates a new Router function data.
7580
*/
@@ -78,20 +83,17 @@ public RouterFunctionData() { }
7883
/**
7984
* Instantiates a new Router function data.
8085
*
81-
* @param path the path
82-
* @param consumes the consumes
83-
* @param produces the produces
84-
* @param headers the headers
85-
* @param queryParams the query params
86-
* @param methods the methods
86+
* @param nestedOrPath the nested or path
87+
* @param functionData the function data
8788
*/
88-
public RouterFunctionData(String path, String[] consumes, String[] produces, String[] headers, Map<String, String> queryParams, RequestMethod[] methods) {
89-
this.path = path;
90-
this.consumes = Arrays.asList(consumes);
91-
this.produces = Arrays.asList(produces);
92-
this.headers = Arrays.asList(headers);
93-
this.queryParams = queryParams;
94-
this.methods = methods;
89+
public RouterFunctionData(String nestedOrPath, RouterFunctionData functionData) {
90+
this.path = nestedOrPath + functionData.getPath();
91+
this.consumes = Arrays.asList(functionData.getConsumes());
92+
this.produces = Arrays.asList(functionData.getProduces());
93+
this.headers = Arrays.asList(functionData.getHeaders());
94+
this.queryParams = functionData.getQueryParams();
95+
this.methods = functionData.getMethods();
96+
this.attributes = functionData.getAttributes();
9597
}
9698

9799
/**
@@ -273,4 +275,22 @@ private RequestMethod getRequestMethod(HttpMethod httpMethod) {
273275
}
274276
return requestMethod;
275277
}
278+
279+
/**
280+
* Gets attributes.
281+
*
282+
* @return the attributes
283+
*/
284+
public Map<String, Object> getAttributes() {
285+
return attributes;
286+
}
287+
288+
/**
289+
* Add attributes.
290+
*
291+
* @param attributes the attributes
292+
*/
293+
public void addAttributes(Map<String, Object> attributes) {
294+
this.attributes.putAll(attributes);
295+
}
276296
}

0 commit comments

Comments
 (0)