Skip to content

Commit

Permalink
fix: generated schema id should not be same as tag
Browse files Browse the repository at this point in the history
id follows "${schema.tag}/schema"
  • Loading branch information
ketozhang committed Aug 26, 2024
1 parent 7c0abfc commit e5eb795
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion asdf_pydantic/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def generate(self, schema, mode="validation"):

if self.tag_uri:
json_schema["$schema"] = self.schema_dialect
json_schema["id"] = self.tag_uri
json_schema["id"] = f"{self.tag_uri}/schema"
json_schema["tag"] = f"tag:{self.tag_uri.split('://', maxsplit=2)[-1]}"

# TODO: Convert jsonschema 2020-12 to ASDF schema
Expand Down
21 changes: 17 additions & 4 deletions tests/test_model.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import pytest
import yaml
from asdf.extension import TagDefinition

from asdf_pydantic import AsdfPydanticModel


def tag(request):
return request.param


########################################################################################
# TAGS
########################################################################################
@pytest.mark.parametrize(
"tag",
(
Expand Down Expand Up @@ -49,3 +49,16 @@ class TestModel(AsdfPydanticModel):
_tag = tag

assert TestModel.get_tag_uri()


########################################################################################
# SCHEMA
########################################################################################
def test_generated_schema_id_uses_tag_in_pattern():
class TestModel(AsdfPydanticModel):
_tag = "asdf://asdf-pydantic/tags/test-0.0.1"

assert (
yaml.safe_load(TestModel.model_asdf_schema())["id"]
== "asdf://asdf-pydantic/tags/test-0.0.1/schema"
)

0 comments on commit e5eb795

Please sign in to comment.