Search in sources :

Example 1 with Publisher

use of example.models.Publisher 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 2 with Publisher

use of example.models.Publisher 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)2 EntityDictionary (com.yahoo.elide.core.dictionary.EntityDictionary)2 NO_VERSION (com.yahoo.elide.core.dictionary.EntityDictionary.NO_VERSION)2 Resource (com.yahoo.elide.swagger.model.Resource)2 Data (com.yahoo.elide.swagger.property.Data)2 Datum (com.yahoo.elide.swagger.property.Datum)2 Relationship (com.yahoo.elide.swagger.property.Relationship)2 Author (example.models.Author)2 Book (example.models.Book)2 Publisher (example.models.Publisher)2 Info (io.swagger.models.Info)2 Model (io.swagger.models.Model)2 Operation (io.swagger.models.Operation)2 Path (io.swagger.models.Path)2 Response (io.swagger.models.Response)2 Swagger (io.swagger.models.Swagger)2 Tag (io.swagger.models.Tag)2 BodyParameter (io.swagger.models.parameters.BodyParameter)2 Parameter (io.swagger.models.parameters.Parameter)2 QueryParameter (io.swagger.models.parameters.QueryParameter)2