{"slug":"br-openapi","title":"br-openapi","summary":"Generate or serve better-route 1.1 OpenAPI 3.1 documents from Router/Resource/Woo contracts. Use for OpenApiExporter, OpenApiRouteRegistrar, contracts, contractsFromSources, route args to parameters, explicit parameter overrides, custom responses, OPTIONS 204, strictSchemas, comp","platform":"Claude","tags":[],"authorName":"LLM Mart","authorSlug":"llm-mart","score":0,"source":"github","price":null,"verified":false,"createdAt":"2026-09-16T14:51:39.160232Z","repo":{"url":"https://github.com/Lonsdale201/wp-agent-skills","stars":22,"forks":2,"license":"MIT","updatedAt":"2026-09-21T19:53:59Z"},"bodyHtml":"<hr>\n<h2>name: br-openapi\ndescription: Generate or serve better-route 1.1 OpenAPI 3.1 documents from Router/Resource/Woo contracts. Use for OpenApiExporter, OpenApiRouteRegistrar, contracts, contractsFromSources, route args to parameters, explicit parameter overrides, custom responses, OPTIONS 204, strictSchemas, components, securitySchemes, globalSecurity, publicRoute security, Resource response envelopes, Woo schemas, or openapi.json permissions.\nmetadata:\nwp-skills-author: \"Soczó Kristóf\"\nwp-skills-contact: \"mailto:lonsdale201@hotmail.com\"\nwp-skills-plugin: \"better-route\"\nwp-skills-plugin-version-tested: \"1.1.0\"\nwp-skills-php-min: \"8.1\"\nwp-skills-last-updated: \"2026-07-13\"</h2>\n<h1>better-route: OpenAPI 3.1</h1>\n<p>Export collected contracts directly or publish a protected REST document endpoint.</p>\n<h2>Export</h2>\n<pre><code>use BetterRoute\\BetterRoute;\n\n$contracts = array_merge(\n    $router-&gt;contracts(openApiOnly: true),\n    $resource-&gt;contracts(openApiOnly: true),\n);\n\n$document = BetterRoute::openApiExporter()-&gt;export($contracts, [\n    'title' =&gt; 'My API',\n    'version' =&gt; 'v1.1.0',\n    'serverUrl' =&gt; '/wp-json',\n    'strictSchemas' =&gt; true,\n    'components' =&gt; [\n        'schemas' =&gt; [/* application schemas */],\n    ],\n]);\n</code></pre>\n<p>Contracts exist after route declarations for a Router and after <code>register()</code> for a Resource/Woo registrar result.</p>\n<h2>Publish openapi.json</h2>\n<pre><code>use BetterRoute\\OpenApi\\OpenApiRouteRegistrar;\n\nOpenApiRouteRegistrar::register(\n    restNamespace: 'myapp/v1',\n    contractsProvider: static fn (): array =&gt; OpenApiRouteRegistrar::contractsFromSources([\n        $router,\n        $resource,\n        $woo,\n    ]),\n    options: [\n        'title' =&gt; 'My API',\n        'version' =&gt; 'v1.1.0',\n        // Omit to keep the manage_options default.\n        'permissionCallback' =&gt; static fn (): bool =&gt; current_user_can('view_api_docs'),\n    ],\n);\n</code></pre>\n<p>The registrar mounts <code>GET /wp-json/myapp/v1/openapi.json</code>. Its default permission is <code>current_user_can('manage_options')</code>. Make it public only deliberately:</p>\n<pre><code>'permissionCallback' =&gt; static fn (): bool =&gt; true,\n</code></pre>\n<p>The provider must be callable and return a contract list. <code>contractsFromSources()</code> accepts a mixed list of Router instances, Resource instances, and contract lists and filters each source with <code>openApiOnly: true</code> by default.</p>\n<h2>Route inclusion</h2>\n<p>Exclude a route with the actual metadata shape:</p>\n<pre><code>$router-&gt;get('/internal', $handler)\n    -&gt;permission($adminPermission)\n    -&gt;meta(['openapi' =&gt; ['include' =&gt; false]]);\n</code></pre>\n<p>Then use <code>contracts(true)</code> or the exporter's default <code>includeExcluded: false</code>. The obsolete <code>meta(['openApiOnly' =&gt; false])</code> shape does not control inclusion.</p>\n<h2>1.1 parameter derivation</h2>\n<p>Executable WordPress route <code>args</code> automatically become OpenAPI path/query parameters:</p>\n<pre><code>$router-&gt;get('/articles/(?P&lt;id&gt;\\d+)', $handler)\n    -&gt;publicRoute()\n    -&gt;args([\n        'id' =&gt; ['type' =&gt; 'integer', 'required' =&gt; true],\n        'context' =&gt; ['type' =&gt; 'string', 'enum' =&gt; ['view', 'edit']],\n    ]);\n</code></pre>\n<p>The exporter renders the path as <code>/myapp/v1/articles/{id}</code>, puts <code>id</code> in <code>path</code>, and <code>context</code> in <code>query</code>. It carries supported schema keys such as enum/default/format/items/min/max/length/pattern.</p>\n<p>Explicit <code>meta.parameters</code> entries override a derived entry with the same case-insensitive <code>in</code> + <code>name</code>; derived parameters not overridden remain present. Use explicit metadata for headers/cookies or richer descriptions, not to duplicate every <code>args</code> rule.</p>\n<h2>Responses</h2>\n<p>Defaults are:</p>\n<ul>\n<li>POST: <code>201</code>;</li>\n<li>OPTIONS: <code>204</code> with no JSON body;</li>\n<li>other supported methods: <code>200</code>;</li>\n<li><code>default</code>: <code>ErrorResponse</code>.</li>\n</ul>\n<p>An explicit <code>meta.responses[status]</code> replaces the default at that same status:</p>\n<pre><code>-&gt;meta([\n    'responses' =&gt; [\n        '202' =&gt; ['description' =&gt; 'Accepted'],\n        'default' =&gt; ['$ref' =&gt; '#/components/responses/ErrorResponse'],\n    ],\n])\n</code></pre>\n<p><code>HEAD</code> and <code>204</code> responses are emitted without content.</p>\n<h2>Resource envelope schemas</h2>\n<p>Resource create/update responses are <code>{data: ...}</code> and must reference <code>&lt;Resource&gt;Response</code>. A get references <code>&lt;Resource&gt;</code> unless <code>uniformEnvelope(true)</code> is enabled, in which case it also references <code>&lt;Resource&gt;Response</code>. Lists use <code>&lt;Resource&gt;ListResponse</code>.</p>\n<p>In strict mode provide, as applicable:</p>\n<ul>\n<li><code>&lt;Resource&gt;</code></li>\n<li><code>&lt;Resource&gt;Input</code></li>\n<li><code>&lt;Resource&gt;Response</code></li>\n<li><code>&lt;Resource&gt;ListResponse</code></li>\n<li><code>DeleteResponse</code></li>\n</ul>\n<h2>Security</h2>\n<p>Declare schemes and document defaults explicitly:</p>\n<pre><code>'securitySchemes' =&gt; [\n    'bearerAuth' =&gt; [\n        'type' =&gt; 'http',\n        'scheme' =&gt; 'bearer',\n        'bearerFormat' =&gt; 'JWT',\n    ],\n],\n'globalSecurity' =&gt; [['bearerAuth' =&gt; []]],\n</code></pre>\n<p><code>publicRoute()</code> and explicitly public Resource actions emit operation <code>security: []</code>. <code>protectedByMiddleware('bearerAuth')</code> or a list of security objects sets route metadata. Better Route does not infer a scheme definition from middleware; the component must still be supplied.</p>\n<h2>Components and strict mode</h2>\n<p><code>strictSchemas: true</code> throws when a referenced <code>#/components/schemas/...</code> is absent. Default <code>false</code> inserts a permissive object schema for compatibility. Prefer strict mode for a controlled API contract.</p>\n<p>Merge components recursively so Woo and application schema maps do not overwrite one another:</p>\n<pre><code>'components' =&gt; array_replace_recursive(\n    BetterRoute::wooOpenApiComponents(),\n    $applicationComponents,\n),\n</code></pre>\n<p>Woo 1.1 components match runtime strict payloads: money is string-typed, product input excludes derived <code>price</code>, customer create requires email, coupon create requires code, and nested objects reject unknown properties where runtime does.</p>\n<h2>Review checklist</h2>\n<ul>\n<li>Protect the document endpoint unless public exposure is intentional.</li>\n<li>Use <code>openapi.include</code>, not <code>openApiOnly</code> metadata.</li>\n<li>Derive parameters from <code>args</code>; override rather than duplicate.</li>\n<li>Provide envelope schemas required by Resource runtime responses.</li>\n<li>Replace response codes intentionally and document error defaults.</li>\n<li>Define schemes plus global/per-operation security.</li>\n<li>Run strict export in CI and validate the emitted document with an OpenAPI 3.1 validator.</li>\n</ul>\n<h2>Related skills</h2>\n<ul>\n<li>Use <code>br-routes</code> for args, intent, and route metadata.</li>\n<li>Use <code>br-resource-cpt</code>/<code>br-resource-table</code> for Resource response shapes.</li>\n<li>Use <code>br-woo-routes</code> for Woo runtime contracts.</li>\n</ul>\n<h2>References</h2>\n<ul>\n<li>Verified source paths:\n<ul>\n<li><code>src/OpenApi/OpenApiExporter.php</code></li>\n<li><code>src/OpenApi/OpenApiRouteRegistrar.php</code></li>\n<li><code>src/Router/Router.php</code></li>\n<li><code>src/Resource/Resource.php</code></li>\n<li><code>src/Integration/Woo/WooOpenApiComponents.php</code></li>\n</ul>\n</li>\n</ul>\n","files":[{"path":"SKILL.md","sizeBytes":7039,"isText":true}],"reviewScore":null,"reviewSummary":null,"trust":{"provenance":"trusted-source-unreviewed","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow.","bodySource":null},"bodyLocked":false,"purchaseUrl":null,"sourceUrl":null,"report":{"provenance":"trusted-source-unreviewed","screen":{"ran":true,"outcome":"clean","suspicious":0,"notes":0,"hiddenCharacters":false},"virusScan":{"engine":"clamav","status":"clean","scannedAt":"2026-09-22T13:52:40.256586Z","sha256":"8FA2C92A24191C4A2C59EB3C0014839DF268DF0A884D6B5EDB3645500172AEDE","sizeBytes":2992},"review":null,"source":{"repositoryUrl":"https://github.com/Lonsdale201/wp-agent-skills","path":"better-route/br-openapi","license":"MIT","commit":"8820ff3c301066297e696611e3bc4ebeb47d1851","subtreeSha":"531E1DB7DCF0F175FE595F2429F377CAB68F9FFB9DC64816F1B951F5801EBEB8","lastSyncedAt":"2026-09-22T13:51:11.366991Z"},"reviewedAt":"2026-09-22T13:56:50.111901Z","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow."},"install":[{"target":"skills-cli","command":"npx skills add https://github.com/Lonsdale201/wp-agent-skills/tree/main/better-route/br-openapi"},{"target":"claude-code","command":"claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install lonsdale201-wp-agent-skills@llmmart"},{"target":"git","command":"git clone https://github.com/Lonsdale201/wp-agent-skills.git"}]}