I had the same problem and I used sth as shown below.
I have a bean that contains a list of possible values generated when the application starts through config. Swagger should show the list, but this will not work.
@GET @Path("info/types") @PermitAll @Produces(MediaType.APPLICATION_JSON) @ApiOperation(value = "Possible bean types", notes = "List all available bean types", response = BeanTypesList.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "List of all available bean types", response = BeanTypesList.class) }) @Timed @ExceptionMetered @CacheControl(maxAge = 6, maxAgeUnit = TimeUnit.HOURS) public List<BeanType> getBeanTypes() throws JsonProcessingException { return new ArrayList<BeanType>(BeanType.values()); }
public class SwaggerClassHelper { @ApiModel(value = "BeanTypesList", description = "Overview of possible bean types") public class BeanTypesList { @ApiModelProperty(value = "List of several possible bean types.", required = true) private List<BeanType> types; @JsonCreator public BeanTypesList( List<BeanType> types) { this.types = types; } public List<BeanType> getTypes() { return this.types; } @JsonIgnore @Override public String toString() { return ReflectionToStringBuilder.toString(this); } } }
@ApiModel(value = "Bean type", description = "Represents the type of a bean.") public final class BeanType { @JsonIgnore private static Set<String> names = new HashSet<String>(); @JsonProperty("name") private String name; private BeanType( List<String> names) { synchronized (BeanType.names) { BeanType.names.addAll(names); } } private BeanType( String name) { this.name = name; }
I know this is not a solution if you use swagger, but you can specify input / output through the response fields!
hiaclibe
source share