Repository navigation
Build the OpenAPI generator and rename to wp-openapi-generator - #18
Merged
Merged
Conversation
Generate an OpenAPI 3.1 document from registered REST routes, serve it from a REST endpoint and WP-CLI, and render it with Swagger UI on an optionally public docs page. Adds filters for routes, arguments, schemas, responses, info, servers, and security.
Adds an allow/deny list of wildcard path patterns and a settings page list of operations with incomplete shapes. Drops the WordPress autoloader and wp-type-extensions for Composer PSR-4 with a fallback autoloader, leaving no runtime dependencies.
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Six moderate review issues remain involving namespace selection, hidden operations, repeated generation, and rewrite-rule cleanup.
Review effort: Lite
Findings: 2
Open (2)
What changed in this PR
This PR turns the scaffold into a functional OpenAPI 3.1 WordPress plugin named wp-openapi-generator.
Changes:
- Generates specifications from WordPress REST routes.
- Adds Swagger UI, REST/CLI endpoints, settings, filtering, and audits.
- Updates autoloading, documentation, workflows, and tests.
| File | Description |
|---|---|
wp-swagger-generator.php |
Removes the old plugin entry point. |
wp-openapi-generator.php |
Adds the renamed bootstrap and fallback autoloader. |
uninstall.php |
Removes plugin settings on uninstall. |
tests/Unit/ShapeAuditTest.php |
Tests shape auditing. |
tests/Unit/SettingsTest.php |
Tests settings sanitization. |
tests/Unit/SchemaConverterTest.php |
Tests schema conversion. |
tests/Unit/RoutePathTest.php |
Tests route conversion. |
tests/Unit/PathFilterTest.php |
Tests wildcard path matching. |
tests/Unit/ExampleUnitTest.php |
Removes the scaffold test. |
tests/TestCase.php |
Updates the test base namespace. |
tests/Feature/SpecGeneratorTest.php |
Tests document generation. |
tests/Feature/SpecEndpointTest.php |
Tests REST access and filtering. |
tests/Feature/SettingsPageTest.php |
Tests the settings page. |
tests/Feature/PathFilterTest.php |
Tests configured path filtering. |
tests/Feature/ExampleFeatureTest.php |
Removes the scaffold test. |
tests/Feature/DocsPageTest.php |
Tests documentation routing. |
tests/bootstrap.php |
Loads the renamed plugin. |
templates/docs.php |
Renders the Swagger UI shell. |
src/Spec_Generator.php |
Generates OpenAPI documents. |
src/Shape_Audit.php |
Detects incomplete operation shapes. |
src/Settings.php |
Defines and sanitizes settings. |
src/Schema_Converter.php |
Converts WordPress schemas. |
src/Route_Path.php |
Converts route regexes to paths. |
src/meta.php |
Removes obsolete scaffold functionality. |
src/main.php |
Boots plugin features. |
src/Features/Spec_Endpoint.php |
Serves generated specifications. |
src/Features/Settings_Page.php |
Adds the settings screen. |
src/features/README.md |
Removes obsolete feature documentation. |
src/Features/Path_Filter.php |
Applies configured path filters. |
src/Features/Docs_Page.php |
Provides the Swagger UI page. |
src/Features/CLI_Command.php |
Adds the WP-CLI command. |
src/Feature.php |
Defines the feature interface. |
src/class-swagger-api-documentation-generator.php |
Removes the obsolete scaffold class. |
README.md |
Documents installation and usage. |
phpstan.neon |
Updates static-analysis configuration. |
composer.json |
Renames the package and configures PSR-4 loading. |
CHANGELOG.md |
Documents the initial release. |
.scaffolder/plugin-feature/test.php.hbs |
Updates test scaffolding. |
.scaffolder/plugin-feature/feature.php.hbs |
Updates feature scaffolding. |
.scaffolder/plugin-feature/config.yml |
Updates scaffolding configuration. |
.phpcs.xml |
Updates coding-standard configuration. |
.github/workflows/upgrade-wordpress-plugin.yml |
Updates plugin automation. |
.github/workflows/built-release.yml |
Restores release workflow execution. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
|
||
| foreach ( $server->get_namespaces() as $namespace ) { | ||
| // Skip namespaces whose routes are all excluded, so the menu doesn't offer empty documents. | ||
| $paths = ( new Spec_Generator( $server, [ $namespace ] ) )->generate()['paths'] ?? []; |
| public static function url( array $namespaces = [] ): string { | ||
| $url = rest_url( self::NAMESPACE . self::ROUTE ); | ||
|
|
||
| return $namespaces ? add_query_arg( 'namespace', rawurlencode( implode( ',', $namespaces ) ), $url ) : $url; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Turns the scaffold into a working plugin and renames it to
wp-openapi-generator(namespaceAlley\WP\OpenAPI_Generator, main filewp-openapi-generator.php).It builds an OpenAPI 3.1 document from the routes registered with the REST server: route regexes become path templates, endpoint
argsbecome query parameters or a JSON request body, and route schemas become shared response components. The document is served at/wp-json/openapi/v1/spec, generated withwp openapi generate, and rendered with Swagger UI at/openapi/. The docs are admin-only by default.Settings > OpenAPI can make the docs public, change their path, and limit the documented paths with an allow or deny list of wildcard patterns (
wp/v2/posts/*). It also lists operations with missing request or response shapes. Endpoints can override their operation with anopenapioption, and filters cover routes, arguments, schemas, responses, info, servers, and security. The README has the details.The plugin uses Composer PSR-4 autoloading instead of the WordPress autoloader.
wp-type-extensionsis dropped too, since it depends on that autoloader and requires PHP 8.2. With no runtime dependencies left, the plugin registers its own autoloader whenvendor/is missing, so it runs withoutcomposer install.Also fixes
built-release.yml, whose template guard had been rewritten to this repo's name, so releases never ran. Merging will tag 0.1.0.Verified with
composer test(PHPCS, PHPStan max, 66 PHPUnit tests), Redocly lint of the full core spec (valid), and a manual pass on a WordPress 7.1 site: browsing in Swagger UI, an authenticated create, a media upload, the public, path, and path filter settings, the missing shapes list, and running withoutvendor/.