-
Notifications
You must be signed in to change notification settings - Fork 1
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
644cf44
commit 5b14573
Showing
3 changed files
with
62 additions
and
60 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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import type { JSONSchema } from "./types"; | ||
|
||
export interface SchemaTSOptions { | ||
useSingleQuotes: boolean; | ||
useCamelCase: boolean; | ||
} | ||
|
||
export interface SchemaTSContextI { | ||
options: SchemaTSOptions; | ||
root: JSONSchema; | ||
schema: JSONSchema; | ||
parents: JSONSchema[] | ||
} | ||
|
||
|
||
export class SchemaTSContext implements SchemaTSContextI { | ||
options: SchemaTSOptions; | ||
root: JSONSchema; | ||
schema: JSONSchema; | ||
parents: JSONSchema[]; | ||
|
||
constructor( | ||
options: SchemaTSOptions, | ||
root: JSONSchema, | ||
schema: JSONSchema, | ||
parents: JSONSchema[] = [] | ||
) { | ||
this.options = options; | ||
this.schema = schema; | ||
this.root = root; | ||
this.parents = parents; | ||
} | ||
|
||
// Clone the context with the option to add a new parent | ||
clone(newParent: JSONSchema): SchemaTSContext { | ||
// Create a new array for parents to avoid mutation of the original array | ||
const newParents = [...this.parents, newParent]; | ||
return new SchemaTSContext(this.options, this.root, this.schema, newParents); | ||
} | ||
} | ||
|
||
export const defaultOptions: SchemaTSOptions = { useSingleQuotes: true, useCamelCase: false }; |
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,18 @@ | ||
export interface JSONSchema { | ||
title: string; | ||
properties?: { [key: string]: JSONSchemaProperty }; | ||
required?: string[]; | ||
type?: string; | ||
items?: JSONSchema; | ||
$defs?: { [key: string]: JSONSchema }; | ||
additionalProperties?: boolean | JSONSchemaProperty; | ||
} | ||
|
||
export type JSONSchemaProperty = { | ||
type?: string; | ||
properties?: { [key: string]: JSONSchemaProperty }; | ||
items?: JSONSchemaProperty; | ||
required?: string[]; | ||
$ref?: string; | ||
additionalProperties?: boolean | JSONSchemaProperty; | ||
}; |