Skip to content

Commit 8e0c4ab

Browse files
authored
Merge pull request #57 from json-schema-tools/fix/general-fixups
Fix/general fixups
2 parents c53be3e + bef7782 commit 8e0c4ab

File tree

5 files changed

+94
-10
lines changed

5 files changed

+94
-10
lines changed

.circleci/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,6 @@ workflows:
8787
- build
8888
- release:
8989
filters: *filter-only-master
90+
context: sem-rel-json-schema-tools
9091
requires:
9192
- hold

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: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,45 @@ 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";
1617

1718
const languages: SupportedLanguages[] = ["typescript", "golang", "python", "rust"];
1819

20+
const defaultSchema = {
21+
title: "example",
22+
type: "object",
23+
required: ["thing"],
24+
properties: {
25+
thing: {
26+
title: "bar",
27+
description: "This is a bar thing",
28+
type: "string",
29+
enum: [ "one", "two", "three" ]
30+
},
31+
otherThing: {
32+
description: "generated Title when there is none",
33+
type: "array",
34+
items: {
35+
title: "foo",
36+
type: "number"
37+
}
38+
},
39+
baz: {
40+
"$ref": "#/definitions/baz"
41+
}
42+
},
43+
definitions: {
44+
baz: { type: "number", title: "baz" }
45+
}
46+
};
47+
1948
const MyApp: React.FC = () => {
2049
const darkMode = useDarkMode();
2150
const [, setIsEditorReady] = useState(false);
22-
const [defaultValue] = useState(`{\n "title": "foo",\n "type": "string"\n}`);
51+
const [defaultValue] = useState(JSON.stringify(defaultSchema, undefined, " "));
2352
const [value, setValue] = useState(defaultValue);
2453
const [results, setResults] = useState("");
2554
const [languageAnchorEl, setLanguageAnchorEl] = React.useState<null | HTMLElement>(null);
@@ -33,8 +62,11 @@ const MyApp: React.FC = () => {
3362
function handleTranspile() {
3463
try {
3564
const result = JSON.parse(value);
36-
const tr = new Transpiler(result);
37-
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+
});
3870
} catch (e) {
3971
console.error(e);
4072
}
@@ -78,9 +110,9 @@ const MyApp: React.FC = () => {
78110
<AppBar position="static" color="default" elevation={0}>
79111
<Toolbar>
80112
<Grid container alignContent="center" alignItems="center" justify="flex-start">
81-
<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>
82114
<Typography variant="caption" style={{ paddingRight: "5px" }}>
83-
{t("playground")}
115+
{t("playground") as string}
84116
</Typography>
85117
</Grid>
86118
<Grid container alignContent="center" alignItems="center" justify="flex-end">
@@ -108,15 +140,15 @@ const MyApp: React.FC = () => {
108140
</Menu>
109141
</>
110142
}
111-
<Tooltip title={t("json-schema.tools Github")}>
143+
<Tooltip title={t("json-schema.tools Github") as string}>
112144
<IconButton
113145
onClick={() =>
114-
window.open("https://github.com/json-schema-tools/playground")
146+
window.open("https://github.com/json-schema-tools/")
115147
}>
116148
<CodeIcon />
117149
</IconButton>
118150
</Tooltip>
119-
<Tooltip title={t("Toggle Dark Mode")}>
151+
<Tooltip title={t("Toggle Dark Mode") as string}>
120152
<IconButton onClick={darkMode.toggle}>
121153
{darkMode.value ? <Brightness3Icon /> : <WbSunnyIcon />}
122154
</IconButton>

0 commit comments

Comments
 (0)