@Path("/stats") @Component @Api(value = "/stats", description = "Resource to show stats for a box using sigar") public class StatsResource implements RestResource { @GET @Path("/ping") @Produces("application/json") @ApiOperation(value = "Make a ping call", response = List.class) public List<Integer> getMachineStats() { return ImmutableList.of(1); } }
private String getDescription(HandlerMethod handlerMethod) { Class<?> controllerClass = handlerMethod.getBeanType(); String description = splitCamelCase(controllerClass.getSimpleName(), " "); Api apiAnnotation = AnnotationUtils.findAnnotation(controllerClass, Api.class); if (null != apiAnnotation) { String descriptionFromAnnotation = Optional.fromNullable(emptyToNull(apiAnnotation.value())) .or(apiAnnotation.description()); if (!isNullOrEmpty(descriptionFromAnnotation)) { return descriptionFromAnnotation; } } return description; } }
Api api = classElementIn.getAnnotation(Api.class); if (api!=null) { String shortDescription = api.value(); setOptionalAttribute(classElement, "shortDesc", shortDescription); String longDescription = api.description(); setOptionalAttribute(classElement, "description", longDescription); String basePathAttr = api.basePath(); setOptionalAttribute(classElement, "basePath",basePathAttr);
@Override public Optional<String> apply(Api input) { if (null != input) { String stripSlashes = input.value().replace("/", ""); return Optional.fromNullable(emptyToNull(stripSlashes)); } return Optional.absent(); } };
@Override public Integer getResourcePosition(RequestMappingInfo requestMappingInfo, HandlerMethod handlerMethod) { Class<?> controllerClass = handlerMethod.getBeanType(); Api apiAnnotation = AnnotationUtils.findAnnotation(controllerClass, Api.class); if (null != apiAnnotation && hasText(apiAnnotation.value())) { return apiAnnotation.position(); } return 0; }
@Override public Optional<String> apply(Api input) { if (null != input) { return Optional.fromNullable(emptyToNull(input.description())); } return Optional.absent(); } };
Api controllerApi = controllerClass.getAnnotation(Api.class); if (controllerApi != null) { resourcePath = controllerApi.basePath();
/** * Adds data from the {@link Api} annotation to the resource. * * @param api * The {@link Api} annotation. * @param resource * The {@link Resource} to update. */ public static void processApi(Api api, Resource resource) { if (!StringUtils.isNullOrEmpty(api.value())) { resource.setName(api.value()); } if (!StringUtils.isNullOrEmpty(api.description())) { resource.setDescription(api.description()); } }
@Override public Optional<String> apply(Api input) { if (null != input) { String stripSlashes = input.value().replace("/", ""); return Optional.fromNullable(emptyToNull(stripSlashes)); } return Optional.absent(); } };
@Override public Integer getResourcePosition(RequestMappingInfo requestMappingInfo, HandlerMethod handlerMethod) { Class<?> controllerClass = handlerMethod.getBeanType(); Api apiAnnotation = AnnotationUtils.findAnnotation(controllerClass, Api.class); if (null != apiAnnotation && hasText(apiAnnotation.value())) { return apiAnnotation.position(); } return 0; }
@Override public Optional<String> apply(Api input) { if (null != input) { return Optional.fromNullable(emptyToNull(input.description())); } return Optional.absent(); } };
@Api(value = "messaging", description = "Operations to interact with the asynchronous message queue") public class QueueMessageResource extends RedboxServerResource { @ApiOperation(value = "Queues a message on the specified message queue", tags = "messaging") @ApiResponses({ @ApiResponse(code = 200, message = "The record's metadata is updated"), @ApiResponse(code = 500, message = "General Error", response = Exception.class) }) @Post("json") public String sendMessageToQueue(JsonRepresentation data) throws IOException, MessagingException { MessagingServices ms = MessagingServices.getInstance(); String messageQueue = getAttribute("messageQueue"); String message = data.getText(); ms.queueMessage(messageQueue, message); return getSuccessResponseString(null); } }
/** * Adds data from the {@link Api} annotation to the resource. * * @param api * The {@link Api} annotation. * @param resource * The {@link Resource} to update. */ public static void processApi(Api api, Resource resource) { if (!StringUtils.isNullOrEmpty(api.value())) { resource.setName(api.value()); } if (!StringUtils.isNullOrEmpty(api.description())) { resource.setDescription(api.description()); } }
com.wordnik.swagger.annotations.Api api = resourceClass.getAnnotation(com.wordnik.swagger.annotations.Api.class); if (api != null) { String apiPath = api.value(); String serverAddress = server.getEndpoint().getEndpointInfo().getAddress(); String apiDocs = serverAddress + "/api-docs";
private Map<String, ApiListing> processControllers(Set<Class<?>> controllerClasses) { //Loop over end points (controllers) for (Class<?> controllerClass : controllerClasses) { if (ApiDocumentationController.class.isAssignableFrom(controllerClass)) { continue; } Set<Method> requestMappingMethods = AnnotationUtils.getAnnotatedMethods(controllerClass, RequestMapping.class); ApiListing apiListing = processControllerApi(controllerClass); String description = ""; Api controllerApi = controllerClass.getAnnotation(Api.class); if (controllerApi != null) { description = controllerApi.description(); } if (apiListing.apis().size() == 0) { apiListing = processMethods(requestMappingMethods, controllerClass, apiListing, description); } //Allow for multiple controllers having the same resource path. ApiListing existingApiListing = apiListingMap.get(apiListing.resourcePath()); if (existingApiListing != null) { apiListing = ApiListingUtil.mergeApiListing(existingApiListing, apiListing); } // controllers without any operations are excluded from the apiListingMap list if (apiListing.apis() != null && !apiListing.apis().isEmpty()) { apiListingMap.put(apiListing.resourcePath(), apiListing); } } return apiListingMap; }
@Api(value = "object", description = "Operations on ReDBox Objects") public class DeleteObjectResource extends RedboxServerResource { @ApiOperation(value = "Delete an existing ReDBox object", tags = "object") @ApiResponses({ @ApiResponse(code = 200, message = "The object is deleted"), @ApiResponse(code = 500, message = "General Error", response = Exception.class) }) @Delete public String deleteObjectResource() throws IOException, PluginException, MessagingException { Storage storage = (Storage) ApplicationContextProvider.getApplicationContext().getBean("fascinatorStorage"); Indexer indexer = (Indexer) ApplicationContextProvider.getApplicationContext().getBean("fascinatorIndexer"); String oid = getAttribute("oid"); storage.removeObject(oid); indexer.remove(oid); return getSuccessResponseString(oid); } }
/** * Adds data from the {@link Api} annotation to the resource. * * @param api * The {@link Api} annotation. * @param resource * The {@link Resource} to update. */ public static void processApi(Api api, Resource resource) { if (!StringUtils.isNullOrEmpty(api.value())) { resource.setName(api.value()); } if (!StringUtils.isNullOrEmpty(api.description())) { resource.setDescription(api.description()); } }
throw new SiteWhereException("Swagger Api annotation missing on documented controller."); parsed.setResource(api.value());
/** * @author Lukas Krejci * @since 4.10 */ @Api("Encapsulates a simple boolean value. In XML this is represented as <value value=\"...\"/>") public final class BooleanValue { private boolean value; public BooleanValue() { } public BooleanValue(boolean value) { this.value = value; } public boolean isValue() { return value; } public void setValue(boolean value) { this.value = value; } }
/** * Adds data from the {@link Api} annotation to the resource. * * @param api * The {@link Api} annotation. * @param resource * The {@link Resource} to update. */ public static void processApi(Api api, Resource resource) { if (!StringUtils.isNullOrEmpty(api.value())) { resource.setName(api.value()); } if (!StringUtils.isNullOrEmpty(api.description())) { resource.setDescription(api.description()); } }