Skip to content

Build the OpenAPI generator and rename to wp-openapi-generator - #18

Merged
srtfisher merged 3 commits into
developfrom
openapi-generator
Oct 7, 2026
Merged

srtfisher merged 3 commits into
developfrom
openapi-generator

Conversation

@srtfisher

@srtfisher srtfisher commented Oct 6, 2026 •

Copy link
Copy Markdown
Member

Turns the scaffold into a working plugin and renames it to wp-openapi-generator (namespace Alley\WP\OpenAPI_Generator, main file wp-openapi-generator.php).

It builds an OpenAPI 3.1 document from the routes registered with the REST server: route regexes become path templates, endpoint args become 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 with wp 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 an openapi option, 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-extensions is dropped too, since it depends on that autoloader and requires PHP 8.2. With no runtime dependencies left, the plugin registers its own autoloader when vendor/ is missing, so it runs without composer 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 without vendor/.

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 Medium severity

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.

Comment thread src/Features/Docs_Page.php Outdated

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;
@srtfisher
srtfisher merged commit f8e0b52 into develop Oct 7, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants