io.swagger.models.properties.IntegerProperty Java Examples
The following examples show how to use
io.swagger.models.properties.IntegerProperty.
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: OpenApiTransformer.java From spring-openapi with MIT License | 6 votes |
@SuppressWarnings("squid:S1192") // better in-place defined for better readability protected Property createBaseTypeProperty(Class<?> type, Annotation[] annotations) { if (byte.class.equals(type) || short.class.equals(type) || int.class.equals(type)) { return createNumberSchema(new IntegerProperty(), annotations); } else if (long.class.equals(type)) { return createNumberSchema(new LongProperty(), annotations); } else if (float.class.equals(type)) { return createNumberSchema(new FloatProperty().vendorExtension("x-type", "System.BigDecimal"), annotations); } else if (double.class.equals(type)) { return createNumberSchema(new DoubleProperty().vendorExtension("x-type", "System.BigDecimal"), annotations); } else if (char.class.equals(type)) { return createStringProperty(null, annotations); } else if (boolean.class.equals(type)) { return new BooleanProperty(); } logger.info("Ignoring unsupported type=[{}]", type.getSimpleName()); return null; }
Example #2
Source File: PropertyAdapter.java From swagger2markup with Apache License 2.0 | 6 votes |
/** * Retrieves the default value of a property * * @return the default value of the property */ public Optional<Object> getDefaultValue() { if (property instanceof BooleanProperty) { BooleanProperty booleanProperty = (BooleanProperty) property; return Optional.ofNullable(booleanProperty.getDefault()); } else if (property instanceof StringProperty) { StringProperty stringProperty = (StringProperty) property; return Optional.ofNullable(stringProperty.getDefault()); } else if (property instanceof DoubleProperty) { DoubleProperty doubleProperty = (DoubleProperty) property; return Optional.ofNullable(doubleProperty.getDefault()); } else if (property instanceof FloatProperty) { FloatProperty floatProperty = (FloatProperty) property; return Optional.ofNullable(floatProperty.getDefault()); } else if (property instanceof IntegerProperty) { IntegerProperty integerProperty = (IntegerProperty) property; return Optional.ofNullable(integerProperty.getDefault()); } else if (property instanceof LongProperty) { LongProperty longProperty = (LongProperty) property; return Optional.ofNullable(longProperty.getDefault()); } else if (property instanceof UUIDProperty) { UUIDProperty uuidProperty = (UUIDProperty) property; return Optional.ofNullable(uuidProperty.getDefault()); } return Optional.empty(); }
Example #3
Source File: OpenApiTransformer.java From spring-openapi with MIT License | 6 votes |
@SuppressWarnings("squid:S3776") // no other solution protected Property createRefTypeProperty(Class<?> typeClass, Annotation[] annotations, GenerationContext generationContext) { if (Byte.class.equals(typeClass) || Short.class.equals(typeClass) || Integer.class.equals(typeClass)) { return createNumberSchema(new IntegerProperty(), annotations); } else if (Long.class.equals(typeClass) || BigInteger.class.equals(typeClass)) { return createNumberSchema(new LongProperty(), annotations); } else if (Float.class.equals(typeClass)) { return createNumberSchema(new FloatProperty().vendorExtension("x-type", "System.BigDecimal"), annotations); } else if (Double.class.equals(typeClass) || BigDecimal.class.equals(typeClass)) { return createNumberSchema(new DoubleProperty().vendorExtension("x-type", "System.BigDecimal"), annotations); } else if (Character.class.equals(typeClass) || String.class.equals(typeClass)) { return createStringProperty(null, annotations); } else if (Boolean.class.equals(typeClass)) { return new BooleanProperty(); } else if (List.class.equals(typeClass)) { return createArrayProperty(typeClass, generationContext, annotations); } else if (LocalDate.class.equals(typeClass) || Date.class.equals(typeClass)) { return createStringProperty("date", annotations); } else if (LocalDateTime.class.equals(typeClass) || LocalTime.class.equals(typeClass)) { return createStringProperty("date-time", annotations); } return createRefProperty(typeClass, generationContext); }
Example #4
Source File: SwaggerGenerator.java From endpoints-java with Apache License 2.0 | 6 votes |
private static Property getSwaggerArrayProperty(TypeToken<?> typeToken) { Class<?> type = typeToken.getRawType(); if (type == String.class) { return new StringProperty(); } else if (type == Boolean.class || type == Boolean.TYPE) { return new BooleanProperty(); } else if (type == Integer.class || type == Integer.TYPE) { return new IntegerProperty(); } else if (type == Long.class || type == Long.TYPE) { return new LongProperty(); } else if (type == Float.class || type == Float.TYPE) { return new FloatProperty(); } else if (type == Double.class || type == Double.TYPE) { return new DoubleProperty(); } else if (type == byte[].class) { return new ByteArrayProperty(); } else if (type.isEnum()) { return new StringProperty(); } throw new IllegalArgumentException("invalid property type"); }
Example #5
Source File: ConverterMgr.java From servicecomb-java-chassis with Apache License 2.0 | 6 votes |
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 #6
Source File: WSDL11SOAPOperationExtractor.java From carbon-apimgt with Apache License 2.0 | 5 votes |
private Property getPropertyFromDataType(String dataType) { switch (dataType) { case "string": return new StringProperty(); case "boolean": return new BooleanProperty(); case "int": return new IntegerProperty(); case "nonNegativeInteger": return new IntegerProperty(); case "integer": return new IntegerProperty(); case "positiveInteger": return new IntegerProperty(); case "double": return new DoubleProperty(); case "float": return new FloatProperty(); case "long": return new LongProperty(); case "date": return new DateProperty(); case "dateTime": return new DateTimeProperty(); default: return new RefProperty(); } }
Example #7
Source File: PropertyAdapter.java From swagger2markup with Apache License 2.0 | 5 votes |
/** * Generate a default example value for property. * * @param property property * @param markupDocBuilder doc builder * @return a generated example for the property */ public static Object generateExample(Property property, MarkupDocBuilder markupDocBuilder) { if (property.getType() == null) { return "untyped"; } switch (property.getType()) { case "integer": return ExamplesUtil.generateIntegerExample(property instanceof IntegerProperty ? ((IntegerProperty) property).getEnum() : null); case "number": return 0.0; case "boolean": return true; case "string": return ExamplesUtil.generateStringExample(property.getFormat(), property instanceof StringProperty ? ((StringProperty) property).getEnum() : null); case "ref": if (property instanceof RefProperty) { if (logger.isDebugEnabled()) logger.debug("generateExample RefProperty for " + property.getName()); return markupDocBuilder.copy(false).crossReference(((RefProperty) property).getSimpleRef()).toString(); } else { if (logger.isDebugEnabled()) logger.debug("generateExample for ref not RefProperty"); } case "array": if (property instanceof ArrayProperty) { return generateArrayExample((ArrayProperty) property, markupDocBuilder); } default: return property.getType(); } }
Example #8
Source File: SwaggerDefinition.java From Web-API with MIT License | 5 votes |
private static Response constructResponse(int status, String error) { Property statusProp = new IntegerProperty() .description("The status code of the error (also provided in the HTTP header)"); statusProp.setExample(status); Property errorProp = new StringProperty() .description("The error message describing the error"); errorProp.setExample((Object)error); return new Response() .description(error) .schema(new ObjectProperty() .property("status", statusProp) .property("error", errorProp)); }
Example #9
Source File: TizenClientCodegen.java From TypeScript-Microservices with MIT License | 5 votes |
@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 #10
Source File: SwaggerUtil.java From yshopmall with Apache License 2.0 | 5 votes |
/** * 获取Swagger支持的类型 * * @return {@link Map<String, AbstractProperty >} */ private static Map<String, AbstractProperty> getPropMap() { Map<String, AbstractProperty> map = new HashMap<>(8); map.put("integer", new IntegerProperty()); map.put("int", new IntegerProperty()); map.put("long", new LongProperty()); map.put("string", new StringProperty()); map.put("object", new ObjectProperty()); map.put("array", new ArrayProperty()); map.put("boolean", new BooleanProperty()); map.put("date", new DateTimeProperty()); return map; }
Example #11
Source File: OpenApiTransformer.java From spring-openapi with MIT License | 5 votes |
protected Property createProperty(Class<?> elementTypeSignature) { if (byte.class.equals(elementTypeSignature) || short.class.equals(elementTypeSignature) || int.class.equals(elementTypeSignature) || long.class.equals(elementTypeSignature) || Byte.class.equals(elementTypeSignature) || Short.class.equals(elementTypeSignature) || Integer.class.equals(elementTypeSignature) || Long.class.equals(elementTypeSignature) || BigInteger.class.equals(elementTypeSignature)) { return new IntegerProperty(); } else if (float.class.equals(elementTypeSignature) || Float.class.equals(elementTypeSignature)) { return new FloatProperty().vendorExtension("x-type", "System.BigDecimal"); } else if (double.class.equals(elementTypeSignature) || Double.class.equals(elementTypeSignature) || BigDecimal.class.equals(elementTypeSignature)) { return new DoubleProperty().vendorExtension("x-type", "System.BigDecimal"); } else if (List.class.equals(elementTypeSignature)) { throw new IllegalArgumentException("Nested List types are not supported" + elementTypeSignature.getName() ); } else { if (char.class.equals(elementTypeSignature) || Character.class.equals(elementTypeSignature) || String.class.equals(elementTypeSignature) || LocalDate.class.equals(elementTypeSignature) || Date.class.equals(elementTypeSignature) || LocalDateTime.class.equals(elementTypeSignature) || LocalTime.class.equals(elementTypeSignature)) { return new StringProperty(); } else if (elementTypeSignature.isEnum()) { StringProperty property = new StringProperty(); property.setEnum(Arrays.stream(elementTypeSignature.getEnumConstants()).map(Object::toString).collect(toList())); return property; } else if (boolean.class.equals(elementTypeSignature) || Boolean.class.equals(elementTypeSignature)) { return new BooleanProperty(); } } return null; }
Example #12
Source File: OpenApiTransformer.java From spring-openapi with MIT License | 5 votes |
protected void setParameterDetails(AbstractSerializableParameter<?> oasParameter, Class<?> type, Annotation[] annotations) { if (byte.class.equals(type) || short.class.equals(type) || int.class.equals(type) || Byte.class.equals(type) || Short.class.equals(type) || Integer.class.equals(type)) { oasParameter.setProperty(new IntegerProperty()); } else if (long.class.equals(type) || Long.class.equals(type) || BigInteger.class.equals(type)) { oasParameter.setProperty(new LongProperty()); } else if (float.class.equals(type) || Float.class.equals(type)) { oasParameter.setProperty(new FloatProperty().vendorExtension("x-type", "System.BigDecimal")); } else if (double.class.equals(type) || Double.class.equals(type) || BigDecimal.class.equals(type)) { oasParameter.setProperty(new DoubleProperty().vendorExtension("x-type", "System.BigDecimal")); } else if (char.class.equals(type) || Character.class.equals(type) || String.class.equals(type)) { oasParameter.setProperty(new StringProperty()); } else if (boolean.class.equals(type) || Boolean.class.equals(type)) { oasParameter.setProperty(new BooleanProperty()); } else if (List.class.equals(type)) { oasParameter.setProperty(createArrayProperty(type, null, annotations)); } else if (LocalDate.class.equals(type) || Date.class.equals(type)) { oasParameter.setProperty(new DateProperty()); } else if (LocalDateTime.class.equals(type) || LocalTime.class.equals(type)) { oasParameter.setProperty(new DateTimeProperty()); } else if (type.isEnum()) { mapEnum(oasParameter, type); } else { oasParameter.setProperty(createRefProperty(type, null)); } asList(annotations).forEach(annotation -> applyAnnotationDetailsOnParameter(oasParameter, annotation)); }
Example #13
Source File: AbstractTypeScriptClientCodegen.java From TypeScript-Microservices with MIT License | 4 votes |
@Override public String toDefaultValue(Property p) { if (p instanceof StringProperty) { StringProperty sp = (StringProperty) p; if (sp.getDefault() != null) { return "'" + sp.getDefault() + "'"; } return UNDEFINED_VALUE; } else if (p instanceof BooleanProperty) { return UNDEFINED_VALUE; } else if (p instanceof DateProperty) { return UNDEFINED_VALUE; } else if (p instanceof DateTimeProperty) { return UNDEFINED_VALUE; } else if (p instanceof DoubleProperty) { DoubleProperty dp = (DoubleProperty) p; if (dp.getDefault() != null) { return dp.getDefault().toString(); } return UNDEFINED_VALUE; } else if (p instanceof FloatProperty) { FloatProperty fp = (FloatProperty) p; if (fp.getDefault() != null) { return fp.getDefault().toString(); } return UNDEFINED_VALUE; } else if (p instanceof IntegerProperty) { IntegerProperty ip = (IntegerProperty) p; if (ip.getDefault() != null) { return ip.getDefault().toString(); } return UNDEFINED_VALUE; } else if (p instanceof LongProperty) { LongProperty lp = (LongProperty) p; if (lp.getDefault() != null) { return lp.getDefault().toString(); } return UNDEFINED_VALUE; } else { return UNDEFINED_VALUE; } }
Example #14
Source File: DefaultCodegen.java From TypeScript-Microservices with MIT License | 4 votes |
/** * 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 #15
Source File: ElmClientCodegen.java From TypeScript-Microservices with MIT License | 4 votes |
@Override public String toDefaultValue(Property p) { if (p instanceof StringProperty) { StringProperty sp = (StringProperty) p; if (sp.getDefault() != null) { return toOptionalValue("\"" + sp.getDefault().toString() + "\""); } return toOptionalValue(null); } else if (p instanceof BooleanProperty) { BooleanProperty bp = (BooleanProperty) p; if (bp.getDefault() != null) { return toOptionalValue(bp.getDefault() ? "True" : "False"); } return toOptionalValue(null); } else if (p instanceof DateProperty) { return toOptionalValue(null); } else if (p instanceof DateTimeProperty) { return toOptionalValue(null); } else if (p instanceof DoubleProperty) { DoubleProperty dp = (DoubleProperty) p; if (dp.getDefault() != null) { return toOptionalValue(dp.getDefault().toString()); } return toOptionalValue(null); } else if (p instanceof FloatProperty) { FloatProperty fp = (FloatProperty) p; if (fp.getDefault() != null) { return toOptionalValue(fp.getDefault().toString()); } return toOptionalValue(null); } else if (p instanceof IntegerProperty) { IntegerProperty ip = (IntegerProperty) p; if (ip.getDefault() != null) { return toOptionalValue(ip.getDefault().toString()); } return toOptionalValue(null); } else if (p instanceof LongProperty) { LongProperty lp = (LongProperty) p; if (lp.getDefault() != null) { return toOptionalValue(lp.getDefault().toString()); } return toOptionalValue(null); } else { return toOptionalValue(null); } }
Example #16
Source File: ArrayParameterValidatorTest.java From light-rest-4j with Apache License 2.0 | 4 votes |
@Test public void validate_withTooFewValues_shouldFail_whenMinItemsSpecified() { Status status = classUnderTest.validate("1,2", arrayParam(true, "csv", 3, 5, null, new IntegerProperty())); Assert.assertNotNull(status); Assert.assertEquals("ERR11007", status.getCode()); // request parameter collection too few items }
Example #17
Source File: ArrayParameterValidatorTest.java From light-rest-4j with Apache License 2.0 | 4 votes |
@Test public void validate_withTooManyValues_shouldFail_whenMaxItemsSpecified() { Status status = classUnderTest.validate("1,2,3,4,5,6", arrayParam(true, "csv", 3, 5, null, new IntegerProperty())); Assert.assertNotNull(status); Assert.assertEquals("ERR11006", status.getCode()); // request parameter collection too many items }
Example #18
Source File: ArrayParameterValidatorTest.java From light-rest-4j with Apache License 2.0 | 4 votes |
@Test public void validate_withNonUniqueValues_shouldFail_whenUniqueSpecified() { Status status = classUnderTest.validate("1,2,1", arrayParam(true, "csv", null, null, true, new IntegerProperty())); Assert.assertNotNull(status); Assert.assertEquals("ERR11008", status.getCode()); // request parameter collection duplicate items }
Example #19
Source File: ArrayParameterValidatorTest.java From light-rest-4j with Apache License 2.0 | 4 votes |
@Test public void validate_withNonUniqueValues_shouldPass_whenUniqueNotSpecified() { Assert.assertNull(classUnderTest.validate("1,2,1", arrayParam(true, "csv", null, null, false, new IntegerProperty()))); }
Example #20
Source File: ArrayParameterValidatorTest.java From light-rest-4j with Apache License 2.0 | 4 votes |
@Test public void validate_withEnumValues_shouldPass_whenAllValuesMatchEnum() { Assert.assertNull(classUnderTest.validate("1,2,1", enumeratedArrayParam(true, "csv", new IntegerProperty(), "1", "2", "3"))); }
Example #21
Source File: ArrayParameterValidatorTest.java From light-rest-4j with Apache License 2.0 | 4 votes |
@Test public void validate_withEnumValues_shouldFail_whenValueDoesntMatchEnum() { Status status = classUnderTest.validate("1,2,1,4", enumeratedArrayParam(true, "csv", new IntegerProperty(), "1", "2", "bob")); Assert.assertNotNull(status); Assert.assertEquals("ERR11009", status.getCode()); // request parameter collection duplicate items }
Example #22
Source File: ValidatorTestUtil.java From light-rest-4j with Apache License 2.0 | 4 votes |
public static SerializableParameter intArrayParam(final boolean required, final String collectionFormat) { final IntegerProperty property = new IntegerProperty(); return arrayParam(required, collectionFormat, null, null, null, property); }
Example #23
Source File: SwaggerUtils.java From micro-integrator with Apache License 2.0 | 4 votes |
/** * This method will generate a sample request body for the request. * * @param method Rest resource method. * @param operation Swagger operation object. * @param parameterList list of parameters. */ private static void generateSampleRequestPayload(String method, Operation operation, List<AxisResourceParameter> parameterList) { // GET method does not have a body if (!"GET".equals(method)) { BodyParameter bodyParameter = new BodyParameter(); bodyParameter.description("Sample Payload"); bodyParameter.name("payload"); bodyParameter.setRequired(false); ModelImpl modelschema = new ModelImpl(); modelschema.setType("object"); Map<String, Property> propertyMap = new HashMap<>(1); ObjectProperty objectProperty = new ObjectProperty(); objectProperty.name("payload"); Map<String, Property> payloadProperties = new HashMap<>(); for (AxisResourceParameter resourceParameter : parameterList) { switch (resourceParameter.getParameterDataType()) { case SwaggerProcessorConstants.INTEGER: payloadProperties.put(resourceParameter.getParameterName(), new IntegerProperty()); break; case SwaggerProcessorConstants.NUMBER: payloadProperties.put(resourceParameter.getParameterName(), new DoubleProperty()); break; case SwaggerProcessorConstants.BOOLEAN: payloadProperties.put(resourceParameter.getParameterName(), new BooleanProperty()); break; default: payloadProperties.put(resourceParameter.getParameterName(), new StringProperty()); break; } } objectProperty.setProperties(payloadProperties); propertyMap.put("payload", objectProperty); modelschema.setProperties(propertyMap); bodyParameter.setSchema(modelschema); operation.addParameter(bodyParameter); } }