Search in sources :

Example 6 with Parameter

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

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

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

Example 9 with Parameter

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

the class SwaggerGenerator method bodyParameter.

private Parameter bodyParameter(String name, String description, String ref) {
    final Parameter bodyParameter = new Parameter();
    bodyParameter.setName(name);
    bodyParameter.setDescription(description);
    bodyParameter.setIn(ParameterType.BODY);
    bodyParameter.setRequired(true);
    bodyParameter.addSchema(REF, ref);
    return bodyParameter;
}
Also used : Parameter(org.motechproject.mds.docs.swagger.model.Parameter)

Example 10 with Parameter

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

the class SwaggerGenerator method sortParameter.

private Parameter sortParameter(List<Field> restExposedFields, Locale locale) {
    Parameter sortParameter = queryParameter(SORT_BY_PARAM, msg(locale, SORT_DESC_KEY), STRING_TYPE);
    List<String> restExposedFieldNames = Lambda.extract(restExposedFields, Lambda.on(Field.class).getName());
    sortParameter.setEnumValues(restExposedFieldNames);
    return sortParameter;
}
Also used : Parameter(org.motechproject.mds.docs.swagger.model.Parameter)

Aggregations

Parameter (org.motechproject.mds.docs.swagger.model.Parameter)13 Response (org.motechproject.mds.docs.swagger.model.Response)6 ResponseWithSchema (org.motechproject.mds.docs.swagger.model.ResponseWithSchema)5 Property (org.motechproject.mds.docs.swagger.model.Property)2 ArrayList (java.util.ArrayList)1 Field (org.motechproject.mds.domain.Field)1 LookupFieldType (org.motechproject.mds.dto.LookupFieldType)1