mirror of
https://github.com/morluto/rea.git
synced 2026-12-06 15:33:56 +08:00
refactor(schema): share resource ID collision handling (#17426)
This commit is contained in:
@@ -227,27 +227,22 @@ export class JsonSchemaReferences {
|
||||
dialect: dialectOf(schema, parent.dialect),
|
||||
parent,
|
||||
};
|
||||
if (baseUri !== undefined) {
|
||||
const existing = this.#identities.get(baseUri);
|
||||
if (existing !== undefined && existing.root !== schema) {
|
||||
this.#ambiguous.add(existing);
|
||||
this.#ambiguous.add(scope);
|
||||
} else if (existing !== undefined) scope = existing;
|
||||
else this.#identities.set(baseUri, scope);
|
||||
} else {
|
||||
let identities = this.#relativeIdentities.get(parent);
|
||||
if (identities === undefined) {
|
||||
identities = new Map();
|
||||
this.#relativeIdentities.set(parent, identities);
|
||||
let identities = this.#identities;
|
||||
if (baseUri === undefined) {
|
||||
let relative = this.#relativeIdentities.get(parent);
|
||||
if (relative === undefined) {
|
||||
relative = new Map();
|
||||
this.#relativeIdentities.set(parent, relative);
|
||||
}
|
||||
const identity = schema.$id.replace(/#$/u, "");
|
||||
const existing = identities.get(identity);
|
||||
if (existing !== undefined && existing.root !== schema) {
|
||||
this.#ambiguous.add(existing);
|
||||
this.#ambiguous.add(scope);
|
||||
} else if (existing !== undefined) scope = existing;
|
||||
else identities.set(identity, scope);
|
||||
identities = relative;
|
||||
}
|
||||
const identity = baseUri ?? schema.$id.replace(/#$/u, "");
|
||||
const existing = identities.get(identity);
|
||||
if (existing !== undefined && existing.root !== schema) {
|
||||
this.#ambiguous.add(existing);
|
||||
this.#ambiguous.add(scope);
|
||||
} else if (existing !== undefined) scope = existing;
|
||||
else identities.set(identity, scope);
|
||||
} catch {
|
||||
// An opaque or unknown URI base must not be replaced with a guessed scope.
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user