Commit bfc85d9
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
- schemas
- src
- components/native-inserter
- utils
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
| 100 | + | |
100 | 101 | | |
101 | 102 | | |
102 | 103 | | |
| |||
0 commit comments