Search in sources :

Example 1 with Book

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());
}
Also used : Path(io.swagger.models.Path) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Resource(com.yahoo.elide.swagger.model.Resource) Arrays(java.util.Arrays) Data(com.yahoo.elide.swagger.property.Data) Swagger(io.swagger.models.Swagger) Tag(io.swagger.models.Tag) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Include(com.yahoo.elide.annotation.Include) StringProperty(io.swagger.models.properties.StringProperty) HashMap(java.util.HashMap) Publisher(example.models.Publisher) ArrayProperty(io.swagger.models.properties.ArrayProperty) Model(io.swagger.models.Model) TestInstance(org.junit.jupiter.api.TestInstance) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Author(example.models.Author) BeforeAll(org.junit.jupiter.api.BeforeAll) Path(io.swagger.models.Path) Map(java.util.Map) NO_VERSION(com.yahoo.elide.core.dictionary.EntityDictionary.NO_VERSION) Book(example.models.Book) RefProperty(io.swagger.models.properties.RefProperty) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Operation(io.swagger.models.Operation) Datum(com.yahoo.elide.swagger.property.Datum) Property(io.swagger.models.properties.Property) Id(javax.persistence.Id) Entity(javax.persistence.Entity) BodyParameter(io.swagger.models.parameters.BodyParameter) Set(java.util.Set) Parameter(io.swagger.models.parameters.Parameter) Collectors(java.util.stream.Collectors) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) Info(io.swagger.models.Info) QueryParameter(io.swagger.models.parameters.QueryParameter) Test(org.junit.jupiter.api.Test) Response(io.swagger.models.Response) ObjectProperty(io.swagger.models.properties.ObjectProperty) List(java.util.List) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Relationship(com.yahoo.elide.swagger.property.Relationship) Optional(java.util.Optional) BodyParameter(io.swagger.models.parameters.BodyParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) Test(org.junit.jupiter.api.Test)

Example 2 with Book

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);
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Resource(com.yahoo.elide.swagger.model.Resource) Arrays(java.util.Arrays) Data(com.yahoo.elide.swagger.property.Data) Swagger(io.swagger.models.Swagger) Tag(io.swagger.models.Tag) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Include(com.yahoo.elide.annotation.Include) StringProperty(io.swagger.models.properties.StringProperty) HashMap(java.util.HashMap) Publisher(example.models.Publisher) ArrayProperty(io.swagger.models.properties.ArrayProperty) Model(io.swagger.models.Model) TestInstance(org.junit.jupiter.api.TestInstance) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Author(example.models.Author) BeforeAll(org.junit.jupiter.api.BeforeAll) Path(io.swagger.models.Path) Map(java.util.Map) NO_VERSION(com.yahoo.elide.core.dictionary.EntityDictionary.NO_VERSION) Book(example.models.Book) RefProperty(io.swagger.models.properties.RefProperty) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Operation(io.swagger.models.Operation) Datum(com.yahoo.elide.swagger.property.Datum) Property(io.swagger.models.properties.Property) Id(javax.persistence.Id) Entity(javax.persistence.Entity) BodyParameter(io.swagger.models.parameters.BodyParameter) Set(java.util.Set) Parameter(io.swagger.models.parameters.Parameter) Collectors(java.util.stream.Collectors) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) Info(io.swagger.models.Info) QueryParameter(io.swagger.models.parameters.QueryParameter) Test(org.junit.jupiter.api.Test) Response(io.swagger.models.Response) ObjectProperty(io.swagger.models.properties.ObjectProperty) List(java.util.List) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Relationship(com.yahoo.elide.swagger.property.Relationship) Optional(java.util.Optional) Swagger(io.swagger.models.Swagger) BodyParameter(io.swagger.models.parameters.BodyParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) Operation(io.swagger.models.Operation) Info(io.swagger.models.Info) Test(org.junit.jupiter.api.Test)

Example 3 with Book

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());
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Resource(com.yahoo.elide.swagger.model.Resource) Arrays(java.util.Arrays) Data(com.yahoo.elide.swagger.property.Data) Swagger(io.swagger.models.Swagger) Tag(io.swagger.models.Tag) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Include(com.yahoo.elide.annotation.Include) StringProperty(io.swagger.models.properties.StringProperty) HashMap(java.util.HashMap) Publisher(example.models.Publisher) ArrayProperty(io.swagger.models.properties.ArrayProperty) Model(io.swagger.models.Model) TestInstance(org.junit.jupiter.api.TestInstance) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Author(example.models.Author) BeforeAll(org.junit.jupiter.api.BeforeAll) Path(io.swagger.models.Path) Map(java.util.Map) NO_VERSION(com.yahoo.elide.core.dictionary.EntityDictionary.NO_VERSION) Book(example.models.Book) RefProperty(io.swagger.models.properties.RefProperty) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Operation(io.swagger.models.Operation) Datum(com.yahoo.elide.swagger.property.Datum) Property(io.swagger.models.properties.Property) Id(javax.persistence.Id) Entity(javax.persistence.Entity) BodyParameter(io.swagger.models.parameters.BodyParameter) Set(java.util.Set) Parameter(io.swagger.models.parameters.Parameter) Collectors(java.util.stream.Collectors) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) Info(io.swagger.models.Info) QueryParameter(io.swagger.models.parameters.QueryParameter) Test(org.junit.jupiter.api.Test) Response(io.swagger.models.Response) ObjectProperty(io.swagger.models.properties.ObjectProperty) List(java.util.List) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Relationship(com.yahoo.elide.swagger.property.Relationship) Optional(java.util.Optional) QueryParameter(io.swagger.models.parameters.QueryParameter) BodyParameter(io.swagger.models.parameters.BodyParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) StringProperty(io.swagger.models.properties.StringProperty) Test(org.junit.jupiter.api.Test)

Example 4 with Book

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);
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Resource(com.yahoo.elide.swagger.model.Resource) Arrays(java.util.Arrays) Data(com.yahoo.elide.swagger.property.Data) Swagger(io.swagger.models.Swagger) Tag(io.swagger.models.Tag) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Include(com.yahoo.elide.annotation.Include) StringProperty(io.swagger.models.properties.StringProperty) HashMap(java.util.HashMap) Publisher(example.models.Publisher) ArrayProperty(io.swagger.models.properties.ArrayProperty) Model(io.swagger.models.Model) TestInstance(org.junit.jupiter.api.TestInstance) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Author(example.models.Author) BeforeAll(org.junit.jupiter.api.BeforeAll) Path(io.swagger.models.Path) Map(java.util.Map) NO_VERSION(com.yahoo.elide.core.dictionary.EntityDictionary.NO_VERSION) Book(example.models.Book) RefProperty(io.swagger.models.properties.RefProperty) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Operation(io.swagger.models.Operation) Datum(com.yahoo.elide.swagger.property.Datum) Property(io.swagger.models.properties.Property) Id(javax.persistence.Id) Entity(javax.persistence.Entity) BodyParameter(io.swagger.models.parameters.BodyParameter) Set(java.util.Set) Parameter(io.swagger.models.parameters.Parameter) Collectors(java.util.stream.Collectors) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) Info(io.swagger.models.Info) QueryParameter(io.swagger.models.parameters.QueryParameter) Test(org.junit.jupiter.api.Test) Response(io.swagger.models.Response) ObjectProperty(io.swagger.models.properties.ObjectProperty) List(java.util.List) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Relationship(com.yahoo.elide.swagger.property.Relationship) Optional(java.util.Optional) Swagger(io.swagger.models.Swagger) BodyParameter(io.swagger.models.parameters.BodyParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) Operation(io.swagger.models.Operation) Info(io.swagger.models.Info) Test(org.junit.jupiter.api.Test)

Example 5 with Book

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());
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Resource(com.yahoo.elide.swagger.model.Resource) Arrays(java.util.Arrays) Data(com.yahoo.elide.swagger.property.Data) Swagger(io.swagger.models.Swagger) Tag(io.swagger.models.Tag) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Include(com.yahoo.elide.annotation.Include) StringProperty(io.swagger.models.properties.StringProperty) HashMap(java.util.HashMap) Publisher(example.models.Publisher) ArrayProperty(io.swagger.models.properties.ArrayProperty) Model(io.swagger.models.Model) TestInstance(org.junit.jupiter.api.TestInstance) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Author(example.models.Author) BeforeAll(org.junit.jupiter.api.BeforeAll) Path(io.swagger.models.Path) Map(java.util.Map) NO_VERSION(com.yahoo.elide.core.dictionary.EntityDictionary.NO_VERSION) Book(example.models.Book) RefProperty(io.swagger.models.properties.RefProperty) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Operation(io.swagger.models.Operation) Datum(com.yahoo.elide.swagger.property.Datum) Property(io.swagger.models.properties.Property) Id(javax.persistence.Id) Entity(javax.persistence.Entity) BodyParameter(io.swagger.models.parameters.BodyParameter) Set(java.util.Set) Parameter(io.swagger.models.parameters.Parameter) Collectors(java.util.stream.Collectors) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) Info(io.swagger.models.Info) QueryParameter(io.swagger.models.parameters.QueryParameter) Test(org.junit.jupiter.api.Test) Response(io.swagger.models.Response) ObjectProperty(io.swagger.models.properties.ObjectProperty) List(java.util.List) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Relationship(com.yahoo.elide.swagger.property.Relationship) Optional(java.util.Optional) QueryParameter(io.swagger.models.parameters.QueryParameter) BodyParameter(io.swagger.models.parameters.BodyParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) StringProperty(io.swagger.models.properties.StringProperty) Test(org.junit.jupiter.api.Test)

Aggregations

Include (com.yahoo.elide.annotation.Include)8 EntityDictionary (com.yahoo.elide.core.dictionary.EntityDictionary)8 NO_VERSION (com.yahoo.elide.core.dictionary.EntityDictionary.NO_VERSION)8 Resource (com.yahoo.elide.swagger.model.Resource)8 Data (com.yahoo.elide.swagger.property.Data)8 Datum (com.yahoo.elide.swagger.property.Datum)8 Relationship (com.yahoo.elide.swagger.property.Relationship)8 Author (example.models.Author)8 Book (example.models.Book)8 Publisher (example.models.Publisher)8 Info (io.swagger.models.Info)8 Model (io.swagger.models.Model)8 Operation (io.swagger.models.Operation)8 Path (io.swagger.models.Path)8 Response (io.swagger.models.Response)8 Swagger (io.swagger.models.Swagger)8 Tag (io.swagger.models.Tag)8 BodyParameter (io.swagger.models.parameters.BodyParameter)8 Parameter (io.swagger.models.parameters.Parameter)8 QueryParameter (io.swagger.models.parameters.QueryParameter)8