Java Code Examples for io.swagger.models.properties.Property#getType()
The following examples show how to use
io.swagger.models.properties.Property#getType() .
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: SwaggerToWordExample.java From poi-tl with Apache License 2.0 | 6 votes |
private Object valueOfProperty(Map<String, Model> definitions, Property prop, Set<String> keyCache) { Object value; if (prop instanceof RefProperty) { String ref = ((RefProperty) prop).get$ref().substring("#/definitions/".length()); if (keyCache.contains(ref)) value = ((RefProperty) prop).get$ref(); else value = valueOfModel(definitions, definitions.get(ref), keyCache); } else if (prop instanceof ArrayProperty) { List<Object> list = new ArrayList<>(); Property insideItems = ((ArrayProperty) prop).getItems(); list.add(valueOfProperty(definitions, insideItems, keyCache)); value = list; } else if (prop instanceof AbstractNumericProperty) { value = 0; } else if (prop instanceof BooleanProperty) { value = false; } else { value = prop.getType(); } return value; }
Example 2
Source File: JaxrsReader.java From swagger-maven-plugin with Apache License 2.0 | 6 votes |
private Parameter replaceArrayModelForOctetStream(Operation operation, Parameter parameter) { if (parameter instanceof BodyParameter && operation.getConsumes() != null && operation.getConsumes().contains("application/octet-stream")) { BodyParameter bodyParam = (BodyParameter) parameter; Model schema = bodyParam.getSchema(); if (schema instanceof ArrayModel) { ArrayModel arrayModel = (ArrayModel) schema; Property items = arrayModel.getItems(); if (items != null && items.getFormat() == "byte" && items.getType() == "string") { ModelImpl model = new ModelImpl(); model.setFormat("byte"); model.setType("string"); bodyParam.setSchema(model); } } } return parameter; }
Example 3
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 4
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; }