Skip to content

Commit

Permalink
Merge pull request #236 from candleindark/with-schema-dialect
Browse files Browse the repository at this point in the history
Set the `$schema` key with the schema dialect
  • Loading branch information
yarikoptic authored Apr 30, 2024
2 parents baae3d2 + 862f25f commit 2b4eacd
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 2b4eacd

Please sign in to comment.