@@ -10,16 +10,45 @@ import { lightTheme, darkTheme } from "../themes/theme";
1010import { useTranslation } from "react-i18next" ;
1111import SplitPane from "react-split-pane" ;
1212import Transpiler , { SupportedLanguages } from "@json-schema-tools/transpiler" ;
13+ import Dereferencer from "@json-schema-tools/dereferencer" ;
1314import "./MyApp.css" ;
1415import Editor from "@etclabscore/react-monaco-editor" ;
1516import { addDiagnostics } from "@etclabscore/monaco-add-json-schema-diagnostics" ;
1617
1718const 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+
1948const 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