Skip to content

Commit

Permalink
fix: remove type field from schema if ref exists
Browse files Browse the repository at this point in the history
  • Loading branch information
ketozhang committed Nov 17, 2024
1 parent 6c56cb2 commit ef9d068
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
10 changes: 10 additions & 0 deletions asdf_pydantic/schema.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Optional

from pydantic import WithJsonSchema
from pydantic.json_schema import GenerateJsonSchema

DEFAULT_ASDF_SCHEMA_REF_TEMPLATE = "#/definitions/{model}"
Expand Down Expand Up @@ -60,3 +61,12 @@ def generate(self, schema, mode="validation"):
}

return json_schema


class WithAsdfSchema(WithJsonSchema):
def __init__(self, asdf_schema: dict, **kwargs):
super().__init__(asdf_schema, **kwargs)


def AsdfTag(tag: str) -> WithAsdfSchema:
return WithAsdfSchema({"$ref": tag})
3 changes: 3 additions & 0 deletions tests/examples/test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

import textwrap
from typing import Annotated
from unittest.mock import MagicMock, patch

import asdf
Expand All @@ -14,6 +15,8 @@

from asdf_pydantic import AsdfPydanticConverter, AsdfPydanticModel

SelfAnnotatedAsdfNode = Annotated[AsdfTag]


class AsdfNode(AsdfPydanticModel):
"""Model for a node in a graph/tree.
Expand Down

0 comments on commit ef9d068

Please sign in to comment.