-
Notifications
You must be signed in to change notification settings - Fork 9
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
Generate JSON Schema #3
Comments
Here is the current JSON schema, >>> from pyodide_lock import PyodideLockSpec
>>> print(PyodideLockSpec.schema_json(indent=2))
{
"title": "PyodideLockSpec",
"description": "A specification for the pyodide-lock.json file.",
"type": "object",
"properties": {
"info": {
"$ref": "#/definitions/InfoSpec"
},
"packages": {
"title": "Packages",
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/PackageSpec"
}
}
},
"required": [
"info",
"packages"
],
"additionalProperties": false,
"definitions": {
"InfoSpec": {
"title": "InfoSpec",
"type": "object",
"properties": {
"arch": {
"title": "Arch",
"default": "wasm32",
"enum": [
"wasm32",
"wasm64"
],
"type": "string"
},
"platform": {
"title": "Platform",
"type": "string"
},
"version": {
"title": "Version",
"type": "string"
},
"python": {
"title": "Python",
"type": "string"
}
},
"required": [
"platform",
"version",
"python"
],
"additionalProperties": false
},
"PackageSpec": {
"title": "PackageSpec",
"type": "object",
"properties": {
"name": {
"title": "Name",
"type": "string"
},
"version": {
"title": "Version",
"type": "string"
},
"file_name": {
"title": "File Name",
"type": "string"
},
"install_dir": {
"title": "Install Dir",
"type": "string"
},
"sha256": {
"title": "Sha256",
"default": "",
"type": "string"
},
"package_type": {
"title": "Package Type",
"default": "package",
"enum": [
"package",
"cpython_module",
"shared_library",
"static_library"
],
"type": "string"
},
"imports": {
"title": "Imports",
"default": [],
"type": "array",
"items": {
"type": "string"
}
},
"depends": {
"title": "Depends",
"default": [],
"type": "array",
"items": {
"type": "string"
}
},
"unvendored_tests": {
"title": "Unvendored Tests",
"default": false,
"type": "boolean"
},
"shared_library": {
"title": "Shared Library",
"default": false,
"type": "boolean"
}
},
"required": [
"name",
"version",
"file_name",
"install_dir"
],
"additionalProperties": false
}
}
} |
Right: so with that schema in-hand, if it were checked in, in e.g. From a JSON schema, stdlib-compatible static types can be generate with: ... which could also be checked in, documented, etc. But these won't catch things like "a negative number," without a lot of jumping jacks. Alternately, the relationship with Or, libraries can be used to validate instances against the schema at runtime: The value of having these as dependencies is then debateable vs a one-stop-shop like At-rest schema can plug into existing documentation toolchains: As well as property-based testing tools: |
Thanks for the feedback!
It feels to me like it depends on the perspective: If we are talking about Python then pydantic would do all the validation needed, but then JS validation would be less optimal. If we are talking about JS then indeed starting from the schema would probably be easier but then in Python one would need to re-implement parts of what pydantic does. Personally, for now, I would be +1 to go with the first option of committing That's something we can have now, which would already be an improvement over the current situation. If it turns out that this is not enough, and that the produced schema doesn't allow sufficient validation on the JS side, I'm open to re-designing it differently, but it would likely need more work in this repo. |
In pyodide/pyodide#3573 @bollwyvl requested that it would be useful to generate a JSON Schema for
pyodide-lock.json
.We can do that from the current Pydantic spec, though the question is where to put it (keeping in mind that this is a Python package).
@bollwyvl could you please explain more what would work for you?
The text was updated successfully, but these errors were encountered: