use of org.motechproject.mds.docs.swagger.model.Parameter in project motech by motech.
the class SwaggerGenerator method orderParameter.
private Parameter orderParameter(Locale locale) {
Parameter orderParameter = queryParameter(ORDER_DIR_PARAM, msg(locale, ORDER_DESC_KEY), STRING_TYPE);
orderParameter.setEnumValues(Arrays.asList("Ascending", "Descending"));
return orderParameter;
}
use of org.motechproject.mds.docs.swagger.model.Parameter in project motech by motech.
the class SwaggerFieldConverter method lookupParameter.
public static Parameter lookupParameter(String lookupFieldName, Field field, LookupFieldType lookupFieldType, String paramDescription) {
// first convert this to property
Property property;
if (lookupFieldType == LookupFieldType.RANGE) {
// range is a string in the format of 1..5
property = new Property(STRING_TYPE);
} else {
property = fieldToProperty(field);
// in case of a set we nest the property
if (lookupFieldType == LookupFieldType.SET) {
property = new Property(ARRAY_TYPE, property);
}
}
// then convert to a parameter
Parameter parameter = new Parameter(property);
parameter.setName(lookupFieldName);
parameter.setIn(ParameterType.QUERY);
parameter.setDescription(paramDescription);
return parameter;
}
use of org.motechproject.mds.docs.swagger.model.Parameter 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"));
}
use of org.motechproject.mds.docs.swagger.model.Parameter 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());
}
use of org.motechproject.mds.docs.swagger.model.Parameter 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"));
}
Aggregations