Test case
1 generated file · +1 −1test/inputs/regressions/unicode-codepoint-length.schema
Mschema-typescriptdefault / TopLevel.ts+1 −1
| @@ -11,7 +11,7 @@ export interface TopLevel { | ||
| 11 | 11 | exact: string; |
| 12 | 12 | maximum: string; |
| 13 | 13 | minimum: string; |
| 14 | - [property: string]: unknown | string | string | string; | |
| 14 | + [property: string]: unknown; | |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | // Converts JSON strings to/from your types |
Test case
2 generated files · +2 −2test/inputs/schema/any.schema
Mschema-flowdefault / TopLevel.js+1 −1
| @@ -12,7 +12,7 @@ | ||
| 12 | 12 | export type TopLevel = { |
| 13 | 13 | foo: mixed; |
| 14 | 14 | values: { [key: string]: mixed }; |
| 15 | - [property: string]: mixed | mixed | { [key: string]: mixed }; | |
| 15 | + [property: string]: mixed; | |
| 16 | 16 | }; |
| 17 | 17 | |
| 18 | 18 | // Converts JSON strings to/from your types |
Mschema-typescriptdefault / TopLevel.ts+1 −1
| @@ -10,7 +10,7 @@ | ||
| 10 | 10 | export interface TopLevel { |
| 11 | 11 | foo: unknown; |
| 12 | 12 | values: { [key: string]: unknown }; |
| 13 | - [property: string]: unknown | unknown | { [key: string]: unknown }; | |
| 13 | + [property: string]: unknown; | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | // Converts JSON strings to/from your types |
Test case
2 generated files · +2 −2test/inputs/schema/bool-string.schema
Mschema-flowdefault / TopLevel.js+1 −1
| @@ -17,7 +17,7 @@ export type TopLevel = { | ||
| 17 | 17 | optional?: string; |
| 18 | 18 | unionWithBool: UnionWithBool; |
| 19 | 19 | unionWithBoolAndEnum: UnionWithBool; |
| 20 | - [property: string]: mixed | (null | string)[] | string[] | null | string | string | string | UnionWithBool | UnionWithBool; | |
| 20 | + [property: string]: mixed; | |
| 21 | 21 | }; |
| 22 | 22 | |
| 23 | 23 | export type UnionWithBool = boolean | string; |
Mschema-typescriptdefault / TopLevel.ts+1 −1
| @@ -15,7 +15,7 @@ export interface TopLevel { | ||
| 15 | 15 | optional?: string; |
| 16 | 16 | unionWithBool: UnionWithBool; |
| 17 | 17 | unionWithBoolAndEnum: UnionWithBool; |
| 18 | - [property: string]: unknown | (null | string)[] | string[] | null | string | string | string | UnionWithBool | UnionWithBool; | |
| 18 | + [property: string]: unknown; | |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | export type UnionWithBool = boolean | string; |
Test case
2 generated files · +2 −2test/inputs/schema/camelCase.schema
Mschema-flowdefault / TopLevel.js+1 −1
| @@ -12,7 +12,7 @@ | ||
| 12 | 12 | export type TopLevel = { |
| 13 | 13 | myProperty?: string; |
| 14 | 14 | secondProperty?: string; |
| 15 | - [property: string]: mixed | string | string; | |
| 15 | + [property: string]: mixed; | |
| 16 | 16 | }; |
| 17 | 17 | |
| 18 | 18 | // Converts JSON strings to/from your types |
Mschema-typescriptdefault / TopLevel.ts+1 −1
| @@ -10,7 +10,7 @@ | ||
| 10 | 10 | export interface TopLevel { |
| 11 | 11 | myProperty?: string; |
| 12 | 12 | secondProperty?: string; |
| 13 | - [property: string]: unknown | string | string; | |
| 13 | + [property: string]: unknown; | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | // Converts JSON strings to/from your types |
Test case
2 generated files · +4 −4test/inputs/schema/class-map-union.schema
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -16,14 +16,14 @@ export type TopLevel = { | ||
| 16 | 16 | export type TopLevelUnion = { |
| 17 | 17 | foo?: Foo; |
| 18 | 18 | bar?: Bar; |
| 19 | - [property: string]: UnionValue | Foo | Bar; | |
| 19 | + [property: string]: UnionValue | Foo | Bar | void; | |
| 20 | 20 | }; |
| 21 | 21 | |
| 22 | 22 | export type Bar = boolean | BarObject | string; |
| 23 | 23 | |
| 24 | 24 | export type BarObject = { |
| 25 | 25 | quux?: number; |
| 26 | - [property: string]: mixed | number; | |
| 26 | + [property: string]: mixed; | |
| 27 | 27 | }; |
| 28 | 28 | |
| 29 | 29 | export type Foo = boolean | number | BarObject; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -14,14 +14,14 @@ export interface TopLevel { | ||
| 14 | 14 | export interface TopLevelUnion { |
| 15 | 15 | foo?: Foo; |
| 16 | 16 | bar?: Bar; |
| 17 | - [property: string]: UnionValue | Foo | Bar; | |
| 17 | + [property: string]: UnionValue | Foo | Bar | undefined; | |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | export type Bar = boolean | BarObject | string; |
| 21 | 21 | |
| 22 | 22 | export interface BarObject { |
| 23 | 23 | quux?: number; |
| 24 | - [property: string]: unknown | number; | |
| 24 | + [property: string]: unknown; | |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | export type Foo = boolean | number | BarObject; |
Test case
2 generated files · +2 −2test/inputs/schema/class-with-additional.schema
Mschema-flowdefault / TopLevel.js+1 −1
| @@ -15,7 +15,7 @@ export type TopLevel = { | ||
| 15 | 15 | |
| 16 | 16 | export type Map = { |
| 17 | 17 | foo?: number; |
| 18 | - [property: string]: boolean | number; | |
| 18 | + [property: string]: boolean | number | void; | |
| 19 | 19 | }; |
| 20 | 20 | |
| 21 | 21 | // Converts JSON strings to/from your types |
Mschema-typescriptdefault / TopLevel.ts+1 −1
| @@ -13,7 +13,7 @@ export interface TopLevel { | ||
| 13 | 13 | |
| 14 | 14 | export interface Map { |
| 15 | 15 | foo?: number; |
| 16 | - [property: string]: boolean | number; | |
| 16 | + [property: string]: boolean | number | undefined; | |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | // Converts JSON strings to/from your types |
Test case
2 generated files · +2 −2test/inputs/schema/const-non-string.schema
Mschema-flowdefault / TopLevel.js+1 −1
| @@ -15,7 +15,7 @@ export type TopLevel = { | ||
| 15 | 15 | kind: Kind; |
| 16 | 16 | ratio: number; |
| 17 | 17 | version: number; |
| 18 | - [property: string]: mixed | number | boolean | Kind | number | number; | |
| 18 | + [property: string]: mixed; | |
| 19 | 19 | }; |
| 20 | 20 | |
| 21 | 21 | export type Kind = |
Mschema-typescriptdefault / TopLevel.ts+1 −1
| @@ -13,7 +13,7 @@ export interface TopLevel { | ||
| 13 | 13 | kind: Kind; |
| 14 | 14 | ratio: number; |
| 15 | 15 | version: number; |
| 16 | - [property: string]: unknown | number | boolean | Kind | number | number; | |
| 16 | + [property: string]: unknown; | |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | export type Kind = "widget"; |
Test case
2 generated files · +2 −2test/inputs/schema/constructor.schema
Mschema-flowdefault / TopLevel.js+1 −1
| @@ -11,7 +11,7 @@ | ||
| 11 | 11 | |
| 12 | 12 | export type TopLevel = { |
| 13 | 13 | constructor?: UnionConstructor; |
| 14 | - [property: string]: mixed | UnionConstructor; | |
| 14 | + [property: string]: mixed; | |
| 15 | 15 | }; |
| 16 | 16 | |
| 17 | 17 | export type UnionConstructor = Constructor | number; |
Mschema-typescriptdefault / TopLevel.ts+1 −1
| @@ -9,7 +9,7 @@ | ||
| 9 | 9 | |
| 10 | 10 | export interface TopLevel { |
| 11 | 11 | constructor?: UnionConstructor; |
| 12 | - [property: string]: unknown | UnionConstructor; | |
| 12 | + [property: string]: unknown; | |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | export type UnionConstructor = object | number; |
Test case
2 generated files · +2 −2test/inputs/schema/cut-enum.schema
Mschema-flowdefault / TopLevel.js+1 −1
| @@ -11,7 +11,7 @@ | ||
| 11 | 11 | |
| 12 | 12 | export type TopLevel = { |
| 13 | 13 | foo: number; |
| 14 | - [property: string]: mixed | number; | |
| 14 | + [property: string]: mixed; | |
| 15 | 15 | }; |
| 16 | 16 | |
| 17 | 17 | // Converts JSON strings to/from your types |
Mschema-typescriptdefault / TopLevel.ts+1 −1
| @@ -9,7 +9,7 @@ | ||
| 9 | 9 | |
| 10 | 10 | export interface TopLevel { |
| 11 | 11 | foo: number; |
| 12 | - [property: string]: unknown | number; | |
| 12 | + [property: string]: unknown; | |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | // Converts JSON strings to/from your types |
Test case
2 generated files · +2 −2test/inputs/schema/date-time-or-string.schema
Mschema-flowdefault / TopLevel.js+1 −1
| @@ -12,7 +12,7 @@ | ||
| 12 | 12 | export type TopLevel = { |
| 13 | 13 | bar: BarUnion; |
| 14 | 14 | foo: string; |
| 15 | - [property: string]: mixed | BarUnion | string; | |
| 15 | + [property: string]: mixed; | |
| 16 | 16 | }; |
| 17 | 17 | |
| 18 | 18 | export type BarUnion = Date | BarEnum; |
Mschema-typescriptdefault / TopLevel.ts+1 −1
| @@ -10,7 +10,7 @@ | ||
| 10 | 10 | export interface TopLevel { |
| 11 | 11 | bar: BarUnion; |
| 12 | 12 | foo: string; |
| 13 | - [property: string]: unknown | BarUnion | string; | |
| 13 | + [property: string]: unknown; | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | export type BarUnion = Date | BarEnum; |
Test case
2 generated files · +2 −2test/inputs/schema/description-with-double-quotes.schema
Mschema-flowdefault / TopLevel.js+1 −1
| @@ -14,7 +14,7 @@ | ||
| 14 | 14 | */ |
| 15 | 15 | export type TopLevel = { |
| 16 | 16 | foo?: boolean; |
| 17 | - [property: string]: mixed | boolean; | |
| 17 | + [property: string]: mixed; | |
| 18 | 18 | }; |
| 19 | 19 | |
| 20 | 20 | // Converts JSON strings to/from your types |
Mschema-typescriptdefault / TopLevel.ts+1 −1
| @@ -12,7 +12,7 @@ | ||
| 12 | 12 | */ |
| 13 | 13 | export interface TopLevel { |
| 14 | 14 | foo?: boolean; |
| 15 | - [property: string]: unknown | boolean; | |
| 15 | + [property: string]: unknown; | |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | // Converts JSON strings to/from your types |
Test case
2 generated files · +2 −2test/inputs/schema/description.schema
Mschema-flowdefault / TopLevel.js+1 −1
| @@ -44,7 +44,7 @@ export type ObjectOrStringObject = { | ||
| 44 | 44 | * This must not get lost |
| 45 | 45 | */ |
| 46 | 46 | prop: number; |
| 47 | - [property: string]: mixed | number; | |
| 47 | + [property: string]: mixed; | |
| 48 | 48 | }; |
| 49 | 49 | |
| 50 | 50 | /** |
Mschema-typescriptdefault / TopLevel.ts+1 −1
| @@ -40,7 +40,7 @@ export interface ObjectOrStringObject { | ||
| 40 | 40 | * This must not get lost |
| 41 | 41 | */ |
| 42 | 42 | prop: number; |
| 43 | - [property: string]: unknown | number; | |
| 43 | + [property: string]: unknown; | |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | /** |
Test case
2 generated files · +2 −2test/inputs/schema/enum-large.schema
Mschema-flowdefault / TopLevel.js+1 −1
| @@ -12,7 +12,7 @@ | ||
| 12 | 12 | export type TopLevel = { |
| 13 | 13 | callsign: Callsign; |
| 14 | 14 | priority: Priority; |
| 15 | - [property: string]: mixed | Callsign | Priority; | |
| 15 | + [property: string]: mixed; | |
| 16 | 16 | }; |
| 17 | 17 | |
| 18 | 18 | export type Callsign = |
Mschema-typescriptdefault / TopLevel.ts+1 −1
| @@ -10,7 +10,7 @@ | ||
| 10 | 10 | export interface TopLevel { |
| 11 | 11 | callsign: Callsign; |
| 12 | 12 | priority: Priority; |
| 13 | - [property: string]: unknown | Callsign | Priority; | |
| 13 | + [property: string]: unknown; | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | export type Callsign = "alpha" | "bravo" | "charlie" | "delta" | "echo" | "foxtrot" | "golf" | "hotel" | "india" | "juliett" | "kilo" | "lima" | "mike" | "november" | "oscar" | "papa" | "quebec" | "romeo" | "sierra" | "tango"; |
Test case
2 generated files · +2 −2test/inputs/schema/enum-with-values.schema
Mschema-flowdefault / TopLevel.js+1 −1
| @@ -11,7 +11,7 @@ | ||
| 11 | 11 | |
| 12 | 12 | export type TopLevel = { |
| 13 | 13 | weekdays: Weekdays; |
| 14 | - [property: string]: mixed | Weekdays; | |
| 14 | + [property: string]: mixed; | |
| 15 | 15 | }; |
| 16 | 16 | |
| 17 | 17 | export type Weekdays = |
Mschema-typescriptdefault / TopLevel.ts+1 −1
| @@ -9,7 +9,7 @@ | ||
| 9 | 9 | |
| 10 | 10 | export interface TopLevel { |
| 11 | 11 | weekdays: Weekdays; |
| 12 | - [property: string]: unknown | Weekdays; | |
| 12 | + [property: string]: unknown; | |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | export type Weekdays = "Monday" | "Tuesday" | "Wednesday" | "Thursday" | "Friday" | "Saturday" | "Sunday"; |
Test case
2 generated files · +2 −2test/inputs/schema/enum.schema
Mschema-flowdefault / TopLevel.js+1 −1
| @@ -15,7 +15,7 @@ export type TopLevel = { | ||
| 15 | 15 | gve: Gve; |
| 16 | 16 | lvc?: Lvc; |
| 17 | 17 | otherArr?: OtherArr[]; |
| 18 | - [property: string]: mixed | Arr[] | string | Gve | Lvc | OtherArr[]; | |
| 18 | + [property: string]: mixed; | |
| 19 | 19 | }; |
| 20 | 20 | |
| 21 | 21 | export type Arr = OtherArr | number; |
Mschema-typescriptdefault / TopLevel.ts+1 −1
| @@ -13,7 +13,7 @@ export interface TopLevel { | ||
| 13 | 13 | gve: Gve; |
| 14 | 14 | lvc?: Lvc; |
| 15 | 15 | otherArr?: OtherArr[]; |
| 16 | - [property: string]: unknown | Arr[] | string | Gve | Lvc | OtherArr[]; | |
| 16 | + [property: string]: unknown; | |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | export type Arr = OtherArr | number; |
Test case
2 generated files · +2 −2test/inputs/schema/fractional-bounds.schema
Mschema-flowdefault / TopLevel.js+1 −1
| @@ -11,7 +11,7 @@ | ||
| 11 | 11 | |
| 12 | 12 | export type TopLevel = { |
| 13 | 13 | value: number; |
| 14 | - [property: string]: mixed | number; | |
| 14 | + [property: string]: mixed; | |
| 15 | 15 | }; |
| 16 | 16 | |
| 17 | 17 | // Converts JSON strings to/from your types |
Mschema-typescriptdefault / TopLevel.ts+1 −1
| @@ -9,7 +9,7 @@ | ||
| 9 | 9 | |
| 10 | 10 | export interface TopLevel { |
| 11 | 11 | value: number; |
| 12 | - [property: string]: unknown | number; | |
| 12 | + [property: string]: unknown; | |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | // Converts JSON strings to/from your types |
Test case
2 generated files · +2 −2test/inputs/schema/go-schema-pattern-properties.schema
Mschema-flowdefault / TopLevel.js+1 −1
| @@ -11,7 +11,7 @@ | ||
| 11 | 11 | |
| 12 | 12 | export type TopLevel = { |
| 13 | 13 | map: { [key: string]: number }; |
| 14 | - [property: string]: mixed | { [key: string]: number }; | |
| 14 | + [property: string]: mixed; | |
| 15 | 15 | }; |
| 16 | 16 | |
| 17 | 17 | // Converts JSON strings to/from your types |
Mschema-typescriptdefault / TopLevel.ts+1 −1
| @@ -9,7 +9,7 @@ | ||
| 9 | 9 | |
| 10 | 10 | export interface TopLevel { |
| 11 | 11 | map: { [key: string]: number }; |
| 12 | - [property: string]: unknown | { [key: string]: number }; | |
| 12 | + [property: string]: unknown; | |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | // Converts JSON strings to/from your types |
Test case
2 generated files · +2 −2test/inputs/schema/haskell-enum-forbidden.schema
Mschema-flowdefault / TopLevel.js+1 −1
| @@ -11,7 +11,7 @@ | ||
| 11 | 11 | |
| 12 | 12 | export type TopLevel = { |
| 13 | 13 | health: Health; |
| 14 | - [property: string]: mixed | Health; | |
| 14 | + [property: string]: mixed; | |
| 15 | 15 | }; |
| 16 | 16 | |
| 17 | 17 | export type Health = |
Mschema-typescriptdefault / TopLevel.ts+1 −1
| @@ -9,7 +9,7 @@ | ||
| 9 | 9 | |
| 10 | 10 | export interface TopLevel { |
| 11 | 11 | health: Health; |
| 12 | - [property: string]: unknown | Health; | |
| 12 | + [property: string]: unknown; | |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | export type Health = "ok" | "error"; |
Test case
2 generated files · +2 −2test/inputs/schema/id-no-address.schema
Mschema-flowdefault / TopLevel.js+1 −1
| @@ -11,7 +11,7 @@ | ||
| 11 | 11 | |
| 12 | 12 | export type TopLevel = { |
| 13 | 13 | item: number; |
| 14 | - [property: string]: mixed | number; | |
| 14 | + [property: string]: mixed; | |
| 15 | 15 | }; |
| 16 | 16 | |
| 17 | 17 | // Converts JSON strings to/from your types |
Mschema-typescriptdefault / TopLevel.ts+1 −1
| @@ -9,7 +9,7 @@ | ||
| 9 | 9 | |
| 10 | 10 | export interface TopLevel { |
| 11 | 11 | item: number; |
| 12 | - [property: string]: unknown | number; | |
| 12 | + [property: string]: unknown; | |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | // Converts JSON strings to/from your types |
Test case
2 generated files · +2 −2test/inputs/schema/id-root.schema
Mschema-flowdefault / TopLevel.js+1 −1
| @@ -11,7 +11,7 @@ | ||
| 11 | 11 | |
| 12 | 12 | export type TopLevel = { |
| 13 | 13 | bar: number; |
| 14 | - [property: string]: mixed | number; | |
| 14 | + [property: string]: mixed; | |
| 15 | 15 | }; |
| 16 | 16 | |
| 17 | 17 | // Converts JSON strings to/from your types |
Mschema-typescriptdefault / TopLevel.ts+1 −1
| @@ -9,7 +9,7 @@ | ||
| 9 | 9 | |
| 10 | 10 | export interface TopLevel { |
| 11 | 11 | bar: number; |
| 12 | - [property: string]: unknown | number; | |
| 12 | + [property: string]: unknown; | |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | // Converts JSON strings to/from your types |
Test case
2 generated files · +4 −4test/inputs/schema/ie-suffix-singularization.schema
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -11,13 +11,13 @@ | ||
| 11 | 11 | |
| 12 | 12 | export type TopLevel = { |
| 13 | 13 | cookies: Cookie[]; |
| 14 | - [property: string]: mixed | Cookie[]; | |
| 14 | + [property: string]: mixed; | |
| 15 | 15 | }; |
| 16 | 16 | |
| 17 | 17 | export type Cookie = { |
| 18 | 18 | name: string; |
| 19 | 19 | value: string; |
| 20 | - [property: string]: mixed | string | string; | |
| 20 | + [property: string]: mixed; | |
| 21 | 21 | }; |
| 22 | 22 | |
| 23 | 23 | // Converts JSON strings to/from your types |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -9,13 +9,13 @@ | ||
| 9 | 9 | |
| 10 | 10 | export interface TopLevel { |
| 11 | 11 | cookies: Cookie[]; |
| 12 | - [property: string]: unknown | Cookie[]; | |
| 12 | + [property: string]: unknown; | |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | export interface Cookie { |
| 16 | 16 | name: string; |
| 17 | 17 | value: string; |
| 18 | - [property: string]: unknown | string | string; | |
| 18 | + [property: string]: unknown; | |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | // Converts JSON strings to/from your types |
Test case
2 generated files · +2 −2test/inputs/schema/implicit-all-of.schema
Mschema-flowdefault / TopLevel.js+1 −1
| @@ -13,7 +13,7 @@ export type TopLevel = { | ||
| 13 | 13 | foo: number; |
| 14 | 14 | bar: boolean; |
| 15 | 15 | quux: string; |
| 16 | - [property: string]: mixed | number | boolean | string; | |
| 16 | + [property: string]: mixed; | |
| 17 | 17 | }; |
| 18 | 18 | |
| 19 | 19 | // Converts JSON strings to/from your types |
Mschema-typescriptdefault / TopLevel.ts+1 −1
| @@ -11,7 +11,7 @@ export interface TopLevel { | ||
| 11 | 11 | foo: number; |
| 12 | 12 | bar: boolean; |
| 13 | 13 | quux: string; |
| 14 | - [property: string]: unknown | number | boolean | string; | |
| 14 | + [property: string]: unknown; | |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | // Converts JSON strings to/from your types |
Test case
2 generated files · +4 −4test/inputs/schema/implicit-class-array-union.schema
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -11,14 +11,14 @@ | ||
| 11 | 11 | |
| 12 | 12 | export type TopLevel = { |
| 13 | 13 | foo: FooUnion; |
| 14 | - [property: string]: mixed | FooUnion; | |
| 14 | + [property: string]: mixed; | |
| 15 | 15 | }; |
| 16 | 16 | |
| 17 | 17 | export type FooUnion = number[] | boolean | number | number | null | FooObject | string; |
| 18 | 18 | |
| 19 | 19 | export type FooObject = { |
| 20 | 20 | bar: number; |
| 21 | - [property: string]: mixed | number; | |
| 21 | + [property: string]: mixed; | |
| 22 | 22 | }; |
| 23 | 23 | |
| 24 | 24 | // Converts JSON strings to/from your types |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -9,14 +9,14 @@ | ||
| 9 | 9 | |
| 10 | 10 | export interface TopLevel { |
| 11 | 11 | foo: FooUnion; |
| 12 | - [property: string]: unknown | FooUnion; | |
| 12 | + [property: string]: unknown; | |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | export type FooUnion = number[] | boolean | number | number | null | FooObject | string; |
| 16 | 16 | |
| 17 | 17 | export interface FooObject { |
| 18 | 18 | bar: number; |
| 19 | - [property: string]: unknown | number; | |
| 19 | + [property: string]: unknown; | |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | // Converts JSON strings to/from your types |
Test case
2 generated files · +2 −2test/inputs/schema/implicit-one-of.schema
Mschema-flowdefault / TopLevel.js+1 −1
| @@ -13,7 +13,7 @@ export type TopLevel = { | ||
| 13 | 13 | foo: number; |
| 14 | 14 | bar?: boolean; |
| 15 | 15 | quux?: string; |
| 16 | - [property: string]: mixed | number | boolean | string; | |
| 16 | + [property: string]: mixed; | |
| 17 | 17 | }; |
| 18 | 18 | |
| 19 | 19 | // Converts JSON strings to/from your types |
Mschema-typescriptdefault / TopLevel.ts+1 −1
| @@ -11,7 +11,7 @@ export interface TopLevel { | ||
| 11 | 11 | foo: number; |
| 12 | 12 | bar?: boolean; |
| 13 | 13 | quux?: string; |
| 14 | - [property: string]: unknown | number | boolean | string; | |
| 14 | + [property: string]: unknown; | |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | // Converts JSON strings to/from your types |
Test case
2 generated files · +2 −2test/inputs/schema/integer-float-union.schema
Mschema-flowdefault / TopLevel.js+1 −1
| @@ -11,7 +11,7 @@ | ||
| 11 | 11 | |
| 12 | 12 | export type TopLevel = { |
| 13 | 13 | number: number; |
| 14 | - [property: string]: mixed | number; | |
| 14 | + [property: string]: mixed; | |
| 15 | 15 | }; |
| 16 | 16 | |
| 17 | 17 | // Converts JSON strings to/from your types |
Mschema-typescriptdefault / TopLevel.ts+1 −1
| @@ -9,7 +9,7 @@ | ||
| 9 | 9 | |
| 10 | 10 | export interface TopLevel { |
| 11 | 11 | number: number; |
| 12 | - [property: string]: unknown | number; | |
| 12 | + [property: string]: unknown; | |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | // Converts JSON strings to/from your types |
Test case
2 generated files · +2 −2test/inputs/schema/integer-string.schema
Mschema-flowdefault / TopLevel.js+1 −1
| @@ -17,7 +17,7 @@ export type TopLevel = { | ||
| 17 | 17 | optional?: string; |
| 18 | 18 | unionWithInt: UnionWithInt; |
| 19 | 19 | unionWithIntAndEnum: UnionWithInt; |
| 20 | - [property: string]: mixed | (null | string)[] | string[] | null | string | string | string | UnionWithInt | UnionWithInt; | |
| 20 | + [property: string]: mixed; | |
| 21 | 21 | }; |
| 22 | 22 | |
| 23 | 23 | export type UnionWithInt = number | string; |
Mschema-typescriptdefault / TopLevel.ts+1 −1
| @@ -15,7 +15,7 @@ export interface TopLevel { | ||
| 15 | 15 | optional?: string; |
| 16 | 16 | unionWithInt: UnionWithInt; |
| 17 | 17 | unionWithIntAndEnum: UnionWithInt; |
| 18 | - [property: string]: unknown | (null | string)[] | string[] | null | string | string | string | UnionWithInt | UnionWithInt; | |
| 18 | + [property: string]: unknown; | |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | export type UnionWithInt = number | string; |
Test case
2 generated files · +2 −2test/inputs/schema/integer-type.schema
Mschema-flowdefault / TopLevel.js+1 −1
| @@ -19,7 +19,7 @@ export type TopLevel = { | ||
| 19 | 19 | small_negative: number; |
| 20 | 20 | small_positive: number; |
| 21 | 21 | unbounded: number; |
| 22 | - [property: string]: mixed | number | number | number | number | number | number | number | number | number; | |
| 22 | + [property: string]: mixed; | |
| 23 | 23 | }; |
| 24 | 24 | |
| 25 | 25 | // Converts JSON strings to/from your types |
Mschema-typescriptdefault / TopLevel.ts+1 −1
| @@ -17,7 +17,7 @@ export interface TopLevel { | ||
| 17 | 17 | small_negative: number; |
| 18 | 18 | small_positive: number; |
| 19 | 19 | unbounded: number; |
| 20 | - [property: string]: unknown | number | number | number | number | number | number | number | number | number; | |
| 20 | + [property: string]: unknown; | |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | // Converts JSON strings to/from your types |
Test case
2 generated files · +2 −2test/inputs/schema/intersection.schema
Mschema-flowdefault / TopLevel.js+1 −1
| @@ -16,7 +16,7 @@ export type TopLevel = { | ||
| 16 | 16 | export type Intersection = { |
| 17 | 17 | foo: number; |
| 18 | 18 | bar?: string; |
| 19 | - [property: string]: mixed | number | string; | |
| 19 | + [property: string]: mixed; | |
| 20 | 20 | }; |
| 21 | 21 | |
| 22 | 22 | // Converts JSON strings to/from your types |
Mschema-typescriptdefault / TopLevel.ts+1 −1
| @@ -14,7 +14,7 @@ export interface TopLevel { | ||
| 14 | 14 | export interface Intersection { |
| 15 | 15 | foo: number; |
| 16 | 16 | bar?: string; |
| 17 | - [property: string]: unknown | number | string; | |
| 17 | + [property: string]: unknown; | |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | // Converts JSON strings to/from your types |
Test case
2 generated files · +2 −2test/inputs/schema/keyword-enum.schema
Mschema-flowdefault / TopLevel.js+1 −1
| @@ -11,7 +11,7 @@ | ||
| 11 | 11 | |
| 12 | 12 | export type TopLevel = { |
| 13 | 13 | enum?: Enum; |
| 14 | - [property: string]: mixed | Enum; | |
| 14 | + [property: string]: mixed; | |
| 15 | 15 | }; |
| 16 | 16 | |
| 17 | 17 | export type Enum = |
Mschema-typescriptdefault / TopLevel.ts+1 −1
| @@ -9,7 +9,7 @@ | ||
| 9 | 9 | |
| 10 | 10 | export interface TopLevel { |
| 11 | 11 | enum?: Enum; |
| 12 | - [property: string]: unknown | Enum; | |
| 12 | + [property: string]: unknown; | |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | export type Enum = "_" | "_Bool" | "_Complex" | "_Imaginery" | "abstract" | "alignas" | "alignof" | "and" | "and_eq" | "any" | "Any" | "array" | "as" | "asm" | "assert" | "associatedtype" | "associativity" | "async" | "atomic" | "atomic_cancel" | "atomic_commit" | "atomic_noexcept" | "auto" | "await" | "base" | "bitand" | "bitor" | "BOOL" | "bool" | "boolean" | "break" | "bycopy" | "byref" | "byte" | "case" | "catch" | "chan" | "char" | "char16_t" | "char32_t" | "checked" | "class" | "Class" | "co_await" | "co_return" | "co_yield" | "compl" | "concept" | "console" | "const" | "const_cast" | "constexpr" | "constructor" | "continue" | "convenience" | "convert" | "converter" | "date" | "date_parse_handling" | "debugger" | "decimal" | "declare" | "decltype" | "decode_string" | "def" | "default" | "defer" | "deinit" | "del" | "delegate" | "delete" | "dict" | "dictionary" | "didSet" | "do" | "double" | "dynamic" | "dynamic_cast" | "elif" | "else" | "encode_quick_type" | "enum" | "event" | "except" | "exception" | "explicit" | "export" | "exposing" | "extends" | "extension" | "extern" | "fallthrough" | "false" | "False" | "fileprivate" | "final" | "finally" | "fixed" | "float" | "for" | "foreach" | "friend" | "from" | "from_json" | "func" | "function" | "get" | "global" | "go" | "goto" | "guard" | "hasOwnProperty" | "id" | "if" | "IMP" | "implements" | "implicit" | "import" | "in" | "indirect" | "infix" | "init" | "inline" | "inout" | "instanceof" | "int" | "interface" | "internal" | "iterable" | "is" | "jdec" | "jenc" | "jpipe" | "json" | "json_converter" | "json_serializer" | "json_token" | "json_writer" | "lambda" | "lazy" | "left" | "let" | "list" | "lock" | "long" | "map" | "metadata_property_handling" | "module" | "mutable" | "mutating" | "namespace" | "native" | "new" | "newtonsoft" | "nil" | "NO" | "noexcept" | "nonatomic" | "none" | "None" | "nonlocal" | "nonmutating" | "not" | "not_eq" | "NSString" | "NULL" | "null" | "nullptr" | "number" | "object" | "of" | "oneway" | "open" | "operator" | "optional" | "or" | "or_eq" | "out" | "override" | "package" | "params" | "pass" | "port" | "postfix" | "precedence" | "prefix" | "print" | "printf" | "private" | "protected" | "Protocol" | "protocol" | "public" | "quicktype" | "raise" | "range" | "readonly" | "ref" | "register" | "reinterpret_cast" | "repeat" | "require" | "required" | "requires" | "restrict" | "retain" | "rethrows" | "return" | "right" | "sbyte" | "sealed" | "SEL" | "select" | "Self" | "self" | "serialize" | "set" | "short" | "signed" | "sizeof" | "stackalloc" | "static" | "static_assert" | "static_cast" | "strictfp" | "string" | "struct" | "subscript" | "super" | "switch" | "symbol" | "synchronized" | "system" | "template" | "then" | "this" | "thread_local" | "throw" | "throws" | "to_json" | "top_level" | "transient" | "True" | "true" | "try" | "Type" | "type" | "typealias" | "typedef" | "typeid" | "typename" | "typeof" | "uint" | "ulong" | "unchecked" | "undefined" | "union" | "unowned" | "unsafe" | "unsigned" | "ushort" | "using" | "var" | "virtual" | "void" | "volatile" | "wchar_t" | "weak" | "where" | "while" | "willSet" | "with" | "xor" | "xor_eq" | "YES" | "yield" | "dummy"; |
Test case
2 generated files · +2 −2test/inputs/schema/keyword-unions.schema
Mschema-flowdefault / TopLevel.js+1 −1
| @@ -287,7 +287,7 @@ export type TopLevel = { | ||
| 287 | 287 | xor_eq?: UnionXorEq; |
| 288 | 288 | YES?: UnionYES; |
| 289 | 289 | yield?: UnionYield; |
| 290 | - [property: string]: mixed | UnionUnion | UnionBool | UnionComplex | UnionImaginery | UnionAbstract | UnionAlignas | UnionAlignof | UnionAnd | UnionAndEq | UnionAnyUnion | UnionAny | UnionArray | UnionAs | UnionASM | UnionAssert | UnionAssociatedtype | UnionAssociativity | UnionAsync | UnionAtomic | UnionAtomicCancel | UnionAtomicCommit | UnionAtomicNoexcept | UnionAuto | UnionAwait | UnionBase | UnionBitand | UnionBitor | UnionBOOL | UnionBoolUnion | UnionBoolean | UnionBreak | UnionBycopy | UnionByref | UnionByte | UnionCase | UnionCatch | UnionChan | UnionChar | UnionChar16T | UnionChar32T | UnionChecked | UnionClassUnion | UnionClass | UnionCoAwait | UnionCoReturn | UnionCoYield | UnionCompl | UnionConcept | UnionConsole | UnionConst | UnionConstCast | UnionConstexpr | UnionConstructor | UnionContinue | UnionConvenience | UnionConvert | UnionConverter | UnionDate | UnionDateParseHandling | UnionDebugger | UnionDecimal | UnionDeclare | UnionDecltype | UnionDecodeString | UnionDef | UnionDefault | UnionDefer | UnionDeinit | UnionDel | UnionDelegate | UnionDelete | UnionDict | UnionDictionary | UnionDidSet | UnionDo | UnionDouble | number | UnionDynamic | UnionDynamicCast | UnionElif | UnionElse | UnionEncodeQuickType | UnionEnum | UnionEvent | UnionExcept | UnionException | UnionExplicit | UnionExport | UnionExposing | UnionExtends | UnionExtension | UnionExtern | UnionFallthrough | UnionFalseUnion | UnionFalse | UnionFileprivate | UnionFinal | UnionFinally | UnionFixed | UnionFloat | UnionFor | UnionForeach | UnionFriend | UnionFrom | UnionFromJSON | UnionFunc | UnionFunction | UnionGet | UnionGlobal | UnionGo | UnionGoto | UnionGuard | UnionHasOwnProperty | UnionID | UnionIf | UnionIMP | UnionImplements | UnionImplicit | UnionImport | UnionIn | UnionIndirect | UnionInfix | UnionInit | UnionInline | UnionInout | UnionInstanceof | UnionInt | UnionInterface | UnionInternal | UnionIs | UnionIterable | UnionJdec | UnionJenc | UnionJpipe | UnionJSON | UnionJSONConverter | UnionJSONSerializer | UnionJSONToken | UnionJSONWriter | UnionLambda | UnionLazy | UnionLeft | UnionLet | UnionList | UnionLock | UnionLong | UnionMap | UnionMetadataPropertyHandling | UnionModule | UnionMutable | UnionMutating | UnionNamespace | UnionNative | UnionNew | UnionNewtonsoft | UnionNil | UnionNO | UnionNoexcept | UnionNonatomic | UnionNoneUnion | UnionNone | UnionNonlocal | UnionNonmutating | UnionNot | UnionNotEq | UnionNSString | UnionNULL | UnionNull | UnionNullptr | UnionNumber | UnionObject | UnionOf | UnionOneway | UnionOpen | UnionOperator | UnionOptional | UnionOr | UnionOrEq | UnionOut | UnionOverride | UnionPackage | UnionParams | UnionPass | UnionPort | UnionPostfix | UnionPrecedence | UnionPrefix | UnionPrint | UnionPrintf | UnionPrivate | UnionProtected | UnionProtocol | UnionProtocolUnion | UnionPublic | UnionQuicktype | UnionRaise | UnionRange | UnionReadonly | UnionRef | UnionRegister | UnionReinterpretCast | UnionRepeat | UnionRequire | UnionRequired | UnionRequires | UnionRestrict | UnionRetain | UnionRethrows | UnionReturn | UnionRight | UnionSbyte | UnionSealed | UnionSEL | UnionSelect | UnionSelf | UnionSelfUnion | UnionSerialize | UnionSet | UnionShort | UnionSigned | UnionSizeof | UnionStackalloc | UnionStatic | UnionStaticAssert | UnionStaticCast | UnionStrictfp | UnionString | UnionStruct | UnionSubscript | UnionSuper | UnionSwitch | UnionSymbol | UnionSynchronized | UnionSystem | UnionTemplate | UnionThen | UnionThis | UnionThreadLocal | UnionThrow | UnionThrows | UnionToJSON | UnionTopLevel | UnionTransient | UnionTrue | UnionTrueUnion | UnionTry | UnionType | UnionTypeUnion | UnionTypealias | UnionTypedef | UnionTypeid | UnionTypename | UnionTypeof | UnionUint | UnionUlong | UnionUnchecked | UnionUndefined | UnionUnionUnion | UnionUnowned | UnionUnsafe | UnionUnsigned | UnionUshort | UnionUsing | UnionVar | UnionVirtual | UnionVoid | UnionVolatile | UnionWcharT | UnionWeak | UnionWhere | UnionWhile | UnionWillSet | UnionWith | UnionXor | UnionXorEq | UnionYES | UnionYield; | |
| 290 | + [property: string]: mixed; | |
| 291 | 291 | }; |
| 292 | 292 | |
| 293 | 293 | export type UnionAny = Any | number; |
Mschema-typescriptdefault / TopLevel.ts+1 −1
| @@ -285,7 +285,7 @@ export interface TopLevel { | ||
| 285 | 285 | xor_eq?: UnionXorEq; |
| 286 | 286 | YES?: UnionYES; |
| 287 | 287 | yield?: UnionYield; |
| 288 | - [property: string]: unknown | UnionUnion | UnionBool | UnionComplex | UnionImaginery | UnionAbstract | UnionAlignas | UnionAlignof | UnionAnd | UnionAndEq | UnionAnyUnion | UnionAny | UnionArray | UnionAs | UnionASM | UnionAssert | UnionAssociatedtype | UnionAssociativity | UnionAsync | UnionAtomic | UnionAtomicCancel | UnionAtomicCommit | UnionAtomicNoexcept | UnionAuto | UnionAwait | UnionBase | UnionBitand | UnionBitor | UnionBOOL | UnionBoolUnion | UnionBoolean | UnionBreak | UnionBycopy | UnionByref | UnionByte | UnionCase | UnionCatch | UnionChan | UnionChar | UnionChar16T | UnionChar32T | UnionChecked | UnionClassUnion | UnionClass | UnionCoAwait | UnionCoReturn | UnionCoYield | UnionCompl | UnionConcept | UnionConsole | UnionConst | UnionConstCast | UnionConstexpr | UnionConstructor | UnionContinue | UnionConvenience | UnionConvert | UnionConverter | UnionDate | UnionDateParseHandling | UnionDebugger | UnionDecimal | UnionDeclare | UnionDecltype | UnionDecodeString | UnionDef | UnionDefault | UnionDefer | UnionDeinit | UnionDel | UnionDelegate | UnionDelete | UnionDict | UnionDictionary | UnionDidSet | UnionDo | UnionDouble | number | UnionDynamic | UnionDynamicCast | UnionElif | UnionElse | UnionEncodeQuickType | UnionEnum | UnionEvent | UnionExcept | UnionException | UnionExplicit | UnionExport | UnionExposing | UnionExtends | UnionExtension | UnionExtern | UnionFallthrough | UnionFalseUnion | UnionFalse | UnionFileprivate | UnionFinal | UnionFinally | UnionFixed | UnionFloat | UnionFor | UnionForeach | UnionFriend | UnionFrom | UnionFromJSON | UnionFunc | UnionFunction | UnionGet | UnionGlobal | UnionGo | UnionGoto | UnionGuard | UnionHasOwnProperty | UnionID | UnionIf | UnionIMP | UnionImplements | UnionImplicit | UnionImport | UnionIn | UnionIndirect | UnionInfix | UnionInit | UnionInline | UnionInout | UnionInstanceof | UnionInt | UnionInterface | UnionInternal | UnionIs | UnionIterable | UnionJdec | UnionJenc | UnionJpipe | UnionJSON | UnionJSONConverter | UnionJSONSerializer | UnionJSONToken | UnionJSONWriter | UnionLambda | UnionLazy | UnionLeft | UnionLet | UnionList | UnionLock | UnionLong | UnionMap | UnionMetadataPropertyHandling | UnionModule | UnionMutable | UnionMutating | UnionNamespace | UnionNative | UnionNew | UnionNewtonsoft | UnionNil | UnionNO | UnionNoexcept | UnionNonatomic | UnionNoneUnion | UnionNone | UnionNonlocal | UnionNonmutating | UnionNot | UnionNotEq | UnionNSString | UnionNULL | UnionNull | UnionNullptr | UnionNumber | UnionObject | UnionOf | UnionOneway | UnionOpen | UnionOperator | UnionOptional | UnionOr | UnionOrEq | UnionOut | UnionOverride | UnionPackage | UnionParams | UnionPass | UnionPort | UnionPostfix | UnionPrecedence | UnionPrefix | UnionPrint | UnionPrintf | UnionPrivate | UnionProtected | UnionProtocol | UnionProtocolUnion | UnionPublic | UnionQuicktype | UnionRaise | UnionRange | UnionReadonly | UnionRef | UnionRegister | UnionReinterpretCast | UnionRepeat | UnionRequire | UnionRequired | UnionRequires | UnionRestrict | UnionRetain | UnionRethrows | UnionReturn | UnionRight | UnionSbyte | UnionSealed | UnionSEL | UnionSelect | UnionSelf | UnionSelfUnion | UnionSerialize | UnionSet | UnionShort | UnionSigned | UnionSizeof | UnionStackalloc | UnionStatic | UnionStaticAssert | UnionStaticCast | UnionStrictfp | UnionString | UnionStruct | UnionSubscript | UnionSuper | UnionSwitch | UnionSymbol | UnionSynchronized | UnionSystem | UnionTemplate | UnionThen | UnionThis | UnionThreadLocal | UnionThrow | UnionThrows | UnionToJSON | UnionTopLevel | UnionTransient | UnionTrue | UnionTrueUnion | UnionTry | UnionType | UnionTypeUnion | UnionTypealias | UnionTypedef | UnionTypeid | UnionTypename | UnionTypeof | UnionUint | UnionUlong | UnionUnchecked | UnionUndefined | UnionUnionUnion | UnionUnowned | UnionUnsafe | UnionUnsigned | UnionUshort | UnionUsing | UnionVar | UnionVirtual | UnionVoid | UnionVolatile | UnionWcharT | UnionWeak | UnionWhere | UnionWhile | UnionWillSet | UnionWith | UnionXor | UnionXorEq | UnionYES | UnionYield; | |
| 288 | + [property: string]: unknown; | |
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | export type UnionAny = object | number; |
Test case
2 generated files · +2 −2test/inputs/schema/list.schema
Mschema-flowdefault / TopLevel.js+1 −1
| @@ -14,7 +14,7 @@ | ||
| 14 | 14 | */ |
| 15 | 15 | export type TopLevel = { |
| 16 | 16 | next?: TopLevel; |
| 17 | - [property: string]: mixed | TopLevel; | |
| 17 | + [property: string]: mixed; | |
| 18 | 18 | }; |
| 19 | 19 | |
| 20 | 20 | // Converts JSON strings to/from your types |
Mschema-typescriptdefault / TopLevel.ts+1 −1
| @@ -12,7 +12,7 @@ | ||
| 12 | 12 | */ |
| 13 | 13 | export interface TopLevel { |
| 14 | 14 | next?: TopLevel; |
| 15 | - [property: string]: unknown | TopLevel; | |
| 15 | + [property: string]: unknown; | |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | // Converts JSON strings to/from your types |
Test case
2 generated files · +2 −2test/inputs/schema/min-max-items.schema
Mschema-flowdefault / TopLevel.js+1 −1
| @@ -15,7 +15,7 @@ export type TopLevel = { | ||
| 15 | 15 | minOnly: string[]; |
| 16 | 16 | plain: string[]; |
| 17 | 17 | unionItems: UnionItem[]; |
| 18 | - [property: string]: mixed | number[] | number[] | string[] | string[] | UnionItem[]; | |
| 18 | + [property: string]: mixed; | |
| 19 | 19 | }; |
| 20 | 20 | |
| 21 | 21 | export type UnionItem = number | string; |
Mschema-typescriptdefault / TopLevel.ts+1 −1
| @@ -13,7 +13,7 @@ export interface TopLevel { | ||
| 13 | 13 | minOnly: [string, string, ...string[]]; |
| 14 | 14 | plain: string[]; |
| 15 | 15 | unionItems: [UnionItem, UnionItem, ...UnionItem[]]; |
| 16 | - [property: string]: unknown | number[] | [number, ...number[]] | [string, string, ...string[]] | string[] | [UnionItem, UnionItem, ...UnionItem[]]; | |
| 16 | + [property: string]: unknown; | |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | export type UnionItem = number | string; |
Test case
2 generated files · +2 −2test/inputs/schema/minmax-integer.schema
Mschema-flowdefault / TopLevel.js+1 −1
| @@ -18,7 +18,7 @@ export type TopLevel = { | ||
| 18 | 18 | minMaxIntersection: number; |
| 19 | 19 | minMaxUnion: number; |
| 20 | 20 | union: number; |
| 21 | - [property: string]: mixed | number | number | number | number | number | number | number | number; | |
| 21 | + [property: string]: mixed; | |
| 22 | 22 | }; |
| 23 | 23 | |
| 24 | 24 | // Converts JSON strings to/from your types |
Mschema-typescriptdefault / TopLevel.ts+1 −1
| @@ -16,7 +16,7 @@ export interface TopLevel { | ||
| 16 | 16 | minMaxIntersection: number; |
| 17 | 17 | minMaxUnion: number; |
| 18 | 18 | union: number; |
| 19 | - [property: string]: unknown | number | number | number | number | number | number | number | number; | |
| 19 | + [property: string]: unknown; | |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | // Converts JSON strings to/from your types |
Test case
2 generated files · +2 −2test/inputs/schema/minmax.schema
Mschema-flowdefault / TopLevel.js+1 −1
| @@ -18,7 +18,7 @@ export type TopLevel = { | ||
| 18 | 18 | minMaxIntersection: number; |
| 19 | 19 | minMaxUnion: number; |
| 20 | 20 | union: number; |
| 21 | - [property: string]: mixed | number | number | number | number | number | number | number | number; | |
| 21 | + [property: string]: mixed; | |
| 22 | 22 | }; |
| 23 | 23 | |
| 24 | 24 | // Converts JSON strings to/from your types |
Mschema-typescriptdefault / TopLevel.ts+1 −1
| @@ -16,7 +16,7 @@ export interface TopLevel { | ||
| 16 | 16 | minMaxIntersection: number; |
| 17 | 17 | minMaxUnion: number; |
| 18 | 18 | union: number; |
| 19 | - [property: string]: unknown | number | number | number | number | number | number | number | number; | |
| 19 | + [property: string]: unknown; | |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | // Converts JSON strings to/from your types |
Test case
2 generated files · +2 −2test/inputs/schema/minmaxlength.schema
Mschema-flowdefault / TopLevel.js+1 −1
| @@ -18,7 +18,7 @@ export type TopLevel = { | ||
| 18 | 18 | minmaxlength: string; |
| 19 | 19 | minMaxUnion: string; |
| 20 | 20 | union: string; |
| 21 | - [property: string]: mixed | string | InUnion | string | string | string | string | string | string; | |
| 21 | + [property: string]: mixed; | |
| 22 | 22 | }; |
| 23 | 23 | |
| 24 | 24 | export type InUnion = number | string; |
Mschema-typescriptdefault / TopLevel.ts+1 −1
| @@ -16,7 +16,7 @@ export interface TopLevel { | ||
| 16 | 16 | minmaxlength: string; |
| 17 | 17 | minMaxUnion: string; |
| 18 | 18 | union: string; |
| 19 | - [property: string]: unknown | string | InUnion | string | string | string | string | string | string; | |
| 19 | + [property: string]: unknown; | |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | export type InUnion = number | string; |
Test case
36 generated files · +2,677 −0test/inputs/schema/mixed-additional-properties.schema
Aschema-cjsondefault / TopLevel.c+131 −0
| @@ -0,0 +1,131 @@ | ||
| 1 | +/** | |
| 2 | + * TopLevel.c | |
| 3 | + * This file has been autogenerated using quicktype https://github.com/quicktype/quicktype - DO NOT EDIT | |
| 4 | + */ | |
| 5 | + | |
| 6 | +#include "TopLevel.h" | |
| 7 | + | |
| 8 | +struct TopLevelValue * cJSON_GetTopLevelValueValue(const cJSON * j) { | |
| 9 | + struct TopLevelValue * x = cJSON_malloc(sizeof(struct TopLevelValue)); | |
| 10 | + if (NULL != x) { | |
| 11 | + memset(x, 0, sizeof(struct TopLevelValue)); | |
| 12 | + if (cJSON_IsString(j)) { | |
| 13 | + x->type = cJSON_String; | |
| 14 | + x->value.string = strdup(cJSON_GetStringValue(j)); | |
| 15 | + } | |
| 16 | + else if (cJSON_IsNumber(j)) { | |
| 17 | + x->type = cJSON_Number; | |
| 18 | + x->value.number = cJSON_GetNumberValue(j); | |
| 19 | + } | |
| 20 | + if (0 == x->type) { cJSON_free(x); return NULL; } | |
| 21 | + } | |
| 22 | + return x; | |
| 23 | +} | |
| 24 | +struct TopLevelValue * cJSON_ParseTopLevelValue(const char * s) { cJSON * j = cJSON_Parse(s); struct TopLevelValue * x = j ? cJSON_GetTopLevelValueValue(j) : NULL; cJSON_Delete(j); return x; } | |
| 25 | +char * cJSON_PrintTopLevelValue(const struct TopLevelValue * x) { cJSON * j = cJSON_CreateTopLevelValue(x); char * s = j ? cJSON_Print(j) : NULL; cJSON_Delete(j); return s; } | |
| 26 | + | |
| 27 | +cJSON * cJSON_CreateTopLevelValue(const struct TopLevelValue * x) { | |
| 28 | + cJSON * j = NULL; | |
| 29 | + if (NULL != x) { | |
| 30 | + if (cJSON_String == x->type) { | |
| 31 | + j = cJSON_CreateString(x->value.string); | |
| 32 | + } | |
| 33 | + else if (cJSON_Number == x->type) { | |
| 34 | + j = cJSON_CreateNumber(x->value.number); | |
| 35 | + } | |
| 36 | + } | |
| 37 | + return j; | |
| 38 | +} | |
| 39 | + | |
| 40 | +void cJSON_DeleteTopLevelValue(struct TopLevelValue * x) { | |
| 41 | + if (NULL != x) { | |
| 42 | + if (cJSON_String == x->type) { | |
| 43 | + cJSON_free(x->value.string); | |
| 44 | + } | |
| 45 | + else if (cJSON_Number == x->type) { | |
| 46 | + } | |
| 47 | + cJSON_free(x); | |
| 48 | + } | |
| 49 | +} | |
| 50 | + | |
| 51 | +struct TopLevel * cJSON_ParseTopLevel(const char * s) { | |
| 52 | + struct TopLevel * x = NULL; | |
| 53 | + if (NULL != s) { | |
| 54 | + cJSON * j = cJSON_Parse(s); | |
| 55 | + if (NULL != j) { | |
| 56 | + x = cJSON_GetTopLevelValue(j); | |
| 57 | + cJSON_Delete(j); | |
| 58 | + } | |
| 59 | + } | |
| 60 | + return x; | |
| 61 | +} | |
| 62 | + | |
| 63 | +struct TopLevel * cJSON_GetTopLevelValue(const cJSON * j) { | |
| 64 | + struct TopLevel * x = NULL; | |
| 65 | + if (NULL != j) { | |
| 66 | + if (NULL != (x = cJSON_malloc(sizeof(struct TopLevel)))) { | |
| 67 | + memset(x, 0, sizeof(struct TopLevel)); | |
| 68 | + x->value = hashtable_create(64, false); | |
| 69 | + if (NULL != x->value) { | |
| 70 | + cJSON * e = NULL; | |
| 71 | + cJSON_ArrayForEach(e, j) { | |
| 72 | + hashtable_add(x->value, e->string, cJSON_GetTopLevelValueValue(e), sizeof(struct TopLevelValue *)); | |
| 73 | + } | |
| 74 | + } | |
| 75 | + } | |
| 76 | + } | |
| 77 | + return x; | |
| 78 | +} | |
| 79 | + | |
| 80 | +cJSON * cJSON_CreateTopLevel(const struct TopLevel * x) { | |
| 81 | + cJSON * j = NULL; | |
| 82 | + if (NULL != x) { | |
| 83 | + if (NULL != x->value) { | |
| 84 | + j = cJSON_CreateObject(); | |
| 85 | + if (NULL != j) { | |
| 86 | + char **keys = NULL; | |
| 87 | + size_t count = hashtable_get_keys(x->value, &keys); | |
| 88 | + if (NULL != keys) { | |
| 89 | + for (size_t index = 0; index < count; index++) { | |
| 90 | + struct TopLevelValue *x2 = hashtable_lookup(x->value, keys[index]); | |
| 91 | + cJSON_AddItemToObject(j, keys[index], cJSON_CreateTopLevelValue(x2)); | |
| 92 | + } | |
| 93 | + cJSON_free(keys); | |
| 94 | + } | |
| 95 | + } | |
| 96 | + } | |
| 97 | + } | |
| 98 | + return j; | |
| 99 | +} | |
| 100 | + | |
| 101 | +char * cJSON_PrintTopLevel(const struct TopLevel * x) { | |
| 102 | + char * s = NULL; | |
| 103 | + if (NULL != x) { | |
| 104 | + cJSON * j = cJSON_CreateTopLevel(x); | |
| 105 | + if (NULL != j) { | |
| 106 | + s = cJSON_Print(j); | |
| 107 | + cJSON_Delete(j); | |
| 108 | + } | |
| 109 | + } | |
| 110 | + return s; | |
| 111 | +} | |
| 112 | + | |
| 113 | +void cJSON_DeleteTopLevel(struct TopLevel * x) { | |
| 114 | + if (NULL != x) { | |
| 115 | + if (NULL != x->value) { | |
| 116 | + char **keys = NULL; | |
| 117 | + size_t count = hashtable_get_keys(x->value, &keys); | |
| 118 | + if (NULL != keys) { | |
| 119 | + for (size_t index = 0; index < count; index++) { | |
| 120 | + struct TopLevelValue *x2 = hashtable_lookup(x->value, keys[index]); | |
| 121 | + if (NULL != x2) { | |
| 122 | + cJSON_DeleteTopLevelValue(x2); | |
| 123 | + } | |
| 124 | + } | |
| 125 | + cJSON_free(keys); | |
| 126 | + } | |
| 127 | + hashtable_release(x->value); | |
| 128 | + } | |
| 129 | + cJSON_free(x); | |
| 130 | + } | |
| 131 | +} |
Aschema-cjsondefault / TopLevel.h+70 −0
| @@ -0,0 +1,70 @@ | ||
| 1 | +/** | |
| 2 | + * TopLevel.h | |
| 3 | + * This file has been autogenerated using quicktype https://github.com/quicktype/quicktype - DO NOT EDIT | |
| 4 | + * This file depends of https://github.com/DaveGamble/cJSON, https://github.com/joelguittet/c-list and https://github.com/joelguittet/c-hashtable | |
| 5 | + * To parse json data from json string use the following: struct <type> * data = cJSON_Parse<type>(<string>); | |
| 6 | + * To get json data from cJSON object use the following: struct <type> * data = cJSON_Get<type>Value(<cjson>); | |
| 7 | + * To get cJSON object from json data use the following: cJSON * cjson = cJSON_Create<type>(<data>); | |
| 8 | + * To print json string from json data use the following: char * string = cJSON_Print<type>(<data>); | |
| 9 | + * To delete json data use the following: cJSON_Delete<type>(<data>); | |
| 10 | + */ | |
| 11 | + | |
| 12 | +#ifndef __TOPLEVEL_H__ | |
| 13 | +#define __TOPLEVEL_H__ | |
| 14 | + | |
| 15 | +#ifdef __cplusplus | |
| 16 | +extern "C" { | |
| 17 | +#endif | |
| 18 | + | |
| 19 | +#include <stdint.h> | |
| 20 | +#include <stdbool.h> | |
| 21 | +#include <stdlib.h> | |
| 22 | +#include <string.h> | |
| 23 | +#include <regex.h> | |
| 24 | +#include <cJSON.h> | |
| 25 | +#include <hashtable.h> | |
| 26 | +#include <list.h> | |
| 27 | + | |
| 28 | +#define quicktype_cJSON_Duplicate(j) cJSON_Duplicate(j, true) | |
| 29 | +#define cJSON_Integer (1 << 18) | |
| 30 | +#define quicktype_cJSON_IsInteger(j) (cJSON_IsNumber(j) && (j)->valuedouble == (int64_t)(j)->valuedouble) | |
| 31 | +#ifndef cJSON_Bool | |
| 32 | +#define cJSON_Bool (cJSON_True | cJSON_False) | |
| 33 | +#endif | |
| 34 | +#ifndef cJSON_Map | |
| 35 | +#define cJSON_Map (1 << 16) | |
| 36 | +#endif | |
| 37 | +#ifndef cJSON_Enum | |
| 38 | +#define cJSON_Enum (1 << 17) | |
| 39 | +#endif | |
| 40 | + | |
| 41 | +struct TopLevelValue { | |
| 42 | + int type; | |
| 43 | + union { | |
| 44 | + char * string; | |
| 45 | + double number; | |
| 46 | + } value; | |
| 47 | +}; | |
| 48 | + | |
| 49 | +struct TopLevel { | |
| 50 | + hashtable_t * value; | |
| 51 | +}; | |
| 52 | + | |
| 53 | +#define cJSON_IsTopLevelValue(j) (cJSON_IsString(j) || cJSON_IsNumber(j)) | |
| 54 | +struct TopLevelValue * cJSON_GetTopLevelValueValue(const cJSON * j); | |
| 55 | +cJSON * cJSON_CreateTopLevelValue(const struct TopLevelValue * x); | |
| 56 | +void cJSON_DeleteTopLevelValue(struct TopLevelValue * x); | |
| 57 | +struct TopLevelValue * cJSON_ParseTopLevelValue(const char * s); | |
| 58 | +char * cJSON_PrintTopLevelValue(const struct TopLevelValue * x); | |
| 59 | + | |
| 60 | +struct TopLevel * cJSON_ParseTopLevel(const char * s); | |
| 61 | +struct TopLevel * cJSON_GetTopLevelValue(const cJSON * j); | |
| 62 | +cJSON * cJSON_CreateTopLevel(const struct TopLevel * x); | |
| 63 | +char * cJSON_PrintTopLevel(const struct TopLevel * x); | |
| 64 | +void cJSON_DeleteTopLevel(struct TopLevel * x); | |
| 65 | + | |
| 66 | +#ifdef __cplusplus | |
| 67 | +} | |
| 68 | +#endif | |
| 69 | + | |
| 70 | +#endif /* __TOPLEVEL_H__ */ |
Aschema-cplusplusdefault / quicktype.hpp+122 −0
| @@ -0,0 +1,122 @@ | ||
| 1 | +// To parse this JSON data, first install | |
| 2 | +// | |
| 3 | +// json.hpp https://github.com/nlohmann/json | |
| 4 | +// | |
| 5 | +// Then include this file, and then do | |
| 6 | +// | |
| 7 | +// TopLevel data = nlohmann::json::parse(jsonString); | |
| 8 | + | |
| 9 | +#pragma once | |
| 10 | + | |
| 11 | +#include <variant> | |
| 12 | +#include "json.hpp" | |
| 13 | + | |
| 14 | +#include <optional> | |
| 15 | +#include <stdexcept> | |
| 16 | +#include <regex> | |
| 17 | + | |
| 18 | +#ifndef NLOHMANN_OPT_HELPER | |
| 19 | +#define NLOHMANN_OPT_HELPER | |
| 20 | +namespace nlohmann { | |
| 21 | + template <typename T> | |
| 22 | + struct adl_serializer<std::shared_ptr<T>> { | |
| 23 | + static void to_json(json & j, const std::shared_ptr<T> & opt) { | |
| 24 | + if (!opt) j = nullptr; else j = *opt; | |
| 25 | + } | |
| 26 | + | |
| 27 | + static std::shared_ptr<T> from_json(const json & j) { | |
| 28 | + if (j.is_null()) return std::shared_ptr<T>(); else return std::make_shared<T>(j.get<T>()); | |
| 29 | + } | |
| 30 | + }; | |
| 31 | + template <typename T> | |
| 32 | + struct adl_serializer<std::optional<T>> { | |
| 33 | + static void to_json(json & j, const std::optional<T> & opt) { | |
| 34 | + if (!opt) j = nullptr; else j = *opt; | |
| 35 | + } | |
| 36 | + | |
| 37 | + static std::optional<T> from_json(const json & j) { | |
| 38 | + if (j.is_null()) return std::optional<T>(); else return std::make_optional<T>(j.get<T>()); | |
| 39 | + } | |
| 40 | + }; | |
| 41 | +} | |
| 42 | +#endif | |
| 43 | + | |
| 44 | +namespace quicktype { | |
| 45 | + using nlohmann::json; | |
| 46 | + | |
| 47 | + #ifndef NLOHMANN_UNTYPED_quicktype_HELPER | |
| 48 | + #define NLOHMANN_UNTYPED_quicktype_HELPER | |
| 49 | + inline json get_untyped(const json & j, const char * property) { | |
| 50 | + if (j.find(property) != j.end()) { | |
| 51 | + return j.at(property).get<json>(); | |
| 52 | + } | |
| 53 | + return json(); | |
| 54 | + } | |
| 55 | + | |
| 56 | + inline json get_untyped(const json & j, std::string property) { | |
| 57 | + return get_untyped(j, property.data()); | |
| 58 | + } | |
| 59 | + #endif | |
| 60 | + | |
| 61 | + #ifndef NLOHMANN_OPTIONAL_quicktype_HELPER | |
| 62 | + #define NLOHMANN_OPTIONAL_quicktype_HELPER | |
| 63 | + template <typename T> | |
| 64 | + inline std::shared_ptr<T> get_heap_optional(const json & j, const char * property) { | |
| 65 | + auto it = j.find(property); | |
| 66 | + if (it != j.end() && !it->is_null()) { | |
| 67 | + return j.at(property).get<std::shared_ptr<T>>(); | |
| 68 | + } | |
| 69 | + return std::shared_ptr<T>(); | |
| 70 | + } | |
| 71 | + | |
| 72 | + template <typename T> | |
| 73 | + inline std::shared_ptr<T> get_heap_optional(const json & j, std::string property) { | |
| 74 | + return get_heap_optional<T>(j, property.data()); | |
| 75 | + } | |
| 76 | + template <typename T> | |
| 77 | + inline std::optional<T> get_stack_optional(const json & j, const char * property) { | |
| 78 | + auto it = j.find(property); | |
| 79 | + if (it != j.end() && !it->is_null()) { | |
| 80 | + return j.at(property).get<std::optional<T>>(); | |
| 81 | + } | |
| 82 | + return std::optional<T>(); | |
| 83 | + } | |
| 84 | + | |
| 85 | + template <typename T> | |
| 86 | + inline std::optional<T> get_stack_optional(const json & j, std::string property) { | |
| 87 | + return get_stack_optional<T>(j, property.data()); | |
| 88 | + } | |
| 89 | + #endif | |
| 90 | + | |
| 91 | + using TopLevelValue = std::variant<double, std::string>; | |
| 92 | + | |
| 93 | + using TopLevel = std::map<std::string, TopLevelValue>; | |
| 94 | +} | |
| 95 | + | |
| 96 | +namespace nlohmann { | |
| 97 | + template <> | |
| 98 | + struct adl_serializer<std::variant<double, std::string>> { | |
| 99 | + static void from_json(const json & j, std::variant<double, std::string> & x); | |
| 100 | + static void to_json(json & j, const std::variant<double, std::string> & x); | |
| 101 | + }; | |
| 102 | + | |
| 103 | + inline void adl_serializer<std::variant<double, std::string>>::from_json(const json & j, std::variant<double, std::string> & x) { | |
| 104 | + if (j.is_number()) | |
| 105 | + x = j.get<double>(); | |
| 106 | + else if (j.is_string()) | |
| 107 | + x = j.get<std::string>(); | |
| 108 | + else throw std::runtime_error("Could not deserialise!"); | |
| 109 | + } | |
| 110 | + | |
| 111 | + inline void adl_serializer<std::variant<double, std::string>>::to_json(json & j, const std::variant<double, std::string> & x) { | |
| 112 | + switch (x.index()) { | |
| 113 | + case 0: | |
| 114 | + j = std::get<double>(x); | |
| 115 | + break; | |
| 116 | + case 1: | |
| 117 | + j = std::get<std::string>(x); | |
| 118 | + break; | |
| 119 | + default: throw std::runtime_error("Input JSON does not conform to schema!"); | |
| 120 | + } | |
| 121 | + } | |
| 122 | +} |
Aschema-crystaldefault / TopLevel.cr+5 −0
| @@ -0,0 +1,5 @@ | ||
| 1 | +require "json" | |
| 2 | + | |
| 3 | +alias TopLevel = Hash(String, TopLevelValue) | |
| 4 | + | |
| 5 | +alias TopLevelValue = Float64 | String |
Aschema-csharp-recordsdefault / QuickType.cs+104 −0
| @@ -0,0 +1,104 @@ | ||
| 1 | +// <auto-generated /> | |
| 2 | +// | |
| 3 | +// To parse this JSON data, add NuGet 'Newtonsoft.Json' then do: | |
| 4 | +// | |
| 5 | +// using QuickType; | |
| 6 | +// | |
| 7 | +// var topLevel = TopLevel.FromJson(jsonString); | |
| 8 | +#nullable enable | |
| 9 | +#pragma warning disable CS8618 | |
| 10 | +#pragma warning disable CS8601 | |
| 11 | +#pragma warning disable CS8602 | |
| 12 | +#pragma warning disable CS8603 | |
| 13 | +#pragma warning disable CS8604 | |
| 14 | +#pragma warning disable CS8625 | |
| 15 | +#pragma warning disable CS8765 | |
| 16 | + | |
| 17 | +namespace QuickType | |
| 18 | +{ | |
| 19 | + using System; | |
| 20 | + using System.Collections.Generic; | |
| 21 | + | |
| 22 | + using System.Globalization; | |
| 23 | + using Newtonsoft.Json; | |
| 24 | + using Newtonsoft.Json.Converters; | |
| 25 | + | |
| 26 | + public partial struct TopLevelValue | |
| 27 | + { | |
| 28 | + public double? Double; | |
| 29 | + public string? String; | |
| 30 | + | |
| 31 | + public static implicit operator TopLevelValue(double Double) => new TopLevelValue { Double = Double }; | |
| 32 | + public static implicit operator TopLevelValue(string String) => new TopLevelValue { String = String }; | |
| 33 | + } | |
| 34 | + | |
| 35 | + public class TopLevel | |
| 36 | + { | |
| 37 | + public static Dictionary<string, TopLevelValue> FromJson(string json) => JsonConvert.DeserializeObject<Dictionary<string, TopLevelValue>>(json, QuickType.Converter.Settings); | |
| 38 | + } | |
| 39 | + | |
| 40 | + public static partial class Serialize | |
| 41 | + { | |
| 42 | + public static string ToJson(this Dictionary<string, TopLevelValue> self) => JsonConvert.SerializeObject(self, QuickType.Converter.Settings); | |
| 43 | + } | |
| 44 | + | |
| 45 | + internal static partial class Converter | |
| 46 | + { | |
| 47 | + public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings | |
| 48 | + { | |
| 49 | + MetadataPropertyHandling = MetadataPropertyHandling.Ignore, | |
| 50 | + DateParseHandling = DateParseHandling.None, | |
| 51 | + Converters = | |
| 52 | + { | |
| 53 | + TopLevelValueConverter.Singleton, | |
| 54 | + new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal } | |
| 55 | + }, | |
| 56 | + }; | |
| 57 | + } | |
| 58 | + | |
| 59 | + internal class TopLevelValueConverter : JsonConverter | |
| 60 | + { | |
| 61 | + public override bool CanConvert(Type t) => t == typeof(TopLevelValue) || t == typeof(TopLevelValue?); | |
| 62 | + | |
| 63 | + public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer) | |
| 64 | + { | |
| 65 | + switch (reader.TokenType) | |
| 66 | + { | |
| 67 | + case JsonToken.Integer: | |
| 68 | + case JsonToken.Float: | |
| 69 | + var doubleValue = serializer.Deserialize<double>(reader); | |
| 70 | + return new TopLevelValue { Double = doubleValue }; | |
| 71 | + case JsonToken.String: | |
| 72 | + case JsonToken.Date: | |
| 73 | + var stringValue = serializer.Deserialize<string>(reader); | |
| 74 | + return new TopLevelValue { String = stringValue }; | |
| 75 | + } | |
| 76 | + throw new Exception("Cannot unmarshal type TopLevelValue"); | |
| 77 | + } | |
| 78 | + | |
| 79 | + public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer) | |
| 80 | + { | |
| 81 | + var value = (TopLevelValue)untypedValue; | |
| 82 | + if (value.Double != null) | |
| 83 | + { | |
| 84 | + serializer.Serialize(writer, value.Double.Value); | |
| 85 | + return; | |
| 86 | + } | |
| 87 | + if (value.String != null) | |
| 88 | + { | |
| 89 | + serializer.Serialize(writer, value.String); | |
| 90 | + return; | |
| 91 | + } | |
| 92 | + throw new Exception("Cannot marshal type TopLevelValue"); | |
| 93 | + } | |
| 94 | + | |
| 95 | + public static readonly TopLevelValueConverter Singleton = new TopLevelValueConverter(); | |
| 96 | + } | |
| 97 | +} | |
| 98 | +#pragma warning restore CS8618 | |
| 99 | +#pragma warning restore CS8601 | |
| 100 | +#pragma warning restore CS8602 | |
| 101 | +#pragma warning restore CS8603 | |
| 102 | +#pragma warning restore CS8604 | |
| 103 | +#pragma warning restore CS8625 | |
| 104 | +#pragma warning restore CS8765 |
Aschema-csharp-SystemTextJsondefault / QuickType.cs+205 −0
| @@ -0,0 +1,205 @@ | ||
| 1 | +// <auto-generated /> | |
| 2 | +// | |
| 3 | +// To parse this JSON data, add NuGet 'System.Text.Json' then do: | |
| 4 | +// | |
| 5 | +// using QuickType; | |
| 6 | +// | |
| 7 | +// var topLevel = TopLevel.FromJson(jsonString); | |
| 8 | +#nullable enable | |
| 9 | +#pragma warning disable CS8618 | |
| 10 | +#pragma warning disable CS8601 | |
| 11 | +#pragma warning disable CS8602 | |
| 12 | +#pragma warning disable CS8603 | |
| 13 | + | |
| 14 | +namespace QuickType | |
| 15 | +{ | |
| 16 | + using System; | |
| 17 | + using System.Collections.Generic; | |
| 18 | + | |
| 19 | + using System.Text.Json; | |
| 20 | + using System.Text.Json.Serialization; | |
| 21 | + using System.Globalization; | |
| 22 | + | |
| 23 | + public partial struct TopLevelValue | |
| 24 | + { | |
| 25 | + public double? Double; | |
| 26 | + public string? String; | |
| 27 | + | |
| 28 | + public static implicit operator TopLevelValue(double Double) => new TopLevelValue { Double = Double }; | |
| 29 | + public static implicit operator TopLevelValue(string String) => new TopLevelValue { String = String }; | |
| 30 | + } | |
| 31 | + | |
| 32 | + public class TopLevel | |
| 33 | + { | |
| 34 | + public static Dictionary<string, TopLevelValue> FromJson(string json) => global::System.Text.Json.JsonSerializer.Deserialize<Dictionary<string, TopLevelValue>>(json, QuickType.Converter.Settings); | |
| 35 | + } | |
| 36 | + | |
| 37 | + public static partial class Serialize | |
| 38 | + { | |
| 39 | + public static string ToJson(this Dictionary<string, TopLevelValue> self) => JsonSerializer.Serialize(self, QuickType.Converter.Settings); | |
| 40 | + } | |
| 41 | + | |
| 42 | + internal static partial class Converter | |
| 43 | + { | |
| 44 | + public static readonly JsonSerializerOptions Settings = new(JsonSerializerDefaults.General) | |
| 45 | + { | |
| 46 | + Converters = | |
| 47 | + { | |
| 48 | + TopLevelValueConverter.Singleton, | |
| 49 | + new DateOnlyConverter(), | |
| 50 | + new TimeOnlyConverter(), | |
| 51 | + IsoDateTimeOffsetConverter.Singleton | |
| 52 | + }, | |
| 53 | + }; | |
| 54 | + } | |
| 55 | + | |
| 56 | + internal class TopLevelValueConverter : JsonConverter<TopLevelValue> | |
| 57 | + { | |
| 58 | + public override bool CanConvert(Type t) => t == typeof(TopLevelValue); | |
| 59 | + | |
| 60 | + public override TopLevelValue Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | |
| 61 | + { | |
| 62 | + switch (reader.TokenType) | |
| 63 | + { | |
| 64 | + case JsonTokenType.Number: | |
| 65 | + var doubleValue1 = reader.GetDouble(); | |
| 66 | + return new TopLevelValue { Double = doubleValue1 }; | |
| 67 | + case JsonTokenType.String: | |
| 68 | + var stringValue = reader.GetString(); | |
| 69 | + return new TopLevelValue { String = stringValue }; | |
| 70 | + } | |
| 71 | + throw new JsonException("Cannot unmarshal type TopLevelValue"); | |
| 72 | + } | |
| 73 | + | |
| 74 | + public override void Write(Utf8JsonWriter writer, TopLevelValue value, JsonSerializerOptions options) | |
| 75 | + { | |
| 76 | + if (value.Double != null) | |
| 77 | + { | |
| 78 | + JsonSerializer.Serialize(writer, value.Double.Value, options); | |
| 79 | + return; | |
| 80 | + } | |
| 81 | + if (value.String != null) | |
| 82 | + { | |
| 83 | + JsonSerializer.Serialize(writer, value.String, options); | |
| 84 | + return; | |
| 85 | + } | |
| 86 | + throw new NotSupportedException("Cannot marshal type TopLevelValue"); | |
| 87 | + } | |
| 88 | + | |
| 89 | + public static readonly TopLevelValueConverter Singleton = new TopLevelValueConverter(); | |
| 90 | + } | |
| 91 | + | |
| 92 | + public class DateOnlyConverter : JsonConverter<DateOnly> | |
| 93 | + { | |
| 94 | + private readonly string serializationFormat; | |
| 95 | + public DateOnlyConverter() : this(null) { } | |
| 96 | + | |
| 97 | + public DateOnlyConverter(string? serializationFormat) | |
| 98 | + { | |
| 99 | + this.serializationFormat = serializationFormat ?? "yyyy-MM-dd"; | |
| 100 | + } | |
| 101 | + | |
| 102 | + public override DateOnly Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | |
| 103 | + { | |
| 104 | + var value = reader.GetString(); | |
| 105 | + return DateOnly.Parse(value!); | |
| 106 | + } | |
| 107 | + | |
| 108 | + public override void Write(Utf8JsonWriter writer, DateOnly value, JsonSerializerOptions options) | |
| 109 | + => writer.WriteStringValue(value.ToString(serializationFormat)); | |
| 110 | + } | |
| 111 | + | |
| 112 | + public class TimeOnlyConverter : JsonConverter<TimeOnly> | |
| 113 | + { | |
| 114 | + private readonly string serializationFormat; | |
| 115 | + | |
| 116 | + public TimeOnlyConverter() : this(null) { } | |
| 117 | + | |
| 118 | + public TimeOnlyConverter(string? serializationFormat) | |
| 119 | + { | |
| 120 | + this.serializationFormat = serializationFormat ?? "HH:mm:ss.fff"; | |
| 121 | + } | |
| 122 | + | |
| 123 | + public override TimeOnly Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | |
| 124 | + { | |
| 125 | + var value = reader.GetString(); | |
| 126 | + return TimeOnly.Parse(value!); | |
| 127 | + } | |
| 128 | + | |
| 129 | + public override void Write(Utf8JsonWriter writer, TimeOnly value, JsonSerializerOptions options) | |
| 130 | + => writer.WriteStringValue(value.ToString(serializationFormat)); | |
| 131 | + } | |
| 132 | + | |
| 133 | + internal class IsoDateTimeOffsetConverter : JsonConverter<DateTimeOffset> | |
| 134 | + { | |
| 135 | + public override bool CanConvert(Type t) => t == typeof(DateTimeOffset); | |
| 136 | + | |
| 137 | + private const string DefaultDateTimeFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss.FFFFFFFK"; | |
| 138 | + | |
| 139 | + private DateTimeStyles _dateTimeStyles = DateTimeStyles.RoundtripKind; | |
| 140 | + private string? _dateTimeFormat; | |
| 141 | + private CultureInfo? _culture; | |
| 142 | + | |
| 143 | + public DateTimeStyles DateTimeStyles | |
| 144 | + { | |
| 145 | + get => _dateTimeStyles; | |
| 146 | + set => _dateTimeStyles = value; | |
| 147 | + } | |
| 148 | + | |
| 149 | + public string? DateTimeFormat | |
| 150 | + { | |
| 151 | + get => _dateTimeFormat ?? string.Empty; | |
| 152 | + set => _dateTimeFormat = (string.IsNullOrEmpty(value)) ? null : value; | |
| 153 | + } | |
| 154 | + | |
| 155 | + public CultureInfo Culture | |
| 156 | + { | |
| 157 | + get => _culture ?? CultureInfo.CurrentCulture; | |
| 158 | + set => _culture = value; | |
| 159 | + } | |
| 160 | + | |
| 161 | + public override void Write(Utf8JsonWriter writer, DateTimeOffset value, JsonSerializerOptions options) | |
| 162 | + { | |
| 163 | + string text; | |
| 164 | + | |
| 165 | + | |
| 166 | + if ((_dateTimeStyles & DateTimeStyles.AdjustToUniversal) == DateTimeStyles.AdjustToUniversal | |
| 167 | + || (_dateTimeStyles & DateTimeStyles.AssumeUniversal) == DateTimeStyles.AssumeUniversal) | |
| 168 | + { | |
| 169 | + value = value.ToUniversalTime(); | |
| 170 | + } | |
| 171 | + | |
| 172 | + text = value.ToString(_dateTimeFormat ?? DefaultDateTimeFormat, Culture); | |
| 173 | + | |
| 174 | + writer.WriteStringValue(text); | |
| 175 | + } | |
| 176 | + | |
| 177 | + public override DateTimeOffset Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | |
| 178 | + { | |
| 179 | + string? dateText = reader.GetString(); | |
| 180 | + | |
| 181 | + if (string.IsNullOrEmpty(dateText) == false) | |
| 182 | + { | |
| 183 | + if (!string.IsNullOrEmpty(_dateTimeFormat)) | |
| 184 | + { | |
| 185 | + return DateTimeOffset.ParseExact(dateText, _dateTimeFormat, Culture, _dateTimeStyles); | |
| 186 | + } | |
| 187 | + else | |
| 188 | + { | |
| 189 | + return DateTimeOffset.Parse(dateText, Culture, _dateTimeStyles); | |
| 190 | + } | |
| 191 | + } | |
| 192 | + else | |
| 193 | + { | |
| 194 | + throw new JsonException("Cannot unmarshal date-time"); | |
| 195 | + } | |
| 196 | + } | |
| 197 | + | |
| 198 | + | |
| 199 | + public static readonly IsoDateTimeOffsetConverter Singleton = new IsoDateTimeOffsetConverter(); | |
| 200 | + } | |
| 201 | +} | |
| 202 | +#pragma warning restore CS8618 | |
| 203 | +#pragma warning restore CS8601 | |
| 204 | +#pragma warning restore CS8602 | |
| 205 | +#pragma warning restore CS8603 |
Aschema-csharpdefault / QuickType.cs+104 −0
| @@ -0,0 +1,104 @@ | ||
| 1 | +// <auto-generated /> | |
| 2 | +// | |
| 3 | +// To parse this JSON data, add NuGet 'Newtonsoft.Json' then do: | |
| 4 | +// | |
| 5 | +// using QuickType; | |
| 6 | +// | |
| 7 | +// var topLevel = TopLevel.FromJson(jsonString); | |
| 8 | +#nullable enable | |
| 9 | +#pragma warning disable CS8618 | |
| 10 | +#pragma warning disable CS8601 | |
| 11 | +#pragma warning disable CS8602 | |
| 12 | +#pragma warning disable CS8603 | |
| 13 | +#pragma warning disable CS8604 | |
| 14 | +#pragma warning disable CS8625 | |
| 15 | +#pragma warning disable CS8765 | |
| 16 | + | |
| 17 | +namespace QuickType | |
| 18 | +{ | |
| 19 | + using System; | |
| 20 | + using System.Collections.Generic; | |
| 21 | + | |
| 22 | + using System.Globalization; | |
| 23 | + using Newtonsoft.Json; | |
| 24 | + using Newtonsoft.Json.Converters; | |
| 25 | + | |
| 26 | + public partial struct TopLevelValue | |
| 27 | + { | |
| 28 | + public double? Double; | |
| 29 | + public string? String; | |
| 30 | + | |
| 31 | + public static implicit operator TopLevelValue(double Double) => new TopLevelValue { Double = Double }; | |
| 32 | + public static implicit operator TopLevelValue(string String) => new TopLevelValue { String = String }; | |
| 33 | + } | |
| 34 | + | |
| 35 | + public class TopLevel | |
| 36 | + { | |
| 37 | + public static Dictionary<string, TopLevelValue> FromJson(string json) => JsonConvert.DeserializeObject<Dictionary<string, TopLevelValue>>(json, QuickType.Converter.Settings); | |
| 38 | + } | |
| 39 | + | |
| 40 | + public static partial class Serialize | |
| 41 | + { | |
| 42 | + public static string ToJson(this Dictionary<string, TopLevelValue> self) => JsonConvert.SerializeObject(self, QuickType.Converter.Settings); | |
| 43 | + } | |
| 44 | + | |
| 45 | + internal static partial class Converter | |
| 46 | + { | |
| 47 | + public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings | |
| 48 | + { | |
| 49 | + MetadataPropertyHandling = MetadataPropertyHandling.Ignore, | |
| 50 | + DateParseHandling = DateParseHandling.None, | |
| 51 | + Converters = | |
| 52 | + { | |
| 53 | + TopLevelValueConverter.Singleton, | |
| 54 | + new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal } | |
| 55 | + }, | |
| 56 | + }; | |
| 57 | + } | |
| 58 | + | |
| 59 | + internal class TopLevelValueConverter : JsonConverter | |
| 60 | + { | |
| 61 | + public override bool CanConvert(Type t) => t == typeof(TopLevelValue) || t == typeof(TopLevelValue?); | |
| 62 | + | |
| 63 | + public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer) | |
| 64 | + { | |
| 65 | + switch (reader.TokenType) | |
| 66 | + { | |
| 67 | + case JsonToken.Integer: | |
| 68 | + case JsonToken.Float: | |
| 69 | + var doubleValue = serializer.Deserialize<double>(reader); | |
| 70 | + return new TopLevelValue { Double = doubleValue }; | |
| 71 | + case JsonToken.String: | |
| 72 | + case JsonToken.Date: | |
| 73 | + var stringValue = serializer.Deserialize<string>(reader); | |
| 74 | + return new TopLevelValue { String = stringValue }; | |
| 75 | + } | |
| 76 | + throw new Exception("Cannot unmarshal type TopLevelValue"); | |
| 77 | + } | |
| 78 | + | |
| 79 | + public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer) | |
| 80 | + { | |
| 81 | + var value = (TopLevelValue)untypedValue; | |
| 82 | + if (value.Double != null) | |
| 83 | + { | |
| 84 | + serializer.Serialize(writer, value.Double.Value); | |
| 85 | + return; | |
| 86 | + } | |
| 87 | + if (value.String != null) | |
| 88 | + { | |
| 89 | + serializer.Serialize(writer, value.String); | |
| 90 | + return; | |
| 91 | + } | |
| 92 | + throw new Exception("Cannot marshal type TopLevelValue"); | |
| 93 | + } | |
| 94 | + | |
| 95 | + public static readonly TopLevelValueConverter Singleton = new TopLevelValueConverter(); | |
| 96 | + } | |
| 97 | +} | |
| 98 | +#pragma warning restore CS8618 | |
| 99 | +#pragma warning restore CS8601 | |
| 100 | +#pragma warning restore CS8602 | |
| 101 | +#pragma warning restore CS8603 | |
| 102 | +#pragma warning restore CS8604 | |
| 103 | +#pragma warning restore CS8625 | |
| 104 | +#pragma warning restore CS8765 |
Aschema-dartdefault / TopLevel.dart+9 −0
| @@ -0,0 +1,9 @@ | ||
| 1 | +// To parse this JSON data, do | |
| 2 | +// | |
| 3 | +// final topLevel = topLevelFromJson(jsonString); | |
| 4 | + | |
| 5 | +import 'dart:convert'; | |
| 6 | + | |
| 7 | +Map<String, dynamic> topLevelFromJson(String str) => Map.from(json.decode(str)).map((k, v) => MapEntry<String, dynamic>(k, v)); | |
| 8 | + | |
| 9 | +String topLevelToJson(Map<String, dynamic> data) => json.encode(Map.from(data).map((k, v) => MapEntry<String, dynamic>(k, v))); |
Aschema-elixirdefault / QuickType.ex+20 −0
| @@ -0,0 +1,20 @@ | ||
| 1 | +# This file was autogenerated using quicktype https://github.com/quicktype/quicktype | |
| 2 | +# | |
| 3 | +# Add Jason to your mix.exs | |
| 4 | +# | |
| 5 | +# Decode a JSON string: TopLevel.from_json(data) | |
| 6 | +# Encode into a JSON string: TopLevel.to_json(struct) | |
| 7 | + | |
| 8 | +defmodule TopLevel do | |
| 9 | + def decode_value(value) when is_map(value), do: value | |
| 10 | + | |
| 11 | + def from_json(json) do | |
| 12 | + json | |
| 13 | + |> Jason.decode!() | |
| 14 | + |> decode_value() | |
| 15 | + end | |
| 16 | + | |
| 17 | + def to_json(data) do | |
| 18 | + Jason.encode!(data) | |
| 19 | + end | |
| 20 | +end |
Aschema-elmdefault / QuickType.elm+64 −0
| @@ -0,0 +1,64 @@ | ||
| 1 | +-- To decode the JSON data, add this file to your project, run | |
| 2 | +-- | |
| 3 | +-- elm install NoRedInk/elm-json-decode-pipeline | |
| 4 | +-- | |
| 5 | +-- add these imports | |
| 6 | +-- | |
| 7 | +-- import Json.Decode exposing (decodeString) | |
| 8 | +-- import QuickType exposing (quickType) | |
| 9 | +-- | |
| 10 | +-- and you're off to the races with | |
| 11 | +-- | |
| 12 | +-- decodeString quickType myJsonString | |
| 13 | + | |
| 14 | +module QuickType exposing | |
| 15 | + ( QuickType | |
| 16 | + , quickTypeToString | |
| 17 | + , quickType | |
| 18 | + , QuickTypeValue(..) | |
| 19 | + ) | |
| 20 | + | |
| 21 | +import Json.Decode as Jdec | |
| 22 | +import Json.Decode.Pipeline as Jpipe | |
| 23 | +import Json.Encode as Jenc | |
| 24 | +import Dict exposing (Dict) | |
| 25 | + | |
| 26 | +type alias QuickType = Dict String QuickTypeValue | |
| 27 | + | |
| 28 | +type QuickTypeValue | |
| 29 | + = DoubleInQuickTypeValue Float | |
| 30 | + | StringInQuickTypeValue String | |
| 31 | + | |
| 32 | +-- decoders and encoders | |
| 33 | +optionalField key decoder fallback = | |
| 34 | + Jdec.dict Jdec.value | |
| 35 | + |> Jdec.andThen (\m -> | |
| 36 | + case Dict.get key m of | |
| 37 | + Nothing -> Jdec.succeed fallback | |
| 38 | + Just x -> Jdec.decodeValue decoder x |> Result.map Jdec.succeed |> Result.withDefault (Jdec.fail ("Invalid " ++ key))) | |
| 39 | + | |
| 40 | +quickType : Jdec.Decoder QuickType | |
| 41 | +quickType = Jdec.dict quickTypeValue | |
| 42 | + | |
| 43 | +quickTypeToString : QuickType -> String | |
| 44 | +quickTypeToString r = Jenc.encode 0 (Jenc.dict identity encodeQuickTypeValue r) | |
| 45 | + | |
| 46 | +quickTypeValue : Jdec.Decoder QuickTypeValue | |
| 47 | +quickTypeValue = | |
| 48 | + Jdec.oneOf | |
| 49 | + [ Jdec.map StringInQuickTypeValue Jdec.string | |
| 50 | + , Jdec.map DoubleInQuickTypeValue Jdec.float | |
| 51 | + ] | |
| 52 | + | |
| 53 | +encodeQuickTypeValue : QuickTypeValue -> Jenc.Value | |
| 54 | +encodeQuickTypeValue x = case x of | |
| 55 | + StringInQuickTypeValue y -> Jenc.string y | |
| 56 | + DoubleInQuickTypeValue y -> Jenc.float y | |
| 57 | + | |
| 58 | +--- encoder helpers | |
| 59 | + | |
| 60 | +makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value | |
| 61 | +makeNullableEncoder f m = | |
| 62 | + case m of | |
| 63 | + Just x -> f x | |
| 64 | + Nothing -> Jenc.null |
Aschema-flowdefault / TopLevel.js+210 −0
| @@ -0,0 +1,210 @@ | ||
| 1 | +// @flow | |
| 2 | + | |
| 3 | +// To parse this data: | |
| 4 | +// | |
| 5 | +// const Convert = require("./TopLevel"); | |
| 6 | +// | |
| 7 | +// const topLevel = Convert.toTopLevel(json); | |
| 8 | +// | |
| 9 | +// These functions will throw an error if the JSON doesn't | |
| 10 | +// match the expected interface, even if the JSON is valid. | |
| 11 | + | |
| 12 | +export type TopLevel = { | |
| 13 | + id?: string; | |
| 14 | + [property: string]: number | string | void; | |
| 15 | +}; | |
| 16 | + | |
| 17 | +// Converts JSON strings to/from your types | |
| 18 | +// and asserts the results of JSON.parse at runtime | |
| 19 | +function toTopLevel(json: string): TopLevel { | |
| 20 | + return cast(JSON.parse(json), r("TopLevel")); | |
| 21 | +} | |
| 22 | + | |
| 23 | +function topLevelToJson(value: TopLevel): string { | |
| 24 | + return JSON.stringify(uncast(value, r("TopLevel")), null, 2); | |
| 25 | +} | |
| 26 | + | |
| 27 | +function invalidValue(typ: any, val: any, key: any, parent: any = '') { | |
| 28 | + const prettyTyp = prettyTypeName(typ); | |
| 29 | + const parentText = parent ? ` on ${parent}` : ''; | |
| 30 | + const keyText = key ? ` for key "${key}"` : ''; | |
| 31 | + throw Error(`Invalid value${keyText}${parentText}. Expected ${prettyTyp} but got ${JSON.stringify(val)}`); | |
| 32 | +} | |
| 33 | + | |
| 34 | +function prettyTypeName(typ: any): string { | |
| 35 | + if (Array.isArray(typ)) { | |
| 36 | + if (typ.length === 2 && typ[0] === undefined) { | |
| 37 | + return `an optional ${prettyTypeName(typ[1])}`; | |
| 38 | + } else { | |
| 39 | + return `one of [${typ.map(a => { return prettyTypeName(a); }).join(", ")}]`; | |
| 40 | + } | |
| 41 | + } else if (typeof typ === "object" && typ.literal !== undefined) { | |
| 42 | + return typ.literal; | |
| 43 | + } else { | |
| 44 | + return typeof typ; | |
| 45 | + } | |
| 46 | +} | |
| 47 | + | |
| 48 | +function jsonToJSProps(typ: any): any { | |
| 49 | + if (typ.jsonToJS === undefined) { | |
| 50 | + const map: any = {}; | |
| 51 | + typ.props.forEach((p: any) => map[p.json] = { key: p.js, typ: p.typ }); | |
| 52 | + typ.jsonToJS = map; | |
| 53 | + } | |
| 54 | + return typ.jsonToJS; | |
| 55 | +} | |
| 56 | + | |
| 57 | +function jsToJSONProps(typ: any): any { | |
| 58 | + if (typ.jsToJSON === undefined) { | |
| 59 | + const map: any = {}; | |
| 60 | + typ.props.forEach((p: any) => map[p.js] = { key: p.json, typ: p.typ }); | |
| 61 | + typ.jsToJSON = map; | |
| 62 | + } | |
| 63 | + return typ.jsToJSON; | |
| 64 | +} | |
| 65 | + | |
| 66 | +function transform(val: any, typ: any, getProps: any, key: any = '', parent: any = ''): any { | |
| 67 | + function transformPrimitive(typ: string, val: any): any { | |
| 68 | + if (typeof typ === typeof val) return val; | |
| 69 | + return invalidValue(typ, val, key, parent); | |
| 70 | + } | |
| 71 | + | |
| 72 | + function transformUnion(typs: any[], val: any): any { | |
| 73 | + // val must validate against one typ in typs | |
| 74 | + const l = typs.length; | |
| 75 | + for (let i = 0; i < l; i++) { | |
| 76 | + const typ = typs[i]; | |
| 77 | + try { | |
| 78 | + return transform(val, typ, getProps); | |
| 79 | + } catch (_) {} | |
| 80 | + } | |
| 81 | + return invalidValue(typs, val, key, parent); | |
| 82 | + } | |
| 83 | + | |
| 84 | + function transformEnum(cases: string[], val: any): any { | |
| 85 | + if (cases.indexOf(val) !== -1) return val; | |
| 86 | + return invalidValue(cases.map(a => { return l(a); }), val, key, parent); | |
| 87 | + } | |
| 88 | + | |
| 89 | + function transformArray(typ: any, val: any): any { | |
| 90 | + // val must be an array with no invalid elements | |
| 91 | + if (!Array.isArray(val)) return invalidValue(l("array"), val, key, parent); | |
| 92 | + | |
| 93 | + return val.map(el => transform(el, typ, getProps)); | |
| 94 | + } | |
| 95 | + | |
| 96 | + function transformDate(val: any): any { | |
| 97 | + if (val === null) { | |
| 98 | + return null; | |
| 99 | + } | |
| 100 | + const d = new Date(val); | |
| 101 | + if (isNaN(d.valueOf())) { | |
| 102 | + return invalidValue(l("Date"), val, key, parent); | |
| 103 | + } | |
| 104 | + return d; | |
| 105 | + } | |
| 106 | + | |
| 107 | + function transformObject(props: { [k: string]: any }, additional: any, val: any): any { | |
| 108 | + if (val === null || typeof val !== "object" || Array.isArray(val)) { | |
| 109 | + return invalidValue(l(ref || "object"), val, key, parent); | |
| 110 | + } | |
| 111 | + const result: any = {}; | |
| 112 | + Object.getOwnPropertyNames(props).forEach(key => { | |
| 113 | + const prop = props[key]; | |
| 114 | + const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; | |
| 115 | + result[prop.key] = transform(v, prop.typ, getProps, key, ref); | |
| 116 | + }); | |
| 117 | + Object.getOwnPropertyNames(val).forEach(key => { | |
| 118 | + if (!Object.prototype.hasOwnProperty.call(props, key)) { | |
| 119 | + result[key] = transform(val[key], additional, getProps, key, ref); | |
| 120 | + } | |
| 121 | + }); | |
| 122 | + return result; | |
| 123 | + } | |
| 124 | + | |
| 125 | + if (typ === "any") return val; | |
| 126 | + if (typ === null) { | |
| 127 | + if (val === null) return val; | |
| 128 | + return invalidValue(typ, val, key, parent); | |
| 129 | + } | |
| 130 | + if (typ === false) return invalidValue(typ, val, key, parent); | |
| 131 | + let ref: any = undefined; | |
| 132 | + while (typeof typ === "object" && typ.ref !== undefined) { | |
| 133 | + ref = typ.ref; | |
| 134 | + typ = typeMap[typ.ref]; | |
| 135 | + } | |
| 136 | + if (Array.isArray(typ)) return transformEnum(typ, val); | |
| 137 | + if (typeof typ === "object") { | |
| 138 | + return typ.hasOwnProperty("pattern") ? typeof val === "string" && new RegExp(typ.pattern).test(val) ? val : invalidValue(typ, val, key, parent) | |
| 139 | + : typ.hasOwnProperty("string") ? typeof val === "string" && (typ.min === undefined || Array.from(val).length >= typ.min) && (typ.max === undefined || Array.from(val).length <= typ.max) ? transform(val, typ.string, getProps, key, parent) : invalidValue(typ, val, key, parent) | |
| 140 | + : typ.hasOwnProperty("number") ? typeof val === "number" && (typ.min === undefined || val >= typ.min) && (typ.max === undefined || val <= typ.max) ? transform(val, typ.number, getProps, key, parent) : invalidValue(typ, val, key, parent) | |
| 141 | + : typ.hasOwnProperty("integer") ? typeof val === "number" && val % 1 === 0 ? val : invalidValue(l("integer"), val, key, parent) | |
| 142 | + : typ.hasOwnProperty("unionMembers") ? transformUnion(typ.unionMembers, val) | |
| 143 | + : typ.hasOwnProperty("arrayItems") ? transformArray(typ.arrayItems, val) | |
| 144 | + : typ.hasOwnProperty("props") ? transformObject(getProps(typ), typ.additional, val) | |
| 145 | + : invalidValue(typ, val, key, parent); | |
| 146 | + } | |
| 147 | + // Numbers can be parsed by Date but shouldn't be. | |
| 148 | + if (typ === Date && (typeof val === "string" || val instanceof Date)) return transformDate(val); | |
| 149 | + return transformPrimitive(typ, val); | |
| 150 | +} | |
| 151 | + | |
| 152 | +function cast<T>(val: any, typ: any): T { | |
| 153 | + return transform(val, typ, jsonToJSProps); | |
| 154 | +} | |
| 155 | + | |
| 156 | +function uncast<T>(val: T, typ: any): any { | |
| 157 | + return transform(val, typ, jsToJSONProps); | |
| 158 | +} | |
| 159 | + | |
| 160 | +function l(typ: any) { | |
| 161 | + return { literal: typ }; | |
| 162 | +} | |
| 163 | + | |
| 164 | +function a(typ: any) { | |
| 165 | + return { arrayItems: typ }; | |
| 166 | +} | |
| 167 | + | |
| 168 | +function i(typ: any) { | |
| 169 | + return { integer: typ }; | |
| 170 | +} | |
| 171 | + | |
| 172 | +function p(pattern: any) { | |
| 173 | + return { pattern }; | |
| 174 | +} | |
| 175 | + | |
| 176 | +function s(typ: any, min: any, max: any) { | |
| 177 | + return { string: typ, min, max }; | |
| 178 | +} | |
| 179 | + | |
| 180 | +function n(typ: any, min: any, max: any) { | |
| 181 | + return { number: typ, min, max }; | |
| 182 | +} | |
| 183 | + | |
| 184 | +function u(...typs: any[]) { | |
| 185 | + return { unionMembers: typs }; | |
| 186 | +} | |
| 187 | + | |
| 188 | +function o(props: any[], additional: any) { | |
| 189 | + return { props, additional }; | |
| 190 | +} | |
| 191 | + | |
| 192 | +function m(additional: any) { | |
| 193 | + const props: any[] = []; | |
| 194 | + return { props, additional }; | |
| 195 | +} | |
| 196 | + | |
| 197 | +function r(name: string) { | |
| 198 | + return { ref: name }; | |
| 199 | +} | |
| 200 | + | |
| 201 | +const typeMap: any = { | |
| 202 | + "TopLevel": o([ | |
| 203 | + { json: "id", js: "id", typ: u(undefined, "") }, | |
| 204 | + ], 3.14), | |
| 205 | +}; | |
| 206 | + | |
| 207 | +module.exports = { | |
| 208 | + "topLevelToJson": topLevelToJson, | |
| 209 | + "toTopLevel": toTopLevel, | |
| 210 | +}; |
Aschema-golangdefault / quicktype.go+156 −0
| @@ -0,0 +1,156 @@ | ||
| 1 | +// Code generated from JSON Schema using quicktype. DO NOT EDIT. | |
| 2 | +// To parse and unparse this JSON data, add this code to your project and do: | |
| 3 | +// | |
| 4 | +// topLevel, err := UnmarshalTopLevel(bytes) | |
| 5 | +// bytes, err = topLevel.Marshal() | |
| 6 | + | |
| 7 | +package main | |
| 8 | + | |
| 9 | +import "bytes" | |
| 10 | +import "errors" | |
| 11 | + | |
| 12 | +import "encoding/json" | |
| 13 | + | |
| 14 | +type TopLevel map[string]*TopLevelValue | |
| 15 | + | |
| 16 | +func UnmarshalTopLevel(data []byte) (TopLevel, error) { | |
| 17 | + var r TopLevel | |
| 18 | + err := json.Unmarshal(data, &r) | |
| 19 | + return r, err | |
| 20 | +} | |
| 21 | + | |
| 22 | +func (r *TopLevel) Marshal() ([]byte, error) { | |
| 23 | + return json.Marshal(r) | |
| 24 | +} | |
| 25 | + | |
| 26 | +type TopLevelValue struct { | |
| 27 | + Double *float64 | |
| 28 | + String *string | |
| 29 | +} | |
| 30 | + | |
| 31 | +func (x *TopLevelValue) UnmarshalJSON(data []byte) error { | |
| 32 | + object, err := unmarshalUnion(data, nil, &x.Double, nil, &x.String, false, nil, false, nil, false, nil, false, nil, false) | |
| 33 | + if err != nil { | |
| 34 | + return err | |
| 35 | + } | |
| 36 | + if object { | |
| 37 | + } | |
| 38 | + return nil | |
| 39 | +} | |
| 40 | + | |
| 41 | +func (x *TopLevelValue) MarshalJSON() ([]byte, error) { | |
| 42 | + return marshalUnion(nil, x.Double, nil, x.String, false, nil, false, nil, false, nil, false, nil, false) | |
| 43 | +} | |
| 44 | + | |
| 45 | +func unmarshalUnion(data []byte, pi **int64, pf **float64, pb **bool, ps **string, haveArray bool, pa interface{}, haveObject bool, pc interface{}, haveMap bool, pm interface{}, haveEnum bool, pe interface{}, nullable bool) (bool, error) { | |
| 46 | + if pi != nil { | |
| 47 | + *pi = nil | |
| 48 | + } | |
| 49 | + if pf != nil { | |
| 50 | + *pf = nil | |
| 51 | + } | |
| 52 | + if pb != nil { | |
| 53 | + *pb = nil | |
| 54 | + } | |
| 55 | + if ps != nil { | |
| 56 | + *ps = nil | |
| 57 | + } | |
| 58 | + | |
| 59 | + dec := json.NewDecoder(bytes.NewReader(data)) | |
| 60 | + dec.UseNumber() | |
| 61 | + tok, err := dec.Token() | |
| 62 | + if err != nil { | |
| 63 | + return false, err | |
| 64 | + } | |
| 65 | + | |
| 66 | + switch v := tok.(type) { | |
| 67 | + case json.Number: | |
| 68 | + if pi != nil { | |
| 69 | + i, err := v.Int64() | |
| 70 | + if err == nil { | |
| 71 | + *pi = &i | |
| 72 | + return false, nil | |
| 73 | + } | |
| 74 | + } | |
| 75 | + if pf != nil { | |
| 76 | + f, err := v.Float64() | |
| 77 | + if err == nil { | |
| 78 | + *pf = &f | |
| 79 | + return false, nil | |
| 80 | + } | |
| 81 | + return false, errors.New("Unparsable number") | |
| 82 | + } | |
| 83 | + return false, errors.New("Union does not contain number") | |
| 84 | + case float64: | |
| 85 | + return false, errors.New("Decoder should not return float64") | |
| 86 | + case bool: | |
| 87 | + if pb != nil { | |
| 88 | + *pb = &v | |
| 89 | + return false, nil | |
| 90 | + } | |
| 91 | + return false, errors.New("Union does not contain bool") | |
| 92 | + case string: | |
| 93 | + if haveEnum { | |
| 94 | + return false, json.Unmarshal(data, pe) | |
| 95 | + } | |
| 96 | + if ps != nil { | |
| 97 | + *ps = &v | |
| 98 | + return false, nil | |
| 99 | + } | |
| 100 | + return false, errors.New("Union does not contain string") | |
| 101 | + case nil: | |
| 102 | + if nullable { | |
| 103 | + return false, nil | |
| 104 | + } | |
| 105 | + return false, errors.New("Union does not contain null") | |
| 106 | + case json.Delim: | |
| 107 | + if v == '{' { | |
| 108 | + if haveObject { | |
| 109 | + return true, json.Unmarshal(data, pc) | |
| 110 | + } | |
| 111 | + if haveMap { | |
| 112 | + return false, json.Unmarshal(data, pm) | |
| 113 | + } | |
| 114 | + return false, errors.New("Union does not contain object") | |
| 115 | + } | |
| 116 | + if v == '[' { | |
| 117 | + if haveArray { | |
| 118 | + return false, json.Unmarshal(data, pa) | |
| 119 | + } | |
| 120 | + return false, errors.New("Union does not contain array") | |
| 121 | + } | |
| 122 | + return false, errors.New("Cannot handle delimiter") | |
| 123 | + } | |
| 124 | + return false, errors.New("Cannot unmarshal union") | |
| 125 | +} | |
| 126 | + | |
| 127 | +func marshalUnion(pi *int64, pf *float64, pb *bool, ps *string, haveArray bool, pa interface{}, haveObject bool, pc interface{}, haveMap bool, pm interface{}, haveEnum bool, pe interface{}, nullable bool) ([]byte, error) { | |
| 128 | + if pi != nil { | |
| 129 | + return json.Marshal(*pi) | |
| 130 | + } | |
| 131 | + if pf != nil { | |
| 132 | + return json.Marshal(*pf) | |
| 133 | + } | |
| 134 | + if pb != nil { | |
| 135 | + return json.Marshal(*pb) | |
| 136 | + } | |
| 137 | + if ps != nil { | |
| 138 | + return json.Marshal(*ps) | |
| 139 | + } | |
| 140 | + if haveArray { | |
| 141 | + return json.Marshal(pa) | |
| 142 | + } | |
| 143 | + if haveObject { | |
| 144 | + return json.Marshal(pc) | |
| 145 | + } | |
| 146 | + if haveMap { | |
| 147 | + return json.Marshal(pm) | |
| 148 | + } | |
| 149 | + if haveEnum { | |
| 150 | + return json.Marshal(pe) | |
| 151 | + } | |
| 152 | + if nullable { | |
| 153 | + return json.Marshal(nil) | |
| 154 | + } | |
| 155 | + return nil, errors.New("Union must not be null") | |
| 156 | +} |
Aschema-haskelldefault / QuickType.hs+32 −0
| @@ -0,0 +1,32 @@ | ||
| 1 | +{-# LANGUAGE StrictData #-} | |
| 2 | +{-# LANGUAGE OverloadedStrings #-} | |
| 3 | + | |
| 4 | +module QuickType | |
| 5 | + ( QuickType (..) | |
| 6 | + , QuickTypeValue (..) | |
| 7 | + , decodeTopLevel | |
| 8 | + ) where | |
| 9 | + | |
| 10 | +import Data.Aeson | |
| 11 | +import Data.Aeson.Types (emptyObject) | |
| 12 | +import Data.ByteString.Lazy (ByteString) | |
| 13 | +import Data.HashMap.Strict (HashMap) | |
| 14 | +import Data.Text (Text) | |
| 15 | + | |
| 16 | +type QuickType = HashMap Text QuickTypeValue | |
| 17 | + | |
| 18 | +data QuickTypeValue | |
| 19 | + = DoubleInQuickTypeValue Double | |
| 20 | + | StringInQuickTypeValue Text | |
| 21 | + deriving (Show) | |
| 22 | + | |
| 23 | +decodeTopLevel :: ByteString -> Maybe QuickType | |
| 24 | +decodeTopLevel = decode | |
| 25 | + | |
| 26 | +instance ToJSON QuickTypeValue where | |
| 27 | + toJSON (DoubleInQuickTypeValue x) = toJSON x | |
| 28 | + toJSON (StringInQuickTypeValue x) = toJSON x | |
| 29 | + | |
| 30 | +instance FromJSON QuickTypeValue where | |
| 31 | + parseJSON xs@(Number _) = (fmap DoubleInQuickTypeValue . parseJSON) xs | |
| 32 | + parseJSON xs@(String _) = (fmap StringInQuickTypeValue . parseJSON) xs |
Aschema-java-datetime-legacydefault / src / main / java / io / quicktype / Converter.java+123 −0
| @@ -0,0 +1,123 @@ | ||
| 1 | +// To use this code, add the following Maven dependency to your project: | |
| 2 | +// | |
| 3 | +// | |
| 4 | +// com.fasterxml.jackson.core : jackson-databind : 2.9.0 | |
| 5 | +// | |
| 6 | +// | |
| 7 | +// Import this package: | |
| 8 | +// | |
| 9 | +// import io.quicktype.Converter; | |
| 10 | +// | |
| 11 | +// Then you can deserialize a JSON string with | |
| 12 | +// | |
| 13 | +// Map<String, TopLevel> data = Converter.fromJsonString(jsonString); | |
| 14 | + | |
| 15 | +package io.quicktype; | |
| 16 | + | |
| 17 | +import java.io.IOException; | |
| 18 | +import com.fasterxml.jackson.databind.*; | |
| 19 | +import com.fasterxml.jackson.databind.module.SimpleModule; | |
| 20 | +import com.fasterxml.jackson.core.JsonParser; | |
| 21 | +import com.fasterxml.jackson.core.JsonProcessingException; | |
| 22 | +import com.fasterxml.jackson.core.type.TypeReference; | |
| 23 | +import java.util.*; | |
| 24 | +import java.util.Date; | |
| 25 | +import java.text.SimpleDateFormat; | |
| 26 | + | |
| 27 | +public class Converter { | |
| 28 | + // Date-time helpers | |
| 29 | + | |
| 30 | + private static final String[] DATE_TIME_FORMATS = { | |
| 31 | + "yyyy-MM-dd'T'HH:mm:ss.SX", | |
| 32 | + "yyyy-MM-dd'T'HH:mm:ss.S", | |
| 33 | + "yyyy-MM-dd'T'HH:mm:ssX", | |
| 34 | + "yyyy-MM-dd'T'HH:mm:ss", | |
| 35 | + "yyyy-MM-dd HH:mm:ss.SX", | |
| 36 | + "yyyy-MM-dd HH:mm:ss.S", | |
| 37 | + "yyyy-MM-dd HH:mm:ssX", | |
| 38 | + "yyyy-MM-dd HH:mm:ss", | |
| 39 | + "HH:mm:ss.SZ", | |
| 40 | + "HH:mm:ss.S", | |
| 41 | + "HH:mm:ssZ", | |
| 42 | + "HH:mm:ss", | |
| 43 | + "yyyy-MM-dd", | |
| 44 | + }; | |
| 45 | + | |
| 46 | + public static Date parseAllDateTimeString(String str) { | |
| 47 | + str = str.replaceFirst("(\\.\\d{3})\\d+", "$1"); | |
| 48 | + for (String format : DATE_TIME_FORMATS) { | |
| 49 | + try { | |
| 50 | + return new SimpleDateFormat(format).parse(str); | |
| 51 | + } catch (Exception ex) { | |
| 52 | + // Ignored | |
| 53 | + } | |
| 54 | + } | |
| 55 | + return null; | |
| 56 | + } | |
| 57 | + | |
| 58 | + public static String serializeDateTime(Date datetime) { | |
| 59 | + return new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ssZ").format(datetime); | |
| 60 | + } | |
| 61 | + | |
| 62 | + public static String serializeDate(Date datetime) { | |
| 63 | + return new SimpleDateFormat("yyyy-MM-dd").format(datetime); | |
| 64 | + } | |
| 65 | + | |
| 66 | + public static String serializeTime(Date datetime) { | |
| 67 | + return new SimpleDateFormat("hh:mm:ssZ").format(datetime); | |
| 68 | + } | |
| 69 | + // Serialize/deserialize helpers | |
| 70 | + | |
| 71 | + public static Map<String, TopLevel> fromJsonString(String json) throws IOException { | |
| 72 | + return getObjectReader().readValue(json); | |
| 73 | + } | |
| 74 | + | |
| 75 | + public static String toJsonString(Map<String, TopLevel> obj) throws JsonProcessingException { | |
| 76 | + return getObjectWriter().writeValueAsString(obj); | |
| 77 | + } | |
| 78 | + | |
| 79 | + private static ObjectReader reader; | |
| 80 | + private static ObjectWriter writer; | |
| 81 | + | |
| 82 | + private static void instantiateMapper() { | |
| 83 | + ObjectMapper mapper = new ObjectMapper(); | |
| 84 | + mapper.findAndRegisterModules(); | |
| 85 | + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); | |
| 86 | + mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); | |
| 87 | + SimpleModule module = new SimpleModule(); | |
| 88 | + module.addDeserializer(Date.class, new JsonDeserializer<Date>() { | |
| 89 | + @Override | |
| 90 | + public Date deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { | |
| 91 | + String value = jsonParser.getText(); | |
| 92 | + return Converter.parseAllDateTimeString(value); | |
| 93 | + } | |
| 94 | + }); | |
| 95 | + module.addDeserializer(Date.class, new JsonDeserializer<Date>() { | |
| 96 | + @Override | |
| 97 | + public Date deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { | |
| 98 | + String value = jsonParser.getText(); | |
| 99 | + return Converter.parseAllDateTimeString(value); | |
| 100 | + } | |
| 101 | + }); | |
| 102 | + module.addDeserializer(Date.class, new JsonDeserializer<Date>() { | |
| 103 | + @Override | |
| 104 | + public Date deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { | |
| 105 | + String value = jsonParser.getText(); | |
| 106 | + return Converter.parseAllDateTimeString(value); | |
| 107 | + } | |
| 108 | + }); | |
| 109 | + mapper.registerModule(module); | |
| 110 | + reader = mapper.readerFor(Map.class); | |
| 111 | + writer = mapper.writerFor(Map.class); | |
| 112 | + } | |
| 113 | + | |
| 114 | + private static ObjectReader getObjectReader() { | |
| 115 | + if (reader == null) instantiateMapper(); | |
| 116 | + return reader; | |
| 117 | + } | |
| 118 | + | |
| 119 | + private static ObjectWriter getObjectWriter() { | |
| 120 | + if (writer == null) instantiateMapper(); | |
| 121 | + return writer; | |
| 122 | + } | |
| 123 | +} |
Aschema-java-datetime-legacydefault / src / main / java / io / quicktype / TopLevel.java+49 −0
| @@ -0,0 +1,49 @@ | ||
| 1 | +package io.quicktype; | |
| 2 | + | |
| 3 | +import java.io.IOException; | |
| 4 | +import java.io.IOException; | |
| 5 | +import com.fasterxml.jackson.core.*; | |
| 6 | +import com.fasterxml.jackson.databind.*; | |
| 7 | +import com.fasterxml.jackson.databind.annotation.*; | |
| 8 | +import com.fasterxml.jackson.core.type.*; | |
| 9 | + | |
| 10 | +@JsonDeserialize(using = TopLevel.Deserializer.class) | |
| 11 | +@JsonSerialize(using = TopLevel.Serializer.class) | |
| 12 | +public class TopLevel { | |
| 13 | + public String stringValue; | |
| 14 | + public Double doubleValue; | |
| 15 | + | |
| 16 | + static class Deserializer extends JsonDeserializer<TopLevel> { | |
| 17 | + @Override | |
| 18 | + public TopLevel deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { | |
| 19 | + TopLevel value = new TopLevel(); | |
| 20 | + switch (jsonParser.currentToken()) { | |
| 21 | + case VALUE_NUMBER_INT: | |
| 22 | + case VALUE_NUMBER_FLOAT: | |
| 23 | + value.doubleValue = jsonParser.readValueAs(Double.class); | |
| 24 | + break; | |
| 25 | + case VALUE_STRING: | |
| 26 | + String string = jsonParser.readValueAs(String.class); | |
| 27 | + value.stringValue = string; | |
| 28 | + break; | |
| 29 | + default: throw new IOException("Cannot deserialize TopLevel"); | |
| 30 | + } | |
| 31 | + return value; | |
| 32 | + } | |
| 33 | + } | |
| 34 | + | |
| 35 | + static class Serializer extends JsonSerializer<TopLevel> { | |
| 36 | + @Override | |
| 37 | + public void serialize(TopLevel obj, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { | |
| 38 | + if (obj.stringValue != null) { | |
| 39 | + jsonGenerator.writeObject(obj.stringValue); | |
| 40 | + return; | |
| 41 | + } | |
| 42 | + if (obj.doubleValue != null) { | |
| 43 | + jsonGenerator.writeObject(obj.doubleValue); | |
| 44 | + return; | |
| 45 | + } | |
| 46 | + throw new IOException("TopLevel must not be null"); | |
| 47 | + } | |
| 48 | + } | |
| 49 | +} |
Aschema-java-lombokdefault / src / main / java / io / quicktype / Converter.java+102 −0
| @@ -0,0 +1,102 @@ | ||
| 1 | +// To use this code, add the following Maven dependency to your project: | |
| 2 | +// | |
| 3 | +// | |
| 4 | +// com.fasterxml.jackson.core : jackson-databind : 2.9.0 | |
| 5 | +// com.fasterxml.jackson.datatype : jackson-datatype-jsr310 : 2.9.0 | |
| 6 | +// | |
| 7 | +// Import this package: | |
| 8 | +// | |
| 9 | +// import io.quicktype.Converter; | |
| 10 | +// | |
| 11 | +// Then you can deserialize a JSON string with | |
| 12 | +// | |
| 13 | +// Map<String, TopLevel> data = Converter.fromJsonString(jsonString); | |
| 14 | + | |
| 15 | +package io.quicktype; | |
| 16 | + | |
| 17 | +import java.io.IOException; | |
| 18 | +import com.fasterxml.jackson.databind.*; | |
| 19 | +import com.fasterxml.jackson.databind.module.SimpleModule; | |
| 20 | +import com.fasterxml.jackson.core.JsonParser; | |
| 21 | +import com.fasterxml.jackson.core.JsonProcessingException; | |
| 22 | +import com.fasterxml.jackson.core.type.TypeReference; | |
| 23 | +import java.util.*; | |
| 24 | +import java.time.LocalDate; | |
| 25 | +import java.time.OffsetDateTime; | |
| 26 | +import java.time.OffsetTime; | |
| 27 | +import java.time.ZoneOffset; | |
| 28 | +import java.time.ZonedDateTime; | |
| 29 | +import java.time.format.DateTimeFormatter; | |
| 30 | +import java.time.format.DateTimeFormatterBuilder; | |
| 31 | +import java.time.temporal.ChronoField; | |
| 32 | + | |
| 33 | +public class Converter { | |
| 34 | + // Date-time helpers | |
| 35 | + | |
| 36 | + private static final DateTimeFormatter DATE_TIME_FORMATTER = new DateTimeFormatterBuilder() | |
| 37 | + .appendOptional(DateTimeFormatter.ISO_DATE_TIME) | |
| 38 | + .appendOptional(DateTimeFormatter.ISO_OFFSET_DATE_TIME) | |
| 39 | + .appendOptional(DateTimeFormatter.ISO_INSTANT) | |
| 40 | + .appendOptional(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SX")) | |
| 41 | + .appendOptional(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ssX")) | |
| 42 | + .appendOptional(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")) | |
| 43 | + .toFormatter() | |
| 44 | + .withZone(ZoneOffset.UTC); | |
| 45 | + | |
| 46 | + public static OffsetDateTime parseDateTimeString(String str) { | |
| 47 | + return ZonedDateTime.from(Converter.DATE_TIME_FORMATTER.parse(str)).toOffsetDateTime(); | |
| 48 | + } | |
| 49 | + | |
| 50 | + private static final DateTimeFormatter TIME_FORMATTER = new DateTimeFormatterBuilder() | |
| 51 | + .appendOptional(DateTimeFormatter.ISO_TIME) | |
| 52 | + .appendOptional(DateTimeFormatter.ISO_OFFSET_TIME) | |
| 53 | + .parseDefaulting(ChronoField.YEAR, 2020) | |
| 54 | + .parseDefaulting(ChronoField.MONTH_OF_YEAR, 1) | |
| 55 | + .parseDefaulting(ChronoField.DAY_OF_MONTH, 1) | |
| 56 | + .toFormatter() | |
| 57 | + .withZone(ZoneOffset.UTC); | |
| 58 | + | |
| 59 | + public static OffsetTime parseTimeString(String str) { | |
| 60 | + return ZonedDateTime.from(Converter.TIME_FORMATTER.parse(str)).toOffsetDateTime().toOffsetTime(); | |
| 61 | + } | |
| 62 | + // Serialize/deserialize helpers | |
| 63 | + | |
| 64 | + public static Map<String, TopLevel> fromJsonString(String json) throws IOException { | |
| 65 | + return getObjectReader().readValue(json); | |
| 66 | + } | |
| 67 | + | |
| 68 | + public static String toJsonString(Map<String, TopLevel> obj) throws JsonProcessingException { | |
| 69 | + return getObjectWriter().writeValueAsString(obj); | |
| 70 | + } | |
| 71 | + | |
| 72 | + private static ObjectReader reader; | |
| 73 | + private static ObjectWriter writer; | |
| 74 | + | |
| 75 | + private static void instantiateMapper() { | |
| 76 | + ObjectMapper mapper = new ObjectMapper(); | |
| 77 | + mapper.findAndRegisterModules(); | |
| 78 | + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); | |
| 79 | + mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); | |
| 80 | + SimpleModule module = new SimpleModule(); | |
| 81 | + module.addDeserializer(OffsetDateTime.class, new JsonDeserializer<OffsetDateTime>() { | |
| 82 | + @Override | |
| 83 | + public OffsetDateTime deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { | |
| 84 | + String value = jsonParser.getText(); | |
| 85 | + return Converter.parseDateTimeString(value); | |
| 86 | + } | |
| 87 | + }); | |
| 88 | + mapper.registerModule(module); | |
| 89 | + reader = mapper.readerFor(Map.class); | |
| 90 | + writer = mapper.writerFor(Map.class); | |
| 91 | + } | |
| 92 | + | |
| 93 | + private static ObjectReader getObjectReader() { | |
| 94 | + if (reader == null) instantiateMapper(); | |
| 95 | + return reader; | |
| 96 | + } | |
| 97 | + | |
| 98 | + private static ObjectWriter getObjectWriter() { | |
| 99 | + if (writer == null) instantiateMapper(); | |
| 100 | + return writer; | |
| 101 | + } | |
| 102 | +} |
Aschema-java-lombokdefault / src / main / java / io / quicktype / TopLevel.java+49 −0
| @@ -0,0 +1,49 @@ | ||
| 1 | +package io.quicktype; | |
| 2 | + | |
| 3 | +import java.io.IOException; | |
| 4 | +import java.io.IOException; | |
| 5 | +import com.fasterxml.jackson.core.*; | |
| 6 | +import com.fasterxml.jackson.databind.*; | |
| 7 | +import com.fasterxml.jackson.databind.annotation.*; | |
| 8 | +import com.fasterxml.jackson.core.type.*; | |
| 9 | + | |
| 10 | +@JsonDeserialize(using = TopLevel.Deserializer.class) | |
| 11 | +@JsonSerialize(using = TopLevel.Serializer.class) | |
| 12 | +public class TopLevel { | |
| 13 | + public String stringValue; | |
| 14 | + public Double doubleValue; | |
| 15 | + | |
| 16 | + static class Deserializer extends JsonDeserializer<TopLevel> { | |
| 17 | + @Override | |
| 18 | + public TopLevel deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { | |
| 19 | + TopLevel value = new TopLevel(); | |
| 20 | + switch (jsonParser.currentToken()) { | |
| 21 | + case VALUE_NUMBER_INT: | |
| 22 | + case VALUE_NUMBER_FLOAT: | |
| 23 | + value.doubleValue = jsonParser.readValueAs(Double.class); | |
| 24 | + break; | |
| 25 | + case VALUE_STRING: | |
| 26 | + String string = jsonParser.readValueAs(String.class); | |
| 27 | + value.stringValue = string; | |
| 28 | + break; | |
| 29 | + default: throw new IOException("Cannot deserialize TopLevel"); | |
| 30 | + } | |
| 31 | + return value; | |
| 32 | + } | |
| 33 | + } | |
| 34 | + | |
| 35 | + static class Serializer extends JsonSerializer<TopLevel> { | |
| 36 | + @Override | |
| 37 | + public void serialize(TopLevel obj, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { | |
| 38 | + if (obj.stringValue != null) { | |
| 39 | + jsonGenerator.writeObject(obj.stringValue); | |
| 40 | + return; | |
| 41 | + } | |
| 42 | + if (obj.doubleValue != null) { | |
| 43 | + jsonGenerator.writeObject(obj.doubleValue); | |
| 44 | + return; | |
| 45 | + } | |
| 46 | + throw new IOException("TopLevel must not be null"); | |
| 47 | + } | |
| 48 | + } | |
| 49 | +} |
Aschema-javadefault / src / main / java / io / quicktype / Converter.java+102 −0
| @@ -0,0 +1,102 @@ | ||
| 1 | +// To use this code, add the following Maven dependency to your project: | |
| 2 | +// | |
| 3 | +// | |
| 4 | +// com.fasterxml.jackson.core : jackson-databind : 2.9.0 | |
| 5 | +// com.fasterxml.jackson.datatype : jackson-datatype-jsr310 : 2.9.0 | |
| 6 | +// | |
| 7 | +// Import this package: | |
| 8 | +// | |
| 9 | +// import io.quicktype.Converter; | |
| 10 | +// | |
| 11 | +// Then you can deserialize a JSON string with | |
| 12 | +// | |
| 13 | +// Map<String, TopLevel> data = Converter.fromJsonString(jsonString); | |
| 14 | + | |
| 15 | +package io.quicktype; | |
| 16 | + | |
| 17 | +import java.io.IOException; | |
| 18 | +import com.fasterxml.jackson.databind.*; | |
| 19 | +import com.fasterxml.jackson.databind.module.SimpleModule; | |
| 20 | +import com.fasterxml.jackson.core.JsonParser; | |
| 21 | +import com.fasterxml.jackson.core.JsonProcessingException; | |
| 22 | +import com.fasterxml.jackson.core.type.TypeReference; | |
| 23 | +import java.util.*; | |
| 24 | +import java.time.LocalDate; | |
| 25 | +import java.time.OffsetDateTime; | |
| 26 | +import java.time.OffsetTime; | |
| 27 | +import java.time.ZoneOffset; | |
| 28 | +import java.time.ZonedDateTime; | |
| 29 | +import java.time.format.DateTimeFormatter; | |
| 30 | +import java.time.format.DateTimeFormatterBuilder; | |
| 31 | +import java.time.temporal.ChronoField; | |
| 32 | + | |
| 33 | +public class Converter { | |
| 34 | + // Date-time helpers | |
| 35 | + | |
| 36 | + private static final DateTimeFormatter DATE_TIME_FORMATTER = new DateTimeFormatterBuilder() | |
| 37 | + .appendOptional(DateTimeFormatter.ISO_DATE_TIME) | |
| 38 | + .appendOptional(DateTimeFormatter.ISO_OFFSET_DATE_TIME) | |
| 39 | + .appendOptional(DateTimeFormatter.ISO_INSTANT) | |
| 40 | + .appendOptional(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SX")) | |
| 41 | + .appendOptional(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ssX")) | |
| 42 | + .appendOptional(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")) | |
| 43 | + .toFormatter() | |
| 44 | + .withZone(ZoneOffset.UTC); | |
| 45 | + | |
| 46 | + public static OffsetDateTime parseDateTimeString(String str) { | |
| 47 | + return ZonedDateTime.from(Converter.DATE_TIME_FORMATTER.parse(str)).toOffsetDateTime(); | |
| 48 | + } | |
| 49 | + | |
| 50 | + private static final DateTimeFormatter TIME_FORMATTER = new DateTimeFormatterBuilder() | |
| 51 | + .appendOptional(DateTimeFormatter.ISO_TIME) | |
| 52 | + .appendOptional(DateTimeFormatter.ISO_OFFSET_TIME) | |
| 53 | + .parseDefaulting(ChronoField.YEAR, 2020) | |
| 54 | + .parseDefaulting(ChronoField.MONTH_OF_YEAR, 1) | |
| 55 | + .parseDefaulting(ChronoField.DAY_OF_MONTH, 1) | |
| 56 | + .toFormatter() | |
| 57 | + .withZone(ZoneOffset.UTC); | |
| 58 | + | |
| 59 | + public static OffsetTime parseTimeString(String str) { | |
| 60 | + return ZonedDateTime.from(Converter.TIME_FORMATTER.parse(str)).toOffsetDateTime().toOffsetTime(); | |
| 61 | + } | |
| 62 | + // Serialize/deserialize helpers | |
| 63 | + | |
| 64 | + public static Map<String, TopLevel> fromJsonString(String json) throws IOException { | |
| 65 | + return getObjectReader().readValue(json); | |
| 66 | + } | |
| 67 | + | |
| 68 | + public static String toJsonString(Map<String, TopLevel> obj) throws JsonProcessingException { | |
| 69 | + return getObjectWriter().writeValueAsString(obj); | |
| 70 | + } | |
| 71 | + | |
| 72 | + private static ObjectReader reader; | |
| 73 | + private static ObjectWriter writer; | |
| 74 | + | |
| 75 | + private static void instantiateMapper() { | |
| 76 | + ObjectMapper mapper = new ObjectMapper(); | |
| 77 | + mapper.findAndRegisterModules(); | |
| 78 | + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); | |
| 79 | + mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); | |
| 80 | + SimpleModule module = new SimpleModule(); | |
| 81 | + module.addDeserializer(OffsetDateTime.class, new JsonDeserializer<OffsetDateTime>() { | |
| 82 | + @Override | |
| 83 | + public OffsetDateTime deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { | |
| 84 | + String value = jsonParser.getText(); | |
| 85 | + return Converter.parseDateTimeString(value); | |
| 86 | + } | |
| 87 | + }); | |
| 88 | + mapper.registerModule(module); | |
| 89 | + reader = mapper.readerFor(Map.class); | |
| 90 | + writer = mapper.writerFor(Map.class); | |
| 91 | + } | |
| 92 | + | |
| 93 | + private static ObjectReader getObjectReader() { | |
| 94 | + if (reader == null) instantiateMapper(); | |
| 95 | + return reader; | |
| 96 | + } | |
| 97 | + | |
| 98 | + private static ObjectWriter getObjectWriter() { | |
| 99 | + if (writer == null) instantiateMapper(); | |
| 100 | + return writer; | |
| 101 | + } | |
| 102 | +} |
Aschema-javadefault / src / main / java / io / quicktype / TopLevel.java+49 −0
| @@ -0,0 +1,49 @@ | ||
| 1 | +package io.quicktype; | |
| 2 | + | |
| 3 | +import java.io.IOException; | |
| 4 | +import java.io.IOException; | |
| 5 | +import com.fasterxml.jackson.core.*; | |
| 6 | +import com.fasterxml.jackson.databind.*; | |
| 7 | +import com.fasterxml.jackson.databind.annotation.*; | |
| 8 | +import com.fasterxml.jackson.core.type.*; | |
| 9 | + | |
| 10 | +@JsonDeserialize(using = TopLevel.Deserializer.class) | |
| 11 | +@JsonSerialize(using = TopLevel.Serializer.class) | |
| 12 | +public class TopLevel { | |
| 13 | + public String stringValue; | |
| 14 | + public Double doubleValue; | |
| 15 | + | |
| 16 | + static class Deserializer extends JsonDeserializer<TopLevel> { | |
| 17 | + @Override | |
| 18 | + public TopLevel deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { | |
| 19 | + TopLevel value = new TopLevel(); | |
| 20 | + switch (jsonParser.currentToken()) { | |
| 21 | + case VALUE_NUMBER_INT: | |
| 22 | + case VALUE_NUMBER_FLOAT: | |
| 23 | + value.doubleValue = jsonParser.readValueAs(Double.class); | |
| 24 | + break; | |
| 25 | + case VALUE_STRING: | |
| 26 | + String string = jsonParser.readValueAs(String.class); | |
| 27 | + value.stringValue = string; | |
| 28 | + break; | |
| 29 | + default: throw new IOException("Cannot deserialize TopLevel"); | |
| 30 | + } | |
| 31 | + return value; | |
| 32 | + } | |
| 33 | + } | |
| 34 | + | |
| 35 | + static class Serializer extends JsonSerializer<TopLevel> { | |
| 36 | + @Override | |
| 37 | + public void serialize(TopLevel obj, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { | |
| 38 | + if (obj.stringValue != null) { | |
| 39 | + jsonGenerator.writeObject(obj.stringValue); | |
| 40 | + return; | |
| 41 | + } | |
| 42 | + if (obj.doubleValue != null) { | |
| 43 | + jsonGenerator.writeObject(obj.doubleValue); | |
| 44 | + return; | |
| 45 | + } | |
| 46 | + throw new IOException("TopLevel must not be null"); | |
| 47 | + } | |
| 48 | + } | |
| 49 | +} |
Aschema-javascript-prop-typesdefault / toplevel.js+15 −0
| @@ -0,0 +1,15 @@ | ||
| 1 | +// Example usage: | |
| 2 | +// | |
| 3 | +// import { MyShape } from ./myShape.js; | |
| 4 | +// | |
| 5 | +// class MyComponent extends React.Component { | |
| 6 | +// // | |
| 7 | +// } | |
| 8 | +// | |
| 9 | +// MyComponent.propTypes = { | |
| 10 | +// input: MyShape | |
| 11 | +// }; | |
| 12 | + | |
| 13 | +import PropTypes from "prop-types"; | |
| 14 | + | |
| 15 | +export const TopLevel = PropTypes.oneOfType([PropTypes.objectOf(PropTypes.oneOfType([PropTypes.number, PropTypes.string]))]).isRequired; |
Aschema-javascriptdefault / TopLevel.js+203 −0
| @@ -0,0 +1,203 @@ | ||
| 1 | +// To parse this data: | |
| 2 | +// | |
| 3 | +// const Convert = require("./TopLevel"); | |
| 4 | +// | |
| 5 | +// const topLevel = Convert.toTopLevel(json); | |
| 6 | +// | |
| 7 | +// These functions will throw an error if the JSON doesn't | |
| 8 | +// match the expected interface, even if the JSON is valid. | |
| 9 | + | |
| 10 | +// Converts JSON strings to/from your types | |
| 11 | +// and asserts the results of JSON.parse at runtime | |
| 12 | +function toTopLevel(json) { | |
| 13 | + return cast(JSON.parse(json), r("TopLevel")); | |
| 14 | +} | |
| 15 | + | |
| 16 | +function topLevelToJson(value) { | |
| 17 | + return JSON.stringify(uncast(value, r("TopLevel")), null, 2); | |
| 18 | +} | |
| 19 | + | |
| 20 | +function invalidValue(typ, val, key, parent = '') { | |
| 21 | + const prettyTyp = prettyTypeName(typ); | |
| 22 | + const parentText = parent ? ` on ${parent}` : ''; | |
| 23 | + const keyText = key ? ` for key "${key}"` : ''; | |
| 24 | + throw Error(`Invalid value${keyText}${parentText}. Expected ${prettyTyp} but got ${JSON.stringify(val)}`); | |
| 25 | +} | |
| 26 | + | |
| 27 | +function prettyTypeName(typ) { | |
| 28 | + if (Array.isArray(typ)) { | |
| 29 | + if (typ.length === 2 && typ[0] === undefined) { | |
| 30 | + return `an optional ${prettyTypeName(typ[1])}`; | |
| 31 | + } else { | |
| 32 | + return `one of [${typ.map(a => { return prettyTypeName(a); }).join(", ")}]`; | |
| 33 | + } | |
| 34 | + } else if (typeof typ === "object" && typ.literal !== undefined) { | |
| 35 | + return typ.literal; | |
| 36 | + } else { | |
| 37 | + return typeof typ; | |
| 38 | + } | |
| 39 | +} | |
| 40 | + | |
| 41 | +function jsonToJSProps(typ) { | |
| 42 | + if (typ.jsonToJS === undefined) { | |
| 43 | + const map = {}; | |
| 44 | + typ.props.forEach((p) => map[p.json] = { key: p.js, typ: p.typ }); | |
| 45 | + typ.jsonToJS = map; | |
| 46 | + } | |
| 47 | + return typ.jsonToJS; | |
| 48 | +} | |
| 49 | + | |
| 50 | +function jsToJSONProps(typ) { | |
| 51 | + if (typ.jsToJSON === undefined) { | |
| 52 | + const map = {}; | |
| 53 | + typ.props.forEach((p) => map[p.js] = { key: p.json, typ: p.typ }); | |
| 54 | + typ.jsToJSON = map; | |
| 55 | + } | |
| 56 | + return typ.jsToJSON; | |
| 57 | +} | |
| 58 | + | |
| 59 | +function transform(val, typ, getProps, key = '', parent = '') { | |
| 60 | + function transformPrimitive(typ, val) { | |
| 61 | + if (typeof typ === typeof val) return val; | |
| 62 | + return invalidValue(typ, val, key, parent); | |
| 63 | + } | |
| 64 | + | |
| 65 | + function transformUnion(typs, val) { | |
| 66 | + // val must validate against one typ in typs | |
| 67 | + const l = typs.length; | |
| 68 | + for (let i = 0; i < l; i++) { | |
| 69 | + const typ = typs[i]; | |
| 70 | + try { | |
| 71 | + return transform(val, typ, getProps); | |
| 72 | + } catch (_) {} | |
| 73 | + } | |
| 74 | + return invalidValue(typs, val, key, parent); | |
| 75 | + } | |
| 76 | + | |
| 77 | + function transformEnum(cases, val) { | |
| 78 | + if (cases.indexOf(val) !== -1) return val; | |
| 79 | + return invalidValue(cases.map(a => { return l(a); }), val, key, parent); | |
| 80 | + } | |
| 81 | + | |
| 82 | + function transformArray(typ, val) { | |
| 83 | + // val must be an array with no invalid elements | |
| 84 | + if (!Array.isArray(val)) return invalidValue(l("array"), val, key, parent); | |
| 85 | + | |
| 86 | + return val.map(el => transform(el, typ, getProps)); | |
| 87 | + } | |
| 88 | + | |
| 89 | + function transformDate(val) { | |
| 90 | + if (val === null) { | |
| 91 | + return null; | |
| 92 | + } | |
| 93 | + const d = new Date(val); | |
| 94 | + if (isNaN(d.valueOf())) { | |
| 95 | + return invalidValue(l("Date"), val, key, parent); | |
| 96 | + } | |
| 97 | + return d; | |
| 98 | + } | |
| 99 | + | |
| 100 | + function transformObject(props, additional, val) { | |
| 101 | + if (val === null || typeof val !== "object" || Array.isArray(val)) { | |
| 102 | + return invalidValue(l(ref || "object"), val, key, parent); | |
| 103 | + } | |
| 104 | + const result = {}; | |
| 105 | + Object.getOwnPropertyNames(props).forEach(key => { | |
| 106 | + const prop = props[key]; | |
| 107 | + const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; | |
| 108 | + result[prop.key] = transform(v, prop.typ, getProps, key, ref); | |
| 109 | + }); | |
| 110 | + Object.getOwnPropertyNames(val).forEach(key => { | |
| 111 | + if (!Object.prototype.hasOwnProperty.call(props, key)) { | |
| 112 | + result[key] = transform(val[key], additional, getProps, key, ref); | |
| 113 | + } | |
| 114 | + }); | |
| 115 | + return result; | |
| 116 | + } | |
| 117 | + | |
| 118 | + if (typ === "any") return val; | |
| 119 | + if (typ === null) { | |
| 120 | + if (val === null) return val; | |
| 121 | + return invalidValue(typ, val, key, parent); | |
| 122 | + } | |
| 123 | + if (typ === false) return invalidValue(typ, val, key, parent); | |
| 124 | + let ref = undefined; | |
| 125 | + while (typeof typ === "object" && typ.ref !== undefined) { | |
| 126 | + ref = typ.ref; | |
| 127 | + typ = typeMap[typ.ref]; | |
| 128 | + } | |
| 129 | + if (Array.isArray(typ)) return transformEnum(typ, val); | |
| 130 | + if (typeof typ === "object") { | |
| 131 | + return typ.hasOwnProperty("pattern") ? typeof val === "string" && new RegExp(typ.pattern).test(val) ? val : invalidValue(typ, val, key, parent) | |
| 132 | + : typ.hasOwnProperty("string") ? typeof val === "string" && (typ.min === undefined || Array.from(val).length >= typ.min) && (typ.max === undefined || Array.from(val).length <= typ.max) ? transform(val, typ.string, getProps, key, parent) : invalidValue(typ, val, key, parent) | |
| 133 | + : typ.hasOwnProperty("number") ? typeof val === "number" && (typ.min === undefined || val >= typ.min) && (typ.max === undefined || val <= typ.max) ? transform(val, typ.number, getProps, key, parent) : invalidValue(typ, val, key, parent) | |
| 134 | + : typ.hasOwnProperty("integer") ? typeof val === "number" && val % 1 === 0 ? val : invalidValue(l("integer"), val, key, parent) | |
| 135 | + : typ.hasOwnProperty("unionMembers") ? transformUnion(typ.unionMembers, val) | |
| 136 | + : typ.hasOwnProperty("arrayItems") ? transformArray(typ.arrayItems, val) | |
| 137 | + : typ.hasOwnProperty("props") ? transformObject(getProps(typ), typ.additional, val) | |
| 138 | + : invalidValue(typ, val, key, parent); | |
| 139 | + } | |
| 140 | + // Numbers can be parsed by Date but shouldn't be. | |
| 141 | + if (typ === Date && (typeof val === "string" || val instanceof Date)) return transformDate(val); | |
| 142 | + return transformPrimitive(typ, val); | |
| 143 | +} | |
| 144 | + | |
| 145 | +function cast(val, typ) { | |
| 146 | + return transform(val, typ, jsonToJSProps); | |
| 147 | +} | |
| 148 | + | |
| 149 | +function uncast(val, typ) { | |
| 150 | + return transform(val, typ, jsToJSONProps); | |
| 151 | +} | |
| 152 | + | |
| 153 | +function l(typ) { | |
| 154 | + return { literal: typ }; | |
| 155 | +} | |
| 156 | + | |
| 157 | +function a(typ) { | |
| 158 | + return { arrayItems: typ }; | |
| 159 | +} | |
| 160 | + | |
| 161 | +function i(typ) { | |
| 162 | + return { integer: typ }; | |
| 163 | +} | |
| 164 | + | |
| 165 | +function p(pattern) { | |
| 166 | + return { pattern }; | |
| 167 | +} | |
| 168 | + | |
| 169 | +function s(typ, min, max) { | |
| 170 | + return { string: typ, min, max }; | |
| 171 | +} | |
| 172 | + | |
| 173 | +function n(typ, min, max) { | |
| 174 | + return { number: typ, min, max }; | |
| 175 | +} | |
| 176 | + | |
| 177 | +function u(...typs) { | |
| 178 | + return { unionMembers: typs }; | |
| 179 | +} | |
| 180 | + | |
| 181 | +function o(props, additional) { | |
| 182 | + return { props, additional }; | |
| 183 | +} | |
| 184 | + | |
| 185 | +function m(additional) { | |
| 186 | + const props = []; | |
| 187 | + return { props, additional }; | |
| 188 | +} | |
| 189 | + | |
| 190 | +function r(name) { | |
| 191 | + return { ref: name }; | |
| 192 | +} | |
| 193 | + | |
| 194 | +const typeMap = { | |
| 195 | + "TopLevel": o([ | |
| 196 | + { json: "id", js: "id", typ: u(undefined, "") }, | |
| 197 | + ], 3.14), | |
| 198 | +}; | |
| 199 | + | |
| 200 | +module.exports = { | |
| 201 | + "topLevelToJson": topLevelToJson, | |
| 202 | + "toTopLevel": toTopLevel, | |
| 203 | +}; |
Aschema-kotlin-jacksondefault / TopLevel.kt+57 −0
| @@ -0,0 +1,57 @@ | ||
| 1 | +// To parse the JSON, install jackson-module-kotlin and do: | |
| 2 | +// | |
| 3 | +// val topLevel = TopLevel.fromJson(jsonString) | |
| 4 | + | |
| 5 | +package quicktype | |
| 6 | + | |
| 7 | +import com.fasterxml.jackson.annotation.* | |
| 8 | +import com.fasterxml.jackson.core.* | |
| 9 | +import com.fasterxml.jackson.databind.* | |
| 10 | +import com.fasterxml.jackson.databind.deser.std.StdDeserializer | |
| 11 | +import com.fasterxml.jackson.databind.module.SimpleModule | |
| 12 | +import com.fasterxml.jackson.databind.node.* | |
| 13 | +import com.fasterxml.jackson.databind.ser.std.StdSerializer | |
| 14 | +import com.fasterxml.jackson.module.kotlin.* | |
| 15 | + | |
| 16 | + | |
| 17 | +@Suppress("UNCHECKED_CAST") | |
| 18 | +private fun <T> ObjectMapper.convert(k: kotlin.reflect.KClass<*>, fromJson: (JsonNode) -> T, toJson: (T) -> String, isUnion: Boolean = false) = registerModule(SimpleModule().apply { | |
| 19 | + addSerializer(k.java as Class<T>, object : StdSerializer<T>(k.java as Class<T>) { | |
| 20 | + override fun serialize(value: T, gen: JsonGenerator, provider: SerializerProvider) = gen.writeRawValue(toJson(value)) | |
| 21 | + }) | |
| 22 | + addDeserializer(k.java as Class<T>, object : StdDeserializer<T>(k.java as Class<T>) { | |
| 23 | + override fun deserialize(p: JsonParser, ctxt: DeserializationContext) = fromJson(p.readValueAsTree()) | |
| 24 | + }) | |
| 25 | +}) | |
| 26 | + | |
| 27 | +val mapper = jacksonObjectMapper().apply { | |
| 28 | + propertyNamingStrategy = object : PropertyNamingStrategy.PropertyNamingStrategyBase() { override fun translate(name: String) = if (name == "empty") "" else name } | |
| 29 | + setSerializationInclusion(JsonInclude.Include.NON_NULL) | |
| 30 | + convert(TopLevelValue::class, { TopLevelValue.fromJson(it) }, { it.toJson() }, true) | |
| 31 | +} | |
| 32 | + | |
| 33 | +class TopLevel(elements: Map<String, TopLevelValue>) : HashMap<String, TopLevelValue>(elements) { | |
| 34 | + fun toJson() = mapper.writeValueAsString(this) | |
| 35 | + | |
| 36 | + companion object { | |
| 37 | + fun fromJson(json: String) = mapper.readValue<TopLevel>(json) | |
| 38 | + } | |
| 39 | +} | |
| 40 | + | |
| 41 | +sealed class TopLevelValue { | |
| 42 | + class DoubleValue(val value: Double) : TopLevelValue() | |
| 43 | + class StringValue(val value: String) : TopLevelValue() | |
| 44 | + | |
| 45 | + fun toJson(): String = mapper.writeValueAsString(when (this) { | |
| 46 | + is DoubleValue -> this.value | |
| 47 | + is StringValue -> this.value | |
| 48 | + }) | |
| 49 | + | |
| 50 | + companion object { | |
| 51 | + fun fromJson(jn: JsonNode): TopLevelValue = when (jn) { | |
| 52 | + is IntNode, is LongNode, is DoubleNode -> DoubleValue(mapper.convertValue(jn)) | |
| 53 | + is TextNode -> StringValue(mapper.convertValue(jn)) | |
| 54 | + else -> throw IllegalArgumentException() | |
| 55 | + } | |
| 56 | + } | |
| 57 | +} |
Aschema-kotlinxdefault / TopLevel.kt+15 −0
| @@ -0,0 +1,15 @@ | ||
| 1 | +// To parse the JSON, install kotlin's serialization plugin and do: | |
| 2 | +// | |
| 3 | +// val json = Json { allowStructuredMapKeys = true } | |
| 4 | +// val topLevel = json.parse(TopLevel.serializer(), jsonString) | |
| 5 | + | |
| 6 | +package quicktype | |
| 7 | + | |
| 8 | +import kotlinx.serialization.* | |
| 9 | +import kotlinx.serialization.json.* | |
| 10 | +import kotlinx.serialization.descriptors.* | |
| 11 | +import kotlinx.serialization.encoding.* | |
| 12 | + | |
| 13 | +typealias TopLevel = HashMap<String, JsonElement> | |
| 14 | + | |
| 15 | +typealias TopLevelValue = JsonElement |
Aschema-objective-cdefault / QTTopLevel.h+21 −0
| @@ -0,0 +1,21 @@ | ||
| 1 | +// To parse this JSON: | |
| 2 | +// | |
| 3 | +// NSError *error; | |
| 4 | +// QTTopLevel *topLevel = QTTopLevelFromJSON(json, NSUTF8Encoding, &error); | |
| 5 | + | |
| 6 | +#import <Foundation/Foundation.h> | |
| 7 | + | |
| 8 | +NS_ASSUME_NONNULL_BEGIN | |
| 9 | + | |
| 10 | +typedef NSDictionary<NSString *, id> QTTopLevel; | |
| 11 | + | |
| 12 | +#pragma mark - Top-level marshaling functions | |
| 13 | + | |
| 14 | +QTTopLevel *_Nullable QTTopLevelFromData(NSData *data, NSError **error); | |
| 15 | +QTTopLevel *_Nullable QTTopLevelFromJSON(NSString *json, NSStringEncoding encoding, NSError **error); | |
| 16 | +NSData *_Nullable QTTopLevelToData(QTTopLevel *topLevel, NSError **error); | |
| 17 | +NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding encoding, NSError **error); | |
| 18 | + | |
| 19 | +#pragma mark - Object interfaces | |
| 20 | + | |
| 21 | +NS_ASSUME_NONNULL_END |
Aschema-objective-cdefault / QTTopLevel.m+60 −0
| @@ -0,0 +1,60 @@ | ||
| 1 | +#import "QTTopLevel.h" | |
| 2 | + | |
| 3 | +#define λ(decl, expr) (^(decl) { return (expr); }) | |
| 4 | + | |
| 5 | +static id NSNullify(id _Nullable x) { | |
| 6 | + return (x == nil || x == NSNull.null) ? NSNull.null : x; | |
| 7 | +} | |
| 8 | + | |
| 9 | +NS_ASSUME_NONNULL_BEGIN | |
| 10 | + | |
| 11 | +static id map(id collection, id (^f)(id value)) { | |
| 12 | + id result = nil; | |
| 13 | + if ([collection isKindOfClass:NSArray.class]) { | |
| 14 | + result = [NSMutableArray arrayWithCapacity:[(NSArray *)collection count]]; | |
| 15 | + for (id x in collection) [result addObject:NSNullify(f(x))]; | |
| 16 | + } else if ([collection isKindOfClass:NSDictionary.class]) { | |
| 17 | + result = [NSMutableDictionary dictionaryWithCapacity:[(NSDictionary *)collection count]]; | |
| 18 | + for (id key in collection) [result setObject:f([collection objectForKey:key]) forKey:key]; | |
| 19 | + } | |
| 20 | + return result; | |
| 21 | +} | |
| 22 | + | |
| 23 | +#pragma mark - JSON serialization | |
| 24 | + | |
| 25 | +QTTopLevel *_Nullable QTTopLevelFromData(NSData *data, NSError **error) | |
| 26 | +{ | |
| 27 | + @try { | |
| 28 | + id json = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:error]; | |
| 29 | + if (![json isKindOfClass:NSDictionary.class]) [NSException raise:@"Invalid JSON" format:@"Expected NSDictionary."]; | |
| 30 | + return *error ? nil : map(json, λ(id x, x)); | |
| 31 | + } @catch (NSException *exception) { | |
| 32 | + *error = [NSError errorWithDomain:@"JSONSerialization" code:-1 userInfo:@{ @"exception": exception }]; | |
| 33 | + return nil; | |
| 34 | + } | |
| 35 | +} | |
| 36 | + | |
| 37 | +QTTopLevel *_Nullable QTTopLevelFromJSON(NSString *json, NSStringEncoding encoding, NSError **error) | |
| 38 | +{ | |
| 39 | + return QTTopLevelFromData([json dataUsingEncoding:encoding], error); | |
| 40 | +} | |
| 41 | + | |
| 42 | +NSData *_Nullable QTTopLevelToData(QTTopLevel *topLevel, NSError **error) | |
| 43 | +{ | |
| 44 | + @try { | |
| 45 | + id json = topLevel; | |
| 46 | + NSData *data = [NSJSONSerialization dataWithJSONObject:json options:NSJSONWritingFragmentsAllowed error:error]; | |
| 47 | + return *error ? nil : data; | |
| 48 | + } @catch (NSException *exception) { | |
| 49 | + *error = [NSError errorWithDomain:@"JSONSerialization" code:-1 userInfo:@{ @"exception": exception }]; | |
| 50 | + return nil; | |
| 51 | + } | |
| 52 | +} | |
| 53 | + | |
| 54 | +NSString *_Nullable QTTopLevelToJSON(QTTopLevel *topLevel, NSStringEncoding encoding, NSError **error) | |
| 55 | +{ | |
| 56 | + NSData *data = QTTopLevelToData(topLevel, error); | |
| 57 | + return data ? [[NSString alloc] initWithData:data encoding:encoding] : nil; | |
| 58 | +} | |
| 59 | + | |
| 60 | +NS_ASSUME_NONNULL_END |
Aschema-pikedefault / TopLevel.pmod+29 −0
| @@ -0,0 +1,29 @@ | ||
| 1 | +// This source has been automatically generated by quicktype. | |
| 2 | +// ( https://github.com/quicktype/quicktype ) | |
| 3 | +// | |
| 4 | +// To use this code, simply import it into your project as a Pike module. | |
| 5 | +// To JSON-encode your object, you can pass it to `Standards.JSON.encode` | |
| 6 | +// or call `encode_json` on it. | |
| 7 | +// | |
| 8 | +// To decode a JSON string, first pass it to `Standards.JSON.decode`, | |
| 9 | +// and then pass the result to `<YourClass>_from_JSON`. | |
| 10 | +// It will return an instance of <YourClass>. | |
| 11 | +// Bear in mind that these functions have unexpected behavior, | |
| 12 | +// and will likely throw an error, if the JSON string does not | |
| 13 | +// match the expected interface, even if the JSON itself is valid. | |
| 14 | + | |
| 15 | +typedef mapping(string:TopLevelValue) TopLevel; | |
| 16 | + | |
| 17 | +TopLevel TopLevel_from_JSON(mixed json) { | |
| 18 | + mapping(string:TopLevelValue) retval = ([]); | |
| 19 | + foreach (json; string k; mixed v) { | |
| 20 | + retval[k] = TopLevelValue_from_JSON(v); | |
| 21 | + } | |
| 22 | + return retval; | |
| 23 | +} | |
| 24 | + | |
| 25 | +typedef float|string TopLevelValue; | |
| 26 | + | |
| 27 | +TopLevelValue TopLevelValue_from_JSON(mixed json) { | |
| 28 | + return json; | |
| 29 | +} |
Aschema-pythondefault / quicktype.py+41 −0
| @@ -0,0 +1,41 @@ | ||
| 1 | +from typing import Any, TypeVar, Callable | |
| 2 | + | |
| 3 | + | |
| 4 | +T = TypeVar("T") | |
| 5 | + | |
| 6 | + | |
| 7 | +def from_dict(f: Callable[[Any], T], x: Any) -> dict[str, T]: | |
| 8 | + assert isinstance(x, dict) | |
| 9 | + return { k: f(v) for (k, v) in x.items() } | |
| 10 | + | |
| 11 | + | |
| 12 | +def from_str(x: Any) -> str: | |
| 13 | + assert isinstance(x, str) | |
| 14 | + return x | |
| 15 | + | |
| 16 | + | |
| 17 | +def from_float(x: Any) -> float: | |
| 18 | + assert isinstance(x, (float, int)) and not isinstance(x, bool) | |
| 19 | + return float(x) | |
| 20 | + | |
| 21 | + | |
| 22 | +def from_union(fs, x): | |
| 23 | + for f in fs: | |
| 24 | + try: | |
| 25 | + return f(x) | |
| 26 | + except: | |
| 27 | + pass | |
| 28 | + assert False | |
| 29 | + | |
| 30 | + | |
| 31 | +def to_float(x: Any) -> float: | |
| 32 | + assert isinstance(x, (int, float)) | |
| 33 | + return x | |
| 34 | + | |
| 35 | + | |
| 36 | +def top_level_from_dict(s: Any) -> dict[str, str | float]: | |
| 37 | + return from_dict(lambda x: from_union([from_str, from_float], x), s) | |
| 38 | + | |
| 39 | + | |
| 40 | +def top_level_to_dict(x: dict[str, str | float]) -> Any: | |
| 41 | + return from_dict(lambda x: from_union([from_str, to_float], x), x) |
Aschema-rubydefault / TopLevel.rb+58 −0
| @@ -0,0 +1,58 @@ | ||
| 1 | +# This code may look unusually verbose for Ruby (and it is), but | |
| 2 | +# it performs some subtle and complex validation of JSON data. | |
| 3 | +# | |
| 4 | +# To parse this JSON, add 'dry-struct' and 'dry-types' gems, then do: | |
| 5 | +# | |
| 6 | +# top_level = TopLevel.from_json! "{…}" | |
| 7 | +# puts top_level["…"] | |
| 8 | +# | |
| 9 | +# If from_json! succeeds, the value returned matches the schema. | |
| 10 | + | |
| 11 | +require 'json' | |
| 12 | +require 'dry-types' | |
| 13 | +require 'dry-struct' | |
| 14 | + | |
| 15 | +module Types | |
| 16 | + include Dry.Types(default: :nominal) | |
| 17 | + | |
| 18 | + Hash = Strict::Hash | |
| 19 | + String = Strict::String | |
| 20 | + Double = Strict::Float | Strict::Integer | |
| 21 | +end | |
| 22 | + | |
| 23 | +class TopLevelValue < Dry::Struct | |
| 24 | + attribute :double, Types::Double.optional | |
| 25 | + attribute :string, Types::String.optional | |
| 26 | + | |
| 27 | + def self.from_dynamic!(d) | |
| 28 | + if schema.key(:double).type.right.valid? d | |
| 29 | + return new(double: d, string: nil) | |
| 30 | + end | |
| 31 | + if schema.key(:string).type.right.valid? d | |
| 32 | + return new(string: d, double: nil) | |
| 33 | + end | |
| 34 | + raise "Invalid union" | |
| 35 | + end | |
| 36 | + | |
| 37 | + def self.from_json!(json) | |
| 38 | + from_dynamic!(JSON.parse(json)) | |
| 39 | + end | |
| 40 | + | |
| 41 | + def to_dynamic | |
| 42 | + if double != nil | |
| 43 | + double | |
| 44 | + elsif string != nil | |
| 45 | + string | |
| 46 | + end | |
| 47 | + end | |
| 48 | + | |
| 49 | + def to_json(options = nil) | |
| 50 | + JSON.generate(to_dynamic, options) | |
| 51 | + end | |
| 52 | +end | |
| 53 | + | |
| 54 | +class TopLevel | |
| 55 | + def self.from_json!(json) | |
| 56 | + Types::Hash[JSON.parse(json, quirks_mode: true)].map { |k, v| [k, TopLevelValue.from_dynamic!(v)] }.to_h | |
| 57 | + end | |
| 58 | +end |
Aschema-rustdefault / module_under_test.rs+25 −0
| @@ -0,0 +1,25 @@ | ||
| 1 | +// Example code that deserializes and serializes the model. | |
| 2 | +// extern crate serde; | |
| 3 | +// #[macro_use] | |
| 4 | +// extern crate serde_derive; | |
| 5 | +// extern crate serde_json; | |
| 6 | +// | |
| 7 | +// use generated_module::TopLevel; | |
| 8 | +// | |
| 9 | +// fn main() { | |
| 10 | +// let json = r#"{"answer": 42}"#; | |
| 11 | +// let model: TopLevel = serde_json::from_str(&json).unwrap(); | |
| 12 | +// } | |
| 13 | + | |
| 14 | +use serde::{Serialize, Deserialize}; | |
| 15 | +use std::collections::HashMap; | |
| 16 | + | |
| 17 | +pub type TopLevel = HashMap<String, TopLevelValue>; | |
| 18 | + | |
| 19 | +#[derive(Debug, Clone, Serialize, Deserialize)] | |
| 20 | +#[serde(untagged)] | |
| 21 | +pub enum TopLevelValue { | |
| 22 | + Double(f64), | |
| 23 | + | |
| 24 | + PurpleString(String), | |
| 25 | +} |
Aschema-scala3-upickledefault / TopLevel.scala+93 −0
| @@ -0,0 +1,93 @@ | ||
| 1 | +package quicktype | |
| 2 | + | |
| 3 | +// Custom pickler so that missing keys and JSON nulls both read as None, | |
| 4 | +// and None is left out when writing (upickle's default for Option is a | |
| 5 | +// JSON array). | |
| 6 | +object OptionPickler extends upickle.AttributeTagged: | |
| 7 | + import upickle.default.Writer | |
| 8 | + import upickle.default.Reader | |
| 9 | + override implicit def OptionWriter[T: Writer]: Writer[Option[T]] = | |
| 10 | + implicitly[Writer[T]].comap[Option[T]] { | |
| 11 | + case None => null.asInstanceOf[T] | |
| 12 | + case Some(x) => x | |
| 13 | + } | |
| 14 | + | |
| 15 | + override implicit def OptionReader[T: Reader]: Reader[Option[T]] = { | |
| 16 | + new Reader.Delegate[Any, Option[T]](implicitly[Reader[T]].map(Some(_))){ | |
| 17 | + override def visitNull(index: Int) = None | |
| 18 | + } | |
| 19 | + } | |
| 20 | +end OptionPickler | |
| 21 | + | |
| 22 | +// If a union has a null in, then we'll need this too... | |
| 23 | +type NullValue = None.type | |
| 24 | +given OptionPickler.ReadWriter[NullValue] = OptionPickler.readwriter[ujson.Value].bimap[NullValue]( | |
| 25 | + _ => ujson.Null, | |
| 26 | + json => if json.isNull then None else throw new upickle.core.Abort("not null") | |
| 27 | +) | |
| 28 | +given OptionPickler.ReadWriter[java.time.Instant] = OptionPickler.readwriter[ujson.Value].bimap( | |
| 29 | + value => ujson.Str(value.toString), | |
| 30 | + json => json match | |
| 31 | + case ujson.Str(value) => java.time.Instant.parse(value) | |
| 32 | + case other => throw new upickle.core.Abort("expected date-time, got " + other) | |
| 33 | +) | |
| 34 | +given OptionPickler.ReadWriter[java.util.UUID] = OptionPickler.readwriter[String].bimap( | |
| 35 | + _.toString, | |
| 36 | + value => | |
| 37 | + val uuid = java.util.UUID.fromString(value) | |
| 38 | + if uuid.toString.equalsIgnoreCase(value) then uuid else throw new upickle.core.Abort("invalid UUID") | |
| 39 | +) | |
| 40 | + | |
| 41 | +object JsonExt: | |
| 42 | + val valueReader = OptionPickler.readwriter[ujson.Value] | |
| 43 | + | |
| 44 | + // upickle's built-in primitive readers are lenient -- the numeric and | |
| 45 | + // boolean readers accept strings, and the string reader accepts | |
| 46 | + // numbers and booleans -- so untagged unions need strict readers to | |
| 47 | + // pick the right member. | |
| 48 | + val strictString: OptionPickler.Reader[String] = valueReader.map { | |
| 49 | + case ujson.Str(s) => s | |
| 50 | + case json => throw new upickle.core.Abort("expected string, got " + json) | |
| 51 | + } | |
| 52 | + val strictLong: OptionPickler.Reader[Long] = valueReader.map { | |
| 53 | + case ujson.Num(n) if n.isWhole => n.toLong | |
| 54 | + case json => throw new upickle.core.Abort("expected integer, got " + json) | |
| 55 | + } | |
| 56 | + val strictDouble: OptionPickler.Reader[Double] = valueReader.map { | |
| 57 | + case ujson.Num(n) => n | |
| 58 | + case json => throw new upickle.core.Abort("expected number, got " + json) | |
| 59 | + } | |
| 60 | + val strictBoolean: OptionPickler.Reader[Boolean] = valueReader.map { | |
| 61 | + case ujson.Bool(b) => b | |
| 62 | + case json => throw new upickle.core.Abort("expected boolean, got " + json) | |
| 63 | + } | |
| 64 | + | |
| 65 | + def badMerge[T](r1: => OptionPickler.Reader[?], rest: OptionPickler.Reader[?]*): OptionPickler.Reader[T] = valueReader.map { json => | |
| 66 | + var t: T | Null = null | |
| 67 | + val stack = Vector.newBuilder[Throwable] | |
| 68 | + (r1 +: rest).foreach { reader => | |
| 69 | + if t == null then | |
| 70 | + try | |
| 71 | + t = OptionPickler.read[T](json, trace = true)(using reader.asInstanceOf[OptionPickler.Reader[T]]) | |
| 72 | + catch | |
| 73 | + case exc => stack += exc | |
| 74 | + } | |
| 75 | + if t != null then t.nn else throw new Exception(json.toString(), stack.result().headOption.getOrElse(null)) | |
| 76 | + } | |
| 77 | +end JsonExt | |
| 78 | +given OptionPickler.Reader[Long] = JsonExt.strictLong | |
| 79 | + | |
| 80 | + | |
| 81 | +type TopLevel = Map[String, TopLevelValue] | |
| 82 | + | |
| 83 | +type TopLevelValue = Double | String | |
| 84 | +given unionReaderTopLevelValue: OptionPickler.Reader[TopLevelValue] = JsonExt.badMerge[TopLevelValue]( | |
| 85 | + JsonExt.strictString, | |
| 86 | + JsonExt.strictDouble, | |
| 87 | + ) | |
| 88 | + | |
| 89 | +given unionWriterTopLevelValue: OptionPickler.Writer[TopLevelValue] = OptionPickler.writer[ujson.Value].comap[TopLevelValue]{ _v => | |
| 90 | + (_v: @unchecked) match | |
| 91 | + case v: String => OptionPickler.writeJs[String](v) | |
| 92 | + case v: Double => OptionPickler.writeJs[Double](v) | |
| 93 | +} |
Aschema-scala3default / TopLevel.scala+25 −0
| @@ -0,0 +1,25 @@ | ||
| 1 | +package quicktype | |
| 2 | + | |
| 3 | +import io.circe.syntax._ | |
| 4 | +import io.circe._ | |
| 5 | +import cats.syntax.functor._ | |
| 6 | + | |
| 7 | +// If a union has a null in, then we'll need this too... | |
| 8 | +type NullValue = None.type | |
| 9 | + | |
| 10 | +type TopLevel = Map[String, TopLevelValue] | |
| 11 | + | |
| 12 | +given (using ev : TopLevelValue): Encoder[Map[String, TopLevelValue]] = Encoder.encodeMap[String, TopLevelValue] | |
| 13 | + | |
| 14 | +type TopLevelValue = Double | String | |
| 15 | +given Decoder[TopLevelValue] = { | |
| 16 | + List[Decoder[TopLevelValue]]( | |
| 17 | + Decoder[String].widen, | |
| 18 | + Decoder[Double].widen, | |
| 19 | + ).reduceLeft(_ or _) | |
| 20 | +} | |
| 21 | + | |
| 22 | +given Encoder[TopLevelValue] = Encoder.instance { | |
| 23 | + case enc0 : String => Encoder.encodeString(enc0) | |
| 24 | + case enc1 : Double => Encoder.encodeDouble(enc1) | |
| 25 | +} |
Aschema-schemadefault / TopLevel.schema+19 −0
| @@ -0,0 +1,19 @@ | ||
| 1 | +{ | |
| 2 | + "$schema": "http://json-schema.org/draft-06/schema#", | |
| 3 | + "$ref": "#/definitions/TopLevel", | |
| 4 | + "definitions": { | |
| 5 | + "TopLevel": { | |
| 6 | + "type": "object", | |
| 7 | + "additionalProperties": { | |
| 8 | + "type": "number" | |
| 9 | + }, | |
| 10 | + "properties": { | |
| 11 | + "id": { | |
| 12 | + "type": "string" | |
| 13 | + } | |
| 14 | + }, | |
| 15 | + "required": [], | |
| 16 | + "title": "TopLevel" | |
| 17 | + } | |
| 18 | + } | |
| 19 | +} |
Aschema-swiftdefault / quicktype.swift+97 −0
| @@ -0,0 +1,97 @@ | ||
| 1 | +// This file was generated from JSON Schema using quicktype, do not modify it directly. | |
| 2 | +// To parse the JSON, add this file to your project and do: | |
| 3 | +// | |
| 4 | +// let topLevel = try TopLevel(json) | |
| 5 | + | |
| 6 | +import Foundation | |
| 7 | + | |
| 8 | +enum TopLevelValue: Codable { | |
| 9 | + case double(Double) | |
| 10 | + case string(String) | |
| 11 | + | |
| 12 | + init(from decoder: Decoder) throws { | |
| 13 | + let container = try decoder.singleValueContainer() | |
| 14 | + if let x = try? container.decode(Double.self) { | |
| 15 | + self = .double(x) | |
| 16 | + return | |
| 17 | + } | |
| 18 | + if let x = try? container.decode(String.self) { | |
| 19 | + self = .string(x) | |
| 20 | + return | |
| 21 | + } | |
| 22 | + throw DecodingError.typeMismatch(TopLevelValue.self, DecodingError.Context(codingPath: decoder.codingPath, debugDescription: "Wrong type for TopLevelValue")) | |
| 23 | + } | |
| 24 | + | |
| 25 | + func encode(to encoder: Encoder) throws { | |
| 26 | + var container = encoder.singleValueContainer() | |
| 27 | + switch self { | |
| 28 | + case .double(let x): | |
| 29 | + try container.encode(x) | |
| 30 | + case .string(let x): | |
| 31 | + try container.encode(x) | |
| 32 | + } | |
| 33 | + } | |
| 34 | +} | |
| 35 | + | |
| 36 | +typealias TopLevel = [String: TopLevelValue] | |
| 37 | + | |
| 38 | +extension Dictionary where Key == String, Value == TopLevelValue { | |
| 39 | + init(data: Data) throws { | |
| 40 | + self = try newJSONDecoder().decode(TopLevel.self, from: data) | |
| 41 | + } | |
| 42 | + | |
| 43 | + init(_ json: String, using encoding: String.Encoding = .utf8) throws { | |
| 44 | + guard let data = json.data(using: encoding) else { | |
| 45 | + throw NSError(domain: "JSONDecoding", code: 0, userInfo: nil) | |
| 46 | + } | |
| 47 | + try self.init(data: data) | |
| 48 | + } | |
| 49 | + | |
| 50 | + init(fromURL url: URL) throws { | |
| 51 | + try self.init(data: try Data(contentsOf: url)) | |
| 52 | + } | |
| 53 | + | |
| 54 | + func jsonData() throws -> Data { | |
| 55 | + return try newJSONEncoder().encode(self) | |
| 56 | + } | |
| 57 | + | |
| 58 | + func jsonString(encoding: String.Encoding = .utf8) throws -> String? { | |
| 59 | + return String(data: try self.jsonData(), encoding: encoding) | |
| 60 | + } | |
| 61 | +} | |
| 62 | + | |
| 63 | +// MARK: - Helper functions for creating encoders and decoders | |
| 64 | + | |
| 65 | +func newJSONDecoder() -> JSONDecoder { | |
| 66 | + let decoder = JSONDecoder() | |
| 67 | + decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in | |
| 68 | + let container = try decoder.singleValueContainer() | |
| 69 | + let dateStr = try container.decode(String.self) | |
| 70 | + | |
| 71 | + let formatter = DateFormatter() | |
| 72 | + formatter.calendar = Calendar(identifier: .iso8601) | |
| 73 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 74 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 75 | + formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSXXXXX" | |
| 76 | + if let date = formatter.date(from: dateStr) { | |
| 77 | + return date | |
| 78 | + } | |
| 79 | + formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssXXXXX" | |
| 80 | + if let date = formatter.date(from: dateStr) { | |
| 81 | + return date | |
| 82 | + } | |
| 83 | + throw DecodingError.typeMismatch(Date.self, DecodingError.Context(codingPath: decoder.codingPath, debugDescription: "Could not decode date")) | |
| 84 | + }) | |
| 85 | + return decoder | |
| 86 | +} | |
| 87 | + | |
| 88 | +func newJSONEncoder() -> JSONEncoder { | |
| 89 | + let encoder = JSONEncoder() | |
| 90 | + let formatter = DateFormatter() | |
| 91 | + formatter.calendar = Calendar(identifier: .iso8601) | |
| 92 | + formatter.locale = Locale(identifier: "en_US_POSIX") | |
| 93 | + formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
| 94 | + formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSSSSXXXXX" | |
| 95 | + encoder.dateEncodingStrategy = .formatted(formatter) | |
| 96 | + return encoder | |
| 97 | +} |
Aschema-typescript-effect-schemadefault / TopLevel.ts+4 −0
| @@ -0,0 +1,4 @@ | ||
| 1 | +import * as S from "effect/Schema"; | |
| 2 | + | |
| 3 | +export const TopLevel = S.Record({ key: S.String, value: S.Union(S.Number, S.String)}); | |
| 4 | +export type TopLevel = S.Schema.Type<typeof TopLevel>; |
Aschema-typescript-zoddefault / TopLevel.ts+4 −0
| @@ -0,0 +1,4 @@ | ||
| 1 | +import * as z from "zod"; | |
| 2 | + | |
| 3 | +export const TopLevelSchema = z.record(z.string(), z.union([z.number(), z.string()])); | |
| 4 | +export type TopLevel = z.infer<typeof TopLevelSchema>; |
Aschema-typescriptdefault / TopLevel.ts+205 −0
| @@ -0,0 +1,205 @@ | ||
| 1 | +// To parse this data: | |
| 2 | +// | |
| 3 | +// import { Convert, TopLevel } from "./TopLevel"; | |
| 4 | +// | |
| 5 | +// const topLevel = Convert.toTopLevel(json); | |
| 6 | +// | |
| 7 | +// These functions will throw an error if the JSON doesn't | |
| 8 | +// match the expected interface, even if the JSON is valid. | |
| 9 | + | |
| 10 | +export interface TopLevel { | |
| 11 | + id?: string; | |
| 12 | + [property: string]: number | string | undefined; | |
| 13 | +} | |
| 14 | + | |
| 15 | +// Converts JSON strings to/from your types | |
| 16 | +// and asserts the results of JSON.parse at runtime | |
| 17 | +export class Convert { | |
| 18 | + public static toTopLevel(json: string): TopLevel { | |
| 19 | + return cast(JSON.parse(json), r("TopLevel")); | |
| 20 | + } | |
| 21 | + | |
| 22 | + public static topLevelToJson(value: TopLevel): string { | |
| 23 | + return JSON.stringify(uncast(value, r("TopLevel")), null, 2); | |
| 24 | + } | |
| 25 | +} | |
| 26 | + | |
| 27 | +function invalidValue(typ: any, val: any, key: any, parent: any = ''): never { | |
| 28 | + const prettyTyp = prettyTypeName(typ); | |
| 29 | + const parentText = parent ? ` on ${parent}` : ''; | |
| 30 | + const keyText = key ? ` for key "${key}"` : ''; | |
| 31 | + throw Error(`Invalid value${keyText}${parentText}. Expected ${prettyTyp} but got ${JSON.stringify(val)}`); | |
| 32 | +} | |
| 33 | + | |
| 34 | +function prettyTypeName(typ: any): string { | |
| 35 | + if (Array.isArray(typ)) { | |
| 36 | + if (typ.length === 2 && typ[0] === undefined) { | |
| 37 | + return `an optional ${prettyTypeName(typ[1])}`; | |
| 38 | + } else { | |
| 39 | + return `one of [${typ.map(a => { return prettyTypeName(a); }).join(", ")}]`; | |
| 40 | + } | |
| 41 | + } else if (typeof typ === "object" && typ.literal !== undefined) { | |
| 42 | + return typ.literal; | |
| 43 | + } else { | |
| 44 | + return typeof typ; | |
| 45 | + } | |
| 46 | +} | |
| 47 | + | |
| 48 | +function jsonToJSProps(typ: any): any { | |
| 49 | + if (typ.jsonToJS === undefined) { | |
| 50 | + const map: any = {}; | |
| 51 | + typ.props.forEach((p: any) => map[p.json] = { key: p.js, typ: p.typ }); | |
| 52 | + typ.jsonToJS = map; | |
| 53 | + } | |
| 54 | + return typ.jsonToJS; | |
| 55 | +} | |
| 56 | + | |
| 57 | +function jsToJSONProps(typ: any): any { | |
| 58 | + if (typ.jsToJSON === undefined) { | |
| 59 | + const map: any = {}; | |
| 60 | + typ.props.forEach((p: any) => map[p.js] = { key: p.json, typ: p.typ }); | |
| 61 | + typ.jsToJSON = map; | |
| 62 | + } | |
| 63 | + return typ.jsToJSON; | |
| 64 | +} | |
| 65 | + | |
| 66 | +function transform(val: any, typ: any, getProps: any, key: any = '', parent: any = ''): any { | |
| 67 | + function transformPrimitive(typ: string, val: any): any { | |
| 68 | + if (typeof typ === typeof val) return val; | |
| 69 | + return invalidValue(typ, val, key, parent); | |
| 70 | + } | |
| 71 | + | |
| 72 | + function transformUnion(typs: any[], val: any): any { | |
| 73 | + // val must validate against one typ in typs | |
| 74 | + const l = typs.length; | |
| 75 | + for (let i = 0; i < l; i++) { | |
| 76 | + const typ = typs[i]; | |
| 77 | + try { | |
| 78 | + return transform(val, typ, getProps); | |
| 79 | + } catch (_) {} | |
| 80 | + } | |
| 81 | + return invalidValue(typs, val, key, parent); | |
| 82 | + } | |
| 83 | + | |
| 84 | + function transformEnum(cases: string[], val: any): any { | |
| 85 | + if (cases.indexOf(val) !== -1) return val; | |
| 86 | + return invalidValue(cases.map(a => { return l(a); }), val, key, parent); | |
| 87 | + } | |
| 88 | + | |
| 89 | + function transformArray(typ: any, val: any): any { | |
| 90 | + // val must be an array with no invalid elements | |
| 91 | + if (!Array.isArray(val)) return invalidValue(l("array"), val, key, parent); | |
| 92 | + | |
| 93 | + return val.map(el => transform(el, typ, getProps)); | |
| 94 | + } | |
| 95 | + | |
| 96 | + function transformDate(val: any): any { | |
| 97 | + if (val === null) { | |
| 98 | + return null; | |
| 99 | + } | |
| 100 | + const d = new Date(val); | |
| 101 | + if (isNaN(d.valueOf())) { | |
| 102 | + return invalidValue(l("Date"), val, key, parent); | |
| 103 | + } | |
| 104 | + return d; | |
| 105 | + } | |
| 106 | + | |
| 107 | + function transformObject(props: { [k: string]: any }, additional: any, val: any): any { | |
| 108 | + if (val === null || typeof val !== "object" || Array.isArray(val)) { | |
| 109 | + return invalidValue(l(ref || "object"), val, key, parent); | |
| 110 | + } | |
| 111 | + const result: any = {}; | |
| 112 | + Object.getOwnPropertyNames(props).forEach(key => { | |
| 113 | + const prop = props[key]; | |
| 114 | + const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; | |
| 115 | + result[prop.key] = transform(v, prop.typ, getProps, key, ref); | |
| 116 | + }); | |
| 117 | + Object.getOwnPropertyNames(val).forEach(key => { | |
| 118 | + if (!Object.prototype.hasOwnProperty.call(props, key)) { | |
| 119 | + result[key] = transform(val[key], additional, getProps, key, ref); | |
| 120 | + } | |
| 121 | + }); | |
| 122 | + return result; | |
| 123 | + } | |
| 124 | + | |
| 125 | + if (typ === "any") return val; | |
| 126 | + if (typ === null) { | |
| 127 | + if (val === null) return val; | |
| 128 | + return invalidValue(typ, val, key, parent); | |
| 129 | + } | |
| 130 | + if (typ === false) return invalidValue(typ, val, key, parent); | |
| 131 | + let ref: any = undefined; | |
| 132 | + while (typeof typ === "object" && typ.ref !== undefined) { | |
| 133 | + ref = typ.ref; | |
| 134 | + typ = typeMap[typ.ref]; | |
| 135 | + } | |
| 136 | + if (Array.isArray(typ)) return transformEnum(typ, val); | |
| 137 | + if (typeof typ === "object") { | |
| 138 | + return typ.hasOwnProperty("pattern") ? typeof val === "string" && new RegExp(typ.pattern).test(val) ? val : invalidValue(typ, val, key, parent) | |
| 139 | + : typ.hasOwnProperty("string") ? typeof val === "string" && (typ.min === undefined || Array.from(val).length >= typ.min) && (typ.max === undefined || Array.from(val).length <= typ.max) ? transform(val, typ.string, getProps, key, parent) : invalidValue(typ, val, key, parent) | |
| 140 | + : typ.hasOwnProperty("number") ? typeof val === "number" && (typ.min === undefined || val >= typ.min) && (typ.max === undefined || val <= typ.max) ? transform(val, typ.number, getProps, key, parent) : invalidValue(typ, val, key, parent) | |
| 141 | + : typ.hasOwnProperty("integer") ? typeof val === "number" && val % 1 === 0 ? val : invalidValue(l("integer"), val, key, parent) | |
| 142 | + : typ.hasOwnProperty("unionMembers") ? transformUnion(typ.unionMembers, val) | |
| 143 | + : typ.hasOwnProperty("arrayItems") ? transformArray(typ.arrayItems, val) | |
| 144 | + : typ.hasOwnProperty("props") ? transformObject(getProps(typ), typ.additional, val) | |
| 145 | + : invalidValue(typ, val, key, parent); | |
| 146 | + } | |
| 147 | + // Numbers can be parsed by Date but shouldn't be. | |
| 148 | + if (typ === Date && (typeof val === "string" || val instanceof Date)) return transformDate(val); | |
| 149 | + return transformPrimitive(typ, val); | |
| 150 | +} | |
| 151 | + | |
| 152 | +function cast<T>(val: any, typ: any): T { | |
| 153 | + return transform(val, typ, jsonToJSProps); | |
| 154 | +} | |
| 155 | + | |
| 156 | +function uncast<T>(val: T, typ: any): any { | |
| 157 | + return transform(val, typ, jsToJSONProps); | |
| 158 | +} | |
| 159 | + | |
| 160 | +function l(typ: any) { | |
| 161 | + return { literal: typ }; | |
| 162 | +} | |
| 163 | + | |
| 164 | +function a(typ: any) { | |
| 165 | + return { arrayItems: typ }; | |
| 166 | +} | |
| 167 | + | |
| 168 | +function i(typ: any) { | |
| 169 | + return { integer: typ }; | |
| 170 | +} | |
| 171 | + | |
| 172 | +function p(pattern: any) { | |
| 173 | + return { pattern }; | |
| 174 | +} | |
| 175 | + | |
| 176 | +function s(typ: any, min: any, max: any) { | |
| 177 | + return { string: typ, min, max }; | |
| 178 | +} | |
| 179 | + | |
| 180 | +function n(typ: any, min: any, max: any) { | |
| 181 | + return { number: typ, min, max }; | |
| 182 | +} | |
| 183 | + | |
| 184 | +function u(...typs: any[]) { | |
| 185 | + return { unionMembers: typs }; | |
| 186 | +} | |
| 187 | + | |
| 188 | +function o(props: any[], additional: any) { | |
| 189 | + return { props, additional }; | |
| 190 | +} | |
| 191 | + | |
| 192 | +function m(additional: any) { | |
| 193 | + const props: any[] = []; | |
| 194 | + return { props, additional }; | |
| 195 | +} | |
| 196 | + | |
| 197 | +function r(name: string) { | |
| 198 | + return { ref: name }; | |
| 199 | +} | |
| 200 | + | |
| 201 | +const typeMap: any = { | |
| 202 | + "TopLevel": o([ | |
| 203 | + { json: "id", js: "id", typ: u(undefined, "") }, | |
| 204 | + ], 3.14), | |
| 205 | +}; |
Test case
2 generated files · +2 −2test/inputs/schema/multi-type-enum.schema
Mschema-flowdefault / TopLevel.js+1 −1
| @@ -11,7 +11,7 @@ | ||
| 11 | 11 | |
| 12 | 12 | export type TopLevel = { |
| 13 | 13 | foo: FooUnion; |
| 14 | - [property: string]: mixed | FooUnion; | |
| 14 | + [property: string]: mixed; | |
| 15 | 15 | }; |
| 16 | 16 | |
| 17 | 17 | export type FooUnion = boolean | number | FooEnum; |
Mschema-typescriptdefault / TopLevel.ts+1 −1
| @@ -9,7 +9,7 @@ | ||
| 9 | 9 | |
| 10 | 10 | export interface TopLevel { |
| 11 | 11 | foo: FooUnion; |
| 12 | - [property: string]: unknown | FooUnion; | |
| 12 | + [property: string]: unknown; | |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | export type FooUnion = boolean | number | FooEnum; |
Test case
2 generated files · +4 −4test/inputs/schema/mutually-recursive.schema
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -13,12 +13,12 @@ export type Foo = TopLevel[] | TopLevel; | ||
| 13 | 13 | |
| 14 | 14 | export type Bar = { |
| 15 | 15 | foo: Foo; |
| 16 | - [property: string]: mixed | Foo; | |
| 16 | + [property: string]: mixed; | |
| 17 | 17 | }; |
| 18 | 18 | |
| 19 | 19 | export type TopLevel = { |
| 20 | 20 | bar?: Bar; |
| 21 | - [property: string]: mixed | Bar; | |
| 21 | + [property: string]: mixed; | |
| 22 | 22 | }; |
| 23 | 23 | |
| 24 | 24 | // Converts JSON strings to/from your types |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -11,12 +11,12 @@ export type Foo = TopLevel[] | TopLevel; | ||
| 11 | 11 | |
| 12 | 12 | export interface Bar { |
| 13 | 13 | foo: Foo; |
| 14 | - [property: string]: unknown | Foo; | |
| 14 | + [property: string]: unknown; | |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | export interface TopLevel { |
| 18 | 18 | bar?: Bar; |
| 19 | - [property: string]: unknown | Bar; | |
| 19 | + [property: string]: unknown; | |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | // Converts JSON strings to/from your types |
Test case
2 generated files · +2 −2test/inputs/schema/nested-intersection-union.schema
Mschema-flowdefault / TopLevel.js+1 −1
| @@ -18,7 +18,7 @@ export type Item = { | ||
| 18 | 18 | id?: string; |
| 19 | 19 | output?: string; |
| 20 | 20 | summary?: string; |
| 21 | - [property: string]: mixed | string | string | string | string; | |
| 21 | + [property: string]: mixed; | |
| 22 | 22 | }; |
| 23 | 23 | |
| 24 | 24 | // Converts JSON strings to/from your types |
Mschema-typescriptdefault / TopLevel.ts+1 −1
| @@ -16,7 +16,7 @@ export interface Item { | ||
| 16 | 16 | id?: string; |
| 17 | 17 | output?: string; |
| 18 | 18 | summary?: string; |
| 19 | - [property: string]: unknown | string | string | string | string; | |
| 19 | + [property: string]: unknown; | |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | // Converts JSON strings to/from your types |
Test case
2 generated files · +2 −2test/inputs/schema/non-standard-ref.schema
Mschema-flowdefault / TopLevel.js+1 −1
| @@ -13,7 +13,7 @@ export type TopLevel = { | ||
| 13 | 13 | bar: number; |
| 14 | 14 | foo: number; |
| 15 | 15 | quux: boolean; |
| 16 | - [property: string]: mixed | number | number | boolean; | |
| 16 | + [property: string]: mixed; | |
| 17 | 17 | }; |
| 18 | 18 | |
| 19 | 19 | // Converts JSON strings to/from your types |
Mschema-typescriptdefault / TopLevel.ts+1 −1
| @@ -11,7 +11,7 @@ export interface TopLevel { | ||
| 11 | 11 | bar: number; |
| 12 | 12 | foo: number; |
| 13 | 13 | quux: boolean; |
| 14 | - [property: string]: unknown | number | number | boolean; | |
| 14 | + [property: string]: unknown; | |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | // Converts JSON strings to/from your types |
Test case
2 generated files · +2 −2test/inputs/schema/nullable-optional-one-of.schema
Mschema-flowdefault / TopLevel.js+1 −1
| @@ -12,7 +12,7 @@ | ||
| 12 | 12 | export type TopLevel = { |
| 13 | 13 | b?: null | string; |
| 14 | 14 | kind: Kind; |
| 15 | - [property: string]: mixed | null | string | Kind; | |
| 15 | + [property: string]: mixed; | |
| 16 | 16 | }; |
| 17 | 17 | |
| 18 | 18 | export type Kind = |
Mschema-typescriptdefault / TopLevel.ts+1 −1
| @@ -10,7 +10,7 @@ | ||
| 10 | 10 | export interface TopLevel { |
| 11 | 11 | b?: null | string; |
| 12 | 12 | kind: Kind; |
| 13 | - [property: string]: unknown | null | string | Kind; | |
| 13 | + [property: string]: unknown; | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | export type Kind = "one" | "two"; |
Test case
2 generated files · +2 −2test/inputs/schema/object-type-required.schema
Mschema-flowdefault / TopLevel.js+1 −1
| @@ -13,7 +13,7 @@ export type TopLevel = { | ||
| 13 | 13 | empty: Empty; |
| 14 | 14 | foo: string; |
| 15 | 15 | bar?: string; |
| 16 | - [property: string]: mixed | Empty | string | string; | |
| 16 | + [property: string]: mixed; | |
| 17 | 17 | }; |
| 18 | 18 | |
| 19 | 19 | export type Empty = { |
Mschema-typescriptdefault / TopLevel.ts+1 −1
| @@ -11,7 +11,7 @@ export interface TopLevel { | ||
| 11 | 11 | empty: object; |
| 12 | 12 | foo: string; |
| 13 | 13 | bar?: string; |
| 14 | - [property: string]: unknown | object | string | string; | |
| 14 | + [property: string]: unknown; | |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | // Converts JSON strings to/from your types |
Test case
2 generated files · +2 −2test/inputs/schema/optional-constraints.schema
Mschema-flowdefault / TopLevel.js+1 −1
| @@ -15,7 +15,7 @@ export type TopLevel = { | ||
| 15 | 15 | optPattern?: string; |
| 16 | 16 | optString?: string; |
| 17 | 17 | reqZeroMin: number; |
| 18 | - [property: string]: mixed | number | number | string | string | number; | |
| 18 | + [property: string]: mixed; | |
| 19 | 19 | }; |
| 20 | 20 | |
| 21 | 21 | // Converts JSON strings to/from your types |
Mschema-typescriptdefault / TopLevel.ts+1 −1
| @@ -13,7 +13,7 @@ export interface TopLevel { | ||
| 13 | 13 | optPattern?: string; |
| 14 | 14 | optString?: string; |
| 15 | 15 | reqZeroMin: number; |
| 16 | - [property: string]: unknown | number | number | string | string | number; | |
| 16 | + [property: string]: unknown; | |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | // Converts JSON strings to/from your types |
Test case
2 generated files · +2 −2test/inputs/schema/pattern.schema
Mschema-flowdefault / TopLevel.js+1 −1
| @@ -13,7 +13,7 @@ export type TopLevel = { | ||
| 13 | 13 | pattern1: string; |
| 14 | 14 | pattern2: string; |
| 15 | 15 | union: string; |
| 16 | - [property: string]: mixed | string | string | string; | |
| 16 | + [property: string]: mixed; | |
| 17 | 17 | }; |
| 18 | 18 | |
| 19 | 19 | // Converts JSON strings to/from your types |
Mschema-typescriptdefault / TopLevel.ts+1 −1
| @@ -11,7 +11,7 @@ export interface TopLevel { | ||
| 11 | 11 | pattern1: string; |
| 12 | 12 | pattern2: string; |
| 13 | 13 | union: string; |
| 14 | - [property: string]: unknown | string | string | string; | |
| 14 | + [property: string]: unknown; | |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | // Converts JSON strings to/from your types |
Test case
2 generated files · +4 −4test/inputs/schema/postman-collection.schema
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -16,12 +16,12 @@ export type TopLevel = { | ||
| 16 | 16 | item?: TopLevel[]; |
| 17 | 17 | name?: string; |
| 18 | 18 | response?: Response[]; |
| 19 | - [property: string]: mixed | TopLevel[] | string | Response[]; | |
| 19 | + [property: string]: mixed; | |
| 20 | 20 | }; |
| 21 | 21 | |
| 22 | 22 | export type Response = { |
| 23 | 23 | body?: string; |
| 24 | - [property: string]: mixed | string; | |
| 24 | + [property: string]: mixed; | |
| 25 | 25 | }; |
| 26 | 26 | |
| 27 | 27 | // Converts JSON strings to/from your types |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -14,12 +14,12 @@ export interface TopLevel { | ||
| 14 | 14 | item?: TopLevel[]; |
| 15 | 15 | name?: string; |
| 16 | 16 | response?: Response[]; |
| 17 | - [property: string]: unknown | TopLevel[] | string | Response[]; | |
| 17 | + [property: string]: unknown; | |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | export interface Response { |
| 21 | 21 | body?: string; |
| 22 | - [property: string]: unknown | string; | |
| 22 | + [property: string]: unknown; | |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | // Converts JSON strings to/from your types |
Test case
2 generated files · +2 −2test/inputs/schema/prefix-items.schema
Mschema-flowdefault / TopLevel.js+1 −1
| @@ -12,7 +12,7 @@ | ||
| 12 | 12 | export type TopLevel = { |
| 13 | 13 | open: Open[]; |
| 14 | 14 | tuple: Open[]; |
| 15 | - [property: string]: mixed | Open[] | Open[]; | |
| 15 | + [property: string]: mixed; | |
| 16 | 16 | }; |
| 17 | 17 | |
| 18 | 18 | export type Open = boolean | number; |
Mschema-typescriptdefault / TopLevel.ts+1 −1
| @@ -10,7 +10,7 @@ | ||
| 10 | 10 | export interface TopLevel { |
| 11 | 11 | open: Open[]; |
| 12 | 12 | tuple: Open[]; |
| 13 | - [property: string]: unknown | Open[] | Open[]; | |
| 13 | + [property: string]: unknown; | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | export type Open = boolean | number; |
Test case
2 generated files · +4 −4test/inputs/schema/recursive-union-flattening.schema
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -15,12 +15,12 @@ export type TopLevelElement = mixed[] | boolean | number | null | TopLevelObject | ||
| 15 | 15 | |
| 16 | 16 | export type TopLevelObject = { |
| 17 | 17 | x?: X; |
| 18 | - [property: string]: mixed | X; | |
| 18 | + [property: string]: mixed; | |
| 19 | 19 | }; |
| 20 | 20 | |
| 21 | 21 | export type XObject = { |
| 22 | 22 | x?: X; |
| 23 | - [property: string]: mixed | X; | |
| 23 | + [property: string]: mixed; | |
| 24 | 24 | }; |
| 25 | 25 | |
| 26 | 26 | export type XElement = mixed[] | boolean | number | null | XObject | string; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -13,12 +13,12 @@ export type TopLevelElement = unknown[] | boolean | number | null | TopLevelObje | ||
| 13 | 13 | |
| 14 | 14 | export interface TopLevelObject { |
| 15 | 15 | x?: X; |
| 16 | - [property: string]: unknown | X; | |
| 16 | + [property: string]: unknown; | |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | export interface XObject { |
| 20 | 20 | x?: X; |
| 21 | - [property: string]: unknown | X; | |
| 21 | + [property: string]: unknown; | |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | export type XElement = unknown[] | boolean | number | null | XObject | string; |
Test case
2 generated files · +2 −2test/inputs/schema/ref-id-files.schema
Mschema-flowdefault / TopLevel.js+1 −1
| @@ -11,7 +11,7 @@ | ||
| 11 | 11 | |
| 12 | 12 | export type TopLevel = { |
| 13 | 13 | foo: number; |
| 14 | - [property: string]: mixed | number; | |
| 14 | + [property: string]: mixed; | |
| 15 | 15 | }; |
| 16 | 16 | |
| 17 | 17 | // Converts JSON strings to/from your types |
Mschema-typescriptdefault / TopLevel.ts+1 −1
| @@ -9,7 +9,7 @@ | ||
| 9 | 9 | |
| 10 | 10 | export interface TopLevel { |
| 11 | 11 | foo: number; |
| 12 | - [property: string]: unknown | number; | |
| 12 | + [property: string]: unknown; | |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | // Converts JSON strings to/from your types |
Test case
2 generated files · +2 −2test/inputs/schema/ref-remote.schema
Mschema-flowdefault / TopLevel.js+1 −1
| @@ -14,7 +14,7 @@ | ||
| 14 | 14 | */ |
| 15 | 15 | export type TopLevel = { |
| 16 | 16 | next?: TopLevel; |
| 17 | - [property: string]: mixed | TopLevel; | |
| 17 | + [property: string]: mixed; | |
| 18 | 18 | }; |
| 19 | 19 | |
| 20 | 20 | // Converts JSON strings to/from your types |
Mschema-typescriptdefault / TopLevel.ts+1 −1
| @@ -12,7 +12,7 @@ | ||
| 12 | 12 | */ |
| 13 | 13 | export interface TopLevel { |
| 14 | 14 | next?: TopLevel; |
| 15 | - [property: string]: unknown | TopLevel; | |
| 15 | + [property: string]: unknown; | |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | // Converts JSON strings to/from your types |
Test case
2 generated files · +28 −28test/inputs/schema/renaming-bug.schema
Mschema-flowdefault / TopLevel.js+14 −14
| @@ -13,60 +13,60 @@ export type TopLevel = { | ||
| 13 | 13 | version?: string; |
| 14 | 14 | fruits?: Fruit[]; |
| 15 | 15 | vehicles?: Vehicle[]; |
| 16 | - [property: string]: mixed | string | Fruit[] | Vehicle[]; | |
| 16 | + [property: string]: mixed; | |
| 17 | 17 | }; |
| 18 | 18 | |
| 19 | 19 | export type Fruit = { |
| 20 | 20 | apple?: boolean; |
| 21 | 21 | berries?: Berry[]; |
| 22 | 22 | orange?: boolean; |
| 23 | - [property: string]: mixed | boolean | Berry[] | boolean; | |
| 23 | + [property: string]: mixed; | |
| 24 | 24 | }; |
| 25 | 25 | |
| 26 | 26 | export type Berry = { |
| 27 | 27 | color?: Color; |
| 28 | 28 | name?: string; |
| 29 | 29 | shapes?: Shape[]; |
| 30 | - [property: string]: mixed | Color | string | Shape[]; | |
| 30 | + [property: string]: mixed; | |
| 31 | 31 | }; |
| 32 | 32 | |
| 33 | 33 | export type Color = { |
| 34 | 34 | rgb?: number; |
| 35 | - [property: string]: mixed | number; | |
| 35 | + [property: string]: mixed; | |
| 36 | 36 | }; |
| 37 | 37 | |
| 38 | 38 | export type Shape = { |
| 39 | 39 | geometry?: Geometry; |
| 40 | 40 | history?: History; |
| 41 | - [property: string]: mixed | Geometry | History; | |
| 41 | + [property: string]: mixed; | |
| 42 | 42 | }; |
| 43 | 43 | |
| 44 | 44 | export type Geometry = { |
| 45 | 45 | rectShape?: RectShape; |
| 46 | 46 | circularShape?: CircularShape[]; |
| 47 | - [property: string]: mixed | RectShape | CircularShape[]; | |
| 47 | + [property: string]: mixed; | |
| 48 | 48 | }; |
| 49 | 49 | |
| 50 | 50 | export type CircularShape = { |
| 51 | 51 | shapeName?: string; |
| 52 | - [property: string]: mixed | string; | |
| 52 | + [property: string]: mixed; | |
| 53 | 53 | }; |
| 54 | 54 | |
| 55 | 55 | export type RectShape = { |
| 56 | 56 | parts?: Part[]; |
| 57 | - [property: string]: mixed | Part[]; | |
| 57 | + [property: string]: mixed; | |
| 58 | 58 | }; |
| 59 | 59 | |
| 60 | 60 | export type Part = { |
| 61 | 61 | depth?: string; |
| 62 | 62 | length?: string; |
| 63 | 63 | width?: string; |
| 64 | - [property: string]: mixed | string | string | string; | |
| 64 | + [property: string]: mixed; | |
| 65 | 65 | }; |
| 66 | 66 | |
| 67 | 67 | export type History = { |
| 68 | 68 | class?: string; |
| 69 | - [property: string]: mixed | string; | |
| 69 | + [property: string]: mixed; | |
| 70 | 70 | }; |
| 71 | 71 | |
| 72 | 72 | export type Vehicle = { |
| @@ -76,25 +76,25 @@ export type Vehicle = { | ||
| 76 | 76 | subModule?: boolean; |
| 77 | 77 | type?: VehicleType; |
| 78 | 78 | year?: string; |
| 79 | - [property: string]: mixed | string | string | Speed | boolean | VehicleType | string; | |
| 79 | + [property: string]: mixed; | |
| 80 | 80 | }; |
| 81 | 81 | |
| 82 | 82 | export type Speed = { |
| 83 | 83 | velocity?: Limit; |
| 84 | - [property: string]: mixed | Limit; | |
| 84 | + [property: string]: mixed; | |
| 85 | 85 | }; |
| 86 | 86 | |
| 87 | 87 | export type Limit = { |
| 88 | 88 | maximum?: number; |
| 89 | 89 | minimum?: number; |
| 90 | - [property: string]: mixed | number | number; | |
| 90 | + [property: string]: mixed; | |
| 91 | 91 | }; |
| 92 | 92 | |
| 93 | 93 | export type VehicleType = { |
| 94 | 94 | name?: Name; |
| 95 | 95 | width?: Axis; |
| 96 | 96 | length?: Axis; |
| 97 | - [property: string]: mixed | Name | Axis | Axis; | |
| 97 | + [property: string]: mixed; | |
| 98 | 98 | }; |
| 99 | 99 | |
| 100 | 100 | export type Axis = |
Mschema-typescriptdefault / TopLevel.ts+14 −14
| @@ -11,60 +11,60 @@ export interface TopLevel { | ||
| 11 | 11 | version?: string; |
| 12 | 12 | fruits?: Fruit[]; |
| 13 | 13 | vehicles?: Vehicle[]; |
| 14 | - [property: string]: unknown | string | Fruit[] | Vehicle[]; | |
| 14 | + [property: string]: unknown; | |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | export interface Fruit { |
| 18 | 18 | apple?: boolean; |
| 19 | 19 | berries?: Berry[]; |
| 20 | 20 | orange?: boolean; |
| 21 | - [property: string]: unknown | boolean | Berry[] | boolean; | |
| 21 | + [property: string]: unknown; | |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | export interface Berry { |
| 25 | 25 | color?: Color; |
| 26 | 26 | name?: string; |
| 27 | 27 | shapes?: Shape[]; |
| 28 | - [property: string]: unknown | Color | string | Shape[]; | |
| 28 | + [property: string]: unknown; | |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | export interface Color { |
| 32 | 32 | rgb?: number; |
| 33 | - [property: string]: unknown | number; | |
| 33 | + [property: string]: unknown; | |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | export interface Shape { |
| 37 | 37 | geometry?: Geometry; |
| 38 | 38 | history?: History; |
| 39 | - [property: string]: unknown | Geometry | History; | |
| 39 | + [property: string]: unknown; | |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | export interface Geometry { |
| 43 | 43 | rectShape?: RectShape; |
| 44 | 44 | circularShape?: CircularShape[]; |
| 45 | - [property: string]: unknown | RectShape | CircularShape[]; | |
| 45 | + [property: string]: unknown; | |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | export interface CircularShape { |
| 49 | 49 | shapeName?: string; |
| 50 | - [property: string]: unknown | string; | |
| 50 | + [property: string]: unknown; | |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | export interface RectShape { |
| 54 | 54 | parts?: Part[]; |
| 55 | - [property: string]: unknown | Part[]; | |
| 55 | + [property: string]: unknown; | |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | export interface Part { |
| 59 | 59 | depth?: string; |
| 60 | 60 | length?: string; |
| 61 | 61 | width?: string; |
| 62 | - [property: string]: unknown | string | string | string; | |
| 62 | + [property: string]: unknown; | |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | export interface History { |
| 66 | 66 | class?: string; |
| 67 | - [property: string]: unknown | string; | |
| 67 | + [property: string]: unknown; | |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | export interface Vehicle { |
| @@ -74,25 +74,25 @@ export interface Vehicle { | ||
| 74 | 74 | subModule?: boolean; |
| 75 | 75 | type?: VehicleType; |
| 76 | 76 | year?: string; |
| 77 | - [property: string]: unknown | string | string | Speed | boolean | VehicleType | string; | |
| 77 | + [property: string]: unknown; | |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | export interface Speed { |
| 81 | 81 | velocity?: Limit; |
| 82 | - [property: string]: unknown | Limit; | |
| 82 | + [property: string]: unknown; | |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | export interface Limit { |
| 86 | 86 | maximum?: number; |
| 87 | 87 | minimum?: number; |
| 88 | - [property: string]: unknown | number | number; | |
| 88 | + [property: string]: unknown; | |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | export interface VehicleType { |
| 92 | 92 | name?: Name; |
| 93 | 93 | width?: Axis; |
| 94 | 94 | length?: Axis; |
| 95 | - [property: string]: unknown | Name | Axis | Axis; | |
| 95 | + [property: string]: unknown; | |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | export type Axis = "X" | "Y" | "Z" | "YZ" | "ZX" | "XY"; |
Test case
2 generated files · +2 −2test/inputs/schema/required-draft3.schema
Mschema-flowdefault / TopLevel.js+1 −1
| @@ -11,7 +11,7 @@ | ||
| 11 | 11 | |
| 12 | 12 | export type TopLevel = { |
| 13 | 13 | longitude: number; |
| 14 | - [property: string]: mixed | number; | |
| 14 | + [property: string]: mixed; | |
| 15 | 15 | }; |
| 16 | 16 | |
| 17 | 17 | // Converts JSON strings to/from your types |
Mschema-typescriptdefault / TopLevel.ts+1 −1
| @@ -9,7 +9,7 @@ | ||
| 9 | 9 | |
| 10 | 10 | export interface TopLevel { |
| 11 | 11 | longitude: number; |
| 12 | - [property: string]: unknown | number; | |
| 12 | + [property: string]: unknown; | |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | // Converts JSON strings to/from your types |
Test case
2 generated files · +2 −2test/inputs/schema/required-non-properties.schema
Mschema-flowdefault / TopLevel.js+1 −1
| @@ -12,7 +12,7 @@ | ||
| 12 | 12 | export type TopLevel = { |
| 13 | 13 | foo: number; |
| 14 | 14 | bar: mixed; |
| 15 | - [property: string]: mixed | number | mixed; | |
| 15 | + [property: string]: mixed; | |
| 16 | 16 | }; |
| 17 | 17 | |
| 18 | 18 | // Converts JSON strings to/from your types |
Mschema-typescriptdefault / TopLevel.ts+1 −1
| @@ -10,7 +10,7 @@ | ||
| 10 | 10 | export interface TopLevel { |
| 11 | 11 | foo: number; |
| 12 | 12 | bar: unknown; |
| 13 | - [property: string]: unknown | number | unknown; | |
| 13 | + [property: string]: unknown; | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | // Converts JSON strings to/from your types |
Test case
2 generated files · +2 −2test/inputs/schema/required.schema
Mschema-flowdefault / TopLevel.js+1 −1
| @@ -11,7 +11,7 @@ | ||
| 11 | 11 | |
| 12 | 12 | export type TopLevel = { |
| 13 | 13 | longitude: number; |
| 14 | - [property: string]: mixed | number; | |
| 14 | + [property: string]: mixed; | |
| 15 | 15 | }; |
| 16 | 16 | |
| 17 | 17 | // Converts JSON strings to/from your types |
Mschema-typescriptdefault / TopLevel.ts+1 −1
| @@ -9,7 +9,7 @@ | ||
| 9 | 9 | |
| 10 | 10 | export interface TopLevel { |
| 11 | 11 | longitude: number; |
| 12 | - [property: string]: unknown | number; | |
| 12 | + [property: string]: unknown; | |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | // Converts JSON strings to/from your types |
Test case
2 generated files · +4 −4test/inputs/schema/rust-cycle-breaker-union.schema
Mschema-flowdefault / TopLevel.js+2 −2
| @@ -12,13 +12,13 @@ | ||
| 12 | 12 | export type TopLevel = { |
| 13 | 13 | next?: Next; |
| 14 | 14 | value: string; |
| 15 | - [property: string]: mixed | Next | string; | |
| 15 | + [property: string]: mixed; | |
| 16 | 16 | }; |
| 17 | 17 | |
| 18 | 18 | export type Node = { |
| 19 | 19 | next?: Next; |
| 20 | 20 | value: string; |
| 21 | - [property: string]: mixed | Next | string; | |
| 21 | + [property: string]: mixed; | |
| 22 | 22 | }; |
| 23 | 23 | |
| 24 | 24 | export type Next = null | Node | string; |
Mschema-typescriptdefault / TopLevel.ts+2 −2
| @@ -10,13 +10,13 @@ | ||
| 10 | 10 | export interface TopLevel { |
| 11 | 11 | next?: Next; |
| 12 | 12 | value: string; |
| 13 | - [property: string]: unknown | Next | string; | |
| 13 | + [property: string]: unknown; | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | export interface Node { |
| 17 | 17 | next?: Next; |
| 18 | 18 | value: string; |
| 19 | - [property: string]: unknown | Next | string; | |
| 19 | + [property: string]: unknown; | |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | export type Next = null | Node | string; |
Test case
2 generated files · +2 −2test/inputs/schema/schema-constraints.schema
Mschema-flowdefault / TopLevel.js+1 −1
| @@ -12,7 +12,7 @@ | ||
| 12 | 12 | export type TopLevel = { |
| 13 | 13 | minMaxLength: string; |
| 14 | 14 | percent: number; |
| 15 | - [property: string]: mixed | string | number; | |
| 15 | + [property: string]: mixed; | |
| 16 | 16 | }; |
| 17 | 17 | |
| 18 | 18 | // Converts JSON strings to/from your types |
Mschema-typescriptdefault / TopLevel.ts+1 −1
| @@ -10,7 +10,7 @@ | ||
| 10 | 10 | export interface TopLevel { |
| 11 | 11 | minMaxLength: string; |
| 12 | 12 | percent: number; |
| 13 | - [property: string]: unknown | string | number; | |
| 13 | + [property: string]: unknown; | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | // Converts JSON strings to/from your types |
Test case
2 generated files · +2 −2test/inputs/schema/simple-ref.schema
Mschema-flowdefault / TopLevel.js+1 −1
| @@ -14,7 +14,7 @@ | ||
| 14 | 14 | */ |
| 15 | 15 | export type TopLevel = { |
| 16 | 16 | next?: TopLevel; |
| 17 | - [property: string]: mixed | TopLevel; | |
| 17 | + [property: string]: mixed; | |
| 18 | 18 | }; |
| 19 | 19 | |
| 20 | 20 | // Converts JSON strings to/from your types |
Mschema-typescriptdefault / TopLevel.ts+1 −1
| @@ -12,7 +12,7 @@ | ||
| 12 | 12 | */ |
| 13 | 13 | export interface TopLevel { |
| 14 | 14 | next?: TopLevel; |
| 15 | - [property: string]: unknown | TopLevel; | |
| 15 | + [property: string]: unknown; | |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | // Converts JSON strings to/from your types |
Test case
2 generated files · +2 −2test/inputs/schema/strict-optional.schema
Mschema-flowdefault / TopLevel.js+1 −1
| @@ -11,7 +11,7 @@ | ||
| 11 | 11 | |
| 12 | 12 | export type TopLevel = { |
| 13 | 13 | foo: number | null; |
| 14 | - [property: string]: mixed | number | null; | |
| 14 | + [property: string]: mixed; | |
| 15 | 15 | }; |
| 16 | 16 | |
| 17 | 17 | // Converts JSON strings to/from your types |
Mschema-typescriptdefault / TopLevel.ts+1 −1
| @@ -9,7 +9,7 @@ | ||
| 9 | 9 | |
| 10 | 10 | export interface TopLevel { |
| 11 | 11 | foo: number | null; |
| 12 | - [property: string]: unknown | number | null; | |
| 12 | + [property: string]: unknown; | |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | // Converts JSON strings to/from your types |
Test case
2 generated files · +2 −2test/inputs/schema/top-level-array.schema
Mschema-flowdefault / TopLevel.js+1 −1
| @@ -14,7 +14,7 @@ export type TopLevel = TextClassificationOutputElement[]; | ||
| 14 | 14 | export type TextClassificationOutputElement = { |
| 15 | 15 | label: string; |
| 16 | 16 | score: number; |
| 17 | - [property: string]: mixed | string | number; | |
| 17 | + [property: string]: mixed; | |
| 18 | 18 | }; |
| 19 | 19 | |
| 20 | 20 | // Converts JSON strings to/from your types |
Mschema-typescriptdefault / TopLevel.ts+1 −1
| @@ -12,7 +12,7 @@ export type TopLevel = TextClassificationOutputElement[]; | ||
| 12 | 12 | export interface TextClassificationOutputElement { |
| 13 | 13 | label: string; |
| 14 | 14 | score: number; |
| 15 | - [property: string]: unknown | string | number; | |
| 15 | + [property: string]: unknown; | |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | // Converts JSON strings to/from your types |
Test case
2 generated files · +2 −2test/inputs/schema/tuple.schema
Mschema-flowdefault / TopLevel.js+1 −1
| @@ -11,7 +11,7 @@ | ||
| 11 | 11 | |
| 12 | 12 | export type TopLevel = { |
| 13 | 13 | tuple: Tuple[]; |
| 14 | - [property: string]: mixed | Tuple[]; | |
| 14 | + [property: string]: mixed; | |
| 15 | 15 | }; |
| 16 | 16 | |
| 17 | 17 | export type Tuple = boolean | number; |
Mschema-typescriptdefault / TopLevel.ts+1 −1
| @@ -9,7 +9,7 @@ | ||
| 9 | 9 | |
| 10 | 10 | export interface TopLevel { |
| 11 | 11 | tuple: Tuple[]; |
| 12 | - [property: string]: unknown | Tuple[]; | |
| 12 | + [property: string]: unknown; | |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | export type Tuple = boolean | number; |
Test case
2 generated files · +6 −6test/inputs/schema/unevaluated-properties.schema
Mschema-flowdefault / TopLevel.js+3 −3
| @@ -11,14 +11,14 @@ | ||
| 11 | 11 | |
| 12 | 12 | export type TopLevel = { |
| 13 | 13 | config?: Config; |
| 14 | - [property: string]: mixed | Config; | |
| 14 | + [property: string]: mixed; | |
| 15 | 15 | }; |
| 16 | 16 | |
| 17 | 17 | export type Config = { |
| 18 | 18 | closed?: Closed; |
| 19 | 19 | name?: string; |
| 20 | 20 | settings?: { [key: string]: Item[] }; |
| 21 | - [property: string]: mixed | Closed | string | { [key: string]: Item[] }; | |
| 21 | + [property: string]: mixed; | |
| 22 | 22 | }; |
| 23 | 23 | |
| 24 | 24 | export type Closed = mixed[] | boolean | ClosedClass | number | number | null | string; |
| @@ -29,7 +29,7 @@ export type ClosedClass = { | ||
| 29 | 29 | export type Item = { |
| 30 | 30 | key: string; |
| 31 | 31 | value: string; |
| 32 | - [property: string]: mixed | string | string; | |
| 32 | + [property: string]: mixed; | |
| 33 | 33 | }; |
| 34 | 34 | |
| 35 | 35 | // Converts JSON strings to/from your types |
Mschema-typescriptdefault / TopLevel.ts+3 −3
| @@ -9,14 +9,14 @@ | ||
| 9 | 9 | |
| 10 | 10 | export interface TopLevel { |
| 11 | 11 | config?: Config; |
| 12 | - [property: string]: unknown | Config; | |
| 12 | + [property: string]: unknown; | |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | export interface Config { |
| 16 | 16 | closed?: Closed; |
| 17 | 17 | name?: string; |
| 18 | 18 | settings?: { [key: string]: Item[] }; |
| 19 | - [property: string]: unknown | Closed | string | { [key: string]: Item[] }; | |
| 19 | + [property: string]: unknown; | |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | export type Closed = unknown[] | boolean | object | number | number | null | string; |
| @@ -24,7 +24,7 @@ export type Closed = unknown[] | boolean | object | number | number | null | str | ||
| 24 | 24 | export interface Item { |
| 25 | 25 | key: string; |
| 26 | 26 | value: string; |
| 27 | - [property: string]: unknown | string | string; | |
| 27 | + [property: string]: unknown; | |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | // Converts JSON strings to/from your types |
Test case
2 generated files · +2 −2test/inputs/schema/union-int-double.schema
Mschema-flowdefault / TopLevel.js+1 −1
| @@ -11,7 +11,7 @@ | ||
| 11 | 11 | |
| 12 | 12 | export type TopLevel = { |
| 13 | 13 | value: Value; |
| 14 | - [property: string]: mixed | Value; | |
| 14 | + [property: string]: mixed; | |
| 15 | 15 | }; |
| 16 | 16 | |
| 17 | 17 | export type Value = number | string; |
Mschema-typescriptdefault / TopLevel.ts+1 −1
| @@ -9,7 +9,7 @@ | ||
| 9 | 9 | |
| 10 | 10 | export interface TopLevel { |
| 11 | 11 | value: Value; |
| 12 | - [property: string]: unknown | Value; | |
| 12 | + [property: string]: unknown; | |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | export type Value = number | string; |
Test case
2 generated files · +2 −2test/inputs/schema/union.schema
Mschema-flowdefault / TopLevel.js+1 −1
| @@ -15,7 +15,7 @@ export type TopLevelElement = { | ||
| 15 | 15 | one?: number; |
| 16 | 16 | two: boolean; |
| 17 | 17 | three?: number; |
| 18 | - [property: string]: mixed | number | boolean | number; | |
| 18 | + [property: string]: mixed; | |
| 19 | 19 | }; |
| 20 | 20 | |
| 21 | 21 | // Converts JSON strings to/from your types |
Mschema-typescriptdefault / TopLevel.ts+1 −1
| @@ -13,7 +13,7 @@ export interface TopLevelElement { | ||
| 13 | 13 | one?: number; |
| 14 | 14 | two: boolean; |
| 15 | 15 | three?: number; |
| 16 | - [property: string]: unknown | number | boolean | number; | |
| 16 | + [property: string]: unknown; | |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | // Converts JSON strings to/from your types |
Test case
2 generated files · +2 −2test/inputs/schema/uuid.schema
Mschema-flowdefault / TopLevel.js+1 −1
| @@ -16,7 +16,7 @@ export type TopLevel = { | ||
| 16 | 16 | one: string; |
| 17 | 17 | optional?: string; |
| 18 | 18 | unionWithEnum: UnionWithEnumUnion; |
| 19 | - [property: string]: mixed | (null | string)[] | string[] | null | string | string | string | UnionWithEnumUnion; | |
| 19 | + [property: string]: mixed; | |
| 20 | 20 | }; |
| 21 | 21 | |
| 22 | 22 | export type UnionWithEnumUnion = UnionWithEnumEnum | string; |
Mschema-typescriptdefault / TopLevel.ts+1 −1
| @@ -14,7 +14,7 @@ export interface TopLevel { | ||
| 14 | 14 | one: string; |
| 15 | 15 | optional?: string; |
| 16 | 16 | unionWithEnum: UnionWithEnumUnion; |
| 17 | - [property: string]: unknown | (null | string)[] | string[] | null | string | string | string | UnionWithEnumUnion; | |
| 17 | + [property: string]: unknown; | |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | export type UnionWithEnumUnion = UnionWithEnumEnum | string; |
Test case
2 generated files · +2 −2test/inputs/schema/vega-lite.schema
Mschema-flowdefault / TopLevel.js+1 −1
| @@ -1800,7 +1800,7 @@ export type RangeConfig = { | ||
| 1800 | 1800 | * Default range palette for the `shape` channel. |
| 1801 | 1801 | */ |
| 1802 | 1802 | symbol?: string[]; |
| 1803 | - [property: string]: RangeConfigValue | Category | Category | Category | Category | Category | string[]; | |
| 1803 | + [property: string]: RangeConfigValue | Category | string[] | void; | |
| 1804 | 1804 | }; |
| 1805 | 1805 | |
| 1806 | 1806 | /** |
Mschema-typescriptdefault / TopLevel.ts+1 −1
| @@ -1706,7 +1706,7 @@ export interface RangeConfig { | ||
| 1706 | 1706 | * Default range palette for the `shape` channel. |
| 1707 | 1707 | */ |
| 1708 | 1708 | symbol?: string[]; |
| 1709 | - [property: string]: RangeConfigValue | Category | Category | Category | Category | Category | string[]; | |
| 1709 | + [property: string]: RangeConfigValue | Category | string[] | undefined; | |
| 1710 | 1710 | } |
| 1711 | 1711 | |
| 1712 | 1712 | /** |
No generated files match these filters.