docs: clarify getDerivedClasses behavior regarding unloaded referencing schemas (#8047)
Fixes #8047.
Analysis:
getDerivedClasses relies on the current SchemaContext to identify subclasses. Since SchemaContext does not maintain a reverse-index of all possible external schemas that might reference a base class, it is architecturally impossible for this method to return classes from unloaded schemas without a global pre-scan.
Changes:
- Added a reproduction test case in
core/backenddemonstrating thatgetDerivedClassesreturns empty until the referencing schema is explicitly loaded. - Updated the JSDoc for
getDerivedClassesincore/ecschema-metadatato explicitly warn users that referencing schemas must be loaded into the context to be discovered.
This resolves the ambiguity noted by the reporter.
I turned the suggestion from @rschili and @MichaelSwigerAtBentley into a suggested code change. I have approved pending the resolution of that suggestion.
We may leave the issue opened to track the problem for a future fix. But in the meantime this update will help many people avoid introducing a tricky bug into the code. So it's a valuable update to the codebase.
Thanks @ashmitKmishra!