use of io.swagger.annotations.ApiResponse in project indy by Commonjava.
the class FoloAdminResource method getRecord.
@ApiOperation("Alias of /{id}/record, returns the tracking record for the specified key")
@ApiResponses({ @ApiResponse(code = 404, message = "No such tracking record exists."), @ApiResponse(code = 200, message = "Tracking record", response = TrackedContentDTO.class) })
@Path("/{id}/record")
@GET
public Response getRecord(@ApiParam("User-assigned tracking session key") @PathParam("id") final String id, @Context final UriInfo uriInfo) {
Response response;
try {
final String baseUrl = uriInfo.getBaseUriBuilder().path("api").build().toString();
final TrackedContentDTO record = controller.getRecord(id, baseUrl);
if (record == null) {
response = Response.status(Status.NOT_FOUND).build();
} else {
response = responseHelper.formatOkResponseWithJsonEntity(record);
}
} catch (final IndyWorkflowException e) {
logger.error(String.format("Failed to retrieve tracking report for: %s. Reason: %s", id, e.getMessage()), e);
response = responseHelper.formatResponse(e);
}
return response;
}
use of io.swagger.annotations.ApiResponse in project graylog2-server by Graylog2.
the class IndexSetsResource method get.
@GET
@Path("{id}")
@Timed
@ApiOperation(value = "Get index set")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Unauthorized"), @ApiResponse(code = 404, message = "Index set not found") })
public IndexSetSummary get(@ApiParam(name = "id", required = true) @PathParam("id") String id) {
checkPermission(RestPermissions.INDEXSETS_READ, id);
final IndexSetConfig defaultIndexSet = indexSetService.getDefault();
return indexSetService.get(id).map(config -> IndexSetSummary.fromIndexSetConfig(config, config.equals(defaultIndexSet))).orElseThrow(() -> new NotFoundException("Couldn't load index set with ID <" + id + ">"));
}
use of io.swagger.annotations.ApiResponse in project graylog2-server by Graylog2.
the class IndexSetsResource method list.
@GET
@Timed
@ApiOperation(value = "Get a list of all index sets")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Unauthorized") })
public IndexSetResponse list(@ApiParam(name = "skip", value = "The number of elements to skip (offset).", required = true) @QueryParam("skip") @DefaultValue("0") int skip, @ApiParam(name = "limit", value = "The maximum number of elements to return.", required = true) @QueryParam("limit") @DefaultValue("0") int limit, @ApiParam(name = "stats", value = "Include index set stats.") @QueryParam("stats") @DefaultValue("false") boolean computeStats) {
final IndexSetConfig defaultIndexSet = indexSetService.getDefault();
List<IndexSetSummary> indexSets;
int count;
if (limit > 0) {
// First collect all index set ids the user is allowed to see.
final Set<String> allowedIds = indexSetService.findAll().stream().filter(indexSet -> isPermitted(RestPermissions.INDEXSETS_READ, indexSet.id())).map(IndexSetConfig::id).collect(Collectors.toSet());
indexSets = indexSetService.findPaginated(allowedIds, limit, skip).stream().map(config -> IndexSetSummary.fromIndexSetConfig(config, config.equals(defaultIndexSet))).collect(Collectors.toList());
count = allowedIds.size();
} else {
indexSets = indexSetService.findAll().stream().filter(indexSetConfig -> isPermitted(RestPermissions.INDEXSETS_READ, indexSetConfig.id())).map(config -> IndexSetSummary.fromIndexSetConfig(config, config.equals(defaultIndexSet))).collect(Collectors.toList());
count = indexSets.size();
}
final Map<String, IndexSetStats> stats;
if (computeStats) {
stats = indexSetRegistry.getAll().stream().collect(Collectors.toMap(indexSet -> indexSet.getConfig().id(), indexSetStatsCreator::getForIndexSet));
} else {
stats = Collections.emptyMap();
}
return IndexSetResponse.create(count, indexSets, stats);
}
use of io.swagger.annotations.ApiResponse in project graylog2-server by Graylog2.
the class Generator method determineResponses.
private List<Map<String, Object>> determineResponses(Method method) {
final List<Map<String, Object>> result = Lists.newArrayList();
final ApiResponses annotation = method.getAnnotation(ApiResponses.class);
if (null != annotation) {
for (ApiResponse response : annotation.value()) {
final Map<String, Object> responseDescription = ImmutableMap.<String, Object>of("code", response.code(), "message", response.message());
result.add(responseDescription);
}
}
return result;
}
use of io.swagger.annotations.ApiResponse in project java-chassis by ServiceComb.
the class MultiErrorCodeService method errorCodeWithHeader.
@Path("/errorCodeWithHeader")
@POST
@ApiResponses({ @ApiResponse(code = 200, response = MultiResponse200.class, message = ""), @ApiResponse(code = 400, response = MultiResponse400.class, message = ""), @ApiResponse(code = 500, response = MultiResponse500.class, message = "") })
@ResponseHeaders({ @ResponseHeader(name = "x-code", response = String.class) })
public Response errorCodeWithHeader(MultiRequest request) {
Response response = new Response();
if (request.getCode() == 400) {
MultiResponse400 r = new MultiResponse400();
r.setCode(400);
r.setMessage("bad request");
response.setStatus(Status.BAD_REQUEST);
// If got many types for different status code, we can only using InvocationException for failed error code like 400-500.
// The result for Failed Family(e.g. 400-500), can not set return value as target type directly or will give exception.
response.setResult(new InvocationException(Status.BAD_REQUEST, r));
response.setHeader("x-code", "400");
} else if (request.getCode() == 500) {
MultiResponse500 r = new MultiResponse500();
r.setCode(500);
r.setMessage("internal error");
response.setStatus(Status.INTERNAL_SERVER_ERROR);
response.setResult(new InvocationException(Status.INTERNAL_SERVER_ERROR, r));
response.setHeader("x-code", "500");
} else {
MultiResponse200 r = new MultiResponse200();
r.setCode(200);
r.setMessage("success result");
response.setStatus(Status.OK);
// If error code is OK family(like 200), we can use the target type.
response.setResult(r);
response.setHeader("x-code", "200");
}
return response;
}
Aggregations