Search in sources :

Example 1 with Response

use of org.motechproject.mds.docs.swagger.model.Response in project motech by motech.

the class SwaggerGeneratorTest method verifyTestEntityGetAllPath.

private void verifyTestEntityGetAllPath(PathEntry pathEntry) {
    assertNotNull(pathEntry);
    verifyTestEntityPathEntryCommon(pathEntry, READ_DESC_KEY, READ_ID_KEY);
    List<Parameter> parameters = pathEntry.getParameters();
    assertNotNull(parameters);
    assertEquals(5, parameters.size());
    verifyQueryParameters(pathEntry.getParameters(), asList("str", "integerField", "longField", "timeField", "owner", "creator", "modifiedBy", "modificationDate", "creationDate"), 0);
    verifyQueryParameter(parameters.get(4), "id", ID_DESC_KEY, "integer", "int64");
    Map<Integer, Response> responses = pathEntry.getResponses();
    assertNotNull(responses);
    assertEquals(3, responses.size());
    verify400Response(responses);
    verify403Response(responses);
    Response response = responses.get(200);
    assertTrue(response instanceof ResponseWithSchema);
    ResponseWithSchema responseWithSchema = (ResponseWithSchema) response;
    assertEquals(msg(RESPONSE_LIST_DESC_KEY, "TestEntity"), responseWithSchema.getDescription());
    Map<String, String> schema = responseWithSchema.getSchema();
    assertNotNull(schema);
    assertEquals(1, schema.size());
    assertEquals("#/definitions/org.example.TestEntity-WithMetadata", schema.get("$ref"));
}
Also used : Response(org.motechproject.mds.docs.swagger.model.Response) ResponseWithSchema(org.motechproject.mds.docs.swagger.model.ResponseWithSchema) Parameter(org.motechproject.mds.docs.swagger.model.Parameter)

Example 2 with Response

use of org.motechproject.mds.docs.swagger.model.Response in project motech by motech.

the class SwaggerGeneratorTest method verify400Response.

private void verify400Response(Map<Integer, Response> responses) {
    Response response = responses.get(400);
    assertNotNull(response);
    assertEquals(msg(RESPONSE_BAD_REQUEST_KEY), response.getDescription());
}
Also used : Response(org.motechproject.mds.docs.swagger.model.Response)

Example 3 with Response

use of org.motechproject.mds.docs.swagger.model.Response in project motech by motech.

the class SwaggerGeneratorTest method verifyExampleEntDeletePath.

private void verifyExampleEntDeletePath(PathEntry pathEntry) {
    assertNotNull(pathEntry);
    verifyExampleEntCommonPath(pathEntry, DELETE_DESC_KEY, DELETE_ID_KEY);
    List<Parameter> parameters = pathEntry.getParameters();
    assertNotNull(parameters);
    assertEquals(1, parameters.size());
    Parameter pathParam = parameters.get(0);
    assertEquals("id", pathParam.getName());
    assertEquals(msg(DELETE_ID_PARAM_KEY), pathParam.getDescription());
    assertEquals(ParameterType.PATH, pathParam.getIn());
    assertNull(pathParam.getItems());
    assertTrue(pathParam.isRequired());
    assertEquals("integer", pathParam.getType());
    assertEquals("int64", pathParam.getFormat());
    assertNull(pathParam.getSchema());
    Map<Integer, Response> responses = pathEntry.getResponses();
    assertNotNull(responses);
    assertEquals(3, responses.size());
    verify400Response(responses);
    verify403Response(responses);
    Response response = responses.get(200);
    assertEquals(msg(RESPONSE_DELETE_DESC_KEY, "ExampleEnt"), response.getDescription());
}
Also used : Response(org.motechproject.mds.docs.swagger.model.Response) Parameter(org.motechproject.mds.docs.swagger.model.Parameter)

Example 4 with Response

use of org.motechproject.mds.docs.swagger.model.Response in project motech by motech.

the class SwaggerGeneratorTest method verify404Response.

private void verify404Response(Map<Integer, Response> responses, String entityName) {
    Response response = responses.get(404);
    assertNotNull(response);
    assertEquals(msg(RESPONSE_NOT_FOUND_KEY, entityName), response.getDescription());
}
Also used : Response(org.motechproject.mds.docs.swagger.model.Response)

Example 5 with Response

use of org.motechproject.mds.docs.swagger.model.Response in project motech by motech.

the class SwaggerGeneratorTest method verifyExampleEntLookup.

private void verifyExampleEntLookup(PathEntry pathEntry) {
    assertNotNull(pathEntry);
    assertEquals("Lookup - By Dt and Locale", pathEntry.getDescription());
    assertEquals(asList("org.motechproject.ExampleEnt"), pathEntry.getTags());
    assertEquals("byDtAndLocale", pathEntry.getOperationId());
    assertEquals(json(), pathEntry.getProduces());
    List<Parameter> parameters = pathEntry.getParameters();
    Parameter dtParam = parameters.get(0);
    assertNotNull(dtParam);
    assertEquals("dtField", dtParam.getName());
    assertEquals(ParameterType.QUERY, dtParam.getIn());
    assertEquals("dtField - " + msg(RANGE_PARAM_DESC_KEY), dtParam.getDescription());
    assertEquals(STRING_TYPE, dtParam.getType());
    assertNull(dtParam.getFormat());
    assertNull(dtParam.getItems());
    assertNull(dtParam.getSchema());
    Parameter localeParam = parameters.get(1);
    assertNotNull(localeParam);
    assertEquals("localeField", localeParam.getName());
    assertEquals(ParameterType.QUERY, localeParam.getIn());
    assertEquals("localeField - " + msg(SET_PARAM_DESC_KEY), localeParam.getDescription());
    assertEquals(ARRAY_TYPE, localeParam.getType());
    assertNull(localeParam.getFormat());
    assertNull(localeParam.getSchema());
    Property localeParamItems = localeParam.getItems();
    assertNotNull(localeParamItems);
    assertEquals(STRING_TYPE, localeParamItems.getType());
    assertNull(localeParamItems.getFormat());
    assertNull(localeParamItems.getItems());
    assertNotNull(parameters);
    assertEquals(6, parameters.size());
    verifyQueryParameters(pathEntry.getParameters(), asList("doubleField", "dateField", "dtField", "ldField", "localeField", "listField", "owner", "creator", "modifiedBy", "modificationDate", "creationDate"), 2);
    Map<Integer, Response> responses = pathEntry.getResponses();
    assertNotNull(responses);
    assertEquals(3, responses.size());
    verify400Response(responses);
    verify403Response(responses);
    Response response = responses.get(200);
    assertTrue(response instanceof ResponseWithSchema);
    ResponseWithSchema responseWithSchema = (ResponseWithSchema) response;
    assertEquals(msg(RESPONSE_LIST_DESC_KEY, "ExampleEnt"), responseWithSchema.getDescription());
    Map<String, String> schema = responseWithSchema.getSchema();
    assertNotNull(schema);
    assertEquals("#/definitions/org.motechproject.ExampleEnt-WithMetadata", schema.get("$ref"));
}
Also used : Response(org.motechproject.mds.docs.swagger.model.Response) ResponseWithSchema(org.motechproject.mds.docs.swagger.model.ResponseWithSchema) Parameter(org.motechproject.mds.docs.swagger.model.Parameter) Property(org.motechproject.mds.docs.swagger.model.Property)

Aggregations

Response (org.motechproject.mds.docs.swagger.model.Response)9 Parameter (org.motechproject.mds.docs.swagger.model.Parameter)6 ResponseWithSchema (org.motechproject.mds.docs.swagger.model.ResponseWithSchema)5 Property (org.motechproject.mds.docs.swagger.model.Property)1