File tree Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ * Custom JSON Schema format validator for URIs.
3+ *
4+ * @param {string } input The string to validate.
5+ * @returns {boolean } True if the input is a valid URI or an empty string, false otherwise.
6+ */
7+ export function safeUriValidator ( input ) {
8+ if ( input === "" ) {
9+ return true ;
10+ }
11+
12+ // Trim whitespace from the input.
13+ const trimmedInput = input . trim ( ) ;
14+
15+ try {
16+ // eslint-disable-next-line no-new
17+ new URL ( trimmedInput ) ;
18+ return true ;
19+ } catch ( e ) {
20+ return false ;
21+ }
22+ }
Original file line number Diff line number Diff line change 11import { Validator } from "jsonschema" ;
22import { ddbSchema , jsonSchema } from "../data/schemas" ;
3+ import { safeUriValidator } from "./safeFormats" ;
4+
5+ const validator = new Validator ( ) ;
6+ validator . customFormats . uri = safeUriValidator ;
37
48export function jsonDiagramIsValid ( obj ) {
5- return new Validator ( ) . validate ( obj , jsonSchema ) . valid ;
9+ return validator . validate ( obj , jsonSchema ) . valid ;
610}
711
812export function ddbDiagramIsValid ( obj ) {
9- return new Validator ( ) . validate ( obj , ddbSchema ) . valid ;
13+ return validator . validate ( obj , ddbSchema ) . valid ;
1014}
You can’t perform that action at this time.
0 commit comments