Search in sources :

Example 46 with RefProperty

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

the class PostParamTest method findPostOperationWithObjectsCollection.

@Test(description = "find a Post operation with collection of objects")
public void findPostOperationWithObjectsCollection() {
    Path petPath = getPath("collectionOfObjects");
    assertNotNull(petPath);
    Operation petPost = petPath.getPost();
    assertNotNull(petPost);
    assertEquals(petPost.getParameters().size(), 1);
    BodyParameter petPostBodyParam = (BodyParameter) petPost.getParameters().get(0);
    assertEquals(petPostBodyParam.getName(), BODY);
    Model inputModel = petPostBodyParam.getSchema();
    assertTrue(inputModel instanceof ArrayModel);
    ArrayModel ap = (ArrayModel) inputModel;
    Property inputSchema = ap.getItems();
    assertTrue(inputSchema instanceof RefProperty);
    RefProperty rm = (RefProperty) inputSchema;
    assertEquals(rm.getSimpleRef(), PET);
}
Also used : Path(io.swagger.models.Path) Model(io.swagger.models.Model) ArrayModel(io.swagger.models.ArrayModel) Operation(io.swagger.models.Operation) BodyParameter(io.swagger.models.parameters.BodyParameter) ArrayModel(io.swagger.models.ArrayModel) StringProperty(io.swagger.models.properties.StringProperty) RefProperty(io.swagger.models.properties.RefProperty) Property(io.swagger.models.properties.Property) RefProperty(io.swagger.models.properties.RefProperty) Test(org.testng.annotations.Test)

Example 47 with RefProperty

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

the class ChildTypeTest method testChildTypeResponse.

@Test(description = "Tests child type response schema ref is correctly set up")
public void testChildTypeResponse() {
    Operation op = swagger.getPath("/childType/testChildTypeResponse").getGet();
    Property schema = op.getResponses().get("200").getSchema();
    assertEquals(schema.getClass().getName(), RefProperty.class.getName());
    assertEquals(((RefProperty) schema).getSimpleRef(), "Sub1Bean");
}
Also used : Operation(io.swagger.models.Operation) RefProperty(io.swagger.models.properties.RefProperty) Property(io.swagger.models.properties.Property) RefProperty(io.swagger.models.properties.RefProperty) Test(org.testng.annotations.Test)

Example 48 with RefProperty

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

the class RefPropertyTest method identifyRefFormats.

@Test(description = "it should correctly identify ref formats")
public void identifyRefFormats() {
    assertRefFormat(new RefProperty("http://my.company.com/models/model.json"), RefFormat.URL);
    assertRefFormat(new RefProperty("http://my.company.com/models/model.json#/thing"), RefFormat.URL);
    assertRefFormat(new RefProperty("./models/model.json"), RefFormat.RELATIVE);
    assertRefFormat(new RefProperty("./models/model.json#/thing"), RefFormat.RELATIVE);
    assertRefFormat(new RefProperty("#/definitions/foo"), RefFormat.INTERNAL);
    assertRefFormat(new RefProperty("foo"), RefFormat.INTERNAL);
}
Also used : RefProperty(io.swagger.models.properties.RefProperty) Test(org.testng.annotations.Test)

Example 49 with RefProperty

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

the class RefPropertyTest method testEquals.

@Test
public void testEquals() {
    final RefProperty prop1 = new RefProperty();
    prop1.setName(PROP_1);
    prop1.setRequired(true);
    final RefProperty prop2 = new RefProperty();
    prop2.setName(PROP_2);
    assertNotEquals(prop1, prop2);
    prop2.setName(PROP_1);
    prop2.setRequired(true);
    assertEquals(prop1, prop2);
}
Also used : RefProperty(io.swagger.models.properties.RefProperty) Test(org.testng.annotations.Test)

Example 50 with RefProperty

use of io.swagger.models.properties.RefProperty 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)

Aggregations

RefProperty (io.swagger.models.properties.RefProperty)74 Property (io.swagger.models.properties.Property)50 ArrayProperty (io.swagger.models.properties.ArrayProperty)46 StringProperty (io.swagger.models.properties.StringProperty)35 Test (org.testng.annotations.Test)35 Model (io.swagger.models.Model)23 MapProperty (io.swagger.models.properties.MapProperty)20 ModelImpl (io.swagger.models.ModelImpl)18 Response (io.swagger.models.Response)18 IntegerProperty (io.swagger.models.properties.IntegerProperty)18 Operation (io.swagger.models.Operation)17 RefModel (io.swagger.models.RefModel)17 LongProperty (io.swagger.models.properties.LongProperty)14 Path (io.swagger.models.Path)12 Swagger (io.swagger.models.Swagger)12 ArrayList (java.util.ArrayList)12 HashMap (java.util.HashMap)12 ArrayModel (io.swagger.models.ArrayModel)11 BodyParameter (io.swagger.models.parameters.BodyParameter)11 Map (java.util.Map)11