Search in sources :

Example 41 with Operation

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

the class GenericsTest method checkCollectionsOfObjectsAsBodyParameter.

@Test(description = "check collection of objects as body parameter")
public void checkCollectionsOfObjectsAsBodyParameter() {
    Operation op = getOperation("testObjectsInBody");
    assertEquals(op.getParameters().size(), 1);
    BodyParameter p = getBodyParameter(op, 0);
    ArrayModel objArray = (ArrayModel) p.getSchema();
    assertEquals(((RefProperty) objArray.getItems()).getSimpleRef(), "Tag");
}
Also used : Operation(io.swagger.models.Operation) BodyParameter(io.swagger.models.parameters.BodyParameter) ArrayModel(io.swagger.models.ArrayModel) Test(org.testng.annotations.Test)

Example 42 with Operation

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

Example 43 with Operation

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

the class GenericsTest method checkGenericResult.

@Test(description = "check generic result")
public void checkGenericResult() {
    Operation op = swagger.getPath("/generics/testGenericResult").getGet();
    Property schema = op.getResponses().get("200").getSchema();
    assertEquals(schema.getClass().getName(), RefProperty.class.getName());
    assertEquals(((RefProperty) schema).getSimpleRef(), "GenericListWrapperTag");
    Property entries = getProperty("GenericListWrapperTag", "entries");
    assertNotEquals(entries, null);
    assertEquals(entries.getClass().getName(), ArrayProperty.class.getName());
    Property items = ((ArrayProperty) entries).getItems();
    assertEquals(items.getClass().getName(), RefProperty.class.getName());
    assertEquals(((RefProperty) items).getSimpleRef(), "Tag");
}
Also used : ArrayProperty(io.swagger.models.properties.ArrayProperty) 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) RefProperty(io.swagger.models.properties.RefProperty) Test(org.testng.annotations.Test)

Example 44 with Operation

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

the class GenericsTest method checkCollectionsOfEnumerations.

@Test(description = "check collections of enumerations")
public void checkCollectionsOfEnumerations() {
    Operation op = getOperation("testEnumContainers");
    assertEquals(op.getParameters().size(), 5);
    testEnumCollection(getQueryParameter(op, 0), "set");
    testEnumCollection(getQueryParameter(op, 1), "list");
    testCollection(getQueryParameter(op, 2), "list2D", "string", null);
    testEnumCollection(getQueryParameter(op, 3), "array");
    QueryParameter scalar = getQueryParameter(op, 4);
    testScalar(scalar, "scalar", "string", null);
    assertEquals(scalar.getEnum(), enumValues);
}
Also used : QueryParameter(io.swagger.models.parameters.QueryParameter) Operation(io.swagger.models.Operation) Test(org.testng.annotations.Test)

Example 45 with Operation

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

the class HiddenParametersScannerTest method shouldScanMethodWithSomeParamsHidden.

@Test
public void shouldScanMethodWithSomeParamsHidden() {
    Operation get = getGet("/some-hidden/{id}");
    assertNotNull(get);
    List<Parameter> parameters = get.getParameters();
    assertEquals(parameters.size(), 3);
    assertEquals(parameters.get(0).getIn(), "cookie");
    assertEquals(parameters.get(1).getIn(), "header");
    assertEquals(parameters.get(2).getIn(), "query");
}
Also used : Parameter(io.swagger.models.parameters.Parameter) Operation(io.swagger.models.Operation) Test(org.testng.annotations.Test)

Aggregations

Operation (io.swagger.models.Operation)118 Test (org.testng.annotations.Test)80 Swagger (io.swagger.models.Swagger)45 Path (io.swagger.models.Path)39 BodyParameter (io.swagger.models.parameters.BodyParameter)27 Property (io.swagger.models.properties.Property)24 Response (io.swagger.models.Response)23 Parameter (io.swagger.models.parameters.Parameter)20 RefProperty (io.swagger.models.properties.RefProperty)16 ArrayModel (io.swagger.models.ArrayModel)15 Model (io.swagger.models.Model)14 QueryParameter (io.swagger.models.parameters.QueryParameter)13 StringProperty (io.swagger.models.properties.StringProperty)13 HashMap (java.util.HashMap)13 ArrayProperty (io.swagger.models.properties.ArrayProperty)12 ReaderContext (io.swagger.servlet.ReaderContext)12 PathParameter (io.swagger.models.parameters.PathParameter)11 ArrayList (java.util.ArrayList)11 MapProperty (io.swagger.models.properties.MapProperty)10 NicknamedOperation (io.swagger.resources.NicknamedOperation)10