use of example.models.Book in project elide by yahoo.
the class SwaggerBuilderTest method testPathParams.
@Test
public void testPathParams() throws Exception {
Path path = swagger.getPaths().get("/book/{bookId}/authors/{authorId}");
assertEquals(2, path.getParameters().stream().filter((param) -> param.getIn().equals("path")).count());
Parameter bookId = path.getParameters().stream().filter((param) -> param.getName().equals("bookId")).findFirst().get();
assertEquals("path", bookId.getIn());
assertTrue(bookId.getRequired());
Parameter authorId = path.getParameters().stream().filter((param) -> param.getName().equals("authorId")).findFirst().get();
assertEquals("path", authorId.getIn());
assertTrue(authorId.getRequired());
path = swagger.getPaths().get("/book/{bookId}/authors");
assertEquals(1, path.getParameters().stream().filter((param) -> param.getIn().equals("path")).count());
bookId = path.getParameters().stream().filter((param) -> param.getName().equals("bookId")).findFirst().get();
assertEquals("path", bookId.getIn());
assertTrue(bookId.getRequired());
path = swagger.getPaths().get("/book/{bookId}/relationships/authors");
assertEquals(1, path.getParameters().stream().filter((param) -> param.getIn().equals("path")).count());
bookId = path.getParameters().stream().filter((param) -> param.getName().equals("bookId")).findFirst().get();
assertEquals("path", bookId.getIn());
assertTrue(bookId.getRequired());
}
use of example.models.Book in project elide by yahoo.
the class SwaggerBuilderTest method testAllFilterParameters.
@Test
public void testAllFilterParameters() throws Exception {
Info info = new Info().title("Test Service");
SwaggerBuilder builder = new SwaggerBuilder(dictionary, info);
Swagger swagger = builder.build();
Operation op = swagger.getPaths().get("/book").getGet();
List<String> paramNames = op.getParameters().stream().filter(param -> param.getName().startsWith("filter")).map(Parameter::getName).sorted().collect(Collectors.toList());
List<String> expectedNames = Arrays.asList("filter", "filter[book.title][ge]", "filter[book.title][gt]", "filter[book.title][in]", "filter[book.title][infix]", "filter[book.title][isnull]", "filter[book.title][le]", "filter[book.title][lt]", "filter[book.title][not]", "filter[book.title][notnull]", "filter[book.title][postfix]", "filter[book.title][prefix]", "filter[book.year][ge]", "filter[book.year][gt]", "filter[book.year][in]", "filter[book.year][infix]", "filter[book.year][isnull]", "filter[book.year][le]", "filter[book.year][lt]", "filter[book.year][not]", "filter[book.year][notnull]", "filter[book.year][postfix]", "filter[book.year][prefix]", "filter[book]");
assertEquals(expectedNames, paramNames);
}
use of example.models.Book in project elide by yahoo.
the class SwaggerBuilderTest method testSparseFieldsParam.
@Test
public void testSparseFieldsParam() throws Exception {
List<Parameter> params = swagger.getPaths().get("/book").getGet().getParameters();
Set<String> paramNames = params.stream().map((param) -> param.getName()).collect(Collectors.toSet());
long fieldParams = paramNames.stream().filter((name) -> name.startsWith("fields")).count();
assertEquals(1, fieldParams);
assertTrue(paramNames.contains("fields[book]"));
QueryParameter fieldParam = (QueryParameter) params.stream().filter((param) -> param.getName().equals("fields[book]")).findFirst().get();
assertEquals("query", fieldParam.getIn());
List<String> filterValues = Arrays.asList("title", "authors", "publisher");
assertTrue(((StringProperty) fieldParam.getItems()).getEnum().containsAll(filterValues));
assertEquals("csv", fieldParam.getCollectionFormat());
}
use of example.models.Book in project elide by yahoo.
the class SwaggerBuilderTest method testLegacyOnlyFilterParameters.
@Test
public void testLegacyOnlyFilterParameters() throws Exception {
Info info = new Info().title("Test Service");
SwaggerBuilder builder = new SwaggerBuilder(dictionary, info);
builder = builder.withRSQLFilterDialect(false);
Swagger swagger = builder.build();
Operation op = swagger.getPaths().get("/book").getGet();
List<String> paramNames = op.getParameters().stream().filter(param -> param.getName().startsWith("filter")).map(Parameter::getName).sorted().collect(Collectors.toList());
List<String> expectedNames = Arrays.asList("filter[book.title][ge]", "filter[book.title][gt]", "filter[book.title][in]", "filter[book.title][infix]", "filter[book.title][isnull]", "filter[book.title][le]", "filter[book.title][lt]", "filter[book.title][not]", "filter[book.title][notnull]", "filter[book.title][postfix]", "filter[book.title][prefix]", "filter[book.year][ge]", "filter[book.year][gt]", "filter[book.year][in]", "filter[book.year][infix]", "filter[book.year][isnull]", "filter[book.year][le]", "filter[book.year][lt]", "filter[book.year][not]", "filter[book.year][notnull]", "filter[book.year][postfix]", "filter[book.year][prefix]");
assertEquals(expectedNames, paramNames);
}
use of example.models.Book in project elide by yahoo.
the class SwaggerBuilderTest method testIncludeParam.
@Test
public void testIncludeParam() throws Exception {
List<Parameter> params = swagger.getPaths().get("/book").getGet().getParameters();
Set<String> paramNames = params.stream().map((param) -> param.getName()).collect(Collectors.toSet());
long includeParams = paramNames.stream().filter((name) -> name.startsWith("include")).count();
assertEquals(1, includeParams);
assertTrue(paramNames.contains("include"));
QueryParameter includeParam = (QueryParameter) params.stream().filter((param) -> param.getName().equals("include")).findFirst().get();
assertEquals("query", includeParam.getIn());
List<String> includeValues = Arrays.asList("authors", "publisher");
assertTrue(((StringProperty) includeParam.getItems()).getEnum().containsAll(includeValues));
assertEquals("csv", includeParam.getCollectionFormat());
}
Aggregations