Skip to content

Commit

Permalink
add JSDoc for default option
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalics committed Jan 21, 2024
1 parent 3254bc8 commit 3ea1a29
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion .changeset/six-pianos-explode.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,22 @@
"ajv-ts": patch
---

Add async keyword support
Add `async` keyword support

example:

```ts
const obj = s.object({}).async()

obj.schema // {type: 'object', $async: true}
// make sync schema
obj.sync() // {type: 'object', $async: false}

// or completely remove the `$async` keyword form schema
obj.sync(true) // {type: 'object'}
```

## fixes/refactories

- refactor `safeParse` logic.
- update JSDoc for `default` method
8 changes: 7 additions & 1 deletion src/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,13 @@ abstract class SchemaBuilder<
return this
}

/** Define default value */
/**
* Option `default` keywords throws exception during schema compilation when used in:
* - not in `properties` or `items` subschemas
* - in schemas inside `anyOf`, `oneOf` and `not` ({@link https://github.com/ajv-validator/ajv/issues/42 #42})
* - in `if` schema
* - in schemas generated by user-defined _macro_ keywords
*/
default(value: Output) {
(this.schema as AnySchema).default = value
return this;
Expand Down

0 comments on commit 3ea1a29

Please sign in to comment.