Example #1
0
  @Override
  protected void doWithMethodDocument(MethodDocument document, Method method) {
    ResourceMethod rm = method.getAnnotation(ResourceMethod.class);
    if (rm == null) {
      throw new IllegalArgumentException(
          "Can't generate document unless method is annotated with @ResourceMethod");
    }

    MethodParamProcessor mpp = new MethodParamProcessor();
    mpp.processAnnotations(method, document);

    // --- Process TGIRest annotations
    ResourceMethod resourceMethod = method.getAnnotation(ResourceMethod.class);
    if (resourceMethod != null) {
      document.setDescription(resourceMethod.description());

      document.setResponseErrors(getResponseErrors(resourceMethod));
      // Parse examples.
      document.setExampleDocuments(getExampleDocuments(resourceMethod));
    }
  }
Example #2
0
  /**
   * Gets the error documentation for the resource method annotation.
   *
   * @param resourceMethod Endpoint method to document.
   * @return a list of ResponseErrors in the parameter
   */
  List<ResponseError> getResponseErrors(ResourceMethod resourceMethod) {
    if (null == resourceMethod) return Collections.emptyList();

    final Collection<ResponseError> errors =
        Collections2.transform(
            Arrays.asList(resourceMethod.errors()),
            new Function<MethodError, ResponseError>() {
              @Override
              public ResponseError apply(MethodError from) {
                return new ResponseError(from.status().getStatusCode(), from.cause());
              }
            });

    return ImmutableList.copyOf(errors);
  }
Example #3
0
  List<ApiExampleDocument> getExampleDocuments(ResourceMethod method) {
    if (null == method) return Collections.emptyList();

    final Collection<ApiExampleDocument> documents =
        Collections2.transform(
            Arrays.asList(method.examples()),
            new Function<ApiCallExample, ApiExampleDocument>() {
              @Override
              public ApiExampleDocument apply(ApiCallExample apiCallExample) {
                return new ApiExampleDocument(
                    apiCallExample.title(),
                    apiCallExample.description(),
                    apiCallExample.input(),
                    apiCallExample.contentType(),
                    apiCallExample.output(),
                    apiCallExample.accepts());
              }
            });

    return ImmutableList.copyOf(documents);
  }