Search in sources :

Example 1 with Definition

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

the class SwaggerGenerator method buildMetadataDefinition.

private Definition buildMetadataDefinition() {
    final Definition definition = new Definition();
    final Map<String, Property> properties = new LinkedHashMap<>();
    properties.put("entity", new Property(STRING_TYPE));
    properties.put("className", new Property(STRING_TYPE));
    properties.put("module", new Property(STRING_TYPE));
    properties.put("namespace", new Property(STRING_TYPE));
    properties.put("totalCount", new Property(INTEGER_TYPE, INT64_FORMAT));
    properties.put("page", new Property(INTEGER_TYPE, INT32_FORMAT));
    properties.put("pageSize", new Property(INTEGER_TYPE, INT32_FORMAT));
    final List<String> required = new ArrayList<>();
    required.add("totalCount");
    required.add("page");
    required.add("pageSize");
    required.add("module");
    required.add("entity");
    required.add("namespace");
    required.add("className");
    definition.setProperties(properties);
    definition.setRequired(required);
    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)

Example 2 with Definition

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

the class SwaggerGenerator method definitionWithMetadata.

private Definition definitionWithMetadata(Entity entity) {
    final Definition definition = new Definition();
    Property metadata = new Property();
    metadata.setRef(definitionPath("Metadata"));
    Property data = new Property(ARRAY_TYPE);
    data.setRef(definitionPath(entity.getClassName()));
    final Map<String, Property> properties = new LinkedHashMap<>();
    properties.put("metadata", metadata);
    properties.put("data", data);
    final List<String> required = new ArrayList<>();
    required.add("metadata");
    required.add("data");
    definition.setProperties(properties);
    definition.setRequired(required);
    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)

Example 3 with Definition

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

the class SwaggerGeneratorTest method verifyTestEntityDefinitions.

private void verifyTestEntityDefinitions(Map<String, Definition> definitions) {
    Definition definition = definitions.get("org.example.TestEntity");
    assertNotNull(definition);
    assertEquals(addRequiredAutoGenerated("str", "integerField"), definition.getRequired());
    verifyTestEntityDefinitionProps(definition.getProperties(), true, true);
    definition = definitions.get("org.example.TestEntity-new");
    assertNotNull(definition);
    assertEquals(asList("str", "integerField"), definition.getRequired());
    verifyTestEntityDefinitionProps(definition.getProperties(), false, false);
}
Also used : Definition(org.motechproject.mds.docs.swagger.model.Definition)

Example 4 with Definition

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

the class SwaggerGeneratorTest method verifyExampleEntDefinitions.

private void verifyExampleEntDefinitions(Map<String, Definition> definitions) {
    Definition definition = definitions.get("org.motechproject.ExampleEnt");
    assertNotNull(definition);
    assertEquals(addRequiredAutoGenerated("doubleField", "listField"), definition.getRequired());
    verifyExampleEntDefinitionProps(definition.getProperties(), true, true);
    definition = definitions.get("org.motechproject.ExampleEnt-new-withId");
    assertNotNull(definition);
    assertEquals(asList("doubleField", "listField"), definition.getRequired());
    verifyExampleEntDefinitionProps(definition.getProperties(), false, true);
}
Also used : Definition(org.motechproject.mds.docs.swagger.model.Definition)

Example 5 with Definition

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

Definition (org.motechproject.mds.docs.swagger.model.Definition)5 ArrayList (java.util.ArrayList)3 LinkedHashMap (java.util.LinkedHashMap)3 Property (org.motechproject.mds.docs.swagger.model.Property)3