Skip to content

Commit b2fecd1

Browse files
committed
Add support for BasePathAwareController. Fixes #1383
1 parent ebec205 commit b2fecd1

File tree

8 files changed

+697
-10
lines changed

8 files changed

+697
-10
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ public interface RepositoryRestResourceProvider {
2323
List<RouterOperation> getRouterOperations(OpenAPI openAPI, Locale locale);
2424

2525
/**
26-
* Gets repository rest controller endpoints.
26+
* Gets Base PathAwar eController endpoints.
2727
*
28-
* @return the repository rest controller endpoints
28+
* @return the Base PathAware Controller endpoints
2929
*/
30-
Map<String, Object> getRepositoryRestControllerEndpoints();
30+
Map<String, Object> getBasePathAwareControllerEndpoints();
3131

3232
/**
3333
* Gets handler methods.

springdoc-openapi-data-rest/src/main/java/org/springdoc/data/rest/SpringRepositoryRestResourceProvider.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@
5555
import org.springframework.data.rest.core.mapping.ResourceMappings;
5656
import org.springframework.data.rest.core.mapping.ResourceMetadata;
5757
import org.springframework.data.rest.core.mapping.SearchResourceMappings;
58+
import org.springframework.data.rest.webmvc.BasePathAwareController;
5859
import org.springframework.data.rest.webmvc.BasePathAwareHandlerMapping;
5960
import org.springframework.data.rest.webmvc.ProfileController;
60-
import org.springframework.data.rest.webmvc.RepositoryRestController;
6161
import org.springframework.data.rest.webmvc.RepositoryRestHandlerMapping;
6262
import org.springframework.data.rest.webmvc.alps.AlpsController;
6363
import org.springframework.data.rest.webmvc.json.JacksonMetadata;
@@ -187,6 +187,7 @@ public class SpringRepositoryRestResourceProvider implements RepositoryRestResou
187187
* @param dataRestRouterOperationService the data rest router operation builder
188188
* @param persistentEntities the persistent entities
189189
* @param mapper the mapper
190+
* @param springDocDataRestUtils the spring doc data rest utils
190191
*/
191192
public SpringRepositoryRestResourceProvider(ResourceMappings mappings, Repositories repositories,
192193
Associations associations, ApplicationContext applicationContext, DataRestRouterOperationService dataRestRouterOperationService,
@@ -279,13 +280,13 @@ else if (handlerMapping instanceof BasePathAwareHandlerMapping) {
279280
}
280281

281282
/**
282-
* Gets repository rest controller endpoints.
283+
* Gets Base Path Aware controller endpoints.
283284
*
284-
* @return the repository rest controller endpoints
285+
* @return the Base Path Aware controller endpoints
285286
*/
286287
@Override
287-
public Map<String, Object> getRepositoryRestControllerEndpoints() {
288-
return applicationContext.getBeansWithAnnotation(RepositoryRestController.class);
288+
public Map<String, Object> getBasePathAwareControllerEndpoints() {
289+
return applicationContext.getBeansWithAnnotation(BasePathAwareController.class);
289290
}
290291

291292
/**
@@ -299,7 +300,7 @@ public Map getHandlerMethods() {
299300
return handlerMappingList.stream().filter(RequestMappingInfoHandlerMapping.class::isInstance)
300301
.flatMap(
301302
handler -> ((RequestMappingInfoHandlerMapping) handler).getHandlerMethods().entrySet().stream())
302-
.filter(entry -> !entry.getValue().getBeanType().getName().startsWith(SPRING_DATA_REST_PACKAGE) && AnnotatedElementUtils.hasAnnotation(entry.getValue().getBeanType(), RepositoryRestController.class))
303+
.filter(entry -> !entry.getValue().getBeanType().getName().startsWith(SPRING_DATA_REST_PACKAGE) && AnnotatedElementUtils.hasAnnotation(entry.getValue().getBeanType(), BasePathAwareController.class))
303304
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
304305
}
305306

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
*
3+
* *
4+
* * *
5+
* * * * Copyright 2019-2020 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+
24+
package test.org.springdoc.api.app29;
25+
26+
import javax.persistence.Entity;
27+
import javax.persistence.GeneratedValue;
28+
import javax.persistence.GenerationType;
29+
import javax.persistence.Id;
30+
31+
@Entity
32+
public class Person {
33+
34+
@Id
35+
@GeneratedValue(strategy = GenerationType.AUTO)
36+
private long id;
37+
38+
private String firstName;
39+
private String lastName;
40+
41+
public String getFirstName() {
42+
return firstName;
43+
}
44+
45+
public void setFirstName(String firstName) {
46+
this.firstName = firstName;
47+
}
48+
49+
public String getLastName() {
50+
return lastName;
51+
}
52+
53+
public void setLastName(String lastName) {
54+
this.lastName = lastName;
55+
}
56+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
*
3+
* *
4+
* * *
5+
* * * * Copyright 2019-2020 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+
24+
package test.org.springdoc.api.app29;
25+
26+
import org.springframework.data.rest.webmvc.BasePathAwareController;
27+
import org.springframework.web.bind.annotation.GetMapping;
28+
29+
@BasePathAwareController
30+
public class PersonApi {
31+
32+
@GetMapping("/people/test")
33+
public Person test() {
34+
return new Person();
35+
}
36+
37+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
*
3+
* *
4+
* * *
5+
* * * * Copyright 2019-2020 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+
24+
package test.org.springdoc.api.app29;
25+
26+
import org.springframework.data.repository.PagingAndSortingRepository;
27+
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
28+
29+
@RepositoryRestResource(path = "people", collectionResourceRel = "people")
30+
public interface PersonRepository extends PagingAndSortingRepository<Person, Long> {
31+
32+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
*
3+
* *
4+
* * *
5+
* * * * Copyright 2019-2020 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+
24+
package test.org.springdoc.api.app29;
25+
26+
import test.org.springdoc.api.AbstractSpringDocTest;
27+
28+
import org.springframework.boot.autoconfigure.SpringBootApplication;
29+
30+
public class SpringDocApp29Test extends AbstractSpringDocTest {
31+
32+
@SpringBootApplication
33+
static class SpringDocTestApp {}
34+
35+
}

0 commit comments

Comments
 (0)