Search in sources :

Example 1 with Data

use of com.yahoo.elide.swagger.property.Data in project elide by yahoo.

the class SwaggerBuilderTest method verifyData.

/**
 * Verifies that the given model is of type 'Data' containing a reference to the given model name.
 * @param model The model to check
 * @param refTypeName The model name to check
 */
private void verifyData(Model model, String refTypeName) {
    assertTrue((model instanceof com.yahoo.elide.swagger.model.Data));
    ArrayProperty data = (ArrayProperty) model.getProperties().get("model");
    RefProperty ref = (RefProperty) data.getItems();
    assertEquals("#/definitions/" + refTypeName, ref.get$ref());
}
Also used : ArrayProperty(io.swagger.models.properties.ArrayProperty) Data(com.yahoo.elide.swagger.property.Data) RefProperty(io.swagger.models.properties.RefProperty)

Example 2 with Data

use of com.yahoo.elide.swagger.property.Data in project elide by yahoo.

the class SwaggerBuilderTest method verifyData.

/**
 * Verifies that the given property is of type 'Data' containing a reference to the given model.
 * @param property The property to check
 * @param refTypeName The model name
 */
private void verifyData(Property property, String refTypeName) {
    assertTrue((property instanceof Data));
    ArrayProperty data = (ArrayProperty) ((Data) property).getProperties().get("data");
    RefProperty ref = (RefProperty) data.getItems();
    assertEquals("#/definitions/" + refTypeName, ref.get$ref());
}
Also used : ArrayProperty(io.swagger.models.properties.ArrayProperty) Data(com.yahoo.elide.swagger.property.Data) RefProperty(io.swagger.models.properties.RefProperty)

Example 3 with Data

use of com.yahoo.elide.swagger.property.Data in project elide by yahoo.

the class SwaggerBuilderTest method verifyDataRelationship.

/**
 * Verifies that the given model is of type 'Data' containing a 'Relationship' with the
 * correct type field.
 * @param model The model to check
 * @param refTypeName The type field to match against
 */
private void verifyDataRelationship(Model model, String refTypeName) {
    assertTrue((model instanceof com.yahoo.elide.swagger.model.Data));
    ArrayProperty data = (ArrayProperty) model.getProperties().get("data");
    Relationship relation = (Relationship) data.getItems();
    StringProperty type = (StringProperty) relation.getProperties().get("type");
    assertTrue(type.getEnum().contains(refTypeName));
}
Also used : ArrayProperty(io.swagger.models.properties.ArrayProperty) Relationship(com.yahoo.elide.swagger.property.Relationship) StringProperty(io.swagger.models.properties.StringProperty) Data(com.yahoo.elide.swagger.property.Data)

Example 4 with Data

use of com.yahoo.elide.swagger.property.Data in project elide by yahoo.

the class SwaggerBuilderTest method verifyDataRelationship.

/**
 * Verifies that the given property is of type 'Data' containing a 'Relationship' with the
 * correct type field.
 * @param property The property to check
 * @param refTypeName The type field to match against
 */
private void verifyDataRelationship(Property property, String refTypeName) {
    assertTrue((property instanceof Data));
    ArrayProperty data = (ArrayProperty) ((Data) property).getProperties().get("data");
    Relationship relation = (Relationship) data.getItems();
    StringProperty type = (StringProperty) relation.getProperties().get("type");
    assertTrue(type.getEnum().contains(refTypeName));
}
Also used : ArrayProperty(io.swagger.models.properties.ArrayProperty) Relationship(com.yahoo.elide.swagger.property.Relationship) StringProperty(io.swagger.models.properties.StringProperty) Data(com.yahoo.elide.swagger.property.Data)

Example 5 with Data

use of com.yahoo.elide.swagger.property.Data in project elide by yahoo.

the class SwaggerBuilderTest method testOperationRequestBodies.

@Test
public void testOperationRequestBodies() throws Exception {
    /* These take a datum pointing to a resource */
    Operation[] resourceOps = { swagger.getPaths().get("/book").getPost(), swagger.getPaths().get("/book/{bookId}").getPatch() };
    for (Operation op : resourceOps) {
        BodyParameter bodyParam = (BodyParameter) op.getParameters().stream().filter((param) -> param.getIn().equals("body")).findFirst().get();
        assertNotNull(bodyParam);
        verifyDatum(bodyParam.getSchema(), "book");
    }
    /* These don't take any params */
    Operation[] noParamOps = { swagger.getPaths().get("/book").getGet(), swagger.getPaths().get("/book/{bookId}").getDelete(), swagger.getPaths().get("/book/{bookId}").getGet() };
    for (Operation op : noParamOps) {
        Optional<Parameter> bodyParam = op.getParameters().stream().filter((param) -> param.getIn().equals("body")).findFirst();
        assertFalse(bodyParam.isPresent());
    }
    /* These take a 'data' of relationships */
    Operation[] relationshipOps = { swagger.getPaths().get("/book/{bookId}/relationships/authors").getPatch(), swagger.getPaths().get("/book/{bookId}/relationships/authors").getDelete(), swagger.getPaths().get("/book/{bookId}/relationships/authors").getPost() };
    for (Operation op : relationshipOps) {
        BodyParameter bodyParam = (BodyParameter) op.getParameters().stream().filter((param) -> param.getIn().equals("body")).findFirst().get();
        assertNotNull(bodyParam);
        verifyDataRelationship(bodyParam.getSchema(), "author");
    }
}
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) BodyParameter(io.swagger.models.parameters.BodyParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) Operation(io.swagger.models.Operation) BodyParameter(io.swagger.models.parameters.BodyParameter) Test(org.junit.jupiter.api.Test)

Aggregations

Data (com.yahoo.elide.swagger.property.Data)5 ArrayProperty (io.swagger.models.properties.ArrayProperty)5 Relationship (com.yahoo.elide.swagger.property.Relationship)3 RefProperty (io.swagger.models.properties.RefProperty)3 StringProperty (io.swagger.models.properties.StringProperty)3 Include (com.yahoo.elide.annotation.Include)1 EntityDictionary (com.yahoo.elide.core.dictionary.EntityDictionary)1 NO_VERSION (com.yahoo.elide.core.dictionary.EntityDictionary.NO_VERSION)1 Resource (com.yahoo.elide.swagger.model.Resource)1 Datum (com.yahoo.elide.swagger.property.Datum)1 Author (example.models.Author)1 Book (example.models.Book)1 Publisher (example.models.Publisher)1 Info (io.swagger.models.Info)1 Model (io.swagger.models.Model)1 Operation (io.swagger.models.Operation)1 Path (io.swagger.models.Path)1 Response (io.swagger.models.Response)1 Swagger (io.swagger.models.Swagger)1 Tag (io.swagger.models.Tag)1