Repository navigation
docs(website): show v0.6.0 on the model, type and API docs pages - #1428
Draft
SnowboardTechie wants to merge 29 commits into
Draft
SnowboardTechie wants to merge 29 commits into
SnowboardTechie wants to merge 29 commits into
Conversation
### Summary - Fixes #1159 - Time to review: 30 minutes ### Changes proposed Adds [ADR 0032](https://github.com/HHS/simpler-grants-protocol/blob/bryan/1159-adr-0032-version-negotiation/website/src/content/docs/governance/adr/0032-api-version-negotiation.md), which decides how a client asks a CommonGrants API for a protocol version and what the server tells it back: - A client selects a version with an optional `CG-Version` request header. Every response confirms the version served in `CG-Version-Served`, and a client that sends no version gets the server's pinned default. - A server publishes the versions it serves at `GET /common-grants/versions`, as a baseline plus entries for routes that differ. - Version problems get dedicated codes: `version.malformed` and `version.conflict` (400), and `version.unsupported` and `version.retired` (406). - Retirement uses the standard `Deprecation`, `Sunset`, and `Link` headers. A change of default uses `Link` with `rel="successor-version"`, and the date is published in discovery. The ADR is organized as Overview, Evaluation, and Specification, with client and implementer questions in each area. It also covers how a client discovers versions and how a server retires one. It also answers #1372, which is already closed. ### Context for reviewers Implementation is tracked in the [[Core] v0.6.0 release](https://github.com/HHS/simpler-grants-protocol/milestone/5) milestone: headers #1386, discovery #1387, version errors #1388, and the mock API #1393. The specification's versioning section still describes a patch as adding "new optional functionality", which contradicts this ADR. #1389 owns that correction, along with documenting the default-change link. This PR also adds a "Partly superseded" note to [ADR 0028](https://github.com/HHS/simpler-grants-protocol/blob/bryan/1159-adr-0032-version-negotiation/website/src/content/docs/governance/adr/0028-mock-api-hosting.md), since this decision replaces its version path prefix while the rest of 0028 stands. Verified locally: Prettier and cspell pass on the changed files, and the website builds. ### Additional information Rendered page: the website preview link on this PR, at `/governance/adr/0032-api-version-negotiation/`.
Adds GET /common-grants/versions to the 0.6.0 base API, tagged optional, with the VersionDiscovery, OperationVersions, UpcomingDefault and VersionRetirement models and a protocolVersion type. The route lets a server publish its default version, the versions every route serves, per-route exceptions, an upcoming default and deprecated versions, per the API version negotiation ADR draft (#1159, #1372). Versions.v0_6 and Types.protocolVersion are stubs owned by #1386 and are dropped when that PR lands. The 0.1.0 through 0.5.0 OpenAPI documents are unchanged. Refs #1387
Discovery sits outside version selection, so its models tolerate fields they don't know instead of being versioned per document, as the route description promises. The baseline fields now say they describe routes without an operations entry, versions requires at least one entry, and the deprecated map documents its keys. Refs #1387
OkT now spreads the version response headers, so discovery would have advertised CG-Version-Served and Vary. ADR 0032 says discovery carries neither, because clients call it before they know which version to request. The route returns a dedicated VersionDiscoveryResponse instead. Refs #1387
The defaultVersion docs now say a default is one of the listed versions, which the schema can't express. The route description adds the ADR's authentication ceiling and narrows "fields are only ever added" to data, since the response envelope stays closed. The interface comment says adopters don't type-parameterize the response, now that the models accept unknown fields. Refs #1387
Adds the lookup protocol pages will use to show a schema's code without file paths or line numbers. TypeSpec is read with the compiler's own parser; TypeScript with the TypeScript parser; Python with a small scanner that tracks brackets and strings. A name that isn't declared, or is declared more than once, throws.
Each protocol page now names the schema in <SchemaTable schema=...> and <SchemaFormatTabs schema=... typeSpec python typescript>, and the code tabs show the whole declaration found by name. About 100 tabs that were cut off, shifted or showing other code now show the right declaration, and a schema or snippet that can't be found fails the build. The schema-to-page map that links table types to their pages is built from the pages during the site build, so generate-schema-docs.ts goes, along with generate-schema-metadata.ts, generate-type-formatting.ts and SchemaMetadataLoader, whose output nothing read. Closes #872
… fields - The dev server re-reads the TypeSpec, Python and TypeScript sources once per page render, so a source edit shows on reload; a production build still reads them once. - Declarations shown together keep the blank lines the source has between them, so Python classes sit two blank lines apart. - The Python tabs for the pagination and sorting models show their base class (PaginatedBase, SortBase), which holds the inherited fields. - Drop code with no reader: the example file branch, the cache-clearing helper and an export; use the TypeSpec parser's line lookup and one shared recursive file listing.
…-docs # Conflicts: # website/public/openapi/openapi.0.6.0.yaml
Move the specification page to v0.6.0, correct the patch rule, and add the version negotiation rules from ADR 0032, including the successor-version link that announces a change of default. Add the discovery route to the routes tables, v0.6.0 migration notes, and a Versioning page that explains the model with the ADR's examples.
Adds GET /common-grants/versions to the 0.6.0 base API, tagged optional, with the VersionDiscovery, OperationVersions, UpcomingDefault and VersionRetirement models and a protocolVersion type. The route lets a server publish its default version, the versions every route serves, per-route exceptions, an upcoming default and deprecated versions, per the API version negotiation ADR draft (#1159, #1372). Versions.v0_6 and Types.protocolVersion are stubs owned by #1386 and are dropped when that PR lands. The 0.1.0 through 0.5.0 OpenAPI documents are unchanged. Refs #1387
Discovery sits outside version selection, so its models tolerate fields they don't know instead of being versioned per document, as the route description promises. The baseline fields now say they describe routes without an operations entry, versions requires at least one entry, and the deprecated map documents its keys. Refs #1387
OkT now spreads the version response headers, so discovery would have advertised CG-Version-Served and Vary. ADR 0032 says discovery carries neither, because clients call it before they know which version to request. The route returns a dedicated VersionDiscoveryResponse instead. Refs #1387
The defaultVersion docs now say a default is one of the listed versions, which the schema can't express. The route description adds the ADR's authentication ceiling and narrows "fields are only ever added" to data, since the response envelope stays closed. The interface comment says adopters don't type-parameterize the response, now that the models accept unknown fields. Refs #1387
Validate each key of `deprecated` against the protocol version format in the JSON Schema files, and say that an upcoming default is one of `versions`, as ADR 0032 requires of every default.
A key is written exactly as its version appears in `versions`. Matching on major and minor is how a client finds the entry for the version it requested, so say that separately, with an example.
…nto bryan/1389-versioning-docs # Conflicts: # lib/core/lib/core/models/version-discovery.tsp # website/public/openapi/openapi.0.6.0.yaml # website/public/schemas/yaml/OperationVersions.yaml # website/public/schemas/yaml/VersionDiscovery.yaml
… and send CG-Version The API docs dropdown now lists every emitted openapi.X.Y.Z.yaml, newest first, and opens on the newest (v0.6.0). Try it out sends the selected version as the CG-Version header on mock API requests, unless a value was typed into the header field.
…nd discovery response Adds protocolVersion to the string types, VersionDiscoveryResponse to the success responses, a version headers note on the success, paginated, sorted and filtered pages, and updates the common error types to the 0.6.0 aliases with the version errors and WithVersionErrors. Fixes the error and filtered usage examples so they compile.
…sioning-docs # Conflicts: # website/src/content/docs/governance/adr/0028-mock-api-hosting.md
… bryan/1391-v06-docs-pages # Conflicts: # website/src/pages/protocol/api-docs.astro # website/src/scripts/inject-mock-server.ts
Contributor
|
🚀 Website Preview Deployed! Preview your changes at: https://pr-1428-common-grants.agile6.workers.dev Built from commit 158ea71 |
3 tasks
This branch has not been deployed
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
Changes proposed
The protocol docs now cover the 0.6.0 core library, and the API docs page offers v0.6.0 as its default and sends the selected version as
CG-Versionfrom "Try it out".api-docs.astrolists everypublic/openapi/openapi.X.Y.Z.yamlthe build emits, newest first, with the newest labelled "(Latest)" and selected by default. It no longer needs a hand edit per release, and the build fails if no document is found. Today that is v0.6.0 (Latest) down to v0.1.0. The filename parsing moved frominject-mock-server.tstowebsite/src/lib/openapi-versions.tsso both use one regex.CG-Version. A SwaggerrequestInterceptorsets the header to the selected version on calls to the mock, unless the user typed a value. It uses thewithVersionHeaderhelper that feat(website): move the mock API to the CG-Version header #1415 (the mock API's move to theCG-Versionheader) added to the hold branch, so the mock answers in the version picked in the dropdown.protocolVersionon the string types page, andVersionDiscoveryResponseon the success responses page, each with a card on its index page.CG-Version-Served,Vary,Deprecation,SunsetandLinkfrom v0.6.0, and link the Versioning page and the specification.BadRequest(which declares its version header inline), the four version error aliases andWithVersionErrors<R>, copied fromlib/core.Usageexamples compile again. The error page's example usedTestModelwithout declaring it, and the filtered page's usedFilters.*withoutusing CommonGrants;.Every other model and type table and code tab already follows 0.6.0, because #1420 generates them from the sources by schema name.
Context for reviewers
This PR's own changes are two commits. The rest of the diff comes from the PRs it builds on and drops out as they land:
CORE-v0.6.0), which carries docs(website): show the whole declaration in protocol docs code tabs #1420 (protocol pages find their code by schema name, intomain). The new sections use docs(website): show the whole declaration in protocol docs code tabs #1420's components and link docs(website): document version negotiation for v0.6.0 #1423's Versioning page.CORE-v0.6.0, through docs(website): document version negotiation for v0.6.0 #1423's branch.This comparison shows only this PR's changes. It stays a draft until #1423 has merged.
Things worth a look:
withVersionHeaderinto the page. This PR keeps its imports (MOCK_SERVER_URL,VERSION_HEADER) and interceptor, and replaces its hand-typed list with the generated one.CompetitionBase,FormBaseand the 35 schemas they reference are identical in the 0.5.0 and 0.6.0 OpenAPI documents.CORE-v0.6.0reachesmain.Verified on the current head: build with link validation, eslint, Prettier,
tsc,astro check, cspell (1,502 files) and 1,346 tests pass. In a browser againstastro preview, the dropdown opens on v0.6.0. ExecutingGET /common-grants/opportunitieson v0.4.0 sendsCG-Version: 0.4.0and the mock answers withCG-Version-Served: 0.4.0. On v0.6.0, a value typed into theCG-Versionfield (0.5.0) is sent instead, and served.Additional information
Pages to check in this PR's website preview, once it deploys:
/protocol/api-docs/: the dropdown, and "Try it out" with the request'sCG-Version/protocol/types/string/#protocolversion/protocol/responses/success/#versiondiscoveryresponse/protocol/responses/error/#common-error-typesFrom the local browser run, the v0.4.0 "Try it out" request:
Response headers include
cg-version-served: 0.4.0andvary: CG-Version.