Coder Social home page Coder Social logo

teunmooij / payload-tools Goto Github PK

View Code? Open in Web Editor NEW
85.0 4.0 9.0 1.62 MB

Collection of payload plugins and tools: payload-openapi, payload-swagger, create-payload-api-docs, payload-rbac

Home Page: https://github.com/teunmooij/payload-tools/#readme

License: MIT License

Shell 0.19% TypeScript 99.18% SCSS 0.61% JavaScript 0.02%
payload-plugin openapi swagger-ui api-docs rbac access-control query select

payload-tools's People

Contributors

alessiogr avatar teunmooij avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

payload-tools's Issues

globals

Description

Please describe the required functionality

Better tests

Description

Unittests for:

  • createDocument with basic configuration
  • plugin

[Bug]: `[email protected]` is incompatible with `[email protected]`+

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/[email protected]_@[email protected][email protected][email protected]/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/[email protected]_@[email protected][email protected][email protected]/node_modules/payload/src/utilities/entityToJSONSchema.ts:56:43)
@xxx/cms:dev:     at /Volumes/dev/repos/xxx/node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]/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/[email protected]_@[email protected][email protected][email protected]/node_modules/payload/src/utilities/entityToJSONSchema.ts:56:43)
@xxx/cms:dev:     at entityToJSONSchema (/Volumes/dev/repos/xxx/node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]/node_modules/payload/src/utilities/entityToJSONSchema.ts:439:8)
@xxx/cms:dev:     at /Volumes/dev/repos/xxx/node_modules/.pnpm/[email protected][email protected]/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/[email protected][email protected]/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

Loosing existing endpoint when merging custom method

          Thank you, @teunmooij , for the excellent plugin for Payload CMS. I encountered an issue related to the custom endpoint. I want to add an API with `type='options'` to my custom endpoint. However, when I do so, the Swagger document removes all the existing endpoints with types `'get,' 'post,' and 'delete'` 

My concern is whether there is a solution to merge the default types with the custom type in our Swagger document.
Screenshot 2023-05-22 at 13 20 36

Originally posted by @thnhat51202574 in #25 (comment)

validation of extension schemas

Description

payload-openapi reads json data from package.json and .openapi file. It would be nice to validate this data before accepting it.

[Bug]: error when trying to run

Package name

payload-openapi

What happened?

When I try to run this I get the following error. I did a quick look at the source and tried setting the tsconfig baseUrl but that didn't fix it.

Any pointers?

โฏ npx create-payload-api-docs -c src/config.ts                                                                                                                                 [13:45:25]
thread '<unnamed>' panicked at 'base_dir(`./`) must be absolute. Please ensure that `jsc.baseUrl` is specified correctly. This cannot be deduced by SWC itself because SWC is a transpiler and it does not try to resolve project details. In other works, SWC does not know which directory should be used as a base directory. It can be deduced if `.swcrc` is used, but if not, there are many candidates. e.g. the directory containing `package.json`, or the current working directory. Because of that, the caller (typically the developer of the JavaScript package) should specify it. If you see this error, please report an issue to the package author.', /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/swc_ecma_transforms_module-0.175.3/src/path.rs:104:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Error: failed to handle: base_dir(`./`) must be absolute. Please ensure that `jsc.baseUrl` is specified correctly. This cannot be deduced by SWC itself because SWC is a transpiler and it does not try to resolve project details. In other works, SWC does not know which directory should be used as a base directory. It can be deduced if `.swcrc` is used, but if not, there are many candidates. e.g. the directory containing `package.json`, or the current working directory. Because of that, the caller (typically the developer of the JavaScript package) should specify it. If you see this error, please report an issue to the package author.

What did you expect

No response

Setps to reproduce

This was a pretty barebones setup. I installed create-payload-api-docs as a dev dependency and tried to run it as described.

Tool version

1.4.0

Payload version

1.14.0

Node version

18.17.1

some issues with generating typescript client

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

  • Package Version: Latest
  • Application type: Latest
  • Node version: 18

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

Document 'where' type

Description

  • Schema for 'where' type
  • Update parameters array and reference the type
  • Update access type to include where type

[Bug]: SWC Error: base_dir must be absolute & Error "db" is not allowed

Package name

create-payload-api-docs
payload-openapi

What happened?

I'm wanting to generate an openapi spec from the CLI tool.

When running the command npx create-payload-api-docs --config=src/payload.config.ts from a PayloadCMS directory, I encountered the following error related to the SWC transpiler:

thread '<unnamed>' panicked at /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/swc_ecma_transforms_module-0.180.13/src/path.rs:122:13:
base_dir(``) must be absolute. Please ensure that `jsc.baseUrl` is specified correctly...

By adding a simple .swrc file, it seems to start working, but there is no mention of this in the documentation:

{
  "$schema": "https://json.schemastore.org/swcrc",
  "jsc": {
    "baseUrl": "./",
  },
  "module": {
    "type": "es6"
  }
}

After getting passed this, I think recieve other errors in the terminal:

[09:54:29] ERROR (payload): There were 4 errors validating your Payload config
[09:54:29] ERROR (payload): 1: "editor" is not allowed
[09:54:29] ERROR (payload): 2: "db" is not allowed
[09:54:29] ERROR (payload): 3: Collection "payload-migrations" > "graphQL" must be of type object
[09:54:29] ERROR (payload): 4: Collection "payload-migrations" > "endpoints" must be an array

Thanks in advance.

What did you expect

No issue, it generates the docs.

Setps to reproduce

Create a blank application in Payload and add a simple content type, run the commands indicated above.

Tool version

Latest

Payload version

2.0.0

Node version

v18.11.0

security

Description

  • properly publish the authentication: jwt and cookie
  • attempt to determine authentication per endpoint based on payload config

[Bug]: Authorization header missing from requests to custom endpoint

Package name

payload-openapi

What happened?

I am using Swagger to send authorized requests to custom endpoint that expects authorization header, but swagger does not seem to send it.

What did you expect

No response

Setps to reproduce

  1. Define a custom endpoint with a middleware that protects it via checking the authorization header
  2. Attempt to send the request

Authorization header will be missing

Tool version

1.4.0

Payload version

^2.0

Node version

20

constants

Description

Requires more investigation. Looks like openapi doesn't support 'const' like json-schema does. Instead probably only good option is to use an enum with a single value.

[Feature request]: Add request body definition to custom endpoints

Package name

payload-openapi

Description

Hello !

I've noticed that the requestBody definition is not present in the custom endpoint definitions.
I looked at the code and indeed, it seems that they are not handled, whereas the generated endpoints do include the requestBody.

Any plan on supporting this soon ?

Thanks a lot

[Bug]: (payload-openapi) i18n labels not correct

Package name

payload-openapi

What happened?

Hej, thanks for your plugins! Found a little issue:

{
  "paths": {
      "/{collection}/{id}": {
        "patch": {
          "summary": "Updates a [object Object]"
        }
      }
  }
}

labels are not always a string. Using i18n, labels is an object:

labels: {
  singular: {
    // ...
  },
  plural: {
     // ...
  }
}

Link: https://payloadcms.com/docs/configuration/i18n

What did you expect

{
  "paths": {
      "/{collection}/{id}": {
        "patch": {
          "summary": "Updates a {collectionlabel.singular.en}"
        }
      }
  }
}

Setps to reproduce

adding i18n labels to a collection.

Tool version

1.0.3

Payload version

1.6.32

Node version

No response

use a plugin?

Description

Please describe the required functionality

CLI version of payload-openapi

Description

  • generate the document as cli script
  • output locataion and options as parameters
  • maybe also as npx payload-openapi with questionaire?

custom endpoints

Description

Custom endpoint can be at:

  • config level (can be root)
  • global
  • collection

Url is relative to it's parent (except for root on config level)

Requirements:

  • determine route
  • extract route-params from path
  • expose extension type for Config to allow extra metadata with:
    • return type
    • authentication

[Bug]: Auto-generated Payload ID fields not present in Swagger schema definition

Package name

payload-openapi

What happened?

By default Payload provides an auto-generated ID field for collections. In this case, you don't need to provide an ID field in the field definition of the collection.
The payload-openapi generator does not seem to take this into account. The generated Swagger schema definition is lacking an ID field for Payload collections which use auto-generated IDs. Consequently, the data transfer objects which are generated by openapitools based on the Swagger specification lack an id field, even though the payload request response contains IDs for the transferred data objects.

For example, we have a Payload collection "Workshop" with auto-generated ID field and this is what the generated Swagger schema definition looks like:
image
Notice that the id is contained in list of properties.required but not present in the properties definition

What did you expect

Swagger schema definition for a Payload collection with auto-generated ID must contain an additional property id of type string, e.g.
image

Setps to reproduce

Create a Payload CollectionConfig without an id field, in order to let Payload create an auto-generated ID for this collection, e.g.:
image

Tool version

^1.4.0

Payload version

^2.0.0

Node version

20.10.0

Support draft/publish

Description

If a collection support draft, the config contains versions: { draft: true}.
Then on an update there's a _status property with value draft or published

We need to support this.

Versions endpoints

Package name

payload-openapi

Description

Add version endpoints for versioned collections

[Feature request]: Add support for `roles` field access configuration

Package name

payload-rbac

Description

I need to prevent a user from changing their own user Roles and am currently doing this via the Collection-level access configuration on the User collection.

Field-level access configurations solve for this - inaccessible fields are grayed out in the Payload Admin view and it skips adding the field in the request body.

Without field-level access control, the user gets an error when trying to save their user record within the User edit screen (because Payload is adding the roles field to the request body even though it hasn't been changed in the UI), so they are never able to update their user in the Payload Admin view due to this.

If you do try to add a roles field to the Collection, you get this error: Unable to enable payload-rbac on collection ${collection.slug}: collection already has a 'roles' field!.

We need the ability to gray out the Roles select control on the Admin edit screen (via supporting Field-level access configuration).

Is there a way to merge the roles field configuration from the collection into the payload-rbac roles configuration so it can leverage the access field property?

image

Move requestBodies and responses to components object (and 304)

Most messages are now defined inline. It would be cleaner to move this to the components object.

  • define schemas with paths
  • place schemas, request and response messages in components object
  • make sure all additionalProperties: false are added
  • createdAt/updatedAt only required in response, not in request
  • all fields optional in patch
  • add 304 responses on get operations

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.