[YANGTOOLS-1264] SchemaContextUtil.resolveModuleForPrefix does not look at submodules Created: 03/Mar/21 Updated: 27/Oct/22 Resolved: 27/Oct/22 |
|
| Status: | Resolved |
| Project: | yangtools |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Medium |
| Reporter: | Yevgeny Shakhnovich | Assignee: | Unassigned |
| Resolution: | Cannot Reproduce | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
I work with ODL Aluminium SR2. |
||
| Description |
|
We have a yang file ipi-bfd with rather complex structure. It includes some yang files … include ipi-bfd-interface; …
The included yang file ipi-bfd-interface.yang in its turn imports some other yang files and uses them: … import ipi-interface { prefix ipi-interface; }… path "/ipi-interface:interfaces/ipi-interface:interface/ipi-interface:name"; …
These files are located on device and processed by Restconf. We get exception java.lang.IllegalArgumentException: Failed to resolve xpath: no module found for prefix ipi-interface in module ipi-bfd at com.google.common.base.Preconditions.checkArgument(Preconditions.java:441) ~[?:?] at org.opendaylight.yangtools.yang.model.util.SchemaContextUtil.stringPathPartToQName(SchemaContextUtil.java:606)
File ipi-bfd really does not have prefix ipi-interface. It is defined in included file and is used there. It looks like SchemaContextUtil.resolveModuleForPrefix method checks only imports from the top file itself ignoring included files. I fixed this bug in my environment by patching org/opendaylight/yangtools/yang/model/util/SchemaContextUtil.java, methodresolveModuleForPrefix.
This is the patch - return context.findModule(mi.getModuleName(), mi.getRevision()).orElse(null); + Optional<? extends Module> moduleOpt = context.findModule(mi.getModuleName(), mi.getRevision()); + if (moduleOpt.isPresent()) { + return moduleOpt.get(); + }+ } + } + + for (Module submodule : module.getSubmodules()) { + Module result = resolveModuleForPrefix(context, submodule, prefix); + if (result != null) { + return result; |
| Comments |
| Comment by Robert Varga [ 27/Oct/22 ] |
|
SchemaInferenceStack and yang-model-export handle these correctly with help of yang-model-api exposing a few namespaces. |