Repository navigation
Generate content mapper types from json schema - #65565
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The schema is missing from package exports and rejects supported null mappings, preventing intended imports and causing validators to reject valid mapper responses.
2 open issues
2 files not reviewed
tsc/internal/contentmapper/protocol_generated.go: Generated filetsc/internal/spanmap/types_generated.go: Generated file
What changed in this PR
This PR introduces a shared JSON schema for the content mapper protocol, intended for mapper implementers to consume from the TypeScript package. It generates protocol and span-map types from that schema instead of maintaining them separately.
Changes:
- Adds the schema, generator, and generated Go and TypeScript types.
- Replaces raw JSON mappings with typed tuples and adds serialization and validation tests.
- Integrates generation and code-generation checks into Hereby tasks.
| File | Description |
|---|---|
tsc/internal/testutil/contentmappertest/transforming.go |
Returns typed mapping tuples. |
tsc/internal/testutil/contentmappertest/synthesizing.go |
Uses tuples for synthesized output. |
tsc/internal/testutil/contentmappertest/supplemental_diagnostics.go |
Uses typed supplemental mappings. |
tsc/internal/testutil/contentmappertest/protocol.go |
Converts identity mappings to tuples. |
tsc/internal/testutil/contentmappertest/lisp.go |
Uses typed Lisp mappings. |
tsc/internal/testutil/contentmappertest/hoisting.go |
Returns typed hoisting mappings. |
tsc/internal/testutil/contentmappertest/editing.go |
Migrates editing fixtures to tuples. |
tsc/internal/testutil/contentmappertest/duplicate.go |
Migrates duplicate-mapping fixtures to tuples. |
tsc/internal/testutil/contentmappertest/component.go |
Returns typed component mappings. |
tsc/internal/spanmap/types_generated.go |
Adds generated span-map types and constants. |
tsc/internal/spanmap/spanmap.go |
Adds tuple conversion helpers; removes handwritten types. |
tsc/internal/spanmap/spanmap_test.go |
Tests tuple round trips and invalid lengths. |
tsc/internal/contentmapper/protocol_generated.go |
Adds generated protocol types and tuple serialization. |
tsc/internal/contentmapper/hostimpl.go |
Uses generated types and decodes typed mappings. |
tsc/internal/contentmapper/host_test.go |
Tests mapping JSON and malformed tuples. |
tools/scripts/tsc/generate-enums.ts |
Sources span-map enums from the schema. |
tools/scripts/tsc/generate-contentmapper.ts |
Generates protocol and span-map types. |
packages/typescript/src/ast/spanMapTypes.generated.ts |
Adds generated TypeScript span-map types. |
packages/typescript/src/ast/spanMap.ts |
Imports and re-exports generated types. |
packages/typescript/schemas/contentmapper.schema.json |
Defines protocol methods, payloads, and mappings. |
packages/typescript/enums/spanMapKind.js |
Updates the generation-source comment only. |
packages/typescript/enums/spanMapKind.d.ts |
Updates the generation-source comment only. |
packages/typescript/enums/spanMapFidelity.js |
Updates the generation-source comment only. |
packages/typescript/enums/spanMapFidelity.d.ts |
Updates the generation-source comment only. |
packages/typescript/enums/spanMapFeature.js |
Updates the generation-source comment only. |
packages/typescript/enums/spanMapFeature.d.ts |
Uses equivalent numeric literals from the schema. |
Herebyfile.mjs |
Adds content-mapper generation and expands code-generation checks. |
Review effort: Balanced
There was a problem hiding this comment.
🟡 Changes recommended
The new schema is missing from build watch paths, leaving generated bindings and the compiler stale after edits, and codegen tests do not verify the three generated artifacts.
2 open issues
2 resolved since last review
2 files not reviewed
tsc/internal/contentmapper/protocol_generated.go: Generated filetsc/internal/spanmap/types_generated.go: Generated file
Review effort: Balanced
Andrew Branch (andrewbranch)
left a comment
There was a problem hiding this comment.
The way the .Tuples() feature cleans up the test package is really nice too. Thank you!

Similar to what we do for AST, this PR introduces a JSON schema for the content mapper protocol types, and a script for producing Go types from the schema.
Content mapper implementers can then import the schema from our TypeScript package, and generate types/validation for whatever implementation language they're using.