Skip to content

schemas: add tags_schema.json and wire tags into the schema test#1194

Open
VasilisDragon wants to merge 1 commit into
PrismarineJS:masterfrom
VasilisDragon:vasilis-tags-schema
Open

schemas: add tags_schema.json and wire tags into the schema test#1194
VasilisDragon wants to merge 1 commit into
PrismarineJS:masterfrom
VasilisDragon:vasilis-tags-schema

Conversation

@VasilisDragon

Copy link
Copy Markdown

Summary

#1080 has been waiting on one review ask (@rom1504: "We would need a schema for the tags file"). This adds that schema and registers tags in tools/js/test/test.js so the file is validated by CI wherever a tags.json exists. No data files change here: with no tags.json in the tree yet, the new test entry is inert (fs.existsSync guard), so this merges independently of #1080 and starts guarding it the moment it lands.

The schema is derived from the generated data rather than written ahead of it — every constraint below was checked against data/pc/1.21.8/tags.json at #1080's head (4edb806). That ordering follows the review note on #464 ("generate the data … you will need to adapt the schema once you have the data"); #1080 now provides the data half, this is the schema half.

Shape

Registry kind → namespaced tag → flattened member list. Modeled on blockMappings_schema.json (draft-07, $defs, additionalProperties: false).

  • block and item are required; fluid, entity_type, and any future registry the generator emits are accepted with the same tag-map shape, so a new registry kind is not a schema-breaking change. Registry keys themselves must match ^[a-z_/]+$ — this admits path-shaped kinds the game actually has tags for (game_event, worldgen/biome, worldgen/structure) while rejecting malformed keys.
  • Tag keys and members must match the ResourceLocation grammar (^[a-z0-9_.-]+:[a-z0-9_./-]+$). 0 of 414 tags / 5,421 members in the Add Minecraft pc 1.21.8 tags #1080 data violate it. The pattern is not pinned to minecraft: so datapack/mod namespaces remain representable.
  • Members must be concrete entries, never #tag references — the generator flattens nested tags (0 # members in the real data), and consumers should never see one. An unflattened emission becomes a CI failure instead of a silent regression downstream.
  • uniqueItems on member lists (0 duplicates in the real data; catches double-emits).
  • Empty member lists are deliberately valid: vanilla ships empty tags — on 1.21.8 both minecraft:incorrect_for_diamond_tool and minecraft:incorrect_for_netherite_tool are empty. A min-1 constraint (as drafted in Tag schemas #464) would reject the real file.

Verification

  • The unmodified Add Minecraft pc 1.21.8 tags #1080 tags.json validates with the repo's Ajv setup (new Ajv({ verbose: true }), same as test.js).
  • 22-case battery against the same setup — real file, future registries (game_event, worldgen/biome), modded namespaces, and empty-array cases pass; root-as-array, missing registry, non-array tag value, non-string member, malformed tag key, #tag member, duplicate members, malformed/miscased registry keys, null/array registry values, and empty-string members are all rejected.
  • Cross-referential integrity: all 5,417 block/item/entity_type members in the Add Minecraft pc 1.21.8 tags #1080 file exist in the same head's blocks.json / items.json / entities.json — 0 dangling references. (fluid's 4 members have no data file to check against.)
  • Full tools/js suite: 1762 passing / 1 pending before and after this change — no behavior change while no tags.json exists.
  • Merged-state simulation: with Add Minecraft pc 1.21.8 tags #1080's tags.json + dataPaths entry applied locally, the suite goes to 1763 passing / 1 pending — the +1 is pc 1.21.8: tags.json is valid — and audit dataPaths stays green both directions. Corrupting one member to #minecraft:planks flips exactly that one test red (should match pattern "^[a-z0-9_.-]+:[a-z0-9_./-]+$").
  • json-schema-to-typescript (which node-minecraft-data generates its typings from, walking schemas/) compiles this schema to a usable Tags interface.

On the second question in #1080 ("are we adding it only for 1.21.8?"): the schema is version-agnostic — coverage can grow as PrismarineJS/minecraft-data-generator#56 stabilizes on older versions (extremeheat noted pre-1.20.5 versions lack Mojang mappings there). Versions without a tags.json are not validated against it.

I left README's "Data provided" row and the doc/add-data-new-version.md entry for when the data itself lands (#1080 / the generator work) rather than advertise tags the repo doesn't provide yet.

Context: #463 (2021) proposed a tags schema and #464 closed waiting on generated data to derive one from. With #1080 staged, this is the remaining half of that sequence, and the data-side prerequisite for exposing mcData.tags in node-minecraft-data (#412 discussion).

rom1504 asked for a schema for the tags file on PrismarineJS#1080; this adds it,
derived from that PR's generated data (head 4edb806) rather than
written ahead of it, per the review direction on PrismarineJS#464.

Shape: registry kind -> namespaced tag -> flattened member list.
block/item required; fluid, entity_type, and future registries accepted
with the same shape, with registry keys constrained to ^[a-z_/]+$ so
path-shaped kinds (game_event, worldgen/biome) stay valid while
malformed keys fail. Tag keys and members must match the
ResourceLocation grammar (0 of 414 tags / 5421 members violate it),
members must not be unflattened #tag references (0 in the data; a
regression becomes a CI failure), uniqueItems on members (0
duplicates), and empty member lists stay valid because vanilla ships
empty tags (incorrect_for_diamond_tool, incorrect_for_netherite_tool
on 1.21.8). All 5417 block/item/entity_type members cross-resolve
against the same head's blocks/items/entities files.

Registering tags in test.js is inert while no tags.json exists
(existsSync guard): full tools/js suite is 1762 passing / 1 pending
both before and after this change. With PrismarineJS#1080's files applied locally,
pc 1.21.8 tags.json validates (1763 passing) and audit dataPaths stays
green.
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.

1 participant