Search in sources :

Example 61 with ArrayProperty

use of io.swagger.models.properties.ArrayProperty in project swagger-core by swagger-api.

the class ModelImplTest method testClone.

@Test
public void testClone() {
    // given
    propertiesAndValues = new Object[] { "additionalProperties", new ArrayProperty(), "description", "description", "discriminator", "discriminator", "example", new Object(), "isSimple", true, "name", "name", "properties", new HashMap<String, Property>(), "required", new ArrayList<String>(), "type", "type", "xml", new Xml(), "defaultValue", "defaultValue" };
    TestUtils.testClone(instance, propertiesAndValues);
}
Also used : ArrayProperty(io.swagger.models.properties.ArrayProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) Property(io.swagger.models.properties.Property) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 62 with ArrayProperty

use of io.swagger.models.properties.ArrayProperty in project java-chassis by ServiceComb.

the class TestApiOperation method testSet.

private void testSet(Path path) {
    Operation operation = path.getPost();
    Property result200 = operation.getResponses().get("200").getSchema();
    Assert.assertEquals(ArrayProperty.class, result200.getClass());
    Assert.assertEquals(true, ((ArrayProperty) result200).getUniqueItems());
}
Also used : ApiOperation(io.swagger.annotations.ApiOperation) Operation(io.swagger.models.Operation) MapProperty(io.swagger.models.properties.MapProperty) ExtensionProperty(io.swagger.annotations.ExtensionProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) Property(io.swagger.models.properties.Property)

Example 63 with ArrayProperty

use of io.swagger.models.properties.ArrayProperty in project java-chassis by ServiceComb.

the class TestApiOperation method testList.

private void testList(Path path) {
    Operation operation = path.getPost();
    Property result200 = operation.getResponses().get("200").getSchema();
    Assert.assertEquals(ArrayProperty.class, result200.getClass());
    Assert.assertEquals(null, ((ArrayProperty) result200).getUniqueItems());
}
Also used : ApiOperation(io.swagger.annotations.ApiOperation) Operation(io.swagger.models.Operation) MapProperty(io.swagger.models.properties.MapProperty) ExtensionProperty(io.swagger.annotations.ExtensionProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) Property(io.swagger.models.properties.Property)

Example 64 with ArrayProperty

use of io.swagger.models.properties.ArrayProperty in project herd by FINRAOS.

the class DefinitionGenerator method getPropertyFromType.

/**
 * Gets a property from the given fieldType. This method may be called recursively.
 *
 * @param fieldType the field type class.
 *
 * @return the property.
 * @throws MojoExecutionException if any problems were encountered.
 */
private Property getPropertyFromType(Class<?> fieldType) throws MojoExecutionException {
    Property property;
    if (String.class.isAssignableFrom(fieldType)) {
        property = new StringProperty();
    } else if (Integer.class.isAssignableFrom(fieldType) || int.class.isAssignableFrom(fieldType)) {
        property = new IntegerProperty();
    } else if (Long.class.isAssignableFrom(fieldType) || long.class.isAssignableFrom(fieldType)) {
        property = new LongProperty();
    } else if (BigDecimal.class.isAssignableFrom(fieldType)) {
        property = new DecimalProperty();
    } else if (XMLGregorianCalendar.class.isAssignableFrom(fieldType)) {
        property = new DateTimeProperty();
    } else if (Boolean.class.isAssignableFrom(fieldType) || boolean.class.isAssignableFrom(fieldType)) {
        property = new BooleanProperty();
    } else if (Collection.class.isAssignableFrom(fieldType)) {
        property = new ArrayProperty(new StringProperty());
    } else if (fieldType.getAnnotation(XmlEnum.class) != null) {
        /*
             * Enums are a string property which have enum constants
             */
        List<String> enums = new ArrayList<>();
        for (Enum<?> anEnum : (Enum<?>[]) fieldType.getEnumConstants()) {
            enums.add(anEnum.name());
        }
        property = new StringProperty()._enum(enums);
    } else /*
         * Recursively process complex objects which is a XmlType
         */
    if (fieldType.getAnnotation(XmlType.class) != null) {
        processDefinitionClass(fieldType);
        property = new RefProperty(fieldType.getAnnotation(XmlType.class).name());
    } else {
        // Default to a string property in other cases.
        property = new StringProperty();
    }
    log.debug("Field type \"" + fieldType.getName() + "\" is a property type \"" + property.getType() + "\".");
    return property;
}
Also used : XmlEnum(javax.xml.bind.annotation.XmlEnum) IntegerProperty(io.swagger.models.properties.IntegerProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) BooleanProperty(io.swagger.models.properties.BooleanProperty) DateTimeProperty(io.swagger.models.properties.DateTimeProperty) StringProperty(io.swagger.models.properties.StringProperty) DecimalProperty(io.swagger.models.properties.DecimalProperty) BigDecimal(java.math.BigDecimal) XmlType(javax.xml.bind.annotation.XmlType) RefProperty(io.swagger.models.properties.RefProperty) LongProperty(io.swagger.models.properties.LongProperty) ArrayList(java.util.ArrayList) List(java.util.List) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) DateTimeProperty(io.swagger.models.properties.DateTimeProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) BooleanProperty(io.swagger.models.properties.BooleanProperty) LongProperty(io.swagger.models.properties.LongProperty) RefProperty(io.swagger.models.properties.RefProperty) DecimalProperty(io.swagger.models.properties.DecimalProperty) Property(io.swagger.models.properties.Property)

Example 65 with ArrayProperty

use of io.swagger.models.properties.ArrayProperty in project herd by FINRAOS.

the class DefinitionGenerator method processField.

/**
 * Processes a Field of a model class which can be converted into a Swagger definition property. The property is added into the given model. This method may
 * be called recursively.
 *
 * @param field the field to process.
 * @param model model the model.
 *
 * @throws MojoExecutionException if any problems were encountered.
 */
private void processField(Field field, ModelImpl model) throws MojoExecutionException {
    log.debug("Processing field \"" + field.getName() + "\".");
    if (!Modifier.isStatic(field.getModifiers())) {
        Property property;
        Class<?> fieldClass = field.getType();
        if (Collection.class.isAssignableFrom(fieldClass)) {
            property = new ArrayProperty(getPropertyFromType(FieldUtils.getCollectionType(field)));
        } else {
            property = getPropertyFromType(fieldClass);
        }
        // Set the required field based on the XmlElement that comes from the XSD.
        XmlElement xmlElement = field.getAnnotation(XmlElement.class);
        if (xmlElement != null) {
            property.setRequired(xmlElement.required());
        }
        if (xsdParser != null) {
            property.setDescription(xsdParser.getAnnotation(model.getName(), field.getName()));
        }
        // Set the property on model.
        model.property(field.getName(), property);
    }
}
Also used : ArrayProperty(io.swagger.models.properties.ArrayProperty) XmlElement(javax.xml.bind.annotation.XmlElement) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) DateTimeProperty(io.swagger.models.properties.DateTimeProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) BooleanProperty(io.swagger.models.properties.BooleanProperty) LongProperty(io.swagger.models.properties.LongProperty) RefProperty(io.swagger.models.properties.RefProperty) DecimalProperty(io.swagger.models.properties.DecimalProperty) Property(io.swagger.models.properties.Property)

Aggregations

ArrayProperty (io.swagger.models.properties.ArrayProperty)82 Property (io.swagger.models.properties.Property)62 StringProperty (io.swagger.models.properties.StringProperty)42 RefProperty (io.swagger.models.properties.RefProperty)39 Test (org.testng.annotations.Test)36 MapProperty (io.swagger.models.properties.MapProperty)25 Model (io.swagger.models.Model)23 IntegerProperty (io.swagger.models.properties.IntegerProperty)23 LongProperty (io.swagger.models.properties.LongProperty)14 ModelImpl (io.swagger.models.ModelImpl)13 BooleanProperty (io.swagger.models.properties.BooleanProperty)12 DoubleProperty (io.swagger.models.properties.DoubleProperty)12 RefModel (io.swagger.models.RefModel)10 FloatProperty (io.swagger.models.properties.FloatProperty)10 Operation (io.swagger.models.Operation)9 ByteArrayProperty (io.swagger.models.properties.ByteArrayProperty)9 DecimalProperty (io.swagger.models.properties.DecimalProperty)9 HashMap (java.util.HashMap)9 Response (io.swagger.models.Response)7 Swagger (io.swagger.models.Swagger)7