Skip to content

Commit 9cb0ea0

Browse files
committed
Fixed the expanded parameter plugin
Currently the swagger plugin that overlays on top of the un-annotated property incorrectly also tries to set the model ref. Rather than duplicate the behavior from the vanila plugin, we simply ignore attributes not infered from the @ApiModelProperty and @ApiParam annotations fixes springfox#1317
1 parent b838cce commit 9cb0ea0

File tree

2 files changed

+3
-23
lines changed

2 files changed

+3
-23
lines changed

springfox-spring-web/src/main/java/springfox/documentation/spring/web/readers/parameter/ExpandedParameterBuilder.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import java.lang.reflect.ParameterizedType;
4444
import java.lang.reflect.Type;
4545
import java.util.Arrays;
46-
import java.util.Collection;
4746
import java.util.List;
4847

4948
import static com.google.common.base.Strings.*;
@@ -70,11 +69,10 @@ public void apply(ParameterExpansionContext context) {
7069
? context.getField().getName()
7170
: String.format("%s.%s", context.getParentName(), context.getField().getName());
7271

73-
boolean isCollection = isCollection(context.getField().getType());
7472
String typeName = context.getDataTypeName();
7573
ModelReference itemModel = null;
7674
ResolvedType resolved = resolver.resolve(context.getField().getType());
77-
if (isCollection) {
75+
if (isContainerType(resolved)) {
7876
resolved = fieldType(context).or(resolved);
7977
ResolvedType elementType = collectionElementType(resolved);
8078
String itemTypeName = typeNameFor(elementType.getErasedType());
@@ -91,7 +89,7 @@ public void apply(ParameterExpansionContext context) {
9189
.description(null)
9290
.defaultValue(null)
9391
.required(Boolean.FALSE)
94-
.allowMultiple(isCollection)
92+
.allowMultiple(isContainerType(resolved))
9593
.type(resolved)
9694
.modelRef(new ModelRef(typeName, itemModel))
9795
.allowableValues(allowable)
@@ -132,10 +130,6 @@ private AllowableValues allowableValues(final Field field) {
132130
return allowable;
133131
}
134132

135-
private boolean isCollection(Class<?> fieldType) {
136-
return Collection.class.isAssignableFrom(fieldType) || fieldType.isArray();
137-
}
138-
139133
private List<String> getEnumValues(final Class<?> subject) {
140134
return transform(Arrays.asList(subject.getEnumConstants()), new Function<Object, String>() {
141135
@Override

springfox-swagger-common/src/main/java/springfox/documentation/swagger/readers/parameter/SwaggerExpandedParameterBuilder.java

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import io.swagger.annotations.ApiParam;
2626
import org.springframework.core.annotation.Order;
2727
import org.springframework.stereotype.Component;
28-
import springfox.documentation.schema.ModelRef;
2928
import springfox.documentation.service.AllowableListValues;
3029
import springfox.documentation.service.AllowableValues;
3130
import springfox.documentation.spi.DocumentationType;
@@ -68,36 +67,23 @@ public boolean supports(DocumentationType delimiter) {
6867
private void fromApiParam(ParameterExpansionContext context, ApiParam apiParam) {
6968
String allowableProperty = emptyToNull(apiParam.allowableValues());
7069
AllowableValues allowable = allowableValues(fromNullable(allowableProperty), context.getField());
71-
String name = isNullOrEmpty(context.getParentName())
72-
? context.getField().getName()
73-
: String.format("%s.%s", context.getParentName(), context.getField().getName());
7470
context.getParameterBuilder()
75-
.name(name)
7671
.description(apiParam.value())
7772
.defaultValue(apiParam.defaultValue())
7873
.required(apiParam.required())
7974
.allowMultiple(apiParam.allowMultiple())
80-
.modelRef(new ModelRef(context.getDataTypeName()))
8175
.allowableValues(allowable)
82-
.parameterType("query")
8376
.parameterAccess(apiParam.access())
8477
.build();
8578
}
8679

8780
private void fromApiModelProperty(ParameterExpansionContext context, ApiModelProperty apiModelProperty) {
8881
String allowableProperty = emptyToNull(apiModelProperty.allowableValues());
8982
AllowableValues allowable = allowableValues(fromNullable(allowableProperty), context.getField());
90-
String name = isNullOrEmpty(context.getParentName()) ? context.getField().getName() : String.format("%s.%s",
91-
context.getParentName(),
92-
context.getField().getName());
9383
context.getParameterBuilder()
94-
.name(name)
9584
.description(apiModelProperty.value())
96-
.defaultValue(null)
9785
.required(apiModelProperty.required())
98-
.allowMultiple(Boolean.FALSE)
99-
.modelRef(new ModelRef(context.getDataTypeName()))
100-
.allowableValues(allowable).parameterType("query")
86+
.allowableValues(allowable)
10187
.parameterAccess(apiModelProperty.access())
10288
.build();
10389
}

0 commit comments

Comments
 (0)