Skip to content

Commit

Permalink
fix: json schema of LinkId
Browse files Browse the repository at this point in the history
  • Loading branch information
sushichan044 committed Oct 16, 2024
1 parent 504ab72 commit e77fe1b
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions common/birdxplorer_common/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@
from pydantic import Field as PydanticField
from pydantic import (
GetCoreSchemaHandler,
GetJsonSchemaHandler,
HttpUrl,
TypeAdapter,
computed_field,
model_validator,
)
from pydantic.alias_generators import to_camel
from pydantic.json_schema import JsonSchemaValue
from pydantic.main import IncEx
from pydantic_core import core_schema

Expand Down Expand Up @@ -751,6 +753,20 @@ def __get_pydantic_core_schema__(cls, _source_type: Any, _handler: GetCoreSchema
),
)

@classmethod
def __get_pydantic_json_schema__(
cls, core_schema: core_schema.CoreSchema, handler: GetJsonSchemaHandler
) -> JsonSchemaValue:
json_schema = handler(core_schema)
json_schema = handler.resolve_ref_schema(json_schema)
# __get_pydantic_core_schema__ に is_instance_schema を追加したが、
# APIから返却する際の実態は string (uuid) のみである
# この差分により、openapi specを自動生成する際に不要な anyOf: [] が生成されてしまうのを抑制する
del json_schema["anyOf"]
json_schema["type"] = "string"
json_schema["format"] = "uuid"
return json_schema

@classmethod
def validate(cls, v: Any) -> "LinkId":
return cls(v)
Expand Down

0 comments on commit e77fe1b

Please sign in to comment.