Package com.carma.swagger.doclet.translator.Translator

Examples of com.carma.swagger.doclet.translator.Translator.OptionalName


      String typeName = entry.getKey();
      TypeRef typeRef = entry.getValue();
      Type type = typeRef.type;
      ClassDoc typeClassDoc = type.asClassDoc();

      OptionalName propertyTypeFormat = this.translator.typeName(type);
      String propertyType = propertyTypeFormat.value();

      // set enum values
      List<String> allowableValues = ParserHelper.getAllowableValues(typeClassDoc);
      if (allowableValues != null) {
        propertyType = "string";
      }

      Type containerOf = ParserHelper.getContainerType(type, this.varsToTypes);
      String itemsRef = null;
      String itemsType = 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;
        }
      }
      Boolean uniqueItems = null;
      if (propertyType.equals("array")) {
        if (ParserHelper.isSet(type.qualifiedTypeName())) {
          uniqueItems = Boolean.TRUE;
        }
      }

      String validationContext = " for the " + typeRef.sourceDesc + " of the class: " + classDoc.name();
      // validate min/max
      ParserHelper.verifyNumericValue(validationContext + " min value.", propertyTypeFormat.value(), propertyTypeFormat.getFormat(), typeRef.min);
      ParserHelper.verifyNumericValue(validationContext + " max value.", propertyTypeFormat.value(), propertyTypeFormat.getFormat(), typeRef.max);

      // if enum and default value check it matches the enum values
      if (allowableValues != null && typeRef.defaultValue != null && !allowableValues.contains(typeRef.defaultValue)) {
        throw new IllegalStateException(" Invalid value for the default value of the " + typeRef.sourceDesc + " it should be one of: "
            + allowableValues);
      }
      // verify default vs min, max and by itself
      if (typeRef.defaultValue != null) {
        if (typeRef.min == null && typeRef.max == null) {
          // just validate the default
          ParserHelper.verifyValue(validationContext + " default value.", propertyTypeFormat.value(), propertyTypeFormat.getFormat(),
              typeRef.defaultValue);
        }
        // if min/max then default is validated as part of comparison
        if (typeRef.min != null) {
          int comparison = ParserHelper.compareNumericValues(validationContext + " min value.", propertyTypeFormat.value(),
              propertyTypeFormat.getFormat(), typeRef.defaultValue, typeRef.min);
          if (comparison < 0) {
            throw new IllegalStateException("Invalid value for the default value of the " + typeRef.sourceDesc + " it should be >= the minimum: "
                + typeRef.min);
          }
        }
        if (typeRef.max != null) {
          int comparison = ParserHelper.compareNumericValues(validationContext + " max value.", propertyTypeFormat.value(),
              propertyTypeFormat.getFormat(), typeRef.defaultValue, typeRef.max);
          if (comparison > 0) {
            throw new IllegalStateException("Invalid value for the default value of the " + typeRef.sourceDesc + " it should be <= the maximum: "
                + typeRef.max);
          }
        }
      }

      Property property = new Property(typeRef.rawName, typeRef.paramCategory, propertyType, propertyTypeFormat.getFormat(), typeRef.description,
          itemsRef, itemsType, uniqueItems, allowableValues, typeRef.min, typeRef.max, typeRef.defaultValue);
      elements.put(typeName, property);
    }
    return elements;
  }
View Full Code Here


      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;
View Full Code Here

TOP

Related Classes of com.carma.swagger.doclet.translator.Translator.OptionalName

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.