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);
}
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));
}
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);
}
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());
}
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");
}
Aggregations