ajv-validator / ajv-validator/ajv-merge-patch

DefaultValue not working

Open
#16 1 comment 4 reactions 0 assignees View on GitHub
enhancement
Dominant language
JavaScript
Stars
47
Forks
19
PR merge metrics
No merged PRs in 30d

Description

```
const Ajv = require('ajv');
const ajv = new Ajv({
allErrors: true,
format: 'full',
useDefaults: true,
coerceTypes: false,
errorDataPath: 'property',
sourceCode: false,
});
require('ajv-merge-patch')(ajv);
const base = {
type: 'object',
properties: {
operation: {
type: 'string',
enum: ['create', 'update', 'delete'],
},
id: {
type: 'string',
},
},
};

const schema = {
$merge: {
source: base,
with: {
type: 'object',
properties: {
test: {
type: 'integer',
default: 0,
},
},
}
}
};

const params = {
operation: 'delete'
};
const validate = ajv.compile(schema);
const isValidParams = validate(params);
console.log(params);
```

**Actual :**
{ operation: 'delete' }
**Expected :**
{ operation: 'delete' , test: 0}

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.