Skip to content

Commit

Permalink
Set the $schema key with the schema dialect
Browse files Browse the repository at this point in the history
For each generated schema
  • Loading branch information
candleindark committed Apr 13, 2024
1 parent 57b503a commit 862f25f
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions dandischema/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import re
from typing import Any, Iterator, List, Union, get_args, get_origin

from pydantic.json_schema import GenerateJsonSchema, JsonSchemaValue
from pydantic_core import core_schema
from pydantic.json_schema import GenerateJsonSchema, JsonSchemaMode, JsonSchemaValue
from pydantic_core import CoreSchema, core_schema

TITLE_CASE_LOWER = {
"a",
Expand Down Expand Up @@ -69,6 +69,16 @@ class TransitionalGenerateJsonSchema(GenerateJsonSchema):
schema generation process are the same as the behavior in Pydantic V1.
"""

def generate(
self, schema: CoreSchema, mode: JsonSchemaMode = "validation"
) -> JsonSchemaValue:
json_schema = super().generate(schema, mode)

# Set the `$schema` key with the schema dialect
json_schema["$schema"] = self.schema_dialect

return json_schema

def nullable_schema(self, schema: core_schema.NullableSchema) -> JsonSchemaValue:
# Override the default behavior for handling a schema that allows null values
# With this override, `Optional` fields will not be indicated
Expand Down

0 comments on commit 862f25f

Please sign in to comment.