Skip to content

Commit

Permalink
Add support for BasePathAwareController. Fixes #1383
Browse files Browse the repository at this point in the history
  • Loading branch information
bnasslahsen committed Dec 14, 2021
1 parent ebec205 commit b2fecd1
Show file tree
Hide file tree
Showing 8 changed files with 697 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ public interface RepositoryRestResourceProvider {
List<RouterOperation> getRouterOperations(OpenAPI openAPI, Locale locale);

/**
* Gets repository rest controller endpoints.
* Gets Base PathAwar eController endpoints.
*
* @return the repository rest controller endpoints
* @return the Base PathAware Controller endpoints
*/
Map<String, Object> getRepositoryRestControllerEndpoints();
Map<String, Object> getBasePathAwareControllerEndpoints();

/**
* Gets handler methods.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@
import org.springframework.data.rest.core.mapping.ResourceMappings;
import org.springframework.data.rest.core.mapping.ResourceMetadata;
import org.springframework.data.rest.core.mapping.SearchResourceMappings;
import org.springframework.data.rest.webmvc.BasePathAwareController;
import org.springframework.data.rest.webmvc.BasePathAwareHandlerMapping;
import org.springframework.data.rest.webmvc.ProfileController;
import org.springframework.data.rest.webmvc.RepositoryRestController;
import org.springframework.data.rest.webmvc.RepositoryRestHandlerMapping;
import org.springframework.data.rest.webmvc.alps.AlpsController;
import org.springframework.data.rest.webmvc.json.JacksonMetadata;
Expand Down Expand Up @@ -187,6 +187,7 @@ public class SpringRepositoryRestResourceProvider implements RepositoryRestResou
* @param dataRestRouterOperationService the data rest router operation builder
* @param persistentEntities the persistent entities
* @param mapper the mapper
* @param springDocDataRestUtils the spring doc data rest utils
*/
public SpringRepositoryRestResourceProvider(ResourceMappings mappings, Repositories repositories,
Associations associations, ApplicationContext applicationContext, DataRestRouterOperationService dataRestRouterOperationService,
Expand Down Expand Up @@ -279,13 +280,13 @@ else if (handlerMapping instanceof BasePathAwareHandlerMapping) {
}

/**
* Gets repository rest controller endpoints.
* Gets Base Path Aware controller endpoints.
*
* @return the repository rest controller endpoints
* @return the Base Path Aware controller endpoints
*/
@Override
public Map<String, Object> getRepositoryRestControllerEndpoints() {
return applicationContext.getBeansWithAnnotation(RepositoryRestController.class);
public Map<String, Object> getBasePathAwareControllerEndpoints() {
return applicationContext.getBeansWithAnnotation(BasePathAwareController.class);
}

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
*
* *
* * *
* * * * Copyright 2019-2020 the original author or authors.
* * * *
* * * * Licensed under the Apache License, Version 2.0 (the "License");
* * * * you may not use this file except in compliance with the License.
* * * * You may obtain a copy of the License at
* * * *
* * * * https://www.apache.org/licenses/LICENSE-2.0
* * * *
* * * * Unless required by applicable law or agreed to in writing, software
* * * * distributed under the License is distributed on an "AS IS" BASIS,
* * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * * * See the License for the specific language governing permissions and
* * * * limitations under the License.
* * *
* *
*
*
*/

package test.org.springdoc.api.app29;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

@Entity
public class Person {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;

private String firstName;
private String lastName;

public String getFirstName() {
return firstName;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}

public String getLastName() {
return lastName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
*
* *
* * *
* * * * Copyright 2019-2020 the original author or authors.
* * * *
* * * * Licensed under the Apache License, Version 2.0 (the "License");
* * * * you may not use this file except in compliance with the License.
* * * * You may obtain a copy of the License at
* * * *
* * * * https://www.apache.org/licenses/LICENSE-2.0
* * * *
* * * * Unless required by applicable law or agreed to in writing, software
* * * * distributed under the License is distributed on an "AS IS" BASIS,
* * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * * * See the License for the specific language governing permissions and
* * * * limitations under the License.
* * *
* *
*
*
*/

package test.org.springdoc.api.app29;

import org.springframework.data.rest.webmvc.BasePathAwareController;
import org.springframework.web.bind.annotation.GetMapping;

@BasePathAwareController
public class PersonApi {

@GetMapping("/people/test")
public Person test() {
return new Person();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
*
* *
* * *
* * * * Copyright 2019-2020 the original author or authors.
* * * *
* * * * Licensed under the Apache License, Version 2.0 (the "License");
* * * * you may not use this file except in compliance with the License.
* * * * You may obtain a copy of the License at
* * * *
* * * * https://www.apache.org/licenses/LICENSE-2.0
* * * *
* * * * Unless required by applicable law or agreed to in writing, software
* * * * distributed under the License is distributed on an "AS IS" BASIS,
* * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * * * See the License for the specific language governing permissions and
* * * * limitations under the License.
* * *
* *
*
*
*/

package test.org.springdoc.api.app29;

import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;

@RepositoryRestResource(path = "people", collectionResourceRel = "people")
public interface PersonRepository extends PagingAndSortingRepository<Person, Long> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
*
* *
* * *
* * * * Copyright 2019-2020 the original author or authors.
* * * *
* * * * Licensed under the Apache License, Version 2.0 (the "License");
* * * * you may not use this file except in compliance with the License.
* * * * You may obtain a copy of the License at
* * * *
* * * * https://www.apache.org/licenses/LICENSE-2.0
* * * *
* * * * Unless required by applicable law or agreed to in writing, software
* * * * distributed under the License is distributed on an "AS IS" BASIS,
* * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * * * See the License for the specific language governing permissions and
* * * * limitations under the License.
* * *
* *
*
*
*/

package test.org.springdoc.api.app29;

import test.org.springdoc.api.AbstractSpringDocTest;

import org.springframework.boot.autoconfigure.SpringBootApplication;

public class SpringDocApp29Test extends AbstractSpringDocTest {

@SpringBootApplication
static class SpringDocTestApp {}

}
Loading

0 comments on commit b2fecd1

Please sign in to comment.