Search in sources :

Example 11 with Property

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

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

the class SwaggerGenerator method definition.

private Definition definition(Entity entity, boolean includeAuto, boolean includeId) {
    final Definition definition = new Definition();
    final List<String> required = new ArrayList<>();
    final Map<String, Property> properties = new LinkedHashMap<>();
    buildDefinitionProperties(properties, required, entity, includeAuto, includeId);
    definition.setRequired(required);
    definition.setProperties(properties);
    return definition;
}
Also used : Definition(org.motechproject.mds.docs.swagger.model.Definition) ArrayList(java.util.ArrayList) Property(org.motechproject.mds.docs.swagger.model.Property) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

Property (org.motechproject.mds.docs.swagger.model.Property)12 ArrayList (java.util.ArrayList)3 LinkedHashMap (java.util.LinkedHashMap)3 Definition (org.motechproject.mds.docs.swagger.model.Definition)3 Test (org.junit.Test)2 Parameter (org.motechproject.mds.docs.swagger.model.Parameter)2 Field (org.motechproject.mds.domain.Field)2 Arrays.asList (java.util.Arrays.asList)1 List (java.util.List)1 DateTime (org.joda.time.DateTime)1 Response (org.motechproject.mds.docs.swagger.model.Response)1 ResponseWithSchema (org.motechproject.mds.docs.swagger.model.ResponseWithSchema)1 ComboboxHolder (org.motechproject.mds.domain.ComboboxHolder)1 Entity (org.motechproject.mds.domain.Entity)1