Example #1
0
  private void buildResponseErrors(Method method, MethodDocument document, JavaMethod javaMethod) {
    final DocletTag[] errorStatuses = javaMethod.getTagsByName("error.status");
    final DocletTag[] errorCauses = javaMethod.getTagsByName("error.cause");
    int totalErrors = errorCauses.length;
    if (errorStatuses.length != errorCauses.length) {
      LOG.warn(
          "For method {}, the number of tags @error.status is different than the"
              + " number of tags @error.cause; Because of this, the {} will only use the minimum"
              + " count from the two.",
          method.getName(),
          this.getClass().getName());
      totalErrors = Math.min(errorCauses.length, errorStatuses.length);
    }

    List<ResponseError> errors = new ArrayList<ResponseError>(totalErrors);
    for (int i = 0; i < totalErrors; i++) {
      try {
        errors.add(
            new ResponseError(
                Integer.parseInt(errorStatuses[i].getValue()), errorCauses[i].getValue()));
      } catch (NumberFormatException e) {
        LOG.error("Invalid number for @error.status: " + errorStatuses[i].getValue());
      }
    }

    document.setResponseErrors(ImmutableList.copyOf(errors));
  }
Example #2
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));
    }
  }