io.swagger.models.properties.DecimalProperty Java Examples

The following examples show how to use io.swagger.models.properties.DecimalProperty. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ConverterMgr.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
private static void initPropertyMap() {
  PROPERTY_MAP.put(BooleanProperty.class, TypeFactory.defaultInstance().constructType(Boolean.class));

  PROPERTY_MAP.put(FloatProperty.class, TypeFactory.defaultInstance().constructType(Float.class));
  PROPERTY_MAP.put(DoubleProperty.class, TypeFactory.defaultInstance().constructType(Double.class));
  PROPERTY_MAP.put(DecimalProperty.class, TypeFactory.defaultInstance().constructType(BigDecimal.class));

  PROPERTY_MAP.put(ByteProperty.class, TypeFactory.defaultInstance().constructType(Byte.class));
  PROPERTY_MAP.put(ShortProperty.class, TypeFactory.defaultInstance().constructType(Short.class));
  PROPERTY_MAP.put(IntegerProperty.class, TypeFactory.defaultInstance().constructType(Integer.class));
  PROPERTY_MAP.put(BaseIntegerProperty.class, TypeFactory.defaultInstance().constructType(Integer.class));
  PROPERTY_MAP.put(LongProperty.class, TypeFactory.defaultInstance().constructType(Long.class));

  // stringProperty include enum scenes, not always be string type
  // if convert by StringPropertyConverter, can support enum scenes
  PROPERTY_MAP.put(StringProperty.class, TypeFactory.defaultInstance().constructType(String.class));

  PROPERTY_MAP.put(DateProperty.class, TypeFactory.defaultInstance().constructType(LocalDate.class));
  PROPERTY_MAP.put(DateTimeProperty.class, TypeFactory.defaultInstance().constructType(Date.class));

  PROPERTY_MAP.put(ByteArrayProperty.class, TypeFactory.defaultInstance().constructType(byte[].class));

  PROPERTY_MAP.put(FileProperty.class, TypeFactory.defaultInstance().constructType(Part.class));
}
 
Example #2
Source File: TizenClientCodegen.java    From TypeScript-Microservices with MIT License 5 votes vote down vote up
@Override
public String toDefaultValue(Property p) {
    if (p instanceof StringProperty) {
        return "std::string()";
    } else if (p instanceof BooleanProperty) {
        return "bool(false)";
    } else if (p instanceof DoubleProperty) {
        return "double(0)";
    } else if (p instanceof FloatProperty) {
        return "float(0)";
    } else if (p instanceof IntegerProperty) {
        return "int(0)";
    } else if (p instanceof LongProperty) {
        return "long(0)";
    } else if (p instanceof DecimalProperty) {
        return "long(0)";
    } else if (p instanceof MapProperty) {
        return "new std::map()";
    } else if (p instanceof ArrayProperty) {
        return "new std::list()";
    }
    // else
    if (p instanceof RefProperty) {
        RefProperty rp = (RefProperty) p;
        return "new " + toModelName(rp.getSimpleRef()) + "()";
    }
    return "null";
}
 
Example #3
Source File: XmlExampleGenerator.java    From TypeScript-Microservices with MIT License 5 votes vote down vote up
/**
* Get the example string value for the given Property.
*
* If an example value was not provided in the specification, a default will be generated.
*
* @param property Property to get example string for
*
* @return Example String
*/
protected String getExample(Property property) {
    if (property.getExample() != null) {
        return property.getExample().toString();
    } else if (property instanceof DateTimeProperty) {
        return "2000-01-23T04:56:07.000Z";
    } else if (property instanceof DateProperty) {
        return "2000-01-23";
    } else if (property instanceof BooleanProperty) {
        return "true";
    } else if (property instanceof LongProperty) {
        return "123456789";
    } else if (property instanceof DoubleProperty) { // derived from DecimalProperty so make sure this is first
        return "3.149";
    }  else if (property instanceof DecimalProperty) {
        return "1.3579";
    } else if (property instanceof PasswordProperty) {
        return "********";
    } else if (property instanceof UUIDProperty) {
        return "046b6c7f-0b8a-43b9-b35d-6489e6daee91";
    // do these last in case the specific types above are derived from these classes
    } else if (property instanceof StringProperty) {
        return "aeiou";
    } else if (property instanceof BaseIntegerProperty) {
        return "123";
    } else if (property instanceof AbstractNumericProperty) {
        return "1.23";
    }
    LOGGER.warn("default example value not implemented for " + property);
    return "";
}
 
Example #4
Source File: TestRBeanSwaggerModel.java    From datacollector with Apache License 2.0 5 votes vote down vote up
@Test
public void testAllTypes() {
  Map<String, Model> modelMap = ModelConverters.getInstance()
      .read(TypeToken.of(RAllTypes.class).getType());

  Model rAllTypes = modelMap.get(RAllTypes.class.getSimpleName());
  Assert.assertNotNull(rAllTypes);

  Map<String, Class<? extends Property>> expectedProperties = ImmutableMap.<String, Class<? extends Property>>builder()
      .put("id", StringProperty.class)
      .put("rChar", StringProperty.class)
      .put("rDate", LongProperty.class)
      .put("rTime", LongProperty.class)
      .put("rDatetime", LongProperty.class)
      .put("rLong", LongProperty.class)
      .put("rDouble", DoubleProperty.class)
      .put("rDecimal", DecimalProperty.class)
      .put("rEnum", StringProperty.class)
      .put("rSubBean", RefProperty.class)
      .put("rSubBeanList", ArrayProperty.class)
      .build();

  Assert.assertEquals(expectedProperties.size(), rAllTypes.getProperties().size());
  expectedProperties.forEach(
      (k, v) -> Assert.assertEquals(v, rAllTypes.getProperties().get(k).getClass())
  );
  StringProperty rEnumProperty = ((StringProperty)rAllTypes.getProperties().get("rEnum"));
  Assert.assertTrue(
      new HashSet<>(rEnumProperty.getEnum())
          .containsAll(Arrays.stream(Alphabet.values()).map(Enum::name).collect(Collectors.toSet()))
  );

  RefProperty refProperty = (RefProperty) rAllTypes.getProperties().get("rSubBean");
  Assert.assertEquals(refProperty.getSimpleRef(), RSubBean.class.getSimpleName());

  ArrayProperty arrayProperty = (ArrayProperty) rAllTypes.getProperties().get("rSubBeanList");
  Assert.assertEquals(((RefProperty)arrayProperty.getItems()).getSimpleRef(), RSubBean.class.getSimpleName());
}
 
Example #5
Source File: DefaultCodegen.java    From TypeScript-Microservices with MIT License 4 votes vote down vote up
/**
 * returns the swagger type for the property
 * @param p Swagger property object
 * @return string presentation of the type
 **/
@SuppressWarnings("static-method")
public String getSwaggerType(Property p) {
    String datatype = null;
    if (p instanceof StringProperty && "number".equals(p.getFormat())) {
        datatype = "BigDecimal";
    } else if ((p instanceof ByteArrayProperty) || (p instanceof StringProperty && "byte".equals(p.getFormat()))) {
        datatype = "ByteArray";
    } else if (p instanceof BinaryProperty) {
        datatype = "binary";
    } else if (p instanceof FileProperty) {
        datatype = "file";
    } else if (p instanceof BooleanProperty) {
        datatype = "boolean";
    } else if (p instanceof DateProperty) {
        datatype = "date";
    } else if (p instanceof DateTimeProperty) {
        datatype = "DateTime";
    } else if (p instanceof DoubleProperty) {
        datatype = "double";
    } else if (p instanceof FloatProperty) {
        datatype = "float";
    } else if (p instanceof IntegerProperty) {
        datatype = "integer";
    } else if (p instanceof LongProperty) {
        datatype = "long";
    } else if (p instanceof MapProperty) {
        datatype = "map";
    } else if (p instanceof DecimalProperty) {
        datatype = "number";
    } else if ( p instanceof UUIDProperty) {
        datatype = "UUID";
    } else if (p instanceof RefProperty) {
        try {
            RefProperty r = (RefProperty) p;
            datatype = r.get$ref();
            if (datatype.indexOf("#/definitions/") == 0) {
                datatype = datatype.substring("#/definitions/".length());
            }
        } catch (Exception e) {
            LOGGER.warn("Error obtaining the datatype from RefProperty:" + p + ". Datatype default to Object");
            datatype = "Object";
            LOGGER.error(e.getMessage(), e);
        }
    } else if (p instanceof StringProperty) {
        datatype = "string";
    } else {
        if (p != null) {
            datatype = p.getType();
        }
    }
    return datatype;
}
 
Example #6
Source File: RJsonModelConverter.java    From datacollector with Apache License 2.0 4 votes vote down vote up
@Override
public Property resolveProperty(java.lang.reflect.Type type, ModelConverterContext context, Annotation[] annotations,
    Iterator<ModelConverter> chain) {
  final JavaType jType = _mapper.constructType(type);
  if (jType != null) {
    final Class<?> cls = jType.getRawClass();
    if (cls.equals(RString.class)) {
      return new StringProperty();
    } else if (cls.equals(RChar.class)) {
      return new StringProperty();
    } else if (cls.equals(RText.class)) {
      return new StringProperty();
    } else if (cls.equals(RDate.class)) {
      return new LongProperty();
    } else if (cls.equals(RDatetime.class)) {
      return new LongProperty();
    } else if (cls.equals(RTime.class)) {
      return new LongProperty();
    } else if (cls.equals(RLong.class)) {
      return new LongProperty();
    } else if (cls.equals(RBoolean.class)) {
      return new BooleanProperty();
    } else if(cls.equals(RDecimal.class)) {
      return new DecimalProperty();
    } else if(cls.equals(RDouble.class)) {
      return new DoubleProperty();
    } else if(cls.equals(REnum.class)) {
      Property property = new StringProperty();
      if (jType.containedTypeCount() > 0) {
        _addEnumProps(jType.containedType(0).getRawClass(), property);
      }
      return property;
    } else if (RBean.class.isAssignableFrom(cls)) {
      // complex type
      Model innerModel = context.resolve(jType);
      RBEAN_INTERNAL_FIELDS.forEach(innerModel.getProperties()::remove);
      if (innerModel instanceof ComposedModel) {
        innerModel = ((ComposedModel) innerModel).getChild();
      }
      if (innerModel instanceof ModelImpl) {
        ModelImpl mi = (ModelImpl) innerModel;
        return new RefProperty(StringUtils.isNotEmpty(mi.getReference()) ? mi.getReference() : mi.getName());
      }
    }
    return chain.next().resolveProperty(type, context, annotations, chain);
  } else {
    return null;
  }
}