Skip to content

Commit a6228a3

Browse files
committed
Merge branch 'ParkerM-repro/rest-enum-array-param'
2 parents 78e136e + b892f35 commit a6228a3

File tree

13 files changed

+332
-22
lines changed

13 files changed

+332
-22
lines changed

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<parent>
1212
<groupId>org.springframework.boot</groupId>
1313
<artifactId>spring-boot-starter-parent</artifactId>
14-
<version>2.7.5</version>
14+
<version>2.7.6</version>
1515
</parent>
1616

1717
<licenses>

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

-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
import io.swagger.v3.oas.models.Paths;
6767
import io.swagger.v3.oas.models.media.StringSchema;
6868
import io.swagger.v3.oas.models.parameters.Parameter;
69-
import io.swagger.v3.oas.models.parameters.PathParameter;
7069
import io.swagger.v3.oas.models.responses.ApiResponses;
7170
import io.swagger.v3.oas.models.servers.Server;
7271
import org.apache.commons.lang3.ArrayUtils;

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

-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
import org.apache.commons.lang3.StringUtils;
5656
import org.slf4j.Logger;
5757
import org.slf4j.LoggerFactory;
58-
import org.springdoc.core.converters.AdditionalModelsConverter;
5958
import org.springdoc.core.providers.JavadocProvider;
6059
import org.springdoc.core.providers.ObjectMapperProvider;
6160

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

-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
package org.springdoc.core;
2323

2424

25-
import java.util.Collection;
26-
2725
import org.springframework.boot.autoconfigure.condition.AnyNestedCondition;
2826
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
2927
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;

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

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
package org.springdoc.core;
2424

2525
import java.lang.annotation.Annotation;
26-
import java.math.BigDecimal;
2726
import java.util.function.Predicate;
2827

2928
import io.swagger.v3.oas.models.media.Schema;

springdoc-openapi-data-rest/src/main/java/org/springdoc/data/rest/core/DataRestOperationService.java

+39-11
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import java.lang.reflect.Field;
2626
import java.lang.reflect.Method;
27+
import java.lang.reflect.Type;
2728
import java.util.Arrays;
2829

2930
import io.swagger.v3.oas.annotations.enums.ParameterIn;
@@ -39,6 +40,7 @@
3940
import org.springdoc.core.SpringDocAnnotationsUtils;
4041

4142
import org.springframework.core.MethodParameter;
43+
import org.springframework.core.ResolvableType;
4244
import org.springframework.core.annotation.AnnotatedElementUtils;
4345
import org.springframework.data.repository.query.Param;
4446
import org.springframework.data.rest.core.mapping.MethodResourceMapping;
@@ -54,6 +56,7 @@
5456

5557
/**
5658
* The type Data rest operation builder.
59+
*
5760
* @author bnasslahsen
5861
*/
5962
public class DataRestOperationService {
@@ -202,17 +205,8 @@ private Operation buildSearchOperation(HandlerMethod handlerMethod, DataRestRepo
202205
String pName = parameterMetadatum.getName();
203206
ResourceDescription description = parameterMetadatum.getDescription();
204207
if (description instanceof TypedResourceDescription) {
205-
TypedResourceDescription typedResourceDescription = (TypedResourceDescription) description;
206-
Field fieldType = FieldUtils.getField(TypedResourceDescription.class, "type", true);
207-
Class<?> type;
208-
try {
209-
type = (Class<?>) fieldType.get(typedResourceDescription);
210-
}
211-
catch (IllegalAccessException e) {
212-
LOGGER.warn(e.getMessage());
213-
type = String.class;
214-
}
215-
Schema<?> schema = SpringDocAnnotationsUtils.resolveSchemaFromType(type, openAPI.getComponents(), null, null);
208+
Type type = getParameterType(pName,method,description);
209+
Schema<?> schema = SpringDocAnnotationsUtils.extractSchema(openAPI.getComponents(), type, null, null);
216210
Parameter parameter = getParameterFromAnnotations(openAPI, methodAttributes, method, pName);
217211
if (parameter == null)
218212
parameter = new Parameter().name(pName).in(ParameterIn.QUERY.toString()).schema(schema);
@@ -231,6 +225,39 @@ private Operation buildSearchOperation(HandlerMethod handlerMethod, DataRestRepo
231225
return operation;
232226
}
233227

228+
/**
229+
* Gets parameter type.
230+
*
231+
* @param pName the p name
232+
* @param method the method
233+
* @param description the description
234+
* @return the parameter type
235+
*/
236+
private Type getParameterType(String pName, Method method, ResourceDescription description) {
237+
Type type = null;
238+
java.lang.reflect.Parameter[] parameters = method.getParameters();
239+
for (int i = 0; i < parameters.length; i++) {
240+
java.lang.reflect.Parameter parameter = parameters[i];
241+
if (pName.equals(parameter.getName()) || pName.equals(parameter.getAnnotation(Param.class).value())) {
242+
ResolvableType resolvableType = ResolvableType.forMethodParameter(method, i);
243+
type = resolvableType.getType();
244+
break;
245+
}
246+
}
247+
if (type == null) {
248+
TypedResourceDescription typedResourceDescription = (TypedResourceDescription) description;
249+
Field fieldType = FieldUtils.getField(TypedResourceDescription.class, "type", true);
250+
try {
251+
type = (Type) fieldType.get(typedResourceDescription);
252+
}
253+
catch (IllegalAccessException e) {
254+
LOGGER.warn(e.getMessage());
255+
type = String.class;
256+
}
257+
}
258+
return type;
259+
}
260+
234261
/**
235262
* Update parameter from annotations parameter.
236263
*
@@ -279,6 +306,7 @@ private Operation initOperation(HandlerMethod handlerMethod, Class<?> domainType
279306

280307
/**
281308
* Add operation description.
309+
*
282310
* @param operation the operation
283311
* @param requestMethod the request method
284312
* @param entity the entity
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
*
3+
* * Copyright 2019-2022 the original author or authors.
4+
* *
5+
* * Licensed under the Apache License, Version 2.0 (the "License");
6+
* * you may not use this file except in compliance with the License.
7+
* * You may obtain a copy of the License at
8+
* *
9+
* * https://www.apache.org/licenses/LICENSE-2.0
10+
* *
11+
* * Unless required by applicable law or agreed to in writing, software
12+
* * distributed under the License is distributed on an "AS IS" BASIS,
13+
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* * See the License for the specific language governing permissions and
15+
* * limitations under the License.
16+
*
17+
*/
18+
19+
package test.org.springdoc.api.app36;
20+
21+
import javax.persistence.Entity;
22+
import javax.persistence.GeneratedValue;
23+
import javax.persistence.Id;
24+
25+
@Entity
26+
public class EnumFieldHolder {
27+
28+
public enum EnumField {
29+
30+
FOO, BAR;
31+
32+
}
33+
34+
@Id
35+
@GeneratedValue
36+
private Long id;
37+
38+
private EnumField enumField;
39+
40+
public Long getId() {
41+
return id;
42+
}
43+
44+
public EnumField getEnumField() {
45+
return enumField;
46+
}
47+
48+
public void setEnumField(EnumField enumField) {
49+
this.enumField = enumField;
50+
}
51+
52+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
*
3+
* * Copyright 2019-2022 the original author or authors.
4+
* *
5+
* * Licensed under the Apache License, Version 2.0 (the "License");
6+
* * you may not use this file except in compliance with the License.
7+
* * You may obtain a copy of the License at
8+
* *
9+
* * https://www.apache.org/licenses/LICENSE-2.0
10+
* *
11+
* * Unless required by applicable law or agreed to in writing, software
12+
* * distributed under the License is distributed on an "AS IS" BASIS,
13+
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* * See the License for the specific language governing permissions and
15+
* * limitations under the License.
16+
*
17+
*/
18+
19+
package test.org.springdoc.api.app36;
20+
21+
import java.util.List;
22+
23+
import org.springframework.data.repository.Repository;
24+
import org.springframework.data.repository.query.Param;
25+
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
26+
import org.springframework.data.util.Streamable;
27+
28+
@RepositoryRestResource
29+
public interface EnumFieldHolderRepository extends Repository<EnumFieldHolder, Long> {
30+
31+
Streamable<EnumFieldHolder> findAllByEnumField(@Param("enumField") EnumFieldHolder.EnumField enumField);
32+
33+
Streamable<EnumFieldHolder> findAllByEnumFieldIn(@Param("enumFields") List<EnumFieldHolder.EnumField> enumFields);
34+
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
*
3+
* * Copyright 2019-2022 the original author or authors.
4+
* *
5+
* * Licensed under the Apache License, Version 2.0 (the "License");
6+
* * you may not use this file except in compliance with the License.
7+
* * You may obtain a copy of the License at
8+
* *
9+
* * https://www.apache.org/licenses/LICENSE-2.0
10+
* *
11+
* * Unless required by applicable law or agreed to in writing, software
12+
* * distributed under the License is distributed on an "AS IS" BASIS,
13+
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* * See the License for the specific language governing permissions and
15+
* * limitations under the License.
16+
*
17+
*/
18+
19+
package test.org.springdoc.api.app36;
20+
21+
import test.org.springdoc.api.AbstractSpringDocTest;
22+
23+
import org.springframework.boot.autoconfigure.SpringBootApplication;
24+
25+
public class SpringDocApp36Test extends AbstractSpringDocTest {
26+
27+
@SpringBootApplication
28+
static class SpringDocTestApp {
29+
30+
}
31+
32+
}

0 commit comments

Comments
 (0)