Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add uriresolver option #1862

Merged
merged 15 commits into from
Feb 4, 2022
Prev Previous commit
Next Next commit
fix: param order
  • Loading branch information
zekth committed Jan 15, 2022
commit 206550e4cf633feac50e83997ca7be30e6a9c077
4 changes: 2 additions & 2 deletions lib/compile/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export function compileSchema(this: Ajv, sch: SchemaEnv): SchemaEnv {
// TODO refactor - remove compilations
const _sch = getCompilingSchema.call(this, sch)
if (_sch) return _sch
const rootId = getFullPath(sch.root.baseId, this.opts.uriResolver) // TODO if getFullPath removed 1 tests fails
const rootId = getFullPath(this.opts.uriResolver, sch.root.baseId) // TODO if getFullPath removed 1 tests fails
const {es5, lines} = this.opts.code
const {ownProperties} = this.opts
const gen = new CodeGen(this.scope, {es5, lines, ownProperties})
Expand Down Expand Up @@ -259,7 +259,7 @@ export function resolveSchema(
): SchemaEnv | undefined {
const p = this.opts.uriResolver.parse(ref)
const refPath = _getFullPath(p, this.opts.uriResolver)
let baseId = getFullPath(root.baseId, this.opts.uriResolver, undefined)
let baseId = getFullPath(this.opts.uriResolver, root.baseId, undefined)
// TODO `Object.keys(root.schema).length > 0` should not be needed - but removing breaks 2 tests
if (Object.keys(root.schema).length > 0 && refPath === baseId) {
return getJsonPointer.call(this, p, root)
Expand Down
2 changes: 1 addition & 1 deletion lib/compile/ref_error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ export default class MissingRefError extends Error {
constructor(baseId: string, ref: string, resolver: UriResolver, msg?: string) {
super(msg || `can't resolve reference ${ref} from id ${baseId}`)
this.missingRef = resolveUrl(baseId, ref, resolver)
this.missingSchema = normalizeId(getFullPath(this.missingRef, resolver))
this.missingSchema = normalizeId(getFullPath(resolver, this.missingRef))
}
}