Skip to content

Commit

Permalink
Merge branch 'master' into perf
Browse files Browse the repository at this point in the history
  • Loading branch information
gurgunday authored Jul 13, 2024
2 parents 2799edd + 9050ba1 commit 2332716
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 14 deletions.
2 changes: 1 addition & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ Add validation keyword to Ajv instance.

Keyword should be different from all standard JSON Schema keywords and different from previously defined keywords. There is no way to redefine keywords or to remove keyword definition from the instance.

Keyword must start with a letter, `_` or `$`, and may continue with letters, numbers, `_`, `$`, or `-`.
Keyword must start with an ASCII letter, `_` or `$`, and may continue with ASCII letters, numbers, `_`, `$`, `-`, or `:`.
It is recommended to use an application-specific prefix for keywords to avoid current and future name collisions.

Example Keywords:
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/modifying-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ With `useDefaults` option `default` keywords throws exception during schema comp

The strict mode option can change the behaviour for these unsupported defaults (`strict: false` to ignore them, `"log"` to log a warning).

See [Strict mode](./strict-mode.md).
See [Strict mode](../strict-mode.md).

::: tip Default with discriminator keyword
Defaults will be assigned in schemas inside `oneOf` in case [discriminator](../json-schema.md#discriminator) keyword is used.
Expand Down
20 changes: 10 additions & 10 deletions lib/types/json-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,25 +108,25 @@ type UncheckedJSONSchemaType<T, IsPartial extends boolean> = (
: UncheckedPropertiesSchema<T>
patternProperties?: Record<string, UncheckedJSONSchemaType<T[string], false>>
propertyNames?: Omit<UncheckedJSONSchemaType<string, false>, "type"> & {type?: "string"}
dependencies?: {[K in keyof T]?: Readonly<(keyof T)[]> | UncheckedPartialSchema<T>}
dependentRequired?: {[K in keyof T]?: Readonly<(keyof T)[]>}
dependencies?: {[K in keyof T]?: readonly (keyof T)[] | UncheckedPartialSchema<T>}
dependentRequired?: {[K in keyof T]?: readonly (keyof T)[]}
dependentSchemas?: {[K in keyof T]?: UncheckedPartialSchema<T>}
minProperties?: number
maxProperties?: number
} & (IsPartial extends true // "required" is not necessary if it's a non-partial type with no required keys // are listed it only asserts that optional cannot be listed. // "required" type does not guarantee that all required properties
? {required: Readonly<(keyof T)[]>}
? {required: readonly (keyof T)[]}
: [UncheckedRequiredMembers<T>] extends [never]
? {required?: Readonly<UncheckedRequiredMembers<T>[]>}
: {required: Readonly<UncheckedRequiredMembers<T>[]>})
? {required?: readonly UncheckedRequiredMembers<T>[]}
: {required: readonly UncheckedRequiredMembers<T>[]})
: T extends null
? {
type: JSONType<"null", IsPartial>
nullable: true
}
: never) & {
allOf?: Readonly<UncheckedPartialSchema<T>[]>
anyOf?: Readonly<UncheckedPartialSchema<T>[]>
oneOf?: Readonly<UncheckedPartialSchema<T>[]>
allOf?: readonly UncheckedPartialSchema<T>[]
anyOf?: readonly UncheckedPartialSchema<T>[]
oneOf?: readonly UncheckedPartialSchema<T>[]
if?: UncheckedPartialSchema<T>
then?: UncheckedPartialSchema<T>
else?: UncheckedPartialSchema<T>
Expand Down Expand Up @@ -176,12 +176,12 @@ type Nullable<T> = undefined extends T
? {
nullable: true
const?: null // any non-null value would fail `const: null`, `null` would fail any other value in const
enum?: Readonly<(T | null)[]> // `null` must be explicitly included in "enum" for `null` to pass
enum?: readonly (T | null)[] // `null` must be explicitly included in "enum" for `null` to pass
default?: T | null
}
: {
nullable?: false
const?: T
enum?: Readonly<T[]>
enum?: readonly T[]
default?: T
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ajv",
"version": "8.16.0",
"version": "8.17.1",
"description": "Another JSON Schema Validator",
"main": "dist/ajv.js",
"types": "dist/ajv.d.ts",
Expand Down Expand Up @@ -59,7 +59,7 @@
"runkitExampleFilename": ".runkit_example.js",
"dependencies": {
"fast-deep-equal": "^3.1.3",
"fast-uri": "^2.4.0",
"fast-uri": "^3.0.1",
"json-schema-traverse": "^1.0.0",
"require-from-string": "^2.0.2"
},
Expand Down
35 changes: 35 additions & 0 deletions spec/resolve.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,41 @@ uriResolvers.forEach((resolver) => {
})
})

describe("URIs with encoded characters (issue #2447)", () => {
it("should resolve the ref", () => {
const schema = {
$ref: "#/definitions/Record%3Cstring%2CPerson%3E",
$schema: "http://json-schema.org/draft-07/schema#",
definitions: {
Person: {
type: "object",
properties: {
firstName: {
type: "string",
description: "The person's first name.",
},
},
},
"Record<string,Person>": {
type: "object",
additionalProperties: {
$ref: "#/definitions/Person",
},
},
},
}
const data = {
joe: {
firstName: "Joe",
},
}
instances.forEach((ajv) => {
const validate = ajv.compile(schema)
validate(data).should.equal(true)
})
})
})

describe("missing schema error", function () {
this.timeout(4000)

Expand Down

0 comments on commit 2332716

Please sign in to comment.