Declare json-schema metadata decorators with auto dec - #11812
Declare json-schema metadata decorators with auto dec#11812Timothee Guerin (timotheeguerin) wants to merge 3 commits into
Conversation
commit: |
|
All changed packages have been documented.
Show changes
|
|
You can try these changes here
|
Load the config file when compiling a library for signature generation and reference docs, so features it opts into (such as auto-decorators) apply.
Use the decorator's own description so libraries re-exporting the accessors satisfy api-extractor.
94e1964 to
317484a
Compare
Every metadata-only decorator in
@typespec/json-schemacarried the same JavaScript boilerplate: astate symbol, a
useStateMappair, and a$decfunction whose entire body was asetcall. Fourteendecorators, ~150 lines of plumbing that says nothing about the language.
auto dec(compiler 1.15, experimental) lets the compiler synthesize that implementation and letstspdgenerate typed accessors from the declaration. This makes@typespec/json-schemathe firststable library to adopt it — a real test of the feature beyond the internal markers in
@typespec/graphql.Affects
@baseUri,@id,@oneOf,@multipleOf,@contains,@minContains,@maxContains,@uniqueItems,@minProperties,@maxProperties,@contentEncoding,@contentMediaType,@contentSchemaand@prefixItems.@jsonSchema,@extensionandPrivate.@validatesRawJsondoreal work and stay as they are.
Not breaking. The library opts itself into the feature through its own
tspconfig.yaml, soconsumers need no configuration. Every previously exported
$decfunction andNameDecoratortypeis kept as a deprecated shim delegating to the generated
set*accessor. Accessors whose historicalsignature was wider than the generated one (
getBaseUri,isOneOf,getContentEncoding, ...) orshaped differently (
getUniqueItemsmust returntrue | undefined, notboolean, or the emitterwould start writing
uniqueItems: falseeverywhere) keep their old signature via a thin wrapper.One intentional behaviour change: applying one of these decorators twice on the same declaration now
reports a
duplicate-decoratorwarning.createDataDecoratornever validated that. Last write stillwins.
Stacked on #11813, which carries the two
tspdfixes this migration needs:loading the library's own
tspconfig.yamlbefore compiling it, and giving generated accessors doccomments so api-extractor accepts them. Those commits drop out of this branch once #11813 merges;
review them there.
The existing json-schema test suite passes unchanged, which is the behaviour contract here.