Search in sources :

Example 1 with ResponseWithSchema

use of org.motechproject.mds.docs.swagger.model.ResponseWithSchema 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 ResponseWithSchema

use of org.motechproject.mds.docs.swagger.model.ResponseWithSchema 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)

Example 3 with ResponseWithSchema

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

the class SwaggerGeneratorTest method verifyExampleEntUpdatePath.

private void verifyExampleEntUpdatePath(PathEntry pathEntry) {
    assertNotNull(pathEntry);
    verifyExampleEntCommonPath(pathEntry, UPDATE_DESC_KEY, UPDATE_ID_KEY);
    List<Parameter> parameters = pathEntry.getParameters();
    assertNotNull(parameters);
    assertEquals(1, parameters.size());
    Parameter bodyParam = parameters.get(0);
    assertEquals("ExampleEnt", bodyParam.getName());
    assertEquals(msg(UPDATE_BODY_DESC_KEY, "ExampleEnt"), bodyParam.getDescription());
    assertEquals(ParameterType.BODY, bodyParam.getIn());
    assertNull(bodyParam.getItems());
    assertTrue(bodyParam.isRequired());
    assertNull(bodyParam.getType());
    assertNull(bodyParam.getFormat());
    Map<String, String> paramSchema = bodyParam.getSchema();
    assertNotNull(paramSchema);
    assertEquals(1, paramSchema.size());
    assertEquals("#/definitions/org.motechproject.ExampleEnt-new-withId", paramSchema.get("$ref"));
    Map<Integer, Response> responses = pathEntry.getResponses();
    assertNotNull(responses);
    assertEquals(4, responses.size());
    verify404Response(responses, "ExampleEnt");
    verify400Response(responses);
    verify403Response(responses);
    Response response = responses.get(200);
    assertTrue(response instanceof ResponseWithSchema);
    ResponseWithSchema singleItemResponse = (ResponseWithSchema) response;
    assertEquals(msg(RESPONSE_UPDATED_DESC_KEY, "ExampleEnt"), singleItemResponse.getDescription());
    Map<String, String> newResponseSchema = singleItemResponse.getSchema();
    assertNotNull(newResponseSchema);
    assertEquals(1, newResponseSchema.size());
    assertEquals("#/definitions/org.motechproject.ExampleEnt", newResponseSchema.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 4 with ResponseWithSchema

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

the class SwaggerGeneratorTest method verifyTestEntityLookup.

private void verifyTestEntityLookup(PathEntry pathEntry) {
    assertNotNull(pathEntry);
    assertEquals("Lookup - Find By Str & Long", pathEntry.getDescription());
    assertEquals(asList("org.example.TestEntity"), pathEntry.getTags());
    assertEquals("findByStrLong", pathEntry.getOperationId());
    assertEquals(json(), pathEntry.getProduces());
    List<Parameter> parameters = pathEntry.getParameters();
    Parameter strParam = parameters.get(0);
    assertNotNull(strParam);
    assertEquals("str", strParam.getName());
    assertEquals(ParameterType.QUERY, strParam.getIn());
    assertEquals("A string field used in tests", strParam.getDescription());
    assertEquals(STRING_TYPE, strParam.getType());
    assertNull(strParam.getFormat());
    assertNull(strParam.getItems());
    assertNull(strParam.getSchema());
    Parameter longParam = parameters.get(1);
    assertNotNull(longParam);
    assertEquals("longField", longParam.getName());
    assertEquals(ParameterType.QUERY, strParam.getIn());
    assertEquals("longField", longParam.getDescription());
    assertEquals(INTEGER_TYPE, longParam.getType());
    assertEquals(INT64_FORMAT, longParam.getFormat());
    assertNull(longParam.getItems());
    assertNull(longParam.getSchema());
    assertNotNull(parameters);
    assertEquals(6, parameters.size());
    verifyQueryParameters(pathEntry.getParameters(), asList("str", "integerField", "longField", "timeField", "owner", "creator", "modifiedBy", "modificationDate", "creationDate"), 2);
    Map<Integer, Response> responses = pathEntry.getResponses();
    assertNotNull(responses);
    assertEquals(4, responses.size());
    verify400Response(responses);
    verify403Response(responses);
    Response response = responses.get(404);
    assertNotNull(response);
    assertEquals(msg(RESPONSE_LOOKUP_NOT_FOUND_KEY, "TestEntity"), response.getDescription());
    response = responses.get(200);
    assertTrue(response instanceof ResponseWithSchema);
    ResponseWithSchema singleItemResponse = (ResponseWithSchema) response;
    assertEquals(msg(RESPONSE_SINGLE_DESC_KEY, "TestEntity"), singleItemResponse.getDescription());
    Map<String, String> newResponseSchema = singleItemResponse.getSchema();
    assertNotNull(newResponseSchema);
    assertEquals(1, newResponseSchema.size());
    assertEquals("#/definitions/org.example.TestEntity-WithMetadata", newResponseSchema.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 5 with ResponseWithSchema

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

the class SwaggerGeneratorTest method verifyTestEntityPostPath.

private void verifyTestEntityPostPath(PathEntry pathEntry) {
    assertNotNull(pathEntry);
    verifyTestEntityPathEntryCommon(pathEntry, CREATE_DESC_KEY, CREATE_ID_KEY);
    List<Parameter> parameters = pathEntry.getParameters();
    assertNotNull(parameters);
    assertEquals(1, parameters.size());
    Parameter newParam = parameters.get(0);
    assertNotNull(newParam);
    assertEquals("TestEntity", newParam.getName());
    assertEquals(ParameterType.BODY, newParam.getIn());
    assertNull(newParam.getFormat());
    assertTrue(newParam.isRequired());
    assertEquals(msg(CREATE_BODY_DESC_KEY, "TestEntity"), newParam.getDescription());
    Map<String, String> newParamSchema = newParam.getSchema();
    assertNotNull(newParamSchema);
    assertEquals(1, newParamSchema.size());
    assertEquals("#/definitions/org.example.TestEntity-new", newParamSchema.get("$ref"));
    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 singleItemResponse = (ResponseWithSchema) response;
    assertEquals(msg(RESPONSE_NEW_DESC_KEY, "TestEntity"), singleItemResponse.getDescription());
    Map<String, String> newResponseSchema = singleItemResponse.getSchema();
    assertNotNull(newResponseSchema);
    assertEquals(1, newResponseSchema.size());
    assertEquals("#/definitions/org.example.TestEntity", newResponseSchema.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)

Aggregations

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