Search in sources :

Example 81 with Operation

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

the class ReaderFixFor1959Test method readAndCompare.

private void readAndCompare(Set<Class<?>> testClasses, Set<String> expectedOperationIds) {
    Swagger swagger = new Swagger();
    new Reader(swagger).read(testClasses);
    Set<String> actualOperationIds = new HashSet<String>();
    for (Path path : swagger.getPaths().values()) {
        for (Operation operation : path.getOperations()) {
            actualOperationIds.add(operation.getOperationId());
        }
    }
    Assert.assertEquals(actualOperationIds, expectedOperationIds);
}
Also used : Path(io.swagger.models.Path) Swagger(io.swagger.models.Swagger) Operation(io.swagger.models.Operation) HashSet(java.util.HashSet)

Example 82 with Operation

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

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

the class PostParamTest method findAPostOperationWithStringsList.

@Test(description = "find a Post operation with list of strings")
public void findAPostOperationWithStringsList() {
    Path petPath = getPath("listOfStrings");
    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 StringProperty);
}
Also used : Path(io.swagger.models.Path) Model(io.swagger.models.Model) ArrayModel(io.swagger.models.ArrayModel) StringProperty(io.swagger.models.properties.StringProperty) 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) Test(org.testng.annotations.Test)

Example 84 with Operation

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

the class ReaderTest method scanDeclaredExceptions.

@Test(description = "scan resource with annotated exception")
public void scanDeclaredExceptions() {
    Swagger swagger = getSwagger(ResourceWithCustomException.class);
    assertNotNull(swagger);
    Operation operation = getGet(swagger, "/{id}");
    assertEquals(operation.getResponses().size(), 3);
    assertTrue(operation.getResponses().containsKey("200"));
    assertTrue(operation.getResponses().containsKey("400"));
    assertTrue(operation.getResponses().containsKey("404"));
}
Also used : Swagger(io.swagger.models.Swagger) Operation(io.swagger.models.Operation) Test(org.testng.annotations.Test)

Example 85 with Operation

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

the class SimpleReaderTest method verifyTopLevelAuthorization.

@Test(description = "verify top-level auth #1041")
public void verifyTopLevelAuthorization() {
    Swagger swagger = getSwagger(Resource1041.class);
    Operation path1 = getGet(swagger, "/external/info/path1");
    List<Map<String, List<String>>> security1 = path1.getSecurity();
    assertEquals(security1.size(), 1);
    assertNotNull(security1.get(0).get("my_auth"));
    Operation path2 = getGet(swagger, "/external/info/path2");
    List<Map<String, List<String>>> security2 = path2.getSecurity();
    assertEquals(security2.size(), 1);
    assertNotNull(security2.get(0).get("your_auth"));
}
Also used : Swagger(io.swagger.models.Swagger) Operation(io.swagger.models.Operation) NicknamedOperation(io.swagger.resources.NicknamedOperation) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) 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