-
Notifications
You must be signed in to change notification settings - Fork 214
Open
Labels
Description
Hello,
I'm trying to use your module to progamaticly generate JSON Schema from my defined types. Most of my custom types extends from packages types, such as Prisma. I don't have a lot of types, for here there are:
import { Prisma, Challenge } from "@prisma/client"
import { SessionRequest } from "supertokens-node/framework/fastify"
import { Certificate } from "tls"
export interface ChallengeWithStats extends Challenge {
currentValue: number
}
export interface ExoCertificate extends Certificate {
DC: string
}
interface RouteInterface {
Params?: unknown
Body?: unknown
}
export interface FastifyRequestSession<T extends RouteInterface> extends SessionRequest {
body: T["Body"]
params: T["Params"]
}
export interface UserWithRoles extends Prisma.UserGetPayload<{ include: { preferences: true } }>{
roles: string[]
}
export interface SessionJsonData {
sessionId: string
start_date: Date
end_date: Date
steps: number
distance: number
verticalDuration: number
walkDuration: number
totalDuration: number
}
export interface SessionStatistics {
total: {
steps: number
distance: number
verticalDuration: number
walkDuration: number
totalDuration: number
}
}
Note that all those types are located in ./src/types/**.ts
, and all exported in ./src/types/index.ts
.
Here is my script I'm trying to run to make my schema:
const fs = require("fs")
import("ts-json-schema-generator").then(async tsj => {
const config = {
path: "./src/types/index.ts",
tsconfig: "./tsconfig.json",
type: "*",
}
const outputPath = "./testSchema.json"
const schema = tsj.createGenerator(config).createSchema(config.type)
const schemaString = JSON.stringify(schema, null, 2)
fs.writeFile(outputPath, schemaString, err => {
if (err) throw err
})
})
This file is located in ./src/generateSchema.js
and i'm running the script like node ./src/schemaGenerator.js
And the output throw me this error:
file:///src/api/node_modules/ts-json-schema-generator/dist/src/NodeParser/IndexedAccessTypeNodeParser.js:60
throw new LogicError(`Invalid index "${type.getValue()}" in type "${objectType.getId()}"`);
^
LogicError: Invalid index "exoskeleton" in type "indexed-type-1777104669-59854-59949-1777104669-59841-59950-1777104669-59839-60229-1777104669-59543-60230-1777104669-0-108983<structure-1777104669-16731-16733-1777104669-16717-16746-1777104669-16680-16747-1777104669-0-108983,structure-1777104669-16734-16737-1777104669-16717-16746-1777104669-16680-16747-1777104669-0-108983,structure-1777104669-16738-16741-1777104669-16717-16746-1777104669-16680-16747-1777104669-0-108983,structure-1777104669-16742-16745-1777104669-16717-16746-1777104669-16680-16747-1777104669-0-108983>"
at file:///src/api/node_modules/ts-json-schema-generator/dist/src/NodeParser/IndexedAccessTypeNodeParser.js:60:27
at Array.map (<anonymous>)
at IndexedAccessTypeNodeParser.createType (file:///src/api/node_modules/ts-json-schema-generator/dist/src/NodeParser/IndexedAccessTypeNodeParser.js:47:42)
at ChainNodeParser.createType (file:///src/api/node_modules/ts-json-schema-generator/dist/src/ChainNodeParser.js:27:54)
at TypeReferenceNodeParser.createSubContext (file:///src/api/node_modules/ts-json-schema-generator/dist/src/NodeParser/TypeReferenceNodeParser.js:60:62)
at TypeReferenceNodeParser.createType (file:///src/api/node_modules/ts-json-schema-generator/dist/src/NodeParser/TypeReferenceNodeParser.js:30:70)
at ChainNodeParser.createType (file:///src/api/node_modules/ts-json-schema-generator/dist/src/ChainNodeParser.js:27:54)
at AnnotatedNodeParser.createType (file:///src/api/node_modules/ts-json-schema-generator/dist/src/NodeParser/AnnotatedNodeParser.js:25:47)
at file:///src/api/node_modules/ts-json-schema-generator/dist/src/NodeParser/TypeLiteralNodeParser.js:35:117
at Array.map (<anonymous>) {
msg: 'Invalid index "exoskeleton" in type "indexed-type-1777104669-59854-59949-1777104669-59841-59950-1777104669-59839-60229-1777104669-59543-60230-1777104669-0-108983<structure-1777104669-16731-16733-1777104669-16717-16746-1777104669-16680-16747-1777104669-0-108983,structure-1777104669-16734-16737-1777104669-16717-16746-1777104669-16680-16747-1777104669-0-108983,structure-1777104669-16738-16741-1777104669-16717-16746-1777104669-16680-16747-1777104669-0-108983,structure-1777104669-16742-16745-1777104669-16717-16746-1777104669-16680-16747-1777104669-0-108983>"'
}
Node.js v20.13.1
And to be honest, I have no clue about how to read and correct this at this point!
Do you guys have any clue on how to fix this ?
Thanks