Skip to content

alleyinteractive/wp-swagger-generator

Swagger API Documentation Generator

Contributors: alleyinteractive

Tags: alleyinteractive, wp-swagger-generator

Stable tag: 0.0.0

Requires at least: 6.3

Tested up to: 6.7

Requires PHP: 8.1

License: GPL v2 or later

Testing Suite

Plugin/package to generate Swagger documentation for the WordPress REST API..

Installation

You can install the package via Composer:

composer require alleyinteractive/wp-swagger-generator

Usage

Activate the plugin in WordPress and use it like so:

$plugin = Create_WordPress_Plugin\Swagger_API_Documentation_Generator\Swagger_API_Documentation_Generator();
$plugin->perform_magic();

Testing

Run npm run test to run Jest tests against JavaScript files. Run npm run test:watch to keep the test runner open and watching for changes.

Run npm run lint to run ESLint against all JavaScript files. Linting will also happen when running development or production builds.

Run composer test to run tests against PHPUnit and the PHP code in the plugin. Unit testing code is written in PSR-4 format and can be found in the tests directory.

The entries directory and entry points

All directories created in the entries directory can serve as entry points and will be compiled with @wordpress/scripts into the build directory with an accompanied index.asset.php asset map.

Scaffolding an entry point

To generate a new entry point, run the following command:

npm run create-entry

To generate a new slotfill, run the following command:

npm run create-slotfill

The command will prompt the user through several options for creating an entry or slotfill. The entries are scaffolded with the @alleyinteractive/create-entry script. Run the help command to see all the options:

npx @alleyinteractive/create-entry --help

Visit the package README for more information.

Enqueuing Entry Points

You can also include an index.php file in the entry point directory for enqueueing or registering a script. This file will then be moved to the build directory and will be auto-loaded with the load_scripts() function in the functions.php file. Alternatively, if a script is to be enqueued elsewhere there are helper functions in the src/assets.php file for getting the assets.

Scaffold a dynamic block with create-block

Use the create-block command to create custom blocks with @alleyinteractive/create-block script and follow the prompts to generate all the block assets in the blocks/ directory. Block registration, script creation, etc will be scaffolded from the create-block script. Run npm run build to compile and build the custom block. Blocks are enqueued using the load_scripts() function in src/assets.php.

Updating WP Dependencies

Update the WordPress dependency packages used in the project to their latest version.

To update @wordpress dependencies to their latest version use the packages-update command:

npx wp-scripts packages-update

This script provides the following custom options:

  • --dist-tag – allows specifying a custom dist-tag when updating npm packages. Defaults to latest. This is especially useful when using @wordpress/dependency-extraction-webpack-plugin. It lets installing the npm dependencies at versions used by the given WordPress major version for local testing, etc. Example:
npx wp-scripts packages-update --dist-tag=wp-WPVERSION`

Where WPVERSION is the version of WordPress you are targeting. The version must include both the major and minor version (e.g., 6.7). For example:

npx wp-scripts packages-update --dist-tag=wp-6.7`

Releasing the Plugin

The plugin uses a built release workflow to compile and tag releases. Whenever a new version is detected in the root composer.json file or in the plugin's headers, the workflow will automatically build the plugin and tag it with a new version. The built tag will contain all the required front-end assets the plugin may require. This works well for publishing to WordPress.org or for submodule-ing.

When you are ready to release a new version of the plugin, you can run npm run release to start the process of setting up a new release.

Changelog

Please see CHANGELOG for more information on what has changed recently.

Credits

This project is actively maintained by Alley Interactive. Like what you see? Come work with us.

License

The GNU General Public License (GPL) license. Please see License File for more information.

About

Generate Swagger API documentation from the WordPress REST API

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published