Package com.carma.swagger.doclet.model

Examples of com.carma.swagger.doclet.model.ApiParameter


              Boolean required = getRequired(paramCategory, fawFieldName, property.getType(), optionalParams, requiredParams);

              String itemsRef = property.getItems() == null ? null : property.getItems().getRef();
              String itemsType = property.getItems() == null ? null : property.getItems().getType();

              ApiParameter param = new ApiParameter(property.getParamCategory(), renderedParamName, required, allowMultiple, property.getType(),
                  property.getFormat(), property.getDescription(), itemsRef, itemsType, property.getUniqueItems(),
                  property.getAllowableValues(), property.getMinimum(), property.getMaximum(), property.getDefaultValue());

              parameters.add(param);
            }
            break;
          }
        }

        continue;
      }

      // look for a custom input type for body params
      if ("body".equals(paramCategory)) {
        String customParamType = ParserHelper.getTagValue(this.methodDoc, this.options.getInputTypeTags());
        paramType = readCustomParamType(customParamType, paramType);
      }

      OptionalName paramTypeFormat = this.translator.parameterTypeName(consumesMultipart, parameter, paramType);
      String typeName = paramTypeFormat.value();
      String format = paramTypeFormat.getFormat();

      Boolean allowMultiple = null;
      List<String> allowableValues = null;
      String itemsRef = null;
      String itemsType = null;
      Boolean uniqueItems = null;
      String minimum = null;
      String maximum = null;
      String defaultVal = null;

      // set to form param type if data type is File
      if ("File".equals(typeName)) {
        paramCategory = "form";
      } else {

        if (this.options.isParseModels()) {
          this.models.addAll(new ApiModelParser(this.options, this.translator, paramType).parse());
        }

        // set enum values
        ClassDoc typeClassDoc = parameter.type().asClassDoc();
        allowableValues = ParserHelper.getAllowableValues(typeClassDoc);
        if (allowableValues != null) {
          typeName = "string";
        }

        // set whether its a csv param
        allowMultiple = getAllowMultiple(paramCategory, paramName, csvParams);

        // get min and max param values
        minimum = paramMinVals.get(paramName);
        maximum = paramMaxVals.get(paramName);

        String validationContext = " for the method: " + this.methodDoc.name() + " parameter: " + paramName;

        // verify min max are numbers
        ParserHelper.verifyNumericValue(validationContext + " min value.", typeName, format, minimum);
        ParserHelper.verifyNumericValue(validationContext + " max value.", typeName, format, maximum);

        // get a default value, prioritize the jaxrs annotation
        // otherwise look for the javadoc tag
        defaultVal = ParserHelper.getDefaultValue(parameter);
        if (defaultVal == null) {
          defaultVal = paramDefaultVals.get(paramName);
        }

        // verify default vs min, max and by itself
        if (defaultVal != null) {
          if (minimum == null && maximum == null) {
            // just validate the default
            ParserHelper.verifyValue(validationContext + " default value.", typeName, format, defaultVal);
          }
          // if min/max then default is validated as part of comparison
          if (minimum != null) {
            int comparison = ParserHelper.compareNumericValues(validationContext + " min value.", typeName, format, defaultVal, minimum);
            if (comparison < 0) {
              throw new IllegalStateException("Invalid value for the default value of the method: " + this.methodDoc.name() + " parameter: "
                  + paramName + " it should be >= the minimum: " + minimum);
            }
          }
          if (maximum != null) {
            int comparison = ParserHelper.compareNumericValues(validationContext + " max value.", typeName, format, defaultVal, maximum);
            if (comparison > 0) {
              throw new IllegalStateException("Invalid value for the default value of the method: " + this.methodDoc.name() + " parameter: "
                  + paramName + " it should be <= the maximum: " + maximum);
            }
          }
        }

        // if enum and default value check it matches the enum values
        if (allowableValues != null && defaultVal != null && !allowableValues.contains(defaultVal)) {
          throw new IllegalStateException("Invalid value for the default value of the method: " + this.methodDoc.name() + " parameter: " + paramName
              + " it should be one of: " + allowableValues);
        }

        // set collection related fields
        // TODO: consider supporting parameterized collections as api parameters...
        Type containerOf = null;
        containerOf = ParserHelper.getContainerType(paramType, null);
        String containerTypeOf = containerOf == null ? null : this.translator.typeName(containerOf).value();
        if (containerOf != null) {
          if (ParserHelper.isPrimitive(containerOf, this.options)) {
            itemsType = containerTypeOf;
          } else {
            itemsRef = containerTypeOf;
          }
        }

        if (typeName.equals("array")) {
          if (ParserHelper.isSet(paramType.qualifiedTypeName())) {
            uniqueItems = Boolean.TRUE;
          }
        }
      }

      // get whether required
      Boolean required = getRequired(paramCategory, paramName, typeName, optionalParams, requiredParams);

      // get the parameter name to use for the documentation
      String renderedParamName = ParserHelper.paramNameOf(parameter, paramNames, this.options.getParameterNameAnnotations());

      ApiParameter param = new ApiParameter(paramCategory, renderedParamName, required, allowMultiple, typeName, format, commentForParameter(
          this.methodDoc, parameter), itemsRef, itemsType, uniqueItems, allowableValues, minimum, maximum, defaultVal);

      parameters.add(param);
    }
View Full Code Here

TOP

Related Classes of com.carma.swagger.doclet.model.ApiParameter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.