feat(core): add ExtensibleEnum schema and templated model#1006
Draft
SnowboardTechie wants to merge 1 commit into
Draft
feat(core): add ExtensibleEnum schema and templated model#1006SnowboardTechie wants to merge 1 commit into
SnowboardTechie wants to merge 1 commit into
Conversation
Formalize the extensible enum pattern (value + optional customValue + description) as a reusable Fields.ExtensibleEnum model and Fields.ExtensibleEnumT<T> template, mirroring the CommonBenefits protocol. OppStatus, AppStatus, ApplicantType, FormResponseStatus, and CompetitionStatus are now one-line instantiations of the template. Adds the custom option to FormResponseStatusOptions at v0.4.0 (its docstring already listed it) and drops a stray customValue from the CompetitionStatus example. Emitted schemas are unchanged apart from property description wording; published versions 0.1.0-0.3.0 keep their exact validation shape.
Contributor
|
🚀 Website Preview Deployed! Preview your changes at: https://cg-pr-1006.billy-daly.workers.dev This preview will be automatically deleted when the PR is closed. |
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
ExtensibleEnumschema and templated model #961Changes proposed
Fields.ExtensibleEnumbase model andFields.ExtensibleEnumT<T>template to the core library, formalizing the extensible enum pattern (value+ optionalcustomValue+description) that our status-style fields all repeat by hand.OppStatus,AppStatus,ApplicantType,FormResponseStatus,CompetitionStatus— as one-line instantiations of the template, so the pattern has a single source of truth.customoption toFormResponseStatusOptionsat v0.4.0 — its docstring already listedcustom, but the enum was missing it (the only one of the five that was)./protocol/fields/extensible-enum/, regenerates the committed schema artifacts, and re-pins the TypeSpec line references in the affected model pages.Context for reviewers
Approach matches CommonBenefits (extensible-enum.tsp): an untyped
ExtensibleEnumplus a typedExtensibleEnumT<T>, consumed asmodel AppStatus is Fields.ExtensibleEnumT<AppStatusOptions>;. One deliberate wording difference: CommonBenefits' template property docs say "typed toT", which leaks the template parameter into every emitted consumer schema — I reworded the property docs to be reader-facing instead.Breaking-change review (per the issue's acceptance criteria):
required,$reftargets, types, and enum membership are all byte-identical, except the intendedcustomaddition, which appears only in the 0.4.0 output (the@added(v0_4)gate works — 0.2.0/0.3.0 emit the enum without it).Also fixed in passing: the
Examples.Competition.statusexample setcustomValue: "custom"whilevaluewasopen— the custom value only applies whenvalueiscustom, so it's dropped.Verified with:
pnpm --filter @common-grants/core run checks && build && typespec, full emitted-schema diff against the branch point,pnpm --filter @common-grants/sdk run build && test:coverage, and a full website build (163 pages, links validated).Additional information
Defining a new extensible enum field is now: