예제 #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));
    }
  }
예제 #2
0
  private void buildExamples(JavaMethod javaMethod, MethodDocument document) {
    final DocletTag[] exampleTitles = javaMethod.getTagsByName("example.title");
    final DocletTag[] exampleDescriptions = javaMethod.getTagsByName("example.description");
    final DocletTag[] exampleRequests = javaMethod.getTagsByName("example.request");
    final DocletTag[] exampleRequestsContentType =
        javaMethod.getTagsByName("example.requestContentType");
    final DocletTag[] exampleResponses = javaMethod.getTagsByName("example.response");
    final DocletTag[] exampleResponsesContentType =
        javaMethod.getTagsByName("example.responseContentType");

    if ((exampleTitles.length != exampleDescriptions.length)
        || (exampleTitles.length != exampleRequests.length)
        || (exampleTitles.length != exampleRequestsContentType.length)
        || (exampleTitles.length != exampleResponses.length)
        || (exampleTitles.length != exampleResponsesContentType.length)) {
      LOG.error(
          "Unable to build examples. The number of tags "
              + "example/title,description,request,requestContentType,response,responseContentType "
              + "must be equal.");
      return;
    }

    List<ApiExampleDocument> examples = new ArrayList<ApiExampleDocument>();
    for (int i = 0; i < exampleTitles.length; i++) {
      ApiExampleDocument example =
          new ApiExampleDocument(
              exampleTitles[i].getValue(),
              exampleDescriptions[i].getValue(),
              exampleRequests[i].getValue(),
              exampleRequestsContentType[i].getValue(),
              exampleResponses[i].getValue(),
              exampleResponsesContentType[i].getValue());
      LOG.info("Added new example for {}: {}", document.getPath(), example);
      examples.add(example);
    }

    document.setExampleDocuments(ImmutableList.copyOf(examples));
  }