generated from json-schema-org/repo-template
-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3d1c5df
commit fbb0aa8
Showing
10 changed files
with
275 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,15 @@ | ||
.codeEditor { | ||
overflow-y: auto; | ||
border-radius: 5px; | ||
padding: 8px; | ||
border: 1px solid rgba(0, 0, 0, 0.334); | ||
border-radius: 16px; | ||
height: 100%; | ||
|
||
overflow-y: auto; | ||
} | ||
|
||
.validateBtn { | ||
position: fixed; | ||
right: 10px; | ||
top: 10px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,28 @@ | ||
"use client"; | ||
import { CodeFile } from "@/lib/types"; | ||
|
||
import styles from "./CodeEditor.module.css"; | ||
import ctx from "classnames"; | ||
import { GeistMono } from "geist/font/mono"; | ||
import Editor from "@monaco-editor/react"; | ||
import { Button } from "@chakra-ui/react"; | ||
|
||
export default function CodeEditor({ code }: { code: Object }) { | ||
const codeString = JSON.stringify(code, null, 2); | ||
export default function CodeEditor({ | ||
code, | ||
setCode, | ||
}: { | ||
code: string; | ||
setCode: (code: string) => void; | ||
}) { | ||
return ( | ||
<div className={ctx(styles.codeEditor, GeistMono.className)}> | ||
<Editor language="jsonc" defaultValue={codeString} /> | ||
<Editor | ||
language="json" | ||
defaultValue={code} | ||
value={code} | ||
height={"100%"} | ||
onChange={(code) => setCode(code ? code : "")} | ||
options={{ minimap: { enabled: false }, fontSize: 16 }} | ||
/> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,5 @@ | |
border: 1px solid rgba(0, 0, 0, 0.334); | ||
border-radius: 16px; | ||
height: 100%; | ||
white-space: pre-wrap; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import React from "react"; | ||
import styles from "./Output.module.css"; | ||
|
||
export default function Output() { | ||
return <div className={styles.output}>Output</div>; | ||
export default function Output({ output }: { output: string }) { | ||
return <div className={styles.output}>{output}</div>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import Ajv from "ajv/dist/2020.js"; | ||
// @ts-ignore | ||
import betterAjvErrors from "better-ajv-errors"; | ||
export function ajv(data: any, schema: any) { | ||
const ajv = new Ajv({ allErrors: true, verbose: true }); // options can be passed, e.g. {allErrors: true} | ||
|
||
const validate = ajv.compile(schema); | ||
const valid = validate(data); | ||
const errors = betterAjvErrors(schema, data, validate.errors); | ||
return { valid, errors }; | ||
|
||
// { | ||
// instancePath: '/1', | ||
// schemaPath: '#/items/type', | ||
// keyword: 'type', | ||
// params: { type: 'string' }, | ||
// message: 'must be string' | ||
// }, | ||
} | ||
|
||
import { | ||
validate, | ||
registerSchema, | ||
setMetaSchemaOutputFormat, | ||
unregisterSchema, | ||
} from "@hyperjump/json-schema/draft-2020-12"; | ||
import { BASIC } from "@hyperjump/json-schema/experimental"; | ||
|
||
setMetaSchemaOutputFormat(BASIC); | ||
|
||
export async function hyperjumpValidate(data: any, schema: any) { | ||
registerSchema(schema, "http://example.com/schemas/string"); | ||
try { | ||
const output = await validate("http://example.com/schemas/string", data); | ||
return output; | ||
} catch (e) { | ||
// throw e; | ||
} finally { | ||
unregisterSchema("http://example.com/schemas/string"); | ||
} | ||
// console.log(BASIC); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.