Search in sources :

Example 71 with Operation

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

the class SimpleScannerWithDecoratorExtensionTest method scanSimpleResourceWithoutDecorator.

/**
     * Test for method annotated without vendor annotation.
     */
@Test(description = "scan a simple resource without custom decorator")
public void scanSimpleResourceWithoutDecorator() {
    final Swagger swagger = getSwagger(SimpleResourceWithVendorAnnotation.class);
    assertEquals(swagger.getPaths().size(), 2);
    final Operation get = getGet(swagger, "/{id}/value");
    assertNotNull(get);
    assertEquals(get.getParameters().size(), 0);
    final Response response = get.getResponses().get(RESPONSE_STATUS_401);
    assertNull(response);
}
Also used : Response(io.swagger.models.Response) Swagger(io.swagger.models.Swagger) Operation(io.swagger.models.Operation) Test(org.testng.annotations.Test)

Example 72 with Operation

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

the class SubResourceReaderTest method readAnotherResourceWithSubresources.

@Test(description = "scan another resource with subresources")
public void readAnotherResourceWithSubresources() {
    final Swagger swagger = getSwagger(TestResource.class);
    final Operation get = getGet(swagger, "/test/more/otherStatus");
    assertEquals(get.getOperationId(), "otherStatus");
    final Parameter qp = get.getParameters().get(0);
    assertEquals(qp.getIn(), "query");
    assertEquals(qp.getName(), "qp");
    assertTrue(get.getProduces().containsAll(Arrays.asList("application/json", "application/xml")));
    assertEquals(swagger.getPaths().keySet().size(), 2);
}
Also used : Swagger(io.swagger.models.Swagger) BodyParameter(io.swagger.models.parameters.BodyParameter) Parameter(io.swagger.models.parameters.Parameter) Operation(io.swagger.models.Operation) Test(org.testng.annotations.Test)

Example 73 with Operation

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

the class RegexPathParamTest method scanSimpleResource.

@Test(description = "scan a simple resource")
public void scanSimpleResource() {
    Swagger swagger = new Reader(new Swagger()).read(RegexPathParamResource.class);
    Operation get = swagger.getPaths().get("/{report_type}").getGet();
    Parameter param = get.getParameters().get(0);
    assertEquals(param.getName(), "report_type");
    assertEquals(param.getPattern(), "[aA-zZ]+");
}
Also used : Swagger(io.swagger.models.Swagger) Reader(io.swagger.jaxrs.Reader) Parameter(io.swagger.models.parameters.Parameter) Operation(io.swagger.models.Operation) Test(org.testng.annotations.Test)

Example 74 with Operation

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

the class SimpleReaderTest method scanResourceWithBodyParameters.

@Test(description = "scan a resource with body parameters")
public void scanResourceWithBodyParameters() {
    Swagger swagger = getSwagger(ResourceWithBodyParams.class);
    BodyParameter param = (BodyParameter) getPostParameters(swagger, "/testShort").get(0);
    assertEquals(param.getDescription(), "a short input");
    ModelImpl schema = (ModelImpl) param.getSchema();
    assertEquals(schema.getType(), "integer");
    assertEquals(schema.getFormat(), "int32");
    assertEquals(swagger.getDefinitions().keySet(), Arrays.asList("Tag"));
    testString(swagger, "/testApiString", "input", "String parameter");
    testString(swagger, "/testString", "body", null);
    testObject(swagger, "/testApiObject", "input", "Object parameter");
    testObject(swagger, "/testObject", "body", null);
    List<Operation> operations = new ArrayList<Operation>();
    for (Path item : swagger.getPaths().values()) {
        Operation op = item.getPost();
        if (op.getOperationId().startsWith("testPrimitive")) {
            operations.add(op);
        }
    }
    assertEquals(operations.size(), 16);
    for (Operation item : operations) {
        assertEquals(item.getParameters().size(), 1);
    }
}
Also used : Path(io.swagger.models.Path) Swagger(io.swagger.models.Swagger) ArrayList(java.util.ArrayList) Operation(io.swagger.models.Operation) NicknamedOperation(io.swagger.resources.NicknamedOperation) BodyParameter(io.swagger.models.parameters.BodyParameter) ModelImpl(io.swagger.models.ModelImpl) Test(org.testng.annotations.Test)

Example 75 with Operation

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

the class GenericsTest method checkCollectionsOfStringsAsBodyParameter.

@Test(description = "check collection of strings as body parameter")
public void checkCollectionsOfStringsAsBodyParameter() {
    Operation op = getOperation("testStringsInBody");
    assertEquals(op.getParameters().size(), 1);
    BodyParameter p = getBodyParameter(op, 0);
    ArrayModel strArray = (ArrayModel) p.getSchema();
    assertEquals(strArray.getItems().getType(), "string");
}
Also used : Operation(io.swagger.models.Operation) BodyParameter(io.swagger.models.parameters.BodyParameter) ArrayModel(io.swagger.models.ArrayModel) 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