feat: MCD-1297: Add @schemaType so @schemaRef can point at object definitions. - #202
Open
drubot wants to merge 2 commits into
Open
feat: MCD-1297: Add @schemaType so @schemaRef can point at object definitions.#202drubot wants to merge 2 commits into
drubot wants to merge 2 commits into
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.
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.A prop typed as a TypeScript interface carries no JSON Schema type of its own (
mapVueTypeToJsonSchemafalls through tostring), so the type has to be stated explicitly. This adds a@schemaTypeJSDoc tag:It defaults to
string, so every existing@schemaRefprop is unchanged.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.Changes
@schemaTypetag detection, validated against the JSON Schema primitive types; an unknown value warns and falls back.TestSchemaRefFile.richImage) exercising an object$ref.$refhonours@schemaType;@schemaRefwithout the tag still yieldstype: string.Testing
npm run lintclean (5 pre-existing warnings in an untouched file).npm test— 130/130 pass, including the 2 new cases.Refs: MCD-1297
Drafted with Claude Code from claude-vm-1.