1 package cn.home1.oss.lib.swagger.model;
2
3 import static com.google.common.base.Strings.isNullOrEmpty;
4 import static com.google.common.collect.Lists.newArrayList;
5
6 import com.fasterxml.classmate.TypeResolver;
7
8 import lombok.Builder;
9 import lombok.Data;
10
11 import springfox.documentation.builders.ParameterBuilder;
12 import springfox.documentation.schema.ModelRef;
13 import springfox.documentation.service.AllowableListValues;
14 import springfox.documentation.service.Parameter;
15
16 import java.util.List;
17
18
19
20
21
22 @Data
23 @Builder
24 public class ApiRequest {
25
26 List<Parameter> parameters;
27
28
29
30
31 public ApiRequest addParameter(final String name, final String description, final boolean required) {
32 return addParameter(name, description, null, required, false);
33 }
34
35 public ApiRequest addParameter(
36 final String name,
37 final String description,
38 final String defaultValue,
39 final boolean required,
40 final boolean allowableValues
41 ) {
42 if (this.parameters == null) {
43 this.setParameters(newArrayList());
44 }
45 this.getParameters().add(new ParameterBuilder()
46 .name(name)
47 .description(description)
48 .defaultValue(defaultValue)
49 .required(required)
50 .allowMultiple(false)
51 .type(new TypeResolver().resolve(String.class))
52 .modelRef(new ModelRef("string"))
53 .allowableValues(!isNullOrEmpty(defaultValue)
54 ? new AllowableListValues(newArrayList(defaultValue), "string") : null)
55 .parameterType("query")
56 .build());
57 return this;
58 }
59 }