Test case
3 generated files · +26 −22test/inputs/json/misc/00c36.json
Mflowdefault / TopLevel.js+11 −9
| @@ -9,9 +9,11 @@ | ||
| 9 | 9 | // These functions will throw an error if the JSON doesn't |
| 10 | 10 | // match the expected interface, even if the JSON is valid. |
| 11 | 11 | |
| 12 | -export type TopLevel = TopLevelElement[] | PurpleTopLevel; | |
| 12 | +export type TopLevel = TopLevelUnion[]; | |
| 13 | 13 | |
| 14 | -export type TopLevelElement = { | |
| 14 | +export type TopLevelUnion = PurpleTopLevel[] | FluffyTopLevel; | |
| 15 | + | |
| 16 | +export type PurpleTopLevel = { | |
| 15 | 17 | country: Country; |
| 16 | 18 | date: string; |
| 17 | 19 | decimal: string; |
| @@ -32,7 +34,7 @@ export type Value = | ||
| 32 | 34 | "United States" |
| 33 | 35 | | "GDP (current US$)"; |
| 34 | 36 | |
| 35 | -export type PurpleTopLevel = { | |
| 37 | +export type FluffyTopLevel = { | |
| 36 | 38 | page: number; |
| 37 | 39 | pages: number; |
| 38 | 40 | per_page: string; |
| @@ -41,12 +43,12 @@ export type PurpleTopLevel = { | ||
| 41 | 43 | |
| 42 | 44 | // Converts JSON strings to/from your types |
| 43 | 45 | // and asserts the results of JSON.parse at runtime |
| 44 | -function toTopLevel(json: string): TopLevel[] { | |
| 45 | - return cast(JSON.parse(json), a(u(a(r("TopLevelElement")), r("PurpleTopLevel")))); | |
| 46 | +function toTopLevel(json: string): TopLevelUnion[] { | |
| 47 | + return cast(JSON.parse(json), a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel")))); | |
| 46 | 48 | } |
| 47 | 49 | |
| 48 | -function topLevelToJson(value: TopLevel[]): string { | |
| 49 | - return JSON.stringify(uncast(value, a(u(a(r("TopLevelElement")), r("PurpleTopLevel")))), null, 2); | |
| 50 | +function topLevelToJson(value: TopLevelUnion[]): string { | |
| 51 | + return JSON.stringify(uncast(value, a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel")))), null, 2); | |
| 50 | 52 | } |
| 51 | 53 | |
| 52 | 54 | function invalidValue(typ: any, val: any, key: any, parent: any = '') { |
| @@ -203,7 +205,7 @@ function r(name: string) { | ||
| 203 | 205 | } |
| 204 | 206 | |
| 205 | 207 | const typeMap: any = { |
| 206 | - "TopLevelElement": o([ | |
| 208 | + "PurpleTopLevel": o([ | |
| 207 | 209 | { json: "country", js: "country", typ: r("Country") }, |
| 208 | 210 | { json: "date", js: "date", typ: "" }, |
| 209 | 211 | { json: "decimal", js: "decimal", typ: "" }, |
| @@ -214,7 +216,7 @@ const typeMap: any = { | ||
| 214 | 216 | { json: "id", js: "id", typ: r("ID") }, |
| 215 | 217 | { json: "value", js: "value", typ: r("Value") }, |
| 216 | 218 | ], false), |
| 217 | - "PurpleTopLevel": o([ | |
| 219 | + "FluffyTopLevel": o([ | |
| 218 | 220 | { json: "page", js: "page", typ: 0 }, |
| 219 | 221 | { json: "pages", js: "pages", typ: 0 }, |
| 220 | 222 | { json: "per_page", js: "per_page", typ: "" }, |
Mjavascriptdefault / TopLevel.js+4 −4
| @@ -10,11 +10,11 @@ | ||
| 10 | 10 | // Converts JSON strings to/from your types |
| 11 | 11 | // and asserts the results of JSON.parse at runtime |
| 12 | 12 | function toTopLevel(json) { |
| 13 | - return cast(JSON.parse(json), a(u(a(r("TopLevelElement")), r("PurpleTopLevel")))); | |
| 13 | + return cast(JSON.parse(json), a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel")))); | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | function topLevelToJson(value) { |
| 17 | - return JSON.stringify(uncast(value, a(u(a(r("TopLevelElement")), r("PurpleTopLevel")))), null, 2); | |
| 17 | + return JSON.stringify(uncast(value, a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel")))), null, 2); | |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | function invalidValue(typ, val, key, parent = '') { |
| @@ -171,7 +171,7 @@ function r(name) { | ||
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | const typeMap = { |
| 174 | - "TopLevelElement": o([ | |
| 174 | + "PurpleTopLevel": o([ | |
| 175 | 175 | { json: "country", js: "country", typ: r("Country") }, |
| 176 | 176 | { json: "date", js: "date", typ: "" }, |
| 177 | 177 | { json: "decimal", js: "decimal", typ: "" }, |
| @@ -182,7 +182,7 @@ const typeMap = { | ||
| 182 | 182 | { json: "id", js: "id", typ: r("ID") }, |
| 183 | 183 | { json: "value", js: "value", typ: r("Value") }, |
| 184 | 184 | ], false), |
| 185 | - "PurpleTopLevel": o([ | |
| 185 | + "FluffyTopLevel": o([ | |
| 186 | 186 | { json: "page", js: "page", typ: 0 }, |
| 187 | 187 | { json: "pages", js: "pages", typ: 0 }, |
| 188 | 188 | { json: "per_page", js: "per_page", typ: "" }, |
Mtypescriptdefault / TopLevel.ts+11 −9
| @@ -7,9 +7,11 @@ | ||
| 7 | 7 | // These functions will throw an error if the JSON doesn't |
| 8 | 8 | // match the expected interface, even if the JSON is valid. |
| 9 | 9 | |
| 10 | -export type TopLevel = TopLevelElement[] | PurpleTopLevel; | |
| 10 | +export type TopLevel = TopLevelUnion[]; | |
| 11 | 11 | |
| 12 | -export interface TopLevelElement { | |
| 12 | +export type TopLevelUnion = PurpleTopLevel[] | FluffyTopLevel; | |
| 13 | + | |
| 14 | +export interface PurpleTopLevel { | |
| 13 | 15 | country: Country; |
| 14 | 16 | date: string; |
| 15 | 17 | decimal: string; |
| @@ -26,7 +28,7 @@ export type ID = "US" | "NY.GDP.MKTP.CD"; | ||
| 26 | 28 | |
| 27 | 29 | export type Value = "United States" | "GDP (current US$)"; |
| 28 | 30 | |
| 29 | -export interface PurpleTopLevel { | |
| 31 | +export interface FluffyTopLevel { | |
| 30 | 32 | page: number; |
| 31 | 33 | pages: number; |
| 32 | 34 | per_page: string; |
| @@ -36,12 +38,12 @@ export interface PurpleTopLevel { | ||
| 36 | 38 | // Converts JSON strings to/from your types |
| 37 | 39 | // and asserts the results of JSON.parse at runtime |
| 38 | 40 | export class Convert { |
| 39 | - public static toTopLevel(json: string): TopLevel[] { | |
| 40 | - return cast(JSON.parse(json), a(u(a(r("TopLevelElement")), r("PurpleTopLevel")))); | |
| 41 | + public static toTopLevel(json: string): TopLevelUnion[] { | |
| 42 | + return cast(JSON.parse(json), a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel")))); | |
| 41 | 43 | } |
| 42 | 44 | |
| 43 | - public static topLevelToJson(value: TopLevel[]): string { | |
| 44 | - return JSON.stringify(uncast(value, a(u(a(r("TopLevelElement")), r("PurpleTopLevel")))), null, 2); | |
| 45 | + public static topLevelToJson(value: TopLevelUnion[]): string { | |
| 46 | + return JSON.stringify(uncast(value, a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel")))), null, 2); | |
| 45 | 47 | } |
| 46 | 48 | } |
| 47 | 49 | |
| @@ -199,7 +201,7 @@ function r(name: string) { | ||
| 199 | 201 | } |
| 200 | 202 | |
| 201 | 203 | const typeMap: any = { |
| 202 | - "TopLevelElement": o([ | |
| 204 | + "PurpleTopLevel": o([ | |
| 203 | 205 | { json: "country", js: "country", typ: r("Country") }, |
| 204 | 206 | { json: "date", js: "date", typ: "" }, |
| 205 | 207 | { json: "decimal", js: "decimal", typ: "" }, |
| @@ -210,7 +212,7 @@ const typeMap: any = { | ||
| 210 | 212 | { json: "id", js: "id", typ: r("ID") }, |
| 211 | 213 | { json: "value", js: "value", typ: r("Value") }, |
| 212 | 214 | ], false), |
| 213 | - "PurpleTopLevel": o([ | |
| 215 | + "FluffyTopLevel": o([ | |
| 214 | 216 | { json: "page", js: "page", typ: 0 }, |
| 215 | 217 | { json: "pages", js: "pages", typ: 0 }, |
| 216 | 218 | { json: "per_page", js: "per_page", typ: "" }, |
Test case
3 generated files · +19 −15test/inputs/json/misc/010b1.json
Mflowdefault / TopLevel.js+8 −6
| @@ -9,7 +9,9 @@ | ||
| 9 | 9 | // These functions will throw an error if the JSON doesn't |
| 10 | 10 | // match the expected interface, even if the JSON is valid. |
| 11 | 11 | |
| 12 | -export type TopLevel = { | |
| 12 | +export type TopLevel = TopLevelElement[]; | |
| 13 | + | |
| 14 | +export type TopLevelElement = { | |
| 13 | 15 | age: number; |
| 14 | 16 | country: Country; |
| 15 | 17 | females: number; |
| @@ -23,12 +25,12 @@ export type Country = | ||
| 23 | 25 | |
| 24 | 26 | // Converts JSON strings to/from your types |
| 25 | 27 | // and asserts the results of JSON.parse at runtime |
| 26 | -function toTopLevel(json: string): TopLevel[] { | |
| 27 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 28 | +function toTopLevel(json: string): TopLevelElement[] { | |
| 29 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 28 | 30 | } |
| 29 | 31 | |
| 30 | -function topLevelToJson(value: TopLevel[]): string { | |
| 31 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 32 | +function topLevelToJson(value: TopLevelElement[]): string { | |
| 33 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 32 | 34 | } |
| 33 | 35 | |
| 34 | 36 | function invalidValue(typ: any, val: any, key: any, parent: any = '') { |
| @@ -185,7 +187,7 @@ function r(name: string) { | ||
| 185 | 187 | } |
| 186 | 188 | |
| 187 | 189 | const typeMap: any = { |
| 188 | - "TopLevel": o([ | |
| 190 | + "TopLevelElement": o([ | |
| 189 | 191 | { json: "age", js: "age", typ: 0 }, |
| 190 | 192 | { json: "country", js: "country", typ: r("Country") }, |
| 191 | 193 | { json: "females", js: "females", typ: 0 }, |
Mjavascriptdefault / TopLevel.js+3 −3
| @@ -10,11 +10,11 @@ | ||
| 10 | 10 | // Converts JSON strings to/from your types |
| 11 | 11 | // and asserts the results of JSON.parse at runtime |
| 12 | 12 | function toTopLevel(json) { |
| 13 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 13 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | function topLevelToJson(value) { |
| 17 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 17 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | function invalidValue(typ, val, key, parent = '') { |
| @@ -171,7 +171,7 @@ function r(name) { | ||
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | const typeMap = { |
| 174 | - "TopLevel": o([ | |
| 174 | + "TopLevelElement": o([ | |
| 175 | 175 | { json: "age", js: "age", typ: 0 }, |
| 176 | 176 | { json: "country", js: "country", typ: r("Country") }, |
| 177 | 177 | { json: "females", js: "females", typ: 0 }, |
Mtypescriptdefault / TopLevel.ts+8 −6
| @@ -7,7 +7,9 @@ | ||
| 7 | 7 | // These functions will throw an error if the JSON doesn't |
| 8 | 8 | // match the expected interface, even if the JSON is valid. |
| 9 | 9 | |
| 10 | -export interface TopLevel { | |
| 10 | +export type TopLevel = TopLevelElement[]; | |
| 11 | + | |
| 12 | +export interface TopLevelElement { | |
| 11 | 13 | age: number; |
| 12 | 14 | country: Country; |
| 13 | 15 | females: number; |
| @@ -21,12 +23,12 @@ export type Country = "United States"; | ||
| 21 | 23 | // Converts JSON strings to/from your types |
| 22 | 24 | // and asserts the results of JSON.parse at runtime |
| 23 | 25 | export class Convert { |
| 24 | - public static toTopLevel(json: string): TopLevel[] { | |
| 25 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 26 | + public static toTopLevel(json: string): TopLevelElement[] { | |
| 27 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 26 | 28 | } |
| 27 | 29 | |
| 28 | - public static topLevelToJson(value: TopLevel[]): string { | |
| 29 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 30 | + public static topLevelToJson(value: TopLevelElement[]): string { | |
| 31 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 30 | 32 | } |
| 31 | 33 | } |
| 32 | 34 | |
| @@ -184,7 +186,7 @@ function r(name: string) { | ||
| 184 | 186 | } |
| 185 | 187 | |
| 186 | 188 | const typeMap: any = { |
| 187 | - "TopLevel": o([ | |
| 189 | + "TopLevelElement": o([ | |
| 188 | 190 | { json: "age", js: "age", typ: 0 }, |
| 189 | 191 | { json: "country", js: "country", typ: r("Country") }, |
| 190 | 192 | { json: "females", js: "females", typ: 0 }, |
Test case
3 generated files · +19 −15test/inputs/json/misc/050b0.json
Mflowdefault / TopLevel.js+8 −6
| @@ -9,7 +9,9 @@ | ||
| 9 | 9 | // These functions will throw an error if the JSON doesn't |
| 10 | 10 | // match the expected interface, even if the JSON is valid. |
| 11 | 11 | |
| 12 | -export type TopLevel = { | |
| 12 | +export type TopLevel = TopLevelElement[]; | |
| 13 | + | |
| 14 | +export type TopLevelElement = { | |
| 13 | 15 | id: string; |
| 14 | 16 | identifiers: Identifier[]; |
| 15 | 17 | keywords: Keyword[]; |
| @@ -69,12 +71,12 @@ export type Title = | ||
| 69 | 71 | |
| 70 | 72 | // Converts JSON strings to/from your types |
| 71 | 73 | // and asserts the results of JSON.parse at runtime |
| 72 | -function toTopLevel(json: string): TopLevel[] { | |
| 73 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 74 | +function toTopLevel(json: string): TopLevelElement[] { | |
| 75 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 74 | 76 | } |
| 75 | 77 | |
| 76 | -function topLevelToJson(value: TopLevel[]): string { | |
| 77 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 78 | +function topLevelToJson(value: TopLevelElement[]): string { | |
| 79 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 78 | 80 | } |
| 79 | 81 | |
| 80 | 82 | function invalidValue(typ: any, val: any, key: any, parent: any = '') { |
| @@ -231,7 +233,7 @@ function r(name: string) { | ||
| 231 | 233 | } |
| 232 | 234 | |
| 233 | 235 | const typeMap: any = { |
| 234 | - "TopLevel": o([ | |
| 236 | + "TopLevelElement": o([ | |
| 235 | 237 | { json: "id", js: "id", typ: "" }, |
| 236 | 238 | { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) }, |
| 237 | 239 | { json: "keywords", js: "keywords", typ: a(r("Keyword")) }, |
Mjavascriptdefault / TopLevel.js+3 −3
| @@ -10,11 +10,11 @@ | ||
| 10 | 10 | // Converts JSON strings to/from your types |
| 11 | 11 | // and asserts the results of JSON.parse at runtime |
| 12 | 12 | function toTopLevel(json) { |
| 13 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 13 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | function topLevelToJson(value) { |
| 17 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 17 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | function invalidValue(typ, val, key, parent = '') { |
| @@ -171,7 +171,7 @@ function r(name) { | ||
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | const typeMap = { |
| 174 | - "TopLevel": o([ | |
| 174 | + "TopLevelElement": o([ | |
| 175 | 175 | { json: "id", js: "id", typ: "" }, |
| 176 | 176 | { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) }, |
| 177 | 177 | { json: "keywords", js: "keywords", typ: a(r("Keyword")) }, |
Mtypescriptdefault / TopLevel.ts+8 −6
| @@ -7,7 +7,9 @@ | ||
| 7 | 7 | // These functions will throw an error if the JSON doesn't |
| 8 | 8 | // match the expected interface, even if the JSON is valid. |
| 9 | 9 | |
| 10 | -export interface TopLevel { | |
| 10 | +export type TopLevel = TopLevelElement[]; | |
| 11 | + | |
| 12 | +export interface TopLevelElement { | |
| 11 | 13 | id: string; |
| 12 | 14 | identifiers: Identifier[]; |
| 13 | 15 | keywords: Keyword[]; |
| @@ -52,12 +54,12 @@ export type Title = "HTML" | "Plain Text"; | ||
| 52 | 54 | // Converts JSON strings to/from your types |
| 53 | 55 | // and asserts the results of JSON.parse at runtime |
| 54 | 56 | export class Convert { |
| 55 | - public static toTopLevel(json: string): TopLevel[] { | |
| 56 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 57 | + public static toTopLevel(json: string): TopLevelElement[] { | |
| 58 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 57 | 59 | } |
| 58 | 60 | |
| 59 | - public static topLevelToJson(value: TopLevel[]): string { | |
| 60 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 61 | + public static topLevelToJson(value: TopLevelElement[]): string { | |
| 62 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 61 | 63 | } |
| 62 | 64 | } |
| 63 | 65 | |
| @@ -215,7 +217,7 @@ function r(name: string) { | ||
| 215 | 217 | } |
| 216 | 218 | |
| 217 | 219 | const typeMap: any = { |
| 218 | - "TopLevel": o([ | |
| 220 | + "TopLevelElement": o([ | |
| 219 | 221 | { json: "id", js: "id", typ: "" }, |
| 220 | 222 | { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) }, |
| 221 | 223 | { json: "keywords", js: "keywords", typ: a(r("Keyword")) }, |
Test case
3 generated files · +19 −15test/inputs/json/misc/06bee.json
Mflowdefault / TopLevel.js+8 −6
| @@ -9,7 +9,9 @@ | ||
| 9 | 9 | // These functions will throw an error if the JSON doesn't |
| 10 | 10 | // match the expected interface, even if the JSON is valid. |
| 11 | 11 | |
| 12 | -export type TopLevel = { | |
| 12 | +export type TopLevel = TopLevelElement[]; | |
| 13 | + | |
| 14 | +export type TopLevelElement = { | |
| 13 | 15 | id: string; |
| 14 | 16 | identifiers: Identifier[]; |
| 15 | 17 | keywords: Keyword[]; |
| @@ -57,12 +59,12 @@ export type Title = | ||
| 57 | 59 | |
| 58 | 60 | // Converts JSON strings to/from your types |
| 59 | 61 | // and asserts the results of JSON.parse at runtime |
| 60 | -function toTopLevel(json: string): TopLevel[] { | |
| 61 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 62 | +function toTopLevel(json: string): TopLevelElement[] { | |
| 63 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 62 | 64 | } |
| 63 | 65 | |
| 64 | -function topLevelToJson(value: TopLevel[]): string { | |
| 65 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 66 | +function topLevelToJson(value: TopLevelElement[]): string { | |
| 67 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 66 | 68 | } |
| 67 | 69 | |
| 68 | 70 | function invalidValue(typ: any, val: any, key: any, parent: any = '') { |
| @@ -219,7 +221,7 @@ function r(name: string) { | ||
| 219 | 221 | } |
| 220 | 222 | |
| 221 | 223 | const typeMap: any = { |
| 222 | - "TopLevel": o([ | |
| 224 | + "TopLevelElement": o([ | |
| 223 | 225 | { json: "id", js: "id", typ: "" }, |
| 224 | 226 | { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) }, |
| 225 | 227 | { json: "keywords", js: "keywords", typ: a(r("Keyword")) }, |
Mjavascriptdefault / TopLevel.js+3 −3
| @@ -10,11 +10,11 @@ | ||
| 10 | 10 | // Converts JSON strings to/from your types |
| 11 | 11 | // and asserts the results of JSON.parse at runtime |
| 12 | 12 | function toTopLevel(json) { |
| 13 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 13 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | function topLevelToJson(value) { |
| 17 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 17 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | function invalidValue(typ, val, key, parent = '') { |
| @@ -171,7 +171,7 @@ function r(name) { | ||
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | const typeMap = { |
| 174 | - "TopLevel": o([ | |
| 174 | + "TopLevelElement": o([ | |
| 175 | 175 | { json: "id", js: "id", typ: "" }, |
| 176 | 176 | { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) }, |
| 177 | 177 | { json: "keywords", js: "keywords", typ: a(r("Keyword")) }, |
Mtypescriptdefault / TopLevel.ts+8 −6
| @@ -7,7 +7,9 @@ | ||
| 7 | 7 | // These functions will throw an error if the JSON doesn't |
| 8 | 8 | // match the expected interface, even if the JSON is valid. |
| 9 | 9 | |
| 10 | -export interface TopLevel { | |
| 10 | +export type TopLevel = TopLevelElement[]; | |
| 11 | + | |
| 12 | +export interface TopLevelElement { | |
| 11 | 13 | id: string; |
| 12 | 14 | identifiers: Identifier[]; |
| 13 | 15 | keywords: Keyword[]; |
| @@ -47,12 +49,12 @@ export type Title = "HTML"; | ||
| 47 | 49 | // Converts JSON strings to/from your types |
| 48 | 50 | // and asserts the results of JSON.parse at runtime |
| 49 | 51 | export class Convert { |
| 50 | - public static toTopLevel(json: string): TopLevel[] { | |
| 51 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 52 | + public static toTopLevel(json: string): TopLevelElement[] { | |
| 53 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 52 | 54 | } |
| 53 | 55 | |
| 54 | - public static topLevelToJson(value: TopLevel[]): string { | |
| 55 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 56 | + public static topLevelToJson(value: TopLevelElement[]): string { | |
| 57 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 56 | 58 | } |
| 57 | 59 | } |
| 58 | 60 | |
| @@ -210,7 +212,7 @@ function r(name: string) { | ||
| 210 | 212 | } |
| 211 | 213 | |
| 212 | 214 | const typeMap: any = { |
| 213 | - "TopLevel": o([ | |
| 215 | + "TopLevelElement": o([ | |
| 214 | 216 | { json: "id", js: "id", typ: "" }, |
| 215 | 217 | { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) }, |
| 216 | 218 | { json: "keywords", js: "keywords", typ: a(r("Keyword")) }, |
Test case
3 generated files · +19 −15test/inputs/json/misc/07c75.json
Mflowdefault / TopLevel.js+8 −6
| @@ -9,7 +9,9 @@ | ||
| 9 | 9 | // These functions will throw an error if the JSON doesn't |
| 10 | 10 | // match the expected interface, even if the JSON is valid. |
| 11 | 11 | |
| 12 | -export type TopLevel = { | |
| 12 | +export type TopLevel = TopLevelElement[]; | |
| 13 | + | |
| 14 | +export type TopLevelElement = { | |
| 13 | 15 | id: string; |
| 14 | 16 | identifiers: Identifier[]; |
| 15 | 17 | keywords: string[]; |
| @@ -38,12 +40,12 @@ export type Text = { | ||
| 38 | 40 | |
| 39 | 41 | // Converts JSON strings to/from your types |
| 40 | 42 | // and asserts the results of JSON.parse at runtime |
| 41 | -function toTopLevel(json: string): TopLevel[] { | |
| 42 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 43 | +function toTopLevel(json: string): TopLevelElement[] { | |
| 44 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 43 | 45 | } |
| 44 | 46 | |
| 45 | -function topLevelToJson(value: TopLevel[]): string { | |
| 46 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 47 | +function topLevelToJson(value: TopLevelElement[]): string { | |
| 48 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 47 | 49 | } |
| 48 | 50 | |
| 49 | 51 | function invalidValue(typ: any, val: any, key: any, parent: any = '') { |
| @@ -200,7 +202,7 @@ function r(name: string) { | ||
| 200 | 202 | } |
| 201 | 203 | |
| 202 | 204 | const typeMap: any = { |
| 203 | - "TopLevel": o([ | |
| 205 | + "TopLevelElement": o([ | |
| 204 | 206 | { json: "id", js: "id", typ: "" }, |
| 205 | 207 | { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) }, |
| 206 | 208 | { json: "keywords", js: "keywords", typ: a("") }, |
Mjavascriptdefault / TopLevel.js+3 −3
| @@ -10,11 +10,11 @@ | ||
| 10 | 10 | // Converts JSON strings to/from your types |
| 11 | 11 | // and asserts the results of JSON.parse at runtime |
| 12 | 12 | function toTopLevel(json) { |
| 13 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 13 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | function topLevelToJson(value) { |
| 17 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 17 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | function invalidValue(typ, val, key, parent = '') { |
| @@ -171,7 +171,7 @@ function r(name) { | ||
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | const typeMap = { |
| 174 | - "TopLevel": o([ | |
| 174 | + "TopLevelElement": o([ | |
| 175 | 175 | { json: "id", js: "id", typ: "" }, |
| 176 | 176 | { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) }, |
| 177 | 177 | { json: "keywords", js: "keywords", typ: a("") }, |
Mtypescriptdefault / TopLevel.ts+8 −6
| @@ -7,7 +7,9 @@ | ||
| 7 | 7 | // These functions will throw an error if the JSON doesn't |
| 8 | 8 | // match the expected interface, even if the JSON is valid. |
| 9 | 9 | |
| 10 | -export interface TopLevel { | |
| 10 | +export type TopLevel = TopLevelElement[]; | |
| 11 | + | |
| 12 | +export interface TopLevelElement { | |
| 11 | 13 | id: string; |
| 12 | 14 | identifiers: Identifier[]; |
| 13 | 15 | keywords: string[]; |
| @@ -37,12 +39,12 @@ export interface Text { | ||
| 37 | 39 | // Converts JSON strings to/from your types |
| 38 | 40 | // and asserts the results of JSON.parse at runtime |
| 39 | 41 | export class Convert { |
| 40 | - public static toTopLevel(json: string): TopLevel[] { | |
| 41 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 42 | + public static toTopLevel(json: string): TopLevelElement[] { | |
| 43 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 42 | 44 | } |
| 43 | 45 | |
| 44 | - public static topLevelToJson(value: TopLevel[]): string { | |
| 45 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 46 | + public static topLevelToJson(value: TopLevelElement[]): string { | |
| 47 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 46 | 48 | } |
| 47 | 49 | } |
| 48 | 50 | |
| @@ -200,7 +202,7 @@ function r(name: string) { | ||
| 200 | 202 | } |
| 201 | 203 | |
| 202 | 204 | const typeMap: any = { |
| 203 | - "TopLevel": o([ | |
| 205 | + "TopLevelElement": o([ | |
| 204 | 206 | { json: "id", js: "id", typ: "" }, |
| 205 | 207 | { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) }, |
| 206 | 208 | { json: "keywords", js: "keywords", typ: a("") }, |
Test case
3 generated files · +19 −15test/inputs/json/misc/0a91a.json
Mflowdefault / TopLevel.js+8 −6
| @@ -9,7 +9,9 @@ | ||
| 9 | 9 | // These functions will throw an error if the JSON doesn't |
| 10 | 10 | // match the expected interface, even if the JSON is valid. |
| 11 | 11 | |
| 12 | -export type TopLevel = { | |
| 12 | +export type TopLevel = TopLevelElement[]; | |
| 13 | + | |
| 14 | +export type TopLevelElement = { | |
| 13 | 15 | actor: Actor; |
| 14 | 16 | created_at: Date; |
| 15 | 17 | id: string; |
| @@ -233,12 +235,12 @@ export type Type = | ||
| 233 | 235 | |
| 234 | 236 | // Converts JSON strings to/from your types |
| 235 | 237 | // and asserts the results of JSON.parse at runtime |
| 236 | -function toTopLevel(json: string): TopLevel[] { | |
| 237 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 238 | +function toTopLevel(json: string): TopLevelElement[] { | |
| 239 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 238 | 240 | } |
| 239 | 241 | |
| 240 | -function topLevelToJson(value: TopLevel[]): string { | |
| 241 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 242 | +function topLevelToJson(value: TopLevelElement[]): string { | |
| 243 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 242 | 244 | } |
| 243 | 245 | |
| 244 | 246 | function invalidValue(typ: any, val: any, key: any, parent: any = '') { |
| @@ -395,7 +397,7 @@ function r(name: string) { | ||
| 395 | 397 | } |
| 396 | 398 | |
| 397 | 399 | const typeMap: any = { |
| 398 | - "TopLevel": o([ | |
| 400 | + "TopLevelElement": o([ | |
| 399 | 401 | { json: "actor", js: "actor", typ: r("Actor") }, |
| 400 | 402 | { json: "created_at", js: "created_at", typ: Date }, |
| 401 | 403 | { json: "id", js: "id", typ: "" }, |
Mjavascriptdefault / TopLevel.js+3 −3
| @@ -10,11 +10,11 @@ | ||
| 10 | 10 | // Converts JSON strings to/from your types |
| 11 | 11 | // and asserts the results of JSON.parse at runtime |
| 12 | 12 | function toTopLevel(json) { |
| 13 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 13 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | function topLevelToJson(value) { |
| 17 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 17 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | function invalidValue(typ, val, key, parent = '') { |
| @@ -171,7 +171,7 @@ function r(name) { | ||
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | const typeMap = { |
| 174 | - "TopLevel": o([ | |
| 174 | + "TopLevelElement": o([ | |
| 175 | 175 | { json: "actor", js: "actor", typ: r("Actor") }, |
| 176 | 176 | { json: "created_at", js: "created_at", typ: Date }, |
| 177 | 177 | { json: "id", js: "id", typ: "" }, |
Mtypescriptdefault / TopLevel.ts+8 −6
| @@ -7,7 +7,9 @@ | ||
| 7 | 7 | // These functions will throw an error if the JSON doesn't |
| 8 | 8 | // match the expected interface, even if the JSON is valid. |
| 9 | 9 | |
| 10 | -export interface TopLevel { | |
| 10 | +export type TopLevel = TopLevelElement[]; | |
| 11 | + | |
| 12 | +export interface TopLevelElement { | |
| 11 | 13 | actor: Actor; |
| 12 | 14 | created_at: Date; |
| 13 | 15 | id: string; |
| @@ -227,12 +229,12 @@ export type Type = "PushEvent" | "CreateEvent" | "WatchEvent" | "PullRequestEven | ||
| 227 | 229 | // Converts JSON strings to/from your types |
| 228 | 230 | // and asserts the results of JSON.parse at runtime |
| 229 | 231 | export class Convert { |
| 230 | - public static toTopLevel(json: string): TopLevel[] { | |
| 231 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 232 | + public static toTopLevel(json: string): TopLevelElement[] { | |
| 233 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 232 | 234 | } |
| 233 | 235 | |
| 234 | - public static topLevelToJson(value: TopLevel[]): string { | |
| 235 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 236 | + public static topLevelToJson(value: TopLevelElement[]): string { | |
| 237 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 236 | 238 | } |
| 237 | 239 | } |
| 238 | 240 | |
| @@ -390,7 +392,7 @@ function r(name: string) { | ||
| 390 | 392 | } |
| 391 | 393 | |
| 392 | 394 | const typeMap: any = { |
| 393 | - "TopLevel": o([ | |
| 395 | + "TopLevelElement": o([ | |
| 394 | 396 | { json: "actor", js: "actor", typ: r("Actor") }, |
| 395 | 397 | { json: "created_at", js: "created_at", typ: Date }, |
| 396 | 398 | { json: "id", js: "id", typ: "" }, |
Test case
3 generated files · +19 −15test/inputs/json/misc/10be4.json
Mflowdefault / TopLevel.js+8 −6
| @@ -9,7 +9,9 @@ | ||
| 9 | 9 | // These functions will throw an error if the JSON doesn't |
| 10 | 10 | // match the expected interface, even if the JSON is valid. |
| 11 | 11 | |
| 12 | -export type TopLevel = { | |
| 12 | +export type TopLevel = TopLevelElement[]; | |
| 13 | + | |
| 14 | +export type TopLevelElement = { | |
| 13 | 15 | id: string; |
| 14 | 16 | identifiers: Identifier[]; |
| 15 | 17 | keywords: Keyword[]; |
| @@ -80,12 +82,12 @@ export type Title = | ||
| 80 | 82 | |
| 81 | 83 | // Converts JSON strings to/from your types |
| 82 | 84 | // and asserts the results of JSON.parse at runtime |
| 83 | -function toTopLevel(json: string): TopLevel[] { | |
| 84 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 85 | +function toTopLevel(json: string): TopLevelElement[] { | |
| 86 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 85 | 87 | } |
| 86 | 88 | |
| 87 | -function topLevelToJson(value: TopLevel[]): string { | |
| 88 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 89 | +function topLevelToJson(value: TopLevelElement[]): string { | |
| 90 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 89 | 91 | } |
| 90 | 92 | |
| 91 | 93 | function invalidValue(typ: any, val: any, key: any, parent: any = '') { |
| @@ -242,7 +244,7 @@ function r(name: string) { | ||
| 242 | 244 | } |
| 243 | 245 | |
| 244 | 246 | const typeMap: any = { |
| 245 | - "TopLevel": o([ | |
| 247 | + "TopLevelElement": o([ | |
| 246 | 248 | { json: "id", js: "id", typ: "" }, |
| 247 | 249 | { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) }, |
| 248 | 250 | { json: "keywords", js: "keywords", typ: a(r("Keyword")) }, |
Mjavascriptdefault / TopLevel.js+3 −3
| @@ -10,11 +10,11 @@ | ||
| 10 | 10 | // Converts JSON strings to/from your types |
| 11 | 11 | // and asserts the results of JSON.parse at runtime |
| 12 | 12 | function toTopLevel(json) { |
| 13 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 13 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | function topLevelToJson(value) { |
| 17 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 17 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | function invalidValue(typ, val, key, parent = '') { |
| @@ -171,7 +171,7 @@ function r(name) { | ||
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | const typeMap = { |
| 174 | - "TopLevel": o([ | |
| 174 | + "TopLevelElement": o([ | |
| 175 | 175 | { json: "id", js: "id", typ: "" }, |
| 176 | 176 | { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) }, |
| 177 | 177 | { json: "keywords", js: "keywords", typ: a(r("Keyword")) }, |
Mtypescriptdefault / TopLevel.ts+8 −6
| @@ -7,7 +7,9 @@ | ||
| 7 | 7 | // These functions will throw an error if the JSON doesn't |
| 8 | 8 | // match the expected interface, even if the JSON is valid. |
| 9 | 9 | |
| 10 | -export interface TopLevel { | |
| 10 | +export type TopLevel = TopLevelElement[]; | |
| 11 | + | |
| 12 | +export interface TopLevelElement { | |
| 11 | 13 | id: string; |
| 12 | 14 | identifiers: Identifier[]; |
| 13 | 15 | keywords: Keyword[]; |
| @@ -52,12 +54,12 @@ export type Title = "HTML" | "Plain Text" | "PDF"; | ||
| 52 | 54 | // Converts JSON strings to/from your types |
| 53 | 55 | // and asserts the results of JSON.parse at runtime |
| 54 | 56 | export class Convert { |
| 55 | - public static toTopLevel(json: string): TopLevel[] { | |
| 56 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 57 | + public static toTopLevel(json: string): TopLevelElement[] { | |
| 58 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 57 | 59 | } |
| 58 | 60 | |
| 59 | - public static topLevelToJson(value: TopLevel[]): string { | |
| 60 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 61 | + public static topLevelToJson(value: TopLevelElement[]): string { | |
| 62 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 61 | 63 | } |
| 62 | 64 | } |
| 63 | 65 | |
| @@ -215,7 +217,7 @@ function r(name: string) { | ||
| 215 | 217 | } |
| 216 | 218 | |
| 217 | 219 | const typeMap: any = { |
| 218 | - "TopLevel": o([ | |
| 220 | + "TopLevelElement": o([ | |
| 219 | 221 | { json: "id", js: "id", typ: "" }, |
| 220 | 222 | { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) }, |
| 221 | 223 | { json: "keywords", js: "keywords", typ: a(r("Keyword")) }, |
Test case
3 generated files · +19 −15test/inputs/json/misc/13d8d.json
Mflowdefault / TopLevel.js+8 −6
| @@ -9,7 +9,9 @@ | ||
| 9 | 9 | // These functions will throw an error if the JSON doesn't |
| 10 | 10 | // match the expected interface, even if the JSON is valid. |
| 11 | 11 | |
| 12 | -export type TopLevel = { | |
| 12 | +export type TopLevel = TopLevelElement[]; | |
| 13 | + | |
| 14 | +export type TopLevelElement = { | |
| 13 | 15 | category: string; |
| 14 | 16 | context: string; |
| 15 | 17 | id: number; |
| @@ -39,12 +41,12 @@ export type OutcomeStatus = { | ||
| 39 | 41 | |
| 40 | 42 | // Converts JSON strings to/from your types |
| 41 | 43 | // and asserts the results of JSON.parse at runtime |
| 42 | -function toTopLevel(json: string): TopLevel[] { | |
| 43 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 44 | +function toTopLevel(json: string): TopLevelElement[] { | |
| 45 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 44 | 46 | } |
| 45 | 47 | |
| 46 | -function topLevelToJson(value: TopLevel[]): string { | |
| 47 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 48 | +function topLevelToJson(value: TopLevelElement[]): string { | |
| 49 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 48 | 50 | } |
| 49 | 51 | |
| 50 | 52 | function invalidValue(typ: any, val: any, key: any, parent: any = '') { |
| @@ -201,7 +203,7 @@ function r(name: string) { | ||
| 201 | 203 | } |
| 202 | 204 | |
| 203 | 205 | const typeMap: any = { |
| 204 | - "TopLevel": o([ | |
| 206 | + "TopLevelElement": o([ | |
| 205 | 207 | { json: "category", js: "category", typ: "" }, |
| 206 | 208 | { json: "context", js: "context", typ: "" }, |
| 207 | 209 | { json: "id", js: "id", typ: 0 }, |
Mjavascriptdefault / TopLevel.js+3 −3
| @@ -10,11 +10,11 @@ | ||
| 10 | 10 | // Converts JSON strings to/from your types |
| 11 | 11 | // and asserts the results of JSON.parse at runtime |
| 12 | 12 | function toTopLevel(json) { |
| 13 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 13 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | function topLevelToJson(value) { |
| 17 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 17 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | function invalidValue(typ, val, key, parent = '') { |
| @@ -171,7 +171,7 @@ function r(name) { | ||
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | const typeMap = { |
| 174 | - "TopLevel": o([ | |
| 174 | + "TopLevelElement": o([ | |
| 175 | 175 | { json: "category", js: "category", typ: "" }, |
| 176 | 176 | { json: "context", js: "context", typ: "" }, |
| 177 | 177 | { json: "id", js: "id", typ: 0 }, |
Mtypescriptdefault / TopLevel.ts+8 −6
| @@ -7,7 +7,9 @@ | ||
| 7 | 7 | // These functions will throw an error if the JSON doesn't |
| 8 | 8 | // match the expected interface, even if the JSON is valid. |
| 9 | 9 | |
| 10 | -export interface TopLevel { | |
| 10 | +export type TopLevel = TopLevelElement[]; | |
| 11 | + | |
| 12 | +export interface TopLevelElement { | |
| 11 | 13 | category: string; |
| 12 | 14 | context: string; |
| 13 | 15 | id: number; |
| @@ -38,12 +40,12 @@ export interface OutcomeStatus { | ||
| 38 | 40 | // Converts JSON strings to/from your types |
| 39 | 41 | // and asserts the results of JSON.parse at runtime |
| 40 | 42 | export class Convert { |
| 41 | - public static toTopLevel(json: string): TopLevel[] { | |
| 42 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 43 | + public static toTopLevel(json: string): TopLevelElement[] { | |
| 44 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 43 | 45 | } |
| 44 | 46 | |
| 45 | - public static topLevelToJson(value: TopLevel[]): string { | |
| 46 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 47 | + public static topLevelToJson(value: TopLevelElement[]): string { | |
| 48 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 47 | 49 | } |
| 48 | 50 | } |
| 49 | 51 | |
| @@ -201,7 +203,7 @@ function r(name: string) { | ||
| 201 | 203 | } |
| 202 | 204 | |
| 203 | 205 | const typeMap: any = { |
| 204 | - "TopLevel": o([ | |
| 206 | + "TopLevelElement": o([ | |
| 205 | 207 | { json: "category", js: "category", typ: "" }, |
| 206 | 208 | { json: "context", js: "context", typ: "" }, |
| 207 | 209 | { json: "id", js: "id", typ: 0 }, |
Test case
3 generated files · +19 −15test/inputs/json/misc/1a7f5.json
Mflowdefault / TopLevel.js+8 −6
| @@ -9,7 +9,9 @@ | ||
| 9 | 9 | // These functions will throw an error if the JSON doesn't |
| 10 | 10 | // match the expected interface, even if the JSON is valid. |
| 11 | 11 | |
| 12 | -export type TopLevel = { | |
| 12 | +export type TopLevel = TopLevelElement[]; | |
| 13 | + | |
| 14 | +export type TopLevelElement = { | |
| 13 | 15 | age: number; |
| 14 | 16 | country: Country; |
| 15 | 17 | females: number; |
| @@ -23,12 +25,12 @@ export type Country = | ||
| 23 | 25 | |
| 24 | 26 | // Converts JSON strings to/from your types |
| 25 | 27 | // and asserts the results of JSON.parse at runtime |
| 26 | -function toTopLevel(json: string): TopLevel[] { | |
| 27 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 28 | +function toTopLevel(json: string): TopLevelElement[] { | |
| 29 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 28 | 30 | } |
| 29 | 31 | |
| 30 | -function topLevelToJson(value: TopLevel[]): string { | |
| 31 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 32 | +function topLevelToJson(value: TopLevelElement[]): string { | |
| 33 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 32 | 34 | } |
| 33 | 35 | |
| 34 | 36 | function invalidValue(typ: any, val: any, key: any, parent: any = '') { |
| @@ -185,7 +187,7 @@ function r(name: string) { | ||
| 185 | 187 | } |
| 186 | 188 | |
| 187 | 189 | const typeMap: any = { |
| 188 | - "TopLevel": o([ | |
| 190 | + "TopLevelElement": o([ | |
| 189 | 191 | { json: "age", js: "age", typ: 0 }, |
| 190 | 192 | { json: "country", js: "country", typ: r("Country") }, |
| 191 | 193 | { json: "females", js: "females", typ: 0 }, |
Mjavascriptdefault / TopLevel.js+3 −3
| @@ -10,11 +10,11 @@ | ||
| 10 | 10 | // Converts JSON strings to/from your types |
| 11 | 11 | // and asserts the results of JSON.parse at runtime |
| 12 | 12 | function toTopLevel(json) { |
| 13 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 13 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | function topLevelToJson(value) { |
| 17 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 17 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | function invalidValue(typ, val, key, parent = '') { |
| @@ -171,7 +171,7 @@ function r(name) { | ||
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | const typeMap = { |
| 174 | - "TopLevel": o([ | |
| 174 | + "TopLevelElement": o([ | |
| 175 | 175 | { json: "age", js: "age", typ: 0 }, |
| 176 | 176 | { json: "country", js: "country", typ: r("Country") }, |
| 177 | 177 | { json: "females", js: "females", typ: 0 }, |
Mtypescriptdefault / TopLevel.ts+8 −6
| @@ -7,7 +7,9 @@ | ||
| 7 | 7 | // These functions will throw an error if the JSON doesn't |
| 8 | 8 | // match the expected interface, even if the JSON is valid. |
| 9 | 9 | |
| 10 | -export interface TopLevel { | |
| 10 | +export type TopLevel = TopLevelElement[]; | |
| 11 | + | |
| 12 | +export interface TopLevelElement { | |
| 11 | 13 | age: number; |
| 12 | 14 | country: Country; |
| 13 | 15 | females: number; |
| @@ -21,12 +23,12 @@ export type Country = "United States"; | ||
| 21 | 23 | // Converts JSON strings to/from your types |
| 22 | 24 | // and asserts the results of JSON.parse at runtime |
| 23 | 25 | export class Convert { |
| 24 | - public static toTopLevel(json: string): TopLevel[] { | |
| 25 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 26 | + public static toTopLevel(json: string): TopLevelElement[] { | |
| 27 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 26 | 28 | } |
| 27 | 29 | |
| 28 | - public static topLevelToJson(value: TopLevel[]): string { | |
| 29 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 30 | + public static topLevelToJson(value: TopLevelElement[]): string { | |
| 31 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 30 | 32 | } |
| 31 | 33 | } |
| 32 | 34 | |
| @@ -184,7 +186,7 @@ function r(name: string) { | ||
| 184 | 186 | } |
| 185 | 187 | |
| 186 | 188 | const typeMap: any = { |
| 187 | - "TopLevel": o([ | |
| 189 | + "TopLevelElement": o([ | |
| 188 | 190 | { json: "age", js: "age", typ: 0 }, |
| 189 | 191 | { json: "country", js: "country", typ: r("Country") }, |
| 190 | 192 | { json: "females", js: "females", typ: 0 }, |
Test case
3 generated files · +26 −22test/inputs/json/misc/2df80.json
Mflowdefault / TopLevel.js+11 −9
| @@ -9,9 +9,11 @@ | ||
| 9 | 9 | // These functions will throw an error if the JSON doesn't |
| 10 | 10 | // match the expected interface, even if the JSON is valid. |
| 11 | 11 | |
| 12 | -export type TopLevel = TopLevelElement[] | PurpleTopLevel; | |
| 12 | +export type TopLevel = TopLevelUnion[]; | |
| 13 | 13 | |
| 14 | -export type TopLevelElement = { | |
| 14 | +export type TopLevelUnion = PurpleTopLevel[] | FluffyTopLevel; | |
| 15 | + | |
| 16 | +export type PurpleTopLevel = { | |
| 15 | 17 | adminregion: Adminregion; |
| 16 | 18 | capitalCity: string; |
| 17 | 19 | id: string; |
| @@ -77,7 +79,7 @@ export type Value = | ||
| 77 | 79 | | "East Asia & Pacific" |
| 78 | 80 | | "North America"; |
| 79 | 81 | |
| 80 | -export type PurpleTopLevel = { | |
| 82 | +export type FluffyTopLevel = { | |
| 81 | 83 | page: number; |
| 82 | 84 | pages: number; |
| 83 | 85 | per_page: string; |
| @@ -86,12 +88,12 @@ export type PurpleTopLevel = { | ||
| 86 | 88 | |
| 87 | 89 | // Converts JSON strings to/from your types |
| 88 | 90 | // and asserts the results of JSON.parse at runtime |
| 89 | -function toTopLevel(json: string): TopLevel[] { | |
| 90 | - return cast(JSON.parse(json), a(u(a(r("TopLevelElement")), r("PurpleTopLevel")))); | |
| 91 | +function toTopLevel(json: string): TopLevelUnion[] { | |
| 92 | + return cast(JSON.parse(json), a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel")))); | |
| 91 | 93 | } |
| 92 | 94 | |
| 93 | -function topLevelToJson(value: TopLevel[]): string { | |
| 94 | - return JSON.stringify(uncast(value, a(u(a(r("TopLevelElement")), r("PurpleTopLevel")))), null, 2); | |
| 95 | +function topLevelToJson(value: TopLevelUnion[]): string { | |
| 96 | + return JSON.stringify(uncast(value, a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel")))), null, 2); | |
| 95 | 97 | } |
| 96 | 98 | |
| 97 | 99 | function invalidValue(typ: any, val: any, key: any, parent: any = '') { |
| @@ -248,7 +250,7 @@ function r(name: string) { | ||
| 248 | 250 | } |
| 249 | 251 | |
| 250 | 252 | const typeMap: any = { |
| 251 | - "TopLevelElement": o([ | |
| 253 | + "PurpleTopLevel": o([ | |
| 252 | 254 | { json: "adminregion", js: "adminregion", typ: r("Adminregion") }, |
| 253 | 255 | { json: "capitalCity", js: "capitalCity", typ: "" }, |
| 254 | 256 | { json: "id", js: "id", typ: "" }, |
| @@ -264,7 +266,7 @@ const typeMap: any = { | ||
| 264 | 266 | { json: "id", js: "id", typ: r("ID") }, |
| 265 | 267 | { json: "value", js: "value", typ: r("Value") }, |
| 266 | 268 | ], false), |
| 267 | - "PurpleTopLevel": o([ | |
| 269 | + "FluffyTopLevel": o([ | |
| 268 | 270 | { json: "page", js: "page", typ: 0 }, |
| 269 | 271 | { json: "pages", js: "pages", typ: 0 }, |
| 270 | 272 | { json: "per_page", js: "per_page", typ: "" }, |
Mjavascriptdefault / TopLevel.js+4 −4
| @@ -10,11 +10,11 @@ | ||
| 10 | 10 | // Converts JSON strings to/from your types |
| 11 | 11 | // and asserts the results of JSON.parse at runtime |
| 12 | 12 | function toTopLevel(json) { |
| 13 | - return cast(JSON.parse(json), a(u(a(r("TopLevelElement")), r("PurpleTopLevel")))); | |
| 13 | + return cast(JSON.parse(json), a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel")))); | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | function topLevelToJson(value) { |
| 17 | - return JSON.stringify(uncast(value, a(u(a(r("TopLevelElement")), r("PurpleTopLevel")))), null, 2); | |
| 17 | + return JSON.stringify(uncast(value, a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel")))), null, 2); | |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | function invalidValue(typ, val, key, parent = '') { |
| @@ -171,7 +171,7 @@ function r(name) { | ||
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | const typeMap = { |
| 174 | - "TopLevelElement": o([ | |
| 174 | + "PurpleTopLevel": o([ | |
| 175 | 175 | { json: "adminregion", js: "adminregion", typ: r("Adminregion") }, |
| 176 | 176 | { json: "capitalCity", js: "capitalCity", typ: "" }, |
| 177 | 177 | { json: "id", js: "id", typ: "" }, |
| @@ -187,7 +187,7 @@ const typeMap = { | ||
| 187 | 187 | { json: "id", js: "id", typ: r("ID") }, |
| 188 | 188 | { json: "value", js: "value", typ: r("Value") }, |
| 189 | 189 | ], false), |
| 190 | - "PurpleTopLevel": o([ | |
| 190 | + "FluffyTopLevel": o([ | |
| 191 | 191 | { json: "page", js: "page", typ: 0 }, |
| 192 | 192 | { json: "pages", js: "pages", typ: 0 }, |
| 193 | 193 | { json: "per_page", js: "per_page", typ: "" }, |
Mtypescriptdefault / TopLevel.ts+11 −9
| @@ -7,9 +7,11 @@ | ||
| 7 | 7 | // These functions will throw an error if the JSON doesn't |
| 8 | 8 | // match the expected interface, even if the JSON is valid. |
| 9 | 9 | |
| 10 | -export type TopLevel = TopLevelElement[] | PurpleTopLevel; | |
| 10 | +export type TopLevel = TopLevelUnion[]; | |
| 11 | 11 | |
| 12 | -export interface TopLevelElement { | |
| 12 | +export type TopLevelUnion = PurpleTopLevel[] | FluffyTopLevel; | |
| 13 | + | |
| 14 | +export interface PurpleTopLevel { | |
| 13 | 15 | adminregion: Adminregion; |
| 14 | 16 | capitalCity: string; |
| 15 | 17 | id: string; |
| @@ -31,7 +33,7 @@ export type ID = "" | "SAS" | "SSA" | "ECA" | "LAC" | "EAP" | "MNA" | "HIC" | "L | ||
| 31 | 33 | |
| 32 | 34 | export type Value = "" | "South Asia" | "Sub-Saharan Africa (excluding high income)" | "Europe & Central Asia (excluding high income)" | "Latin America & Caribbean (excluding high income)" | "East Asia & Pacific (excluding high income)" | "Middle East & North Africa (excluding high income)" | "High income" | "Low income" | "Aggregates" | "Lower middle income" | "Upper middle income" | "Not classified" | "IDA" | "IBRD" | "Blend" | "Latin America & Caribbean " | "Sub-Saharan Africa " | "Europe & Central Asia" | "Middle East & North Africa" | "East Asia & Pacific" | "North America"; |
| 33 | 35 | |
| 34 | -export interface PurpleTopLevel { | |
| 36 | +export interface FluffyTopLevel { | |
| 35 | 37 | page: number; |
| 36 | 38 | pages: number; |
| 37 | 39 | per_page: string; |
| @@ -41,12 +43,12 @@ export interface PurpleTopLevel { | ||
| 41 | 43 | // Converts JSON strings to/from your types |
| 42 | 44 | // and asserts the results of JSON.parse at runtime |
| 43 | 45 | export class Convert { |
| 44 | - public static toTopLevel(json: string): TopLevel[] { | |
| 45 | - return cast(JSON.parse(json), a(u(a(r("TopLevelElement")), r("PurpleTopLevel")))); | |
| 46 | + public static toTopLevel(json: string): TopLevelUnion[] { | |
| 47 | + return cast(JSON.parse(json), a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel")))); | |
| 46 | 48 | } |
| 47 | 49 | |
| 48 | - public static topLevelToJson(value: TopLevel[]): string { | |
| 49 | - return JSON.stringify(uncast(value, a(u(a(r("TopLevelElement")), r("PurpleTopLevel")))), null, 2); | |
| 50 | + public static topLevelToJson(value: TopLevelUnion[]): string { | |
| 51 | + return JSON.stringify(uncast(value, a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel")))), null, 2); | |
| 50 | 52 | } |
| 51 | 53 | } |
| 52 | 54 | |
| @@ -204,7 +206,7 @@ function r(name: string) { | ||
| 204 | 206 | } |
| 205 | 207 | |
| 206 | 208 | const typeMap: any = { |
| 207 | - "TopLevelElement": o([ | |
| 209 | + "PurpleTopLevel": o([ | |
| 208 | 210 | { json: "adminregion", js: "adminregion", typ: r("Adminregion") }, |
| 209 | 211 | { json: "capitalCity", js: "capitalCity", typ: "" }, |
| 210 | 212 | { json: "id", js: "id", typ: "" }, |
| @@ -220,7 +222,7 @@ const typeMap: any = { | ||
| 220 | 222 | { json: "id", js: "id", typ: r("ID") }, |
| 221 | 223 | { json: "value", js: "value", typ: r("Value") }, |
| 222 | 224 | ], false), |
| 223 | - "PurpleTopLevel": o([ | |
| 225 | + "FluffyTopLevel": o([ | |
| 224 | 226 | { json: "page", js: "page", typ: 0 }, |
| 225 | 227 | { json: "pages", js: "pages", typ: 0 }, |
| 226 | 228 | { json: "per_page", js: "per_page", typ: "" }, |
Test case
3 generated files · +19 −15test/inputs/json/misc/32d5c.json
Mflowdefault / TopLevel.js+8 −6
| @@ -9,7 +9,9 @@ | ||
| 9 | 9 | // These functions will throw an error if the JSON doesn't |
| 10 | 10 | // match the expected interface, even if the JSON is valid. |
| 11 | 11 | |
| 12 | -export type TopLevel = { | |
| 12 | +export type TopLevel = TopLevelElement[]; | |
| 13 | + | |
| 14 | +export type TopLevelElement = { | |
| 13 | 15 | BirthDate: Date | null; |
| 14 | 16 | BirthDateIsProtected: boolean; |
| 15 | 17 | GenderTypeID: number; |
| @@ -22,12 +24,12 @@ export type TopLevel = { | ||
| 22 | 24 | |
| 23 | 25 | // Converts JSON strings to/from your types |
| 24 | 26 | // and asserts the results of JSON.parse at runtime |
| 25 | -function toTopLevel(json: string): TopLevel[] { | |
| 26 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 27 | +function toTopLevel(json: string): TopLevelElement[] { | |
| 28 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 27 | 29 | } |
| 28 | 30 | |
| 29 | -function topLevelToJson(value: TopLevel[]): string { | |
| 30 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 31 | +function topLevelToJson(value: TopLevelElement[]): string { | |
| 32 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 31 | 33 | } |
| 32 | 34 | |
| 33 | 35 | function invalidValue(typ: any, val: any, key: any, parent: any = '') { |
| @@ -184,7 +186,7 @@ function r(name: string) { | ||
| 184 | 186 | } |
| 185 | 187 | |
| 186 | 188 | const typeMap: any = { |
| 187 | - "TopLevel": o([ | |
| 189 | + "TopLevelElement": o([ | |
| 188 | 190 | { json: "BirthDate", js: "BirthDate", typ: u(Date, null) }, |
| 189 | 191 | { json: "BirthDateIsProtected", js: "BirthDateIsProtected", typ: true }, |
| 190 | 192 | { json: "GenderTypeID", js: "GenderTypeID", typ: 0 }, |
Mjavascriptdefault / TopLevel.js+3 −3
| @@ -10,11 +10,11 @@ | ||
| 10 | 10 | // Converts JSON strings to/from your types |
| 11 | 11 | // and asserts the results of JSON.parse at runtime |
| 12 | 12 | function toTopLevel(json) { |
| 13 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 13 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | function topLevelToJson(value) { |
| 17 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 17 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | function invalidValue(typ, val, key, parent = '') { |
| @@ -171,7 +171,7 @@ function r(name) { | ||
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | const typeMap = { |
| 174 | - "TopLevel": o([ | |
| 174 | + "TopLevelElement": o([ | |
| 175 | 175 | { json: "BirthDate", js: "BirthDate", typ: u(Date, null) }, |
| 176 | 176 | { json: "BirthDateIsProtected", js: "BirthDateIsProtected", typ: true }, |
| 177 | 177 | { json: "GenderTypeID", js: "GenderTypeID", typ: 0 }, |
Mtypescriptdefault / TopLevel.ts+8 −6
| @@ -7,7 +7,9 @@ | ||
| 7 | 7 | // These functions will throw an error if the JSON doesn't |
| 8 | 8 | // match the expected interface, even if the JSON is valid. |
| 9 | 9 | |
| 10 | -export interface TopLevel { | |
| 10 | +export type TopLevel = TopLevelElement[]; | |
| 11 | + | |
| 12 | +export interface TopLevelElement { | |
| 11 | 13 | BirthDate: Date | null; |
| 12 | 14 | BirthDateIsProtected: boolean; |
| 13 | 15 | GenderTypeID: number; |
| @@ -21,12 +23,12 @@ export interface TopLevel { | ||
| 21 | 23 | // Converts JSON strings to/from your types |
| 22 | 24 | // and asserts the results of JSON.parse at runtime |
| 23 | 25 | export class Convert { |
| 24 | - public static toTopLevel(json: string): TopLevel[] { | |
| 25 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 26 | + public static toTopLevel(json: string): TopLevelElement[] { | |
| 27 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 26 | 28 | } |
| 27 | 29 | |
| 28 | - public static topLevelToJson(value: TopLevel[]): string { | |
| 29 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 30 | + public static topLevelToJson(value: TopLevelElement[]): string { | |
| 31 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 30 | 32 | } |
| 31 | 33 | } |
| 32 | 34 | |
| @@ -184,7 +186,7 @@ function r(name: string) { | ||
| 184 | 186 | } |
| 185 | 187 | |
| 186 | 188 | const typeMap: any = { |
| 187 | - "TopLevel": o([ | |
| 189 | + "TopLevelElement": o([ | |
| 188 | 190 | { json: "BirthDate", js: "BirthDate", typ: u(Date, null) }, |
| 189 | 191 | { json: "BirthDateIsProtected", js: "BirthDateIsProtected", typ: true }, |
| 190 | 192 | { json: "GenderTypeID", js: "GenderTypeID", typ: 0 }, |
Test case
3 generated files · +19 −15test/inputs/json/misc/3536b.json
Mflowdefault / TopLevel.js+8 −6
| @@ -9,7 +9,9 @@ | ||
| 9 | 9 | // These functions will throw an error if the JSON doesn't |
| 10 | 10 | // match the expected interface, even if the JSON is valid. |
| 11 | 11 | |
| 12 | -export type TopLevel = { | |
| 12 | +export type TopLevel = TopLevelElement[]; | |
| 13 | + | |
| 14 | +export type TopLevelElement = { | |
| 13 | 15 | id: string; |
| 14 | 16 | identifiers: Identifier[]; |
| 15 | 17 | keywords: Keyword[]; |
| @@ -48,12 +50,12 @@ export type Text = { | ||
| 48 | 50 | |
| 49 | 51 | // Converts JSON strings to/from your types |
| 50 | 52 | // and asserts the results of JSON.parse at runtime |
| 51 | -function toTopLevel(json: string): TopLevel[] { | |
| 52 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 53 | +function toTopLevel(json: string): TopLevelElement[] { | |
| 54 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 53 | 55 | } |
| 54 | 56 | |
| 55 | -function topLevelToJson(value: TopLevel[]): string { | |
| 56 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 57 | +function topLevelToJson(value: TopLevelElement[]): string { | |
| 58 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 57 | 59 | } |
| 58 | 60 | |
| 59 | 61 | function invalidValue(typ: any, val: any, key: any, parent: any = '') { |
| @@ -210,7 +212,7 @@ function r(name: string) { | ||
| 210 | 212 | } |
| 211 | 213 | |
| 212 | 214 | const typeMap: any = { |
| 213 | - "TopLevel": o([ | |
| 215 | + "TopLevelElement": o([ | |
| 214 | 216 | { json: "id", js: "id", typ: "" }, |
| 215 | 217 | { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) }, |
| 216 | 218 | { json: "keywords", js: "keywords", typ: a(r("Keyword")) }, |
Mjavascriptdefault / TopLevel.js+3 −3
| @@ -10,11 +10,11 @@ | ||
| 10 | 10 | // Converts JSON strings to/from your types |
| 11 | 11 | // and asserts the results of JSON.parse at runtime |
| 12 | 12 | function toTopLevel(json) { |
| 13 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 13 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | function topLevelToJson(value) { |
| 17 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 17 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | function invalidValue(typ, val, key, parent = '') { |
| @@ -171,7 +171,7 @@ function r(name) { | ||
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | const typeMap = { |
| 174 | - "TopLevel": o([ | |
| 174 | + "TopLevelElement": o([ | |
| 175 | 175 | { json: "id", js: "id", typ: "" }, |
| 176 | 176 | { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) }, |
| 177 | 177 | { json: "keywords", js: "keywords", typ: a(r("Keyword")) }, |
Mtypescriptdefault / TopLevel.ts+8 −6
| @@ -7,7 +7,9 @@ | ||
| 7 | 7 | // These functions will throw an error if the JSON doesn't |
| 8 | 8 | // match the expected interface, even if the JSON is valid. |
| 9 | 9 | |
| 10 | -export interface TopLevel { | |
| 10 | +export type TopLevel = TopLevelElement[]; | |
| 11 | + | |
| 12 | +export interface TopLevelElement { | |
| 11 | 13 | id: string; |
| 12 | 14 | identifiers: Identifier[]; |
| 13 | 15 | keywords: Keyword[]; |
| @@ -41,12 +43,12 @@ export interface Text { | ||
| 41 | 43 | // Converts JSON strings to/from your types |
| 42 | 44 | // and asserts the results of JSON.parse at runtime |
| 43 | 45 | export class Convert { |
| 44 | - public static toTopLevel(json: string): TopLevel[] { | |
| 45 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 46 | + public static toTopLevel(json: string): TopLevelElement[] { | |
| 47 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 46 | 48 | } |
| 47 | 49 | |
| 48 | - public static topLevelToJson(value: TopLevel[]): string { | |
| 49 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 50 | + public static topLevelToJson(value: TopLevelElement[]): string { | |
| 51 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 50 | 52 | } |
| 51 | 53 | } |
| 52 | 54 | |
| @@ -204,7 +206,7 @@ function r(name: string) { | ||
| 204 | 206 | } |
| 205 | 207 | |
| 206 | 208 | const typeMap: any = { |
| 207 | - "TopLevel": o([ | |
| 209 | + "TopLevelElement": o([ | |
| 208 | 210 | { json: "id", js: "id", typ: "" }, |
| 209 | 211 | { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) }, |
| 210 | 212 | { json: "keywords", js: "keywords", typ: a(r("Keyword")) }, |
Test case
3 generated files · +19 −15test/inputs/json/misc/43970.json
Mflowdefault / TopLevel.js+8 −6
| @@ -9,7 +9,9 @@ | ||
| 9 | 9 | // These functions will throw an error if the JSON doesn't |
| 10 | 10 | // match the expected interface, even if the JSON is valid. |
| 11 | 11 | |
| 12 | -export type TopLevel = { | |
| 12 | +export type TopLevel = TopLevelElement[]; | |
| 13 | + | |
| 14 | +export type TopLevelElement = { | |
| 13 | 15 | ID: number; |
| 14 | 16 | Name: string; |
| 15 | 17 | Notes: string; |
| @@ -17,12 +19,12 @@ export type TopLevel = { | ||
| 17 | 19 | |
| 18 | 20 | // Converts JSON strings to/from your types |
| 19 | 21 | // and asserts the results of JSON.parse at runtime |
| 20 | -function toTopLevel(json: string): TopLevel[] { | |
| 21 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 22 | +function toTopLevel(json: string): TopLevelElement[] { | |
| 23 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 22 | 24 | } |
| 23 | 25 | |
| 24 | -function topLevelToJson(value: TopLevel[]): string { | |
| 25 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 26 | +function topLevelToJson(value: TopLevelElement[]): string { | |
| 27 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 26 | 28 | } |
| 27 | 29 | |
| 28 | 30 | function invalidValue(typ: any, val: any, key: any, parent: any = '') { |
| @@ -179,7 +181,7 @@ function r(name: string) { | ||
| 179 | 181 | } |
| 180 | 182 | |
| 181 | 183 | const typeMap: any = { |
| 182 | - "TopLevel": o([ | |
| 184 | + "TopLevelElement": o([ | |
| 183 | 185 | { json: "ID", js: "ID", typ: 0 }, |
| 184 | 186 | { json: "Name", js: "Name", typ: "" }, |
| 185 | 187 | { json: "Notes", js: "Notes", typ: "" }, |
Mjavascriptdefault / TopLevel.js+3 −3
| @@ -10,11 +10,11 @@ | ||
| 10 | 10 | // Converts JSON strings to/from your types |
| 11 | 11 | // and asserts the results of JSON.parse at runtime |
| 12 | 12 | function toTopLevel(json) { |
| 13 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 13 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | function topLevelToJson(value) { |
| 17 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 17 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | function invalidValue(typ, val, key, parent = '') { |
| @@ -171,7 +171,7 @@ function r(name) { | ||
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | const typeMap = { |
| 174 | - "TopLevel": o([ | |
| 174 | + "TopLevelElement": o([ | |
| 175 | 175 | { json: "ID", js: "ID", typ: 0 }, |
| 176 | 176 | { json: "Name", js: "Name", typ: "" }, |
| 177 | 177 | { json: "Notes", js: "Notes", typ: "" }, |
Mtypescriptdefault / TopLevel.ts+8 −6
| @@ -7,7 +7,9 @@ | ||
| 7 | 7 | // These functions will throw an error if the JSON doesn't |
| 8 | 8 | // match the expected interface, even if the JSON is valid. |
| 9 | 9 | |
| 10 | -export interface TopLevel { | |
| 10 | +export type TopLevel = TopLevelElement[]; | |
| 11 | + | |
| 12 | +export interface TopLevelElement { | |
| 11 | 13 | ID: number; |
| 12 | 14 | Name: string; |
| 13 | 15 | Notes: string; |
| @@ -16,12 +18,12 @@ export interface TopLevel { | ||
| 16 | 18 | // Converts JSON strings to/from your types |
| 17 | 19 | // and asserts the results of JSON.parse at runtime |
| 18 | 20 | export class Convert { |
| 19 | - public static toTopLevel(json: string): TopLevel[] { | |
| 20 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 21 | + public static toTopLevel(json: string): TopLevelElement[] { | |
| 22 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 21 | 23 | } |
| 22 | 24 | |
| 23 | - public static topLevelToJson(value: TopLevel[]): string { | |
| 24 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 25 | + public static topLevelToJson(value: TopLevelElement[]): string { | |
| 26 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 25 | 27 | } |
| 26 | 28 | } |
| 27 | 29 | |
| @@ -179,7 +181,7 @@ function r(name: string) { | ||
| 179 | 181 | } |
| 180 | 182 | |
| 181 | 183 | const typeMap: any = { |
| 182 | - "TopLevel": o([ | |
| 184 | + "TopLevelElement": o([ | |
| 183 | 185 | { json: "ID", js: "ID", typ: 0 }, |
| 184 | 186 | { json: "Name", js: "Name", typ: "" }, |
| 185 | 187 | { json: "Notes", js: "Notes", typ: "" }, |
Test case
3 generated files · +19 −15test/inputs/json/misc/570ec.json
Mflowdefault / TopLevel.js+8 −6
| @@ -9,7 +9,9 @@ | ||
| 9 | 9 | // These functions will throw an error if the JSON doesn't |
| 10 | 10 | // match the expected interface, even if the JSON is valid. |
| 11 | 11 | |
| 12 | -export type TopLevel = { | |
| 12 | +export type TopLevel = TopLevelElement[]; | |
| 13 | + | |
| 14 | +export type TopLevelElement = { | |
| 13 | 15 | id: string; |
| 14 | 16 | identifiers: Identifier[]; |
| 15 | 17 | keywords: string[]; |
| @@ -48,12 +50,12 @@ export type Text = { | ||
| 48 | 50 | |
| 49 | 51 | // Converts JSON strings to/from your types |
| 50 | 52 | // and asserts the results of JSON.parse at runtime |
| 51 | -function toTopLevel(json: string): TopLevel[] { | |
| 52 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 53 | +function toTopLevel(json: string): TopLevelElement[] { | |
| 54 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 53 | 55 | } |
| 54 | 56 | |
| 55 | -function topLevelToJson(value: TopLevel[]): string { | |
| 56 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 57 | +function topLevelToJson(value: TopLevelElement[]): string { | |
| 58 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 57 | 59 | } |
| 58 | 60 | |
| 59 | 61 | function invalidValue(typ: any, val: any, key: any, parent: any = '') { |
| @@ -210,7 +212,7 @@ function r(name: string) { | ||
| 210 | 212 | } |
| 211 | 213 | |
| 212 | 214 | const typeMap: any = { |
| 213 | - "TopLevel": o([ | |
| 215 | + "TopLevelElement": o([ | |
| 214 | 216 | { json: "id", js: "id", typ: "" }, |
| 215 | 217 | { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) }, |
| 216 | 218 | { json: "keywords", js: "keywords", typ: a("") }, |
Mjavascriptdefault / TopLevel.js+3 −3
| @@ -10,11 +10,11 @@ | ||
| 10 | 10 | // Converts JSON strings to/from your types |
| 11 | 11 | // and asserts the results of JSON.parse at runtime |
| 12 | 12 | function toTopLevel(json) { |
| 13 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 13 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | function topLevelToJson(value) { |
| 17 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 17 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | function invalidValue(typ, val, key, parent = '') { |
| @@ -171,7 +171,7 @@ function r(name) { | ||
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | const typeMap = { |
| 174 | - "TopLevel": o([ | |
| 174 | + "TopLevelElement": o([ | |
| 175 | 175 | { json: "id", js: "id", typ: "" }, |
| 176 | 176 | { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) }, |
| 177 | 177 | { json: "keywords", js: "keywords", typ: a("") }, |
Mtypescriptdefault / TopLevel.ts+8 −6
| @@ -7,7 +7,9 @@ | ||
| 7 | 7 | // These functions will throw an error if the JSON doesn't |
| 8 | 8 | // match the expected interface, even if the JSON is valid. |
| 9 | 9 | |
| 10 | -export interface TopLevel { | |
| 10 | +export type TopLevel = TopLevelElement[]; | |
| 11 | + | |
| 12 | +export interface TopLevelElement { | |
| 11 | 13 | id: string; |
| 12 | 14 | identifiers: Identifier[]; |
| 13 | 15 | keywords: string[]; |
| @@ -44,12 +46,12 @@ export interface Text { | ||
| 44 | 46 | // Converts JSON strings to/from your types |
| 45 | 47 | // and asserts the results of JSON.parse at runtime |
| 46 | 48 | export class Convert { |
| 47 | - public static toTopLevel(json: string): TopLevel[] { | |
| 48 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 49 | + public static toTopLevel(json: string): TopLevelElement[] { | |
| 50 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 49 | 51 | } |
| 50 | 52 | |
| 51 | - public static topLevelToJson(value: TopLevel[]): string { | |
| 52 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 53 | + public static topLevelToJson(value: TopLevelElement[]): string { | |
| 54 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 53 | 55 | } |
| 54 | 56 | } |
| 55 | 57 | |
| @@ -207,7 +209,7 @@ function r(name: string) { | ||
| 207 | 209 | } |
| 208 | 210 | |
| 209 | 211 | const typeMap: any = { |
| 210 | - "TopLevel": o([ | |
| 212 | + "TopLevelElement": o([ | |
| 211 | 213 | { json: "id", js: "id", typ: "" }, |
| 212 | 214 | { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) }, |
| 213 | 215 | { json: "keywords", js: "keywords", typ: a("") }, |
Test case
3 generated files · +19 −15test/inputs/json/misc/5eae5.json
Mflowdefault / TopLevel.js+8 −6
| @@ -9,7 +9,9 @@ | ||
| 9 | 9 | // These functions will throw an error if the JSON doesn't |
| 10 | 10 | // match the expected interface, even if the JSON is valid. |
| 11 | 11 | |
| 12 | -export type TopLevel = { | |
| 12 | +export type TopLevel = TopLevelElement[]; | |
| 13 | + | |
| 14 | +export type TopLevelElement = { | |
| 13 | 15 | Date: Date; |
| 14 | 16 | ID: number; |
| 15 | 17 | Sponsor: string; |
| @@ -18,12 +20,12 @@ export type TopLevel = { | ||
| 18 | 20 | |
| 19 | 21 | // Converts JSON strings to/from your types |
| 20 | 22 | // and asserts the results of JSON.parse at runtime |
| 21 | -function toTopLevel(json: string): TopLevel[] { | |
| 22 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 23 | +function toTopLevel(json: string): TopLevelElement[] { | |
| 24 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 23 | 25 | } |
| 24 | 26 | |
| 25 | -function topLevelToJson(value: TopLevel[]): string { | |
| 26 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 27 | +function topLevelToJson(value: TopLevelElement[]): string { | |
| 28 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 27 | 29 | } |
| 28 | 30 | |
| 29 | 31 | function invalidValue(typ: any, val: any, key: any, parent: any = '') { |
| @@ -180,7 +182,7 @@ function r(name: string) { | ||
| 180 | 182 | } |
| 181 | 183 | |
| 182 | 184 | const typeMap: any = { |
| 183 | - "TopLevel": o([ | |
| 185 | + "TopLevelElement": o([ | |
| 184 | 186 | { json: "Date", js: "Date", typ: Date }, |
| 185 | 187 | { json: "ID", js: "ID", typ: 0 }, |
| 186 | 188 | { json: "Sponsor", js: "Sponsor", typ: "" }, |
Mjavascriptdefault / TopLevel.js+3 −3
| @@ -10,11 +10,11 @@ | ||
| 10 | 10 | // Converts JSON strings to/from your types |
| 11 | 11 | // and asserts the results of JSON.parse at runtime |
| 12 | 12 | function toTopLevel(json) { |
| 13 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 13 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | function topLevelToJson(value) { |
| 17 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 17 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | function invalidValue(typ, val, key, parent = '') { |
| @@ -171,7 +171,7 @@ function r(name) { | ||
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | const typeMap = { |
| 174 | - "TopLevel": o([ | |
| 174 | + "TopLevelElement": o([ | |
| 175 | 175 | { json: "Date", js: "Date", typ: Date }, |
| 176 | 176 | { json: "ID", js: "ID", typ: 0 }, |
| 177 | 177 | { json: "Sponsor", js: "Sponsor", typ: "" }, |
Mtypescriptdefault / TopLevel.ts+8 −6
| @@ -7,7 +7,9 @@ | ||
| 7 | 7 | // These functions will throw an error if the JSON doesn't |
| 8 | 8 | // match the expected interface, even if the JSON is valid. |
| 9 | 9 | |
| 10 | -export interface TopLevel { | |
| 10 | +export type TopLevel = TopLevelElement[]; | |
| 11 | + | |
| 12 | +export interface TopLevelElement { | |
| 11 | 13 | Date: Date; |
| 12 | 14 | ID: number; |
| 13 | 15 | Sponsor: string; |
| @@ -17,12 +19,12 @@ export interface TopLevel { | ||
| 17 | 19 | // Converts JSON strings to/from your types |
| 18 | 20 | // and asserts the results of JSON.parse at runtime |
| 19 | 21 | export class Convert { |
| 20 | - public static toTopLevel(json: string): TopLevel[] { | |
| 21 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 22 | + public static toTopLevel(json: string): TopLevelElement[] { | |
| 23 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 22 | 24 | } |
| 23 | 25 | |
| 24 | - public static topLevelToJson(value: TopLevel[]): string { | |
| 25 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 26 | + public static topLevelToJson(value: TopLevelElement[]): string { | |
| 27 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 26 | 28 | } |
| 27 | 29 | } |
| 28 | 30 | |
| @@ -180,7 +182,7 @@ function r(name: string) { | ||
| 180 | 182 | } |
| 181 | 183 | |
| 182 | 184 | const typeMap: any = { |
| 183 | - "TopLevel": o([ | |
| 185 | + "TopLevelElement": o([ | |
| 184 | 186 | { json: "Date", js: "Date", typ: Date }, |
| 185 | 187 | { json: "ID", js: "ID", typ: 0 }, |
| 186 | 188 | { json: "Sponsor", js: "Sponsor", typ: "" }, |
Test case
3 generated files · +19 −15test/inputs/json/misc/66121.json
Mflowdefault / TopLevel.js+8 −6
| @@ -9,7 +9,9 @@ | ||
| 9 | 9 | // These functions will throw an error if the JSON doesn't |
| 10 | 10 | // match the expected interface, even if the JSON is valid. |
| 11 | 11 | |
| 12 | -export type TopLevel = { | |
| 12 | +export type TopLevel = TopLevelElement[]; | |
| 13 | + | |
| 14 | +export type TopLevelElement = { | |
| 13 | 15 | id: string; |
| 14 | 16 | identifiers: Identifier[]; |
| 15 | 17 | keywords: Keyword[]; |
| @@ -57,12 +59,12 @@ export type Title = | ||
| 57 | 59 | |
| 58 | 60 | // Converts JSON strings to/from your types |
| 59 | 61 | // and asserts the results of JSON.parse at runtime |
| 60 | -function toTopLevel(json: string): TopLevel[] { | |
| 61 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 62 | +function toTopLevel(json: string): TopLevelElement[] { | |
| 63 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 62 | 64 | } |
| 63 | 65 | |
| 64 | -function topLevelToJson(value: TopLevel[]): string { | |
| 65 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 66 | +function topLevelToJson(value: TopLevelElement[]): string { | |
| 67 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 66 | 68 | } |
| 67 | 69 | |
| 68 | 70 | function invalidValue(typ: any, val: any, key: any, parent: any = '') { |
| @@ -219,7 +221,7 @@ function r(name: string) { | ||
| 219 | 221 | } |
| 220 | 222 | |
| 221 | 223 | const typeMap: any = { |
| 222 | - "TopLevel": o([ | |
| 224 | + "TopLevelElement": o([ | |
| 223 | 225 | { json: "id", js: "id", typ: "" }, |
| 224 | 226 | { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) }, |
| 225 | 227 | { json: "keywords", js: "keywords", typ: a(r("Keyword")) }, |
Mjavascriptdefault / TopLevel.js+3 −3
| @@ -10,11 +10,11 @@ | ||
| 10 | 10 | // Converts JSON strings to/from your types |
| 11 | 11 | // and asserts the results of JSON.parse at runtime |
| 12 | 12 | function toTopLevel(json) { |
| 13 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 13 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | function topLevelToJson(value) { |
| 17 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 17 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | function invalidValue(typ, val, key, parent = '') { |
| @@ -171,7 +171,7 @@ function r(name) { | ||
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | const typeMap = { |
| 174 | - "TopLevel": o([ | |
| 174 | + "TopLevelElement": o([ | |
| 175 | 175 | { json: "id", js: "id", typ: "" }, |
| 176 | 176 | { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) }, |
| 177 | 177 | { json: "keywords", js: "keywords", typ: a(r("Keyword")) }, |
Mtypescriptdefault / TopLevel.ts+8 −6
| @@ -7,7 +7,9 @@ | ||
| 7 | 7 | // These functions will throw an error if the JSON doesn't |
| 8 | 8 | // match the expected interface, even if the JSON is valid. |
| 9 | 9 | |
| 10 | -export interface TopLevel { | |
| 10 | +export type TopLevel = TopLevelElement[]; | |
| 11 | + | |
| 12 | +export interface TopLevelElement { | |
| 11 | 13 | id: string; |
| 12 | 14 | identifiers: Identifier[]; |
| 13 | 15 | keywords: Keyword[]; |
| @@ -47,12 +49,12 @@ export type Title = "HTML"; | ||
| 47 | 49 | // Converts JSON strings to/from your types |
| 48 | 50 | // and asserts the results of JSON.parse at runtime |
| 49 | 51 | export class Convert { |
| 50 | - public static toTopLevel(json: string): TopLevel[] { | |
| 51 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 52 | + public static toTopLevel(json: string): TopLevelElement[] { | |
| 53 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 52 | 54 | } |
| 53 | 55 | |
| 54 | - public static topLevelToJson(value: TopLevel[]): string { | |
| 55 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 56 | + public static topLevelToJson(value: TopLevelElement[]): string { | |
| 57 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 56 | 58 | } |
| 57 | 59 | } |
| 58 | 60 | |
| @@ -210,7 +212,7 @@ function r(name: string) { | ||
| 210 | 212 | } |
| 211 | 213 | |
| 212 | 214 | const typeMap: any = { |
| 213 | - "TopLevel": o([ | |
| 215 | + "TopLevelElement": o([ | |
| 214 | 216 | { json: "id", js: "id", typ: "" }, |
| 215 | 217 | { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) }, |
| 216 | 218 | { json: "keywords", js: "keywords", typ: a(r("Keyword")) }, |
Test case
3 generated files · +19 −15test/inputs/json/misc/6eb00.json
Mflowdefault / TopLevel.js+8 −6
| @@ -9,7 +9,9 @@ | ||
| 9 | 9 | // These functions will throw an error if the JSON doesn't |
| 10 | 10 | // match the expected interface, even if the JSON is valid. |
| 11 | 11 | |
| 12 | -export type TopLevel = { | |
| 12 | +export type TopLevel = TopLevelElement[]; | |
| 13 | + | |
| 14 | +export type TopLevelElement = { | |
| 13 | 15 | DirectorateID: number; |
| 14 | 16 | Id: number; |
| 15 | 17 | Name: string; |
| @@ -17,12 +19,12 @@ export type TopLevel = { | ||
| 17 | 19 | |
| 18 | 20 | // Converts JSON strings to/from your types |
| 19 | 21 | // and asserts the results of JSON.parse at runtime |
| 20 | -function toTopLevel(json: string): TopLevel[] { | |
| 21 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 22 | +function toTopLevel(json: string): TopLevelElement[] { | |
| 23 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 22 | 24 | } |
| 23 | 25 | |
| 24 | -function topLevelToJson(value: TopLevel[]): string { | |
| 25 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 26 | +function topLevelToJson(value: TopLevelElement[]): string { | |
| 27 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 26 | 28 | } |
| 27 | 29 | |
| 28 | 30 | function invalidValue(typ: any, val: any, key: any, parent: any = '') { |
| @@ -179,7 +181,7 @@ function r(name: string) { | ||
| 179 | 181 | } |
| 180 | 182 | |
| 181 | 183 | const typeMap: any = { |
| 182 | - "TopLevel": o([ | |
| 184 | + "TopLevelElement": o([ | |
| 183 | 185 | { json: "DirectorateID", js: "DirectorateID", typ: 0 }, |
| 184 | 186 | { json: "Id", js: "Id", typ: 0 }, |
| 185 | 187 | { json: "Name", js: "Name", typ: "" }, |
Mjavascriptdefault / TopLevel.js+3 −3
| @@ -10,11 +10,11 @@ | ||
| 10 | 10 | // Converts JSON strings to/from your types |
| 11 | 11 | // and asserts the results of JSON.parse at runtime |
| 12 | 12 | function toTopLevel(json) { |
| 13 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 13 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | function topLevelToJson(value) { |
| 17 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 17 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | function invalidValue(typ, val, key, parent = '') { |
| @@ -171,7 +171,7 @@ function r(name) { | ||
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | const typeMap = { |
| 174 | - "TopLevel": o([ | |
| 174 | + "TopLevelElement": o([ | |
| 175 | 175 | { json: "DirectorateID", js: "DirectorateID", typ: 0 }, |
| 176 | 176 | { json: "Id", js: "Id", typ: 0 }, |
| 177 | 177 | { json: "Name", js: "Name", typ: "" }, |
Mtypescriptdefault / TopLevel.ts+8 −6
| @@ -7,7 +7,9 @@ | ||
| 7 | 7 | // These functions will throw an error if the JSON doesn't |
| 8 | 8 | // match the expected interface, even if the JSON is valid. |
| 9 | 9 | |
| 10 | -export interface TopLevel { | |
| 10 | +export type TopLevel = TopLevelElement[]; | |
| 11 | + | |
| 12 | +export interface TopLevelElement { | |
| 11 | 13 | DirectorateID: number; |
| 12 | 14 | Id: number; |
| 13 | 15 | Name: string; |
| @@ -16,12 +18,12 @@ export interface TopLevel { | ||
| 16 | 18 | // Converts JSON strings to/from your types |
| 17 | 19 | // and asserts the results of JSON.parse at runtime |
| 18 | 20 | export class Convert { |
| 19 | - public static toTopLevel(json: string): TopLevel[] { | |
| 20 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 21 | + public static toTopLevel(json: string): TopLevelElement[] { | |
| 22 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 21 | 23 | } |
| 22 | 24 | |
| 23 | - public static topLevelToJson(value: TopLevel[]): string { | |
| 24 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 25 | + public static topLevelToJson(value: TopLevelElement[]): string { | |
| 26 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 25 | 27 | } |
| 26 | 28 | } |
| 27 | 29 | |
| @@ -179,7 +181,7 @@ function r(name: string) { | ||
| 179 | 181 | } |
| 180 | 182 | |
| 181 | 183 | const typeMap: any = { |
| 182 | - "TopLevel": o([ | |
| 184 | + "TopLevelElement": o([ | |
| 183 | 185 | { json: "DirectorateID", js: "DirectorateID", typ: 0 }, |
| 184 | 186 | { json: "Id", js: "Id", typ: 0 }, |
| 185 | 187 | { json: "Name", js: "Name", typ: "" }, |
Test case
3 generated files · +19 −15test/inputs/json/misc/77392.json
Mflowdefault / TopLevel.js+8 −6
| @@ -9,7 +9,9 @@ | ||
| 9 | 9 | // These functions will throw an error if the JSON doesn't |
| 10 | 10 | // match the expected interface, even if the JSON is valid. |
| 11 | 11 | |
| 12 | -export type TopLevel = { | |
| 12 | +export type TopLevel = TopLevelElement[]; | |
| 13 | + | |
| 14 | +export type TopLevelElement = { | |
| 13 | 15 | designation: string; |
| 14 | 16 | discovery_date: Date; |
| 15 | 17 | h_mag?: string; |
| @@ -40,12 +42,12 @@ export type Pha = | ||
| 40 | 42 | |
| 41 | 43 | // Converts JSON strings to/from your types |
| 42 | 44 | // and asserts the results of JSON.parse at runtime |
| 43 | -function toTopLevel(json: string): TopLevel[] { | |
| 44 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 45 | +function toTopLevel(json: string): TopLevelElement[] { | |
| 46 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 45 | 47 | } |
| 46 | 48 | |
| 47 | -function topLevelToJson(value: TopLevel[]): string { | |
| 48 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 49 | +function topLevelToJson(value: TopLevelElement[]): string { | |
| 50 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 49 | 51 | } |
| 50 | 52 | |
| 51 | 53 | function invalidValue(typ: any, val: any, key: any, parent: any = '') { |
| @@ -202,7 +204,7 @@ function r(name: string) { | ||
| 202 | 204 | } |
| 203 | 205 | |
| 204 | 206 | const typeMap: any = { |
| 205 | - "TopLevel": o([ | |
| 207 | + "TopLevelElement": o([ | |
| 206 | 208 | { json: "designation", js: "designation", typ: "" }, |
| 207 | 209 | { json: "discovery_date", js: "discovery_date", typ: Date }, |
| 208 | 210 | { json: "h_mag", js: "h_mag", typ: u(undefined, "") }, |
Mjavascriptdefault / TopLevel.js+3 −3
| @@ -10,11 +10,11 @@ | ||
| 10 | 10 | // Converts JSON strings to/from your types |
| 11 | 11 | // and asserts the results of JSON.parse at runtime |
| 12 | 12 | function toTopLevel(json) { |
| 13 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 13 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | function topLevelToJson(value) { |
| 17 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 17 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | function invalidValue(typ, val, key, parent = '') { |
| @@ -171,7 +171,7 @@ function r(name) { | ||
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | const typeMap = { |
| 174 | - "TopLevel": o([ | |
| 174 | + "TopLevelElement": o([ | |
| 175 | 175 | { json: "designation", js: "designation", typ: "" }, |
| 176 | 176 | { json: "discovery_date", js: "discovery_date", typ: Date }, |
| 177 | 177 | { json: "h_mag", js: "h_mag", typ: u(undefined, "") }, |
Mtypescriptdefault / TopLevel.ts+8 −6
| @@ -7,7 +7,9 @@ | ||
| 7 | 7 | // These functions will throw an error if the JSON doesn't |
| 8 | 8 | // match the expected interface, even if the JSON is valid. |
| 9 | 9 | |
| 10 | -export interface TopLevel { | |
| 10 | +export type TopLevel = TopLevelElement[]; | |
| 11 | + | |
| 12 | +export interface TopLevelElement { | |
| 11 | 13 | designation: string; |
| 12 | 14 | discovery_date: Date; |
| 13 | 15 | h_mag?: string; |
| @@ -27,12 +29,12 @@ export type Pha = "Y" | "N" | "n/a"; | ||
| 27 | 29 | // Converts JSON strings to/from your types |
| 28 | 30 | // and asserts the results of JSON.parse at runtime |
| 29 | 31 | export class Convert { |
| 30 | - public static toTopLevel(json: string): TopLevel[] { | |
| 31 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 32 | + public static toTopLevel(json: string): TopLevelElement[] { | |
| 33 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 32 | 34 | } |
| 33 | 35 | |
| 34 | - public static topLevelToJson(value: TopLevel[]): string { | |
| 35 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 36 | + public static topLevelToJson(value: TopLevelElement[]): string { | |
| 37 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 36 | 38 | } |
| 37 | 39 | } |
| 38 | 40 | |
| @@ -190,7 +192,7 @@ function r(name: string) { | ||
| 190 | 192 | } |
| 191 | 193 | |
| 192 | 194 | const typeMap: any = { |
| 193 | - "TopLevel": o([ | |
| 195 | + "TopLevelElement": o([ | |
| 194 | 196 | { json: "designation", js: "designation", typ: "" }, |
| 195 | 197 | { json: "discovery_date", js: "discovery_date", typ: Date }, |
| 196 | 198 | { json: "h_mag", js: "h_mag", typ: u(undefined, "") }, |
Test case
3 generated files · +19 −15test/inputs/json/misc/7f568.json
Mflowdefault / TopLevel.js+8 −6
| @@ -9,7 +9,9 @@ | ||
| 9 | 9 | // These functions will throw an error if the JSON doesn't |
| 10 | 10 | // match the expected interface, even if the JSON is valid. |
| 11 | 11 | |
| 12 | -export type TopLevel = { | |
| 12 | +export type TopLevel = TopLevelElement[]; | |
| 13 | + | |
| 14 | +export type TopLevelElement = { | |
| 13 | 15 | comments: number; |
| 14 | 16 | comments_url: string; |
| 15 | 17 | commits_url: string; |
| @@ -44,12 +46,12 @@ export type Type = | ||
| 44 | 46 | |
| 45 | 47 | // Converts JSON strings to/from your types |
| 46 | 48 | // and asserts the results of JSON.parse at runtime |
| 47 | -function toTopLevel(json: string): TopLevel[] { | |
| 48 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 49 | +function toTopLevel(json: string): TopLevelElement[] { | |
| 50 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 49 | 51 | } |
| 50 | 52 | |
| 51 | -function topLevelToJson(value: TopLevel[]): string { | |
| 52 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 53 | +function topLevelToJson(value: TopLevelElement[]): string { | |
| 54 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 53 | 55 | } |
| 54 | 56 | |
| 55 | 57 | function invalidValue(typ: any, val: any, key: any, parent: any = '') { |
| @@ -206,7 +208,7 @@ function r(name: string) { | ||
| 206 | 208 | } |
| 207 | 209 | |
| 208 | 210 | const typeMap: any = { |
| 209 | - "TopLevel": o([ | |
| 211 | + "TopLevelElement": o([ | |
| 210 | 212 | { json: "comments", js: "comments", typ: 0 }, |
| 211 | 213 | { json: "comments_url", js: "comments_url", typ: "" }, |
| 212 | 214 | { json: "commits_url", js: "commits_url", typ: "" }, |
Mjavascriptdefault / TopLevel.js+3 −3
| @@ -10,11 +10,11 @@ | ||
| 10 | 10 | // Converts JSON strings to/from your types |
| 11 | 11 | // and asserts the results of JSON.parse at runtime |
| 12 | 12 | function toTopLevel(json) { |
| 13 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 13 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | function topLevelToJson(value) { |
| 17 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 17 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | function invalidValue(typ, val, key, parent = '') { |
| @@ -171,7 +171,7 @@ function r(name) { | ||
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | const typeMap = { |
| 174 | - "TopLevel": o([ | |
| 174 | + "TopLevelElement": o([ | |
| 175 | 175 | { json: "comments", js: "comments", typ: 0 }, |
| 176 | 176 | { json: "comments_url", js: "comments_url", typ: "" }, |
| 177 | 177 | { json: "commits_url", js: "commits_url", typ: "" }, |
Mtypescriptdefault / TopLevel.ts+8 −6
| @@ -7,7 +7,9 @@ | ||
| 7 | 7 | // These functions will throw an error if the JSON doesn't |
| 8 | 8 | // match the expected interface, even if the JSON is valid. |
| 9 | 9 | |
| 10 | -export interface TopLevel { | |
| 10 | +export type TopLevel = TopLevelElement[]; | |
| 11 | + | |
| 12 | +export interface TopLevelElement { | |
| 11 | 13 | comments: number; |
| 12 | 14 | comments_url: string; |
| 13 | 15 | commits_url: string; |
| @@ -41,12 +43,12 @@ export type Type = "text/plain"; | ||
| 41 | 43 | // Converts JSON strings to/from your types |
| 42 | 44 | // and asserts the results of JSON.parse at runtime |
| 43 | 45 | export class Convert { |
| 44 | - public static toTopLevel(json: string): TopLevel[] { | |
| 45 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 46 | + public static toTopLevel(json: string): TopLevelElement[] { | |
| 47 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 46 | 48 | } |
| 47 | 49 | |
| 48 | - public static topLevelToJson(value: TopLevel[]): string { | |
| 49 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 50 | + public static topLevelToJson(value: TopLevelElement[]): string { | |
| 51 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 50 | 52 | } |
| 51 | 53 | } |
| 52 | 54 | |
| @@ -204,7 +206,7 @@ function r(name: string) { | ||
| 204 | 206 | } |
| 205 | 207 | |
| 206 | 208 | const typeMap: any = { |
| 207 | - "TopLevel": o([ | |
| 209 | + "TopLevelElement": o([ | |
| 208 | 210 | { json: "comments", js: "comments", typ: 0 }, |
| 209 | 211 | { json: "comments_url", js: "comments_url", typ: "" }, |
| 210 | 212 | { json: "commits_url", js: "commits_url", typ: "" }, |
Test case
3 generated files · +26 −22test/inputs/json/misc/7fbfb.json
Mflowdefault / TopLevel.js+11 −9
| @@ -9,9 +9,11 @@ | ||
| 9 | 9 | // These functions will throw an error if the JSON doesn't |
| 10 | 10 | // match the expected interface, even if the JSON is valid. |
| 11 | 11 | |
| 12 | -export type TopLevel = TopLevelElement[] | PurpleTopLevel; | |
| 12 | +export type TopLevel = TopLevelUnion[]; | |
| 13 | 13 | |
| 14 | -export type TopLevelElement = { | |
| 14 | +export type TopLevelUnion = PurpleTopLevel[] | FluffyTopLevel; | |
| 15 | + | |
| 16 | +export type PurpleTopLevel = { | |
| 15 | 17 | country: Country; |
| 16 | 18 | date: string; |
| 17 | 19 | decimal: string; |
| @@ -32,7 +34,7 @@ export type Value = | ||
| 32 | 34 | "China" |
| 33 | 35 | | "GDP (current US$)"; |
| 34 | 36 | |
| 35 | -export type PurpleTopLevel = { | |
| 37 | +export type FluffyTopLevel = { | |
| 36 | 38 | page: number; |
| 37 | 39 | pages: number; |
| 38 | 40 | per_page: string; |
| @@ -41,12 +43,12 @@ export type PurpleTopLevel = { | ||
| 41 | 43 | |
| 42 | 44 | // Converts JSON strings to/from your types |
| 43 | 45 | // and asserts the results of JSON.parse at runtime |
| 44 | -function toTopLevel(json: string): TopLevel[] { | |
| 45 | - return cast(JSON.parse(json), a(u(a(r("TopLevelElement")), r("PurpleTopLevel")))); | |
| 46 | +function toTopLevel(json: string): TopLevelUnion[] { | |
| 47 | + return cast(JSON.parse(json), a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel")))); | |
| 46 | 48 | } |
| 47 | 49 | |
| 48 | -function topLevelToJson(value: TopLevel[]): string { | |
| 49 | - return JSON.stringify(uncast(value, a(u(a(r("TopLevelElement")), r("PurpleTopLevel")))), null, 2); | |
| 50 | +function topLevelToJson(value: TopLevelUnion[]): string { | |
| 51 | + return JSON.stringify(uncast(value, a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel")))), null, 2); | |
| 50 | 52 | } |
| 51 | 53 | |
| 52 | 54 | function invalidValue(typ: any, val: any, key: any, parent: any = '') { |
| @@ -203,7 +205,7 @@ function r(name: string) { | ||
| 203 | 205 | } |
| 204 | 206 | |
| 205 | 207 | const typeMap: any = { |
| 206 | - "TopLevelElement": o([ | |
| 208 | + "PurpleTopLevel": o([ | |
| 207 | 209 | { json: "country", js: "country", typ: r("Country") }, |
| 208 | 210 | { json: "date", js: "date", typ: "" }, |
| 209 | 211 | { json: "decimal", js: "decimal", typ: "" }, |
| @@ -214,7 +216,7 @@ const typeMap: any = { | ||
| 214 | 216 | { json: "id", js: "id", typ: r("ID") }, |
| 215 | 217 | { json: "value", js: "value", typ: r("Value") }, |
| 216 | 218 | ], false), |
| 217 | - "PurpleTopLevel": o([ | |
| 219 | + "FluffyTopLevel": o([ | |
| 218 | 220 | { json: "page", js: "page", typ: 0 }, |
| 219 | 221 | { json: "pages", js: "pages", typ: 0 }, |
| 220 | 222 | { json: "per_page", js: "per_page", typ: "" }, |
Mjavascriptdefault / TopLevel.js+4 −4
| @@ -10,11 +10,11 @@ | ||
| 10 | 10 | // Converts JSON strings to/from your types |
| 11 | 11 | // and asserts the results of JSON.parse at runtime |
| 12 | 12 | function toTopLevel(json) { |
| 13 | - return cast(JSON.parse(json), a(u(a(r("TopLevelElement")), r("PurpleTopLevel")))); | |
| 13 | + return cast(JSON.parse(json), a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel")))); | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | function topLevelToJson(value) { |
| 17 | - return JSON.stringify(uncast(value, a(u(a(r("TopLevelElement")), r("PurpleTopLevel")))), null, 2); | |
| 17 | + return JSON.stringify(uncast(value, a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel")))), null, 2); | |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | function invalidValue(typ, val, key, parent = '') { |
| @@ -171,7 +171,7 @@ function r(name) { | ||
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | const typeMap = { |
| 174 | - "TopLevelElement": o([ | |
| 174 | + "PurpleTopLevel": o([ | |
| 175 | 175 | { json: "country", js: "country", typ: r("Country") }, |
| 176 | 176 | { json: "date", js: "date", typ: "" }, |
| 177 | 177 | { json: "decimal", js: "decimal", typ: "" }, |
| @@ -182,7 +182,7 @@ const typeMap = { | ||
| 182 | 182 | { json: "id", js: "id", typ: r("ID") }, |
| 183 | 183 | { json: "value", js: "value", typ: r("Value") }, |
| 184 | 184 | ], false), |
| 185 | - "PurpleTopLevel": o([ | |
| 185 | + "FluffyTopLevel": o([ | |
| 186 | 186 | { json: "page", js: "page", typ: 0 }, |
| 187 | 187 | { json: "pages", js: "pages", typ: 0 }, |
| 188 | 188 | { json: "per_page", js: "per_page", typ: "" }, |
Mtypescriptdefault / TopLevel.ts+11 −9
| @@ -7,9 +7,11 @@ | ||
| 7 | 7 | // These functions will throw an error if the JSON doesn't |
| 8 | 8 | // match the expected interface, even if the JSON is valid. |
| 9 | 9 | |
| 10 | -export type TopLevel = TopLevelElement[] | PurpleTopLevel; | |
| 10 | +export type TopLevel = TopLevelUnion[]; | |
| 11 | 11 | |
| 12 | -export interface TopLevelElement { | |
| 12 | +export type TopLevelUnion = PurpleTopLevel[] | FluffyTopLevel; | |
| 13 | + | |
| 14 | +export interface PurpleTopLevel { | |
| 13 | 15 | country: Country; |
| 14 | 16 | date: string; |
| 15 | 17 | decimal: string; |
| @@ -26,7 +28,7 @@ export type ID = "CN" | "NY.GDP.MKTP.CD"; | ||
| 26 | 28 | |
| 27 | 29 | export type Value = "China" | "GDP (current US$)"; |
| 28 | 30 | |
| 29 | -export interface PurpleTopLevel { | |
| 31 | +export interface FluffyTopLevel { | |
| 30 | 32 | page: number; |
| 31 | 33 | pages: number; |
| 32 | 34 | per_page: string; |
| @@ -36,12 +38,12 @@ export interface PurpleTopLevel { | ||
| 36 | 38 | // Converts JSON strings to/from your types |
| 37 | 39 | // and asserts the results of JSON.parse at runtime |
| 38 | 40 | export class Convert { |
| 39 | - public static toTopLevel(json: string): TopLevel[] { | |
| 40 | - return cast(JSON.parse(json), a(u(a(r("TopLevelElement")), r("PurpleTopLevel")))); | |
| 41 | + public static toTopLevel(json: string): TopLevelUnion[] { | |
| 42 | + return cast(JSON.parse(json), a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel")))); | |
| 41 | 43 | } |
| 42 | 44 | |
| 43 | - public static topLevelToJson(value: TopLevel[]): string { | |
| 44 | - return JSON.stringify(uncast(value, a(u(a(r("TopLevelElement")), r("PurpleTopLevel")))), null, 2); | |
| 45 | + public static topLevelToJson(value: TopLevelUnion[]): string { | |
| 46 | + return JSON.stringify(uncast(value, a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel")))), null, 2); | |
| 45 | 47 | } |
| 46 | 48 | } |
| 47 | 49 | |
| @@ -199,7 +201,7 @@ function r(name: string) { | ||
| 199 | 201 | } |
| 200 | 202 | |
| 201 | 203 | const typeMap: any = { |
| 202 | - "TopLevelElement": o([ | |
| 204 | + "PurpleTopLevel": o([ | |
| 203 | 205 | { json: "country", js: "country", typ: r("Country") }, |
| 204 | 206 | { json: "date", js: "date", typ: "" }, |
| 205 | 207 | { json: "decimal", js: "decimal", typ: "" }, |
| @@ -210,7 +212,7 @@ const typeMap: any = { | ||
| 210 | 212 | { json: "id", js: "id", typ: r("ID") }, |
| 211 | 213 | { json: "value", js: "value", typ: r("Value") }, |
| 212 | 214 | ], false), |
| 213 | - "PurpleTopLevel": o([ | |
| 215 | + "FluffyTopLevel": o([ | |
| 214 | 216 | { json: "page", js: "page", typ: 0 }, |
| 215 | 217 | { json: "pages", js: "pages", typ: 0 }, |
| 216 | 218 | { json: "per_page", js: "per_page", typ: "" }, |
Test case
3 generated files · +19 −15test/inputs/json/misc/9847b.json
Mflowdefault / TopLevel.js+8 −6
| @@ -9,19 +9,21 @@ | ||
| 9 | 9 | // These functions will throw an error if the JSON doesn't |
| 10 | 10 | // match the expected interface, even if the JSON is valid. |
| 11 | 11 | |
| 12 | -export type TopLevel = { | |
| 12 | +export type TopLevel = TopLevelElement[]; | |
| 13 | + | |
| 14 | +export type TopLevelElement = { | |
| 13 | 15 | id: string; |
| 14 | 16 | name: string; |
| 15 | 17 | }; |
| 16 | 18 | |
| 17 | 19 | // Converts JSON strings to/from your types |
| 18 | 20 | // and asserts the results of JSON.parse at runtime |
| 19 | -function toTopLevel(json: string): TopLevel[] { | |
| 20 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 21 | +function toTopLevel(json: string): TopLevelElement[] { | |
| 22 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 21 | 23 | } |
| 22 | 24 | |
| 23 | -function topLevelToJson(value: TopLevel[]): string { | |
| 24 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 25 | +function topLevelToJson(value: TopLevelElement[]): string { | |
| 26 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 25 | 27 | } |
| 26 | 28 | |
| 27 | 29 | function invalidValue(typ: any, val: any, key: any, parent: any = '') { |
| @@ -178,7 +180,7 @@ function r(name: string) { | ||
| 178 | 180 | } |
| 179 | 181 | |
| 180 | 182 | const typeMap: any = { |
| 181 | - "TopLevel": o([ | |
| 183 | + "TopLevelElement": o([ | |
| 182 | 184 | { json: "id", js: "id", typ: "" }, |
| 183 | 185 | { json: "name", js: "name", typ: "" }, |
| 184 | 186 | ], false), |
Mjavascriptdefault / TopLevel.js+3 −3
| @@ -10,11 +10,11 @@ | ||
| 10 | 10 | // Converts JSON strings to/from your types |
| 11 | 11 | // and asserts the results of JSON.parse at runtime |
| 12 | 12 | function toTopLevel(json) { |
| 13 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 13 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | function topLevelToJson(value) { |
| 17 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 17 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | function invalidValue(typ, val, key, parent = '') { |
| @@ -171,7 +171,7 @@ function r(name) { | ||
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | const typeMap = { |
| 174 | - "TopLevel": o([ | |
| 174 | + "TopLevelElement": o([ | |
| 175 | 175 | { json: "id", js: "id", typ: "" }, |
| 176 | 176 | { json: "name", js: "name", typ: "" }, |
| 177 | 177 | ], false), |
Mtypescriptdefault / TopLevel.ts+8 −6
| @@ -7,7 +7,9 @@ | ||
| 7 | 7 | // These functions will throw an error if the JSON doesn't |
| 8 | 8 | // match the expected interface, even if the JSON is valid. |
| 9 | 9 | |
| 10 | -export interface TopLevel { | |
| 10 | +export type TopLevel = TopLevelElement[]; | |
| 11 | + | |
| 12 | +export interface TopLevelElement { | |
| 11 | 13 | id: string; |
| 12 | 14 | name: string; |
| 13 | 15 | } |
| @@ -15,12 +17,12 @@ export interface TopLevel { | ||
| 15 | 17 | // Converts JSON strings to/from your types |
| 16 | 18 | // and asserts the results of JSON.parse at runtime |
| 17 | 19 | export class Convert { |
| 18 | - public static toTopLevel(json: string): TopLevel[] { | |
| 19 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 20 | + public static toTopLevel(json: string): TopLevelElement[] { | |
| 21 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 20 | 22 | } |
| 21 | 23 | |
| 22 | - public static topLevelToJson(value: TopLevel[]): string { | |
| 23 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 24 | + public static topLevelToJson(value: TopLevelElement[]): string { | |
| 25 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 24 | 26 | } |
| 25 | 27 | } |
| 26 | 28 | |
| @@ -178,7 +180,7 @@ function r(name: string) { | ||
| 178 | 180 | } |
| 179 | 181 | |
| 180 | 182 | const typeMap: any = { |
| 181 | - "TopLevel": o([ | |
| 183 | + "TopLevelElement": o([ | |
| 182 | 184 | { json: "id", js: "id", typ: "" }, |
| 183 | 185 | { json: "name", js: "name", typ: "" }, |
| 184 | 186 | ], false), |
Test case
3 generated files · +19 −15test/inputs/json/misc/996bd.json
Mflowdefault / TopLevel.js+8 −6
| @@ -9,7 +9,9 @@ | ||
| 9 | 9 | // These functions will throw an error if the JSON doesn't |
| 10 | 10 | // match the expected interface, even if the JSON is valid. |
| 11 | 11 | |
| 12 | -export type TopLevel = { | |
| 12 | +export type TopLevel = TopLevelElement[]; | |
| 13 | + | |
| 14 | +export type TopLevelElement = { | |
| 13 | 15 | id: string; |
| 14 | 16 | identifiers: Identifier[]; |
| 15 | 17 | keywords: Keyword[]; |
| @@ -57,12 +59,12 @@ export type Title = | ||
| 57 | 59 | |
| 58 | 60 | // Converts JSON strings to/from your types |
| 59 | 61 | // and asserts the results of JSON.parse at runtime |
| 60 | -function toTopLevel(json: string): TopLevel[] { | |
| 61 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 62 | +function toTopLevel(json: string): TopLevelElement[] { | |
| 63 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 62 | 64 | } |
| 63 | 65 | |
| 64 | -function topLevelToJson(value: TopLevel[]): string { | |
| 65 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 66 | +function topLevelToJson(value: TopLevelElement[]): string { | |
| 67 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 66 | 68 | } |
| 67 | 69 | |
| 68 | 70 | function invalidValue(typ: any, val: any, key: any, parent: any = '') { |
| @@ -219,7 +221,7 @@ function r(name: string) { | ||
| 219 | 221 | } |
| 220 | 222 | |
| 221 | 223 | const typeMap: any = { |
| 222 | - "TopLevel": o([ | |
| 224 | + "TopLevelElement": o([ | |
| 223 | 225 | { json: "id", js: "id", typ: "" }, |
| 224 | 226 | { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) }, |
| 225 | 227 | { json: "keywords", js: "keywords", typ: a(r("Keyword")) }, |
Mjavascriptdefault / TopLevel.js+3 −3
| @@ -10,11 +10,11 @@ | ||
| 10 | 10 | // Converts JSON strings to/from your types |
| 11 | 11 | // and asserts the results of JSON.parse at runtime |
| 12 | 12 | function toTopLevel(json) { |
| 13 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 13 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | function topLevelToJson(value) { |
| 17 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 17 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | function invalidValue(typ, val, key, parent = '') { |
| @@ -171,7 +171,7 @@ function r(name) { | ||
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | const typeMap = { |
| 174 | - "TopLevel": o([ | |
| 174 | + "TopLevelElement": o([ | |
| 175 | 175 | { json: "id", js: "id", typ: "" }, |
| 176 | 176 | { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) }, |
| 177 | 177 | { json: "keywords", js: "keywords", typ: a(r("Keyword")) }, |
Mtypescriptdefault / TopLevel.ts+8 −6
| @@ -7,7 +7,9 @@ | ||
| 7 | 7 | // These functions will throw an error if the JSON doesn't |
| 8 | 8 | // match the expected interface, even if the JSON is valid. |
| 9 | 9 | |
| 10 | -export interface TopLevel { | |
| 10 | +export type TopLevel = TopLevelElement[]; | |
| 11 | + | |
| 12 | +export interface TopLevelElement { | |
| 11 | 13 | id: string; |
| 12 | 14 | identifiers: Identifier[]; |
| 13 | 15 | keywords: Keyword[]; |
| @@ -45,12 +47,12 @@ export type Title = "Plain Text" | "HTML"; | ||
| 45 | 47 | // Converts JSON strings to/from your types |
| 46 | 48 | // and asserts the results of JSON.parse at runtime |
| 47 | 49 | export class Convert { |
| 48 | - public static toTopLevel(json: string): TopLevel[] { | |
| 49 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 50 | + public static toTopLevel(json: string): TopLevelElement[] { | |
| 51 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 50 | 52 | } |
| 51 | 53 | |
| 52 | - public static topLevelToJson(value: TopLevel[]): string { | |
| 53 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 54 | + public static topLevelToJson(value: TopLevelElement[]): string { | |
| 55 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 54 | 56 | } |
| 55 | 57 | } |
| 56 | 58 | |
| @@ -208,7 +210,7 @@ function r(name: string) { | ||
| 208 | 210 | } |
| 209 | 211 | |
| 210 | 212 | const typeMap: any = { |
| 211 | - "TopLevel": o([ | |
| 213 | + "TopLevelElement": o([ | |
| 212 | 214 | { json: "id", js: "id", typ: "" }, |
| 213 | 215 | { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) }, |
| 214 | 216 | { json: "keywords", js: "keywords", typ: a(r("Keyword")) }, |
Test case
3 generated files · +19 −15test/inputs/json/misc/9a503.json
Mflowdefault / TopLevel.js+8 −6
| @@ -9,7 +9,9 @@ | ||
| 9 | 9 | // These functions will throw an error if the JSON doesn't |
| 10 | 10 | // match the expected interface, even if the JSON is valid. |
| 11 | 11 | |
| 12 | -export type TopLevel = { | |
| 12 | +export type TopLevel = TopLevelElement[]; | |
| 13 | + | |
| 14 | +export type TopLevelElement = { | |
| 13 | 15 | id: string; |
| 14 | 16 | identifiers: Identifier[]; |
| 15 | 17 | keywords: Keyword[]; |
| @@ -43,12 +45,12 @@ export type Text = { | ||
| 43 | 45 | |
| 44 | 46 | // Converts JSON strings to/from your types |
| 45 | 47 | // and asserts the results of JSON.parse at runtime |
| 46 | -function toTopLevel(json: string): TopLevel[] { | |
| 47 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 48 | +function toTopLevel(json: string): TopLevelElement[] { | |
| 49 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 48 | 50 | } |
| 49 | 51 | |
| 50 | -function topLevelToJson(value: TopLevel[]): string { | |
| 51 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 52 | +function topLevelToJson(value: TopLevelElement[]): string { | |
| 53 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 52 | 54 | } |
| 53 | 55 | |
| 54 | 56 | function invalidValue(typ: any, val: any, key: any, parent: any = '') { |
| @@ -205,7 +207,7 @@ function r(name: string) { | ||
| 205 | 207 | } |
| 206 | 208 | |
| 207 | 209 | const typeMap: any = { |
| 208 | - "TopLevel": o([ | |
| 210 | + "TopLevelElement": o([ | |
| 209 | 211 | { json: "id", js: "id", typ: "" }, |
| 210 | 212 | { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) }, |
| 211 | 213 | { json: "keywords", js: "keywords", typ: a(r("Keyword")) }, |
Mjavascriptdefault / TopLevel.js+3 −3
| @@ -10,11 +10,11 @@ | ||
| 10 | 10 | // Converts JSON strings to/from your types |
| 11 | 11 | // and asserts the results of JSON.parse at runtime |
| 12 | 12 | function toTopLevel(json) { |
| 13 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 13 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | function topLevelToJson(value) { |
| 17 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 17 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | function invalidValue(typ, val, key, parent = '') { |
| @@ -171,7 +171,7 @@ function r(name) { | ||
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | const typeMap = { |
| 174 | - "TopLevel": o([ | |
| 174 | + "TopLevelElement": o([ | |
| 175 | 175 | { json: "id", js: "id", typ: "" }, |
| 176 | 176 | { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) }, |
| 177 | 177 | { json: "keywords", js: "keywords", typ: a(r("Keyword")) }, |
Mtypescriptdefault / TopLevel.ts+8 −6
| @@ -7,7 +7,9 @@ | ||
| 7 | 7 | // These functions will throw an error if the JSON doesn't |
| 8 | 8 | // match the expected interface, even if the JSON is valid. |
| 9 | 9 | |
| 10 | -export interface TopLevel { | |
| 10 | +export type TopLevel = TopLevelElement[]; | |
| 11 | + | |
| 12 | +export interface TopLevelElement { | |
| 11 | 13 | id: string; |
| 12 | 14 | identifiers: Identifier[]; |
| 13 | 15 | keywords: Keyword[]; |
| @@ -39,12 +41,12 @@ export interface Text { | ||
| 39 | 41 | // Converts JSON strings to/from your types |
| 40 | 42 | // and asserts the results of JSON.parse at runtime |
| 41 | 43 | export class Convert { |
| 42 | - public static toTopLevel(json: string): TopLevel[] { | |
| 43 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 44 | + public static toTopLevel(json: string): TopLevelElement[] { | |
| 45 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 44 | 46 | } |
| 45 | 47 | |
| 46 | - public static topLevelToJson(value: TopLevel[]): string { | |
| 47 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 48 | + public static topLevelToJson(value: TopLevelElement[]): string { | |
| 49 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 48 | 50 | } |
| 49 | 51 | } |
| 50 | 52 | |
| @@ -202,7 +204,7 @@ function r(name: string) { | ||
| 202 | 204 | } |
| 203 | 205 | |
| 204 | 206 | const typeMap: any = { |
| 205 | - "TopLevel": o([ | |
| 207 | + "TopLevelElement": o([ | |
| 206 | 208 | { json: "id", js: "id", typ: "" }, |
| 207 | 209 | { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) }, |
| 208 | 210 | { json: "keywords", js: "keywords", typ: a(r("Keyword")) }, |
Test case
3 generated files · +19 −15test/inputs/json/misc/9eed5.json
Mflowdefault / TopLevel.js+8 −6
| @@ -9,7 +9,9 @@ | ||
| 9 | 9 | // These functions will throw an error if the JSON doesn't |
| 10 | 10 | // match the expected interface, even if the JSON is valid. |
| 11 | 11 | |
| 12 | -export type TopLevel = { | |
| 12 | +export type TopLevel = TopLevelElement[]; | |
| 13 | + | |
| 14 | +export type TopLevelElement = { | |
| 13 | 15 | id: string; |
| 14 | 16 | identifiers: Identifier[]; |
| 15 | 17 | keywords: Keyword[]; |
| @@ -42,12 +44,12 @@ export type Text = { | ||
| 42 | 44 | |
| 43 | 45 | // Converts JSON strings to/from your types |
| 44 | 46 | // and asserts the results of JSON.parse at runtime |
| 45 | -function toTopLevel(json: string): TopLevel[] { | |
| 46 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 47 | +function toTopLevel(json: string): TopLevelElement[] { | |
| 48 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 47 | 49 | } |
| 48 | 50 | |
| 49 | -function topLevelToJson(value: TopLevel[]): string { | |
| 50 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 51 | +function topLevelToJson(value: TopLevelElement[]): string { | |
| 52 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 51 | 53 | } |
| 52 | 54 | |
| 53 | 55 | function invalidValue(typ: any, val: any, key: any, parent: any = '') { |
| @@ -204,7 +206,7 @@ function r(name: string) { | ||
| 204 | 206 | } |
| 205 | 207 | |
| 206 | 208 | const typeMap: any = { |
| 207 | - "TopLevel": o([ | |
| 209 | + "TopLevelElement": o([ | |
| 208 | 210 | { json: "id", js: "id", typ: "" }, |
| 209 | 211 | { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) }, |
| 210 | 212 | { json: "keywords", js: "keywords", typ: a(r("Keyword")) }, |
Mjavascriptdefault / TopLevel.js+3 −3
| @@ -10,11 +10,11 @@ | ||
| 10 | 10 | // Converts JSON strings to/from your types |
| 11 | 11 | // and asserts the results of JSON.parse at runtime |
| 12 | 12 | function toTopLevel(json) { |
| 13 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 13 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | function topLevelToJson(value) { |
| 17 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 17 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | function invalidValue(typ, val, key, parent = '') { |
| @@ -171,7 +171,7 @@ function r(name) { | ||
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | const typeMap = { |
| 174 | - "TopLevel": o([ | |
| 174 | + "TopLevelElement": o([ | |
| 175 | 175 | { json: "id", js: "id", typ: "" }, |
| 176 | 176 | { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) }, |
| 177 | 177 | { json: "keywords", js: "keywords", typ: a(r("Keyword")) }, |
Mtypescriptdefault / TopLevel.ts+8 −6
| @@ -7,7 +7,9 @@ | ||
| 7 | 7 | // These functions will throw an error if the JSON doesn't |
| 8 | 8 | // match the expected interface, even if the JSON is valid. |
| 9 | 9 | |
| 10 | -export interface TopLevel { | |
| 10 | +export type TopLevel = TopLevelElement[]; | |
| 11 | + | |
| 12 | +export interface TopLevelElement { | |
| 11 | 13 | id: string; |
| 12 | 14 | identifiers: Identifier[]; |
| 13 | 15 | keywords: Keyword[]; |
| @@ -39,12 +41,12 @@ export interface Text { | ||
| 39 | 41 | // Converts JSON strings to/from your types |
| 40 | 42 | // and asserts the results of JSON.parse at runtime |
| 41 | 43 | export class Convert { |
| 42 | - public static toTopLevel(json: string): TopLevel[] { | |
| 43 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 44 | + public static toTopLevel(json: string): TopLevelElement[] { | |
| 45 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 44 | 46 | } |
| 45 | 47 | |
| 46 | - public static topLevelToJson(value: TopLevel[]): string { | |
| 47 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 48 | + public static topLevelToJson(value: TopLevelElement[]): string { | |
| 49 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 48 | 50 | } |
| 49 | 51 | } |
| 50 | 52 | |
| @@ -202,7 +204,7 @@ function r(name: string) { | ||
| 202 | 204 | } |
| 203 | 205 | |
| 204 | 206 | const typeMap: any = { |
| 205 | - "TopLevel": o([ | |
| 207 | + "TopLevelElement": o([ | |
| 206 | 208 | { json: "id", js: "id", typ: "" }, |
| 207 | 209 | { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) }, |
| 208 | 210 | { json: "keywords", js: "keywords", typ: a(r("Keyword")) }, |
Test case
3 generated files · +19 −15test/inputs/json/misc/a45b0.json
Mflowdefault / TopLevel.js+8 −6
| @@ -9,7 +9,9 @@ | ||
| 9 | 9 | // These functions will throw an error if the JSON doesn't |
| 10 | 10 | // match the expected interface, even if the JSON is valid. |
| 11 | 11 | |
| 12 | -export type TopLevel = { | |
| 12 | +export type TopLevel = TopLevelElement[]; | |
| 13 | + | |
| 14 | +export type TopLevelElement = { | |
| 13 | 15 | age: number; |
| 14 | 16 | country: Country; |
| 15 | 17 | females: number; |
| @@ -23,12 +25,12 @@ export type Country = | ||
| 23 | 25 | |
| 24 | 26 | // Converts JSON strings to/from your types |
| 25 | 27 | // and asserts the results of JSON.parse at runtime |
| 26 | -function toTopLevel(json: string): TopLevel[] { | |
| 27 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 28 | +function toTopLevel(json: string): TopLevelElement[] { | |
| 29 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 28 | 30 | } |
| 29 | 31 | |
| 30 | -function topLevelToJson(value: TopLevel[]): string { | |
| 31 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 32 | +function topLevelToJson(value: TopLevelElement[]): string { | |
| 33 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 32 | 34 | } |
| 33 | 35 | |
| 34 | 36 | function invalidValue(typ: any, val: any, key: any, parent: any = '') { |
| @@ -185,7 +187,7 @@ function r(name: string) { | ||
| 185 | 187 | } |
| 186 | 188 | |
| 187 | 189 | const typeMap: any = { |
| 188 | - "TopLevel": o([ | |
| 190 | + "TopLevelElement": o([ | |
| 189 | 191 | { json: "age", js: "age", typ: 0 }, |
| 190 | 192 | { json: "country", js: "country", typ: r("Country") }, |
| 191 | 193 | { json: "females", js: "females", typ: 0 }, |
Mjavascriptdefault / TopLevel.js+3 −3
| @@ -10,11 +10,11 @@ | ||
| 10 | 10 | // Converts JSON strings to/from your types |
| 11 | 11 | // and asserts the results of JSON.parse at runtime |
| 12 | 12 | function toTopLevel(json) { |
| 13 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 13 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | function topLevelToJson(value) { |
| 17 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 17 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | function invalidValue(typ, val, key, parent = '') { |
| @@ -171,7 +171,7 @@ function r(name) { | ||
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | const typeMap = { |
| 174 | - "TopLevel": o([ | |
| 174 | + "TopLevelElement": o([ | |
| 175 | 175 | { json: "age", js: "age", typ: 0 }, |
| 176 | 176 | { json: "country", js: "country", typ: r("Country") }, |
| 177 | 177 | { json: "females", js: "females", typ: 0 }, |
Mtypescriptdefault / TopLevel.ts+8 −6
| @@ -7,7 +7,9 @@ | ||
| 7 | 7 | // These functions will throw an error if the JSON doesn't |
| 8 | 8 | // match the expected interface, even if the JSON is valid. |
| 9 | 9 | |
| 10 | -export interface TopLevel { | |
| 10 | +export type TopLevel = TopLevelElement[]; | |
| 11 | + | |
| 12 | +export interface TopLevelElement { | |
| 11 | 13 | age: number; |
| 12 | 14 | country: Country; |
| 13 | 15 | females: number; |
| @@ -21,12 +23,12 @@ export type Country = "United States"; | ||
| 21 | 23 | // Converts JSON strings to/from your types |
| 22 | 24 | // and asserts the results of JSON.parse at runtime |
| 23 | 25 | export class Convert { |
| 24 | - public static toTopLevel(json: string): TopLevel[] { | |
| 25 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 26 | + public static toTopLevel(json: string): TopLevelElement[] { | |
| 27 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 26 | 28 | } |
| 27 | 29 | |
| 28 | - public static topLevelToJson(value: TopLevel[]): string { | |
| 29 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 30 | + public static topLevelToJson(value: TopLevelElement[]): string { | |
| 31 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 30 | 32 | } |
| 31 | 33 | } |
| 32 | 34 | |
| @@ -184,7 +186,7 @@ function r(name: string) { | ||
| 184 | 186 | } |
| 185 | 187 | |
| 186 | 188 | const typeMap: any = { |
| 187 | - "TopLevel": o([ | |
| 189 | + "TopLevelElement": o([ | |
| 188 | 190 | { json: "age", js: "age", typ: 0 }, |
| 189 | 191 | { json: "country", js: "country", typ: r("Country") }, |
| 190 | 192 | { json: "females", js: "females", typ: 0 }, |
Test case
3 generated files · +19 −15test/inputs/json/misc/ab0d1.json
Mflowdefault / TopLevel.js+8 −6
| @@ -9,7 +9,9 @@ | ||
| 9 | 9 | // These functions will throw an error if the JSON doesn't |
| 10 | 10 | // match the expected interface, even if the JSON is valid. |
| 11 | 11 | |
| 12 | -export type TopLevel = { | |
| 12 | +export type TopLevel = TopLevelElement[]; | |
| 13 | + | |
| 14 | +export type TopLevelElement = { | |
| 13 | 15 | age: number; |
| 14 | 16 | country: Country; |
| 15 | 17 | females: number; |
| @@ -23,12 +25,12 @@ export type Country = | ||
| 23 | 25 | |
| 24 | 26 | // Converts JSON strings to/from your types |
| 25 | 27 | // and asserts the results of JSON.parse at runtime |
| 26 | -function toTopLevel(json: string): TopLevel[] { | |
| 27 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 28 | +function toTopLevel(json: string): TopLevelElement[] { | |
| 29 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 28 | 30 | } |
| 29 | 31 | |
| 30 | -function topLevelToJson(value: TopLevel[]): string { | |
| 31 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 32 | +function topLevelToJson(value: TopLevelElement[]): string { | |
| 33 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 32 | 34 | } |
| 33 | 35 | |
| 34 | 36 | function invalidValue(typ: any, val: any, key: any, parent: any = '') { |
| @@ -185,7 +187,7 @@ function r(name: string) { | ||
| 185 | 187 | } |
| 186 | 188 | |
| 187 | 189 | const typeMap: any = { |
| 188 | - "TopLevel": o([ | |
| 190 | + "TopLevelElement": o([ | |
| 189 | 191 | { json: "age", js: "age", typ: 0 }, |
| 190 | 192 | { json: "country", js: "country", typ: r("Country") }, |
| 191 | 193 | { json: "females", js: "females", typ: 0 }, |
Mjavascriptdefault / TopLevel.js+3 −3
| @@ -10,11 +10,11 @@ | ||
| 10 | 10 | // Converts JSON strings to/from your types |
| 11 | 11 | // and asserts the results of JSON.parse at runtime |
| 12 | 12 | function toTopLevel(json) { |
| 13 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 13 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | function topLevelToJson(value) { |
| 17 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 17 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | function invalidValue(typ, val, key, parent = '') { |
| @@ -171,7 +171,7 @@ function r(name) { | ||
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | const typeMap = { |
| 174 | - "TopLevel": o([ | |
| 174 | + "TopLevelElement": o([ | |
| 175 | 175 | { json: "age", js: "age", typ: 0 }, |
| 176 | 176 | { json: "country", js: "country", typ: r("Country") }, |
| 177 | 177 | { json: "females", js: "females", typ: 0 }, |
Mtypescriptdefault / TopLevel.ts+8 −6
| @@ -7,7 +7,9 @@ | ||
| 7 | 7 | // These functions will throw an error if the JSON doesn't |
| 8 | 8 | // match the expected interface, even if the JSON is valid. |
| 9 | 9 | |
| 10 | -export interface TopLevel { | |
| 10 | +export type TopLevel = TopLevelElement[]; | |
| 11 | + | |
| 12 | +export interface TopLevelElement { | |
| 11 | 13 | age: number; |
| 12 | 14 | country: Country; |
| 13 | 15 | females: number; |
| @@ -21,12 +23,12 @@ export type Country = "United States"; | ||
| 21 | 23 | // Converts JSON strings to/from your types |
| 22 | 24 | // and asserts the results of JSON.parse at runtime |
| 23 | 25 | export class Convert { |
| 24 | - public static toTopLevel(json: string): TopLevel[] { | |
| 25 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 26 | + public static toTopLevel(json: string): TopLevelElement[] { | |
| 27 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 26 | 28 | } |
| 27 | 29 | |
| 28 | - public static topLevelToJson(value: TopLevel[]): string { | |
| 29 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 30 | + public static topLevelToJson(value: TopLevelElement[]): string { | |
| 31 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 30 | 32 | } |
| 31 | 33 | } |
| 32 | 34 | |
| @@ -184,7 +186,7 @@ function r(name: string) { | ||
| 184 | 186 | } |
| 185 | 187 | |
| 186 | 188 | const typeMap: any = { |
| 187 | - "TopLevel": o([ | |
| 189 | + "TopLevelElement": o([ | |
| 188 | 190 | { json: "age", js: "age", typ: 0 }, |
| 189 | 191 | { json: "country", js: "country", typ: r("Country") }, |
| 190 | 192 | { json: "females", js: "females", typ: 0 }, |
Test case
3 generated files · +19 −15test/inputs/json/misc/ad8be.json
Mflowdefault / TopLevel.js+8 −6
| @@ -9,7 +9,9 @@ | ||
| 9 | 9 | // These functions will throw an error if the JSON doesn't |
| 10 | 10 | // match the expected interface, even if the JSON is valid. |
| 11 | 11 | |
| 12 | -export type TopLevel = { | |
| 12 | +export type TopLevel = TopLevelElement[]; | |
| 13 | + | |
| 14 | +export type TopLevelElement = { | |
| 13 | 15 | id: string; |
| 14 | 16 | identifiers: Identifier[]; |
| 15 | 17 | keywords: Keyword[]; |
| @@ -80,12 +82,12 @@ export type Title = | ||
| 80 | 82 | |
| 81 | 83 | // Converts JSON strings to/from your types |
| 82 | 84 | // and asserts the results of JSON.parse at runtime |
| 83 | -function toTopLevel(json: string): TopLevel[] { | |
| 84 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 85 | +function toTopLevel(json: string): TopLevelElement[] { | |
| 86 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 85 | 87 | } |
| 86 | 88 | |
| 87 | -function topLevelToJson(value: TopLevel[]): string { | |
| 88 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 89 | +function topLevelToJson(value: TopLevelElement[]): string { | |
| 90 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 89 | 91 | } |
| 90 | 92 | |
| 91 | 93 | function invalidValue(typ: any, val: any, key: any, parent: any = '') { |
| @@ -242,7 +244,7 @@ function r(name: string) { | ||
| 242 | 244 | } |
| 243 | 245 | |
| 244 | 246 | const typeMap: any = { |
| 245 | - "TopLevel": o([ | |
| 247 | + "TopLevelElement": o([ | |
| 246 | 248 | { json: "id", js: "id", typ: "" }, |
| 247 | 249 | { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) }, |
| 248 | 250 | { json: "keywords", js: "keywords", typ: a(r("Keyword")) }, |
Mjavascriptdefault / TopLevel.js+3 −3
| @@ -10,11 +10,11 @@ | ||
| 10 | 10 | // Converts JSON strings to/from your types |
| 11 | 11 | // and asserts the results of JSON.parse at runtime |
| 12 | 12 | function toTopLevel(json) { |
| 13 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 13 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | function topLevelToJson(value) { |
| 17 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 17 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | function invalidValue(typ, val, key, parent = '') { |
| @@ -171,7 +171,7 @@ function r(name) { | ||
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | const typeMap = { |
| 174 | - "TopLevel": o([ | |
| 174 | + "TopLevelElement": o([ | |
| 175 | 175 | { json: "id", js: "id", typ: "" }, |
| 176 | 176 | { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) }, |
| 177 | 177 | { json: "keywords", js: "keywords", typ: a(r("Keyword")) }, |
Mtypescriptdefault / TopLevel.ts+8 −6
| @@ -7,7 +7,9 @@ | ||
| 7 | 7 | // These functions will throw an error if the JSON doesn't |
| 8 | 8 | // match the expected interface, even if the JSON is valid. |
| 9 | 9 | |
| 10 | -export interface TopLevel { | |
| 10 | +export type TopLevel = TopLevelElement[]; | |
| 11 | + | |
| 12 | +export interface TopLevelElement { | |
| 11 | 13 | id: string; |
| 12 | 14 | identifiers: Identifier[]; |
| 13 | 15 | keywords: Keyword[]; |
| @@ -52,12 +54,12 @@ export type Title = "HTML" | "Plain Text" | "PDF"; | ||
| 52 | 54 | // Converts JSON strings to/from your types |
| 53 | 55 | // and asserts the results of JSON.parse at runtime |
| 54 | 56 | export class Convert { |
| 55 | - public static toTopLevel(json: string): TopLevel[] { | |
| 56 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 57 | + public static toTopLevel(json: string): TopLevelElement[] { | |
| 58 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 57 | 59 | } |
| 58 | 60 | |
| 59 | - public static topLevelToJson(value: TopLevel[]): string { | |
| 60 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 61 | + public static topLevelToJson(value: TopLevelElement[]): string { | |
| 62 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 61 | 63 | } |
| 62 | 64 | } |
| 63 | 65 | |
| @@ -215,7 +217,7 @@ function r(name: string) { | ||
| 215 | 217 | } |
| 216 | 218 | |
| 217 | 219 | const typeMap: any = { |
| 218 | - "TopLevel": o([ | |
| 220 | + "TopLevelElement": o([ | |
| 219 | 221 | { json: "id", js: "id", typ: "" }, |
| 220 | 222 | { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) }, |
| 221 | 223 | { json: "keywords", js: "keywords", typ: a(r("Keyword")) }, |
Test case
3 generated files · +19 −15test/inputs/json/misc/b4865.json
Mflowdefault / TopLevel.js+8 −6
| @@ -9,7 +9,9 @@ | ||
| 9 | 9 | // These functions will throw an error if the JSON doesn't |
| 10 | 10 | // match the expected interface, even if the JSON is valid. |
| 11 | 11 | |
| 12 | -export type TopLevel = { | |
| 12 | +export type TopLevel = TopLevelElement[]; | |
| 13 | + | |
| 14 | +export type TopLevelElement = { | |
| 13 | 15 | ":@computed_region_cbhk_fwbd"?: string; |
| 14 | 16 | ":@computed_region_nnqa_25f4"?: string; |
| 15 | 17 | fall: Fall; |
| @@ -41,12 +43,12 @@ export type Nametype = | ||
| 41 | 43 | |
| 42 | 44 | // Converts JSON strings to/from your types |
| 43 | 45 | // and asserts the results of JSON.parse at runtime |
| 44 | -function toTopLevel(json: string): TopLevel[] { | |
| 45 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 46 | +function toTopLevel(json: string): TopLevelElement[] { | |
| 47 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 46 | 48 | } |
| 47 | 49 | |
| 48 | -function topLevelToJson(value: TopLevel[]): string { | |
| 49 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 50 | +function topLevelToJson(value: TopLevelElement[]): string { | |
| 51 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 50 | 52 | } |
| 51 | 53 | |
| 52 | 54 | function invalidValue(typ: any, val: any, key: any, parent: any = '') { |
| @@ -203,7 +205,7 @@ function r(name: string) { | ||
| 203 | 205 | } |
| 204 | 206 | |
| 205 | 207 | const typeMap: any = { |
| 206 | - "TopLevel": o([ | |
| 208 | + "TopLevelElement": o([ | |
| 207 | 209 | { json: ":@computed_region_cbhk_fwbd", js: ":@computed_region_cbhk_fwbd", typ: u(undefined, "") }, |
| 208 | 210 | { json: ":@computed_region_nnqa_25f4", js: ":@computed_region_nnqa_25f4", typ: u(undefined, "") }, |
| 209 | 211 | { json: "fall", js: "fall", typ: r("Fall") }, |
Mjavascriptdefault / TopLevel.js+3 −3
| @@ -10,11 +10,11 @@ | ||
| 10 | 10 | // Converts JSON strings to/from your types |
| 11 | 11 | // and asserts the results of JSON.parse at runtime |
| 12 | 12 | function toTopLevel(json) { |
| 13 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 13 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | function topLevelToJson(value) { |
| 17 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 17 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | function invalidValue(typ, val, key, parent = '') { |
| @@ -171,7 +171,7 @@ function r(name) { | ||
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | const typeMap = { |
| 174 | - "TopLevel": o([ | |
| 174 | + "TopLevelElement": o([ | |
| 175 | 175 | { json: ":@computed_region_cbhk_fwbd", js: ":@computed_region_cbhk_fwbd", typ: u(undefined, "") }, |
| 176 | 176 | { json: ":@computed_region_nnqa_25f4", js: ":@computed_region_nnqa_25f4", typ: u(undefined, "") }, |
| 177 | 177 | { json: "fall", js: "fall", typ: r("Fall") }, |
Mtypescriptdefault / TopLevel.ts+8 −6
| @@ -7,7 +7,9 @@ | ||
| 7 | 7 | // These functions will throw an error if the JSON doesn't |
| 8 | 8 | // match the expected interface, even if the JSON is valid. |
| 9 | 9 | |
| 10 | -export interface TopLevel { | |
| 10 | +export type TopLevel = TopLevelElement[]; | |
| 11 | + | |
| 12 | +export interface TopLevelElement { | |
| 11 | 13 | ":@computed_region_cbhk_fwbd"?: string; |
| 12 | 14 | ":@computed_region_nnqa_25f4"?: string; |
| 13 | 15 | fall: Fall; |
| @@ -36,12 +38,12 @@ export type Nametype = "Valid"; | ||
| 36 | 38 | // Converts JSON strings to/from your types |
| 37 | 39 | // and asserts the results of JSON.parse at runtime |
| 38 | 40 | export class Convert { |
| 39 | - public static toTopLevel(json: string): TopLevel[] { | |
| 40 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 41 | + public static toTopLevel(json: string): TopLevelElement[] { | |
| 42 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 41 | 43 | } |
| 42 | 44 | |
| 43 | - public static topLevelToJson(value: TopLevel[]): string { | |
| 44 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 45 | + public static topLevelToJson(value: TopLevelElement[]): string { | |
| 46 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 45 | 47 | } |
| 46 | 48 | } |
| 47 | 49 | |
| @@ -199,7 +201,7 @@ function r(name: string) { | ||
| 199 | 201 | } |
| 200 | 202 | |
| 201 | 203 | const typeMap: any = { |
| 202 | - "TopLevel": o([ | |
| 204 | + "TopLevelElement": o([ | |
| 203 | 205 | { json: ":@computed_region_cbhk_fwbd", js: ":@computed_region_cbhk_fwbd", typ: u(undefined, "") }, |
| 204 | 206 | { json: ":@computed_region_nnqa_25f4", js: ":@computed_region_nnqa_25f4", typ: u(undefined, "") }, |
| 205 | 207 | { json: "fall", js: "fall", typ: r("Fall") }, |
Test case
3 generated files · +26 −22test/inputs/json/misc/c8c7e.json
Mflowdefault / TopLevel.js+11 −9
| @@ -9,9 +9,11 @@ | ||
| 9 | 9 | // These functions will throw an error if the JSON doesn't |
| 10 | 10 | // match the expected interface, even if the JSON is valid. |
| 11 | 11 | |
| 12 | -export type TopLevel = TopLevelElement[] | PurpleTopLevel; | |
| 12 | +export type TopLevel = TopLevelUnion[]; | |
| 13 | 13 | |
| 14 | -export type TopLevelElement = { | |
| 14 | +export type TopLevelUnion = PurpleTopLevel[] | FluffyTopLevel; | |
| 15 | + | |
| 16 | +export type PurpleTopLevel = { | |
| 15 | 17 | country: Country; |
| 16 | 18 | date: string; |
| 17 | 19 | decimal: string; |
| @@ -32,7 +34,7 @@ export type Value = | ||
| 32 | 34 | "India" |
| 33 | 35 | | "GDP (current US$)"; |
| 34 | 36 | |
| 35 | -export type PurpleTopLevel = { | |
| 37 | +export type FluffyTopLevel = { | |
| 36 | 38 | page: number; |
| 37 | 39 | pages: number; |
| 38 | 40 | per_page: string; |
| @@ -41,12 +43,12 @@ export type PurpleTopLevel = { | ||
| 41 | 43 | |
| 42 | 44 | // Converts JSON strings to/from your types |
| 43 | 45 | // and asserts the results of JSON.parse at runtime |
| 44 | -function toTopLevel(json: string): TopLevel[] { | |
| 45 | - return cast(JSON.parse(json), a(u(a(r("TopLevelElement")), r("PurpleTopLevel")))); | |
| 46 | +function toTopLevel(json: string): TopLevelUnion[] { | |
| 47 | + return cast(JSON.parse(json), a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel")))); | |
| 46 | 48 | } |
| 47 | 49 | |
| 48 | -function topLevelToJson(value: TopLevel[]): string { | |
| 49 | - return JSON.stringify(uncast(value, a(u(a(r("TopLevelElement")), r("PurpleTopLevel")))), null, 2); | |
| 50 | +function topLevelToJson(value: TopLevelUnion[]): string { | |
| 51 | + return JSON.stringify(uncast(value, a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel")))), null, 2); | |
| 50 | 52 | } |
| 51 | 53 | |
| 52 | 54 | function invalidValue(typ: any, val: any, key: any, parent: any = '') { |
| @@ -203,7 +205,7 @@ function r(name: string) { | ||
| 203 | 205 | } |
| 204 | 206 | |
| 205 | 207 | const typeMap: any = { |
| 206 | - "TopLevelElement": o([ | |
| 208 | + "PurpleTopLevel": o([ | |
| 207 | 209 | { json: "country", js: "country", typ: r("Country") }, |
| 208 | 210 | { json: "date", js: "date", typ: "" }, |
| 209 | 211 | { json: "decimal", js: "decimal", typ: "" }, |
| @@ -214,7 +216,7 @@ const typeMap: any = { | ||
| 214 | 216 | { json: "id", js: "id", typ: r("ID") }, |
| 215 | 217 | { json: "value", js: "value", typ: r("Value") }, |
| 216 | 218 | ], false), |
| 217 | - "PurpleTopLevel": o([ | |
| 219 | + "FluffyTopLevel": o([ | |
| 218 | 220 | { json: "page", js: "page", typ: 0 }, |
| 219 | 221 | { json: "pages", js: "pages", typ: 0 }, |
| 220 | 222 | { json: "per_page", js: "per_page", typ: "" }, |
Mjavascriptdefault / TopLevel.js+4 −4
| @@ -10,11 +10,11 @@ | ||
| 10 | 10 | // Converts JSON strings to/from your types |
| 11 | 11 | // and asserts the results of JSON.parse at runtime |
| 12 | 12 | function toTopLevel(json) { |
| 13 | - return cast(JSON.parse(json), a(u(a(r("TopLevelElement")), r("PurpleTopLevel")))); | |
| 13 | + return cast(JSON.parse(json), a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel")))); | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | function topLevelToJson(value) { |
| 17 | - return JSON.stringify(uncast(value, a(u(a(r("TopLevelElement")), r("PurpleTopLevel")))), null, 2); | |
| 17 | + return JSON.stringify(uncast(value, a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel")))), null, 2); | |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | function invalidValue(typ, val, key, parent = '') { |
| @@ -171,7 +171,7 @@ function r(name) { | ||
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | const typeMap = { |
| 174 | - "TopLevelElement": o([ | |
| 174 | + "PurpleTopLevel": o([ | |
| 175 | 175 | { json: "country", js: "country", typ: r("Country") }, |
| 176 | 176 | { json: "date", js: "date", typ: "" }, |
| 177 | 177 | { json: "decimal", js: "decimal", typ: "" }, |
| @@ -182,7 +182,7 @@ const typeMap = { | ||
| 182 | 182 | { json: "id", js: "id", typ: r("ID") }, |
| 183 | 183 | { json: "value", js: "value", typ: r("Value") }, |
| 184 | 184 | ], false), |
| 185 | - "PurpleTopLevel": o([ | |
| 185 | + "FluffyTopLevel": o([ | |
| 186 | 186 | { json: "page", js: "page", typ: 0 }, |
| 187 | 187 | { json: "pages", js: "pages", typ: 0 }, |
| 188 | 188 | { json: "per_page", js: "per_page", typ: "" }, |
Mtypescriptdefault / TopLevel.ts+11 −9
| @@ -7,9 +7,11 @@ | ||
| 7 | 7 | // These functions will throw an error if the JSON doesn't |
| 8 | 8 | // match the expected interface, even if the JSON is valid. |
| 9 | 9 | |
| 10 | -export type TopLevel = TopLevelElement[] | PurpleTopLevel; | |
| 10 | +export type TopLevel = TopLevelUnion[]; | |
| 11 | 11 | |
| 12 | -export interface TopLevelElement { | |
| 12 | +export type TopLevelUnion = PurpleTopLevel[] | FluffyTopLevel; | |
| 13 | + | |
| 14 | +export interface PurpleTopLevel { | |
| 13 | 15 | country: Country; |
| 14 | 16 | date: string; |
| 15 | 17 | decimal: string; |
| @@ -26,7 +28,7 @@ export type ID = "IN" | "NY.GDP.MKTP.CD"; | ||
| 26 | 28 | |
| 27 | 29 | export type Value = "India" | "GDP (current US$)"; |
| 28 | 30 | |
| 29 | -export interface PurpleTopLevel { | |
| 31 | +export interface FluffyTopLevel { | |
| 30 | 32 | page: number; |
| 31 | 33 | pages: number; |
| 32 | 34 | per_page: string; |
| @@ -36,12 +38,12 @@ export interface PurpleTopLevel { | ||
| 36 | 38 | // Converts JSON strings to/from your types |
| 37 | 39 | // and asserts the results of JSON.parse at runtime |
| 38 | 40 | export class Convert { |
| 39 | - public static toTopLevel(json: string): TopLevel[] { | |
| 40 | - return cast(JSON.parse(json), a(u(a(r("TopLevelElement")), r("PurpleTopLevel")))); | |
| 41 | + public static toTopLevel(json: string): TopLevelUnion[] { | |
| 42 | + return cast(JSON.parse(json), a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel")))); | |
| 41 | 43 | } |
| 42 | 44 | |
| 43 | - public static topLevelToJson(value: TopLevel[]): string { | |
| 44 | - return JSON.stringify(uncast(value, a(u(a(r("TopLevelElement")), r("PurpleTopLevel")))), null, 2); | |
| 45 | + public static topLevelToJson(value: TopLevelUnion[]): string { | |
| 46 | + return JSON.stringify(uncast(value, a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel")))), null, 2); | |
| 45 | 47 | } |
| 46 | 48 | } |
| 47 | 49 | |
| @@ -199,7 +201,7 @@ function r(name: string) { | ||
| 199 | 201 | } |
| 200 | 202 | |
| 201 | 203 | const typeMap: any = { |
| 202 | - "TopLevelElement": o([ | |
| 204 | + "PurpleTopLevel": o([ | |
| 203 | 205 | { json: "country", js: "country", typ: r("Country") }, |
| 204 | 206 | { json: "date", js: "date", typ: "" }, |
| 205 | 207 | { json: "decimal", js: "decimal", typ: "" }, |
| @@ -210,7 +212,7 @@ const typeMap: any = { | ||
| 210 | 212 | { json: "id", js: "id", typ: r("ID") }, |
| 211 | 213 | { json: "value", js: "value", typ: r("Value") }, |
| 212 | 214 | ], false), |
| 213 | - "PurpleTopLevel": o([ | |
| 215 | + "FluffyTopLevel": o([ | |
| 214 | 216 | { json: "page", js: "page", typ: 0 }, |
| 215 | 217 | { json: "pages", js: "pages", typ: 0 }, |
| 216 | 218 | { json: "per_page", js: "per_page", typ: "" }, |
Test case
3 generated files · +26 −22test/inputs/json/misc/cda6c.json
Mflowdefault / TopLevel.js+11 −9
| @@ -9,9 +9,11 @@ | ||
| 9 | 9 | // These functions will throw an error if the JSON doesn't |
| 10 | 10 | // match the expected interface, even if the JSON is valid. |
| 11 | 11 | |
| 12 | -export type TopLevel = TopLevelElement[] | PurpleTopLevel; | |
| 12 | +export type TopLevel = TopLevelUnion[]; | |
| 13 | 13 | |
| 14 | -export type TopLevelElement = { | |
| 14 | +export type TopLevelUnion = PurpleTopLevel[] | FluffyTopLevel; | |
| 15 | + | |
| 16 | +export type PurpleTopLevel = { | |
| 15 | 17 | country: Country; |
| 16 | 18 | date: string; |
| 17 | 19 | decimal: string; |
| @@ -32,7 +34,7 @@ export type Value = | ||
| 32 | 34 | "China" |
| 33 | 35 | | "Population, total"; |
| 34 | 36 | |
| 35 | -export type PurpleTopLevel = { | |
| 37 | +export type FluffyTopLevel = { | |
| 36 | 38 | page: number; |
| 37 | 39 | pages: number; |
| 38 | 40 | per_page: string; |
| @@ -41,12 +43,12 @@ export type PurpleTopLevel = { | ||
| 41 | 43 | |
| 42 | 44 | // Converts JSON strings to/from your types |
| 43 | 45 | // and asserts the results of JSON.parse at runtime |
| 44 | -function toTopLevel(json: string): TopLevel[] { | |
| 45 | - return cast(JSON.parse(json), a(u(a(r("TopLevelElement")), r("PurpleTopLevel")))); | |
| 46 | +function toTopLevel(json: string): TopLevelUnion[] { | |
| 47 | + return cast(JSON.parse(json), a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel")))); | |
| 46 | 48 | } |
| 47 | 49 | |
| 48 | -function topLevelToJson(value: TopLevel[]): string { | |
| 49 | - return JSON.stringify(uncast(value, a(u(a(r("TopLevelElement")), r("PurpleTopLevel")))), null, 2); | |
| 50 | +function topLevelToJson(value: TopLevelUnion[]): string { | |
| 51 | + return JSON.stringify(uncast(value, a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel")))), null, 2); | |
| 50 | 52 | } |
| 51 | 53 | |
| 52 | 54 | function invalidValue(typ: any, val: any, key: any, parent: any = '') { |
| @@ -203,7 +205,7 @@ function r(name: string) { | ||
| 203 | 205 | } |
| 204 | 206 | |
| 205 | 207 | const typeMap: any = { |
| 206 | - "TopLevelElement": o([ | |
| 208 | + "PurpleTopLevel": o([ | |
| 207 | 209 | { json: "country", js: "country", typ: r("Country") }, |
| 208 | 210 | { json: "date", js: "date", typ: "" }, |
| 209 | 211 | { json: "decimal", js: "decimal", typ: "" }, |
| @@ -214,7 +216,7 @@ const typeMap: any = { | ||
| 214 | 216 | { json: "id", js: "id", typ: r("ID") }, |
| 215 | 217 | { json: "value", js: "value", typ: r("Value") }, |
| 216 | 218 | ], false), |
| 217 | - "PurpleTopLevel": o([ | |
| 219 | + "FluffyTopLevel": o([ | |
| 218 | 220 | { json: "page", js: "page", typ: 0 }, |
| 219 | 221 | { json: "pages", js: "pages", typ: 0 }, |
| 220 | 222 | { json: "per_page", js: "per_page", typ: "" }, |
Mjavascriptdefault / TopLevel.js+4 −4
| @@ -10,11 +10,11 @@ | ||
| 10 | 10 | // Converts JSON strings to/from your types |
| 11 | 11 | // and asserts the results of JSON.parse at runtime |
| 12 | 12 | function toTopLevel(json) { |
| 13 | - return cast(JSON.parse(json), a(u(a(r("TopLevelElement")), r("PurpleTopLevel")))); | |
| 13 | + return cast(JSON.parse(json), a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel")))); | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | function topLevelToJson(value) { |
| 17 | - return JSON.stringify(uncast(value, a(u(a(r("TopLevelElement")), r("PurpleTopLevel")))), null, 2); | |
| 17 | + return JSON.stringify(uncast(value, a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel")))), null, 2); | |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | function invalidValue(typ, val, key, parent = '') { |
| @@ -171,7 +171,7 @@ function r(name) { | ||
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | const typeMap = { |
| 174 | - "TopLevelElement": o([ | |
| 174 | + "PurpleTopLevel": o([ | |
| 175 | 175 | { json: "country", js: "country", typ: r("Country") }, |
| 176 | 176 | { json: "date", js: "date", typ: "" }, |
| 177 | 177 | { json: "decimal", js: "decimal", typ: "" }, |
| @@ -182,7 +182,7 @@ const typeMap = { | ||
| 182 | 182 | { json: "id", js: "id", typ: r("ID") }, |
| 183 | 183 | { json: "value", js: "value", typ: r("Value") }, |
| 184 | 184 | ], false), |
| 185 | - "PurpleTopLevel": o([ | |
| 185 | + "FluffyTopLevel": o([ | |
| 186 | 186 | { json: "page", js: "page", typ: 0 }, |
| 187 | 187 | { json: "pages", js: "pages", typ: 0 }, |
| 188 | 188 | { json: "per_page", js: "per_page", typ: "" }, |
Mtypescriptdefault / TopLevel.ts+11 −9
| @@ -7,9 +7,11 @@ | ||
| 7 | 7 | // These functions will throw an error if the JSON doesn't |
| 8 | 8 | // match the expected interface, even if the JSON is valid. |
| 9 | 9 | |
| 10 | -export type TopLevel = TopLevelElement[] | PurpleTopLevel; | |
| 10 | +export type TopLevel = TopLevelUnion[]; | |
| 11 | 11 | |
| 12 | -export interface TopLevelElement { | |
| 12 | +export type TopLevelUnion = PurpleTopLevel[] | FluffyTopLevel; | |
| 13 | + | |
| 14 | +export interface PurpleTopLevel { | |
| 13 | 15 | country: Country; |
| 14 | 16 | date: string; |
| 15 | 17 | decimal: string; |
| @@ -26,7 +28,7 @@ export type ID = "CN" | "SP.POP.TOTL"; | ||
| 26 | 28 | |
| 27 | 29 | export type Value = "China" | "Population, total"; |
| 28 | 30 | |
| 29 | -export interface PurpleTopLevel { | |
| 31 | +export interface FluffyTopLevel { | |
| 30 | 32 | page: number; |
| 31 | 33 | pages: number; |
| 32 | 34 | per_page: string; |
| @@ -36,12 +38,12 @@ export interface PurpleTopLevel { | ||
| 36 | 38 | // Converts JSON strings to/from your types |
| 37 | 39 | // and asserts the results of JSON.parse at runtime |
| 38 | 40 | export class Convert { |
| 39 | - public static toTopLevel(json: string): TopLevel[] { | |
| 40 | - return cast(JSON.parse(json), a(u(a(r("TopLevelElement")), r("PurpleTopLevel")))); | |
| 41 | + public static toTopLevel(json: string): TopLevelUnion[] { | |
| 42 | + return cast(JSON.parse(json), a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel")))); | |
| 41 | 43 | } |
| 42 | 44 | |
| 43 | - public static topLevelToJson(value: TopLevel[]): string { | |
| 44 | - return JSON.stringify(uncast(value, a(u(a(r("TopLevelElement")), r("PurpleTopLevel")))), null, 2); | |
| 45 | + public static topLevelToJson(value: TopLevelUnion[]): string { | |
| 46 | + return JSON.stringify(uncast(value, a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel")))), null, 2); | |
| 45 | 47 | } |
| 46 | 48 | } |
| 47 | 49 | |
| @@ -199,7 +201,7 @@ function r(name: string) { | ||
| 199 | 201 | } |
| 200 | 202 | |
| 201 | 203 | const typeMap: any = { |
| 202 | - "TopLevelElement": o([ | |
| 204 | + "PurpleTopLevel": o([ | |
| 203 | 205 | { json: "country", js: "country", typ: r("Country") }, |
| 204 | 206 | { json: "date", js: "date", typ: "" }, |
| 205 | 207 | { json: "decimal", js: "decimal", typ: "" }, |
| @@ -210,7 +212,7 @@ const typeMap: any = { | ||
| 210 | 212 | { json: "id", js: "id", typ: r("ID") }, |
| 211 | 213 | { json: "value", js: "value", typ: r("Value") }, |
| 212 | 214 | ], false), |
| 213 | - "PurpleTopLevel": o([ | |
| 215 | + "FluffyTopLevel": o([ | |
| 214 | 216 | { json: "page", js: "page", typ: 0 }, |
| 215 | 217 | { json: "pages", js: "pages", typ: 0 }, |
| 216 | 218 | { json: "per_page", js: "per_page", typ: "" }, |
Test case
3 generated files · +19 −15test/inputs/json/misc/e2a58.json
Mflowdefault / TopLevel.js+8 −6
| @@ -9,19 +9,21 @@ | ||
| 9 | 9 | // These functions will throw an error if the JSON doesn't |
| 10 | 10 | // match the expected interface, even if the JSON is valid. |
| 11 | 11 | |
| 12 | -export type TopLevel = { | |
| 12 | +export type TopLevel = TopLevelElement[]; | |
| 13 | + | |
| 14 | +export type TopLevelElement = { | |
| 13 | 15 | date: string; |
| 14 | 16 | "stop-and-search": string[]; |
| 15 | 17 | }; |
| 16 | 18 | |
| 17 | 19 | // Converts JSON strings to/from your types |
| 18 | 20 | // and asserts the results of JSON.parse at runtime |
| 19 | -function toTopLevel(json: string): TopLevel[] { | |
| 20 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 21 | +function toTopLevel(json: string): TopLevelElement[] { | |
| 22 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 21 | 23 | } |
| 22 | 24 | |
| 23 | -function topLevelToJson(value: TopLevel[]): string { | |
| 24 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 25 | +function topLevelToJson(value: TopLevelElement[]): string { | |
| 26 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 25 | 27 | } |
| 26 | 28 | |
| 27 | 29 | function invalidValue(typ: any, val: any, key: any, parent: any = '') { |
| @@ -178,7 +180,7 @@ function r(name: string) { | ||
| 178 | 180 | } |
| 179 | 181 | |
| 180 | 182 | const typeMap: any = { |
| 181 | - "TopLevel": o([ | |
| 183 | + "TopLevelElement": o([ | |
| 182 | 184 | { json: "date", js: "date", typ: "" }, |
| 183 | 185 | { json: "stop-and-search", js: "stop-and-search", typ: a("") }, |
| 184 | 186 | ], false), |
Mjavascriptdefault / TopLevel.js+3 −3
| @@ -10,11 +10,11 @@ | ||
| 10 | 10 | // Converts JSON strings to/from your types |
| 11 | 11 | // and asserts the results of JSON.parse at runtime |
| 12 | 12 | function toTopLevel(json) { |
| 13 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 13 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | function topLevelToJson(value) { |
| 17 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 17 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | function invalidValue(typ, val, key, parent = '') { |
| @@ -171,7 +171,7 @@ function r(name) { | ||
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | const typeMap = { |
| 174 | - "TopLevel": o([ | |
| 174 | + "TopLevelElement": o([ | |
| 175 | 175 | { json: "date", js: "date", typ: "" }, |
| 176 | 176 | { json: "stop-and-search", js: "stop-and-search", typ: a("") }, |
| 177 | 177 | ], false), |
Mtypescriptdefault / TopLevel.ts+8 −6
| @@ -7,7 +7,9 @@ | ||
| 7 | 7 | // These functions will throw an error if the JSON doesn't |
| 8 | 8 | // match the expected interface, even if the JSON is valid. |
| 9 | 9 | |
| 10 | -export interface TopLevel { | |
| 10 | +export type TopLevel = TopLevelElement[]; | |
| 11 | + | |
| 12 | +export interface TopLevelElement { | |
| 11 | 13 | date: string; |
| 12 | 14 | "stop-and-search": string[]; |
| 13 | 15 | } |
| @@ -15,12 +17,12 @@ export interface TopLevel { | ||
| 15 | 17 | // Converts JSON strings to/from your types |
| 16 | 18 | // and asserts the results of JSON.parse at runtime |
| 17 | 19 | export class Convert { |
| 18 | - public static toTopLevel(json: string): TopLevel[] { | |
| 19 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 20 | + public static toTopLevel(json: string): TopLevelElement[] { | |
| 21 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 20 | 22 | } |
| 21 | 23 | |
| 22 | - public static topLevelToJson(value: TopLevel[]): string { | |
| 23 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 24 | + public static topLevelToJson(value: TopLevelElement[]): string { | |
| 25 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 24 | 26 | } |
| 25 | 27 | } |
| 26 | 28 | |
| @@ -178,7 +180,7 @@ function r(name: string) { | ||
| 178 | 180 | } |
| 179 | 181 | |
| 180 | 182 | const typeMap: any = { |
| 181 | - "TopLevel": o([ | |
| 183 | + "TopLevelElement": o([ | |
| 182 | 184 | { json: "date", js: "date", typ: "" }, |
| 183 | 185 | { json: "stop-and-search", js: "stop-and-search", typ: a("") }, |
| 184 | 186 | ], false), |
Test case
3 generated files · +26 −22test/inputs/json/misc/e53b5.json
Mflowdefault / TopLevel.js+11 −9
| @@ -9,9 +9,11 @@ | ||
| 9 | 9 | // These functions will throw an error if the JSON doesn't |
| 10 | 10 | // match the expected interface, even if the JSON is valid. |
| 11 | 11 | |
| 12 | -export type TopLevel = TopLevelElement[] | PurpleTopLevel; | |
| 12 | +export type TopLevel = TopLevelUnion[]; | |
| 13 | 13 | |
| 14 | -export type TopLevelElement = { | |
| 14 | +export type TopLevelUnion = PurpleTopLevel[] | FluffyTopLevel; | |
| 15 | + | |
| 16 | +export type PurpleTopLevel = { | |
| 15 | 17 | country: Country; |
| 16 | 18 | date: string; |
| 17 | 19 | decimal: string; |
| @@ -32,7 +34,7 @@ export type Value = | ||
| 32 | 34 | "India" |
| 33 | 35 | | "Population, total"; |
| 34 | 36 | |
| 35 | -export type PurpleTopLevel = { | |
| 37 | +export type FluffyTopLevel = { | |
| 36 | 38 | page: number; |
| 37 | 39 | pages: number; |
| 38 | 40 | per_page: string; |
| @@ -41,12 +43,12 @@ export type PurpleTopLevel = { | ||
| 41 | 43 | |
| 42 | 44 | // Converts JSON strings to/from your types |
| 43 | 45 | // and asserts the results of JSON.parse at runtime |
| 44 | -function toTopLevel(json: string): TopLevel[] { | |
| 45 | - return cast(JSON.parse(json), a(u(a(r("TopLevelElement")), r("PurpleTopLevel")))); | |
| 46 | +function toTopLevel(json: string): TopLevelUnion[] { | |
| 47 | + return cast(JSON.parse(json), a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel")))); | |
| 46 | 48 | } |
| 47 | 49 | |
| 48 | -function topLevelToJson(value: TopLevel[]): string { | |
| 49 | - return JSON.stringify(uncast(value, a(u(a(r("TopLevelElement")), r("PurpleTopLevel")))), null, 2); | |
| 50 | +function topLevelToJson(value: TopLevelUnion[]): string { | |
| 51 | + return JSON.stringify(uncast(value, a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel")))), null, 2); | |
| 50 | 52 | } |
| 51 | 53 | |
| 52 | 54 | function invalidValue(typ: any, val: any, key: any, parent: any = '') { |
| @@ -203,7 +205,7 @@ function r(name: string) { | ||
| 203 | 205 | } |
| 204 | 206 | |
| 205 | 207 | const typeMap: any = { |
| 206 | - "TopLevelElement": o([ | |
| 208 | + "PurpleTopLevel": o([ | |
| 207 | 209 | { json: "country", js: "country", typ: r("Country") }, |
| 208 | 210 | { json: "date", js: "date", typ: "" }, |
| 209 | 211 | { json: "decimal", js: "decimal", typ: "" }, |
| @@ -214,7 +216,7 @@ const typeMap: any = { | ||
| 214 | 216 | { json: "id", js: "id", typ: r("ID") }, |
| 215 | 217 | { json: "value", js: "value", typ: r("Value") }, |
| 216 | 218 | ], false), |
| 217 | - "PurpleTopLevel": o([ | |
| 219 | + "FluffyTopLevel": o([ | |
| 218 | 220 | { json: "page", js: "page", typ: 0 }, |
| 219 | 221 | { json: "pages", js: "pages", typ: 0 }, |
| 220 | 222 | { json: "per_page", js: "per_page", typ: "" }, |
Mjavascriptdefault / TopLevel.js+4 −4
| @@ -10,11 +10,11 @@ | ||
| 10 | 10 | // Converts JSON strings to/from your types |
| 11 | 11 | // and asserts the results of JSON.parse at runtime |
| 12 | 12 | function toTopLevel(json) { |
| 13 | - return cast(JSON.parse(json), a(u(a(r("TopLevelElement")), r("PurpleTopLevel")))); | |
| 13 | + return cast(JSON.parse(json), a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel")))); | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | function topLevelToJson(value) { |
| 17 | - return JSON.stringify(uncast(value, a(u(a(r("TopLevelElement")), r("PurpleTopLevel")))), null, 2); | |
| 17 | + return JSON.stringify(uncast(value, a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel")))), null, 2); | |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | function invalidValue(typ, val, key, parent = '') { |
| @@ -171,7 +171,7 @@ function r(name) { | ||
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | const typeMap = { |
| 174 | - "TopLevelElement": o([ | |
| 174 | + "PurpleTopLevel": o([ | |
| 175 | 175 | { json: "country", js: "country", typ: r("Country") }, |
| 176 | 176 | { json: "date", js: "date", typ: "" }, |
| 177 | 177 | { json: "decimal", js: "decimal", typ: "" }, |
| @@ -182,7 +182,7 @@ const typeMap = { | ||
| 182 | 182 | { json: "id", js: "id", typ: r("ID") }, |
| 183 | 183 | { json: "value", js: "value", typ: r("Value") }, |
| 184 | 184 | ], false), |
| 185 | - "PurpleTopLevel": o([ | |
| 185 | + "FluffyTopLevel": o([ | |
| 186 | 186 | { json: "page", js: "page", typ: 0 }, |
| 187 | 187 | { json: "pages", js: "pages", typ: 0 }, |
| 188 | 188 | { json: "per_page", js: "per_page", typ: "" }, |
Mtypescriptdefault / TopLevel.ts+11 −9
| @@ -7,9 +7,11 @@ | ||
| 7 | 7 | // These functions will throw an error if the JSON doesn't |
| 8 | 8 | // match the expected interface, even if the JSON is valid. |
| 9 | 9 | |
| 10 | -export type TopLevel = TopLevelElement[] | PurpleTopLevel; | |
| 10 | +export type TopLevel = TopLevelUnion[]; | |
| 11 | 11 | |
| 12 | -export interface TopLevelElement { | |
| 12 | +export type TopLevelUnion = PurpleTopLevel[] | FluffyTopLevel; | |
| 13 | + | |
| 14 | +export interface PurpleTopLevel { | |
| 13 | 15 | country: Country; |
| 14 | 16 | date: string; |
| 15 | 17 | decimal: string; |
| @@ -26,7 +28,7 @@ export type ID = "IN" | "SP.POP.TOTL"; | ||
| 26 | 28 | |
| 27 | 29 | export type Value = "India" | "Population, total"; |
| 28 | 30 | |
| 29 | -export interface PurpleTopLevel { | |
| 31 | +export interface FluffyTopLevel { | |
| 30 | 32 | page: number; |
| 31 | 33 | pages: number; |
| 32 | 34 | per_page: string; |
| @@ -36,12 +38,12 @@ export interface PurpleTopLevel { | ||
| 36 | 38 | // Converts JSON strings to/from your types |
| 37 | 39 | // and asserts the results of JSON.parse at runtime |
| 38 | 40 | export class Convert { |
| 39 | - public static toTopLevel(json: string): TopLevel[] { | |
| 40 | - return cast(JSON.parse(json), a(u(a(r("TopLevelElement")), r("PurpleTopLevel")))); | |
| 41 | + public static toTopLevel(json: string): TopLevelUnion[] { | |
| 42 | + return cast(JSON.parse(json), a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel")))); | |
| 41 | 43 | } |
| 42 | 44 | |
| 43 | - public static topLevelToJson(value: TopLevel[]): string { | |
| 44 | - return JSON.stringify(uncast(value, a(u(a(r("TopLevelElement")), r("PurpleTopLevel")))), null, 2); | |
| 45 | + public static topLevelToJson(value: TopLevelUnion[]): string { | |
| 46 | + return JSON.stringify(uncast(value, a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel")))), null, 2); | |
| 45 | 47 | } |
| 46 | 48 | } |
| 47 | 49 | |
| @@ -199,7 +201,7 @@ function r(name: string) { | ||
| 199 | 201 | } |
| 200 | 202 | |
| 201 | 203 | const typeMap: any = { |
| 202 | - "TopLevelElement": o([ | |
| 204 | + "PurpleTopLevel": o([ | |
| 203 | 205 | { json: "country", js: "country", typ: r("Country") }, |
| 204 | 206 | { json: "date", js: "date", typ: "" }, |
| 205 | 207 | { json: "decimal", js: "decimal", typ: "" }, |
| @@ -210,7 +212,7 @@ const typeMap: any = { | ||
| 210 | 212 | { json: "id", js: "id", typ: r("ID") }, |
| 211 | 213 | { json: "value", js: "value", typ: r("Value") }, |
| 212 | 214 | ], false), |
| 213 | - "PurpleTopLevel": o([ | |
| 215 | + "FluffyTopLevel": o([ | |
| 214 | 216 | { json: "page", js: "page", typ: 0 }, |
| 215 | 217 | { json: "pages", js: "pages", typ: 0 }, |
| 216 | 218 | { json: "per_page", js: "per_page", typ: "" }, |
Test case
3 generated files · +19 −15test/inputs/json/misc/e8a0b.json
Mflowdefault / TopLevel.js+8 −6
| @@ -9,7 +9,9 @@ | ||
| 9 | 9 | // These functions will throw an error if the JSON doesn't |
| 10 | 10 | // match the expected interface, even if the JSON is valid. |
| 11 | 11 | |
| 12 | -export type TopLevel = { | |
| 12 | +export type TopLevel = TopLevelElement[]; | |
| 13 | + | |
| 14 | +export type TopLevelElement = { | |
| 13 | 15 | age: number; |
| 14 | 16 | country: Country; |
| 15 | 17 | females: number; |
| @@ -23,12 +25,12 @@ export type Country = | ||
| 23 | 25 | |
| 24 | 26 | // Converts JSON strings to/from your types |
| 25 | 27 | // and asserts the results of JSON.parse at runtime |
| 26 | -function toTopLevel(json: string): TopLevel[] { | |
| 27 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 28 | +function toTopLevel(json: string): TopLevelElement[] { | |
| 29 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 28 | 30 | } |
| 29 | 31 | |
| 30 | -function topLevelToJson(value: TopLevel[]): string { | |
| 31 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 32 | +function topLevelToJson(value: TopLevelElement[]): string { | |
| 33 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 32 | 34 | } |
| 33 | 35 | |
| 34 | 36 | function invalidValue(typ: any, val: any, key: any, parent: any = '') { |
| @@ -185,7 +187,7 @@ function r(name: string) { | ||
| 185 | 187 | } |
| 186 | 188 | |
| 187 | 189 | const typeMap: any = { |
| 188 | - "TopLevel": o([ | |
| 190 | + "TopLevelElement": o([ | |
| 189 | 191 | { json: "age", js: "age", typ: 0 }, |
| 190 | 192 | { json: "country", js: "country", typ: r("Country") }, |
| 191 | 193 | { json: "females", js: "females", typ: 0 }, |
Mjavascriptdefault / TopLevel.js+3 −3
| @@ -10,11 +10,11 @@ | ||
| 10 | 10 | // Converts JSON strings to/from your types |
| 11 | 11 | // and asserts the results of JSON.parse at runtime |
| 12 | 12 | function toTopLevel(json) { |
| 13 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 13 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | function topLevelToJson(value) { |
| 17 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 17 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | function invalidValue(typ, val, key, parent = '') { |
| @@ -171,7 +171,7 @@ function r(name) { | ||
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | const typeMap = { |
| 174 | - "TopLevel": o([ | |
| 174 | + "TopLevelElement": o([ | |
| 175 | 175 | { json: "age", js: "age", typ: 0 }, |
| 176 | 176 | { json: "country", js: "country", typ: r("Country") }, |
| 177 | 177 | { json: "females", js: "females", typ: 0 }, |
Mtypescriptdefault / TopLevel.ts+8 −6
| @@ -7,7 +7,9 @@ | ||
| 7 | 7 | // These functions will throw an error if the JSON doesn't |
| 8 | 8 | // match the expected interface, even if the JSON is valid. |
| 9 | 9 | |
| 10 | -export interface TopLevel { | |
| 10 | +export type TopLevel = TopLevelElement[]; | |
| 11 | + | |
| 12 | +export interface TopLevelElement { | |
| 11 | 13 | age: number; |
| 12 | 14 | country: Country; |
| 13 | 15 | females: number; |
| @@ -21,12 +23,12 @@ export type Country = "United States"; | ||
| 21 | 23 | // Converts JSON strings to/from your types |
| 22 | 24 | // and asserts the results of JSON.parse at runtime |
| 23 | 25 | export class Convert { |
| 24 | - public static toTopLevel(json: string): TopLevel[] { | |
| 25 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 26 | + public static toTopLevel(json: string): TopLevelElement[] { | |
| 27 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 26 | 28 | } |
| 27 | 29 | |
| 28 | - public static topLevelToJson(value: TopLevel[]): string { | |
| 29 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 30 | + public static topLevelToJson(value: TopLevelElement[]): string { | |
| 31 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 30 | 32 | } |
| 31 | 33 | } |
| 32 | 34 | |
| @@ -184,7 +186,7 @@ function r(name: string) { | ||
| 184 | 186 | } |
| 185 | 187 | |
| 186 | 188 | const typeMap: any = { |
| 187 | - "TopLevel": o([ | |
| 189 | + "TopLevelElement": o([ | |
| 188 | 190 | { json: "age", js: "age", typ: 0 }, |
| 189 | 191 | { json: "country", js: "country", typ: r("Country") }, |
| 190 | 192 | { json: "females", js: "females", typ: 0 }, |
Test case
3 generated files · +19 −15test/inputs/json/misc/e8b04.json
Mflowdefault / TopLevel.js+8 −6
| @@ -9,7 +9,9 @@ | ||
| 9 | 9 | // These functions will throw an error if the JSON doesn't |
| 10 | 10 | // match the expected interface, even if the JSON is valid. |
| 11 | 11 | |
| 12 | -export type TopLevel = { | |
| 12 | +export type TopLevel = TopLevelElement[]; | |
| 13 | + | |
| 14 | +export type TopLevelElement = { | |
| 13 | 15 | averageRating: number; |
| 14 | 16 | category?: string; |
| 15 | 17 | createdAt: number; |
| @@ -283,12 +285,12 @@ export type ViewType = | ||
| 283 | 285 | |
| 284 | 286 | // Converts JSON strings to/from your types |
| 285 | 287 | // and asserts the results of JSON.parse at runtime |
| 286 | -function toTopLevel(json: string): TopLevel[] { | |
| 287 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 288 | +function toTopLevel(json: string): TopLevelElement[] { | |
| 289 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 288 | 290 | } |
| 289 | 291 | |
| 290 | -function topLevelToJson(value: TopLevel[]): string { | |
| 291 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 292 | +function topLevelToJson(value: TopLevelElement[]): string { | |
| 293 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 292 | 294 | } |
| 293 | 295 | |
| 294 | 296 | function invalidValue(typ: any, val: any, key: any, parent: any = '') { |
| @@ -445,7 +447,7 @@ function r(name: string) { | ||
| 445 | 447 | } |
| 446 | 448 | |
| 447 | 449 | const typeMap: any = { |
| 448 | - "TopLevel": o([ | |
| 450 | + "TopLevelElement": o([ | |
| 449 | 451 | { json: "averageRating", js: "averageRating", typ: 0 }, |
| 450 | 452 | { json: "category", js: "category", typ: u(undefined, "") }, |
| 451 | 453 | { json: "createdAt", js: "createdAt", typ: 0 }, |
Mjavascriptdefault / TopLevel.js+3 −3
| @@ -10,11 +10,11 @@ | ||
| 10 | 10 | // Converts JSON strings to/from your types |
| 11 | 11 | // and asserts the results of JSON.parse at runtime |
| 12 | 12 | function toTopLevel(json) { |
| 13 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 13 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | function topLevelToJson(value) { |
| 17 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 17 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | function invalidValue(typ, val, key, parent = '') { |
| @@ -171,7 +171,7 @@ function r(name) { | ||
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | const typeMap = { |
| 174 | - "TopLevel": o([ | |
| 174 | + "TopLevelElement": o([ | |
| 175 | 175 | { json: "averageRating", js: "averageRating", typ: 0 }, |
| 176 | 176 | { json: "category", js: "category", typ: u(undefined, "") }, |
| 177 | 177 | { json: "createdAt", js: "createdAt", typ: 0 }, |
Mtypescriptdefault / TopLevel.ts+8 −6
| @@ -7,7 +7,9 @@ | ||
| 7 | 7 | // These functions will throw an error if the JSON doesn't |
| 8 | 8 | // match the expected interface, even if the JSON is valid. |
| 9 | 9 | |
| 10 | -export interface TopLevel { | |
| 10 | +export type TopLevel = TopLevelElement[]; | |
| 11 | + | |
| 12 | +export interface TopLevelElement { | |
| 11 | 13 | averageRating: number; |
| 12 | 14 | category?: string; |
| 13 | 15 | createdAt: number; |
| @@ -243,12 +245,12 @@ export type ViewType = "tabular"; | ||
| 243 | 245 | // Converts JSON strings to/from your types |
| 244 | 246 | // and asserts the results of JSON.parse at runtime |
| 245 | 247 | export class Convert { |
| 246 | - public static toTopLevel(json: string): TopLevel[] { | |
| 247 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 248 | + public static toTopLevel(json: string): TopLevelElement[] { | |
| 249 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 248 | 250 | } |
| 249 | 251 | |
| 250 | - public static topLevelToJson(value: TopLevel[]): string { | |
| 251 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 252 | + public static topLevelToJson(value: TopLevelElement[]): string { | |
| 253 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 252 | 254 | } |
| 253 | 255 | } |
| 254 | 256 | |
| @@ -406,7 +408,7 @@ function r(name: string) { | ||
| 406 | 408 | } |
| 407 | 409 | |
| 408 | 410 | const typeMap: any = { |
| 409 | - "TopLevel": o([ | |
| 411 | + "TopLevelElement": o([ | |
| 410 | 412 | { json: "averageRating", js: "averageRating", typ: 0 }, |
| 411 | 413 | { json: "category", js: "category", typ: u(undefined, "") }, |
| 412 | 414 | { json: "createdAt", js: "createdAt", typ: 0 }, |
Test case
3 generated files · +19 −15test/inputs/json/misc/f3139.json
Mflowdefault / TopLevel.js+8 −6
| @@ -9,19 +9,21 @@ | ||
| 9 | 9 | // These functions will throw an error if the JSON doesn't |
| 10 | 10 | // match the expected interface, even if the JSON is valid. |
| 11 | 11 | |
| 12 | -export type TopLevel = { | |
| 12 | +export type TopLevel = TopLevelElement[]; | |
| 13 | + | |
| 14 | +export type TopLevelElement = { | |
| 13 | 15 | id: string; |
| 14 | 16 | name: string; |
| 15 | 17 | }; |
| 16 | 18 | |
| 17 | 19 | // Converts JSON strings to/from your types |
| 18 | 20 | // and asserts the results of JSON.parse at runtime |
| 19 | -function toTopLevel(json: string): TopLevel[] { | |
| 20 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 21 | +function toTopLevel(json: string): TopLevelElement[] { | |
| 22 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 21 | 23 | } |
| 22 | 24 | |
| 23 | -function topLevelToJson(value: TopLevel[]): string { | |
| 24 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 25 | +function topLevelToJson(value: TopLevelElement[]): string { | |
| 26 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 25 | 27 | } |
| 26 | 28 | |
| 27 | 29 | function invalidValue(typ: any, val: any, key: any, parent: any = '') { |
| @@ -178,7 +180,7 @@ function r(name: string) { | ||
| 178 | 180 | } |
| 179 | 181 | |
| 180 | 182 | const typeMap: any = { |
| 181 | - "TopLevel": o([ | |
| 183 | + "TopLevelElement": o([ | |
| 182 | 184 | { json: "id", js: "id", typ: "" }, |
| 183 | 185 | { json: "name", js: "name", typ: "" }, |
| 184 | 186 | ], false), |
Mjavascriptdefault / TopLevel.js+3 −3
| @@ -10,11 +10,11 @@ | ||
| 10 | 10 | // Converts JSON strings to/from your types |
| 11 | 11 | // and asserts the results of JSON.parse at runtime |
| 12 | 12 | function toTopLevel(json) { |
| 13 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 13 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | function topLevelToJson(value) { |
| 17 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 17 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | function invalidValue(typ, val, key, parent = '') { |
| @@ -171,7 +171,7 @@ function r(name) { | ||
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | const typeMap = { |
| 174 | - "TopLevel": o([ | |
| 174 | + "TopLevelElement": o([ | |
| 175 | 175 | { json: "id", js: "id", typ: "" }, |
| 176 | 176 | { json: "name", js: "name", typ: "" }, |
| 177 | 177 | ], false), |
Mtypescriptdefault / TopLevel.ts+8 −6
| @@ -7,7 +7,9 @@ | ||
| 7 | 7 | // These functions will throw an error if the JSON doesn't |
| 8 | 8 | // match the expected interface, even if the JSON is valid. |
| 9 | 9 | |
| 10 | -export interface TopLevel { | |
| 10 | +export type TopLevel = TopLevelElement[]; | |
| 11 | + | |
| 12 | +export interface TopLevelElement { | |
| 11 | 13 | id: string; |
| 12 | 14 | name: string; |
| 13 | 15 | } |
| @@ -15,12 +17,12 @@ export interface TopLevel { | ||
| 15 | 17 | // Converts JSON strings to/from your types |
| 16 | 18 | // and asserts the results of JSON.parse at runtime |
| 17 | 19 | export class Convert { |
| 18 | - public static toTopLevel(json: string): TopLevel[] { | |
| 19 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 20 | + public static toTopLevel(json: string): TopLevelElement[] { | |
| 21 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 20 | 22 | } |
| 21 | 23 | |
| 22 | - public static topLevelToJson(value: TopLevel[]): string { | |
| 23 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 24 | + public static topLevelToJson(value: TopLevelElement[]): string { | |
| 25 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 24 | 26 | } |
| 25 | 27 | } |
| 26 | 28 | |
| @@ -178,7 +180,7 @@ function r(name: string) { | ||
| 178 | 180 | } |
| 179 | 181 | |
| 180 | 182 | const typeMap: any = { |
| 181 | - "TopLevel": o([ | |
| 183 | + "TopLevelElement": o([ | |
| 182 | 184 | { json: "id", js: "id", typ: "" }, |
| 183 | 185 | { json: "name", js: "name", typ: "" }, |
| 184 | 186 | ], false), |
Test case
3 generated files · +19 −15test/inputs/json/misc/f3edf.json
Mflowdefault / TopLevel.js+8 −6
| @@ -9,7 +9,9 @@ | ||
| 9 | 9 | // These functions will throw an error if the JSON doesn't |
| 10 | 10 | // match the expected interface, even if the JSON is valid. |
| 11 | 11 | |
| 12 | -export type TopLevel = { | |
| 12 | +export type TopLevel = TopLevelElement[]; | |
| 13 | + | |
| 14 | +export type TopLevelElement = { | |
| 13 | 15 | age: number; |
| 14 | 16 | country: Country; |
| 15 | 17 | females: number; |
| @@ -23,12 +25,12 @@ export type Country = | ||
| 23 | 25 | |
| 24 | 26 | // Converts JSON strings to/from your types |
| 25 | 27 | // and asserts the results of JSON.parse at runtime |
| 26 | -function toTopLevel(json: string): TopLevel[] { | |
| 27 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 28 | +function toTopLevel(json: string): TopLevelElement[] { | |
| 29 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 28 | 30 | } |
| 29 | 31 | |
| 30 | -function topLevelToJson(value: TopLevel[]): string { | |
| 31 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 32 | +function topLevelToJson(value: TopLevelElement[]): string { | |
| 33 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 32 | 34 | } |
| 33 | 35 | |
| 34 | 36 | function invalidValue(typ: any, val: any, key: any, parent: any = '') { |
| @@ -185,7 +187,7 @@ function r(name: string) { | ||
| 185 | 187 | } |
| 186 | 188 | |
| 187 | 189 | const typeMap: any = { |
| 188 | - "TopLevel": o([ | |
| 190 | + "TopLevelElement": o([ | |
| 189 | 191 | { json: "age", js: "age", typ: 0 }, |
| 190 | 192 | { json: "country", js: "country", typ: r("Country") }, |
| 191 | 193 | { json: "females", js: "females", typ: 0 }, |
Mjavascriptdefault / TopLevel.js+3 −3
| @@ -10,11 +10,11 @@ | ||
| 10 | 10 | // Converts JSON strings to/from your types |
| 11 | 11 | // and asserts the results of JSON.parse at runtime |
| 12 | 12 | function toTopLevel(json) { |
| 13 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 13 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | function topLevelToJson(value) { |
| 17 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 17 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | function invalidValue(typ, val, key, parent = '') { |
| @@ -171,7 +171,7 @@ function r(name) { | ||
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | const typeMap = { |
| 174 | - "TopLevel": o([ | |
| 174 | + "TopLevelElement": o([ | |
| 175 | 175 | { json: "age", js: "age", typ: 0 }, |
| 176 | 176 | { json: "country", js: "country", typ: r("Country") }, |
| 177 | 177 | { json: "females", js: "females", typ: 0 }, |
Mtypescriptdefault / TopLevel.ts+8 −6
| @@ -7,7 +7,9 @@ | ||
| 7 | 7 | // These functions will throw an error if the JSON doesn't |
| 8 | 8 | // match the expected interface, even if the JSON is valid. |
| 9 | 9 | |
| 10 | -export interface TopLevel { | |
| 10 | +export type TopLevel = TopLevelElement[]; | |
| 11 | + | |
| 12 | +export interface TopLevelElement { | |
| 11 | 13 | age: number; |
| 12 | 14 | country: Country; |
| 13 | 15 | females: number; |
| @@ -21,12 +23,12 @@ export type Country = "United States"; | ||
| 21 | 23 | // Converts JSON strings to/from your types |
| 22 | 24 | // and asserts the results of JSON.parse at runtime |
| 23 | 25 | export class Convert { |
| 24 | - public static toTopLevel(json: string): TopLevel[] { | |
| 25 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 26 | + public static toTopLevel(json: string): TopLevelElement[] { | |
| 27 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 26 | 28 | } |
| 27 | 29 | |
| 28 | - public static topLevelToJson(value: TopLevel[]): string { | |
| 29 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 30 | + public static topLevelToJson(value: TopLevelElement[]): string { | |
| 31 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 30 | 32 | } |
| 31 | 33 | } |
| 32 | 34 | |
| @@ -184,7 +186,7 @@ function r(name: string) { | ||
| 184 | 186 | } |
| 185 | 187 | |
| 186 | 188 | const typeMap: any = { |
| 187 | - "TopLevel": o([ | |
| 189 | + "TopLevelElement": o([ | |
| 188 | 190 | { json: "age", js: "age", typ: 0 }, |
| 189 | 191 | { json: "country", js: "country", typ: r("Country") }, |
| 190 | 192 | { json: "females", js: "females", typ: 0 }, |
Test case
3 generated files · +19 −15test/inputs/json/misc/f466a.json
Mflowdefault / TopLevel.js+8 −6
| @@ -9,7 +9,9 @@ | ||
| 9 | 9 | // These functions will throw an error if the JSON doesn't |
| 10 | 10 | // match the expected interface, even if the JSON is valid. |
| 11 | 11 | |
| 12 | -export type TopLevel = { | |
| 12 | +export type TopLevel = TopLevelElement[]; | |
| 13 | + | |
| 14 | +export type TopLevelElement = { | |
| 13 | 15 | age: number; |
| 14 | 16 | country: Country; |
| 15 | 17 | females: number; |
| @@ -23,12 +25,12 @@ export type Country = | ||
| 23 | 25 | |
| 24 | 26 | // Converts JSON strings to/from your types |
| 25 | 27 | // and asserts the results of JSON.parse at runtime |
| 26 | -function toTopLevel(json: string): TopLevel[] { | |
| 27 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 28 | +function toTopLevel(json: string): TopLevelElement[] { | |
| 29 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 28 | 30 | } |
| 29 | 31 | |
| 30 | -function topLevelToJson(value: TopLevel[]): string { | |
| 31 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 32 | +function topLevelToJson(value: TopLevelElement[]): string { | |
| 33 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 32 | 34 | } |
| 33 | 35 | |
| 34 | 36 | function invalidValue(typ: any, val: any, key: any, parent: any = '') { |
| @@ -185,7 +187,7 @@ function r(name: string) { | ||
| 185 | 187 | } |
| 186 | 188 | |
| 187 | 189 | const typeMap: any = { |
| 188 | - "TopLevel": o([ | |
| 190 | + "TopLevelElement": o([ | |
| 189 | 191 | { json: "age", js: "age", typ: 0 }, |
| 190 | 192 | { json: "country", js: "country", typ: r("Country") }, |
| 191 | 193 | { json: "females", js: "females", typ: 0 }, |
Mjavascriptdefault / TopLevel.js+3 −3
| @@ -10,11 +10,11 @@ | ||
| 10 | 10 | // Converts JSON strings to/from your types |
| 11 | 11 | // and asserts the results of JSON.parse at runtime |
| 12 | 12 | function toTopLevel(json) { |
| 13 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 13 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | function topLevelToJson(value) { |
| 17 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 17 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | function invalidValue(typ, val, key, parent = '') { |
| @@ -171,7 +171,7 @@ function r(name) { | ||
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | const typeMap = { |
| 174 | - "TopLevel": o([ | |
| 174 | + "TopLevelElement": o([ | |
| 175 | 175 | { json: "age", js: "age", typ: 0 }, |
| 176 | 176 | { json: "country", js: "country", typ: r("Country") }, |
| 177 | 177 | { json: "females", js: "females", typ: 0 }, |
Mtypescriptdefault / TopLevel.ts+8 −6
| @@ -7,7 +7,9 @@ | ||
| 7 | 7 | // These functions will throw an error if the JSON doesn't |
| 8 | 8 | // match the expected interface, even if the JSON is valid. |
| 9 | 9 | |
| 10 | -export interface TopLevel { | |
| 10 | +export type TopLevel = TopLevelElement[]; | |
| 11 | + | |
| 12 | +export interface TopLevelElement { | |
| 11 | 13 | age: number; |
| 12 | 14 | country: Country; |
| 13 | 15 | females: number; |
| @@ -21,12 +23,12 @@ export type Country = "United States"; | ||
| 21 | 23 | // Converts JSON strings to/from your types |
| 22 | 24 | // and asserts the results of JSON.parse at runtime |
| 23 | 25 | export class Convert { |
| 24 | - public static toTopLevel(json: string): TopLevel[] { | |
| 25 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 26 | + public static toTopLevel(json: string): TopLevelElement[] { | |
| 27 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 26 | 28 | } |
| 27 | 29 | |
| 28 | - public static topLevelToJson(value: TopLevel[]): string { | |
| 29 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 30 | + public static topLevelToJson(value: TopLevelElement[]): string { | |
| 31 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 30 | 32 | } |
| 31 | 33 | } |
| 32 | 34 | |
| @@ -184,7 +186,7 @@ function r(name: string) { | ||
| 184 | 186 | } |
| 185 | 187 | |
| 186 | 188 | const typeMap: any = { |
| 187 | - "TopLevel": o([ | |
| 189 | + "TopLevelElement": o([ | |
| 188 | 190 | { json: "age", js: "age", typ: 0 }, |
| 189 | 191 | { json: "country", js: "country", typ: r("Country") }, |
| 190 | 192 | { json: "females", js: "females", typ: 0 }, |
Test case
3 generated files · +26 −22test/inputs/json/priority/bug863.json
Mflowdefault / TopLevel.js+11 −9
| @@ -9,9 +9,11 @@ | ||
| 9 | 9 | // These functions will throw an error if the JSON doesn't |
| 10 | 10 | // match the expected interface, even if the JSON is valid. |
| 11 | 11 | |
| 12 | -export type TopLevel = TopLevelElement[] | PurpleTopLevel | string; | |
| 12 | +export type TopLevel = TopLevelUnion[]; | |
| 13 | 13 | |
| 14 | -export type TopLevelElement = { | |
| 14 | +export type TopLevelUnion = PurpleTopLevel[] | FluffyTopLevel | string; | |
| 15 | + | |
| 16 | +export type PurpleTopLevel = { | |
| 15 | 17 | ALIENLEVEL: number; |
| 16 | 18 | BREED: Breed; |
| 17 | 19 | CHAR_DIMENSION: number; |
| @@ -59,7 +61,7 @@ export type Sex = | ||
| 59 | 61 | | "Male" |
| 60 | 62 | | "Female"; |
| 61 | 63 | |
| 62 | -export type PurpleTopLevel = { | |
| 64 | +export type FluffyTopLevel = { | |
| 63 | 65 | ADVENTURERCOUNT: number; |
| 64 | 66 | AGENTCOUNT: number; |
| 65 | 67 | ATROXCOUNT: number; |
| @@ -99,12 +101,12 @@ export type PurpleTopLevel = { | ||
| 99 | 101 | |
| 100 | 102 | // Converts JSON strings to/from your types |
| 101 | 103 | // and asserts the results of JSON.parse at runtime |
| 102 | -function toTopLevel(json: string): TopLevel[] { | |
| 103 | - return cast(JSON.parse(json), a(u(a(r("TopLevelElement")), r("PurpleTopLevel"), ""))); | |
| 104 | +function toTopLevel(json: string): TopLevelUnion[] { | |
| 105 | + return cast(JSON.parse(json), a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel"), ""))); | |
| 104 | 106 | } |
| 105 | 107 | |
| 106 | -function topLevelToJson(value: TopLevel[]): string { | |
| 107 | - return JSON.stringify(uncast(value, a(u(a(r("TopLevelElement")), r("PurpleTopLevel"), ""))), null, 2); | |
| 108 | +function topLevelToJson(value: TopLevelUnion[]): string { | |
| 109 | + return JSON.stringify(uncast(value, a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel"), ""))), null, 2); | |
| 108 | 110 | } |
| 109 | 111 | |
| 110 | 112 | function invalidValue(typ: any, val: any, key: any, parent: any = '') { |
| @@ -261,7 +263,7 @@ function r(name: string) { | ||
| 261 | 263 | } |
| 262 | 264 | |
| 263 | 265 | const typeMap: any = { |
| 264 | - "TopLevelElement": o([ | |
| 266 | + "PurpleTopLevel": o([ | |
| 265 | 267 | { json: "ALIENLEVEL", js: "ALIENLEVEL", typ: 0 }, |
| 266 | 268 | { json: "BREED", js: "BREED", typ: r("Breed") }, |
| 267 | 269 | { json: "CHAR_DIMENSION", js: "CHAR_DIMENSION", typ: 0 }, |
| @@ -280,7 +282,7 @@ const typeMap: any = { | ||
| 280 | 282 | { json: "RANK_TITLE", js: "RANK_TITLE", typ: r("RankTitle") }, |
| 281 | 283 | { json: "SEX", js: "SEX", typ: r("Sex") }, |
| 282 | 284 | ], false), |
| 283 | - "PurpleTopLevel": o([ | |
| 285 | + "FluffyTopLevel": o([ | |
| 284 | 286 | { json: "ADVENTURERCOUNT", js: "ADVENTURERCOUNT", typ: 0 }, |
| 285 | 287 | { json: "AGENTCOUNT", js: "AGENTCOUNT", typ: 0 }, |
| 286 | 288 | { json: "ATROXCOUNT", js: "ATROXCOUNT", typ: 0 }, |
Mjavascriptdefault / TopLevel.js+4 −4
| @@ -10,11 +10,11 @@ | ||
| 10 | 10 | // Converts JSON strings to/from your types |
| 11 | 11 | // and asserts the results of JSON.parse at runtime |
| 12 | 12 | function toTopLevel(json) { |
| 13 | - return cast(JSON.parse(json), a(u(a(r("TopLevelElement")), r("PurpleTopLevel"), ""))); | |
| 13 | + return cast(JSON.parse(json), a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel"), ""))); | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | function topLevelToJson(value) { |
| 17 | - return JSON.stringify(uncast(value, a(u(a(r("TopLevelElement")), r("PurpleTopLevel"), ""))), null, 2); | |
| 17 | + return JSON.stringify(uncast(value, a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel"), ""))), null, 2); | |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | function invalidValue(typ, val, key, parent = '') { |
| @@ -171,7 +171,7 @@ function r(name) { | ||
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | const typeMap = { |
| 174 | - "TopLevelElement": o([ | |
| 174 | + "PurpleTopLevel": o([ | |
| 175 | 175 | { json: "ALIENLEVEL", js: "ALIENLEVEL", typ: 0 }, |
| 176 | 176 | { json: "BREED", js: "BREED", typ: r("Breed") }, |
| 177 | 177 | { json: "CHAR_DIMENSION", js: "CHAR_DIMENSION", typ: 0 }, |
| @@ -190,7 +190,7 @@ const typeMap = { | ||
| 190 | 190 | { json: "RANK_TITLE", js: "RANK_TITLE", typ: r("RankTitle") }, |
| 191 | 191 | { json: "SEX", js: "SEX", typ: r("Sex") }, |
| 192 | 192 | ], false), |
| 193 | - "PurpleTopLevel": o([ | |
| 193 | + "FluffyTopLevel": o([ | |
| 194 | 194 | { json: "ADVENTURERCOUNT", js: "ADVENTURERCOUNT", typ: 0 }, |
| 195 | 195 | { json: "AGENTCOUNT", js: "AGENTCOUNT", typ: 0 }, |
| 196 | 196 | { json: "ATROXCOUNT", js: "ATROXCOUNT", typ: 0 }, |
Mtypescriptdefault / TopLevel.ts+11 −9
| @@ -7,9 +7,11 @@ | ||
| 7 | 7 | // These functions will throw an error if the JSON doesn't |
| 8 | 8 | // match the expected interface, even if the JSON is valid. |
| 9 | 9 | |
| 10 | -export type TopLevel = TopLevelElement[] | PurpleTopLevel | string; | |
| 10 | +export type TopLevel = TopLevelUnion[]; | |
| 11 | 11 | |
| 12 | -export interface TopLevelElement { | |
| 12 | +export type TopLevelUnion = PurpleTopLevel[] | FluffyTopLevel | string; | |
| 13 | + | |
| 14 | +export interface PurpleTopLevel { | |
| 13 | 15 | ALIENLEVEL: number; |
| 14 | 16 | BREED: Breed; |
| 15 | 17 | CHAR_DIMENSION: number; |
| @@ -41,7 +43,7 @@ export type RankTitle = "President" | "Advisor" | "Veteran" | "Applicant"; | ||
| 41 | 43 | |
| 42 | 44 | export type Sex = "Neuter" | "Male" | "Female"; |
| 43 | 45 | |
| 44 | -export interface PurpleTopLevel { | |
| 46 | +export interface FluffyTopLevel { | |
| 45 | 47 | ADVENTURERCOUNT: number; |
| 46 | 48 | AGENTCOUNT: number; |
| 47 | 49 | ATROXCOUNT: number; |
| @@ -82,12 +84,12 @@ export interface PurpleTopLevel { | ||
| 82 | 84 | // Converts JSON strings to/from your types |
| 83 | 85 | // and asserts the results of JSON.parse at runtime |
| 84 | 86 | export class Convert { |
| 85 | - public static toTopLevel(json: string): TopLevel[] { | |
| 86 | - return cast(JSON.parse(json), a(u(a(r("TopLevelElement")), r("PurpleTopLevel"), ""))); | |
| 87 | + public static toTopLevel(json: string): TopLevelUnion[] { | |
| 88 | + return cast(JSON.parse(json), a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel"), ""))); | |
| 87 | 89 | } |
| 88 | 90 | |
| 89 | - public static topLevelToJson(value: TopLevel[]): string { | |
| 90 | - return JSON.stringify(uncast(value, a(u(a(r("TopLevelElement")), r("PurpleTopLevel"), ""))), null, 2); | |
| 91 | + public static topLevelToJson(value: TopLevelUnion[]): string { | |
| 92 | + return JSON.stringify(uncast(value, a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel"), ""))), null, 2); | |
| 91 | 93 | } |
| 92 | 94 | } |
| 93 | 95 | |
| @@ -245,7 +247,7 @@ function r(name: string) { | ||
| 245 | 247 | } |
| 246 | 248 | |
| 247 | 249 | const typeMap: any = { |
| 248 | - "TopLevelElement": o([ | |
| 250 | + "PurpleTopLevel": o([ | |
| 249 | 251 | { json: "ALIENLEVEL", js: "ALIENLEVEL", typ: 0 }, |
| 250 | 252 | { json: "BREED", js: "BREED", typ: r("Breed") }, |
| 251 | 253 | { json: "CHAR_DIMENSION", js: "CHAR_DIMENSION", typ: 0 }, |
| @@ -264,7 +266,7 @@ const typeMap: any = { | ||
| 264 | 266 | { json: "RANK_TITLE", js: "RANK_TITLE", typ: r("RankTitle") }, |
| 265 | 267 | { json: "SEX", js: "SEX", typ: r("Sex") }, |
| 266 | 268 | ], false), |
| 267 | - "PurpleTopLevel": o([ | |
| 269 | + "FluffyTopLevel": o([ | |
| 268 | 270 | { json: "ADVENTURERCOUNT", js: "ADVENTURERCOUNT", typ: 0 }, |
| 269 | 271 | { json: "AGENTCOUNT", js: "AGENTCOUNT", typ: 0 }, |
| 270 | 272 | { json: "ATROXCOUNT", js: "ATROXCOUNT", typ: 0 }, |
Test case
3 generated files · +19 −15test/inputs/json/priority/issue2680-object-array.json
Mflowdefault / TopLevel.js+8 −6
| @@ -9,18 +9,20 @@ | ||
| 9 | 9 | // These functions will throw an error if the JSON doesn't |
| 10 | 10 | // match the expected interface, even if the JSON is valid. |
| 11 | 11 | |
| 12 | -export type TopLevel = { | |
| 12 | +export type TopLevel = TopLevelElement[]; | |
| 13 | + | |
| 14 | +export type TopLevelElement = { | |
| 13 | 15 | key: string; |
| 14 | 16 | }; |
| 15 | 17 | |
| 16 | 18 | // Converts JSON strings to/from your types |
| 17 | 19 | // and asserts the results of JSON.parse at runtime |
| 18 | -function toTopLevel(json: string): TopLevel[] { | |
| 19 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 20 | +function toTopLevel(json: string): TopLevelElement[] { | |
| 21 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 20 | 22 | } |
| 21 | 23 | |
| 22 | -function topLevelToJson(value: TopLevel[]): string { | |
| 23 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 24 | +function topLevelToJson(value: TopLevelElement[]): string { | |
| 25 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 24 | 26 | } |
| 25 | 27 | |
| 26 | 28 | function invalidValue(typ: any, val: any, key: any, parent: any = '') { |
| @@ -177,7 +179,7 @@ function r(name: string) { | ||
| 177 | 179 | } |
| 178 | 180 | |
| 179 | 181 | const typeMap: any = { |
| 180 | - "TopLevel": o([ | |
| 182 | + "TopLevelElement": o([ | |
| 181 | 183 | { json: "key", js: "key", typ: "" }, |
| 182 | 184 | ], false), |
| 183 | 185 | }; |
Mjavascriptdefault / TopLevel.js+3 −3
| @@ -10,11 +10,11 @@ | ||
| 10 | 10 | // Converts JSON strings to/from your types |
| 11 | 11 | // and asserts the results of JSON.parse at runtime |
| 12 | 12 | function toTopLevel(json) { |
| 13 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 13 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | function topLevelToJson(value) { |
| 17 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 17 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | function invalidValue(typ, val, key, parent = '') { |
| @@ -171,7 +171,7 @@ function r(name) { | ||
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | const typeMap = { |
| 174 | - "TopLevel": o([ | |
| 174 | + "TopLevelElement": o([ | |
| 175 | 175 | { json: "key", js: "key", typ: "" }, |
| 176 | 176 | ], false), |
| 177 | 177 | }; |
Mtypescriptdefault / TopLevel.ts+8 −6
| @@ -7,19 +7,21 @@ | ||
| 7 | 7 | // These functions will throw an error if the JSON doesn't |
| 8 | 8 | // match the expected interface, even if the JSON is valid. |
| 9 | 9 | |
| 10 | -export interface TopLevel { | |
| 10 | +export type TopLevel = TopLevelElement[]; | |
| 11 | + | |
| 12 | +export interface TopLevelElement { | |
| 11 | 13 | key: string; |
| 12 | 14 | } |
| 13 | 15 | |
| 14 | 16 | // Converts JSON strings to/from your types |
| 15 | 17 | // and asserts the results of JSON.parse at runtime |
| 16 | 18 | export class Convert { |
| 17 | - public static toTopLevel(json: string): TopLevel[] { | |
| 18 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 19 | + public static toTopLevel(json: string): TopLevelElement[] { | |
| 20 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 19 | 21 | } |
| 20 | 22 | |
| 21 | - public static topLevelToJson(value: TopLevel[]): string { | |
| 22 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 23 | + public static topLevelToJson(value: TopLevelElement[]): string { | |
| 24 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 23 | 25 | } |
| 24 | 26 | } |
| 25 | 27 | |
| @@ -177,7 +179,7 @@ function r(name: string) { | ||
| 177 | 179 | } |
| 178 | 180 | |
| 179 | 181 | const typeMap: any = { |
| 180 | - "TopLevel": o([ | |
| 182 | + "TopLevelElement": o([ | |
| 181 | 183 | { json: "key", js: "key", typ: "" }, |
| 182 | 184 | ], false), |
| 183 | 185 | }; |
Test case
2 generated files · +4 −0test/inputs/json/priority/issue2680-scalar-array.json
Mflowdefault / TopLevel.js+2 −0
| @@ -9,6 +9,8 @@ | ||
| 9 | 9 | // These functions will throw an error if the JSON doesn't |
| 10 | 10 | // match the expected interface, even if the JSON is valid. |
| 11 | 11 | |
| 12 | +export type TopLevel = number[]; | |
| 13 | + | |
| 12 | 14 | // Converts JSON strings to/from your types |
| 13 | 15 | // and asserts the results of JSON.parse at runtime |
| 14 | 16 | function toTopLevel(json: string): number[] { |
Mtypescriptdefault / TopLevel.ts+2 −0
| @@ -7,6 +7,8 @@ | ||
| 7 | 7 | // These functions will throw an error if the JSON doesn't |
| 8 | 8 | // match the expected interface, even if the JSON is valid. |
| 9 | 9 | |
| 10 | +export type TopLevel = number[]; | |
| 11 | + | |
| 10 | 12 | // Converts JSON strings to/from your types |
| 11 | 13 | // and asserts the results of JSON.parse at runtime |
| 12 | 14 | export class Convert { |
Test case
3 generated files · +19 −15test/inputs/json/priority/kotlin-enum-class-case-collision.json
Mflowdefault / TopLevel.js+8 −6
| @@ -9,7 +9,9 @@ | ||
| 9 | 9 | // These functions will throw an error if the JSON doesn't |
| 10 | 10 | // match the expected interface, even if the JSON is valid. |
| 11 | 11 | |
| 12 | -export type TopLevel = { | |
| 12 | +export type TopLevel = TopLevelElement[]; | |
| 13 | + | |
| 14 | +export type TopLevelElement = { | |
| 13 | 15 | category: Category; |
| 14 | 16 | }; |
| 15 | 17 | |
| @@ -19,12 +21,12 @@ export type Category = | ||
| 19 | 21 | |
| 20 | 22 | // Converts JSON strings to/from your types |
| 21 | 23 | // and asserts the results of JSON.parse at runtime |
| 22 | -function toTopLevel(json: string): TopLevel[] { | |
| 23 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 24 | +function toTopLevel(json: string): TopLevelElement[] { | |
| 25 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 24 | 26 | } |
| 25 | 27 | |
| 26 | -function topLevelToJson(value: TopLevel[]): string { | |
| 27 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 28 | +function topLevelToJson(value: TopLevelElement[]): string { | |
| 29 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 28 | 30 | } |
| 29 | 31 | |
| 30 | 32 | function invalidValue(typ: any, val: any, key: any, parent: any = '') { |
| @@ -181,7 +183,7 @@ function r(name: string) { | ||
| 181 | 183 | } |
| 182 | 184 | |
| 183 | 185 | const typeMap: any = { |
| 184 | - "TopLevel": o([ | |
| 186 | + "TopLevelElement": o([ | |
| 185 | 187 | { json: "category", js: "category", typ: r("Category") }, |
| 186 | 188 | ], false), |
| 187 | 189 | "Category": [ |
Mjavascriptdefault / TopLevel.js+3 −3
| @@ -10,11 +10,11 @@ | ||
| 10 | 10 | // Converts JSON strings to/from your types |
| 11 | 11 | // and asserts the results of JSON.parse at runtime |
| 12 | 12 | function toTopLevel(json) { |
| 13 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 13 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | function topLevelToJson(value) { |
| 17 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 17 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | function invalidValue(typ, val, key, parent = '') { |
| @@ -171,7 +171,7 @@ function r(name) { | ||
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | const typeMap = { |
| 174 | - "TopLevel": o([ | |
| 174 | + "TopLevelElement": o([ | |
| 175 | 175 | { json: "category", js: "category", typ: r("Category") }, |
| 176 | 176 | ], false), |
| 177 | 177 | "Category": [ |
Mtypescriptdefault / TopLevel.ts+8 −6
| @@ -7,7 +7,9 @@ | ||
| 7 | 7 | // These functions will throw an error if the JSON doesn't |
| 8 | 8 | // match the expected interface, even if the JSON is valid. |
| 9 | 9 | |
| 10 | -export interface TopLevel { | |
| 10 | +export type TopLevel = TopLevelElement[]; | |
| 11 | + | |
| 12 | +export interface TopLevelElement { | |
| 11 | 13 | category: Category; |
| 12 | 14 | } |
| 13 | 15 | |
| @@ -16,12 +18,12 @@ export type Category = " " | ""; | ||
| 16 | 18 | // Converts JSON strings to/from your types |
| 17 | 19 | // and asserts the results of JSON.parse at runtime |
| 18 | 20 | export class Convert { |
| 19 | - public static toTopLevel(json: string): TopLevel[] { | |
| 20 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 21 | + public static toTopLevel(json: string): TopLevelElement[] { | |
| 22 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 21 | 23 | } |
| 22 | 24 | |
| 23 | - public static topLevelToJson(value: TopLevel[]): string { | |
| 24 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 25 | + public static topLevelToJson(value: TopLevelElement[]): string { | |
| 26 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 25 | 27 | } |
| 26 | 28 | } |
| 27 | 29 | |
| @@ -179,7 +181,7 @@ function r(name: string) { | ||
| 179 | 181 | } |
| 180 | 182 | |
| 181 | 183 | const typeMap: any = { |
| 182 | - "TopLevel": o([ | |
| 184 | + "TopLevelElement": o([ | |
| 183 | 185 | { json: "category", js: "category", typ: r("Category") }, |
| 184 | 186 | ], false), |
| 185 | 187 | "Category": [ |
Test case
3 generated files · +19 −15test/inputs/json/priority/optional-union.json
Mflowdefault / TopLevel.js+8 −6
| @@ -9,7 +9,9 @@ | ||
| 9 | 9 | // These functions will throw an error if the JSON doesn't |
| 10 | 10 | // match the expected interface, even if the JSON is valid. |
| 11 | 11 | |
| 12 | -export type TopLevel = { | |
| 12 | +export type TopLevel = TopLevelElement[]; | |
| 13 | + | |
| 14 | +export type TopLevelElement = { | |
| 13 | 15 | a?: A; |
| 14 | 16 | }; |
| 15 | 17 | |
| @@ -17,12 +19,12 @@ export type A = number | string; | ||
| 17 | 19 | |
| 18 | 20 | // Converts JSON strings to/from your types |
| 19 | 21 | // and asserts the results of JSON.parse at runtime |
| 20 | -function toTopLevel(json: string): TopLevel[] { | |
| 21 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 22 | +function toTopLevel(json: string): TopLevelElement[] { | |
| 23 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 22 | 24 | } |
| 23 | 25 | |
| 24 | -function topLevelToJson(value: TopLevel[]): string { | |
| 25 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 26 | +function topLevelToJson(value: TopLevelElement[]): string { | |
| 27 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 26 | 28 | } |
| 27 | 29 | |
| 28 | 30 | function invalidValue(typ: any, val: any, key: any, parent: any = '') { |
| @@ -179,7 +181,7 @@ function r(name: string) { | ||
| 179 | 181 | } |
| 180 | 182 | |
| 181 | 183 | const typeMap: any = { |
| 182 | - "TopLevel": o([ | |
| 184 | + "TopLevelElement": o([ | |
| 183 | 185 | { json: "a", js: "a", typ: u(undefined, u(0, "")) }, |
| 184 | 186 | ], false), |
| 185 | 187 | }; |
Mjavascriptdefault / TopLevel.js+3 −3
| @@ -10,11 +10,11 @@ | ||
| 10 | 10 | // Converts JSON strings to/from your types |
| 11 | 11 | // and asserts the results of JSON.parse at runtime |
| 12 | 12 | function toTopLevel(json) { |
| 13 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 13 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | function topLevelToJson(value) { |
| 17 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 17 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | function invalidValue(typ, val, key, parent = '') { |
| @@ -171,7 +171,7 @@ function r(name) { | ||
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | const typeMap = { |
| 174 | - "TopLevel": o([ | |
| 174 | + "TopLevelElement": o([ | |
| 175 | 175 | { json: "a", js: "a", typ: u(undefined, u(0, "")) }, |
| 176 | 176 | ], false), |
| 177 | 177 | }; |
Mtypescriptdefault / TopLevel.ts+8 −6
| @@ -7,7 +7,9 @@ | ||
| 7 | 7 | // These functions will throw an error if the JSON doesn't |
| 8 | 8 | // match the expected interface, even if the JSON is valid. |
| 9 | 9 | |
| 10 | -export interface TopLevel { | |
| 10 | +export type TopLevel = TopLevelElement[]; | |
| 11 | + | |
| 12 | +export interface TopLevelElement { | |
| 11 | 13 | a?: A; |
| 12 | 14 | } |
| 13 | 15 | |
| @@ -16,12 +18,12 @@ export type A = number | string; | ||
| 16 | 18 | // Converts JSON strings to/from your types |
| 17 | 19 | // and asserts the results of JSON.parse at runtime |
| 18 | 20 | export class Convert { |
| 19 | - public static toTopLevel(json: string): TopLevel[] { | |
| 20 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 21 | + public static toTopLevel(json: string): TopLevelElement[] { | |
| 22 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 21 | 23 | } |
| 22 | 24 | |
| 23 | - public static topLevelToJson(value: TopLevel[]): string { | |
| 24 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 25 | + public static topLevelToJson(value: TopLevelElement[]): string { | |
| 26 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 25 | 27 | } |
| 26 | 28 | } |
| 27 | 29 | |
| @@ -179,7 +181,7 @@ function r(name: string) { | ||
| 179 | 181 | } |
| 180 | 182 | |
| 181 | 183 | const typeMap: any = { |
| 182 | - "TopLevel": o([ | |
| 184 | + "TopLevelElement": o([ | |
| 183 | 185 | { json: "a", js: "a", typ: u(undefined, u(0, "")) }, |
| 184 | 186 | ], false), |
| 185 | 187 | }; |
Test case
3 generated files · +19 −15test/inputs/json/samples/github-events.json
Mflowdefault / TopLevel.js+8 −6
| @@ -9,7 +9,9 @@ | ||
| 9 | 9 | // These functions will throw an error if the JSON doesn't |
| 10 | 10 | // match the expected interface, even if the JSON is valid. |
| 11 | 11 | |
| 12 | -export type TopLevel = { | |
| 12 | +export type TopLevel = TopLevelElement[]; | |
| 13 | + | |
| 14 | +export type TopLevelElement = { | |
| 13 | 15 | actor: Actor; |
| 14 | 16 | created_at: Date; |
| 15 | 17 | id: string; |
| @@ -301,12 +303,12 @@ export type TopLevelRepo = { | ||
| 301 | 303 | |
| 302 | 304 | // Converts JSON strings to/from your types |
| 303 | 305 | // and asserts the results of JSON.parse at runtime |
| 304 | -function toTopLevel(json: string): TopLevel[] { | |
| 305 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 306 | +function toTopLevel(json: string): TopLevelElement[] { | |
| 307 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 306 | 308 | } |
| 307 | 309 | |
| 308 | -function topLevelToJson(value: TopLevel[]): string { | |
| 309 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 310 | +function topLevelToJson(value: TopLevelElement[]): string { | |
| 311 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 310 | 312 | } |
| 311 | 313 | |
| 312 | 314 | function invalidValue(typ: any, val: any, key: any, parent: any = '') { |
| @@ -463,7 +465,7 @@ function r(name: string) { | ||
| 463 | 465 | } |
| 464 | 466 | |
| 465 | 467 | const typeMap: any = { |
| 466 | - "TopLevel": o([ | |
| 468 | + "TopLevelElement": o([ | |
| 467 | 469 | { json: "actor", js: "actor", typ: r("Actor") }, |
| 468 | 470 | { json: "created_at", js: "created_at", typ: Date }, |
| 469 | 471 | { json: "id", js: "id", typ: "" }, |
Mjavascriptdefault / TopLevel.js+3 −3
| @@ -10,11 +10,11 @@ | ||
| 10 | 10 | // Converts JSON strings to/from your types |
| 11 | 11 | // and asserts the results of JSON.parse at runtime |
| 12 | 12 | function toTopLevel(json) { |
| 13 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 13 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | function topLevelToJson(value) { |
| 17 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 17 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | function invalidValue(typ, val, key, parent = '') { |
| @@ -171,7 +171,7 @@ function r(name) { | ||
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | const typeMap = { |
| 174 | - "TopLevel": o([ | |
| 174 | + "TopLevelElement": o([ | |
| 175 | 175 | { json: "actor", js: "actor", typ: r("Actor") }, |
| 176 | 176 | { json: "created_at", js: "created_at", typ: Date }, |
| 177 | 177 | { json: "id", js: "id", typ: "" }, |
Mtypescriptdefault / TopLevel.ts+8 −6
| @@ -7,7 +7,9 @@ | ||
| 7 | 7 | // These functions will throw an error if the JSON doesn't |
| 8 | 8 | // match the expected interface, even if the JSON is valid. |
| 9 | 9 | |
| 10 | -export interface TopLevel { | |
| 10 | +export type TopLevel = TopLevelElement[]; | |
| 11 | + | |
| 12 | +export interface TopLevelElement { | |
| 11 | 13 | actor: Actor; |
| 12 | 14 | created_at: Date; |
| 13 | 15 | id: string; |
| @@ -298,12 +300,12 @@ export interface TopLevelRepo { | ||
| 298 | 300 | // Converts JSON strings to/from your types |
| 299 | 301 | // and asserts the results of JSON.parse at runtime |
| 300 | 302 | export class Convert { |
| 301 | - public static toTopLevel(json: string): TopLevel[] { | |
| 302 | - return cast(JSON.parse(json), a(r("TopLevel"))); | |
| 303 | + public static toTopLevel(json: string): TopLevelElement[] { | |
| 304 | + return cast(JSON.parse(json), a(r("TopLevelElement"))); | |
| 303 | 305 | } |
| 304 | 306 | |
| 305 | - public static topLevelToJson(value: TopLevel[]): string { | |
| 306 | - return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2); | |
| 307 | + public static topLevelToJson(value: TopLevelElement[]): string { | |
| 308 | + return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2); | |
| 307 | 309 | } |
| 308 | 310 | } |
| 309 | 311 | |
| @@ -461,7 +463,7 @@ function r(name: string) { | ||
| 461 | 463 | } |
| 462 | 464 | |
| 463 | 465 | const typeMap: any = { |
| 464 | - "TopLevel": o([ | |
| 466 | + "TopLevelElement": o([ | |
| 465 | 467 | { json: "actor", js: "actor", typ: r("Actor") }, |
| 466 | 468 | { json: "created_at", js: "created_at", typ: Date }, |
| 467 | 469 | { json: "id", js: "id", typ: "" }, |
No generated files match these filters.