-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add YAML schema to asdf-pydantic models and trees #19
Comments
No (see asdf-format/asdf#1793). I was able to get asdf-pydantic/tests/examples/test_node.py Lines 77 to 81 in cb4387c
asdf-pydantic/tests/examples/test_rectangle.py Lines 42 to 46 in cb4387c
ASDF seems to accept this schema (not sure if it's a valid JSONSchema draft 4): ---
type: object
anyOf:
- $ref: "#/definitions/AsdfNode"
definitions:
AsdfNode:
type: object
properties:
name:
type: string
child:
anyOf:
- $ref: "#/definitions/AsdfNode"
- type: null |
The current usage to have ASDF use schemas to validate tags involves two parts:
It's not a good experience as you need to take each model and fill out the converters, tags, then separately the resource map. Currently we have a convenient method for the converters... asdf-pydantic/tests/examples/test_node.py Lines 57 to 62 in cb4387c
...where the users would also use the same converter for registering tags (i.e., Something similar for the tags would be nice but I don't really like having two convenience methods... AsdfPydanticConverter.add_models(AsdfNode)
AsdfPydanticTagRegistry.add(AsdfNode.get_tag_definition())
class TestExtension(Extension):
extension_uri = "asdf://asdf-pydantic/examples/extensions/test-1.0.0"
converters = [AsdfPydanticConverter()]
tags = [*AsdfPydanticTagRegistry().tags] |
Pydantic automatically supports JSON Schema Draft 2020-12 for all JSON-serializable types. Custom types that are not
pydantic.BaseModel
and must have additional parts to have a JSON schema. Pydantic docs outline various ways of doing this and not all methods require the object to be JSON serializable, just have a schema.ASDF schemas, are JSON Schema Draft 4 (older), which has been converted to YAML as specified by their schema docs.
Implementation
If ASDF can support the newer JSON schema, then implementation is extremely simple. We leave it to the user to define schemas for their custom data type.
Issue: Adapt ASDF types (tagged objects) with existing schema
However, there are custom data types that do have ASDF schemas, but not immediately available to pydantic:
asdf-pydantic
like Roman's WFI imageOne may hack around this by directly using ASDF's YAML schema and associate it with a new Pydantic field type. In this example, I use ndarray.
This hack could be a good implementation but forces users to migrate all
np.ndarray
to something we manage (e.g.,asdf_pydantic.builtin.NDArrayType
). This is unfavorable to scale to all various core and extension types of ASDF.Issue: ASDF does not provider helpers for tree schemas
In ASDF, the tree itself also can have a schema.
asdf-pydantic also does not have many features for trees. Users make trees with our models:
However, our models themselves can also be trees
This itself, given the model has a JSON schema, can be enough to generate an ASDF schema. We might not need an ASDF helper
TODO:
Issue: ASDF does not provider helpers for tree schemasasdf.extension.TagDefinitions
)The text was updated successfully, but these errors were encountered: