-
-
Notifications
You must be signed in to change notification settings - Fork 874
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
Does not pick up default value if defined in $ref definition #337
Comments
Yes, only from |
Are there plans to apply defaults from references as well? |
I see it as "nice to have" rather than something many users need. And it's quite complex. So there are no plans to implement it at the moment. |
Even if you define properties in $refs, you can still define default values for the properties alongside $refs rather than inside: https://runkit.com/esp/5942f60cc72ffe0012805f9c |
Thanks, I've tried that before but incorrectly (through allOf), which is why it wasn't working. IMO that's actually better than through Definitions. |
through allOf it also works (unless you put default inside allOf). And it's not that putting default inside allOf is incorrect, it's just unsupported... |
Yep, that's exactly what I've tried. Thanks again - I think it's even cleaner without allOf. |
@epoberezkin this seems especially bad in the case of Can you explain why this is still an issue when using Example Schema{
$id: 'activities.create',
$merge: {
source: {
$ref: 'base.create',
},
with: {
type: 'object',
required: [
'entitySubType',
'name',
'endDateTime',
'startDateTime',
],
additionalProperties: false,
properties: {
attributes: {
type: 'object',
default: {},
},
entityType: {
type: 'string',
const: EntityType.ACTIVITY,
default: EntityType.ACTIVITY,
},
entitySubType: {
$ref: 'types#/definitions/activityType',
},
name: { type: 'string' },
endDateTime: {
type: 'string',
format: 'date-time',
},
startDateTime: {
type: 'string',
format: 'date-time',
},
},
},
},
} In the above schema, neither the defaults from the referenced |
@marshall007 This question belongs in ajv-merge-patch. $merge is implemented as a custom keyword, it doesn't merge anything into the original schema. I don't plan to improve it until json-schema-org standardises it (or some other re-use mechanism). |
@epoberezkin are there any workarounds for oneOf/allOf? It really limits some of our cases |
As a small note on a use case. Currently it seams like the only solution for us would be to resolve the refs our selves and inline them to get the expected behavior? |
@nick4fake: check the newly added support for @tobad357: you could compose JS objects so it is all just one big schema |
What version of Ajv are you using? Does the issue happen if you use the latest version?
4.8.2
Ajv options object (see https://github.com/epoberezkin/ajv#options):
JSON Schema (please make it as small as possible to reproduce the issue):
Above will work only if I define
default: ""
withinphone
.Data (please make it as small as posssible to reproduce the issue):
Validation result, data AFTER validation, error messages:
Data after validation:
{}
No errors. Just the default value is not set for
phone
.What results did you expect?
{ phone: "" }
The text was updated successfully, but these errors were encountered: