Search in sources :

Example 16 with BodyParameter

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

the class ScannerTest method scanBeanParamResource.

@Test(description = "scan a bean param resource")
public void scanBeanParamResource() {
    final Swagger swagger = getSwagger(ResourceWithBeanParams.class);
    final List<Parameter> params = getParameters(swagger, "/bean/{id}");
    final HeaderParameter headerParam1 = (HeaderParameter) params.get(0);
    assertEquals(headerParam1.getDefaultValue(), 1);
    assertEquals(headerParam1.getName(), "test order annotation 1");
    final HeaderParameter headerParam2 = (HeaderParameter) params.get(1);
    assertEquals(headerParam2.getDefaultValue(), 2);
    assertEquals(headerParam2.getName(), "test order annotation 2");
    final QueryParameter priority1 = (QueryParameter) params.get(2);
    assertNull(priority1.getDefaultValue());
    assertEquals(priority1.getName(), "test priority 1");
    final QueryParameter priority2 = (QueryParameter) params.get(3);
    assertEquals(priority2.getDefaultValue(), 4);
    assertEquals(priority2.getName(), "test priority 2");
    final ModelImpl bodyParam1 = (ModelImpl) ((BodyParameter) params.get(4)).getSchema();
    assertEquals(bodyParam1.getDefaultValue(), "bodyParam");
}
Also used : QueryParameter(io.swagger.models.parameters.QueryParameter) Swagger(io.swagger.models.Swagger) BodyParameter(io.swagger.models.parameters.BodyParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) HeaderParameter(io.swagger.models.parameters.HeaderParameter) HeaderParameter(io.swagger.models.parameters.HeaderParameter) ModelImpl(io.swagger.models.ModelImpl) Test(org.testng.annotations.Test)

Example 17 with BodyParameter

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

the class SimpleReaderTest method scanClassWithExamplePostClass.

@Test(description = "scan a resource with operation post example (dataTypeClass)")
public void scanClassWithExamplePostClass() {
    Swagger swagger = getSwagger(ClassWithExamplePostClass.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)

Example 18 with BodyParameter

use of io.swagger.models.parameters.BodyParameter 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 19 with BodyParameter

use of io.swagger.models.parameters.BodyParameter 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 20 with BodyParameter

use of io.swagger.models.parameters.BodyParameter 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

BodyParameter (io.swagger.models.parameters.BodyParameter)45 Test (org.testng.annotations.Test)34 Operation (io.swagger.models.Operation)20 Parameter (io.swagger.models.parameters.Parameter)16 ArrayModel (io.swagger.models.ArrayModel)15 Model (io.swagger.models.Model)14 PathParameter (io.swagger.models.parameters.PathParameter)14 Path (io.swagger.models.Path)13 QueryParameter (io.swagger.models.parameters.QueryParameter)13 StringProperty (io.swagger.models.properties.StringProperty)12 Swagger (io.swagger.models.Swagger)11 RefProperty (io.swagger.models.properties.RefProperty)11 Property (io.swagger.models.properties.Property)10 RefModel (io.swagger.models.RefModel)7 HeaderParameter (io.swagger.models.parameters.HeaderParameter)7 ModelImpl (io.swagger.models.ModelImpl)6 SerializableParameter (io.swagger.models.parameters.SerializableParameter)6 ArrayProperty (io.swagger.models.properties.ArrayProperty)5 PendingBodyParameter (io.servicecomb.swagger.extend.parameter.PendingBodyParameter)4 Response (io.swagger.models.Response)4