File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 6666 "is-svg" : " ^4.3.1" ,
6767 "json-schema-to-typescript" : " ^10.1.4" ,
6868 "json-to-go" : " gist:0d0b8324131c80eeb7e1df20001be32f" ,
69+ "json-to-zod" : " ^1.1.2" ,
6970 "json-ts" : " ^1.6.4" ,
7071 "json_typegen_wasm" : " ^0.7.0" ,
7172 "jsonld" : " ^5.2.0" ,
Original file line number Diff line number Diff line change 1+ import ConversionPanel from "@components/ConversionPanel" ;
2+ import { EditorPanelProps } from "@components/EditorPanel" ;
3+ import Form , { InputType } from "@components/Form" ;
4+ import { useSettings } from "@hooks/useSettings" ;
5+ import * as React from "react" ;
6+ import { useCallback } from "react" ;
7+
8+ interface Settings {
9+ rootName : string ;
10+ }
11+
12+ const formFields = [
13+ {
14+ type : InputType . TEXT_INPUT ,
15+ key : "rootName" ,
16+ label : "Root Schema Name"
17+ }
18+ ] ;
19+
20+ export default function JsonToZod ( ) {
21+ const name = "JSON to Zod Schema" ;
22+
23+ const [ settings , setSettings ] = useSettings ( name , {
24+ rootName : "schema"
25+ } ) ;
26+
27+ const transformer = useCallback (
28+ async ( { value } ) => {
29+ const { jsonToZod } = await import ( "json-to-zod" ) ;
30+ return jsonToZod ( JSON . parse ( value ) , settings . rootName , true ) ;
31+ } ,
32+ [ settings ]
33+ ) ;
34+
35+ const getSettingsElement = useCallback < EditorPanelProps [ "settingElement" ] > (
36+ ( { open, toggle } ) => {
37+ return (
38+ < Form < Settings >
39+ title = { name }
40+ onSubmit = { setSettings }
41+ open = { open }
42+ toggle = { toggle }
43+ formsFields = { formFields }
44+ initialValues = { settings }
45+ />
46+ ) ;
47+ } ,
48+ [ ]
49+ ) ;
50+
51+ return (
52+ < ConversionPanel
53+ transformer = { transformer }
54+ editorTitle = "JSON"
55+ editorLanguage = "json"
56+ resultTitle = "Zod Schema"
57+ resultLanguage = { "typescript" }
58+ editorSettingsElement = { getSettingsElement }
59+ settings = { settings }
60+ />
61+ ) ;
62+ }
Original file line number Diff line number Diff line change @@ -141,6 +141,12 @@ export const categorizedRoutes = [
141141 path : "/json-to-toml" ,
142142 packageUrl : "https://www.npmjs.com/package/@iarna/toml" ,
143143 packageName : "@iarna/toml"
144+ } ,
145+ {
146+ label : "to Zod Schema" ,
147+ path : "/json-to-zod" ,
148+ packageUrl : "https://github.com/rsinohara/json-to-zod" ,
149+ packageName : "json-to-zod"
144150 }
145151 ]
146152 } ,
Original file line number Diff line number Diff line change @@ -5997,6 +5997,13 @@ json-stringify-safe@^5.0.1, json-stringify-safe@~5.0.1:
59975997 version "1.0.0"
59985998 resolved "https://gist.github.com/0d0b8324131c80eeb7e1df20001be32f.git#3c19dec6061daff466b13783fea94c49e4f62e86"
59995999
6000+ json-to-zod@^1.1.2 :
6001+ version "1.1.2"
6002+ resolved "https://registry.yarnpkg.com/json-to-zod/-/json-to-zod-1.1.2.tgz#626d4432f329c51089120858c9404234567dda1b"
6003+ integrity sha512-6YDvnY8oOS5v1H1CWUvfNJkCI3SGbmCwWMytndPHzwyrr1K9ayNXL4rvOSf7WCy3c3Pxu2brvt4idZCkKh9gfQ==
6004+ dependencies :
6005+ prettier "^2.3.2"
6006+
60006007json-ts@^1.6.4 :
60016008 version "1.6.4"
60026009 resolved "https://registry.yarnpkg.com/json-ts/-/json-ts-1.6.4.tgz#e4423b8ccdb3069306f4727d6a579790675abbd0"
@@ -7853,6 +7860,11 @@ prettier@^2.1.1, prettier@^2.2.0:
78537860 resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.3.2.tgz#ef280a05ec253712e486233db5c6f23441e7342d"
78547861 integrity sha512-lnJzDfJ66zkMy58OL5/NY5zp70S7Nz6KqcKkXYzn2tMVrNxvbqaBpg7H3qHaLxCJ5lNMsGuM8+ohS7cZrthdLQ==
78557862
7863+ prettier@^2.3.2 :
7864+ version "2.7.1"
7865+ resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.7.1.tgz#e235806850d057f97bb08368a4f7d899f7760c64"
7866+ integrity sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g==
7867+
78567868pretty-hrtime@^1.0.3 :
78577869 version "1.0.3"
78587870 resolved "https://registry.yarnpkg.com/pretty-hrtime/-/pretty-hrtime-1.0.3.tgz#b7e3ea42435a4c9b2759d99e0f201eb195802ee1"
You can’t perform that action at this time.
0 commit comments