Skip to content

Commit 862f25f

Browse files
committed
Set the $schema key with the schema dialect
For each generated schema
1 parent 57b503a commit 862f25f

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

dandischema/utils.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import re
44
from typing import Any, Iterator, List, Union, get_args, get_origin
55

6-
from pydantic.json_schema import GenerateJsonSchema, JsonSchemaValue
7-
from pydantic_core import core_schema
6+
from pydantic.json_schema import GenerateJsonSchema, JsonSchemaMode, JsonSchemaValue
7+
from pydantic_core import CoreSchema, core_schema
88

99
TITLE_CASE_LOWER = {
1010
"a",
@@ -69,6 +69,16 @@ class TransitionalGenerateJsonSchema(GenerateJsonSchema):
6969
schema generation process are the same as the behavior in Pydantic V1.
7070
"""
7171

72+
def generate(
73+
self, schema: CoreSchema, mode: JsonSchemaMode = "validation"
74+
) -> JsonSchemaValue:
75+
json_schema = super().generate(schema, mode)
76+
77+
# Set the `$schema` key with the schema dialect
78+
json_schema["$schema"] = self.schema_dialect
79+
80+
return json_schema
81+
7282
def nullable_schema(self, schema: core_schema.NullableSchema) -> JsonSchemaValue:
7383
# Override the default behavior for handling a schema that allows null values
7484
# With this override, `Optional` fields will not be indicated

0 commit comments

Comments
 (0)