Search in sources :

Example 1 with DefinitionNames

use of org.opendaylight.netconf.sal.rest.doc.impl.DefinitionNames in project netconf by opendaylight.

the class MountPointSwagger method getMountPointApi.

public CommonApiObject getMountPointApi(final UriInfo uriInfo, final Long id, final Optional<Integer> pageNum, final URIType uriType, final OAversion oaversion) {
    final YangInstanceIdentifier iid = getInstanceId(id);
    final EffectiveModelContext context = getSchemaContext(iid);
    final String urlPrefix = getYangMountUrl(iid);
    final String deviceName = extractDeviceName(iid);
    if (context == null) {
        return null;
    }
    final DefinitionNames definitionNames = new DefinitionNames();
    boolean includeDataStore = true;
    Optional<Range<Integer>> range = Optional.empty();
    if (pageNum.isPresent()) {
        final int pageNumValue = pageNum.get();
        final int end = DEFAULT_PAGESIZE * pageNumValue - 1;
        int start = end - DEFAULT_PAGESIZE;
        if (pageNumValue == 1) {
            start++;
        } else {
            includeDataStore = false;
        }
        range = Optional.of(Range.closed(start, end));
    }
    final SwaggerObject doc;
    final SwaggerObject swaggerObject = swaggerGenerator.getAllModulesDoc(uriInfo, range, context, Optional.of(deviceName), urlPrefix, definitionNames, uriType, oaversion);
    if (includeDataStore) {
        doc = generateDataStoreApiDoc(uriInfo, urlPrefix, deviceName);
        addFields(doc.getPaths(), swaggerObject.getPaths().fields());
        addFields(doc.getDefinitions(), swaggerObject.getDefinitions().fields());
        doc.getInfo().setTitle(swaggerObject.getInfo().getTitle());
    } else {
        doc = swaggerObject;
    }
    return BaseYangSwaggerGenerator.getAppropriateDoc(doc, oaversion);
}
Also used : SwaggerObject(org.opendaylight.netconf.sal.rest.doc.swagger.SwaggerObject) DefinitionNames(org.opendaylight.netconf.sal.rest.doc.impl.DefinitionNames) Range(com.google.common.collect.Range) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)

Example 2 with DefinitionNames

use of org.opendaylight.netconf.sal.rest.doc.impl.DefinitionNames in project netconf by opendaylight.

the class SwaggerObjectTest method testConvertToJsonSchema.

@Test
public void testConvertToJsonSchema() throws Exception {
    final Optional<? extends Module> module = context.findModule("opflex", Revision.of("2014-05-28"));
    assertTrue("Desired module not found", module.isPresent());
    final DefinitionGenerator generator = new DefinitionGenerator();
    final ObjectNode jsonObject = generator.convertToJsonSchema(module.get(), context, new DefinitionNames(), ApiDocServiceImpl.OAversion.V2_0, true);
    Assert.assertNotNull(jsonObject);
}
Also used : DefinitionGenerator(org.opendaylight.netconf.sal.rest.doc.impl.DefinitionGenerator) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DefinitionNames(org.opendaylight.netconf.sal.rest.doc.impl.DefinitionNames) Test(org.junit.Test)

Example 3 with DefinitionNames

use of org.opendaylight.netconf.sal.rest.doc.impl.DefinitionNames in project netconf by opendaylight.

the class SwaggerObjectTest method testStringTypes.

@Test
public void testStringTypes() throws Exception {
    final Optional<? extends Module> module = context.findModule("string-types");
    assertTrue("Desired module not found", module.isPresent());
    final DefinitionGenerator generator = new DefinitionGenerator();
    final ObjectNode jsonObject = generator.convertToJsonSchema(module.get(), context, new DefinitionNames(), ApiDocServiceImpl.OAversion.V2_0, true);
    Assert.assertNotNull(jsonObject);
}
Also used : DefinitionGenerator(org.opendaylight.netconf.sal.rest.doc.impl.DefinitionGenerator) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DefinitionNames(org.opendaylight.netconf.sal.rest.doc.impl.DefinitionNames) Test(org.junit.Test)

Aggregations

DefinitionNames (org.opendaylight.netconf.sal.rest.doc.impl.DefinitionNames)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 Test (org.junit.Test)2 DefinitionGenerator (org.opendaylight.netconf.sal.rest.doc.impl.DefinitionGenerator)2 Range (com.google.common.collect.Range)1 SwaggerObject (org.opendaylight.netconf.sal.rest.doc.swagger.SwaggerObject)1 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)1 EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)1