Search in sources :

Example 86 with Operation

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

the class SimpleReaderTest method scanSimpleSelfReferencingSubResource.

@Test(description = "scan a simple self-referencing subresource")
public void scanSimpleSelfReferencingSubResource() {
    DefaultReaderConfig config = new DefaultReaderConfig();
    config.setScanAllResources(true);
    Swagger swagger = new Reader(new Swagger(), config).read(SimpleSelfReferencingSubResource.class);
    assertEquals(swagger.getPaths().size(), 4);
    // these two paths are directly reachable without passing thru a recursive reference
    Operation retrieve = getGet(swagger, "/sub");
    assertNotNull(retrieve);
    assertEquals(retrieve.getParameters().size(), 0);
    retrieve = getGet(swagger, "/sub/leaf");
    assertNotNull(retrieve);
    assertEquals(retrieve.getParameters().size(), 0);
    retrieve = getGet(swagger, "/sub/recurse2");
    assertNotNull(retrieve);
    assertEquals(retrieve.getParameters().size(), 0);
    retrieve = getGet(swagger, "/sub/recurse2/leaf");
    assertNotNull(retrieve);
    assertEquals(retrieve.getParameters().size(), 0);
}
Also used : Swagger(io.swagger.models.Swagger) Reader(io.swagger.jaxrs.Reader) DefaultReaderConfig(io.swagger.jaxrs.config.DefaultReaderConfig) Operation(io.swagger.models.Operation) NicknamedOperation(io.swagger.resources.NicknamedOperation) Test(org.testng.annotations.Test)

Example 87 with Operation

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

the class SimpleReaderTest method scanResourceWithGenerics.

@Test(description = "scan a resource with generics per 653")
public void scanResourceWithGenerics() {
    Swagger swagger = getSwagger(Resource653.class);
    Operation get = getGet(swagger, "/external/info");
    assertNotNull(get);
    Map<String, Response> responses = get.getResponses();
    assertNotNull(responses);
    Response response = responses.get("default");
    assertNotNull(response);
    assertNull(response.getSchema());
}
Also used : ResourceWithResponse(io.swagger.resources.ResourceWithResponse) Response(io.swagger.models.Response) Swagger(io.swagger.models.Swagger) Operation(io.swagger.models.Operation) NicknamedOperation(io.swagger.resources.NicknamedOperation) Test(org.testng.annotations.Test)

Example 88 with Operation

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

the class ReaderTest method scanMethods.

@Test(description = "scan methods")
public void scanMethods() {
    Method[] methods = SimpleMethods.class.getMethods();
    Reader reader = new Reader(new Swagger());
    for (Method method : methods) {
        if (isValidRestPath(method)) {
            Operation operation = reader.parseMethod(method);
            assertNotNull(operation);
        }
    }
}
Also used : Swagger(io.swagger.models.Swagger) Reader(io.swagger.jaxrs.Reader) Method(java.lang.reflect.Method) ResourceWithDeprecatedMethod(io.swagger.resources.ResourceWithDeprecatedMethod) Operation(io.swagger.models.Operation) Test(org.testng.annotations.Test)

Example 89 with Operation

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

the class ReaderTest method scanOverriddenMethod.

@Test(description = "scan overridden method in descendantResource")
public void scanOverriddenMethod() {
    Swagger swagger = getSwagger(DescendantResource.class);
    Operation overriddenMethodWithTypedParam = getGet(swagger, "/pet/{petId1}");
    assertNotNull(overriddenMethodWithTypedParam);
    assertEquals(overriddenMethodWithTypedParam.getParameters().get(0).getDescription(), "ID of pet to return child");
    Operation methodWithoutTypedParam = getGet(swagger, "/pet/{petId2}");
    assertNotNull(methodWithoutTypedParam);
    Operation overriddenMethodWithoutTypedParam = getGet(swagger, "/pet/{petId3}");
    assertNotNull(overriddenMethodWithoutTypedParam);
    Operation methodWithoutTypedParamFromDescendant = getGet(swagger, "/pet/{petId4}");
    assertNotNull(methodWithoutTypedParamFromDescendant);
    Operation methodFromInterface = getGet(swagger, "/pet/{petId5}");
    assertNotNull(methodFromInterface);
}
Also used : Swagger(io.swagger.models.Swagger) Operation(io.swagger.models.Operation) Test(org.testng.annotations.Test)

Example 90 with Operation

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

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