Skip to content

Commit d8a8a99

Browse files
authored
Merge pull request #2035 from swagger-api/issue-889
added type override
2 parents 8eafef8 + 9e8b2c6 commit d8a8a99

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

modules/swagger-annotations/src/main/java/io/swagger/annotations/ApiImplicitParam.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,23 @@
127127
* @return
128128
*/
129129
Example examples() default @Example(value = @ExampleProperty(mediaType = "", value = ""));
130+
131+
/**
132+
* Adds the ability to override the detected type
133+
*
134+
* @since 1.5.11
135+
*
136+
* @return
137+
*/
138+
String type() default "";
139+
140+
/**
141+
* Adds the ability to provide a custom format
142+
*
143+
* @since 1.5.11
144+
*
145+
* @return
146+
*/
147+
String format() default "";
148+
130149
}

modules/swagger-annotations/src/main/java/io/swagger/annotations/ApiParam.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,15 @@
111111
*/
112112
Example examples() default @Example(value = @ExampleProperty(mediaType = "", value = ""));
113113

114+
/**
115+
* Adds the ability to override the detected type
116+
*
117+
* @since 1.5.11
118+
*
119+
* @return
120+
*/
121+
String type() default "";
122+
114123
/**
115124
* Adds the ability to provide a custom format
116125
*

modules/swagger-core/src/main/java/io/swagger/util/ParameterProcessor.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ public static Parameter applyAnnotations(Swagger swagger, Parameter parameter, T
7979
if (helper.isRequired() != null) {
8080
p.setRequired(true);
8181
}
82+
if(helper.getType() != null) {
83+
p.setType(helper.getType());
84+
}
8285
if(helper.getFormat() != null) {
8386
p.setFormat(helper.getFormat());
8487
}
@@ -255,6 +258,8 @@ public interface ParamWrapper<T extends Annotation> {
255258

256259
String getExample();
257260

261+
String getType();
262+
258263
String getFormat();
259264
}
260265

@@ -266,6 +271,7 @@ private static class AnnotationsHelper {
266271
private static final ApiParam DEFAULT_API_PARAM = getDefaultApiParam(null);
267272
private boolean context;
268273
private ParamWrapper<?> apiParam = new ApiParamWrapper(DEFAULT_API_PARAM);
274+
private String type;
269275
private String format;
270276
private String defaultValue;
271277
private Integer minItems;
@@ -307,6 +313,7 @@ public AnnotationsHelper(List<Annotation> annotations) {
307313
}
308314
}
309315
defaultValue = StringUtils.isNotEmpty(apiParam.getDefaultValue()) ? apiParam.getDefaultValue() : rsDefault;
316+
type = StringUtils.isNotEmpty(apiParam.getType()) ? apiParam.getType() : null;
310317
format = StringUtils.isNotEmpty(apiParam.getFormat()) ? apiParam.getFormat() : null;
311318
}
312319

@@ -374,6 +381,10 @@ public Long getMin() {
374381
return min;
375382
}
376383

384+
public String getType() {
385+
return type;
386+
}
387+
377388
public String getFormat() {
378389
return format;
379390
}
@@ -455,6 +466,10 @@ public Example getExamples() {
455466
return apiParam.examples();
456467
}
457468

469+
public String getType() {
470+
return apiParam.type();
471+
}
472+
458473
public String getFormat() {
459474
return apiParam.format();
460475
}
@@ -535,8 +550,12 @@ public Example getExamples() {
535550
return apiParam.examples();
536551
}
537552

553+
public String getType() {
554+
return apiParam.type();
555+
}
556+
538557
public String getFormat() {
539-
return null;
558+
return apiParam.format();
540559
}
541560
}
542561
}

0 commit comments

Comments
 (0)