-
-
Notifications
You must be signed in to change notification settings - Fork 593
custom validator/process functions for definitions #458
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
Comments
with the above schema, I'll be able to define a custom validator function and get data binding to custom classes |
my actual usecase is taking a django ModelForm, using the fields to generate jsonschema and using the form clean/save methods etc to generate instances. |
it avoids being incompatible with future jsonschema properties by using a Symbol object, that can be skipped in JSON serialization: # jsonschema/__init__.py
class Symbol(object):
__slots__ = []
process = Symbol()
process_bulk = Symbol() |
other option is a class like: import jsonschema
class AddressValidationError extends jsonschema.ValidationError:
pass
def process_address(address):
if valid_physical_address(address):
return Address(address)
raise ValidationError(address)
schema = {
"definitions": {
"address": jsonschema.Process(process_address, {
"type": "object",
"properties": {
"street_address": {
"type": "string"
},
"city": {
"type": "string"
},
"state": {
"type": "string"
}
},
"required": [
"street_address",
"city",
"state"
]
}),
"node": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"children": {
"type": "array",
"items": {
"$ref": "#/definitions/node"
}
}
}
}
},
"type": "object",
"properties": {
"billing_address": {
"title": "Billing address",
"$ref": "#/definitions/address"
},
"shipping_address": {
"title": "Shipping address",
"$ref": "#/definitions/address"
},
"tree": {
"title": "Recursive references",
"$ref": "#/definitions/node"
}
}
} |
I have to read this a bit more carefully, but at first glance it seems like possibly you're talking about the sorts of things that Seep does / did / was envisioned to do -- namely, more geared towards transforming instances using defined rules rather than strictly validation. |
Yeah I think that might work
…On Tue, 18 Sep 2018, 01:08 Julian Berman, ***@***.***> wrote:
I have to read this a bit more carefully, but at first glance it *seems*
like possibly you're talking about the sorts of things that Seep
<https://github.com/Julian/Seep> does / did / was envisioned to do --
namely, more geared towards transforming instances using defined rules
rather than strictly validation.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#458 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAZQTHaorqs2h6tNi6ytBW_M1s855wohks5ucDmDgaJpZM4WZ1O3>
.
|
I like the first implementation better, where the processor function is given as an attribute of the thing it's supposed to process. This means the schema can still be traversed manually easily. I have a use case for this involving hashes. I get some data like: a single validate+process schema would be nice
-edit- Better yet. Just let me define new types and let me set processors for them. like:
|
#475 someone else has a similar issue with dates |
See my comment there and in previous issues -- I think this is in fact still a request for the types of things in Seep, in which case I would definitely be open to pull requests there to add any desired functionality. If anything is missing in this library preventing this type of functionality from being implemented on top, that'd certainly be the kind of thing I'd accept bug reports for and want to add here, but the actual transformation itself is the kind of thing that belongs externally in a second package. This one is intended to strictly be an implementation of the specifications. |
Uh oh!
There was an error while loading. Please reload this page.
The text was updated successfully, but these errors were encountered: