Replies: 1 comment
|
I would argue you're better off doing this with Pydantic unless you have a reason why you want to propagate the consumer-side schemas (e.g., not everyone in the consumer side uses Pydantic or Python). # // dependencies = ['asdf', 'consumer']
import asdf
from consumer.domain.models import Image
from consumer.dto.models import ImageDTO
# Validate & parse to your domain object
with asdf.open('/path/to/producer/file.asdf') as af:
img = Image.model_validate(af.tree)
# Validate & parse to your data transfer object
with asdf.open('/path/to/producer/file.asdf') as af:
img = ImageDTO.model_validate(af.tree) |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Structural typing or better known as duck typing allows you, as the consumer, to:
My motivation for this is, when I read an ASDF file, I am already using duck typing because I do not want my producer's data model to be exposed into my application (e.g., anticorruption layer).
I want to brainstorm what something like this might look like. I can think of two styles:
ltgt).Idea (1) you can already do with no changes. Idea (2) I am not entirely convinced a new tag is necessary since you can do this with JSON
object:..., however I argue the JSON object schema semantic is not very readable at scale. I think we can come up with a better tag with a simpler semantic vocabulary.
I'm posting this here in
asdfinstead ofasdf-standardbecause I think it could go both ways and not all languages favor duck typing. Feel free to move this thread.All reactions