feat: Add opt-in JSON-LD schema support - #1375
Open
dev-geddy wants to merge 1 commit into
Open
Conversation
🦋 Changeset detectedLatest commit: aa0de6a The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This comment was marked as outdated.
This comment was marked as outdated.
dev-geddy
force-pushed
the
feat/add-jsonld-schema-support
branch
from
September 3, 2025 20:04
6de32e5 to
2c0e0b7
Compare
This comment was marked as outdated.
This comment was marked as outdated.
Collaborator
|
@codex review |
Author
|
@codex fix comments |
This comment was marked as off-topic.
This comment was marked as off-topic.
dev-geddy
force-pushed
the
feat/add-jsonld-schema-support
branch
from
September 24, 2025 21:50
314f0e3 to
045fe31
Compare
Collaborator
|
@codex review |
Collaborator
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting
dev-geddy
force-pushed
the
feat/add-jsonld-schema-support
branch
from
October 14, 2025 18:57
f3d7d0d to
a8db0f0
Compare
dev-geddy
force-pushed
the
feat/add-jsonld-schema-support
branch
from
July 29, 2026 12:57
a8db0f0 to
da101f1
Compare
Schemas that declare the `x-jsonld` extension (or one of `x-jsonld-context`, `x-jsonld-type`, `x-jsonld-id`) are parsed as JSON-LD when the new `jsonLdOptions.enabled` option is set (CLI: `--jsonld`). Entities get typed `@context`, `@type` and `@id` members and extend a shared `JsonLdEntity` interface. A property-less `x-jsonld-type` schema becomes a string-literal type alias and stays in `data-contracts` alongside the other aliases. In modular output entities are emitted as `jsonld-entity` and the shared interfaces as `jsonld-utils`, both re-exported from `data-contracts` so route modules keep importing their models from a single place. Setting `jsonLdOptions.generateUtils` to `false` emits standalone entity interfaces instead. Detection is explicit — no auto-discovery from `@context`/`@type`/`@id` property names — and the input document is never mutated, so specs without the extension and runs without `--jsonld` produce unchanged output. Tests cover single-file and modular output, the disabled default, the `generateUtils` opt-out, mixed JSON-LD/plain specs, and the type-alias path. Generated output for all three modes type-checks under `--strict`.
dev-geddy
force-pushed
the
feat/add-jsonld-schema-support
branch
from
July 29, 2026 14:56
da101f1 to
aa0de6a
Compare
|
To use Codex here, create a Codex account and connect to github. |
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.
Adds optional JSON-LD support. Off by default, no effect on existing specs.
--jsonld(orjsonLdOptions.enabled)x-jsonldextension@context,@type,@idand extend a sharedJsonLdEntityx-jsonld-typeschema with no properties becomes a string union aliasjsonld-entityandjsonld-utils, re-exported fromdata-contractsgenerateUtils: falseemits plain interfaces with no shared moduleProblem
If your API returns JSON-LD, the generated types don't mean much.
@contextbecomesobject, nothing connects the JSON-LD fields across entities, and there are no shared types for things like@graphor node references:So you end up writing those types by hand next to the generated file.
Solution
Two things must both be true for anything to change: the schema declares
x-jsonld(orx-jsonld-context/x-jsonld-type/x-jsonld-id), and you pass--jsonld. Otherwise output is identical to before.Under the hood this adds two schema types,
jsonld-entityandjsonld-type, asMonoSchemaParsersubclasses dispatched fromgetInternalSchemaType— the same wayenum,objectandarrayalready work. No new pipeline stage.An entity now looks like:
And a type-only schema becomes an alias, staying in
data-contractswith the other aliases:A few choices worth flagging:
@context/@type/@idproperty names, since those are valid property names in a normal spec and it would change output for people who never asked for it.data-contractsre-exports them. Route modules import models fromdata-contractsonly, so without the re-export their imports would break.@contextusesJsonLdContextrather than a structural type.objector(string | object)[]isn't assignable toJsonLdEntity["@context"], so the generated file wouldn't compile. Literal string contexts keep their literal type.Verification
bun run build,bun run format:checkandbun run testpass — 293 tests, no type errors.tests/spec/jsonld-basic/covers single-file output, the disabled default, modular output (including that route module imports still resolve), thegenerateUtils: falsepath, a mixed JSON-LD/plain spec, and the type alias case.I also compiled the real generated output rather than only snapshotting it: for all three modes the emitted files pass
tsc --noEmit --strictwith the generated// @ts-nocheckheader removed, so the check isn't suppressed.Notes
Rebased onto current
mainand squashed to one commit. The rebase surfaced that the project had moved toes-toolkit, which this now uses.An earlier version had a
generateContextoption with its own parser and template. They're gone: nothing could produce ajsonld-contextschema type, so the option did nothing and the code was unreachable. Happy to build a real context output if that's wanted, but it should be deliberate rather than dead code.