Skip to content

Commit d693216

Browse files
author
bnasslahsen
committed
Servers OpenAPI block resets after customizing with GroupedOpenApi. Fixes #695
1 parent 5b033f0 commit d693216

File tree

7 files changed

+43
-91
lines changed

7 files changed

+43
-91
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public static void addHiddenRestControllers(String... classes) {
145145
hiddenClasses.add(Class.forName(aClass));
146146
}
147147
catch (ClassNotFoundException e) {
148-
LOGGER.warn("The following class doesn't exist and cannot be hidden: " + aClass);
148+
LOGGER.warn("The following class doesn't exist and cannot be hidden: {}", aClass);
149149
}
150150
}
151151
HIDDEN_REST_CONTROLLERS.addAll(hiddenClasses);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ static BeanFactoryPostProcessor springdocBeanFactoryPostProcessor() {
194194
@ConditionalOnMissingClass(value = BINDRESULT_CLASS)
195195
@Lazy(false)
196196
static BeanFactoryPostProcessor springdocBeanFactoryPostProcessor2() {
197-
return beanFactory -> SpringdocBeanFactoryConfigurer.initBeanFactoryPostProcessor(beanFactory);
197+
return SpringdocBeanFactoryConfigurer::initBeanFactoryPostProcessor;
198198
}
199199

200200
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828

2929
import io.swagger.v3.oas.models.OpenAPI;
3030

31-
import org.springframework.beans.BeansException;
3231
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
3332
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
3433
import org.springframework.boot.context.properties.bind.BindResult;
@@ -52,7 +51,7 @@ public void setEnvironment(Environment environment) {
5251
}
5352

5453
@Override
55-
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
54+
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
5655
final BindResult<SpringDocConfigProperties> result = Binder.get(environment)
5756
.bind(SPRINGDOC_PREFIX, SpringDocConfigProperties.class);
5857
if (result.isBound()) {

springdoc-openapi-common/src/main/java/org/springdoc/core/converters/models/DefaultPageable.java

Lines changed: 2 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -21,92 +21,13 @@
2121
package org.springdoc.core.converters.models;
2222

2323
import java.util.List;
24-
import java.util.Objects;
2524

26-
import javax.validation.constraints.Min;
27-
28-
import io.swagger.v3.oas.annotations.Parameter;
29-
import io.swagger.v3.oas.annotations.media.ArraySchema;
30-
import io.swagger.v3.oas.annotations.media.Schema;
3125
import org.springdoc.api.annotations.ParameterObject;
3226

3327
@ParameterObject
34-
public class DefaultPageable {
35-
36-
@Min(0)
37-
@Parameter(description = "Zero-based page index (0..N)", schema = @Schema(type = "integer", defaultValue = "0"))
38-
private Integer page;
39-
40-
@Min(1)
41-
@Parameter(description = "The size of the page to be returned", schema = @Schema(type = "integer", defaultValue = "20"))
42-
private Integer size;
43-
44-
@Parameter(description = "Sorting criteria in the format: property(,asc|desc). "
45-
+ "Default sort order is ascending. " + "Multiple sort criteria are supported."
46-
, name = "sort"
47-
, array = @ArraySchema(schema = @Schema(type = "string")))
48-
private List<String> sort;
28+
public class DefaultPageable extends Pageable {
4929

5030
public DefaultPageable(int page, int size, List<String> sort) {
51-
this.page = page;
52-
this.size = size;
53-
this.sort = sort;
54-
}
55-
56-
public Integer getPage() {
57-
return page;
58-
}
59-
60-
public void setPage(Integer page) {
61-
this.page = page;
62-
}
63-
64-
public Integer getSize() {
65-
return size;
66-
}
67-
68-
public void setSize(Integer size) {
69-
this.size = size;
70-
}
71-
72-
public List<String> getSort() {
73-
return sort;
74-
}
75-
76-
public void setSort(List<String> sort) {
77-
if (sort == null) {
78-
this.sort.clear();
79-
}
80-
else {
81-
this.sort = sort;
82-
}
83-
}
84-
85-
public void addSort(String sort) {
86-
this.sort.add(sort);
87-
}
88-
89-
@Override
90-
public boolean equals(Object o) {
91-
if (this == o) return true;
92-
if (o == null || getClass() != o.getClass()) return false;
93-
DefaultPageable pageable = (DefaultPageable) o;
94-
return Objects.equals(page, pageable.page) &&
95-
Objects.equals(size, pageable.size) &&
96-
Objects.equals(sort, pageable.sort);
97-
}
98-
99-
@Override
100-
public int hashCode() {
101-
return Objects.hash(page, size, sort);
102-
}
103-
104-
@Override
105-
public String toString() {
106-
return "Pageable{" +
107-
"page=" + page +
108-
", size=" + size +
109-
", sort=" + sort +
110-
'}';
31+
super(page, size, sort);
11132
}
11233
}

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020

2121
package org.springdoc.core.fn;
2222

23+
import java.util.Arrays;
2324
import java.util.Map;
25+
import java.util.Objects;
2426

2527
import io.swagger.v3.oas.annotations.Operation;
2628
import org.apache.commons.lang3.ArrayUtils;
@@ -182,4 +184,33 @@ public int compareTo(RouterOperation routerOperation) {
182184
result = operation.operationId().compareTo(routerOperation.getOperation().operationId());
183185
return result;
184186
}
187+
188+
@Override
189+
public boolean equals(Object o) {
190+
if (this == o) return true;
191+
if (o == null || getClass() != o.getClass()) return false;
192+
RouterOperation that = (RouterOperation) o;
193+
return Objects.equals(path, that.path) &&
194+
Arrays.equals(methods, that.methods) &&
195+
Arrays.equals(consumes, that.consumes) &&
196+
Arrays.equals(produces, that.produces) &&
197+
Arrays.equals(headers, that.headers) &&
198+
Objects.equals(beanClass, that.beanClass) &&
199+
Objects.equals(beanMethod, that.beanMethod) &&
200+
Arrays.equals(parameterTypes, that.parameterTypes) &&
201+
Objects.equals(queryParams, that.queryParams) &&
202+
Objects.equals(operation, that.operation) &&
203+
Objects.equals(operationModel, that.operationModel);
204+
}
205+
206+
@Override
207+
public int hashCode() {
208+
int result = Objects.hash(path, beanClass, beanMethod, queryParams, operation, operationModel);
209+
result = 31 * result + Arrays.hashCode(methods);
210+
result = 31 * result + Arrays.hashCode(consumes);
211+
result = 31 * result + Arrays.hashCode(produces);
212+
result = 31 * result + Arrays.hashCode(headers);
213+
result = 31 * result + Arrays.hashCode(parameterTypes);
214+
return result;
215+
}
185216
}

springdoc-openapi-hateoas/src/main/java/org/springdoc/hateoas/converters/CollectionModelContentConverter.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.fasterxml.jackson.core.JsonGenerator;
2727
import com.fasterxml.jackson.databind.SerializerProvider;
2828
import com.fasterxml.jackson.databind.type.CollectionType;
29+
import com.fasterxml.jackson.databind.type.TypeBindings;
2930
import io.swagger.v3.core.converter.AnnotatedType;
3031
import io.swagger.v3.core.converter.ModelConverter;
3132
import io.swagger.v3.core.converter.ModelConverterContext;
@@ -35,6 +36,7 @@
3536

3637
import org.springframework.hateoas.EntityModel;
3738
import org.springframework.hateoas.server.LinkRelationProvider;
39+
import org.springframework.util.CollectionUtils;
3840

3941
/**
4042
* Override resolved schema as there is a custom serializer that converts the data to a map before serializing it.
@@ -69,11 +71,10 @@ public Schema<?> resolve(AnnotatedType type, ModelConverterContext context, Iter
6971

7072
private Class<?> getEntityType(AnnotatedType type) {
7173
Class<?> containerEntityType = ((CollectionType) (type.getType())).getContentType().getRawClass();
72-
73-
if(((CollectionType) type.getType()).getContentType().getBindings().getTypeParameters().size()==0)
74-
return containerEntityType;
7574
if (containerEntityType.isAssignableFrom(EntityModel.class)) {
76-
return ((CollectionType) type.getType()).getContentType().getBindings().getBoundType(0).getRawClass();
75+
TypeBindings typeBindings = ((CollectionType) type.getType()).getContentType().getBindings() ;
76+
if (!CollectionUtils.isEmpty(typeBindings.getTypeParameters()))
77+
return typeBindings.getBoundType(0).getRawClass();
7778
}
7879
return containerEntityType;
7980
}

springdoc-openapi-webmvc-core/src/main/java/org/springdoc/webmvc/api/OpenApiResource.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ protected void getPaths(Map<String, Object> restControllers) {
158158
.ifPresent(routerBeans -> routerBeans.forEach(this::getRouterFunctionPaths)));
159159

160160
if(repositoryRestResourceProvider.isPresent()){
161-
RepositoryRestResourceProvider repositoryRestResourceProvider = this.repositoryRestResourceProvider.get();
162-
List<RouterOperation> operationList = repositoryRestResourceProvider.getRouterOperations(openAPIBuilder.getCalculatedOpenAPI());
161+
RepositoryRestResourceProvider restResourceProvider = this.repositoryRestResourceProvider.get();
162+
List<RouterOperation> operationList = restResourceProvider.getRouterOperations(openAPIBuilder.getCalculatedOpenAPI());
163163
calculatePath(operationList);
164164
}
165165
}

0 commit comments

Comments
 (0)