ts-json-schema-generator
ts-json-schema-generator copied to clipboard
Unable to specify the path of type file
I want to generate json file from the prisma client types:
toJson.js
:
const tsj = require('ts-json-schema-generator')
const fs = require('fs')
const config = {
path: './node_modules/.prisma/client/index.d.ts',
// tsconfig: './tsconfig.base.json',
type: '*', // Or <type-name> if you want to generate schema for that one type only
}
const output_path = 'prisma-types.json'
const schema = tsj.createGenerator(config).createSchema(config.type)
const schemaString = JSON.stringify(schema, null, 2)
fs.writeFile(output_path, schemaString, (err) => {
console.log('error', err.message)
if (err) throw err
})
It printed the schemaString
onto the terminal:
...
' : ReactManagedAttributes<T, P>\n' +
' : ReactManagedAttributes<C, P>;\n' +
'\n' +
' interface IntrinsicAttributes extends React.Attributes { }\n' +
' interface IntrinsicClassAttributes<T> extends React.ClassAttributes<T> { }\n' +
'\n' +
' interface IntrinsicElements {\n' +
' // HTML\n' +
' a: React.DetailedHTMLProps<React.AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>;\n' +
' abbr: React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement>;\n' +
' address: React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement>;\n' +
' area: React.DetailedHTMLProps<React.AreaHTMLAttributes<HTMLAreaElement>, HTMLAreaElement>;\n' +
' article: React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement>;\n' +
' aside: React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement>;\n' +
' audio: React.DetailedHTMLProps<React.AudioHTMLAttributes<HTMLAudioElement>, HTMLAudioElement>;\n' +
' b: React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement>;\n' +
' base: React.DetailedHTMLProps<React.BaseHTMLAttributes<HTMLBaseElement>, HTMLBaseElement>;\n' +
...
It just took all type files from node_modules
.
Changing the path to /nodules/.prisma/client/index.d.ts
did not work.
I also tried copying the type file to the project root directory, and changing the path to /index.d.ts
or index.d.ts
or ./index.d.ts
.
Same behavior - not sure if i was using it totally wrong!