Skip to content

Commit bef7782

Browse files
committed
fix: add dereferencing and a ref to the example
1 parent a9cb349 commit bef7782

File tree

4 files changed

+69
-8
lines changed

4 files changed

+69
-8
lines changed

package-lock.json

Lines changed: 50 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@
3636
]
3737
},
3838
"dependencies": {
39-
"@json-schema-tools/transpiler": "^1.5.4",
4039
"@etclabscore/monaco-add-json-schema-diagnostics": "^1.0.3",
4140
"@etclabscore/react-monaco-editor": "^1.0.3",
41+
"@json-schema-tools/dereferencer": "^1.2.13",
42+
"@json-schema-tools/transpiler": "^1.5.4",
4243
"@material-ui/core": "^4.5.1",
4344
"@material-ui/icons": "^4.5.1",
4445
"i18next": "^17.3.0",

src/containers/LanguageMenu/LanguageMenu.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const LanguageMenu: React.FC = (props) => {
2323

2424
return (
2525
<>
26-
<Tooltip title={t("Change Language")}>
26+
<Tooltip title={t("Change Language") as string}>
2727
<Button onClick={handleClick}>{supportedLanguages[i18n.language]}</Button>
2828
</Tooltip>
2929
<Menu

src/containers/MyApp.tsx

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { lightTheme, darkTheme } from "../themes/theme";
1010
import { useTranslation } from "react-i18next";
1111
import SplitPane from "react-split-pane";
1212
import Transpiler, { SupportedLanguages } from "@json-schema-tools/transpiler";
13+
import Dereferencer from "@json-schema-tools/dereferencer";
1314
import "./MyApp.css";
1415
import Editor from "@etclabscore/react-monaco-editor";
1516
import { addDiagnostics } from "@etclabscore/monaco-add-json-schema-diagnostics";
@@ -34,7 +35,13 @@ const defaultSchema = {
3435
title: "foo",
3536
type: "number"
3637
}
38+
},
39+
baz: {
40+
"$ref": "#/definitions/baz"
3741
}
42+
},
43+
definitions: {
44+
baz: { type: "number", title: "baz" }
3845
}
3946
};
4047

@@ -55,8 +62,11 @@ const MyApp: React.FC = () => {
5562
function handleTranspile() {
5663
try {
5764
const result = JSON.parse(value);
58-
const tr = new Transpiler(result);
59-
setResults(tr.to(selectedLanguage));
65+
const dereffer = new Dereferencer(result);
66+
dereffer.resolve().then((schema) => {
67+
const tr = new Transpiler(schema);
68+
setResults(tr.to(selectedLanguage));
69+
});
6070
} catch (e) {
6171
console.error(e);
6272
}
@@ -100,9 +110,9 @@ const MyApp: React.FC = () => {
100110
<AppBar position="static" color="default" elevation={0}>
101111
<Toolbar>
102112
<Grid container alignContent="center" alignItems="center" justify="flex-start">
103-
<Typography variant="h6" style={{ paddingRight: "20px" }}>{t("json-schema.tools")}</Typography>
113+
<Typography variant="h6" style={{ paddingRight: "20px" }}>{t("json-schema.tools") as string}</Typography>
104114
<Typography variant="caption" style={{ paddingRight: "5px" }}>
105-
{t("playground")}
115+
{t("playground") as string}
106116
</Typography>
107117
</Grid>
108118
<Grid container alignContent="center" alignItems="center" justify="flex-end">
@@ -130,15 +140,15 @@ const MyApp: React.FC = () => {
130140
</Menu>
131141
</>
132142
}
133-
<Tooltip title={t("json-schema.tools Github")}>
143+
<Tooltip title={t("json-schema.tools Github") as string}>
134144
<IconButton
135145
onClick={() =>
136146
window.open("https://github.com/json-schema-tools/")
137147
}>
138148
<CodeIcon />
139149
</IconButton>
140150
</Tooltip>
141-
<Tooltip title={t("Toggle Dark Mode")}>
151+
<Tooltip title={t("Toggle Dark Mode") as string}>
142152
<IconButton onClick={darkMode.toggle}>
143153
{darkMode.value ? <Brightness3Icon /> : <WbSunnyIcon />}
144154
</IconButton>

0 commit comments

Comments
 (0)