Skip to content

Commit 99e9db0

Browse files
authored
Merge pull request #5 from G-USI/feature/ref-escape
Add escaping of ~ and / characters
2 parents b147e12 + b8b8b11 commit 99e9db0

File tree

1 file changed

+5
-2
lines changed
  • src/asyncapi_python_codegen/document

1 file changed

+5
-2
lines changed

src/asyncapi_python_codegen/document/ref.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
set_current_doc_path,
2424
DOCUMENT_CONTEXT_STACK,
2525
)
26-
from typing import Any, Callable, Generic, TypeVar, Annotated, Union
26+
from typing import Any, Callable, Generic, TypeVar, Annotated, Union, cast
2727
from typing_extensions import Self
2828

2929

@@ -88,6 +88,7 @@ def flatten(self, max_depth: int = 1000) -> Self:
8888
@classmethod
8989
def parse_ref(cls, data: Any) -> Any:
9090
fp: Union[str, Path]
91+
ref: str
9192

9293
if (ref := data.get("ref")) or (ref := data.get("$ref")):
9394
fp, dp = ref.split("#")
@@ -101,7 +102,9 @@ def parse_ref(cls, data: Any) -> Any:
101102
return {
102103
**data,
103104
"$ref": ref,
104-
"doc_path": dp.split("/")[1:],
105+
"doc_path": tuple(
106+
p.replace("~0", "~").replace("~1", "/") for p in dp.split("/")[1:]
107+
),
105108
"filepath": Path(fp).absolute(),
106109
}
107110

0 commit comments

Comments
 (0)