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
101 stars 12 forks source link

some issues with generating typescript client #34

Closed krisgrm closed 1 year ago

krisgrm commented 1 year ago

Expected Behavior

Hello, I am using swagger plugin to generate the spec, and then I run the spec though openapi generator

Actual Behavior

I get these validation warnings:

Exception in thread "main" org.openapitools.codegen.SpecValidationException: There were issues with the specification. The option can be disabled via validateSpec (Maven/Gradle) or --skip-validate-spec (CLI).
 | Error count: 56, Warning count: 0
Errors: 
        -attribute paths.'/users/{id}'(patch).responses.200.properties is unexpected
        -attribute paths.'/users'(post).responses.200.properties is unexpected
        -attribute paths.'/policies/{id}'(delete).responses.200.type is unexpected
        -attribute paths.'/users/{id}'(patch).responses.200.type is unexpected
        -attribute paths.'/teams/{id}'(delete).responses.200.properties is unexpected
        -attribute paths.'/access_tokens/{id}'(delete).responses.200.description is missing
        -attribute paths.'/users/{id}'(delete).parameters.[id].type is unexpected
        -attribute paths.'/access_tokens/{id}'(delete).parameters.[id].content is missing
        -attribute paths.'/policies/{id}'(delete).parameters.[id].content is missing
        -attribute paths.'/policies/{id}'(delete).responses.200.required is unexpected
        -attribute paths.'/teams'(post).responses.200.description is missing
        -attribute paths.'/teams/{id}'(delete).responses.200.type is unexpected
        -attribute paths.'/policies/{id}'(patch).responses.200.properties is unexpected
        -attribute paths.'/access_tokens'(post).responses.200.type is unexpected
        -attribute paths.'/users/{id}'(delete).responses.200.description is missing
        -attribute paths.'/policies/{id}'(delete).responses.200.description is missing
        -attribute paths.'/teams'(post).responses.200.properties is unexpected
        -attribute paths.'/policies'(post).responses.200.type is unexpected
        -attribute paths.'/users/{id}'(patch).responses.200.description is missing
        -attribute paths.'/users/{id}'(delete).responses.200.properties is unexpected
        -attribute paths.'/access_tokens/{id}'(delete).responses.200.type is unexpected
        -attribute paths.'/users/{id}'(delete).parameters.[id].content is missing
        -attribute paths.'/access_tokens/{id}'(delete).responses.200.properties is unexpected
        -attribute paths.'/teams'(post).responses.200.type is unexpected
        -attribute paths.'/access_tokens/{id}'(delete).parameters.[id].type is unexpected
        -attribute paths.'/access_tokens'(post).responses.200.properties is unexpected
        -attribute paths.'/users/{id}'(patch).responses.200.required is unexpected
        -attribute paths.'/access_tokens/{id}'(patch).responses.200.properties is unexpected
        -attribute paths.'/teams/{id}'(delete).parameters.[id].content is missing
        -attribute paths.'/policies/{id}'(patch).responses.200.type is unexpected
        -attribute paths.'/access_tokens/{id}'(patch).responses.200.type is unexpected
        -attribute paths.'/access_tokens'(post).responses.200.required is unexpected
        -attribute paths.'/access_tokens/{id}'(delete).responses.200.required is unexpected
        -attribute paths.'/users/{id}'(delete).responses.200.required is unexpected
        -attribute paths.'/policies/{id}'(delete).parameters.[id].type is unexpected
        -attribute paths.'/users'(post).responses.200.required is unexpected
        -attribute paths.'/policies/{id}'(patch).responses.200.required is unexpected
        -attribute paths.'/users'(post).responses.200.type is unexpected
        -attribute paths.'/policies'(post).responses.200.properties is unexpected
        -attribute paths.'/policies/{id}'(delete).responses.200.properties is unexpected
        -attribute paths.'/policies'(post).responses.200.description is missing
        -attribute paths.'/access_tokens'(post).responses.200.description is missing
        -attribute paths.'/teams/{id}'(delete).responses.200.required is unexpected
        -attribute paths.'/teams/{id}'(patch).responses.200.type is unexpected
        -attribute paths.'/access_tokens/{id}'(patch).responses.200.required is unexpected
        -attribute paths.'/teams/{id}'(patch).responses.200.required is unexpected
        -attribute paths.'/teams'(post).responses.200.required is unexpected
        -attribute paths.'/teams/{id}'(patch).responses.200.properties is unexpected
        -attribute paths.'/policies/{id}'(patch).responses.200.description is missing
        -attribute paths.'/policies'(post).responses.200.required is unexpected
        -attribute paths.'/users'(post).responses.200.description is missing
        -attribute paths.'/access_tokens/{id}'(patch).responses.200.description is missing
        -attribute paths.'/users/{id}'(delete).responses.200.type is unexpected
        -attribute paths.'/teams/{id}'(delete).parameters.[id].type is unexpected
        -attribute paths.'/teams/{id}'(delete).responses.200.description is missing
        -attribute paths.'/teams/{id}'(patch).responses.200.description is missing

I'll to run without the validations and see what happens in runtime

Steps to Reproduce the Problem

  1. Install plugin
  2. Run the app
  3. Run the generator

I run generator through docker, here is a snippet:

"generate-typescript-client:local": "docker run --rm -v \"${PWD}:/local\" openapitools/openapi-generator-cli generate \\\n    -i http://host.docker.internal:3004/api-docs/specs \\\n    -g typescript-fetch \\\n    -o /local/src/generated\n",

Specifications

Comments

Hey I've used TRPC in the past with openapi plugin.. I've also used this library https://www.npmjs.com/package/express-zod-api that is based on zod and is capable of outputing the openapi schema.

I wonder if it would be possible to use ZOD for collection&endpoints input&output validation.. and then we use that to generate the openapi. Just wondering out loud, I am not that expirienced to tell if it makes sense, but it sounds really cool

teunmooij commented 1 year ago

Hi, thanks for registering this issue. I'll try to replicate the issue and will get back to you asap.

teunmooij commented 1 year ago

Hi, the version you used was the last beta-version before the 1.0 release and was not fully validated. I was in the midst of refactoring the codebase to iron out the last deviations from the openapi 3.0 definitions. I've now released a version 1, which I validated succesfully against a openapi validator. Can you please update to v1, try again and tell me if you still experience problems? If you do, can you please send me the openapi schema?

teunmooij commented 1 year ago

Verified all parts referenced in your message and all comply to the official openapi spec v3.0 now.