Search in sources :

Example 21 with Parameter

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

the class SimpleReaderTest method scanSimpleResource.

@Test(description = "scan a simple resource")
public void scanSimpleResource() {
    Swagger swagger = getSwagger(SimpleResource.class);
    assertEquals(swagger.getPaths().size(), 3);
    Operation get = getGet(swagger, "/{id}");
    assertNotNull(get);
    assertEquals(get.getParameters().size(), 2);
    PathParameter param1 = (PathParameter) get.getParameters().get(0);
    assertEquals(param1.getIn(), "path");
    assertEquals(param1.getName(), "id");
    assertTrue(param1.getRequired());
    assertEquals(param1.getDescription(), "sample param data");
    assertEquals(param1.getDefaultValue(), "5");
    Parameter param2 = get.getParameters().get(1);
    assertEquals(param2.getIn(), "query");
    assertEquals(param2.getName(), "limit");
    assertFalse(param2.getRequired());
    assertNull(param2.getDescription());
    List<Parameter> params = getPutParameters(swagger, "/{bodyparams}");
    BodyParameter bodyParam1 = (BodyParameter) params.get(0);
    assertEquals(bodyParam1.getIn(), "body");
    assertEquals(bodyParam1.getName(), "body");
    assertTrue(bodyParam1.getRequired());
    BodyParameter bodyParam2 = (BodyParameter) params.get(1);
    assertEquals(bodyParam2.getIn(), "body");
    assertEquals(bodyParam2.getName(), "body");
    assertFalse(bodyParam2.getRequired());
}
Also used : Swagger(io.swagger.models.Swagger) SerializableParameter(io.swagger.models.parameters.SerializableParameter) PathParameter(io.swagger.models.parameters.PathParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) BodyParameter(io.swagger.models.parameters.BodyParameter) Operation(io.swagger.models.Operation) NicknamedOperation(io.swagger.resources.NicknamedOperation) BodyParameter(io.swagger.models.parameters.BodyParameter) PathParameter(io.swagger.models.parameters.PathParameter) Test(org.testng.annotations.Test)

Example 22 with Parameter

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

the class SimpleReaderTest method scanResourceWithParamEnums.

@Test(description = "scan a resource with param enums")
public void scanResourceWithParamEnums() {
    Swagger swagger = getSwagger(ResourceWithEnums.class);
    SerializableParameter param = (SerializableParameter) getGetParameters(swagger, "/{id}").get(2);
    List<String> _enum = param.getEnum();
    assertEquals(_enum, Arrays.asList("a", "b", "c", "d", "e"));
    List<Parameter> checkEnumHandling = getGetParameters(swagger, "/checkEnumHandling/{v0}");
    List<String> allEnumValues = Lists.newArrayList(Collections2.transform(Arrays.asList(TestEnum.values()), Functions.toStringFunction()));
    SerializableParameter v0 = (SerializableParameter) checkEnumHandling.get(0);
    assertEquals(v0.getEnum(), allEnumValues);
    SerializableParameter v1 = (SerializableParameter) checkEnumHandling.get(1);
    assertEquals(((StringProperty) v1.getItems()).getEnum(), allEnumValues);
    SerializableParameter v2 = (SerializableParameter) checkEnumHandling.get(2);
    assertEquals(((StringProperty) v2.getItems()).getEnum(), allEnumValues);
    SerializableParameter v3 = (SerializableParameter) checkEnumHandling.get(3);
    assertEquals(v3.getEnum(), Arrays.asList("A", "B", "C"));
}
Also used : SerializableParameter(io.swagger.models.parameters.SerializableParameter) Swagger(io.swagger.models.Swagger) SerializableParameter(io.swagger.models.parameters.SerializableParameter) PathParameter(io.swagger.models.parameters.PathParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) BodyParameter(io.swagger.models.parameters.BodyParameter) Test(org.testng.annotations.Test)

Example 23 with Parameter

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

the class SimpleReaderTest method scanClassWithExampleQuery.

@Test(description = "scan a resource with query param example")
public void scanClassWithExampleQuery() {
    Swagger swagger = getSwagger(ClassWithExamplePost.class);
    Parameter param = swagger.getPaths().get("/external/info").getGet().getParameters().get(0);
    QueryParameter bp = (QueryParameter) param;
    assertNotNull(bp.getExample());
    Object value = bp.getExample();
    assertEquals("a,b,c", value);
}
Also used : QueryParameter(io.swagger.models.parameters.QueryParameter) Swagger(io.swagger.models.Swagger) SerializableParameter(io.swagger.models.parameters.SerializableParameter) PathParameter(io.swagger.models.parameters.PathParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) BodyParameter(io.swagger.models.parameters.BodyParameter) Test(org.testng.annotations.Test)

Example 24 with Parameter

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

the class SimpleReaderTest method scanClassWithImplicitExamplePost.

@Test(description = "scan a resource with operation implicit post example")
public void scanClassWithImplicitExamplePost() {
    Swagger swagger = getSwagger(ClassWithExamplePost.class);
    Parameter param = swagger.getPaths().get("/external/info2").getPost().getParameters().get(0);
    BodyParameter bp = (BodyParameter) param;
    assertNotNull(bp.getExamples());
    assertTrue(bp.getExamples().size() == 1);
    String value = bp.getExamples().get("application/json");
    assertEquals("[\"a\",\"b\"]", value);
}
Also used : Swagger(io.swagger.models.Swagger) SerializableParameter(io.swagger.models.parameters.SerializableParameter) PathParameter(io.swagger.models.parameters.PathParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) BodyParameter(io.swagger.models.parameters.BodyParameter) BodyParameter(io.swagger.models.parameters.BodyParameter) Test(org.testng.annotations.Test)

Example 25 with Parameter

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

the class SimpleReaderTest method scanClassWithExamplePost.

@Test(description = "scan a resource with operation post example")
public void scanClassWithExamplePost() {
    Swagger swagger = getSwagger(ClassWithExamplePost.class);
    Parameter param = swagger.getPaths().get("/external/info").getPost().getParameters().get(0);
    BodyParameter bp = (BodyParameter) param;
    assertNotNull(bp.getExamples());
    assertTrue(bp.getExamples().size() == 1);
    String value = bp.getExamples().get("application/json");
    assertEquals("[\"a\",\"b\"]", value);
}
Also used : Swagger(io.swagger.models.Swagger) SerializableParameter(io.swagger.models.parameters.SerializableParameter) PathParameter(io.swagger.models.parameters.PathParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) BodyParameter(io.swagger.models.parameters.BodyParameter) BodyParameter(io.swagger.models.parameters.BodyParameter) Test(org.testng.annotations.Test)

Aggregations

Parameter (io.swagger.models.parameters.Parameter)186 BodyParameter (io.swagger.models.parameters.BodyParameter)102 QueryParameter (io.swagger.models.parameters.QueryParameter)101 PathParameter (io.swagger.models.parameters.PathParameter)89 Test (org.testng.annotations.Test)80 HeaderParameter (io.swagger.models.parameters.HeaderParameter)66 Swagger (io.swagger.models.Swagger)63 FormParameter (io.swagger.models.parameters.FormParameter)52 Operation (io.swagger.models.Operation)31 SerializableParameter (io.swagger.models.parameters.SerializableParameter)29 Test (org.junit.Test)25 Type (java.lang.reflect.Type)23 ArrayList (java.util.ArrayList)23 Path (io.swagger.models.Path)19 Annotation (java.lang.annotation.Annotation)17 JavaType (com.fasterxml.jackson.databind.JavaType)14 Response (io.swagger.models.Response)14 Method (java.lang.reflect.Method)14 Property (io.swagger.models.properties.Property)13 ModelImpl (io.swagger.models.ModelImpl)12