Search in sources :

Example 6 with RefProperty

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

the class PostParamTest method findAPostOperationWithObjectsArray.

@Test(description = "find a Post operation with an array of objects")
public void findAPostOperationWithObjectsArray() {
    Path petPath = getPath("arrayOfObjects");
    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 7 with RefProperty

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

the class PostParamTest method findPostOperationWithObjectsList.

@Test(description = "find a Post operation with list of objects")
public void findPostOperationWithObjectsList() {
    Path petPath = getPath("listOfObjects");
    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 8 with RefProperty

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

the class ChildTypeTest method testChildTypeResponseOnOperation.

@Test(description = "Tests child type response schema ref is correctly set up when specified on the operation")
public void testChildTypeResponseOnOperation() {
    Operation op = swagger.getPath("/childType/testChildTypeResponseOnOperation").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 9 with RefProperty

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

the class DefaultParameterExtension method enforcePrimitive.

private Property enforcePrimitive(Property in, int level) {
    if (in instanceof RefProperty) {
        return new StringProperty();
    }
    if (in instanceof ArrayProperty) {
        if (level == 0) {
            final ArrayProperty array = (ArrayProperty) in;
            array.setItems(enforcePrimitive(array.getItems(), level + 1));
        } else {
            return new StringProperty();
        }
    }
    return in;
}
Also used : ArrayProperty(io.swagger.models.properties.ArrayProperty) StringProperty(io.swagger.models.properties.StringProperty) RefProperty(io.swagger.models.properties.RefProperty)

Example 10 with RefProperty

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

the class GenericsTest method checkParametersOfGenericTypes.

@Test(description = "check parameters of generic types")
public void checkParametersOfGenericTypes() {
    Set<String> genericTypes = new HashSet(Arrays.asList("GenericTypeString", "GenericTypeUUID", "GenericTypeGenericTypeString", "RenamedGenericTypeString", "RenamedGenericTypeRenamedGenericTypeString"));
    assertTrue(swagger.getDefinitions().keySet().containsAll(genericTypes));
    Operation opString = getOperation("testGenericType");
    testGenericType(opString, "GenericTypeString");
    Property strValue = getProperty("GenericTypeString", "value");
    assertNotEquals(strValue, null);
    assertEquals(strValue.getClass().getName(), StringProperty.class.getName());
    Operation opUUID = getOperation("testStringBasedGenericType");
    testGenericType(opUUID, "GenericTypeUUID");
    Property uuidValue = getProperty("GenericTypeUUID", "value");
    assertNotEquals(uuidValue, null);
    assertEquals(uuidValue.getClass().getName(), UUIDProperty.class.getName());
    Operation opComplex = getOperation("testComplexGenericType");
    testGenericType(opComplex, "GenericTypeGenericTypeString");
    Property complexValue = getProperty("GenericTypeGenericTypeString", "value");
    assertNotEquals(complexValue, null);
    assertEquals(complexValue.getClass().getName(), RefProperty.class.getName());
    assertEquals(((RefProperty) complexValue).getSimpleRef(), "GenericTypeString");
    Operation opRenamed = getOperation("testRenamedGenericType");
    testGenericType(opRenamed, "RenamedGenericTypeRenamedGenericTypeString");
    Property renamedComplexValue = getProperty("RenamedGenericTypeRenamedGenericTypeString", "value");
    assertNotEquals(renamedComplexValue, null);
    assertTrue(renamedComplexValue instanceof RefProperty);
    assertEquals(((RefProperty) renamedComplexValue).getSimpleRef(), "RenamedGenericTypeString");
}
Also used : UUIDProperty(io.swagger.models.properties.UUIDProperty) StringProperty(io.swagger.models.properties.StringProperty) Operation(io.swagger.models.Operation) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) RefProperty(io.swagger.models.properties.RefProperty) Property(io.swagger.models.properties.Property) UUIDProperty(io.swagger.models.properties.UUIDProperty) HashSet(java.util.HashSet) RefProperty(io.swagger.models.properties.RefProperty) Test(org.testng.annotations.Test)

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