use of org.opendaylight.yangtools.yang.model.api.EffectiveModelContext in project netconf by opendaylight.
the class WadlGenTest method testListGeneration.
@Test
public void testListGeneration() {
final WadlGenerator generator = new WadlGenerator();
final EffectiveModelContext context = YangParserTestUtils.parseYangResourceDirectory("/wadl-gen");
Table<GeneratedFileType, GeneratedFilePath, GeneratedFile> generatedWadlFiles = generator.generateFiles(context, Set.copyOf(context.getModules()), (module, representation) -> Optional.empty());
assertEquals(3, generatedWadlFiles.size());
// TODO: more asserts
}
use of org.opendaylight.yangtools.yang.model.api.EffectiveModelContext in project netconf by opendaylight.
the class MountPointSwagger method getMountPointApi.
public CommonApiObject getMountPointApi(final UriInfo uriInfo, final Long id, final String module, final String revision, 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;
}
if (DATASTORES_LABEL.equals(module) && DATASTORES_REVISION.equals(revision)) {
return generateDataStoreApiDoc(uriInfo, urlPrefix, deviceName);
}
final SwaggerObject swaggerObject = swaggerGenerator.getApiDeclaration(module, revision, uriInfo, context, urlPrefix, uriType, oaversion);
return BaseYangSwaggerGenerator.getAppropriateDoc(swaggerObject, oaversion);
}
use of org.opendaylight.yangtools.yang.model.api.EffectiveModelContext 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);
}
use of org.opendaylight.yangtools.yang.model.api.EffectiveModelContext in project netconf by opendaylight.
the class CreateStreamUtilTest method prepareDomPayload.
private NormalizedNodePayload prepareDomPayload(final String rpcName, final Function<RpcDefinition, ContainerLike> rpcToContainer, final String toasterValue, final String inputOutputName) {
final EffectiveModelContext schema = refSchemaCtx;
final Module rpcModule = schema.findModules("sal-remote").iterator().next();
final QName rpcQName = QName.create(rpcModule.getQNameModule(), rpcName);
ContainerLike rpcInputSchemaNode = null;
for (final RpcDefinition rpc : rpcModule.getRpcs()) {
if (rpcQName.isEqualWithoutRevision(rpc.getQName())) {
rpcInputSchemaNode = rpcToContainer.apply(rpc);
break;
}
}
assertNotNull(rpcInputSchemaNode);
final DataContainerNodeBuilder<YangInstanceIdentifier.NodeIdentifier, ContainerNode> container = SchemaAwareBuilders.containerBuilder(rpcInputSchemaNode);
final QName lfQName = QName.create(rpcModule.getQNameModule(), inputOutputName);
final DataSchemaNode lfSchemaNode = rpcInputSchemaNode.findDataChildByName(lfQName).orElseThrow();
assertThat(lfSchemaNode, instanceOf(LeafSchemaNode.class));
final Object o;
if ("toaster".equals(toasterValue)) {
final QName rpcQname = QName.create("http://netconfcentral.org/ns/toaster", "2009-11-20", toasterValue);
o = YangInstanceIdentifier.builder().node(rpcQname).build();
} else {
o = toasterValue;
}
final LeafNode<Object> lfNode = SchemaAwareBuilders.leafBuilder((LeafSchemaNode) lfSchemaNode).withValue(o).build();
container.withChild(lfNode);
return NormalizedNodePayload.of(new InstanceIdentifierContext<>(null, rpcInputSchemaNode, null, schema), container.build());
}
use of org.opendaylight.yangtools.yang.model.api.EffectiveModelContext in project netconf by opendaylight.
the class ParserIdentifier method coerceModelContext.
private static EffectiveModelContext coerceModelContext(final DOMMountPoint mountPoint) {
final EffectiveModelContext context = modelContext(mountPoint);
checkState(context != null, "Mount point %s does not have a model context", mountPoint);
return context;
}
Aggregations