Repository navigation
feat(codegen): a WordPress API from the site's own index, and permission keys from a field's value - #647
Merged
Conversation
…ion keys from a field's value WordPress has no OpenAPI, but /wp-json/?context=help lists every route with its arguments and the schema of its answer, the same one OPTIONS returns. syncWpJson keeps that one answer without the site's name, address and links; wpJsonToOpenApi turns a namespace's routes into OpenAPI 3.1 for adaptOpenApi: 152 operations from WordPress 6.9.4's wp/v2, ids from the method and path. A route whose value may hold a slash, and every namespace not offered, is left out and listed; an array in the query travels comma-separated, as PHP keeps only the last of a repeated name (checked on WordPress 6.9.4). permissions.valueKeys gives <group>.<key> to a write or delete whose field lists one of the values in its enum, through a reference or a union: status publish or future needs posts.publish, so a profile that denies publishing also stops the raw api group (RISK-2323). Where the field defaults to such a value (templates, template parts, menu items), the key applies on every call. A read that filters by the value gets none. OperationPermission.values carries it; cli-core checks it in the body and the query. sha256 and sortKeys move to snapshot.ts: discovery and graphql had a copy each. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Merged
leemour
added a commit
that referenced
this pull request
Nov 18, 2026
Carries #647 (`wpJsonToOpenApi`, `permissions.valueKeys`), the only change since 0.117.0. Minor: the Unreleased section has Added. cli-core's check of the new `values` waits on this version. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.
Task
C3 of the content category, cli-base half: read a WordPress site's API from its own index, and give a publishing write a permission key, so the WordPress CLI's raw
apigroup cannot publish past a profile that denies it.Why
WordPress publishes no OpenAPI. And a key that only checks "is this flag true" cannot say "
statusispublish": an agent could publish with a plainPOST /wp/v2/posts, whateverposts.publishsays (RISK-2323 in the content-category plan).What
syncWpJson/readWpJson/wpJsonToOpenApi. One call,GET /wp-json/?context=help, returns every route with its arguments and its answer's schema. I checked on WordPress 6.9.4 that this schema equals whatOPTIONSreturns, for all 78 routes callable directly. So the snapshot is one file, not oneOPTIONScall per route as the plan said.adaptOpenApireads it. WordPress 6.9.4'swp/v2gives 152 operations (getWpV2Posts,postWpV2PostsById…), and the generated types, schemas and manifest compile.forcein the query. POST/PUT/PATCH becomes one POST write.include=1,5returns both posts, whileinclude=1&include=5returns only the last.excludenames it.permissions.valueKeys.{ key: "publish", field: "status", values: ["publish", "future"] }gives<group>.publishto a write whosestatusenum lists those values, through refs and unions too. On WordPress 6.9.4 that covers posts, pages, media, blocks, navigation and menu items.statusout publishes.status), get no key.OperationPermission.valuescarries it, and the coverage page says "statusis publish or future".overrides. As a rule besidedeletingFlags, one entry covers every post type.sha256andsortKeysmove tosnapshot.ts. Discovery and GraphQL each had a copy.Not here: cli-core's runtime check of
values(next PR, on this release);wp-jsonas a configspec.kindin cli-template (the WordPress pilot); paging: WordPress pages by headers, sopagination: truefinds none yet. Basic sign-in infakeApiwas already in 0.117.0 (#643); a test here runs the generated WordPress manifest through it.Testing
src/codegen/wp-json.test.tsruns on an excerpt of WordPress 6.9.4's real index. The excerpt is intest/fixtures/wp-json/, with GPL notice. The tests cover:requiredin both spellings,bool, untyped objects,patternProperties;fakeApiwith an application password;statustopublish. It's fixed with the rest of that review's findings._method/X-HTTP-Method-Overridecan't be sent, because cli-core'sapigroup only takes declared parameters.🤖 Generated with Claude Code