Skip to content
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

Validate class object with jsonschema #61

Open
jugaadi opened this issue Mar 1, 2023 · 4 comments
Open

Validate class object with jsonschema #61

jugaadi opened this issue Mar 1, 2023 · 4 comments

Comments

@jugaadi
Copy link

jugaadi commented Mar 1, 2023

Will it be a good idea to pursue class object validation with jsonschema? Can we maintain a protocol instead of the current JSON class ?

@handrews
Copy link
Contributor

handrews commented Mar 4, 2023

@jugaadi I'm (obviously) not the owner of this project, but I'm confused about what you are asking. What do you mean by "class object validation"? JSON Schema works on its own JSON-derived data model which doesn't have a concept of class as in OO programming.

jschon's JSON class does a lot of important work, particularly by enabling upward traversals, and removing it would require a drastic re-architecting of the package.

@jugaadi
Copy link
Author

jugaadi commented Mar 4, 2023

@jugaadi I'm (obviously) not the owner of this project, but I'm confused about what you are asking. What do you mean by "class object validation"? JSON Schema works on its own JSON-derived data model which doesn't have a concept of class as in OO programming.

Yes.. I was wondering whether how I can use JSON Schema to define constraints for dataclass/pydantic class object.

jschon's JSON class does a lot of important work, particularly by enabling upward traversals, and removing it would require a drastic re-architecting of the package.

Completely agree. I wanted to know how to make a dataclass/pydantic equivalent of the jschon JSON class.

@handrews
Copy link
Contributor

handrews commented Mar 4, 2023

@jugaadi oh, I see. My Python knowledge is a little dated and I had not been aware of the dataclass standard module, although I've heard of Pydantic. It looks like Pydantic will generate JSON Schemas from their version of the module, but it looks like thy're using draft-04/OpenAPI 3.0.

So when you say "maintain a protocol" you mean some sort of interface that both jschon's JSON class and dataclasses could implement? Alternatively, you could add a jschon.json.JSON constructor that took a dataclass in lieu of regular JSON data.... hmmm.... interesting. I'm not sure I know what the ideal way to do this would be, but I think I understand your point now.

Are you trying to both generate a schema from a dataclass (as Pydantic does) and treate dataclass instances as schema instances for validatin/annotation purposes?

@jugaadi
Copy link
Author

jugaadi commented Mar 6, 2023

@handrews Thanks for your inputs.

@jugaadi oh, I see. My Python knowledge is a little dated and I had not been aware of the dataclass standard module, although I've heard of Pydantic. It looks like Pydantic will generate JSON Schemas from their version of the module, but it looks like thy're using draft-04/OpenAPI 3.0.

dataclass/pydantic is just an example. It can be a regular class instance too.

So when you say "maintain a protocol" you mean some sort of interface that both jschon's JSON class and dataclasses could implement? Alternatively, you could add a jschon.json.JSON constructor that took a dataclass in lieu of regular JSON data.... hmmm.... interesting. I'm not sure I know what the ideal way to do this would be, but I think I understand your point now.

Yes. Some form of extensibility would help a lot.

Are you trying to both generate a schema from a dataclass (as Pydantic does) and treate dataclass instances as schema instances for validatin/annotation purposes?

We're basically marshalling the pydantic/dataclass/regular object into another schema-defined json. Therefore, the source schema doesnt matter much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants