-
-
Notifications
You must be signed in to change notification settings - Fork 888
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
Base Schema using $merge and the loadSchema option #347
Comments
@davidjamesstone thank you
|
Hey thanks for the quick reply. I was trying to achieve it by extending the list of properties rather than with In regards to require overwriting, I swear this works in my example above. I'll try later when I'm back home but I thought I ended up with a union of 4 required fields. It's a shame it's not supposed to work like that. The approach I had with
Then
Is this what you mean by using $patch? Thanks for looking into async loading with patch/merge too. |
It works in your case in a sense that it passes validation. It doesn't mean it would fail in the case when some required fields are missing - you need test(s) where validation fails.
Yes. You can either start from a bigger schema and remove as you did, or you can start from a smaller one and add, whatever makes more sense for you. I would probably add, but it's just my preference, no difference really.
You're welcome. Just published ajv-merge-patch that supports async loading, if you |
Thanks - you've been a great help. |
What version of Ajv are you using? Does the issue happen if you use the latest version?
4.9.0
Ajv options object (see https://github.com/epoberezkin/ajv#options):
Hi there.
I have been spending the last week or so getting into json schema. I'm really impressed with it so far although the lack of examples is a little frustrating.
I find this lib the best I have evaluated, you also seem active in this community so I thought I'd post the question here, even though it's not entirely related to AJV ;)
My issue is in trying to find the best way separate and reuse schemas.
For example, I have a schema that represents a database entity and I am exposing that resource with a HTTP API defined with hyper-media. I want to reuse bits of schema for both the database validation and the API payload validation. I can see there are various ways of achieving this. I tried
allOf
,$patch
and$merge
I have settled on using
$merge
. I use a base schema to represent the POST payload and the my db schema builds on this and adds anid
property.This code works fine:This code doesn't work as I thought. The required arrays are not merged - the base schema gets overwritten.My first question is do you agree with this approach?
Secondly, I'd also like these schema to live in separate files and, rather than using
addSchema
, I'd like to use theloadSchema
option to resolve the dependant schemas. I can't seem to get this to work though.base-product.json
product.json
This doesn't seem to work though. loadSchema never gets called and, although no errors are present in the callback for
compileAsync
, the validate function is not correct and seems to allow anything.Apologies for the lengthy issue - I hope it all makes sense.
The text was updated successfully, but these errors were encountered: