Skip to content

Commit 22c4d0d

Browse files
committed
bug: fix relative url for refs
fix #88
1 parent c2d93c6 commit 22c4d0d

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

src/components/Instance/StringRestraints/index.svelte

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
3131
const tippy = tippy_orig || noop;
3232
33-
3433
import Range from "../Types/Range.svelte";
3534
3635
import formats from "../Types/String/formats";

src/components/Instance/index.svelte

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
{#if ref}
4545
<div>extends</div>
4646
<div>
47-
<a href={'#' + relative_ref(ref)}>{ref}</a>
47+
<a href={relative_ref(ref)}>{ref}</a>
4848

4949
{#if is_expanded_ref}
5050
<input on:click={remove_ref} type="button" value="unexpand" />
@@ -157,6 +157,9 @@
157157
$: if (!id) id = href || "";
158158
$: if (id && !id.includes("#")) id = id + "#";
159159
160+
$: if (href && !href.includes("#")) {
161+
href = href + "#";
162+
}
160163
const fetch_ref = async () => {
161164
loading_ref = true;
162165
@@ -181,10 +184,11 @@
181184
182185
function relative_ref(ref) {
183186
if (ref.startsWith("#")) {
184-
return id.replace(/#.*/, "") + ref;
187+
console.log({ ref, id });
188+
return "#" + id.replace(/#.*/, "") + ref;
185189
}
186190
187-
return ref;
191+
return "#" + ref;
188192
}
189193
</script>
190194

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const tap = require("../../tests/svelte_loader");
2+
import { render } from "@testing-library/svelte";
3+
4+
const Instance = require("./index.svelte");
5+
6+
const definition = {
7+
$id: "http://json-schema.org/draft-07/schema#",
8+
type: "object",
9+
properties: {
10+
allOf: { $ref: "#/definitions/schemaArray" },
11+
},
12+
};
13+
14+
const { container } = render(Instance, { definition, href: definition.$id });
15+
16+
const links = Array.from(container.querySelectorAll("a")).map((a) =>
17+
a.getAttribute("href")
18+
);
19+
20+
tap.equal(
21+
links[0],
22+
"#http://json-schema.org/draft-07/schema#/definitions/schemaArray",
23+
"relative definition link is properly resolved"
24+
);

0 commit comments

Comments
 (0)