zenstackhq / zenstack

Fullstack TypeScript toolkit that enhances Prisma ORM with flexible Authorization layer for RBAC/ABAC/PBAC/ReBAC, offering auto-generated type-safe APIs and frontend hooks.
https://zenstack.dev
MIT License
2.07k stars 88 forks source link

Error importing openapi.json into clients #642

Closed bhanuc closed 1 year ago

bhanuc commented 1 year ago

Description and expected behavior I am generating API for around 36 tables, which is creating huge openapi.json file. This file hangs up when loading in redoc and swagger ui (this loads and shows the list of routes, but gets stuck when you try to open any route). I thought it could be a size related issue, though I tried to import the json to redocly I got error : Validation failed with 164 errors and 937 warnings. All the errors are unresolved refs - sharing an example of error and the api.json below


openapi.json#/components/schemas/system_module_componentInclude/properties/_count/oneOf/1

148750 |       "type": "boolean"
148751 |     },
148752 |     {
148753 |       "$ref": "#/components/schemas/system_module_componentCountOutputTypeArgs"
148754 |     }
148755 |   ]
148756 | }
Error was generated by the no-unresolved-refs rule.```

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Environment (please complete the following information):**

-   ZenStack version: [1.0.0-beta.19]
-   Prisma version: [^5.1.1]
-   Database type: [Postgresql]

**Additional context**
[openapi.json.zip](https://github.com/zenstackhq/zenstack/files/12405502/openapi.json.zip)

Can reply in case anything else is needed from my end. Thanks
ymc9 commented 1 year ago

Hi @bhanuc , thanks for reporting this issue. I believe the problem is caused by an accidental breaking change in Prisma 5.1.1. The issue is tracked here: https://github.com/prisma/prisma/issues/20614

The issue is supposed to be resolved in Prisma 5.2 release (landing in a few days). Before that happens, please stay with 5.0.

The OpenAPI plugin generates many many types when running with "rpc" flavor (basically mirroring how Prisma generates types), and I believe it'll cause problem loading into UI when there're many tables ...

bhanuc commented 1 year ago

Hi @ymc9, Prisma 5.2 was released few hours ago. I tested 5.2, 5.0 and 4.17.0-dev.87 . Still getting same error on all versions. Should I also downgrade zenstack as well ?

ymc9 commented 1 year ago

Hi @ymc9, Prisma 5.2 was released few hours ago. I tested 5.2, 5.0 and 4.17.0-dev.87 . Still getting same error on all versions. Should I also downgrade zenstack as well ?

Oh, great news! Let me try it out now.

ymc9 commented 1 year ago

Hi @bhanuc , I just tried upgrading and running openapi plugin in a sample project and the generated output loaded fine in redocly. I suspect it has something to do with the casing of your model names, but I couldn't reproduce it ...

Is it possible to have your zmodel file or the generated openapi file? Thanks!

ymc9 commented 1 year ago

Fixed in release beta.20