Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@ docs/license.md
docs/.vuepress/components/Contributors/
docs/packages/*
!docs/packages/README.md
.idea/
13 changes: 11 additions & 2 deletions lib/compile/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,9 @@ export function resolveRef(
this: Ajv,
root: SchemaEnv,
baseId: string,
ref: string
origRef: string
): AnySchema | SchemaEnv | undefined {
ref = resolveUrl(baseId, ref)
const ref = resolveUrl(baseId, origRef)
const schOrFunc = root.refs[ref]
if (schOrFunc) return schOrFunc

Expand All @@ -219,6 +219,15 @@ export function resolveRef(
if (schema) _sch = new SchemaEnv({schema, schemaId, root, baseId})
}

if (_sch === undefined && this.opts.loadSchemaSync) {
const remoteSchema = this.opts.loadSchemaSync(baseId, origRef, ref)

if (remoteSchema && !(this.refs[ref] || this.schemas[ref])) {
this.addSchema(remoteSchema, ref, undefined)
_sch = resolve.call(this, root, ref)
}
}

if (_sch === undefined) return
return (root.refs[ref] = inlineOrCompile.call(this, _sch))
}
Expand Down
3 changes: 3 additions & 0 deletions lib/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,11 @@ export interface CurrentOptions {
schemas?: AnySchema[] | {[Key in string]?: AnySchema}
logger?: Logger | false
loadSchema?: (uri: string) => Promise<AnySchemaObject>
loadSchemaSync?: (base: string, $ref: string, id: string) => AnySchemaObject | boolean
// options to modify validated data:
removeAdditional?: boolean | "all" | "failing"
defaultAdditionalProperties?: boolean;

useDefaults?: boolean | "empty"
coerceTypes?: boolean | "array"
// advanced options:
Expand Down
3 changes: 2 additions & 1 deletion lib/vocabularies/applicator/additionalProperties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ const def: CodeKeywordDefinition & AddedKeywordDefinition = {
trackErrors: true,
error,
code(cxt) {
const {gen, schema, parentSchema, data, errsCount, it} = cxt
const {gen, parentSchema, data, errsCount, it} = cxt
const { schema = it.opts.defaultAdditionalProperties } = cxt
/* istanbul ignore if */
if (!errsCount) throw new Error("ajv implementation error")
const {allErrors, opts} = it
Expand Down
2 changes: 1 addition & 1 deletion lib/vocabularies/applicator/properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const def: CodeKeywordDefinition = {
schemaType: "object",
code(cxt: KeywordCxt) {
const {gen, schema, parentSchema, data, it} = cxt
if (it.opts.removeAdditional === "all" && parentSchema.additionalProperties === undefined) {
if (it.opts.removeAdditional === "all" && parentSchema.additionalProperties === undefined || it.opts.defaultAdditionalProperties === false) {
apDef.code(new KeywordCxt(it, apDef, "additionalProperties"))
}
const allProps = allSchemaProperties(schema)
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "ajv",
"name": "@redocly/ajv",
"version": "8.6.0",
"description": "Another JSON Schema Validator",
"main": "dist/ajv.js",
Expand All @@ -13,8 +13,8 @@
"eslint": "eslint \"lib/**/*.ts\" \"spec/**/*.*s\" scripts --ignore-pattern spec/JSON-Schema-Test-Suite",
"prettier:write": "prettier --write \"./**/*.{json,yaml,js,ts}\"",
"prettier:check": "prettier --list-different \"./**/*.{json,yaml,js,ts}\"",
"test-spec": "cross-env TS_NODE_PROJECT=spec/tsconfig.json mocha -r ts-node/register \"spec/**/*.spec.{ts,js}\" -R dot -g \\(.recursiveRef.with.no..recursiveAnchor\\|.dynamicRef.with.no..dynamicAnchor\\).in.the.initial.target.schema.resource -i",
"test-codegen": "nyc cross-env TS_NODE_PROJECT=spec/tsconfig.json mocha -r ts-node/register 'spec/codegen.spec.ts' -R spec",
"test-spec": "cross-env TS_NODE_TRANSPILE_ONLY=true TS_NODE_PROJECT=spec/tsconfig.json mocha -r ts-node/register \"spec/**/*.spec.{ts,js}\" -R dot -g \\(.recursiveRef.with.no..recursiveAnchor\\|.dynamicRef.with.no..dynamicAnchor\\).in.the.initial.target.schema.resource -i",
"test-codegen": "nyc cross-env TS_NODE_TRANSPILE_ONLY=true TS_NODE_PROJECT=spec/tsconfig.json mocha -r ts-node/register 'spec/codegen.spec.ts' -R spec",
"test-debug": "npm run test-spec -- --inspect-brk",
"test-cov": "nyc npm run test-spec",
"bundle": "rm -rf bundle && rollup -c",
Expand Down
File renamed without changes.