/** * Retrieves the minimum value of a property * * @return the minimum value of the property */ public Optional<BigDecimal> getMin() { if (property instanceof BaseIntegerProperty) { BaseIntegerProperty integerProperty = (BaseIntegerProperty) property; return Optional.ofNullable(integerProperty.getMinimum() != null ? integerProperty.getMinimum() : null); } else if (property instanceof AbstractNumericProperty) { AbstractNumericProperty numericProperty = (AbstractNumericProperty) property; return Optional.ofNullable(numericProperty.getMinimum()); } return Optional.empty(); }
/** * Retrieves the minimum value of a property * * @return the minimum value of the property */ public Optional<BigDecimal> getMax() { if (property instanceof BaseIntegerProperty) { BaseIntegerProperty integerProperty = (BaseIntegerProperty) property; return Optional.ofNullable(integerProperty.getMaximum() != null ? integerProperty.getMaximum() : null); } else if (property instanceof AbstractNumericProperty) { AbstractNumericProperty numericProperty = (AbstractNumericProperty) property; return Optional.ofNullable(numericProperty.getMaximum()); } return Optional.empty(); }
private static Object generateExampleForMapProperty(MapProperty property, MarkupDocBuilder markupDocBuilder) { if (property.getExample() != null) { return property.getExample(); } Map<String, Object> exampleMap = new LinkedHashMap<>(); Property valueProperty = property.getAdditionalProperties(); if (valueProperty.getExample() != null) { return valueProperty.getExample(); } exampleMap.put("string", PropertyAdapter.generateExample(valueProperty, markupDocBuilder)); return exampleMap; }
if (property instanceof RefProperty) { RefProperty refProperty = (RefProperty) property; if (refProperty.getRefFormat() == RefFormat.RELATIVE) type = new ObjectType(refProperty.getTitle(), null); // FIXME : Workaround for https://github.com/swagger-api/swagger-parser/issues/177 else type = new RefType(definitionDocumentResolver.apply(refProperty.getSimpleRef()), new ObjectType(refProperty.getSimpleRef(), null /* FIXME, not used for now */)); } else if (property instanceof ArrayProperty) { ArrayProperty arrayProperty = (ArrayProperty) property; Property items = arrayProperty.getItems(); if (items == null) type = new ArrayType(arrayProperty.getTitle(), new ObjectType(null, null)); // FIXME : Workaround for Swagger parser issue with composed models (https://github.com/Swagger2Markup/swagger2markup/issues/150) else { Type arrayType = new PropertyAdapter(items).getType(definitionDocumentResolver); if (arrayType == null) type = new ArrayType(arrayProperty.getTitle(), new ObjectType(null, null)); // FIXME : Workaround for Swagger parser issue with composed models (https://github.com/Swagger2Markup/swagger2markup/issues/150) else type = new ArrayType(arrayProperty.getTitle(), new PropertyAdapter(items).getType(definitionDocumentResolver)); Property additionalProperties = mapProperty.getAdditionalProperties(); if (additionalProperties == null) type = new MapType(mapProperty.getTitle(), new ObjectType(null, null)); // FIXME : Workaround for Swagger parser issue with composed models (https://github.com/Swagger2Markup/swagger2markup/issues/150) else type = new MapType(mapProperty.getTitle(), new PropertyAdapter(additionalProperties).getType(definitionDocumentResolver)); } else if (property instanceof StringProperty) { StringProperty stringProperty = (StringProperty) property; List<String> enums = stringProperty.getEnum(); if (CollectionUtils.isNotEmpty(enums)) { type = new EnumType(stringProperty.getTitle(), enums); } else if (isNotBlank(stringProperty.getFormat())) {
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; 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"); return property.getType();
private SerializableParameter complement(Property property, RouteParameter source, SerializableParameter param) { param.setType(property.getType()); param.setFormat(property.getFormat()); // array param: if (property instanceof ArrayProperty) { param.setItems(((ArrayProperty) property).getItems()); } // enum values: List<String> enums = source.enums(); if (enums.size() > 0) { param.setEnum(enums); } // default value: if (param instanceof AbstractSerializableParameter) { ((AbstractSerializableParameter) param).setDefault(source.defaultValue()); } return param; } }
private String propertyType(Property property) { if (property instanceof RefProperty) { return ((RefProperty) property).getSimpleRef(); } // Special handling for uuid type reported by Swagger converter String type = property.getType(); if (property instanceof UUIDProperty) { type = UUID.class.getSimpleName(); } RamlType ramlType = types.get(type); return ramlType == null ? property.getType() : ramlType.getRef().getType(); }
if (property.getExample() != null) { return Optional.ofNullable(property.getExample()); } else if (property instanceof MapProperty) { Property additionalProperty = ((MapProperty) property).getAdditionalProperties(); if (additionalProperty.getExample() != null) { return Optional.ofNullable(additionalProperty.getExample()); } else if (generateMissingExamples) { Map<String, Object> exampleMap = new HashMap<>(); Property itemProperty = ((ArrayProperty) property).getItems(); List<Object> exampleArray = new ArrayList<>(); exampleArray.add(generateExample(itemProperty, markupDocBuilder));
@Override public Property resolveProperty(Type type, ModelConverterContext context, Annotation[] annotations, Iterator<ModelConverter> chain) { if (type == null) { return null; } try { TypeLiteral<?> typeLiteral = TypeLiteral.get(type); String typeName = typeLiteral.getType().getTypeName(); if (typeName.equals("java.util.List<org.jooby.Upload>") || typeName.equals("java.util.Set<org.jooby.Upload>")) { return new ArrayProperty(new FileProperty()); } if (typeName.equals(Upload.class.getName())) { return new FileProperty(); } return super.resolveProperty(type, context, annotations, chain); } catch (IllegalArgumentException x) { // shhh return super.resolveProperty(type, context, annotations, chain); } } });
/** * 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(); }
/** * Generates examples from an ArrayProperty * * @param value ArrayProperty * @param definitions map of definitions * @param markupDocBuilder the markup builder * @return array of Object */ private static Object[] generateExampleForArrayProperty(ArrayProperty value, Map<String, Model> definitions, DocumentResolver definitionDocumentResolver, MarkupDocBuilder markupDocBuilder, Map<String, Integer> refStack) { Property property = value.getItems(); return getExample(property, definitions, definitionDocumentResolver, markupDocBuilder, refStack); }
/** * Get example from a property * * @param property Property * @param definitions map of definitions * @param definitionDocumentResolver DocumentResolver * @param markupDocBuilder the markup builder * @param refStack reference stack * @return array of Object */ private static Object[] getExample( Property property, Map<String, Model> definitions, DocumentResolver definitionDocumentResolver, MarkupDocBuilder markupDocBuilder, Map<String, Integer> refStack) { if (property.getExample() != null) { return new Object[]{property.getExample()}; } else if (property instanceof ArrayProperty) { return new Object[]{generateExampleForArrayProperty((ArrayProperty) property, definitions, definitionDocumentResolver, markupDocBuilder, refStack)}; } else if (property instanceof RefProperty) { return new Object[]{generateExampleForRefModel(true, ((RefProperty) property).getSimpleRef(), definitions, definitionDocumentResolver, markupDocBuilder, refStack)}; } else { return new Object[]{PropertyAdapter.generateExample(property, markupDocBuilder)}; } }
/** * Retrieves the pattern of a property * * @return the pattern of the property */ public Optional<String> getPattern() { if (property instanceof StringProperty) { StringProperty stringProperty = (StringProperty) property; return Optional.ofNullable(stringProperty.getPattern()); } else if (property instanceof UUIDProperty) { UUIDProperty uuidProperty = (UUIDProperty) property; return Optional.ofNullable(uuidProperty.getPattern()); } return Optional.empty(); }
/** * Retrieves the minLength of a property * * @return the minLength of the property */ public Optional<Integer> getMinlength() { if (property instanceof StringProperty) { StringProperty stringProperty = (StringProperty) property; return Optional.ofNullable(stringProperty.getMinLength()); } else if (property instanceof UUIDProperty) { UUIDProperty uuidProperty = (UUIDProperty) property; return Optional.ofNullable(uuidProperty.getMinLength()); } return Optional.empty(); }
/** * Retrieves the maxLength of a property * * @return the maxLength of the property */ public Optional<Integer> getMaxlength() { if (property instanceof StringProperty) { StringProperty stringProperty = (StringProperty) property; return Optional.ofNullable(stringProperty.getMaxLength()); } else if (property instanceof UUIDProperty) { UUIDProperty uuidProperty = (UUIDProperty) property; return Optional.ofNullable(uuidProperty.getMaxLength()); } return Optional.empty(); }
/** * Retrieves the exclusiveMinimum value of a property * * @return the exclusiveMinimum value of the property */ public boolean getExclusiveMin() { if (property instanceof AbstractNumericProperty) { AbstractNumericProperty numericProperty = (AbstractNumericProperty) property; return BooleanUtils.isTrue(numericProperty.getExclusiveMinimum()); } return false; }
/** * Retrieves the exclusiveMaximum value of a property * * @return the exclusiveMaximum value of the property */ public boolean getExclusiveMax() { if (property instanceof AbstractNumericProperty) { AbstractNumericProperty numericProperty = (AbstractNumericProperty) property; return BooleanUtils.isTrue((numericProperty.getExclusiveMaximum())); } return false; }
/** * Checks if a property is read-only. * * @return true if the property is read-only */ public boolean getReadOnly() { return BooleanUtils.isTrue(property.getReadOnly()); } }
/** * Generate example for an ArrayProperty * * @param property ArrayProperty to generate example for * @param markupDocBuilder MarkupDocBuilder containing all associated settings * @return String example */ private static Object generateArrayExample(ArrayProperty property, MarkupDocBuilder markupDocBuilder) { Property itemProperty = property.getItems(); List<Object> exampleArray = new ArrayList<>(); exampleArray.add(generateExample(itemProperty, markupDocBuilder)); return exampleArray; }
if (properties != null) { for (Map.Entry<String, Property> property : properties.entrySet()) { Object exampleObject = property.getValue().getExample(); if (exampleObject == null) { if (property.getValue() instanceof RefProperty) { exampleObject = generateExampleForRefModel(true, ((RefProperty) property.getValue()).getSimpleRef(), definitions, definitionDocumentResolver, markupDocBuilder, refStack); } else if (property.getValue() instanceof ArrayProperty) { exampleObject = generateExampleForArrayProperty((ArrayProperty) property.getValue(), definitions, definitionDocumentResolver, markupDocBuilder, refStack);