teunmooij / payload-tools

Collection of payload plugins and tools: payload-openapi, payload-swagger, create-payload-api-docs, payload-rbac
https://github.com/teunmooij/payload-tools/#readme
MIT License
94 stars 12 forks source link

[Bug]: `payload-swagger@1.0.5` is incompatible with `payload@1.9.0`+ #65

Closed klapec closed 1 year ago

klapec commented 1 year ago

Package name

payload-swagger

What happened?

I'm getting

@xxx/cms:dev: TypeError: Cannot read properties of undefined (reading 'set')
@xxx/cms:dev:     at /Volumes/dev/repos/xxx/node_modules/.pnpm/payload@1.9.1_@types+react@18.0.28_esbuild@0.16.3_typescript@5.0.4/node_modules/payload/src/utilities/entityToJSONSchema.ts:326:33
@xxx/cms:dev:     at Array.reduce (<anonymous>)
@xxx/cms:dev:     at entityFieldsToJSONSchema (/Volumes/dev/repos/xxx/node_modules/.pnpm/payload@1.9.1_@types+react@18.0.28_esbuild@0.16.3_typescript@5.0.4/node_modules/payload/src/utilities/entityToJSONSchema.ts:56:43)
@xxx/cms:dev:     at /Volumes/dev/repos/xxx/node_modules/.pnpm/payload@1.9.1_@types+react@18.0.28_esbuild@0.16.3_typescript@5.0.4/node_modules/payload/src/utilities/entityToJSONSchema.ts:321:18
@xxx/cms:dev:     at Array.reduce (<anonymous>)
@xxx/cms:dev:     at entityFieldsToJSONSchema (/Volumes/dev/repos/xxx/node_modules/.pnpm/payload@1.9.1_@types+react@18.0.28_esbuild@0.16.3_typescript@5.0.4/node_modules/payload/src/utilities/entityToJSONSchema.ts:56:43)
@xxx/cms:dev:     at entityToJSONSchema (/Volumes/dev/repos/xxx/node_modules/.pnpm/payload@1.9.1_@types+react@18.0.28_esbuild@0.16.3_typescript@5.0.4/node_modules/payload/src/utilities/entityToJSONSchema.ts:439:8)
@xxx/cms:dev:     at /Volumes/dev/repos/xxx/node_modules/.pnpm/payload-openapi@1.1.3_payload@1.9.1/node_modules/payload-openapi/dist/schemas/entity-to-schema.js:41:59
@xxx/cms:dev:     at Generator.next (<anonymous>)
@xxx/cms:dev:     at /Volumes/dev/repos/xxx/node_modules/.pnpm/payload-openapi@1.1.3_payload@1.9.1/node_modules/payload-openapi/dist/schemas/entity-to-schema.js:8:71

after updating payload to 1.9.1 (latest as of writing this bug report). Apparently you're calling payload's entityToJSONSchema without passing down the third required parameter - fieldDefinitionsMap.

What did you expect

No response

Setps to reproduce

Tool version

1.0.5

Payload version

1.9.1

Node version

No response

teunmooij commented 1 year ago

Thanks for reporting. I'll look into it asap

TopHatCroat commented 1 year ago

I'm experiencing issues with the latest version on payload

    "payload": "^1.10.0",
    "payload-openapi": "^1.1.3",
    "payload-swagger": "^1.0.5",

Both payload-openapi and payload-swagger reporting the same problem

/Users/antonio/Development/nextjs-payloadcms-demo/apps/backend/node_modules/payload-openapi/dist/schemas/entity-to-schema.js:4
    return new (P || (P = Promise))(function (resolve, reject) {
           ^
TypeError: (0 , utilities_1.entityToJSONSchema) is not a function
    at /Users/antonio/Development/nextjs-payloadcms-demo/apps/backend/node_modules/payload-openapi/dist/schemas/entity-to-schema.js:41:59
    at Generator.next (<anonymous>)
    at /Users/antonio/Development/nextjs-payloadcms-demo/apps/backend/node_modules/payload-openapi/dist/schemas/entity-to-schema.js:8:71
    at new Promise (<anonymous>)
    at __awaiter (/Users/antonio/Development/nextjs-payloadcms-demo/apps/backend/node_modules/payload-openapi/dist/schemas/entity-to-schema.js:4:12)
    at entityToSchema (/Users/antonio/Development/nextjs-payloadcms-demo/apps/backend/node_modules/payload-openapi/dist/schemas/entity-to-schema.js:40:52)
    at /Users/antonio/Development/nextjs-payloadcms-demo/apps/backend/node_modules/payload-openapi/dist/payload-config/routes/collection/main-routes.js:115:97
    at Generator.next (<anonymous>)
    at fulfilled (/Users/antonio/Development/nextjs-payloadcms-demo/apps/backend/node_modules/payload-openapi/dist/payload-config/routes/collection/main-routes.js:5:58)
[nodemon] app crashed - waiting for file changes before starting...

It's using a super simple project, it's available here https://github.com/TopHatCroat/nextjs-payloadcms-demo/tree/openapi-docs

teunmooij commented 1 year ago

Payload openapi uses payloads entityToJSONSchema, which is also used to generate the typescript definitions, to generate parts of the openapi document. This function is part of payloads public interface.

teunmooij commented 1 year ago

I've published a new version of payload-swagger and payload-openapi that fixes this bug.

However, payload version 1.9.3 - 1.10.1 contain a bug. Openapi documentation will not work with those version. The next version of payload contains the fix for that bug, but has not yet been published.

thnhat51202574 commented 1 year ago

Hi @teunmooij, the payload tool has deployed a new version 1.10.2, which includes a fix. I'm wondering if this version is compatible with the latest version of payloadtools?

teunmooij commented 1 year ago

I haven't tested this version yet, but yes, it should be.

teunmooij commented 1 year ago

Tested. It's compatible

klapec commented 1 year ago

Can confirm, everything works fine. Thanks!