Skip to content

docs: improve plugin-develop docs#12242

Merged
Baoyuantop merged 7 commits into
apache:masterfrom
ctxinf:plugin-docs-edit
Jun 17, 2025
Merged

docs: improve plugin-develop docs#12242
Baoyuantop merged 7 commits into
apache:masterfrom
ctxinf:plugin-docs-edit

Conversation

@ctxinf

@ctxinf ctxinf commented May 22, 2025

Copy link
Copy Markdown
Contributor

Description

I encountered some difficulties while following the plugin-develop documentation during development:

  1. The structure of the document was confusing and not clearly organized; it didn’t progress from basic to advanced concepts.
  2. Some critical parts were not explained. help request: custom plugin failed to load plugin [demo] err: module 'apisix.plugins.demo' not found: #11835 (comment)

Therefore, I restructured the overall layout, provided more detailed explanations in some sections, and added some relevant resources.

Which issue(s) this PR fixes:

Fixes #

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change
  • I have verified that this change is backward compatible (If not, please discuss on the APISIX mailing list first)

@dosubot dosubot Bot added size:XL This PR changes 500-999 lines, ignoring generated files. doc Documentation things labels May 22, 2025
@kayx23

kayx23 commented May 23, 2025

Copy link
Copy Markdown
Member

Please resolve lint errors.

@kayx23
kayx23 self-requested a review May 24, 2025 09:56
Comment thread docs/en/latest/plugin-develop.md Outdated
## Where to put your plugins

There are two ways to add new features based on APISIX.
Setup the `extra_lua_path` in `conf/config.yaml` to load your own code (or `extra_lua_cpath` for compiled .so or .dll file).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Setup the `extra_lua_path` in `conf/config.yaml` to load your own code (or `extra_lua_cpath` for compiled .so or .dll file).
Use the `extra_lua_path` parameter in `conf/config.yaml` file to load your custom plugin code (or use `extra_lua_cpath` for compiled `.so` or `.dll` file).

│   └── apisix
│   ├── plugins
│   │   └── 3rd-party.lua
│   └── stream

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe leave the stream and mention in text that if you would like to load a custom stream (L4) plugin, this is how it should structured. My concern is that once the stream folder is removed, it is not documented anywhere else.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know nothing about the stream folder, please revise this section yourself.

:::note

If you need to customize the directory of plugin, please create a subdirectory of `/apisix/plugins` under this directory.
The directory (`/path/to/example`) must contain the `/apisix/plugins` subdirectory.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about

Suggested change
The directory (`/path/to/example`) must contain the `/apisix/plugins` subdirectory.
The directory (`/path/to/example`) must contain the `/apisix/plugins` subdirectory for L7 plugins.

Comment thread docs/en/latest/plugin-develop.md Outdated

if you have dependencies on external libraries, check the dependent items. if your plugin needs to use shared memory, it
needs to declare via [customizing Nginx configuration](./customize-nginx-configuration.md), for example :
Once the plugins configuration is defined in `conf/config.yaml`, the new plugins list will replace the default configuration instead of merging. Therefore, when defining the `plugins` field, make sure to include the built-in plugins that are being used. To maintain consistency with the default behavior, you can include all the default enabled plugins defined in **apisix/cli/config.lua**.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Once the plugins configuration is defined in `conf/config.yaml`, the new plugins list will replace the default configuration instead of merging. Therefore, when defining the `plugins` field, make sure to include the built-in plugins that are being used. To maintain consistency with the default behavior, you can include all the default enabled plugins defined in **apisix/cli/config.lua**.
Once the plugins configuration is defined in `conf/config.yaml`, the new plugins list will replace the default configuration instead of merging. Therefore, when defining the `plugins` field, make sure to include the built-in plugins that are being used. To maintain consistency with the default behavior, you can include all the default enabled plugins defined in `apisix/cli/config.lua`.

Comment thread docs/en/latest/plugin-develop.md Outdated
method "http_init" in the file __apisix/init.lua__, and you may need to add some processing on generated part of Nginx
configuration file in __apisix/cli/ngx_tpl.lua__ file. But it is easy to have an impact on the overall situation according to the
existing plugin mechanism, **we do not recommend this unless you have a complete grasp of the code**.
The [example-plugin](https://github.com/apache/apisix/blob/master/apisix/plugins/example-plugin.lua) plugin (local location: **apisix/plugins/example-plugin.lua**) provides an example.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The [example-plugin](https://github.com/apache/apisix/blob/master/apisix/plugins/example-plugin.lua) plugin (local location: **apisix/plugins/example-plugin.lua**) provides an example.
The [`example-plugin`](https://github.com/apache/apisix/blob/master/apisix/plugins/example-plugin.lua) plugin in this repo provides an example.

Comment thread docs/en/latest/plugin-develop.md Outdated

## Check external dependencies

If you have dependencies on external libraries, check the dependent items. if your plugin needs to use shared memory, it

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
If you have dependencies on external libraries, check the dependent items. if your plugin needs to use shared memory, it
If you have dependencies on external libraries, check the dependent items. If your plugin needs to use shared memory, it

Comment thread docs/en/latest/plugin-develop.md Outdated
Parameters can be stored encrypted by specifying `encrypt_fields = {"password"}` in the `schema`. APISIX will provide the following functionality.

- When adding and updating resources via the `Admin API`, APISIX automatically encrypts the parameters declared in `encrypt_fields` and stores them in etcd
- When fetching resources via the `Admin API` and when running the plugin, APISIX automatically decrypts the parameters declared in `encrypt_fields`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

No need to put Admin API in line.

Comment thread docs/en/latest/plugin-develop.md Outdated

::: note
APISIX version is not less than 3.1
:::

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

I think this sentence can be removed since the doc (next) will be released when 3.13 is out. 3.1. is way back in the days already.

If you think this note is still relevant, there is a formatting issue: it should be :::note (without the space); otherwise the admonition will not be rendered properly.

Comment thread docs/en/latest/plugin-develop.md Outdated

How to enable this feature?

Enable `data_encryption` in `config.yaml`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feature is enabled by default now

image

Comment thread docs/en/latest/plugin-develop.md Outdated

Note : if the dependency of some plugin needs to be initialized when Nginx start, you may need to add logic to the initialization
method "http_init" in the file __apisix/init.lua__, and you may need to add some processing on generated part of Nginx
configuration file in __apisix/cli/ngx_tpl.lua__ file. But it is easy to have an impact on the overall situation according to the

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put the paths above in inline code, instead of bolding them?

Comment thread docs/en/latest/plugin-develop.md Outdated
In addition, if the plugin needs to use some metadata, we can define the plugin `metadata_schema`, and then we can dynamically manage these metadata through the `Admin API`. Example:
:::

The input parameter **schema_type** is used to distinguish between different schemas types. For example, many plugins need to use some [metadata](./terminology/plugin-metadata.md), so they define the plugin's `metadata_schema`. Another example, the [key-auth](https://github.com/apache/apisix/blob/master/apisix/plugins/key-auth.lua) plugin needs to provide a `consumer_schema` to check the configuration of the `plugins` attribute of the `consumer` resource in order to be used with the [Consumer](./admin-api.md#consumer) resource.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple issues regarding this rearrangement:

  1. it is easier to read if this info is moved down to its corresponding content:
image
  1. Missing information - consumer_schema was removed in this PR. Why?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the reader, the purpose of this paragraph is simply to indicate that the function can be used to check different schemas, so I removed the excessive content, including consumer_schema. However, consumer_schema might still be worth keeping.
I have reorganized this paragraph.

@kayx23 kayx23 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just this comment and there are a few previous comments that were not addressed. See https://github.com/apache/apisix/pull/12242/files Other changes look good

Comment thread docs/en/latest/plugin-develop.md Outdated
To validate the configuration, the plugin uses a schema like this:
Another example, the [key-auth](https://github.com/apache/apisix/blob/master/apisix/plugins/key-auth.lua) plugin needs to provide a `consumer_schema` to check the configuration of the `plugins` attribute of the `consumer` resource in order to be used with the [Consumer](./admin-api.md#consumer) resource.

```lua

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can put the title like this:

Suggested change
```lua
```lua title="key-auth.lua"

and remove the comment in the code block:

image

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The missing parts have been adddressed.

Except for the stream plugin part(including the descriptions of L4 and L7). Since I can only find related content in the blogs, I thought it's better that the maintainers provide detailed content for this part.

@Baoyuantop
Baoyuantop requested a review from moonming June 9, 2025 02:38
@Baoyuantop
Baoyuantop merged commit cba5ba9 into apache:master Jun 17, 2025
7 checks passed
laz-xyr pushed a commit to laz-xyr/apisix that referenced this pull request Jun 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

doc Documentation things size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants