Ejemplo n.º 1
0
  private static String generateRequestExmple(final DocHttpMethod httpMethod) {

    List<DocParameter> params = httpMethod.getParams();
    Type type = null;
    for (DocParameter docParameter : params) {
      if (requestBodyParamFilter.filter(httpMethod, docParameter)) {
        type = docParameter.getType();
        break;
      }
    }
    if (type == null) {
      return REQUEST_HAS_NO_BODY_MSG;
    }
    String generateExample = null;
    try {
      generateExample = requestExampleGenerator.generateExample(type);
      generateExample = Utils.getIndentJson(generateExample);
    } catch (Exception e) {
      logger.warning(
          "Could not generate request example for method: "
              + httpMethod.getMethodSignatureName()
              + " with the request parameter type "
              + type.qualifiedTypeName()
              + ". Exception was: "
              + e);
      generateExample =
          RestDocConstants.FAILED_TO_CREATE_REQUEST_EXAMPLE
              + "."
              + LINE_SEPARATOR
              + "Parameter type: "
              + type.qualifiedTypeName()
              + "."
              + LINE_SEPARATOR
              + "The exception caught was "
              + e;
    }
    return generateExample;
  }
Ejemplo n.º 2
0
  /** @param options */
  private void setFlags(final String[][] options) {
    int flagPos = 0;
    int contentPos = 1;
    for (int i = 0; i < options.length; i++) {
      String flagName = options[i][flagPos];
      String flagValue = null;
      if (options[i].length > 1) {
        flagValue = options[i][contentPos];
      }
      if (RestDocConstants.VELOCITY_TEMPLATE_PATH_FLAG.equals(flagName)) {
        velocityTemplatePath = flagValue;
        logger.log(Level.INFO, "Updating flag " + flagName + " value = " + flagValue);
      } else if (RestDocConstants.DOC_DEST_PATH_FLAG.equals(flagName)) {
        docPath = flagValue;
        logger.log(Level.INFO, "Updating flag " + flagName + " value = " + flagValue);
      } else if (RestDocConstants.VERSION_FLAG.equals(flagName)) {
        version = flagValue;
        logger.log(Level.INFO, "Updating flag " + flagName + " value = " + flagValue);
      } else if (RestDocConstants.DOC_CSS_PATH_FLAG.equals(flagName)) {
        docCssPath = flagValue;
        logger.log(Level.INFO, "Updating flag " + flagName + " value = " + flagValue);
      } else if (RestDocConstants.REQUEST_EXAMPLE_GENERATOR_CLASS_FLAG.equals(flagName)) {
        requestExampleGeneratorName = flagValue;
        logger.log(Level.INFO, "Updating flag " + flagName + " value = " + flagValue);
      } else if (RestDocConstants.RESPONSE_EXAMPLE_GENERATOR_CLASS_FLAG.equals(flagName)) {
        responseExampleGeneratorName = flagValue;
        logger.log(Level.INFO, "Updating flag " + flagName + " value = " + flagValue);
      } else if (RestDocConstants.REQUEST_BODY_PARAM_FILTER_CLASS_FLAG.equals(flagName)) {
        requestBodyParamFilterName = flagValue;
        logger.log(Level.INFO, "Updating flag " + flagName + " value = " + flagValue);
      }
    }

    if (!StringUtils.isBlank(velocityTemplatePath)) {
      isUserDefineTemplatePath = true;
      int fileNameIndex = velocityTemplatePath.lastIndexOf(File.separator) + 1;
      velocityTemplateFileName = velocityTemplatePath.substring(fileNameIndex);
      velocityTemplatePath = velocityTemplatePath.substring(0, fileNameIndex - 1);
    } else {
      velocityTemplateFileName = RestDocConstants.VELOCITY_TEMPLATE_FILE_NAME;
      velocityTemplatePath =
          this.getClass().getClassLoader().getResource(velocityTemplateFileName).getPath();
    }

    if (StringUtils.isBlank(docPath)) {
      docPath = RestDocConstants.DOC_DEST_PATH;
    }

    if (StringUtils.isBlank(version)) {
      version = RestDocConstants.VERSION;
    }

    if (StringUtils.isBlank(docCssPath)) {
      docCssPath = RestDocConstants.DOC_CSS_PATH;
    }

    initRequestExampleGenerator(requestExampleGeneratorName);
    logger.log(
        Level.INFO,
        "Updating request example generator class to "
            + requestExampleGenerator.getClass().getName());
    initResponseExampleGenerator(responseExampleGeneratorName);
    logger.log(
        Level.INFO,
        "Updating response example generator class to "
            + responseExampleGenerator.getClass().getName());

    initRequestBodyParamFilter();
    logger.log(
        Level.INFO,
        "Updating request body parameter filter class to "
            + requestBodyParamFilter.getClass().getName());
  }