Skip to content

Commit bfc85d9

Browse files
authored
refactor(js): harden native inserter pattern payload shape (#467)
* refactor(js): extract native inserter pattern formatters Pulls the inline pattern/pattern-category serialization in `NativeBlockInserterButton` into named helpers in `src/utils/blocks.js` and flips array fields (`blockTypes`, `categories`, `keywords`) from `?? null` to `?? []` so the JSON shape matches the non-nullable `List<String>` contract in the Kotlin `BlockPattern` model. Emitting `null` for those fields would throw `SerializationException` on the Android side. * test(js): validate native inserter payload against JSON Schema Adds `schemas/block-inserter-payload.schema.json` mirroring the Kotlin `BlockInserterPayload` contract at android/Gutenberg/src/main/java/org/wordpress/gutenberg/model/BlockInserter.kt, plus `src/utils/blocks.test.js` which validates the output of `preprocessBlockTypesForNativeInserter`, `formatPatternsForNativeInserter`, and `formatPatternCategoriesForNativeInserter` against it via `ajv`. The schema is draft-07 with `additionalProperties: false` on every definition, and is co-located at the repo root so it can be consumed by cross-language tooling (`quicktype`, `kotlinx-serialization` codegen) alongside the hand-written Kotlin model. Upstream Gutenberg ships no JSON Schema for these shapes (only JSDoc typedefs on `WPEditorInserterItem` / `WPBlockType`), so the schema is hand-written and tracks the Kotlin model as the source of truth. Catches the null-vs-array drift that motivated #465, plus drift in required fields, types, and unknown-field leaks that Kotlin's `ignoreUnknownKeys = true` would otherwise silently tolerate. Adds `ajv` as a direct devDependency (was transitive).
1 parent d6a5eb8 commit bfc85d9

6 files changed

Lines changed: 653 additions & 107 deletions

File tree

package-lock.json

Lines changed: 60 additions & 85 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
"@wordpress/env": "^11.2.0",
9898
"@wordpress/eslint-plugin": "^24.3.0",
9999
"@wordpress/prettier-config": "^4.43.0",
100+
"ajv": "^8.18.0",
100101
"eslint": "^8.57",
101102
"eslint-import-resolver-typescript": "^4.4.4",
102103
"eslint-plugin-react-refresh": "^0.4.26",

0 commit comments

Comments
 (0)