Search in sources :

Example 36 with PathParameter

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

the class ParameterSerializationTest method serializePathParameter.

@Test(description = "it should serialize a PathParameter")
public void serializePathParameter() {
    final PathParameter p = new PathParameter().property(new StringProperty());
    final String json = "{\"in\":\"path\",\"required\":true,\"type\":\"string\"}";
    SerializationMatchers.assertEqualsToJson(p, json);
}
Also used : StringProperty(io.swagger.models.properties.StringProperty) PathParameter(io.swagger.models.parameters.PathParameter) Test(org.testng.annotations.Test)

Example 37 with PathParameter

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

the class ParameterSerializationTest method deserializeNumberEnumPathParameter.

@Test(description = "it should deserialize a number path parameter with enum")
public void deserializeNumberEnumPathParameter() throws IOException {
    final String json = "{" + "   \"in\":\"path\"," + "   \"required\":true," + "   \"items\":{" + "      \"type\":\"integer\"" + "   }," + "   \"enum\":[1,2,3]" + "}";
    final Parameter p = m.readValue(json, Parameter.class);
    SerializationMatchers.assertEqualsToJson(p, json);
    assertEquals(((PathParameter) p).getEnumValue(), Arrays.asList(1, 2, 3));
}
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 38 with PathParameter

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

the class SimpleReaderTest method scanResourceWithParamRange.

@Test(description = "scan a resource with param range")
public void scanResourceWithParamRange() {
    Swagger swagger = getSwagger(ResourceWithRanges.class);
    List<Parameter> params = getGetParameters(swagger, "/{id}");
    PathParameter param0 = (PathParameter) params.get(0);
    assertEquals(param0.getName(), "id");
    assertEquals(param0.getDefaultValue(), 5);
    assertEquals(param0.getMinimum(), new BigDecimal(0.0));
    assertEquals(param0.getMaximum(), new BigDecimal(10.0));
    PathParameter param1 = (PathParameter) params.get(1);
    assertEquals(param1.getName(), "minValue");
    assertEquals(param1.getMinimum(), new BigDecimal(0.0));
    assertNull(param1.getMaximum(), null);
    PathParameter param2 = (PathParameter) params.get(2);
    assertEquals(param2.getName(), "maxValue");
    assertNull(param2.getMinimum());
    assertEquals(param2.getMaximum(), new BigDecimal(100.0));
    PathParameter param3 = (PathParameter) params.get(3);
    assertEquals(param3.getName(), "values");
    IntegerProperty items = (IntegerProperty) param3.getItems();
    assertEquals(items.getMinimum(), new BigDecimal(0.0));
    assertEquals(items.getMaximum(), new BigDecimal(5.0));
    assertEquals(items.getExclusiveMinimum(), Boolean.TRUE);
    assertEquals(items.getExclusiveMaximum(), Boolean.TRUE);
}
Also used : IntegerProperty(io.swagger.models.properties.IntegerProperty) 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) PathParameter(io.swagger.models.parameters.PathParameter) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 39 with PathParameter

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

the class SimpleReaderTest method scanSimpleResourceWithoutAnnotations.

@Test(description = "scan a simple resource without annotations")
public void scanSimpleResourceWithoutAnnotations() {
    DefaultReaderConfig config = new DefaultReaderConfig();
    config.setScanAllResources(true);
    Swagger swagger = new Reader(new Swagger(), config).read(SimpleResourceWithoutAnnotations.class);
    assertEquals(swagger.getPaths().size(), 2);
    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());
    assertNull(param1.getDescription());
    assertEquals(param1.getDefaultValue(), "5");
    Parameter param2 = get.getParameters().get(1);
    assertEquals(param2.getIn(), "query");
    assertEquals(param2.getName(), "limit");
    assertFalse(param2.getRequired());
    assertNull(param2.getDescription());
}
Also used : Swagger(io.swagger.models.Swagger) Reader(io.swagger.jaxrs.Reader) 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) DefaultReaderConfig(io.swagger.jaxrs.config.DefaultReaderConfig) Operation(io.swagger.models.Operation) NicknamedOperation(io.swagger.resources.NicknamedOperation) PathParameter(io.swagger.models.parameters.PathParameter) Test(org.testng.annotations.Test)

Example 40 with PathParameter

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

the class ReaderTest method scanParametersFromBaseResource.

@Test(description = "it should scan parameters from base resource class")
public void scanParametersFromBaseResource() {
    Swagger swagger = getSwagger(BookResource.class);
    assertNotNull(swagger);
    List<Parameter> parameters = getGet(swagger, "/{id}/v1/books/{name}").getParameters();
    assertEquals(parameters.size(), 4);
    Parameter description = parameters.get(0);
    assertTrue(description instanceof PathParameter);
    assertEquals(description.getName(), "description");
    assertEquals(description.getDescription(), "Overridden description");
    Parameter id = parameters.get(1);
    assertTrue(id instanceof PathParameter);
    assertEquals(id.getName(), "id");
    assertEquals(id.getDescription(), "The Identifier of entity");
    Parameter test = parameters.get(2);
    assertTrue(test instanceof QueryParameter);
    assertEquals(test.getName(), "test");
    assertEquals(test.getDescription(), "Test Query Param");
    Parameter name = parameters.get(3);
    assertTrue(name instanceof PathParameter);
    assertEquals(name.getName(), "name");
    assertEquals(name.getDescription(), "The books name");
}
Also used : QueryParameter(io.swagger.models.parameters.QueryParameter) Swagger(io.swagger.models.Swagger) FormParameter(io.swagger.models.parameters.FormParameter) PathParameter(io.swagger.models.parameters.PathParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) HeaderParameter(io.swagger.models.parameters.HeaderParameter) BodyParameter(io.swagger.models.parameters.BodyParameter) PathParameter(io.swagger.models.parameters.PathParameter) Test(org.testng.annotations.Test)

Aggregations

PathParameter (io.swagger.models.parameters.PathParameter)51 QueryParameter (io.swagger.models.parameters.QueryParameter)35 Parameter (io.swagger.models.parameters.Parameter)32 Test (org.testng.annotations.Test)32 BodyParameter (io.swagger.models.parameters.BodyParameter)26 HeaderParameter (io.swagger.models.parameters.HeaderParameter)16 Swagger (io.swagger.models.Swagger)14 StringProperty (io.swagger.models.properties.StringProperty)12 FormParameter (io.swagger.models.parameters.FormParameter)11 Operation (io.swagger.models.Operation)10 SerializableParameter (io.swagger.models.parameters.SerializableParameter)10 Response (io.swagger.models.Response)8 IntegerProperty (io.swagger.models.properties.IntegerProperty)8 RefProperty (io.swagger.models.properties.RefProperty)8 Path (io.swagger.models.Path)6 ArrayProperty (io.swagger.models.properties.ArrayProperty)6 HashMap (java.util.HashMap)6 ModelImpl (io.swagger.models.ModelImpl)5 RefModel (io.swagger.models.RefModel)5 ArrayList (java.util.ArrayList)5