-
-
Notifications
You must be signed in to change notification settings - Fork 582
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
Support encountering of a "deprecated": true
keyword by propagating a deprecation warning
#1170
Comments
"deprecated": true
"deprecated": true
Just to pull in some of the broader context: It may very well be possible today. If so, a doc example would be awesome. My first thought on the proposed interface is that it's a little odd that this would produce a validation error when the keyword's meaning is "warning like". I'm also not sure that this merits a special keyword argument. My ideal is that this fits in as part of a more generic mechanism like... (Just spitballing) annotations = []
validator.validate(schema, instance, collect_annotations=(annotations, "deprecated"))
print(annotations) # [{...}] |
This definitely immediately discards any solution or implementation where a But indeed I think this at least relies on or benefits from annotation support (which I think has no current open issue because no one has ever asked for its functionality! even though it's been on my radar). If we did have such an interface, I do indeed think this would be implementable on top of it.
(I mentioned this on the PR, but indeed, agree.) |
"deprecated": true
"deprecated": true
keyword by propagating a deprecation warning
I'm looking at this again with ~24 more hours to think about it. I think the CLI to look at, which would help drive this, would be something akin to this: Supporting multiple annotations smoothly and simultaneously is therefore an important feature and has relevance, in that I'd like So I have two questions, as someone who might try to implement this:
(1) is easy to understand as a question, hard to answer, but isn't even really relevant if we know of nasty cases which are likely to block any efforts. Plus, if there are especially complex cases, that may drive what the ideal API looks like.
Everything can be matched by the I don't see an answer to this in the JSON Schema docs, so I'm left scratching my head. |
The reason this hasn't happened already (this being "support annotations") is essentially because so far the answer I have to this question is a large backwards incompatible change. Specifically -- modern versions of JSON Schema are now stateful. Annotations are the representation of that state. Historically, def keyword_function(validator_object, keyword_value, instance, full_schema):
... but this is... wrong for stateful worlds! Instead the "right API" is: def keyword_function(annotator, keyword_value, instance, full_schema):
... where an annotator essentially represents the thus far-collected state for the current validation process, and has methods like So it's quite a delicate change! Literally my best thought so far is to bundle this with other changes related to wanting to better support vocabularies, and essentially deprecate all the existing validator objects ( If you're saying you're interested in playing around, I'd be trying to do a POC of the above, with essentially a completely private extension interface since.. even upstream it's not yet really firm what JSON Schemas "real" compute model is, how complex keywords can get, whether they support complicated ordering mechanisms (for which keyword has to be processed first), etc. Your example is perhaps even a simple example of this sort of thing, I don't honestly remember what the answer is but I can think harder if you'd like :) So if you want to POC it, I can certainly give some opinions. If you want to try something less ambitious, it's possible indeed that this could be done more "localized", especially if the goal is to just support |
Thanks both for starting the discussion, and sorry for the noise with the PR! In particular, my use case was something like {
"type": "string",
"description": "The type of value this setting contains",
"oneOf": [
{
"enum": [
"oauth",
"date_iso8601",
"file",
"email",
"integer",
"options",
"object",
"array",
"boolean",
"string"
]
},
{
"enum": [
"hidden",
"password"
],
"deprecated": true
}
]
}
|
Definitely no need for apologies, thanks for the issue. |
+1 for offering thanks for opening the issues! Having a clear use-case to drive discussion is often worth a thousand design meetings! I'm not sure I can reasonably commit myself to a big project at least until December, so there's no pressure to give me a lot of support. I didn't realize how difficult this would be when I mentioned that I might give it a try -- I was imagining a purely additive change. I'm still interested in a full solution for this, but in the meantime, maybe we can do something as a useful stopgap.
There's already I'll think about this more on the "only in the CLI" side of the house ( python-jsonschema/check-jsonschema#331 ). |
Hi, I wanted to ask what the state of this issue is? I would really like to report deprecated keys in the configuration for our software (MapProxy) via json-schema. Is there a possibility to hook into the validation code? EDIT: I worked it out and do something like this, even though it is not perfect as it also raises some parent errors: class DeprecationError(ValidationError):
pass
def deprecated(validator: Validator, value: Any, instance: Any, schema: Schema):
yield DeprecationError(
f"Value '{instance}' conforming to schema {schema} is deprecated",
validator=validator,
validator_value=value,
instance=instance,
schema=schema,
)
CustomValidator = extend(Draft202012Validator, validators={ 'deprecated': deprecated }) |
Usage example:
I can start working on a PR if the maintainers are interested and the suggested API makes sense.
The text was updated successfully, but these errors were encountered: