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

fix: relax type on object properties #180

Merged
merged 4 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
13 changes: 13 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,16 @@ jobs:
- run: yarn lint
- run: git submodule update --init --recursive
- run: yarn run test
types:
sparten11740 marked this conversation as resolved.
Show resolved Hide resolved
name: 'Test types'
runs-on: ubuntu-latest
defaults:
run:
working-directory: test/types
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: yarn
- run: yarn test
14 changes: 7 additions & 7 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ type Schema =
$id?: string
$anchor?: string
$ref?: string
definitions?: { [id: string]: Schema }
$defs?: { [id: string]: Schema }
definitions?: Partial<{ [id: string]: Schema }>
$defs?: Partial<{ [id: string]: Schema }>
$recursiveRef?: string
$recursiveAnchor?: boolean
// generic
Expand Down Expand Up @@ -61,15 +61,15 @@ type Schema =
contentMediaType?: string
contentSchema?: Schema
// objects
properties?: { [id: string]: Schema }
properties?: Partial<{ [id: string]: Schema }>
maxProperties?: number
minProperties?: number
additionalProperties?: Schema
patternProperties?: { [pattern: string]: Schema }
patternProperties?: Partial<{ [pattern: string]: Schema }>
propertyNames?: Schema
dependencies?: { [id: string]: Array<string> | Schema }
dependentRequired?: { [id: string]: Array<string> }
dependentSchemas?: { [id: string]: Schema }
dependencies?: Partial<{ [id: string]: Array<string> | Schema }>
dependentRequired?: Partial<{ [id: string]: Array<string> }>
dependentSchemas?: Partial<{ [id: string]: Schema }>
// see-through
unevaluatedProperties?: Schema
unevaluatedItems?: Schema
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"test": "npm run test:raw | tap-spec",
"test:raw": "npm run test:normal && npm run test:module",
"test:module": "tape -r ./test/tools/test-module.js test/*.js test/regressions/*.js",
"test:normal": "tape test/*.js test/regressions/*.js"
"test:normal": "tape test/*.js test/regressions/*.js",
"test:types": "cd test/types && yarn test"
sparten11740 marked this conversation as resolved.
Show resolved Hide resolved
},
"dependencies": {},
"devDependencies": {
Expand Down
11 changes: 11 additions & 0 deletions test/types/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "type-tests",
"private": true,
"devDependencies": {
"@types/node": "^20.11.16",
"typescript": "^5.3.3"
},
"scripts": {
"test": "tsc --noEmit"
}
}
41 changes: 41 additions & 0 deletions test/types/tests/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { validator } from '../../../index'

const schema = {
type: 'object',
allOf: [
{
if: {
properties: {
propertyA: {
const: 1,
},
},
},
then: {
properties: {
propertyB: {
const: null,
},
},
},
},
{
if: {
properties: {
propertyA: {
const: 2,
},
},
},
then: {
properties: {
propertyC: {
const: null,
},
},
},
},
],
}

const myValidator = validator(schema)
7 changes: 7 additions & 0 deletions test/types/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"compilerOptions": {
"strict": true,
},
"include": ["tests"],
"exclude": ["node_modules"]
}
20 changes: 20 additions & 0 deletions test/types/yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


"@types/node@^20.11.16":
version "20.11.16"
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.11.16.tgz#4411f79411514eb8e2926f036c86c9f0e4ec6708"
integrity sha512-gKb0enTmRCzXSSUJDq6/sPcqrfCv2mkkG6Jt/clpn5eiCbKTY+SgZUxo+p8ZKMof5dCp9vHQUAB7wOUTod22wQ==
dependencies:
undici-types "~5.26.4"

typescript@^5.3.3:
version "5.3.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.3.3.tgz#b3ce6ba258e72e6305ba66f5c9b452aaee3ffe37"
integrity sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==

undici-types@~5.26.4:
version "5.26.5"
resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-5.26.5.tgz#bcd539893d00b56e964fd2657a4866b221a65617"
integrity sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==
Loading