Search in sources :

Example 51 with BodyParameter

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

the class ParameterProcessorTest method implicitParameterProcessorTest.

@Test(description = "parse implicit parameters from method")
public void implicitParameterProcessorTest() throws NoSuchMethodException {
    final ApiImplicitParams params = getClass().getDeclaredMethod("implicitParametrizedMethod").getAnnotation(ApiImplicitParams.class);
    final PathParameter param0 = (PathParameter) ParameterProcessor.applyAnnotations(null, new PathParameter(), String.class, Collections.<Annotation>singletonList(params.value()[0]));
    assertNotNull(param0);
    assertEquals(param0.getIn(), "path");
    assertEquals(param0.getName(), "paramName1");
    assertEquals(param0.getDescription(), "paramValue1");
    assertNull(param0.getEnum());
    assertNotNull(param0.getItems());
    final BodyParameter param1 = (BodyParameter) ParameterProcessor.applyAnnotations(null, new BodyParameter(), String.class, Collections.<Annotation>singletonList(params.value()[1]));
    assertNotNull(param1);
    assertEquals(param1.getIn(), "body");
    assertEquals(param1.getName(), "body");
    assertEquals(param1.getDescription(), "paramValue2");
    assertEquals(param1.getAccess(), "test");
    final ModelImpl model = (ModelImpl) param1.getSchema();
    assertNotNull(model);
    assertEquals(model.getDefaultValue(), "10");
}
Also used : ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) BodyParameter(io.swagger.models.parameters.BodyParameter) ModelImpl(io.swagger.models.ModelImpl) PathParameter(io.swagger.models.parameters.PathParameter) Annotation(java.lang.annotation.Annotation) Test(org.testng.annotations.Test)

Example 52 with BodyParameter

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

the class ParameterSerializationTest method deserializeRefBodyParameter.

@Test(description = "it should deserialize a ref BodyParameter")
public void deserializeRefBodyParameter() throws IOException {
    final String json = "{\"in\":\"body\",\"required\":false,\"schema\":{\"$ref\":\"#/definitions/Cat\"}}";
    final Parameter p = m.readValue(json, Parameter.class);
    SerializationMatchers.assertEqualsToJson(p, json);
}
Also used : BodyParameter(io.swagger.models.parameters.BodyParameter) PathParameter(io.swagger.models.parameters.PathParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) HeaderParameter(io.swagger.models.parameters.HeaderParameter) Test(org.testng.annotations.Test)

Example 53 with BodyParameter

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

the class ParameterSerializationTest method serializeRefBodyParameter.

@Test(description = "it should serialize a ref BodyParameter")
public void serializeRefBodyParameter() {
    final RefModel model = new RefModel("Cat");
    final BodyParameter p = new BodyParameter().schema(model);
    final String json = "{\"in\":\"body\",\"required\":false,\"schema\":{\"$ref\":\"#/definitions/Cat\"}}";
    SerializationMatchers.assertEqualsToJson(p, json);
}
Also used : RefModel(io.swagger.models.RefModel) BodyParameter(io.swagger.models.parameters.BodyParameter) Test(org.testng.annotations.Test)

Example 54 with BodyParameter

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

the class ParameterSerializationTest method deserializeBodyParameter.

@Test(description = "it should deserialize a BodyParameter")
public void deserializeBodyParameter() throws IOException {
    final String json = "{" + "   \"in\":\"body\"," + "   \"required\":false," + "   \"schema\":{" + "      \"properties\":{" + "         \"name\":{" + "            \"type\":\"string\"" + "         }" + "      }" + "   }" + "}";
    final Parameter p = m.readValue(json, Parameter.class);
    SerializationMatchers.assertEqualsToJson(p, json);
}
Also used : BodyParameter(io.swagger.models.parameters.BodyParameter) PathParameter(io.swagger.models.parameters.PathParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) HeaderParameter(io.swagger.models.parameters.HeaderParameter) Test(org.testng.annotations.Test)

Example 55 with BodyParameter

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

the class ParameterSerializationTest method serializeBodyParameter.

@Test(description = "it should serialize a BodyParameter")
public void serializeBodyParameter() {
    final ModelImpl model = new ModelImpl().name("Cat").property("name", new StringProperty());
    final BodyParameter p = new BodyParameter().schema(model);
    final String json = "{" + "   \"in\":\"body\"," + "   \"required\":false," + "   \"schema\":{" + "      \"properties\":{" + "         \"name\":{" + "            \"type\":\"string\"" + "         }" + "      }" + "   }" + "}";
    SerializationMatchers.assertEqualsToJson(p, json);
}
Also used : StringProperty(io.swagger.models.properties.StringProperty) ModelImpl(io.swagger.models.ModelImpl) BodyParameter(io.swagger.models.parameters.BodyParameter) Test(org.testng.annotations.Test)

Aggregations

BodyParameter (io.swagger.models.parameters.BodyParameter)96 Test (org.testng.annotations.Test)42 Parameter (io.swagger.models.parameters.Parameter)34 Model (io.swagger.models.Model)30 Operation (io.swagger.models.Operation)28 QueryParameter (io.swagger.models.parameters.QueryParameter)26 ModelImpl (io.swagger.models.ModelImpl)23 Swagger (io.swagger.models.Swagger)23 PathParameter (io.swagger.models.parameters.PathParameter)23 RefModel (io.swagger.models.RefModel)22 ArrayModel (io.swagger.models.ArrayModel)21 Property (io.swagger.models.properties.Property)21 Path (io.swagger.models.Path)20 RefProperty (io.swagger.models.properties.RefProperty)19 StringProperty (io.swagger.models.properties.StringProperty)18 ArrayProperty (io.swagger.models.properties.ArrayProperty)13 HeaderParameter (io.swagger.models.parameters.HeaderParameter)12 Response (io.swagger.models.Response)10 SerializableParameter (io.swagger.models.parameters.SerializableParameter)10 ArrayList (java.util.ArrayList)9