Comments (10)
@navalex can you try with v2.3.0-next.2?
After #1963 added diagnostics, the error thrown will have more info about it.
from ts-json-schema-generator.
Thanks for the report. Can you provide a minimal reproducible example that demonstrates the issue?
from ts-json-schema-generator.
Yeah sorry, here is a little project I made up to reproduce this:
package.json
{
"name": "test",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"description": "",
"devDependencies": {
"@types/node": "^20.12.12",
"prisma": "^5.14.0",
"ts-json-schema-generator": "^2.2.0",
"ts-node": "^10.9.2",
"typescript": "^5.4.5"
},
"dependencies": {
"@prisma/client": "^5.14.0"
}
}
prisma/schema.prisma
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "sqlite"
url = env("DATABASE_URL")
}
model User {
id Int @id @default(autoincrement())
email String @unique
name String?
posts Post[]
}
model Post {
id Int @id @default(autoincrement())
title String
content String?
published Boolean @default(false)
author User @relation(fields: [authorId], references: [id])
authorId Int
}
types/index.ts
import { User } from '@prisma/client';
export interface UserTest extends User {
newField: string;
}
schemaGenerator.js
const fs = require("fs")
import("ts-json-schema-generator").then(async tsj => {
const config = {
path: "./types/user.ts",
tsconfig: "./tsconfig.json",
type: "*",
schemaId: "WdcTypes",
}
const outputPath = "./schemas"
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 example + my personnal tests seems to show that any import from the @prisma/client
seems to make the generator crash.
from ts-json-schema-generator.
That's not yet minimal if you can remove anything and the error state does not change. Oncer you identify the offending change, you can see how it's causing the issues you see.
from ts-json-schema-generator.
Okay,
I edited my schema:
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "sqlite"
url = env("DATABASE_URL")
}
model User {
name String @unique
}
That make all my files as minimal as possible (not that the error also trigger with the CLI, without using my .js file).
The error occur when I extends any Prisma type. The moment I remove Prisma imports, everything works, if I add a Prisma type, it triggers this error
from ts-json-schema-generator.
This might be fixed by #1924
from ts-json-schema-generator.
#343 could also help here
from ts-json-schema-generator.
Probably duplicate of #542
from ts-json-schema-generator.
@navalex can you try with v2.3.0-next.2?
After #1963 added diagnostics, the error thrown will have more info about it.
Okay so, after testing, it does fix the issue on my basic exemple, but does not on my main project. I tried both 2.2.0-next.0
and 2.3.0-next.2
, the last one give an enormous output that seems to dump both a ts-json-schema-generator
file and probably my file that throw the error (the Prisma generated client, so a big one).
I don't know if I'll have enough time to do more tests this week, so here is at least the output error, may give you more infos:
Here is the full log: https://logpaste.com/OQTlH3wj
I'll also let my package.json
and prisma.schema
package.json
:
{
"name": "eveapp-api-core",
"version": "1.0.1",
"description": "",
"scripts": {
"start:dev": "nodemon --exec 'ts-node -r tsconfig-paths/register' src/server.ts",
"start:prod": "node -r tsconfig-paths/register dist/server.js",
"build": "tsc && tsc-alias",
"test:watch": "jest --watchAll --collectCoverage",
"test:ci": "jest --collectCoverage",
"test:manual": "jest",
"format:check": "prettier --check \"src/**/*.ts\"",
"format:write": "prettier --write \"src/**/*.ts\"",
"lint:check": "eslint \"src/**/*.ts\"",
"lint:fix": "eslint --fix \"src/**/*.ts\"",
"schema:generate": "node bin/schemaGenerator.js"
},
"nodemonConfig": {
"watch": [
"src"
],
"ext": "ts",
"exec": "ts-node -r tsconfig-paths/register"
},
"author": "",
"license": "ISC",
"dependencies": {
"@fastify/cors": "^9.0.1",
"@fastify/formbody": "^7.4.0",
"@fastify/multipart": "^8.2.0",
"@fastify/sensible": "^5.6.0",
"@fastify/swagger": "^8.14.0",
"@fastify/swagger-ui": "^3.0.0",
"@prisma/client": "^5.14.0",
"fastify": "^4.27.0",
"pino-loki": "^2.3.0",
"pino-pretty": "^11.0.0",
"prom-client": "^15.1.2",
"socket.io": "^4.7.5",
"supertokens-node": "^17.1.2"
},
"devDependencies": {
"@types/jest": "^29.5.12",
"@types/node": "^20.12.12",
"eslint": "^9.3.0",
"eslint-config-prettier": "^9.1.0",
"jest": "^29.7.0",
"jest-mock-extended": "^3.0.7",
"nodemon": "^3.1.0",
"prettier": "^3.2.5",
"prisma": "^5.14.0",
"prisma-json-schema-generator": "5.1.1",
"prisma-json-types-generator": "^3.0.4",
"ts-jest": "^29.1.3",
"ts-json-schema-generator": "^2.3.0-next.2",
"ts-node": "^10.9.2",
"tsc-alias": "^1.8.10",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.4.5"
}
}
prisma.schema
:
// ############################################
// #
// # DATABASE DEFINITION
// #
// ############################################
datasource db {
provider = "postgresql"
url = env("API_POSTGRES_URL")
}
generator client {
provider = "prisma-client-js"
previewFeatures = ["fullTextSearch"]
}
generator jsonTypes {
provider = "prisma-json-types-generator"
}
generator jsonSchema {
provider = "prisma-json-schema-generator"
schemaId = "PrismaSchema"
forceAnyOf = true
}
// ############################################
// #
// # MODELS
// #
// ############################################
model User {
id String @id @default(uuid())
auth_id String @unique
firstname String
lastname String
data Json
activationToken String? @default(uuid())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
following User[] @relation("Follow")
followers User[] @relation("Follow")
exoskeletons ExoskeletonAttribution[]
challenges Challenge[]
authoredChallenges Challenge[] @relation(name: "challengeAuthor")
surveys Survey[]
preferences Preferences?
}
model Preferences {
id String @id @default(uuid())
userId String @unique
user User @relation(fields: [userId], references: [id])
weekStart WeekStartDay @default(MONDAY)
darkMode Boolean @default(false)
unitType UnitType @default(METRIC)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model Exoskeleton {
serial String @id
version String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
attributions ExoskeletonAttribution[]
}
model ExoskeletonAttribution {
id String @id @default(uuid())
createdAt DateTime @default(now())
revokedAt DateTime?
exoskeletonId String
userId String
exoskeleton Exoskeleton @relation(fields: [exoskeletonId], references: [serial])
user User @relation(fields: [userId], references: [id])
sessions Session[]
}
model Session {
id String @id @default(uuid())
/// [SessionData]
data Json
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
attributionId String
attribution ExoskeletonAttribution @relation(fields: [attributionId], references: [id])
}
model Challenge {
id String @default(uuid())
targetValue Float
metric ChallengeMetric
frequency ChallengeFrequency
repeate Boolean @default(false)
weekRepetition Int?
createdAt DateTime @default(now())
archivedAt DateTime?
userId String
authorId String
user User @relation(fields: [userId], references: [id])
author User @relation(name: "challengeAuthor", fields: [authorId], references: [id])
@@id(name: "challengeId", [id, createdAt])
}
model ChallengeTemplate {
id String @id @default(uuid())
description String?
targetValue Float
metric ChallengeMetric
frequency ChallengeFrequency
}
model Survey {
id String @id @default(uuid())
type SurveyType
data Json
createdAt DateTime @default(now())
userId String
user User @relation(fields: [userId], references: [id])
}
// ############################################
// #
// # ENUMS
// #
// ############################################
enum ChallengeMetric {
STEP_COUNT
DISTANCE
VERTICAL_DURATION
WALK_DURATION
}
enum ChallengeFrequency {
DAILY
WEEKLY
}
enum SurveyType {
DAILY_MOOD
}
enum WeekStartDay {
MONDAY
SUNDAY
}
enum UnitType {
METRIC
IMPERIAL
}
from ts-json-schema-generator.
Hey @navalex what about our latest release?
from ts-json-schema-generator.
Related Issues (20)
- [Bug]: Error when using the binary (v2.1.0) HOT 9
- V2 creates empty definitions after updating from V1 HOT 5
- CLI usage is throwing an error with node 22 HOT 3
- RegExp types are now emitted, breaking schema validation (v2.1.1) HOT 1
- Error when following exports?
- Dist types now require @types/ts-expose-internals HOT 9
- Fix CJS imports HOT 8
- CLI - ENOENT: no such file or directory, open 'package.json' HOT 3
- Error: Unknown type "undefined" HOT 2
- Required types not allowed HOT 1
- Generator crashed when no package version is set HOT 4
- Any way to indicate that a string is actually a date-time? HOT 7
- Breaking changes from v1 to v2 HOT 1
- Support for `"format": "uri-reference"` HOT 3
- Incorrect typing when a type uses Omit and inherits properties from a grandparent interface
- `--expose all` breaks generation with generic types. HOT 3
- How do you use ajv with references? HOT 1
- create schema uses `anyOf` instead of `allOf` HOT 5
- When I use discriminator, I am getting an error where it can't find the specific field HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ts-json-schema-generator.