-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Use contentSchema keyword for JSON schema #6715
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
Conversation
Deploying with
|
| Latest commit: |
1380b8c
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://1a721c94.pydantic-docs2.pages.dev |
| Branch Preview URL: | https://json-content-schema.pydantic-docs2.pages.dev |
|
please review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏻
pydantic/json_schema.py
Outdated
| @@ -1609,13 +1609,13 @@ def json_schema(self, schema: core_schema.JsonSchema) -> JsonSchemaValue: | |||
| Returns: | |||
| The generated JSON schema. | |||
| """ | |||
| content_core_schema = schema['schema'] if 'schema' in schema else core_schema.any_schema() | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like the following code more but it will always call core_schema.any_schema()
| content_core_schema = schema['schema'] if 'schema' in schema else core_schema.any_schema() | |
| content_core_schema = schema.get('schema', core_schema.any_schema()) |
It would be nice to have a constant like core_schema.DEFAULT_SCHEMA that will hold this value and allow the above to be as efficient as if..in.
pydantic/json_schema.py
Outdated
| @@ -1609,13 +1609,13 @@ def json_schema(self, schema: core_schema.JsonSchema) -> JsonSchemaValue: | |||
| Returns: | |||
| The generated JSON schema. | |||
| """ | |||
| content_core_schema = schema['schema'] if 'schema' in schema else core_schema.any_schema() | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| content_core_schema = schema['schema'] if 'schema' in schema else core_schema.any_schema() | |
| content_core_schema = schema.get('schema') or core_schema.any_schema() |
I think this is the zero-overhead version of your suggestion, which works since all schemas must have a type key so schema.get('schema') will be falsy only if it is None (and having the value None is not meaningfully different from not being present)
Closes #6663
Selected Reviewer: @lig