Allow plugin to extend payload config #2369
Replies: 6 comments 7 replies
-
Is this something that can be done, or should I start exploring other options? |
Beta Was this translation helpful? Give feedback.
-
@jacobsfletch , would you perhaps be able to answer this question? I'd be happy to do the work. |
Beta Was this translation helpful? Give feedback.
-
Thanks @jmikrut for answering my question. I understand the implications and have also implemented my plugin as a chained function that accepts strongly typed options. This does however not cover all use cases in a way that's easy to use for the users of the plugin. In my plugin, payload-swagger, I'm generating a openAPI document based on the payload config. This includes the custom endpoints. There's however no way for me to determine query parameters, description or return type of the custom endpoint. So let's say given the demo project I'd create a custom endpoint that returns all the posts for a given category. I'd add that endpoint to the endpoints: [
{
path: '/category/:category',
method: 'get',
handler: async (req, res) => {
// implementation
},
},
], So if I follow your suggested solution, if I wanted to document this endpoint, I'd do it like this export default buildConfig({
plugins: [
swagger({
collections: {
posts: {
'/category/:category': {
get: {
description: 'Get the posts for a given category',
returnType: 'posts'
}
}
}
}
})
]
}); This would not be a very good dev experience and quite error prone. What I'd like to do is to allow the user to write this documentation where it makes sense: in the custom endpoint definition: endpoints: [
{
path: '/category/:category',
method: 'get',
description: 'Get the posts for a given category',
returnType: 'posts'
handler: async (req, res) => {
// implementation
},
},
], With that, the collection config would still be a valid
None of these would cause any issues or compromise the overall dev experience of payload. |
Beta Was this translation helpful? Give feedback.
-
Yes, that approach sounds reasonable. Happy to look into it and see if I can make a PR for it. Thanks |
Beta Was this translation helpful? Give feedback.
-
maybe we can use this as inspiration https://ez.robintail.cz/ for custom endpoint builder.... it is pretty awesome |
Beta Was this translation helpful? Give feedback.
-
yeah that is right.. but i suppose I could just hook that library i showed
on the same express server that payload is running on.. I suppose I can use
localAPI and all..
this way I can completely ignore the payload endpoints if I want and I
build more complex endpoint using this library.
Do you see any downsides of this approach? if you ignore the bloat of
having express + payload + zod-api
…On Fri, 31 Mar 2023 at 12:12, Teun Mooij ***@***.***> wrote:
ah, I see. sounds nice, but I'm not sure that would work since the
handlers are not plain express handlers, but payload handlers.
And I don't know how you use custom endpoints, but a lot of mine actually
return payload types that have already been defined, and I do not have a
zod schema for. Of course you could write a zod-to-payload plugin, but I
think that will not be that straightforward, because you'd need to
accommodate also for custom fields.
—
Reply to this email directly, view it on GitHub
<#2369 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADWTG26CPDSUGKODUCZZUL3W62UZTANCNFSM6AAAAAAWCCDTNA>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
It would be nice to be able to extend the config with extra information for a plugin.
Why
I'm working on a payload-swagger plugin and would like to have some extra information in the config. For instance on a custom endpoint I would have
description
andresponse
that I would use in the openapi document.Current situation
When I build the config with some extra information, I get an error saying there's a forbidden field in my config.
Since the plugin runs on the raw config it is already possible to do this, but there's 2 issues with this:
onInit
function to start my plugin;Possible solution
Since the sanitize function uses
joy
for schema validation, simply adding.unknown(true)
to the schemas would solve my issue.If the idea is accepted, I'd be happy to create a PR for this.
Beta Was this translation helpful? Give feedback.
All reactions