refactor: MCD-1297: Derive the schema type of @schemaRef props from the TypeScript type. - #202
Merged
Conversation
…nitions. Canvas resolves a prop's storage from its JSON Schema type before resolving the $ref, so an object definition only matches when the prop declares type: object. A prop typed as a TypeScript interface carries no JSON Schema type, so the type has to be stated. Defaults to string, which is what the Canvas URI refs need.
added 2 commits
August 4, 2026 13:46
…peScript. Canvas resolves a prop's storage from its JSON Schema type before resolving the $ref, so an object definition only matches a prop carrying type: object. The prop's TypeScript declaration already states that, and TypeScript is a hard prerequisite of the whole extraction, so the type is derived from the resolved vue-component-meta schema instead of being restated in JSDoc. Deriving it requires the checker to resolve prop types into structured schemas (schema: true); without that every prop schema is a bare type string and a named interface is indistinguishable from a string. The nested schema members are lazy getters, so the cost is one level per prop, and the generated playground index is unchanged apart from the object-typed $ref prop.
…to feature/mcd-1297-schema-type
Contributor
Author
|
Claude Code: independent review, requested by fago via MCD-1297 ("not sure about this one"). Verdict: merge-ready.
Non-blocking notes:
|
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.
Summary
@schemaRefhard-codedtype: 'string'on the generated prop definition. Canvas resolves a prop's storage from its JSON Schematypebefore it resolves the$ref, so a$refpointing at an object definition never matched — only URI-ish string definitions were reachable. The visible symptom is a media picker silently degrading to a plain string field.The prop's TypeScript declaration already states whether it is an object, and TypeScript is a hard prerequisite of the whole extraction, so the JSON Schema
typeis derived from the resolved type rather than restated in JSDoc:Nothing about existing
@schemaRefprops changes — string-typed props still map totype: string.This unblocks Drupal extensions shipping their own
schema.jsondefinitions — thejson-schema-definitions://<extension>.module/<name>stream wrapper reads aschema.jsonfrom any extension root, not only Canvas. MCD-1297 uses it for a richer image object (media copyright / caption / source / focal point) than Canvas' built-incanvas.module/image.Why the checker needed
schema: truecreateChecker()was constructed without theschemaoption, which disables type resolution entirely — everyprop.schemacame back as a bare type string, so a named interface (LupusCanvasImage) was indistinguishable from a string. Deriving the type is only possible with resolution on.Two things make that cheap and safe:
$refprop (verified by diffing the full generated index both ways). In particular the array-prop handling — which already had a structured-schema branch that had never been reachable — produces exactly the same output.Changes
deriveSchemaRefType()reads the JSON Schema type off the prop's resolved schema:kind: 'object'→object; an optional prop (kind: 'enum'overundefined | T) with an object member →object; otherwise the usual type-string mapping.createChecker(…, { schema: true })so prop types resolve at all.TestSchemaRefFile.richImage, typed as a named interface to mirror real usage.$refprop derivestype: object; a string-typed one derivestype: string.$refparagraph documents derivation.Testing
npm test— 130/130 pass.npm run lint— 0 errors (5 pre-existing warnings in an untouched file). Both re-run after merging1.x(nuxt 4.5.1 / vitest 4).Refs: MCD-1297
Drafted with Claude Code from claude-vm-1.