From 84b9be904f17a26bf74db7cdd7bc0cf35ef468a7 Mon Sep 17 00:00:00 2001 From: Bryan Thompson Date: Thu, 19 Nov 2026 12:44:56 -0800 Subject: [PATCH 1/3] feat(website): find TypeSpec, Python and TypeScript declarations by name 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. --- .../__tests__/lib/schema/schema-files.spec.ts | 26 + .../lib/schema/source-declarations.spec.ts | 530 +++++++++++++++++ website/src/lib/schema/paths.ts | 33 +- website/src/lib/schema/schema-files.ts | 28 + .../src/lib/schema/schema-metadata-loader.ts | 114 ---- website/src/lib/schema/source-declarations.ts | 538 ++++++++++++++++++ website/src/scripts/generate-schema-docs.ts | 164 ------ .../src/scripts/generate-schema-metadata.ts | 184 ------ .../src/scripts/generate-type-formatting.ts | 164 ------ 9 files changed, 1140 insertions(+), 641 deletions(-) create mode 100644 website/__tests__/lib/schema/schema-files.spec.ts create mode 100644 website/__tests__/lib/schema/source-declarations.spec.ts create mode 100644 website/src/lib/schema/schema-files.ts delete mode 100644 website/src/lib/schema/schema-metadata-loader.ts create mode 100644 website/src/lib/schema/source-declarations.ts delete mode 100644 website/src/scripts/generate-schema-docs.ts delete mode 100644 website/src/scripts/generate-schema-metadata.ts delete mode 100644 website/src/scripts/generate-type-formatting.ts diff --git a/website/__tests__/lib/schema/schema-files.spec.ts b/website/__tests__/lib/schema/schema-files.spec.ts new file mode 100644 index 000000000..179ca41f1 --- /dev/null +++ b/website/__tests__/lib/schema/schema-files.spec.ts @@ -0,0 +1,26 @@ +import { describe, it, expect } from "vitest"; +import { schemaFilePath } from "@/lib/schema/schema-files"; + +// Reads the generated schemas — run `pnpm --filter website run build` first. +describe("schemaFilePath", () => { + it("gives the generated JSON Schema file for a schema", () => { + expect(schemaFilePath("AwardBase")).toBe( + "website/public/schemas/yaml/AwardBase.yaml", + ); + }); + + it("gives a version's copy when asked for one", () => { + expect(schemaFilePath("CompetitionBase", "v0.5.0")).toBe( + "website/public/schemas/yaml/versions/v0.5.0/CompetitionBase.yaml", + ); + }); + + it("fails for a schema that has no JSON Schema file", () => { + expect(() => schemaFilePath("NoSuchSchema")).toThrow( + /No JSON Schema for "NoSuchSchema"/, + ); + expect(() => schemaFilePath("AwardBase", "v0.1.0")).toThrow( + /No JSON Schema for "AwardBase" in v0.1.0/, + ); + }); +}); diff --git a/website/__tests__/lib/schema/source-declarations.spec.ts b/website/__tests__/lib/schema/source-declarations.spec.ts new file mode 100644 index 000000000..8e645a6c6 --- /dev/null +++ b/website/__tests__/lib/schema/source-declarations.spec.ts @@ -0,0 +1,530 @@ +import { describe, it, expect } from "vitest"; +import { + listTypeSpecDeclarations, + listPythonDeclarations, + listTypeScriptDeclarations, + findDeclaration, + findSchemaDeclaration, + findSnippet, + sourceUrl, + type Declaration, +} from "@/lib/schema/source-declarations"; + +/** Picks one declaration out of a listing by name. */ +function pick(declarations: Declaration[], name: string): Declaration { + const matches = declarations.filter((d) => d.name === name); + expect(matches, `exactly one declaration named ${name}`).toHaveLength(1); + return matches[0]; +} + +// ############################################################################ +// TypeSpec +// ############################################################################ + +describe("listTypeSpecDeclarations", () => { + it("includes the doc comment and decorators above a model", () => { + const source = [ + "namespace CommonGrants.Fields;", + "", + "// A section banner that belongs to no declaration", + "/** A monetary amount */", + '@example(Examples.Money.usd, #{ title: "US dollars" })', + "@example(", + " Examples.Money.euro,", + ' #{ title: "Euros" }', + ")", + "@Versioning.added(CommonGrants.Versions.v0_1)", + "model Money {", + " /** The amount */", + " amount: decimalString;", + "}", + "", + ].join("\n"); + + const money = pick(listTypeSpecDeclarations(source), "Money"); + expect(money.startLine).toBe(4); + expect(money.endLine).toBe(14); + expect(money.code.split("\n")[0]).toBe("/** A monetary amount */"); + expect(money.code.endsWith("}")).toBe(true); + }); + + it("finds the whole of a model with nested braces", () => { + const source = [ + "model OrgRelationshipT {", + " kind?: {", + " ...Fields.ExtensibleEnumT;", + " };", + "", + " allIds?: Array<{", + " id: string;", + " }>;", + "}", + "", + "model After {}", + ].join("\n"); + + const declaration = pick( + listTypeSpecDeclarations(source), + "OrgRelationshipT", + ); + expect(declaration.startLine).toBe(1); + expect(declaration.endLine).toBe(9); + }); + + it("finds one-line declarations, scalars and aliases", () => { + const source = [ + "/** An email address */", + '@format("email")', + "scalar email extends string;", + "", + "/** An email address. */", + "alias Email = Types.email; // Exposes Email from CommonGrants.Fields", + "", + "/** The status */", + "model AwdStatus is Fields.ExtensibleEnumT;", + ].join("\n"); + + const declarations = listTypeSpecDeclarations(source); + expect(pick(declarations, "email")).toMatchObject({ + startLine: 1, + endLine: 3, + }); + // The trailing comment on the declaration's last line is kept. + expect(pick(declarations, "Email").code).toBe( + [ + "/** An email address. */", + "alias Email = Types.email; // Exposes Email from CommonGrants.Fields", + ].join("\n"), + ); + expect(pick(declarations, "AwdStatus")).toMatchObject({ + startLine: 8, + endLine: 9, + }); + }); + + it("finds declarations inside a namespace block, keeping their indentation", () => { + const source = [ + "namespace CommonGrants.Patch {", + " model OrgProfileWritable {}", + "}", + "", + "namespace CommonGrants.Models {", + " /** A merge patch. */", + " @Versioning.added(CommonGrants.Versions.v0_4)", + " model OrgPatchData is TypeSpec.Http.MergePatchUpdate<", + " CommonGrants.Patch.OrgProfileWritable,", + ' "OrgPatch{name}"', + " >;", + "", + " /** Examples of the OrgPatchData model */", + " namespace Examples.OrgPatchData {", + ' const patch = #{ name: "x" };', + " }", + "}", + ].join("\n"); + + const declarations = listTypeSpecDeclarations(source); + const patch = pick(declarations, "OrgPatchData"); + expect(patch.startLine).toBe(6); + expect(patch.endLine).toBe(11); + expect(patch.code.split("\n")[0]).toBe(" /** A merge patch. */"); + // Namespaces and consts are not declarations a page can name. + expect(declarations.map((d) => d.name)).not.toContain("patch"); + expect(declarations.map((d) => d.name)).toEqual([ + "OrgProfileWritable", + "OrgPatchData", + ]); + // Each declaration records the namespace it's declared in. + expect(pick(declarations, "OrgProfileWritable").namespace).toBe( + "CommonGrants.Patch", + ); + expect(patch.namespace).toBe("CommonGrants.Models"); + }); + + it("records the namespace a file-level namespace statement sets", () => { + const source = [ + "namespace CommonGrants.Fields;", + "", + "model Money {}", + ].join("\n"); + expect(pick(listTypeSpecDeclarations(source), "Money").namespace).toBe( + "CommonGrants.Fields", + ); + }); + + it("keeps names that are prefixes of other names apart", () => { + const source = [ + "model OppStatus is ExtensibleEnumT;", + "", + "enum OppStatusOptions {", + " open,", + "}", + ].join("\n"); + + const declarations = listTypeSpecDeclarations(source); + expect(pick(declarations, "OppStatus").endLine).toBe(1); + expect(pick(declarations, "OppStatusOptions")).toMatchObject({ + startLine: 3, + endLine: 5, + }); + }); + + it("throws on a source that doesn't parse", () => { + expect(() => listTypeSpecDeclarations("model Broken {")).toThrow(); + }); +}); + +// ############################################################################ +// Python +// ############################################################################ + +describe("listPythonDeclarations", () => { + it("covers a class through its last body line, not the next section's comments", () => { + const source = [ + '"""Module docstring."""', + "", + "# ###############", + "# Event Types", + "# ###############", + "", + "", + "class EventType(StrEnum):", + ' """Type of event."""', + "", + ' SINGLE_DATE = "singleDate"', + ' OTHER = "other"', + "", + "", + "# ###############", + "# Event Base", + "# ###############", + "", + "", + "class EventBase(SealedModel):", + " name: str", + ].join("\n"); + + const declarations = listPythonDeclarations(source); + expect(pick(declarations, "EventType")).toMatchObject({ + startLine: 8, + endLine: 12, + }); + expect(pick(declarations, "EventBase")).toMatchObject({ + startLine: 20, + endLine: 21, + }); + }); + + it("keeps a class body whose strings and brackets reach column 0", () => { + const source = [ + "class Filtered(Paginated[ItemsT], Generic[ItemsT, FilterT]):", + ' """A filtered list.', + "", + "Continued at column 0 inside the docstring.", + ' """', + "", + " filter_info: FilterInfo[FilterT] = Field(", + " ...,", + ' alias="filterInfo",', + ")", + " # A trailing comment inside the body", + "", + "", + "class Next:", + " pass", + ].join("\n"); + + expect(pick(listPythonDeclarations(source), "Filtered")).toMatchObject({ + startLine: 1, + endLine: 11, + }); + }); + + it("includes decorators and multi-line class headers", () => { + const source = [ + "@dataclass(", + " frozen=True,", + ")", + "@other", + "class Point(", + " Base,", + "):", + " x: int", + "", + "def helper() -> None:", + " return None", + ].join("\n"); + + const declarations = listPythonDeclarations(source); + expect(pick(declarations, "Point")).toMatchObject({ + startLine: 1, + endLine: 8, + }); + expect(pick(declarations, "helper")).toMatchObject({ + startLine: 10, + endLine: 11, + }); + }); + + it("finds one-line and multi-line assignments", () => { + const source = [ + "Event = Union[SingleDateEvent, DateRangeEvent, OtherEvent]", + 'T = TypeVar("T")', + "UTCDateTime = Annotated[", + " datetime,", + " AfterValidator(_utc),", + "]", + 'Duns: TypeAlias = Annotated[str, StringConstraints(pattern=r"^[0-9]{9}$")]', + "if TYPE_CHECKING:", + " from x import Y", + ].join("\n"); + + const declarations = listPythonDeclarations(source); + expect(pick(declarations, "Event")).toMatchObject({ + startLine: 1, + endLine: 1, + }); + expect(pick(declarations, "UTCDateTime")).toMatchObject({ + startLine: 3, + endLine: 6, + }); + expect(pick(declarations, "Duns").startLine).toBe(7); + expect(declarations.map((d) => d.name)).toEqual([ + "Event", + "T", + "UTCDateTime", + "Duns", + ]); + }); + + it("keeps names that are prefixes of other names apart", () => { + const source = [ + "class OppStatus(Base):", + " value: str", + "", + "", + "class OppStatusOptions(StrEnum):", + ' OPEN = "open"', + ].join("\n"); + + const declarations = listPythonDeclarations(source); + expect(pick(declarations, "OppStatus").endLine).toBe(2); + expect(pick(declarations, "OppStatusOptions").startLine).toBe(5); + }); +}); + +// ############################################################################ +// TypeScript +// ############################################################################ + +describe("listTypeScriptDeclarations", () => { + it("covers a whole statement, starting at the declaration rather than its comment", () => { + const source = [ + 'import { z } from "zod";', + "", + "/** Query parameters for paginated routes */", + "export const PaginatedQueryParamsSchema = z.object({", + " /** The page */", + " page: z.number().int().min(1).default(1),", + "});", + "", + "// Base event schema (common fields)", + "const EventBaseSchema = z.object({", + " name: z.string(),", + "});", + ].join("\n"); + + const declarations = listTypeScriptDeclarations(source); + expect(pick(declarations, "PaginatedQueryParamsSchema")).toMatchObject({ + startLine: 4, + endLine: 7, + }); + // Unexported declarations count too. + expect(pick(declarations, "EventBaseSchema")).toMatchObject({ + startLine: 10, + endLine: 12, + }); + }); + + it("finds one-line declarations and keeps prefix names apart", () => { + const source = [ + 'export const SortOrderEnum = z.enum(["asc", "desc"]);', + 'export const SortOrderEnumExtra = z.enum(["x"]);', + ].join("\n"); + + const declarations = listTypeScriptDeclarations(source); + expect(pick(declarations, "SortOrderEnum")).toMatchObject({ + startLine: 1, + endLine: 1, + code: 'export const SortOrderEnum = z.enum(["asc", "desc"]);', + }); + }); + + it("finds generic functions, types, interfaces and chained calls", () => { + const source = [ + "export const PaginatedSchema = (itemsSchema: T) =>", + " SuccessSchema.extend({", + " items: z.array(itemsSchema),", + " });", + "", + "export type Money = z.infer;", + "", + "export interface Plugin {", + " name: string;", + "}", + "", + "export const MoneySchema = z", + " .object({", + " amount: DecimalStringSchema,", + " })", + " .strict();", + ].join("\n"); + + const declarations = listTypeScriptDeclarations(source); + expect(pick(declarations, "PaginatedSchema")).toMatchObject({ + startLine: 1, + endLine: 4, + }); + expect(pick(declarations, "Money").startLine).toBe(6); + expect(pick(declarations, "Plugin")).toMatchObject({ + startLine: 8, + endLine: 10, + }); + expect(pick(declarations, "MoneySchema")).toMatchObject({ + startLine: 12, + endLine: 16, + }); + }); +}); + +// ############################################################################ +// Finding a declaration across the sources +// ############################################################################ + +describe("findDeclaration", () => { + it("finds a TypeSpec declaration in the protocol sources and names its file", () => { + const found = findDeclaration("typeSpec", "OrgPatchData"); + expect(found.path).toBe("lib/core/lib/core/models/organization-sync.tsp"); + expect(found.code).toMatch(/model OrgPatchData is/); + expect(found.code.split("\n")[0]).toMatch(/^\s*\/\*\*/); + }); + + it("finds Python and TypeScript declarations in the SDK sources", () => { + expect(findDeclaration("python", "OppStatusOptions").path).toMatch( + /^lib\/python-sdk\/common_grants_sdk\/schemas\/pydantic\/.+\.py$/, + ); + expect(findDeclaration("typescript", "MoneySchema").path).toMatch( + /^lib\/ts-sdk\/src\/schemas\/zod\/.+\.ts$/, + ); + }); + + it("fails when no declaration has the name", () => { + expect(() => findDeclaration("typeSpec", "NoSuchSchema")).toThrow( + /No TypeSpec declaration named "NoSuchSchema"/, + ); + expect(() => findDeclaration("python", "NoSuchSchema")).toThrow( + /No Python declaration named "NoSuchSchema"/, + ); + expect(() => findDeclaration("typescript", "NoSuchSchema")).toThrow( + /No TypeScript declaration named "NoSuchSchema"/, + ); + }); + + it("skips the merge-patch mirrors, which reuse the names of the models they mirror", () => { + // CommonGrants.Patch redeclares OrgIds and others as compile-time sources + // for OrgPatchData; the page for OrgIds means the model in Models. + expect(findDeclaration("typeSpec", "OrgIds").path).toBe( + "lib/core/lib/core/models/organization.tsp", + ); + // A qualified name still reaches a mirror. + expect(findDeclaration("typeSpec", "Patch.OrgIds").path).toBe( + "lib/core/lib/core/models/organization-sync.tsp", + ); + expect(findDeclaration("typeSpec", "CommonGrants.Models.OrgIds").path).toBe( + "lib/core/lib/core/models/organization.tsp", + ); + }); + + it("fails when more than one file declares the name", () => { + // `V` is a TypeVar declared separately in several SDK modules. + expect(() => findDeclaration("python", "V")).toThrow( + /More than one Python declaration named "V"/, + ); + }); +}); + +describe("findSchemaDeclaration", () => { + it("finds TypeSpec and Python declarations by the schema's own name", () => { + expect(findSchemaDeclaration("typeSpec", "AwdIdFain").code).toMatch( + /model AwdIdFain is/, + ); + expect(findSchemaDeclaration("python", "OppStatusOptions").code).toMatch( + /^class OppStatusOptions\(/, + ); + }); + + it("finds a TypeScript schema named Schema", () => { + expect(findSchemaDeclaration("typescript", "Money").name).toBe( + "MoneySchema", + ); + }); + + it("fails when the SDK declares the schema under another name", () => { + // The TypeScript SDK names enums Enum. + expect(() => findSchemaDeclaration("typescript", "SortOrder")).toThrow( + /No TypeScript declaration named "SortOrderSchema"/, + ); + // The Python SDK names its operator enums in the singular. + expect(() => + findSchemaDeclaration("python", "EquivalenceOperators"), + ).toThrow(/No Python declaration named "EquivalenceOperators"/); + }); +}); + +describe("findSnippet", () => { + it("looks up the schema's conventional name when the page just asks for the tab", () => { + expect(findSnippet("typescript", true, "Money").name).toBe("MoneySchema"); + }); + + it("looks up the name the page gives instead", () => { + expect(findSnippet("typescript", "SortOrderEnum", "SortOrder").name).toBe( + "SortOrderEnum", + ); + expect(findSnippet("typeSpec", "ExtensibleEnumT").name).toBe( + "ExtensibleEnumT", + ); + }); + + it("shows several declarations from one file together, each whole, linking across them", () => { + const snippet = findSnippet("typeSpec", ["IdentifierT", "Identifier"]); + const template = findDeclaration("typeSpec", "IdentifierT"); + const model = findDeclaration("typeSpec", "Identifier"); + expect(snippet.code).toBe(`${template.code}\n\n${model.code}`); + expect(snippet.path).toBe(model.path); + expect(snippet.startLine).toBe(template.startLine); + expect(snippet.endLine).toBe(model.endLine); + }); + + it("fails when declarations shown together are in different files", () => { + expect(() => findSnippet("typeSpec", ["Money", "AwardBase"])).toThrow( + /must be in one file/, + ); + }); + + it("fails when the page asks for the tab without naming a schema or a declaration", () => { + expect(() => findSnippet("python", true)).toThrow( + /Python tab needs a declaration name/, + ); + }); +}); + +describe("sourceUrl", () => { + it("links to the declaration's lines on GitHub", () => { + expect(sourceUrl({ path: "lib/a.tsp", startLine: 3, endLine: 9 })).toBe( + "https://github.com/HHS/simpler-grants-protocol/tree/main//lib/a.tsp#L3-L9", + ); + expect(sourceUrl({ path: "lib/a.tsp", startLine: 3, endLine: 3 })).toBe( + "https://github.com/HHS/simpler-grants-protocol/tree/main//lib/a.tsp#L3", + ); + }); +}); diff --git a/website/src/lib/schema/paths.ts b/website/src/lib/schema/paths.ts index 686606d0c..8e662866d 100644 --- a/website/src/lib/schema/paths.ts +++ b/website/src/lib/schema/paths.ts @@ -8,9 +8,7 @@ import * as path from "path"; * Directory tree (relative to WEBSITE_ROOT unless noted): * * cache/ - * schema-docs-mapping.json - * schema-metadata.json - * type-formatting-cache.json + * plugin-metadata.json * public/ * openapi/ * schemas/ @@ -23,6 +21,8 @@ import * as path from "path"; * * REPO_ROOT is the parent of WEBSITE_ROOT. Extension schemas are referenced * from repo root as website/.extension-schemas (EXTENSION_SCHEMAS_PATH_PREFIX). + * Docs pages find code snippets by name under TYPESPEC_SOURCE_DIR, + * PYTHON_SDK_SCHEMAS_DIR and TS_SDK_SCHEMAS_DIR. */ export class Paths { /** Absolute path to the website directory (process.cwd() at build time) */ @@ -53,24 +53,27 @@ export class Paths { .join("/"); // Generated cache files - static readonly SCHEMA_DOCS_MAPPING = path.join( - Paths.CACHE_DIR, - "schema-docs-mapping.json", - ); - static readonly SCHEMA_METADATA = path.join( - Paths.CACHE_DIR, - "schema-metadata.json", - ); - static readonly TYPE_FORMATTING_CACHE = path.join( - Paths.CACHE_DIR, - "type-formatting-cache.json", - ); static readonly PLUGIN_METADATA = path.join( Paths.CACHE_DIR, "plugin-metadata.json", ); // Source directories + /** Protocol TypeSpec source, searched for declarations by name */ + static readonly TYPESPEC_SOURCE_DIR = path.join( + Paths.REPO_ROOT, + "lib/core/lib", + ); + /** Python SDK schemas, searched for declarations by name */ + static readonly PYTHON_SDK_SCHEMAS_DIR = path.join( + Paths.REPO_ROOT, + "lib/python-sdk/common_grants_sdk/schemas/pydantic", + ); + /** TypeScript SDK schemas, searched for declarations by name */ + static readonly TS_SDK_SCHEMAS_DIR = path.join( + Paths.REPO_ROOT, + "lib/ts-sdk/src/schemas/zod", + ); static readonly CONTENT_DOCS_DIR = path.join( Paths.WEBSITE_ROOT, "src/content/docs", diff --git a/website/src/lib/schema/schema-files.ts b/website/src/lib/schema/schema-files.ts new file mode 100644 index 000000000..19384ae1a --- /dev/null +++ b/website/src/lib/schema/schema-files.ts @@ -0,0 +1,28 @@ +import { existsSync } from "fs"; +import * as path from "path"; +import { Paths } from "./paths"; + +/** + * Gives the path, relative to the repository root, of the JSON Schema file the + * website's TypeSpec build writes for a schema, or of its copy for one + * protocol version (`v0.5.0`). + * + * @throws if the file doesn't exist, so a page naming an unknown schema fails the build + */ +export function schemaFilePath(schemaName: string, version?: string): string { + const dir = version + ? path.join(Paths.SCHEMAS_DIR, "versions", version) + : Paths.SCHEMAS_DIR; + const file = path.join(dir, `${schemaName}.yaml`); + const relative = path + .relative(Paths.REPO_ROOT, file) + .split(path.sep) + .join("/"); + + if (!existsSync(file)) { + throw new Error( + `No JSON Schema for "${schemaName}"${version ? ` in ${version}` : ""}: ${relative} doesn't exist`, + ); + } + return relative; +} diff --git a/website/src/lib/schema/schema-metadata-loader.ts b/website/src/lib/schema/schema-metadata-loader.ts deleted file mode 100644 index 9761d8680..000000000 --- a/website/src/lib/schema/schema-metadata-loader.ts +++ /dev/null @@ -1,114 +0,0 @@ -import { readFileSync } from "fs"; -import { Paths } from "./paths"; - -/** - * Pre-computed schema metadata - */ -export interface SchemaMetadata { - schemaName: string; - filePath: string; - type: - "object" | "enum" | "array" | "string" | "number" | "boolean" | "unknown"; - isEnum: boolean; - isObject: boolean; - properties?: string[]; - enumValues?: string[]; - lastModified: number; - contentHash: string; -} - -/** - * Schema metadata collection - */ -export interface SchemaMetadataCollection { - schemas: Record; - generatedAt: number; - totalSchemas: number; -} - -/** - * Schema metadata loader service - */ -export class SchemaMetadataLoader { - private static cache: SchemaMetadataCollection | null = null; - - /** - * Loads schema metadata with caching - */ - static loadMetadata(): SchemaMetadataCollection { - if (this.cache) { - return this.cache; - } - - try { - const metadataPath = Paths.SCHEMA_METADATA; - const metadataContent = readFileSync(metadataPath, "utf-8"); - const metadata = JSON.parse(metadataContent) as SchemaMetadataCollection; - - this.cache = metadata; - console.log(`Loaded schema metadata (${metadata.totalSchemas} schemas)`); - return metadata; - } catch (error) { - console.warn(`Could not load schema metadata: ${error}`); - - // Return empty collection as fallback - const fallback: SchemaMetadataCollection = { - schemas: {}, - generatedAt: Date.now(), - totalSchemas: 0, - }; - - this.cache = fallback; - return fallback; - } - } - - /** - * Gets metadata for a specific schema - */ - static getSchemaMetadata(schemaName: string): SchemaMetadata | undefined { - const metadata = this.loadMetadata(); - return metadata.schemas[schemaName]; - } - - /** - * Checks if a schema is an enum schema - */ - static isEnumSchema(schemaName: string): boolean { - const metadata = this.getSchemaMetadata(schemaName); - return metadata?.isEnum || false; - } - - /** - * Checks if a schema is an object schema - */ - static isObjectSchema(schemaName: string): boolean { - const metadata = this.getSchemaMetadata(schemaName); - return metadata?.isObject || false; - } - - /** - * Gets all schema names - */ - static getAllSchemaNames(): string[] { - const metadata = this.loadMetadata(); - return Object.keys(metadata.schemas); - } - - /** - * Gets schemas by type - */ - static getSchemasByType(type: SchemaMetadata["type"]): SchemaMetadata[] { - const metadata = this.loadMetadata(); - return Object.values(metadata.schemas).filter( - (schema) => schema.type === type, - ); - } - - /** - * Clears the cache (useful for testing) - */ - static clearCache(): void { - this.cache = null; - } -} diff --git a/website/src/lib/schema/source-declarations.ts b/website/src/lib/schema/source-declarations.ts new file mode 100644 index 000000000..fcd8399ad --- /dev/null +++ b/website/src/lib/schema/source-declarations.ts @@ -0,0 +1,538 @@ +import { readdirSync, readFileSync } from "fs"; +import * as path from "path"; +import { parse, SyntaxKind } from "@typespec/compiler/ast"; +import type { TypeSpecScriptNode } from "@typespec/compiler/ast"; +import ts from "typescript"; +import { Paths } from "./paths"; + +/** + * Finds a named declaration in the protocol's TypeSpec source or in the SDKs' + * Python and TypeScript source, so a docs page can show the code for a schema + * by naming it rather than by typing a file path and a range of lines. + */ + +/** A declaration found in a source file. */ +export interface Declaration { + /** The declared name */ + name: string; + /** First line of the declaration, 1-based */ + startLine: number; + /** Last line of the declaration, 1-based and inclusive */ + endLine: number; + /** The declaration's source lines, as they appear in the file */ + code: string; + /** The TypeSpec namespace the declaration sits in, if any */ + namespace?: string; +} + +/** A declaration and the file it was found in. */ +export interface FoundDeclaration extends Declaration { + /** Path to the file, relative to the repository root */ + path: string; +} + +/** The source languages a docs page can show a declaration in. */ +export type SourceLanguage = "typeSpec" | "python" | "typescript"; + +/** Where each language's source lives, and how to list its declarations. */ +const SOURCES: Record< + SourceLanguage, + { + label: string; + dir: string; + extension: string; + list: (source: string) => Declaration[]; + } +> = { + typeSpec: { + label: "TypeSpec", + dir: Paths.TYPESPEC_SOURCE_DIR, + extension: ".tsp", + list: listTypeSpecDeclarations, + }, + python: { + label: "Python", + dir: Paths.PYTHON_SDK_SCHEMAS_DIR, + extension: ".py", + list: listPythonDeclarations, + }, + typescript: { + label: "TypeScript", + dir: Paths.TS_SDK_SCHEMAS_DIR, + extension: ".ts", + list: listTypeScriptDeclarations, + }, +}; + +// ############################################################################ +// Finding a declaration by name +// ############################################################################ + +const indexes = new Map>(); + +/** + * TypeSpec namespaces whose declarations a bare name never refers to. + * `CommonGrants.Patch` holds compile-time mirrors of the organization models + * that `OrgPatchData` is built from; they keep the names of the models they + * mirror, so `OrgIds` on its own means the model in `CommonGrants.Models`. A + * qualified name such as `Patch.OrgIds` still reaches a mirror. + */ +const TYPESPEC_MIRROR_NAMESPACES = new Set(["CommonGrants.Patch"]); + +/** + * Finds the one declaration with this name in a language's source. + * + * A TypeSpec name may be qualified with the end of its namespace + * (`Patch.OrgIds`, `CommonGrants.Models.OrgIds`). + * + * @throws if no file declares the name, or more than one declaration has it + */ +export function findDeclaration( + language: SourceLanguage, + name: string, +): FoundDeclaration { + const { label, dir } = SOURCES[language]; + const matches = matchDeclarations(language, name); + + if (matches.length === 0) { + throw new Error( + `No ${label} declaration named "${name}" under ${path.relative(Paths.REPO_ROOT, dir)}`, + ); + } + if (matches.length > 1) { + const places = matches.map((m) => `${m.path}:${m.startLine}`).join(", "); + throw new Error( + `More than one ${label} declaration named "${name}": ${places}. Name the one to show explicitly.`, + ); + } + return matches[0]; +} + +/** The declarations a name refers to, before checking there's exactly one. */ +function matchDeclarations( + language: SourceLanguage, + name: string, +): FoundDeclaration[] { + const parts = name.split("."); + const bareName = parts.pop()!; + const candidates = getIndex(language).get(bareName) ?? []; + + if (parts.length > 0) { + const qualifier = parts.join("."); + return candidates.filter( + (d) => + d.namespace === qualifier || + (d.namespace ?? "").endsWith(`.${qualifier}`), + ); + } + return candidates.filter( + (d) => !TYPESPEC_MIRROR_NAMESPACES.has(d.namespace ?? ""), + ); +} + +/** + * The name a language's source declares a schema under, by convention: + * TypeSpec and Python use the schema's own name, and the TypeScript SDK names + * its Zod schemas `Schema`. A page names the declaration explicitly + * when an SDK doesn't follow this (its enums, for example, end in `Enum`). + */ +export function conventionalName( + language: SourceLanguage, + schemaName: string, +): string { + return language === "typescript" ? `${schemaName}Schema` : schemaName; +} + +/** + * Finds the declaration for a schema under its conventional name. + * + * @throws if nothing or more than one thing has that name + */ +export function findSchemaDeclaration( + language: SourceLanguage, + schemaName: string, +): FoundDeclaration { + return findDeclaration(language, conventionalName(language, schemaName)); +} + +/** + * Finds the code a source tab shows. The page either just asks for the tab + * (`true`), which looks up the schema's conventional name; gives the + * declaration's name, for an SDK that names it differently; or lists several + * names, to show a template with the model built from it. Several + * declarations must be in one file; each is shown whole, in the order listed, + * separated by a blank line. + * + * @throws if a declaration can't be found + */ +export function findSnippet( + language: SourceLanguage, + requested: true | string | string[], + schemaName?: string, +): FoundDeclaration { + if (Array.isArray(requested)) { + const found = requested.map((name) => findDeclaration(language, name)); + const files = new Set(found.map((d) => d.path)); + if (found.length === 0 || files.size !== 1) { + throw new Error( + `Declarations shown together must be in one file: ${requested.join(", ")} are in ${[...files].join(", ") || "no file"}`, + ); + } + return { + name: requested.join(", "), + path: found[0].path, + startLine: Math.min(...found.map((d) => d.startLine)), + endLine: Math.max(...found.map((d) => d.endLine)), + code: found.map((d) => d.code).join("\n\n"), + }; + } + if (typeof requested === "string") { + return findDeclaration(language, requested); + } + if (!schemaName) { + throw new Error( + `The ${SOURCES[language].label} tab needs a declaration name, or a schema name to look it up by`, + ); + } + return findSchemaDeclaration(language, schemaName); +} + +/** + * Links to a declaration's lines in the repository on GitHub. Keeps the + * double slash the docs have always published. + */ +export function sourceUrl( + declaration: Pick, +): string { + const { path: filePath, startLine, endLine } = declaration; + const lines = + endLine > startLine ? `#L${startLine}-L${endLine}` : `#L${startLine}`; + return `https://github.com/HHS/simpler-grants-protocol/tree/main//${filePath}${lines}`; +} + +/** Lists every declaration in a language's source, by name, once per build. */ +function getIndex(language: SourceLanguage): Map { + const cached = indexes.get(language); + if (cached) return cached; + + const { dir, extension, list } = SOURCES[language]; + const index = new Map(); + + for (const file of listFiles(dir, extension)) { + const relativePath = path + .relative(Paths.REPO_ROOT, file) + .split(path.sep) + .join("/"); + let declarations: Declaration[]; + try { + declarations = list(readFileSync(file, "utf-8")); + } catch (error) { + throw new Error(`Could not read declarations from ${relativePath}`, { + cause: error, + }); + } + for (const declaration of declarations) { + const entries = index.get(declaration.name) ?? []; + entries.push({ ...declaration, path: relativePath }); + index.set(declaration.name, entries); + } + } + + indexes.set(language, index); + return index; +} + +/** Lists files with an extension under a directory, in a stable order. */ +function listFiles(dir: string, extension: string): string[] { + const files: string[] = []; + const entries = readdirSync(dir, { withFileTypes: true }).sort((a, b) => + a.name.localeCompare(b.name), + ); + for (const entry of entries) { + const fullPath = path.join(dir, entry.name); + if (entry.isDirectory()) { + files.push(...listFiles(fullPath, extension)); + } else if (entry.isFile() && entry.name.endsWith(extension)) { + files.push(fullPath); + } + } + return files; +} + +// ############################################################################ +// Shared helpers +// ############################################################################ + +/** Converts a character offset to a 1-based line number. */ +function lineAt(lineStarts: number[], offset: number): number { + let low = 0; + let high = lineStarts.length - 1; + while (low < high) { + const mid = Math.ceil((low + high) / 2); + if (lineStarts[mid] <= offset) low = mid; + else high = mid - 1; + } + return low + 1; +} + +function getLineStarts(source: string): number[] { + const starts = [0]; + for (let i = 0; i < source.length; i++) { + if (source[i] === "\n") starts.push(i + 1); + } + return starts; +} + +/** Builds a declaration from whole lines of the source. */ +function fromLines( + lines: string[], + name: string, + startLine: number, + endLine: number, +): Declaration { + return { + name, + startLine, + endLine, + code: lines.slice(startLine - 1, endLine).join("\n"), + }; +} + +// ############################################################################ +// TypeSpec +// ############################################################################ + +/** A statement in a TypeSpec source or namespace block */ +type Statement = TypeSpecScriptNode["statements"][number]; + +const TYPESPEC_DECLARATION_KINDS = new Set([ + SyntaxKind.ModelStatement, + SyntaxKind.EnumStatement, + SyntaxKind.UnionStatement, + SyntaxKind.ScalarStatement, + SyntaxKind.AliasStatement, + SyntaxKind.InterfaceStatement, + SyntaxKind.OperationStatement, +]); + +/** + * Lists the named type declarations in a TypeSpec source, each with the doc + * comment and decorators above it, including those inside namespace blocks. + * Uses the TypeSpec compiler's own parser, so nested braces, one-line + * declarations and multi-line decorators need no special handling. + * + * @throws if the source doesn't parse + */ +export function listTypeSpecDeclarations(source: string): Declaration[] { + const ast = parse(source, { docs: true }); + if (ast.parseDiagnostics.length > 0) { + const messages = ast.parseDiagnostics.map((d) => d.message).join("; "); + throw new Error(`TypeSpec source doesn't parse: ${messages}`); + } + + const lineStarts = getLineStarts(source); + const lines = source.split("\n"); + const declarations: Declaration[] = []; + + const visit = (statements: readonly Statement[], namespace: string[]) => { + // A file-level `namespace X;` applies to the statements after it. + let current = namespace; + for (const statement of statements) { + if (statement.kind === SyntaxKind.NamespaceStatement) { + // `namespace A.B { }` parses as A holding B; walk down to the + // innermost one, collecting the name as we go. + const names = [...namespace]; + let node: Statement | undefined = statement; + let body: unknown; + while (node?.kind === SyntaxKind.NamespaceStatement) { + names.push(node.id.sv); + body = node.statements; + node = Array.isArray(body) ? undefined : (body as Statement); + } + if (Array.isArray(body)) { + visit(body as Statement[], names); + } else { + current = names; + } + continue; + } + if (!TYPESPEC_DECLARATION_KINDS.has(statement.kind)) continue; + + // The node starts at its doc comment; its decorators sit between. + const name = (statement as { id: { sv: string } }).id.sv; + declarations.push({ + ...fromLines( + lines, + name, + lineAt(lineStarts, statement.pos), + lineAt(lineStarts, statement.end - 1), + ), + namespace: current.join(".") || undefined, + }); + } + }; + visit(ast.statements, []); + + return declarations; +} + +// ############################################################################ +// TypeScript +// ############################################################################ + +/** + * Lists the top-level declarations in a TypeScript source. Each one starts at + * its declaration keyword, not at the comment above it, and runs to the end + * of its statement. + */ +export function listTypeScriptDeclarations(source: string): Declaration[] { + const file = ts.createSourceFile( + "source.ts", + source, + ts.ScriptTarget.Latest, + true, + ts.ScriptKind.TS, + ); + const lines = source.split("\n"); + const declarations: Declaration[] = []; + + const add = (name: string, statement: ts.Statement) => { + const startLine = + file.getLineAndCharacterOfPosition(statement.getStart(file)).line + 1; + const endLine = file.getLineAndCharacterOfPosition(statement.end).line + 1; + declarations.push(fromLines(lines, name, startLine, endLine)); + }; + + for (const statement of file.statements) { + if (ts.isVariableStatement(statement)) { + for (const declaration of statement.declarationList.declarations) { + if (ts.isIdentifier(declaration.name)) { + add(declaration.name.text, statement); + } + } + } else if ( + (ts.isFunctionDeclaration(statement) || + ts.isClassDeclaration(statement) || + ts.isInterfaceDeclaration(statement) || + ts.isTypeAliasDeclaration(statement) || + ts.isEnumDeclaration(statement)) && + statement.name + ) { + add(statement.name.text, statement); + } + } + + return declarations; +} + +// ############################################################################ +// Python +// ############################################################################ + +const PYTHON_DEFINITION = /^(?:async\s+)?(?:class|def)\s+([A-Za-z_]\w*)/; +const PYTHON_ASSIGNMENT = /^([A-Za-z_]\w*)\s*(?::[^=]+)?=(?!=)/; + +/** One line of Python, after tracking the strings and brackets around it. */ +interface PythonLine { + text: string; + /** Whether the line opens inside a bracket or a multi-line string */ + continues: boolean; +} + +/** + * Marks which lines of a Python source continue an earlier line, because they + * open inside brackets or a triple-quoted string. Those lines can't start a + * statement, whatever their indentation. + */ +function scanPythonLines(source: string): PythonLine[] { + const result: PythonLine[] = []; + let depth = 0; + let quote: string | null = null; // the open string's delimiter + + for (const text of source.split("\n")) { + result.push({ text, continues: depth > 0 || quote !== null }); + + for (let i = 0; i < text.length; i++) { + const char = text[i]; + if (quote) { + if (char === "\\") { + i++; + } else if (text.startsWith(quote, i)) { + i += quote.length - 1; + quote = null; + } + continue; + } + if (char === "#") break; + if (char === '"' || char === "'") { + const triple = char.repeat(3); + quote = text.startsWith(triple, i) ? triple : char; + i += quote.length - 1; + } else if ("([{".includes(char)) { + depth++; + } else if (")]}".includes(char)) { + depth = Math.max(0, depth - 1); + } + } + // A single-quoted string can't run past the end of its line. + if (quote && quote.length === 1) quote = null; + } + + return result; +} + +/** + * Lists the module-level classes, functions and assignments in a Python + * source. Each one starts at its first decorator, or at its own line, and + * runs to the last non-blank line of its body. + */ +export function listPythonDeclarations(source: string): Declaration[] { + const lines = scanPythonLines(source); + const rawLines = lines.map((l) => l.text); + const declarations: Declaration[] = []; + + /** A line that begins a new module-level statement */ + const startsStatement = (line: PythonLine) => + !line.continues && /^[^\s#]/.test(line.text); + + let i = 0; + while (i < lines.length) { + if (!startsStatement(lines[i])) { + i++; + continue; + } + + // Decorators belong to the definition below them. + const start = i; + while (i < lines.length && /^@/.test(lines[i].text)) { + i++; + while (i < lines.length && lines[i].continues) i++; + } + const header = lines[i]?.text ?? ""; + + // The statement runs until the next line that starts a statement or is + // a comment at column 0. + let end = i; + for (let j = i + 1; j < lines.length; j++) { + const line = lines[j]; + if (startsStatement(line)) break; + if (!line.continues && /^#/.test(line.text)) break; + if (line.text.trim() !== "") end = j; + } + + const name = + header.match(PYTHON_DEFINITION)?.[1] ?? + (start === i ? header.match(PYTHON_ASSIGNMENT)?.[1] : undefined); + if (name) { + declarations.push(fromLines(rawLines, name, start + 1, end + 1)); + } + i = end + 1; + } + + return declarations; +} + +/** Clears the cached source indexes (for tests). */ +export function clearDeclarationCache(): void { + indexes.clear(); +} diff --git a/website/src/scripts/generate-schema-docs.ts b/website/src/scripts/generate-schema-docs.ts deleted file mode 100644 index 0d3e2a0ed..000000000 --- a/website/src/scripts/generate-schema-docs.ts +++ /dev/null @@ -1,164 +0,0 @@ -import { readFileSync, writeFileSync } from "fs"; -import * as path from "path"; -import yaml from "js-yaml"; -import { BuildScriptUtils } from "./utils"; -import { Paths } from "../lib/schema/paths"; - -/** - * Frontmatter schema definition structure - */ -interface FrontmatterSchemaDef { - jsonSchema?: { - file?: { - path?: string; - }; - code?: string; - }; -} - -/** - * Frontmatter structure - */ -interface Frontmatter { - [key: string]: FrontmatterSchemaDef | unknown; -} - -/** - * Build-time script to generate schema documentation mapping - */ -class SchemaDocGenerator { - /** - * Main entry point - */ - static async generate(): Promise { - console.log("Generating schema documentation mapping..."); - - const startTime = Date.now(); - const mapping = new Map(); - - try { - const docsDir = Paths.PROTOCOL_DOCS_DIR; - const mdxFiles = BuildScriptUtils.findFilesByExtension(docsDir, ".mdx"); - - console.log(`Found ${mdxFiles.length} MDX files to process`); - - for (const file of mdxFiles) { - const references = this.extractSchemaReferences(file); - for (const { schemaName, docPath } of references) { - mapping.set(schemaName, docPath); - } - } - - // Convert to object for JSON serialization - const mappingObject = Object.fromEntries(mapping); - - // Write to output file - const outputPath = Paths.SCHEMA_DOCS_MAPPING; - writeFileSync(outputPath, JSON.stringify(mappingObject, null, 2)); - - const duration = Date.now() - startTime; - console.log(`Generated schema documentation mapping in ${duration}ms`); - console.log(`Mapped ${mapping.size} schemas to documentation paths`); - console.log(`Output written to: ${Paths.SCHEMA_DOCS_MAPPING}`); - } catch (error) { - BuildScriptUtils.handleError( - error, - "schema documentation mapping generation", - ); - } - } - - /** - * Extracts schema references from an MDX file's frontmatter - */ - private static extractSchemaReferences( - filePath: string, - ): Array<{ schemaName: string; docPath: string }> { - const references: Array<{ schemaName: string; docPath: string }> = []; - - try { - const content = readFileSync(filePath, "utf-8"); - const frontmatterMatch = content.match(/^---\n([\s\S]*?)\n---/); - - if (!frontmatterMatch) return references; - - const frontmatterYaml = frontmatterMatch[1]; - const frontmatter = yaml.load(frontmatterYaml) as Frontmatter; - - // Convert file path to documentation URL - const relativePath = filePath.replace(Paths.CONTENT_DOCS_DIR + "/", ""); - const docPath = "/" + relativePath.replace(/\.mdx$/, ""); - - // Extract schema paths from each schema definition - for (const [, schemaDef] of Object.entries(frontmatter)) { - if ( - typeof schemaDef === "object" && - schemaDef !== null && - "jsonSchema" in schemaDef - ) { - const jsonSchema = (schemaDef as FrontmatterSchemaDef).jsonSchema; - if ( - jsonSchema?.file?.path && - typeof jsonSchema.file.path === "string" - ) { - const schemaPath = jsonSchema.file.path; - // Frontmatter paths are relative to repo root; convert - // SCHEMAS_DIR to repo-relative so the comparison works. - const relativeSchemaDir = - path.relative(Paths.REPO_ROOT, Paths.SCHEMAS_DIR) + "/"; - if (schemaPath.includes(relativeSchemaDir)) { - // Extract schema name from path - const schemaFileName = schemaPath - .split("/") - .pop() - ?.replace(".yaml", ""); - if (schemaFileName) { - references.push({ schemaName: schemaFileName, docPath }); - } - } - } else if (jsonSchema?.code) { - // Handle inline schemas (like basic types in types/ directory) - const schemaName = Object.keys(frontmatter).find( - (k) => frontmatter[k] === schemaDef, - ); - if (schemaName) { - references.push({ schemaName, docPath }); - - // Also add the actual JSON Schema type to the map - try { - const schemaCode = yaml.load(jsonSchema.code) as { - type?: string; - }; - if ( - schemaCode && - typeof schemaCode === "object" && - schemaCode.type - ) { - references.push({ schemaName: schemaCode.type, docPath }); - } - } catch (error) { - console.warn( - `Could not parse schema code for ${schemaName}: ${error}`, - ); - } - } - } - } - } - } catch (error) { - console.warn(`Could not read file ${filePath}: ${error}`); - } - - return references; - } -} - -// Run the generator if this script is executed directly -if (import.meta.url === `file://${process.argv[1]}`) { - SchemaDocGenerator.generate().catch((error) => { - console.error("Failed to generate schema documentation mapping:", error); - process.exit(1); - }); -} - -export { SchemaDocGenerator }; diff --git a/website/src/scripts/generate-schema-metadata.ts b/website/src/scripts/generate-schema-metadata.ts deleted file mode 100644 index c42ccc747..000000000 --- a/website/src/scripts/generate-schema-metadata.ts +++ /dev/null @@ -1,184 +0,0 @@ -import { readFileSync, writeFileSync, statSync } from "fs"; -import yaml from "js-yaml"; -import { BuildScriptUtils } from "./utils"; -import { HashUtils } from "../lib/schema/hash-utils"; -import { Paths } from "../lib/schema/paths"; - -/** - * Pre-computed schema metadata - */ -interface SchemaMetadata { - schemaName: string; - filePath: string; - type: - "object" | "enum" | "array" | "string" | "number" | "boolean" | "unknown"; - isEnum: boolean; - isObject: boolean; - properties?: string[]; - enumValues?: string[]; - lastModified: number; - contentHash: string; -} - -/** - * Schema metadata collection - */ -interface SchemaMetadataCollection { - schemas: Record; - generatedAt: number; - totalSchemas: number; -} - -/** - * Build-time script to generate schema metadata - */ -class SchemaMetadataGenerator { - /** - * Main entry point - */ - static async generate(): Promise { - console.log("Generating schema metadata..."); - - const startTime = Date.now(); - const schemas: Record = {}; - - try { - const schemasDir = Paths.SCHEMAS_DIR; - const yamlFiles = BuildScriptUtils.findFilesByExtension( - schemasDir, - ".yaml", - ); - - console.log(`Found ${yamlFiles.length} YAML schema files to process`); - - for (const filePath of yamlFiles) { - const metadata = this.processSchemaFile(filePath); - if (metadata) { - schemas[metadata.schemaName] = metadata; - } - } - - const collection: SchemaMetadataCollection = { - schemas, - generatedAt: Date.now(), - totalSchemas: Object.keys(schemas).length, - }; - - // Write to output file - const outputPath = Paths.SCHEMA_METADATA; - writeFileSync(outputPath, JSON.stringify(collection, null, 2)); - - const duration = Date.now() - startTime; - console.log(`Generated schema metadata in ${duration}ms`); - console.log(`Processed ${collection.totalSchemas} schemas`); - console.log(`Output written to: ${Paths.SCHEMA_METADATA}`); - } catch (error) { - BuildScriptUtils.handleError(error, "schema metadata generation"); - } - } - - /** - * Processes a single schema file and extracts metadata - */ - private static processSchemaFile(filePath: string): SchemaMetadata | null { - try { - const content = readFileSync(filePath, "utf-8"); - const schema = yaml.load(content) as Record; - - if (!schema) { - console.warn(`Empty schema file: ${filePath}`); - return null; - } - - const schemaName = BuildScriptUtils.extractSchemaName(filePath); - const stats = statSync(filePath); - const lastModified = stats.mtime.getTime(); - - const metadata: SchemaMetadata = { - schemaName, - filePath: filePath.replace(Paths.WEBSITE_ROOT + "/", ""), - type: this.determineSchemaType(schema), - isEnum: this.isEnumSchema(schema), - isObject: this.isObjectSchema(schema), - properties: this.extractProperties(schema), - enumValues: this.extractEnumValues(schema), - lastModified, - contentHash: HashUtils.hashString(content), - }; - - return metadata; - } catch (error) { - console.warn(`Could not process schema file ${filePath}: ${error}`); - return null; - } - } - - /** - * Determines the primary type of a schema - */ - private static determineSchemaType( - schema: Record, - ): SchemaMetadata["type"] { - if (schema.type) { - return schema.type as SchemaMetadata["type"]; - } - - if (schema.enum) { - return "enum"; - } - - if (schema.properties) { - return "object"; - } - - return "unknown"; - } - - /** - * Checks if schema is an enum schema - */ - private static isEnumSchema(schema: Record): boolean { - return schema.type === "string" && Array.isArray(schema.enum); - } - - /** - * Checks if schema is an object schema - */ - private static isObjectSchema(schema: Record): boolean { - return schema.type === "object" && Boolean(schema.properties); - } - - /** - * Extracts property names from object schemas - */ - private static extractProperties( - schema: Record, - ): string[] | undefined { - if (schema.properties && typeof schema.properties === "object") { - return Object.keys(schema.properties); - } - return undefined; - } - - /** - * Extracts enum values from enum schemas - */ - private static extractEnumValues( - schema: Record, - ): string[] | undefined { - if (Array.isArray(schema.enum)) { - return schema.enum.map((value: unknown) => String(value)); - } - return undefined; - } -} - -// Run the generator if this script is executed directly -if (import.meta.url === `file://${process.argv[1]}`) { - SchemaMetadataGenerator.generate().catch((error) => { - console.error("Failed to generate schema metadata:", error); - process.exit(1); - }); -} - -export { SchemaMetadataGenerator }; diff --git a/website/src/scripts/generate-type-formatting.ts b/website/src/scripts/generate-type-formatting.ts deleted file mode 100644 index 3ed336d0d..000000000 --- a/website/src/scripts/generate-type-formatting.ts +++ /dev/null @@ -1,164 +0,0 @@ -import { readFileSync, writeFileSync } from "fs"; -import yaml from "js-yaml"; -import { TypeFormatter } from "../lib/schema/type-formatter"; -import { SchemaDocMapper } from "../lib/schema/schema-doc-mapper"; -import { BuildScriptUtils } from "./utils"; -import { HashUtils } from "../lib/schema/hash-utils"; -import { Paths } from "../lib/schema/paths"; - -/** - * Pre-computed type formatting entry - */ -interface TypeFormattingEntry { - schemaName: string; - propertyName: string; - formattedType: string; - contentHash: string; -} - -/** - * Type formatting collection - */ -interface TypeFormattingCollection { - entries: Record; - generatedAt: number; - totalEntries: number; -} - -/** - * Build-time script to generate type formatting cache - */ -class TypeFormattingGenerator { - /** - * Main entry point - */ - static async generate(): Promise { - console.log("Generating type formatting cache..."); - - const startTime = Date.now(); - const entries: Record = {}; - - try { - // Initialize schema documentation mapping - const docMap = SchemaDocMapper.getSchemaDocMap(); - const getSchemaDocPath = (schemaName: string) => docMap.get(schemaName); - - const schemasDir = Paths.SCHEMAS_DIR; - const yamlFiles = BuildScriptUtils.findFilesByExtension( - schemasDir, - ".yaml", - ); - - console.log(`Found ${yamlFiles.length} YAML schema files to process`); - - for (const filePath of yamlFiles) { - const schemaEntries = this.processSchemaFile( - filePath, - getSchemaDocPath, - ); - Object.assign(entries, schemaEntries); - } - - const collection: TypeFormattingCollection = { - entries, - generatedAt: Date.now(), - totalEntries: Object.keys(entries).length, - }; - - // Write to output file - const outputPath = Paths.TYPE_FORMATTING_CACHE; - writeFileSync(outputPath, JSON.stringify(collection, null, 2)); - - const duration = Date.now() - startTime; - console.log(`Generated type formatting cache in ${duration}ms`); - console.log( - `Processed ${collection.totalEntries} type formatting entries`, - ); - console.log(`Output written to: ${Paths.TYPE_FORMATTING_CACHE}`); - } catch (error) { - BuildScriptUtils.handleError(error, "type formatting cache generation"); - } - } - - /** - * Processes a single schema file and generates type formatting entries - */ - private static processSchemaFile( - filePath: string, - getSchemaDocPath: (schemaName: string) => string | undefined, - ): Record { - const entries: Record = {}; - - try { - const content = readFileSync(filePath, "utf-8"); - const schema = yaml.load(content) as Record; - - if (!schema) { - console.warn(`Empty schema file: ${filePath}`); - return entries; - } - - const schemaName = BuildScriptUtils.extractSchemaName(filePath); - - // Process object schemas with properties - if (schema.type === "object" && schema.properties) { - for (const [propertyName, propertySchema] of Object.entries( - schema.properties, - )) { - const formattedType = TypeFormatter.formatPropertyType( - propertySchema as Record, - schema, - getSchemaDocPath, - ); - - const entryKey = `${schemaName}.${propertyName}`; - entries[entryKey] = { - schemaName, - propertyName, - formattedType, - contentHash: HashUtils.hashString(content), - }; - } - } - - // Process allOf schemas - if (schema.allOf && Array.isArray(schema.allOf)) { - for (const allOfItem of schema.allOf) { - if (allOfItem.properties) { - for (const [propertyName, propertySchema] of Object.entries( - allOfItem.properties, - )) { - const formattedType = TypeFormatter.formatPropertyType( - propertySchema as Record, - schema, - getSchemaDocPath, - ); - - const entryKey = `${schemaName}.${propertyName}`; - entries[entryKey] = { - schemaName, - propertyName, - formattedType, - contentHash: HashUtils.hashString(content), - }; - } - } - } - } - } catch (error) { - console.warn(`Could not process schema file ${filePath}: ${error}`); - } - - return entries; - } -} - -// Run the generator if this script is executed directly -if (import.meta.url === `file://${process.argv[1]}`) { - TypeFormattingGenerator.generate().catch((error) => { - console.error("Failed to generate type formatting cache:", error); - process.exit(1); - }); -} - -export { TypeFormattingGenerator }; From 65baa5404df9cfe8a012b0def5a85c9172d6792b Mon Sep 17 00:00:00 2001 From: Bryan Thompson Date: Thu, 19 Nov 2026 12:44:56 -0800 Subject: [PATCH 2/3] docs(website): protocol pages name their schemas instead of line ranges Each protocol page now names the schema in and , 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 --- .../conformance/competition-versions.spec.ts | 87 ++-- .../lib/schema/schema-doc-mapper.spec.ts | 122 +++++ website/package.json | 5 +- website/src/components/SchemaFormatTabs.astro | 160 +++---- website/src/components/SchemaTable.astro | 15 +- .../content/docs/protocol/fields/address.mdx | 40 +- .../docs/protocol/fields/custom-field.mdx | 56 +-- .../content/docs/protocol/fields/email.mdx | 32 +- .../content/docs/protocol/fields/event.mdx | 181 +------- .../docs/protocol/fields/extensible-enum.mdx | 26 +- .../src/content/docs/protocol/fields/file.mdx | 20 +- .../docs/protocol/fields/identifier.mdx | 59 +-- .../content/docs/protocol/fields/metadata.mdx | 32 +- .../content/docs/protocol/fields/money.mdx | 32 +- .../src/content/docs/protocol/fields/name.mdx | 20 +- .../src/content/docs/protocol/fields/pcs.mdx | 126 +----- .../content/docs/protocol/fields/phone.mdx | 40 +- .../content/docs/protocol/filters/base.mdx | 185 +------- .../content/docs/protocol/filters/boolean.mdx | 30 +- .../content/docs/protocol/filters/date.mdx | 60 +-- .../content/docs/protocol/filters/money.mdx | 60 +-- .../content/docs/protocol/filters/numeric.mdx | 90 +--- .../content/docs/protocol/filters/string.mdx | 60 +-- .../docs/protocol/models/applicant-type.mdx | 38 +- .../docs/protocol/models/application.mdx | 76 +--- .../content/docs/protocol/models/award.mdx | 182 +------- .../docs/protocol/models/competition.mdx | 75 +--- .../docs/protocol/models/form-response.mdx | 44 +- .../src/content/docs/protocol/models/form.mdx | 41 +- .../content/docs/protocol/models/mapping.mdx | 70 +-- .../docs/protocol/models/opportunity.mdx | 256 +---------- .../docs/protocol/models/organization.mdx | 415 ++---------------- .../content/docs/protocol/models/person.mdx | 14 +- .../content/docs/protocol/models/proposal.mdx | 70 +-- .../content/docs/protocol/models/revision.mdx | 78 +--- .../src/content/docs/protocol/pagination.mdx | 90 +--- .../content/docs/protocol/responses/error.mdx | 54 +-- .../docs/protocol/responses/filtered.mdx | 26 +- .../docs/protocol/responses/paginated.mdx | 26 +- .../docs/protocol/responses/sorted.mdx | 26 +- .../docs/protocol/responses/success.mdx | 70 +-- website/src/content/docs/protocol/sorting.mdx | 121 +---- .../src/content/docs/protocol/types/date.mdx | 80 +--- .../content/docs/protocol/types/numeric.mdx | 19 +- .../content/docs/protocol/types/string.mdx | 114 +---- website/src/lib/schema/schema-doc-mapper.ts | 142 ++++-- 46 files changed, 671 insertions(+), 2994 deletions(-) create mode 100644 website/__tests__/lib/schema/schema-doc-mapper.spec.ts diff --git a/website/__tests__/lib/mock/conformance/competition-versions.spec.ts b/website/__tests__/lib/mock/conformance/competition-versions.spec.ts index 75e62d0f8..199428c26 100644 --- a/website/__tests__/lib/mock/conformance/competition-versions.spec.ts +++ b/website/__tests__/lib/mock/conformance/competition-versions.spec.ts @@ -19,6 +19,7 @@ import { describe, it, expect } from "vitest"; import yaml from "js-yaml"; import type { Version } from "@/lib/mock/data/fixtures"; import { resolveSchemaRefs } from "@/lib/schema/ref-resolver"; +import { schemaFilePath } from "@/lib/schema/schema-files"; import { getValidator } from "./schema-validator"; const HERE = path.dirname(fileURLToPath(import.meta.url)); @@ -319,20 +320,47 @@ describe("the unversioned CompetitionBase authoring schema", () => { // authoring schema, whose references resolve where it is served. describe("the Form and Competition docs pages", () => { const REPO_ROOT = path.resolve(HERE, "../../../../.."); - const page = readFileSync( - path.join(REPO_ROOT, "website/src/content/docs/protocol/models/form.mdx"), - "utf-8", - ); + const readPage = (model: string) => + readFileSync( + path.join( + REPO_ROOT, + `website/src/content/docs/protocol/models/${model}.mdx`, + ), + "utf-8", + ); + const page = readPage("form"); const { form } = yaml.load(page.split("---")[1]) as { - form: { - example: { code: string }; - table: { file: { path: string } }; - jsonSchema: { file: { path: string } }; - }; + form: { example: { code: string } }; }; const load = (repoPath: string) => yaml.load(readFileSync(path.join(REPO_ROOT, repoPath), "utf-8")) as Schema; + /** + * The files a page's table and JSON Schema tab read for a schema. A + * `` with a `version` reads that version's copy; the + * `` JSON Schema tab reads the unversioned file. + */ + const filesFor = (pageText: string, schema: string) => { + const tag = (component: string) => + pageText.match( + new RegExp(`<${component}\\b[^>]*\\bschema="${schema}"[^>]*>`), + )?.[0]; + const table = tag("SchemaTable"); + const tabs = tag("SchemaFormatTabs"); + expect(table, `a SchemaTable for ${schema}`).toBeDefined(); + expect(tabs, `a SchemaFormatTabs for ${schema}`).toBeDefined(); + expect( + tabs, + "the tabs take their JSON Schema from the schema file", + ).not.toMatch(/\bjsonSchema=/); + const version = table!.match(/\bversion="([^"]+)"/)?.[1]; + return { + table: version ? schemaFilePath(schema, version) : schemaFilePath(schema), + jsonSchema: schemaFilePath(schema), + }; + }; + const formFiles = filesFor(page, "FormBase"); + it("shows exactly the v0.5 FormBase example", () => { expect(JSON.parse(form.example.code)).toEqual( exampleOf(requireSchema("jsonSchema", "0.5.0", "FormBase")), @@ -340,58 +368,37 @@ describe("the Form and Competition docs pages", () => { }); it("renders the table from the v0.5 schema, which requires title alone", () => { - expect(page).toContain( - "", - ); - expect(form.table.file.path).toBe( + expect(formFiles.table).toBe( "website/public/schemas/yaml/versions/v0.5.0/FormBase.yaml", ); - const table = load(form.table.file.path); + const table = load(formFiles.table); expect(table.required).toContain("title"); expect(table.required).not.toContain("name"); }); it("renders the Competition table from the v0.5 schema, which requires opportunity alone", () => { - const competitionPage = readFileSync( - path.join( - REPO_ROOT, - "website/src/content/docs/protocol/models/competition.mdx", - ), - "utf-8", - ); - const { competition } = yaml.load(competitionPage.split("---")[1]) as { - competition: { table: { file: { path: string } } }; - }; - expect(competitionPage).toContain( - "", - ); - expect(competition.table.file.path).toBe( + const competition = filesFor(readPage("competition"), "CompetitionBase"); + expect(competition.table).toBe( "website/public/schemas/yaml/versions/v0.5.0/CompetitionBase.yaml", ); - const table = load(competition.table.file.path); + const table = load(competition.table); expect(table.required).toContain("opportunity"); expect(table.required).not.toContain("opportunityId"); }); it("keeps the JSON Schema tab on the unversioned authoring schema", () => { - expect(form.jsonSchema.file.path).toBe( + expect(formFiles.jsonSchema).toBe( "website/public/schemas/yaml/FormBase.yaml", ); - expect(form.jsonSchema.file.path).not.toBe(form.table.file.path); - expect(load(form.jsonSchema.file.path).required).toEqual( + expect(formFiles.jsonSchema).not.toBe(formFiles.table); + expect(load(formFiles.jsonSchema).required).toEqual( expect.arrayContaining(["name", "title"]), ); }); /** The served file a model page tells readers to validate payloads with. */ const validationTarget = (model: string) => { - const text = readFileSync( - path.join( - REPO_ROOT, - `website/src/content/docs/protocol/models/${model}.mdx`, - ), - "utf-8", - ); + const text = readPage(model); const target = text.match( /To validate a payload, use [^`]*`(\/[^`]+)`/, )?.[1]; @@ -401,7 +408,7 @@ describe("the Form and Competition docs pages", () => { it("links and recommends only files a normal resolver can follow", async () => { for (const download of [ - form.jsonSchema.file.path, + formFiles.jsonSchema, validationTarget("form"), validationTarget("competition"), ]) { diff --git a/website/__tests__/lib/schema/schema-doc-mapper.spec.ts b/website/__tests__/lib/schema/schema-doc-mapper.spec.ts new file mode 100644 index 000000000..3b2207a81 --- /dev/null +++ b/website/__tests__/lib/schema/schema-doc-mapper.spec.ts @@ -0,0 +1,122 @@ +import { describe, it, expect, beforeAll, afterAll } from "vitest"; +import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from "fs"; +import { tmpdir } from "os"; +import * as path from "path"; +import { + buildSchemaDocMap, + SchemaDocMapper, +} from "@/lib/schema/schema-doc-mapper"; + +describe("buildSchemaDocMap", () => { + let contentDir: string; + + /** Writes a page under the temporary docs directory. */ + function writePage(relativePath: string, content: string): void { + const file = path.join(contentDir, relativePath); + mkdirSync(path.dirname(file), { recursive: true }); + writeFileSync(file, content); + } + + beforeAll(() => { + contentDir = mkdtempSync(path.join(tmpdir(), "schema-doc-map-")); + + writePage( + "protocol/models/award.mdx", + [ + "---", + "title: Award", + "---", + "", + "## AwardBase", + "", + '', + "", + "", + "", + "## AwdIds", + "", + '', + "", + "## A template, which has no JSON Schema", + "", + '', + ].join("\n"), + ); + + writePage( + "protocol/types/string.mdx", + [ + "---", + "title: String types", + "url:", + " jsonSchema:", + " code: |", + " $id: url.yaml", + " type: string", + "---", + "", + "", + "", + '', + ].join("\n"), + ); + + // Sorts before types/, so types/string.mdx wins for `email`. + writePage( + "protocol/fields/email.mdx", + '\n', + ); + }); + + afterAll(() => { + rmSync(contentDir, { recursive: true, force: true }); + }); + + it("maps each schema a page names to that page", () => { + const map = buildSchemaDocMap( + path.join(contentDir, "protocol"), + contentDir, + ); + expect(map.get("AwardBase")).toBe("/protocol/models/award"); + expect(map.get("AwdIds")).toBe("/protocol/models/award"); + expect(map.get("ExtensibleEnumT")).toBeUndefined(); + }); + + it("maps an inline schema's JSON type to its page as well", () => { + const map = buildSchemaDocMap( + path.join(contentDir, "protocol"), + contentDir, + ); + expect(map.get("url")).toBe("/protocol/types/string"); + expect(map.get("string")).toBe("/protocol/types/string"); + }); + + it("lets the later page win when two pages name the same schema", () => { + const map = buildSchemaDocMap( + path.join(contentDir, "protocol"), + contentDir, + ); + expect(map.get("email")).toBe("/protocol/types/string"); + }); +}); + +describe("SchemaDocMapper", () => { + it("builds the map from the real protocol pages", () => { + SchemaDocMapper.clearCache(); + expect(SchemaDocMapper.getSchemaDocPath("OrgRef")).toBe( + "/protocol/models/organization", + ); + expect(SchemaDocMapper.getSchemaDocPath("Money")).toBe( + "/protocol/fields/money", + ); + expect(SchemaDocMapper.getSchemaDocPath("PaginatedResultsInfo")).toBe( + "/protocol/pagination", + ); + expect(SchemaDocMapper.getSchemaDocPath("string")).toBe( + "/protocol/types/string", + ); + }); +}); diff --git a/website/package.json b/website/package.json index 80e93bd22..c63666d1b 100644 --- a/website/package.json +++ b/website/package.json @@ -14,10 +14,7 @@ "typespec:prune-tags": "tsx src/scripts/prune-openapi-tags.ts", "typespec:extensions": "tsp compile src/specs/extensions/index.tsp --emit @typespec/json-schema --option \"@typespec/json-schema.seal-object-schemas=false\" && mkdir -p .extension-schemas && cp tsp-output/@typespec/json-schema/** .extension-schemas", "typespec:clear-output": "rm -rf tsp-output && rm -rf public/schemas/yaml/* && rm -rf public/openapi/* && rm -rf .extension-schemas", - "generate": "pnpm generate:schema-docs && pnpm generate:schema-metadata && pnpm generate:type-formatting && pnpm generate:versioned-schemas && pnpm generate:plugin-metadata && pnpm generate:mock-server", - "generate:schema-docs": "tsx src/scripts/generate-schema-docs.ts", - "generate:schema-metadata": "tsx src/scripts/generate-schema-metadata.ts", - "generate:type-formatting": "tsx src/scripts/generate-type-formatting.ts", + "generate": "pnpm generate:versioned-schemas && pnpm generate:plugin-metadata && pnpm generate:mock-server", "generate:versioned-schemas": "tsx src/scripts/generate-versioned-schemas.ts", "generate:plugin-metadata": "tsx src/scripts/fetch-plugin-metadata.ts", "generate:mock-server": "tsx src/scripts/inject-mock-server.ts", diff --git a/website/src/components/SchemaFormatTabs.astro b/website/src/components/SchemaFormatTabs.astro index 68642bb5c..1b66a7854 100644 --- a/website/src/components/SchemaFormatTabs.astro +++ b/website/src/components/SchemaFormatTabs.astro @@ -5,46 +5,68 @@ import { readFileSync } from "fs"; import { join } from "path"; import { Paths } from "../lib/schema/paths"; import { generateSchemaExample } from "../lib/schema/example-generator"; +import { schemaFilePath } from "../lib/schema/schema-files"; +import { + findSnippet, + sourceUrl, + type SourceLanguage, +} from "../lib/schema/source-declarations"; /** - * Configuration for a code block to be displayed in a tab. - * Either provide a literal code string or a file path with optional line range. + * A literal code block, or a file to read whole. Pages give literal code for + * hand-written examples and inline JSON Schemas; the custom field catalog + * gives a file. */ interface CodeBlockConfig { - /** A literal code block to display. If provided, file properties are ignored. */ + /** A literal code block to display. If provided, file is ignored. */ code?: string; - /** Configuration for reading code from a file */ + /** A file to display, by its path relative to the repository root */ file?: { - /** Path to the file relative to the repository root */ path: string; - /** Starting line number (1-based) to extract code from */ - startLine?: number; - /** Ending line number (1-based) to extract code from */ - endLine?: number; }; } +/** + * A source code tab: `true` shows the declaration named after the schema + * (`Money` in TypeSpec and Python, `MoneySchema` in TypeScript); a string + * names the declaration to show, for code named differently from the schema; + * a list of names shows several declarations from one file, such as a + * template and the model built from it. + */ +type SourceTab = true | string | string[]; + /** * Props for the SchemaFormatTabs component. - * Each prop represents a different tab that can be displayed. + * + * Name a schema with `schema` and the Example and JSON Schema tabs come from + * its generated JSON Schema file. Each source tab listed is found by name in + * the TypeSpec or SDK source; the build fails if it can't be found. */ interface Props { - /** Example JSON code block to display in the "Example" tab */ + /** The schema's name, which is also the name of its generated JSON Schema file */ + schema?: string; + /** Example JSON: literal code overrides the example generated from the schema */ example?: CodeBlockConfig; - /** JSON Schema code block to display in the "JSON Schema" tab */ + /** JSON Schema: literal code for schemas with no generated file */ jsonSchema?: CodeBlockConfig; - /** TypeSpec code block to display in the "TypeSpec" tab */ - typeSpec?: CodeBlockConfig; - /** Python code block to display in the "Python" tab */ - python?: CodeBlockConfig; - /** TypeScript code block to display in the "TypeScript" tab */ - typescript?: CodeBlockConfig; + /** TypeSpec tab */ + typeSpec?: SourceTab; + /** Python tab */ + python?: SourceTab; + /** TypeScript tab */ + typescript?: SourceTab; } -const { example, jsonSchema, typeSpec, python, typescript } = Astro.props; +const { schema, example, jsonSchema, typeSpec, python, typescript } = + Astro.props; + +// The schema file the Example and JSON Schema tabs read, if the page named one +const schemaPath = schema && !jsonSchema ? schemaFilePath(schema) : undefined; +const jsonSchemaConfig: CodeBlockConfig | undefined = + jsonSchema ?? (schemaPath ? { file: { path: schemaPath } } : undefined); // Validate that at least one tab is provided -if (!example && !jsonSchema && !typeSpec && !python) { +if (!example && !jsonSchemaConfig && !typeSpec && !python && !typescript) { throw new Error("SchemaFormatTabs requires at least one tab to be provided"); } @@ -52,16 +74,33 @@ const exampleCode = example?.code ? example.code : example?.file?.path ? await generateSchemaExample(example.file.path) - : null; -const jsonSchemaCode = jsonSchema ? extractCode(jsonSchema) : null; -const typeSpecCode = typeSpec ? extractCode(typeSpec) : null; -const pythonCode = python ? extractCode(python) : null; -const typescriptCode = typescript ? extractCode(typescript) : null; + : schemaPath + ? await generateSchemaExample(schemaPath) + : null; +const jsonSchemaCode = jsonSchemaConfig ? extractCode(jsonSchemaConfig) : null; +const jsonSchemaUrl = jsonSchemaConfig + ? extractSchemaUrl(jsonSchemaConfig) + : null; + +const typeSpecSnippet = snippet("typeSpec", typeSpec); +const pythonSnippet = snippet("python", python); +const typescriptSnippet = snippet("typescript", typescript); -const jsonSchemaUrl = jsonSchema ? extractSchemaUrl(jsonSchema) : null; -const typeSpecUrl = typeSpec ? extractGithubUrl(typeSpec) : null; -const pythonUrl = python ? extractGithubUrl(python) : null; -const typescriptUrl = typescript ? extractGithubUrl(typescript) : null; +/** + * Finds the declaration a source tab shows. + * @returns The declaration's code and a link to it, or null if the tab isn't shown + * @throws Error if the declaration can't be found + */ +function snippet( + language: SourceLanguage, + requested: SourceTab | undefined, +): { code: string; url: string } | null { + if (!requested) { + return null; + } + const declaration = findSnippet(language, requested, schema); + return { code: declaration.code, url: sourceUrl(declaration) }; +} /** * Constructs a schema URL from file path. @@ -89,31 +128,6 @@ function extractSchemaUrl(props: CodeBlockConfig): string | null { return `/${filePath}`; } -/** - * Extracts a GitHub URL from file configuration. - * @param props - The code block configuration - * @returns The GitHub URL for the file, or null if no file is specified - */ -function extractGithubUrl(props: CodeBlockConfig): string | null { - if (!props.file) { - return null; - } - - const baseUrl = "https://github.com/HHS/simpler-grants-protocol/tree/main/"; - let url = `${baseUrl}/${props.file.path}`; - - if (props.file.startLine || props.file.endLine) { - const start = props.file.startLine || 1; - const end = props.file.endLine || start; - url += `#L${start}`; - if (end > start) { - url += `-L${end}`; - } - } - - return url; -} - /** * Extracts code from either a literal string or a file. * @param props - The code block configuration @@ -126,17 +140,7 @@ function extractCode(props: CodeBlockConfig): string { } if (props.file) { try { - const filePath = join(Paths.REPO_ROOT, props.file.path); - const content = readFileSync(filePath, "utf-8"); - - if (props.file.startLine || props.file.endLine) { - const lines = content.split("\n"); - const start = props.file.startLine ? props.file.startLine - 1 : 0; - const end = props.file.endLine ? props.file.endLine : lines.length; - return lines.slice(start, end).join("\n"); - } - - return content; + return readFileSync(join(Paths.REPO_ROOT, props.file.path), "utf-8"); } catch (error) { throw new Error(`Error reading file ${props.file.path}: ${error}`, { cause: error, @@ -177,44 +181,52 @@ function extractCode(props: CodeBlockConfig): string { ) } { - typeSpecCode && ( + typeSpecSnippet && (

{"The "} - + TypeSpec code {" for this model."}

- +
) } { - pythonCode && ( + pythonSnippet && (

{"The "} - + Python code {" for this model."}

- +
) } { - typescriptCode && ( + typescriptSnippet && (

{"The "} - + TypeScript code {" for this model."}

- +
) } diff --git a/website/src/components/SchemaTable.astro b/website/src/components/SchemaTable.astro index e83e1bbb9..aaedf1107 100644 --- a/website/src/components/SchemaTable.astro +++ b/website/src/components/SchemaTable.astro @@ -3,16 +3,19 @@ import { SchemaLoader } from "../lib/schema/schema-loader"; import type { JsonSchema } from "../lib/schema/schema-loader"; import { SchemaDocMapper } from "../lib/schema/schema-doc-mapper"; import { TableGenerator } from "../lib/schema/table-generator"; +import { schemaFilePath } from "../lib/schema/schema-files"; import type { PropertyRow, EnumRow } from "../lib/schema/table-generator"; -const { filePath, code } = Astro.props; +const { schema, version, code } = Astro.props; /** * Props for the SchemaTable component. */ interface Props { - /** Path to the schema file relative to the repository root */ - filePath?: string; + /** The schema's name, which is also the name of its generated JSON Schema file */ + schema?: string; + /** Read the schema's copy for one protocol version (e.g. "v0.5.0") instead */ + version?: string; /** Inline schema code (YAML string) */ code?: string; } @@ -29,12 +32,12 @@ const getSchemaDocPath = (schemaName: string): string | undefined => { // Load and parse the schema let schemaData: JsonSchema; try { - if (filePath) { - schemaData = SchemaLoader.loadSchema(filePath); + if (schema) { + schemaData = SchemaLoader.loadSchema(schemaFilePath(schema, version)); } else if (code) { schemaData = SchemaLoader.loadInlineSchema(code); } else { - throw new Error("Either filePath or code must be provided"); + throw new Error("Either schema or code must be provided"); } } catch (error) { console.error(`Loading schema:`, error); diff --git a/website/src/content/docs/protocol/fields/address.mdx b/website/src/content/docs/protocol/fields/address.mdx index 0f59a849a..1936a6211 100644 --- a/website/src/content/docs/protocol/fields/address.mdx +++ b/website/src/content/docs/protocol/fields/address.mdx @@ -1,30 +1,6 @@ --- title: Address description: Data model for an address -address: - example: - file: - path: "website/public/schemas/yaml/Address.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/Address.yaml" - typeSpec: - file: - path: "lib/core/lib/core/fields/address.tsp" - startLine: 3 - endLine: 33 -addressCollection: - example: - file: - path: "website/public/schemas/yaml/AddressCollection.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/AddressCollection.yaml" - typeSpec: - file: - path: "lib/core/lib/core/fields/address.tsp" - startLine: 35 - endLine: 45 --- import SchemaFormatTabs from "@/components/SchemaFormatTabs.astro"; @@ -35,15 +11,11 @@ An address is a physical location. ### Table - + ### Formats - + ### Changelog @@ -55,15 +27,11 @@ A collection of addresses for a person or organization. ### Table - + ### Formats - + ### Changelog diff --git a/website/src/content/docs/protocol/fields/custom-field.mdx b/website/src/content/docs/protocol/fields/custom-field.mdx index a50b4d83b..8f1363564 100644 --- a/website/src/content/docs/protocol/fields/custom-field.mdx +++ b/website/src/content/docs/protocol/fields/custom-field.mdx @@ -1,49 +1,9 @@ --- title: CustomField description: A model for defining custom fields that are specific to a given implementation -customField: - example: - file: - path: "website/public/schemas/yaml/CustomField.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/CustomField.yaml" - typeSpec: - file: - path: "lib/core/lib/core/fields/custom-field.tsp" - startLine: 47 - endLine: 64 - python: - file: - path: "lib/python-sdk/common_grants_sdk/schemas/pydantic/fields/custom.py" - startLine: 23 - endLine: 45 - typescript: - file: - path: "lib/ts-sdk/src/schemas/zod/fields.ts" - startLine: 103 - endLine: 118 customFieldType: example: code: "string" - jsonSchema: - file: - path: "website/public/schemas/yaml/CustomFieldType.yaml" - typeSpec: - file: - path: "lib/core/lib/core/fields/custom-field.tsp" - startLine: 7 - endLine: 16 - python: - file: - path: "lib/python-sdk/common_grants_sdk/schemas/pydantic/fields/custom.py" - startLine: 12 - endLine: 20 - typescript: - file: - path: "lib/ts-sdk/src/schemas/zod/fields.ts" - startLine: 94 - endLine: 101 --- import SchemaFormatTabs from "@/components/SchemaFormatTabs.astro"; @@ -65,13 +25,7 @@ A model for defining custom fields on a record. ### Formats - + ### Changelog @@ -95,11 +49,11 @@ The set of JSON schema types supported by a custom field. ### Formats ### Changelog diff --git a/website/src/content/docs/protocol/fields/email.mdx b/website/src/content/docs/protocol/fields/email.mdx index 81d558beb..fdf2eab35 100644 --- a/website/src/content/docs/protocol/fields/email.mdx +++ b/website/src/content/docs/protocol/fields/email.mdx @@ -4,26 +4,6 @@ description: Data model for an email address email: example: code: '"john.doe@example.com"' - jsonSchema: - file: - path: "website/public/schemas/yaml/email.yaml" - typeSpec: - file: - path: "lib/core/lib/core/fields/email.tsp" - startLine: 5 - endLine: 6 -emailCollection: - example: - file: - path: "website/public/schemas/yaml/EmailCollection.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/EmailCollection.yaml" - typeSpec: - file: - path: "lib/core/lib/core/fields/email.tsp" - startLine: 8 - endLine: 17 --- import SchemaFormatTabs from "@/components/SchemaFormatTabs.astro"; @@ -35,9 +15,9 @@ An email address. Alias for the [email](/protocol/types/string#email) type. ### Formats ## EmailCollection @@ -46,15 +26,11 @@ A collection of email addresses for a person or organization. ### Table - + ### Formats - + ### Changelog diff --git a/website/src/content/docs/protocol/fields/event.mdx b/website/src/content/docs/protocol/fields/event.mdx index 86be00d56..450493ad7 100644 --- a/website/src/content/docs/protocol/fields/event.mdx +++ b/website/src/content/docs/protocol/fields/event.mdx @@ -1,138 +1,6 @@ --- title: Event description: A comprehensive model for representing various types of events with dates, date ranges, and custom event types -eventType: - example: - file: - path: "website/public/schemas/yaml/EventType.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/EventType.yaml" - typeSpec: - file: - path: "lib/core/lib/core/fields/event.tsp" - startLine: 11 - endLine: 27 - python: - file: - path: "lib/python-sdk/common_grants_sdk/schemas/pydantic/fields/event.py" - startLine: 13 - endLine: 18 - typescript: - file: - path: "lib/ts-sdk/src/schemas/zod/fields.ts" - startLine: 15 - endLine: 15 -event: - example: - file: - path: "website/public/schemas/yaml/Event.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/Event.yaml" - typeSpec: - file: - path: "lib/core/lib/core/fields/event.tsp" - startLine: 33 - endLine: 45 - python: - file: - path: "lib/python-sdk/common_grants_sdk/schemas/pydantic/fields/event.py" - startLine: 104 - endLine: 104 - typescript: - file: - path: "lib/ts-sdk/src/schemas/zod/fields.ts" - startLine: 72 - endLine: 76 -eventBase: - example: - file: - path: "website/public/schemas/yaml/EventBase.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/EventBase.yaml" - typeSpec: - file: - path: "lib/core/lib/core/fields/event.tsp" - startLine: 51 - endLine: 62 - python: - file: - path: "lib/python-sdk/common_grants_sdk/schemas/pydantic/fields/event.py" - startLine: 22 - endLine: 38 - typescript: - file: - path: "lib/ts-sdk/src/schemas/zod/fields.ts" - startLine: 18 - endLine: 27 -singleDateEvent: - example: - file: - path: "website/public/schemas/yaml/SingleDateEvent.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/SingleDateEvent.yaml" - typeSpec: - file: - path: "lib/core/lib/core/fields/event.tsp" - startLine: 68 - endLine: 81 - python: - file: - path: "lib/python-sdk/common_grants_sdk/schemas/pydantic/fields/event.py" - startLine: 42 - endLine: 56 - typescript: - file: - path: "lib/ts-sdk/src/schemas/zod/fields.ts" - startLine: 30 - endLine: 39 -dateRangeEvent: - example: - file: - path: "website/public/schemas/yaml/DateRangeEvent.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/DateRangeEvent.yaml" - typeSpec: - file: - path: "lib/core/lib/core/fields/event.tsp" - startLine: 86 - endLine: 106 - python: - file: - path: "lib/python-sdk/common_grants_sdk/schemas/pydantic/fields/event.py" - startLine: 60 - endLine: 86 - typescript: - file: - path: "lib/ts-sdk/src/schemas/zod/fields.ts" - startLine: 42 - endLine: 57 -otherEvent: - example: - file: - path: "website/public/schemas/yaml/OtherEvent.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/OtherEvent.yaml" - typeSpec: - file: - path: "lib/core/lib/core/fields/event.tsp" - startLine: 112 - endLine: 125 - python: - file: - path: "lib/python-sdk/common_grants_sdk/schemas/pydantic/fields/event.py" - startLine: 90 - endLine: 100 - typescript: - file: - path: "lib/ts-sdk/src/schemas/zod/fields.ts" - startLine: 60 - endLine: 69 --- import SchemaFormatTabs from "@/components/SchemaFormatTabs.astro"; @@ -155,11 +23,10 @@ Defines the different types of events that can be represented ### Formats ### Changelog @@ -180,13 +47,7 @@ The `Event` union represents all possible event types. ### Formats - + {/* TODO: Add changelog once unions are supported */} @@ -204,13 +65,7 @@ Base model for all events with common properties ### Formats - + ### Changelog @@ -232,13 +87,7 @@ Represents an event that has a specific date (and optional time) associated with ### Formats - + ### Changelog @@ -262,13 +111,7 @@ Represents an event that spans a period of time with start and end dates (and op ### Formats - + ### Changelog @@ -289,13 +132,7 @@ Represents custom events that don't fit the single date or date range patterns. ### Formats - + ### Changelog diff --git a/website/src/content/docs/protocol/fields/extensible-enum.mdx b/website/src/content/docs/protocol/fields/extensible-enum.mdx index 15a755c12..1ee78dbd0 100644 --- a/website/src/content/docs/protocol/fields/extensible-enum.mdx +++ b/website/src/content/docs/protocol/fields/extensible-enum.mdx @@ -1,24 +1,6 @@ --- title: ExtensibleEnum description: A value from a predefined set of options, with support for custom values -extensibleEnum: - example: - file: - path: "website/public/schemas/yaml/ExtensibleEnum.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/ExtensibleEnum.yaml" - typeSpec: - file: - path: "lib/core/lib/core/fields/extensible-enum.tsp" - startLine: 39 - endLine: 47 -extensibleEnumT: - typeSpec: - file: - path: "lib/core/lib/core/fields/extensible-enum.tsp" - startLine: 7 - endLine: 37 --- import SchemaFormatTabs from "@/components/SchemaFormatTabs.astro"; @@ -51,7 +33,7 @@ model OppStatus is Fields.ExtensibleEnumT; ### Formats - + ## ExtensibleEnum @@ -68,11 +50,7 @@ The base model for this pattern, derived from the template with an unconstrained ### Formats - + ### Changelog diff --git a/website/src/content/docs/protocol/fields/file.mdx b/website/src/content/docs/protocol/fields/file.mdx index a0a48dcca..e14b7db49 100644 --- a/website/src/content/docs/protocol/fields/file.mdx +++ b/website/src/content/docs/protocol/fields/file.mdx @@ -1,18 +1,6 @@ --- title: File description: Data model for a file attachment. -file: - example: - file: - path: "website/public/schemas/yaml/File.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/File.yaml" - typeSpec: - file: - path: "lib/core/lib/core/fields/file.tsp" - startLine: 3 - endLine: 25 --- import SchemaFormatTabs from "@/components/SchemaFormatTabs.astro"; @@ -23,15 +11,11 @@ A file attachment. ### Table - + ### Formats - + ### Changelog diff --git a/website/src/content/docs/protocol/fields/identifier.mdx b/website/src/content/docs/protocol/fields/identifier.mdx index 38e90c4b5..4bf99230b 100644 --- a/website/src/content/docs/protocol/fields/identifier.mdx +++ b/website/src/content/docs/protocol/fields/identifier.mdx @@ -1,42 +1,6 @@ --- title: Identifier description: Models for representing registry-issued identifiers on a record -identifier: - example: - file: - path: "website/public/schemas/yaml/Identifier.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/Identifier.yaml" - typeSpec: - file: - path: "lib/core/lib/core/fields/identifier.tsp" - startLine: 17 - endLine: 62 -systemId: - example: - file: - path: "website/public/schemas/yaml/SystemId.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/SystemId.yaml" - typeSpec: - file: - path: "lib/core/lib/core/fields/identifier.tsp" - startLine: 64 - endLine: 71 -identifierCollection: - example: - file: - path: "website/public/schemas/yaml/IdentifierCollection.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/IdentifierCollection.yaml" - typeSpec: - file: - path: "lib/core/lib/core/fields/identifier.tsp" - startLine: 77 - endLine: 88 --- import SchemaFormatTabs from "@/components/SchemaFormatTabs.astro"; @@ -55,14 +19,13 @@ Identifiers are keyed by their canonical CommonGrants registry code ### Table - + ### Formats ### Changelog @@ -78,15 +41,11 @@ through their `systemId` field. ### Table - + ### Formats - + ### Changelog @@ -102,15 +61,11 @@ and [OppIds](/protocol/models/opportunity#oppids)) extend it with their base ide ### Table - + ### Formats - + ### Changelog diff --git a/website/src/content/docs/protocol/fields/metadata.mdx b/website/src/content/docs/protocol/fields/metadata.mdx index f98e4b6be..3026eaf41 100644 --- a/website/src/content/docs/protocol/fields/metadata.mdx +++ b/website/src/content/docs/protocol/fields/metadata.mdx @@ -1,28 +1,6 @@ --- title: SystemMetadata description: System-managed metadata for records -systemMetadata: - example: - file: - path: "website/public/schemas/yaml/SystemMetadata.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/SystemMetadata.yaml" - typeSpec: - file: - path: "lib/core/lib/core/fields/metadata.tsp" - startLine: 21 - endLine: 31 - python: - file: - path: "lib/python-sdk/common_grants_sdk/schemas/pydantic/fields/metadata.py" - startLine: 10 - endLine: 22 - typescript: - file: - path: "lib/ts-sdk/src/schemas/zod/fields.ts" - startLine: 124 - endLine: 130 --- import SchemaFormatTabs from "@/components/SchemaFormatTabs.astro"; @@ -33,17 +11,11 @@ System-managed metadata that is automatically added to records. ### Table - + ### Formats - + ### Changelog diff --git a/website/src/content/docs/protocol/fields/money.mdx b/website/src/content/docs/protocol/fields/money.mdx index dedf1c253..fa73cf02c 100644 --- a/website/src/content/docs/protocol/fields/money.mdx +++ b/website/src/content/docs/protocol/fields/money.mdx @@ -1,28 +1,6 @@ --- title: Money description: A model for representing monetary values -money: - example: - file: - path: "website/public/schemas/yaml/Money.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/Money.yaml" - typeSpec: - file: - path: "lib/core/lib/core/fields/money.tsp" - startLine: 21 - endLine: 29 - python: - file: - path: "lib/python-sdk/common_grants_sdk/schemas/pydantic/fields/money.py" - startLine: 10 - endLine: 22 - typescript: - file: - path: "lib/ts-sdk/src/schemas/zod/fields.ts" - startLine: 82 - endLine: 88 --- import SchemaFormatTabs from "@/components/SchemaFormatTabs.astro"; @@ -33,17 +11,11 @@ A monetary amount and the currency in which it is denominated. ### Table - + ### Formats - + ### Changelog diff --git a/website/src/content/docs/protocol/fields/name.mdx b/website/src/content/docs/protocol/fields/name.mdx index aed17aad2..32acb60bf 100644 --- a/website/src/content/docs/protocol/fields/name.mdx +++ b/website/src/content/docs/protocol/fields/name.mdx @@ -1,18 +1,6 @@ --- title: Name description: Data model for a person's name -name: - example: - file: - path: "website/public/schemas/yaml/Name.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/Name.yaml" - typeSpec: - file: - path: "lib/core/lib/core/fields/name.tsp" - startLine: 3 - endLine: 21 --- import SchemaFormatTabs from "@/components/SchemaFormatTabs.astro"; @@ -23,15 +11,11 @@ A person's name. ### Table - + ### Formats - + ### Changelog diff --git a/website/src/content/docs/protocol/fields/pcs.mdx b/website/src/content/docs/protocol/fields/pcs.mdx index 57f44e477..6eb0c0e52 100644 --- a/website/src/content/docs/protocol/fields/pcs.mdx +++ b/website/src/content/docs/protocol/fields/pcs.mdx @@ -1,90 +1,6 @@ --- title: PCS term description: A Philanthropy Classification System (PCS) term. -pcsTerm: - example: - file: - path: "website/public/schemas/yaml/PCSTerm.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/PCSTerm.yaml" - typeSpec: - file: - path: "lib/core/lib/core/fields/pcs.tsp" - startLine: 15 - endLine: 32 -pcsClass: - example: - file: - path: "website/public/schemas/yaml/PCSClass.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/PCSClass.yaml" - typeSpec: - file: - path: "lib/core/lib/core/fields/pcs.tsp" - startLine: 37 - endLine: 46 -pcsOrgType: - example: - file: - path: "website/public/schemas/yaml/PCSOrgType.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/PCSOrgType.yaml" - typeSpec: - file: - path: "lib/core/lib/core/fields/pcs.tsp" - startLine: 51 - endLine: 59 -pcsSubject: - example: - file: - path: "website/public/schemas/yaml/PCSSubject.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/PCSSubject.yaml" - typeSpec: - file: - path: "lib/core/lib/core/fields/pcs.tsp" - startLine: 61 - endLine: 69 -pcsPopulation: - example: - file: - path: "website/public/schemas/yaml/PCSPopulation.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/PCSPopulation.yaml" - typeSpec: - file: - path: "lib/core/lib/core/fields/pcs.tsp" - startLine: 71 - endLine: 79 -pcsSupportStrategy: - example: - file: - path: "website/public/schemas/yaml/PCSSupportStrategy.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/PCSSupportStrategy.yaml" - typeSpec: - file: - path: "lib/core/lib/core/fields/pcs.tsp" - startLine: 81 - endLine: 89 -pcsTransactionType: - example: - file: - path: "website/public/schemas/yaml/PCSTransactionType.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/PCSTransactionType.yaml" - typeSpec: - file: - path: "lib/core/lib/core/fields/pcs.tsp" - startLine: 91 - endLine: 99 --- import SchemaFormatTabs from "@/components/SchemaFormatTabs.astro"; @@ -107,11 +23,7 @@ Visit [taxonomy.candid.org](https://taxonomy.candid.org/) for more information. ### Formats - + ### Changelog @@ -133,11 +45,7 @@ The class to which the PCS term belongs. ### Formats - + ## Sub-types @@ -155,11 +63,7 @@ A [PCSTerm](#pcsterm) where the `class` is `"Organization types"`. Categorizes t See [PCS organization types](https://taxonomy.candid.org/organization-type) for more information. - + ### PCSSubject @@ -167,11 +71,7 @@ A [PCSTerm](#pcsterm) where the `class` is `"Subjects"`. Categorizes the subject See [PCS subjects](https://taxonomy.candid.org/subject) for more information. - + ### PCSPopulation @@ -179,11 +79,7 @@ A [PCSTerm](#pcsterm) where the `class` is `"Population groups"`. Categorizes th See [PCS population groups](https://taxonomy.candid.org/population-group) for more information. - + ### PCSSupportStrategy @@ -191,11 +87,7 @@ A [PCSTerm](#pcsterm) where the `class` is `"Support strategies"`. Categorizes t See [PCS support strategies](https://taxonomy.candid.org/support-strategy) for more information. - + ### PCSTransactionType @@ -203,8 +95,4 @@ A [PCSTerm](#pcsterm) where the `class` is `"Transaction types"`. Categorizes th See [PCS transaction types](https://taxonomy.candid.org/transaction-type) for more information. - + diff --git a/website/src/content/docs/protocol/fields/phone.mdx b/website/src/content/docs/protocol/fields/phone.mdx index d0762f7af..25e6d4cf8 100644 --- a/website/src/content/docs/protocol/fields/phone.mdx +++ b/website/src/content/docs/protocol/fields/phone.mdx @@ -1,30 +1,6 @@ --- title: Phone description: A model for representing a phone number -phone: - example: - file: - path: "website/public/schemas/yaml/Phone.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/Phone.yaml" - typeSpec: - file: - path: "lib/core/lib/core/fields/phone.tsp" - startLine: 3 - endLine: 20 -phoneCollection: - example: - file: - path: "website/public/schemas/yaml/PhoneCollection.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/PhoneCollection.yaml" - typeSpec: - file: - path: "lib/core/lib/core/fields/phone.tsp" - startLine: 26 - endLine: 39 --- import SchemaFormatTabs from "@/components/SchemaFormatTabs.astro"; @@ -35,15 +11,11 @@ A phone number. ### Table - + ### Formats - + ### Changelog @@ -55,15 +27,11 @@ A collection of phone numbers for a person or organization. ### Table - + ### Formats - + ### Changelog diff --git a/website/src/content/docs/protocol/filters/base.mdx b/website/src/content/docs/protocol/filters/base.mdx index f69ac5068..0502c4f77 100644 --- a/website/src/content/docs/protocol/filters/base.mdx +++ b/website/src/content/docs/protocol/filters/base.mdx @@ -1,138 +1,6 @@ --- title: Base filters description: Base models used to build field-specific filters. -defaultFilter: - example: - file: - path: "website/public/schemas/yaml/DefaultFilter.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/DefaultFilter.yaml" - typeSpec: - file: - path: "lib/core/lib/core/filters/base.tsp" - startLine: 75 - endLine: 89 - python: - file: - path: "lib/python-sdk/common_grants_sdk/schemas/pydantic/filters/base.py" - startLine: 57 - endLine: 70 - typescript: - file: - path: "lib/ts-sdk/src/schemas/zod/filters.ts" - startLine: 30 - endLine: 33 -equivalenceOperators: - example: - file: - path: "website/public/schemas/yaml/EquivalenceOperators.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/EquivalenceOperators.yaml" - typeSpec: - file: - path: "lib/core/lib/core/filters/base.tsp" - startLine: 7 - endLine: 15 - python: - file: - path: "lib/python-sdk/common_grants_sdk/schemas/pydantic/filters/base.py" - startLine: 15 - endLine: 19 - typescript: - file: - path: "lib/ts-sdk/src/schemas/zod/filters.ts" - startLine: 13 - endLine: 13 -comparisonOperators: - example: - file: - path: "website/public/schemas/yaml/ComparisonOperators.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/ComparisonOperators.yaml" - typeSpec: - file: - path: "lib/core/lib/core/filters/base.tsp" - startLine: 17 - endLine: 30 - python: - file: - path: "lib/python-sdk/common_grants_sdk/schemas/pydantic/filters/base.py" - startLine: 22 - endLine: 28 - typescript: - file: - path: "lib/ts-sdk/src/schemas/zod/filters.ts" - startLine: 14 - endLine: 14 -stringOperators: - example: - file: - path: "website/public/schemas/yaml/StringOperators.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/StringOperators.yaml" - typeSpec: - file: - path: "lib/core/lib/core/filters/base.tsp" - startLine: 43 - endLine: 50 - python: - file: - path: "lib/python-sdk/common_grants_sdk/schemas/pydantic/filters/base.py" - startLine: 38 - endLine: 42 - typescript: - file: - path: "lib/ts-sdk/src/schemas/zod/filters.ts" - startLine: 16 - endLine: 16 -arrayOperators: - example: - file: - path: "website/public/schemas/yaml/ArrayOperators.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/ArrayOperators.yaml" - typeSpec: - file: - path: "lib/core/lib/core/filters/base.tsp" - startLine: 33 - endLine: 41 - python: - file: - path: "lib/python-sdk/common_grants_sdk/schemas/pydantic/filters/base.py" - startLine: 31 - endLine: 35 - typescript: - file: - path: "lib/ts-sdk/src/schemas/zod/filters.ts" - startLine: 15 - endLine: 15 -rangeOperators: - example: - file: - path: "website/public/schemas/yaml/RangeOperators.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/RangeOperators.yaml" - typeSpec: - file: - path: "lib/core/lib/core/filters/base.tsp" - startLine: 52 - endLine: 59 - python: - file: - path: "lib/python-sdk/common_grants_sdk/schemas/pydantic/filters/base.py" - startLine: 45 - endLine: 49 - typescript: - file: - path: "lib/ts-sdk/src/schemas/zod/filters.ts" - startLine: 17 - endLine: 17 --- import SchemaFormatTabs from "@/components/SchemaFormatTabs.astro"; @@ -151,13 +19,7 @@ The default filter model is a base model that can be used to create more specifi ### Formats - + ## EquivalenceOperators @@ -179,11 +41,10 @@ Operators that filter a field based on an exact match to a value. Supported valu ### Formats ## ComparisonOperators @@ -206,11 +67,10 @@ Operators that filter a field based on a comparison to a value. Supported value ### Formats ## StringOperators @@ -227,11 +87,10 @@ Operators that filter a field based on a string value. ### Formats ## ArrayOperators @@ -251,11 +110,10 @@ Operators that filter a field based on an array of values. Supported value types ### Formats ## RangeOperators @@ -276,9 +134,8 @@ Operators that filter a field based on a range of values. Supported value types ### Formats diff --git a/website/src/content/docs/protocol/filters/boolean.mdx b/website/src/content/docs/protocol/filters/boolean.mdx index 5c851dde1..313e352c5 100644 --- a/website/src/content/docs/protocol/filters/boolean.mdx +++ b/website/src/content/docs/protocol/filters/boolean.mdx @@ -1,28 +1,6 @@ --- title: Boolean filters description: Filters that can be applied to boolean fields. -booleanComparisonFilter: - example: - file: - path: "website/public/schemas/yaml/BooleanComparisonFilter.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/BooleanComparisonFilter.yaml" - typeSpec: - file: - path: "lib/core/lib/core/filters/boolean.tsp" - startLine: 9 - endLine: 18 - python: - file: - path: "lib/python-sdk/common_grants_sdk/schemas/pydantic/filters/boolean.py" - startLine: 9 - endLine: 31 - typescript: - file: - path: "lib/ts-sdk/src/schemas/zod/filters.ts" - startLine: 114 - endLine: 117 --- import SchemaFormatTabs from "@/components/SchemaFormatTabs.astro"; @@ -41,13 +19,7 @@ A filter that applies a comparison to a boolean value. ### Formats - + ### Changelog diff --git a/website/src/content/docs/protocol/filters/date.mdx b/website/src/content/docs/protocol/filters/date.mdx index ba538a0da..b244bbc19 100644 --- a/website/src/content/docs/protocol/filters/date.mdx +++ b/website/src/content/docs/protocol/filters/date.mdx @@ -1,50 +1,6 @@ --- title: Date filters description: Filters applied to date fields. -dateRangeFilter: - example: - file: - path: "website/public/schemas/yaml/DateRangeFilter.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/DateRangeFilter.yaml" - typeSpec: - file: - path: "lib/core/lib/core/filters/date.tsp" - startLine: 24 - endLine: 39 - python: - file: - path: "lib/python-sdk/common_grants_sdk/schemas/pydantic/filters/date.py" - startLine: 37 - endLine: 52 - typescript: - file: - path: "lib/ts-sdk/src/schemas/zod/filters.ts" - startLine: 85 - endLine: 91 -dateComparisonFilter: - example: - file: - path: "website/public/schemas/yaml/DateComparisonFilter.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/DateComparisonFilter.yaml" - typeSpec: - file: - path: "lib/core/lib/core/filters/date.tsp" - startLine: 10 - endLine: 20 - python: - file: - path: "lib/python-sdk/common_grants_sdk/schemas/pydantic/filters/date.py" - startLine: 55 - endLine: 78 - typescript: - file: - path: "lib/ts-sdk/src/schemas/zod/filters.ts" - startLine: 80 - endLine: 83 --- import SchemaFormatTabs from "@/components/SchemaFormatTabs.astro"; @@ -72,13 +28,7 @@ Filters by comparing a field to a range of date values. ### Formats - + ### Changelog @@ -97,13 +47,7 @@ Filters by comparing a field to a date value. ### Formats - + ### Changelog diff --git a/website/src/content/docs/protocol/filters/money.mdx b/website/src/content/docs/protocol/filters/money.mdx index f986e97ae..45002aa92 100644 --- a/website/src/content/docs/protocol/filters/money.mdx +++ b/website/src/content/docs/protocol/filters/money.mdx @@ -1,50 +1,6 @@ --- title: Money filters description: Filters applied to monetary values. -moneyRangeFilter: - example: - file: - path: "website/public/schemas/yaml/MoneyRangeFilter.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/MoneyRangeFilter.yaml" - typeSpec: - file: - path: "lib/core/lib/core/filters/money.tsp" - startLine: 25 - endLine: 41 - python: - file: - path: "lib/python-sdk/common_grants_sdk/schemas/pydantic/filters/money.py" - startLine: 43 - endLine: 50 - typescript: - file: - path: "lib/ts-sdk/src/schemas/zod/filters.ts" - startLine: 102 - endLine: 108 -moneyComparisonFilter: - example: - file: - path: "website/public/schemas/yaml/MoneyComparisonFilter.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/MoneyComparisonFilter.yaml" - typeSpec: - file: - path: "lib/core/lib/core/filters/money.tsp" - startLine: 10 - endLine: 20 - python: - file: - path: "lib/python-sdk/common_grants_sdk/schemas/pydantic/filters/money.py" - startLine: 72 - endLine: 87 - typescript: - file: - path: "lib/ts-sdk/src/schemas/zod/filters.ts" - startLine: 97 - endLine: 100 --- import SchemaFormatTabs from "@/components/SchemaFormatTabs.astro"; @@ -72,13 +28,7 @@ Filters by comparing a field to a range of monetary values. ### Formats - + ### Changelog @@ -97,13 +47,7 @@ Filters by comparing a field to a monetary value. ### Formats - + ### Changelog diff --git a/website/src/content/docs/protocol/filters/numeric.mdx b/website/src/content/docs/protocol/filters/numeric.mdx index e41c2f03f..1d9a9bbbb 100644 --- a/website/src/content/docs/protocol/filters/numeric.mdx +++ b/website/src/content/docs/protocol/filters/numeric.mdx @@ -1,72 +1,6 @@ --- title: Numeric filters description: Filters that can be applied to numeric fields. -numberComparisonFilter: - example: - file: - path: "website/public/schemas/yaml/NumberComparisonFilter.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/NumberComparisonFilter.yaml" - typeSpec: - file: - path: "lib/core/lib/core/filters/numeric.tsp" - startLine: 11 - endLine: 21 - python: - file: - path: "lib/python-sdk/common_grants_sdk/schemas/pydantic/filters/numeric.py" - startLine: 26 - endLine: 35 - typescript: - file: - path: "lib/ts-sdk/src/schemas/zod/filters.ts" - startLine: 53 - endLine: 56 -numberRangeFilter: - example: - file: - path: "website/public/schemas/yaml/NumberRangeFilter.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/NumberRangeFilter.yaml" - typeSpec: - file: - path: "lib/core/lib/core/filters/numeric.tsp" - startLine: 42 - endLine: 54 - python: - file: - path: "lib/python-sdk/common_grants_sdk/schemas/pydantic/filters/numeric.py" - startLine: 46 - endLine: 61 - typescript: - file: - path: "lib/ts-sdk/src/schemas/zod/filters.ts" - startLine: 58 - endLine: 64 -numberArrayFilter: - example: - file: - path: "website/public/schemas/yaml/NumberArrayFilter.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/NumberArrayFilter.yaml" - typeSpec: - file: - path: "lib/core/lib/core/filters/numeric.tsp" - startLine: 60 - endLine: 69 - python: - file: - path: "lib/python-sdk/common_grants_sdk/schemas/pydantic/filters/numeric.py" - startLine: 64 - endLine: 81 - typescript: - file: - path: "lib/ts-sdk/src/schemas/zod/filters.ts" - startLine: 66 - endLine: 69 --- import SchemaFormatTabs from "@/components/SchemaFormatTabs.astro"; @@ -85,13 +19,7 @@ Filters by comparing a field to a numeric value. ### Formats - + ### Changelog @@ -119,13 +47,7 @@ Filters by comparing a field to a range of numeric values. ### Formats - + ### Changelog @@ -144,13 +66,7 @@ Filters by comparing a field to an array of numeric values. ### Formats - + ### Changelog diff --git a/website/src/content/docs/protocol/filters/string.mdx b/website/src/content/docs/protocol/filters/string.mdx index 95c4d1780..a9dbab56f 100644 --- a/website/src/content/docs/protocol/filters/string.mdx +++ b/website/src/content/docs/protocol/filters/string.mdx @@ -1,50 +1,6 @@ --- title: String filters description: Filters that can be applied to string or enum fields. -stringComparisonFilter: - example: - file: - path: "website/public/schemas/yaml/StringComparisonFilter.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/StringComparisonFilter.yaml" - typeSpec: - file: - path: "lib/core/lib/core/filters/string.tsp" - startLine: 9 - endLine: 18 - python: - file: - path: "lib/python-sdk/common_grants_sdk/schemas/pydantic/filters/string.py" - startLine: 31 - endLine: 49 - typescript: - file: - path: "lib/ts-sdk/src/schemas/zod/filters.ts" - startLine: 39 - endLine: 42 -stringArrayFilter: - example: - file: - path: "website/public/schemas/yaml/StringArrayFilter.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/StringArrayFilter.yaml" - typeSpec: - file: - path: "lib/core/lib/core/filters/string.tsp" - startLine: 24 - endLine: 33 - python: - file: - path: "lib/python-sdk/common_grants_sdk/schemas/pydantic/filters/string.py" - startLine: 13 - endLine: 28 - typescript: - file: - path: "lib/ts-sdk/src/schemas/zod/filters.ts" - startLine: 44 - endLine: 47 --- import SchemaFormatTabs from "@/components/SchemaFormatTabs.astro"; @@ -63,13 +19,7 @@ A filter that applies a comparison to a string value. ### Formats - + ### Changelog @@ -88,13 +38,7 @@ A filter that applies a comparison to an array of string values. ### Formats - + ### Changelog diff --git a/website/src/content/docs/protocol/models/applicant-type.mdx b/website/src/content/docs/protocol/models/applicant-type.mdx index f202b3873..c62ae6e0f 100644 --- a/website/src/content/docs/protocol/models/applicant-type.mdx +++ b/website/src/content/docs/protocol/models/applicant-type.mdx @@ -10,35 +10,9 @@ applicantType: "value": "individual", "description": "An individual applicant" } - jsonSchema: - file: - path: "website/public/schemas/yaml/ApplicantType.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/applicant-type.tsp" - startLine: 7 - endLine: 11 - typescript: - file: - path: "lib/ts-sdk/src/schemas/zod/models.ts" - startLine: 54 - endLine: 65 applicantTypeOptions: example: code: '"individual"' - jsonSchema: - file: - path: "website/public/schemas/yaml/ApplicantTypeOptions.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/applicant-type.tsp" - startLine: 17 - endLine: 70 - typescript: - file: - path: "lib/ts-sdk/src/schemas/zod/models.ts" - startLine: 34 - endLine: 52 --- import SchemaFormatTabs from "@/components/SchemaFormatTabs.astro"; @@ -59,10 +33,10 @@ The type of applicant for a funding opportunity. ### Formats ### Changelog @@ -96,10 +70,10 @@ The type of applicant for a funding opportunity. ### Formats ### Changelog diff --git a/website/src/content/docs/protocol/models/application.mdx b/website/src/content/docs/protocol/models/application.mdx index d71042b89..80ff54954 100644 --- a/website/src/content/docs/protocol/models/application.mdx +++ b/website/src/content/docs/protocol/models/application.mdx @@ -28,26 +28,6 @@ applicationBase: } } } - jsonSchema: - file: - path: "website/public/schemas/yaml/ApplicationBase.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/application.tsp" - startLine: 20 - endLine: 51 -appRef: - example: - file: - path: "website/public/schemas/yaml/AppRef.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/AppRef.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/application.tsp" - startLine: 3 - endLine: 18 appStatus: example: code: | @@ -55,25 +35,9 @@ appStatus: "value": "submitted", "description": "Application has been submitted." } - jsonSchema: - file: - path: "website/public/schemas/yaml/AppStatus.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/application.tsp" - startLine: 57 - endLine: 60 appStatusOptions: example: code: '"submitted"' - jsonSchema: - file: - path: "website/public/schemas/yaml/AppStatusOptions.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/application.tsp" - startLine: 66 - endLine: 80 appFormResponse: example: code: | @@ -101,14 +65,6 @@ appFormResponse: "createdAt": "2024-01-01T00:00:00Z", "lastModifiedAt": "2024-01-01T00:00:00Z" } - jsonSchema: - file: - path: "website/public/schemas/yaml/AppFormResponse.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/application.tsp" - startLine: 86 - endLine: 95 --- import SchemaFormatTabs from "@/components/SchemaFormatTabs.astro"; @@ -121,14 +77,14 @@ Base model for an application to a funding opportunity. ### Table - + ### Formats ### Changelog @@ -141,15 +97,11 @@ A reference to an application, previewing the key fields a consumer needs to ide ### Table - + ### Formats - + ### Changelog @@ -161,14 +113,14 @@ The status of an application. ### Table - + ### Formats ### Changelog @@ -181,14 +133,14 @@ The default set of values accepted for application status. ### Table - + ### Formats ### Changelog @@ -201,14 +153,14 @@ A form response associated with an application. ### Table - + ### Formats ### Changelog diff --git a/website/src/content/docs/protocol/models/award.mdx b/website/src/content/docs/protocol/models/award.mdx index 646db84ef..75039284f 100644 --- a/website/src/content/docs/protocol/models/award.mdx +++ b/website/src/content/docs/protocol/models/award.mdx @@ -3,114 +3,6 @@ title: Award description: The data models for a grant award sidebar: order: 11 -awardBase: - example: - file: - path: "website/public/schemas/yaml/AwardBase.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/AwardBase.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/award.tsp" - startLine: 155 - endLine: 204 -awdRef: - example: - file: - path: "website/public/schemas/yaml/AwdRef.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/AwdRef.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/award.tsp" - startLine: 114 - endLine: 132 -awdStatus: - example: - file: - path: "website/public/schemas/yaml/AwdStatus.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/AwdStatus.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/award.tsp" - startLine: 32 - endLine: 45 -awdStatusOptions: - example: - file: - path: "website/public/schemas/yaml/AwdStatusOptions.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/AwdStatusOptions.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/award.tsp" - startLine: 18 - endLine: 30 -awdFunding: - example: - file: - path: "website/public/schemas/yaml/AwdFunding.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/AwdFunding.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/award.tsp" - startLine: 51 - endLine: 66 -awdTimeline: - example: - file: - path: "website/public/schemas/yaml/AwdTimeline.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/AwdTimeline.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/award.tsp" - startLine: 72 - endLine: 87 -awdRecipientIndividual: - example: - file: - path: "website/public/schemas/yaml/AwdRecipientIndividual.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/AwdRecipientIndividual.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/award.tsp" - startLine: 138 - endLine: 149 -awdIds: - example: - file: - path: "website/public/schemas/yaml/AwdIds.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/AwdIds.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/award.tsp" - startLine: 98 - endLine: 108 -awdIdFain: - example: - file: - path: "website/public/schemas/yaml/AwdIdFain.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/AwdIdFain.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/award.tsp" - startLine: 93 - endLine: 96 --- import SchemaFormatTabs from "@/components/SchemaFormatTabs.astro"; @@ -123,15 +15,11 @@ A grant award, tracking the funder, recipient, and financial details of a grant ### Table - + ### Formats - + ### Changelog @@ -143,15 +31,11 @@ A reference to an award, previewing the key fields a consumer needs to identify ### Table - + ### Formats - + ### Changelog @@ -163,15 +47,11 @@ The lifecycle status of an award, such as whether it has been awarded or complet ### Table - + ### Formats - + ### Changelog @@ -183,15 +63,11 @@ The set of values accepted for award status. ### Table - + ### Formats - + ### Changelog @@ -203,15 +79,11 @@ Financial details about the award, including the requested, awarded, and disburs ### Table - + ### Formats - + ### Changelog @@ -223,15 +95,11 @@ Key dates in the award's timeline, such as the award date and period of performa ### Table - + ### Formats - + ### Changelog @@ -243,17 +111,11 @@ An individual who received an award, when the recipient is a person rather than ### Table - + ### Formats - + ### Changelog @@ -265,15 +127,11 @@ System and registry-specific identifiers for an award, such as its FAIN. ### Table - + ### Formats - + ### Changelog @@ -285,15 +143,11 @@ An award's Federal Award Identification Number (FAIN), assigned by the awarding ### Table - + ### Formats - + ### Changelog diff --git a/website/src/content/docs/protocol/models/competition.mdx b/website/src/content/docs/protocol/models/competition.mdx index c5807f6a6..7d92e0573 100644 --- a/website/src/content/docs/protocol/models/competition.mdx +++ b/website/src/content/docs/protocol/models/competition.mdx @@ -61,17 +61,6 @@ competition: "createdAt": "2025-01-01T00:00:00Z", "lastModifiedAt": "2025-01-01T00:00:00Z" } - table: - file: - path: "website/public/schemas/yaml/versions/v0.5.0/CompetitionBase.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/CompetitionBase.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/competition.tsp" - startLine: 3 - endLine: 49 competitionStatus: example: code: | @@ -80,25 +69,9 @@ competitionStatus: "customValue": "canceled", "description": "Competition has been canceled" } - jsonSchema: - file: - path: "website/public/schemas/yaml/CompetitionStatus.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/competition.tsp" - startLine: 55 - endLine: 58 competitionStatusOptions: example: code: '"open"' - jsonSchema: - file: - path: "website/public/schemas/yaml/CompetitionStatusOptions.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/competition.tsp" - startLine: 64 - endLine: 74 competitionForms: example: code: | @@ -121,14 +94,6 @@ competitionForms: "required": ["formA"] } } - jsonSchema: - file: - path: "website/public/schemas/yaml/CompetitionForms.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/competition.tsp" - startLine: 80 - endLine: 89 competitionTimeline: example: code: | @@ -152,14 +117,6 @@ competitionTimeline: } } } - jsonSchema: - file: - path: "website/public/schemas/yaml/CompetitionTimeline.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/competition.tsp" - startLine: 95 - endLine: 107 --- import SchemaFormatTabs from "@/components/SchemaFormatTabs.astro"; @@ -178,16 +135,16 @@ The table and the example below show the v0.5 payload. To validate a payload, us ### Table - + ### Formats The JSON Schema tab shows the unversioned authoring schema, not a v0.5 payload schema. It combines every version's fields, so it requires both `opportunityId` and `opportunity`. ### Changelog @@ -244,14 +201,14 @@ The status of the competition. ### Table - + ### Formats ### Changelog @@ -264,16 +221,14 @@ Enumeration of possible competition status values. ### Table - + ### Formats ### Changelog @@ -286,14 +241,14 @@ Set of forms that need to be completed to apply to the competition. ### Table - + ### Formats ### Changelog @@ -306,14 +261,14 @@ The key dates in the competition's timeline. ### Table - + ### Formats ### Changelog diff --git a/website/src/content/docs/protocol/models/form-response.mdx b/website/src/content/docs/protocol/models/form-response.mdx index f6b39e4f3..8fba0c698 100644 --- a/website/src/content/docs/protocol/models/form-response.mdx +++ b/website/src/content/docs/protocol/models/form-response.mdx @@ -29,14 +29,6 @@ formResponse: "createdAt": "2024-01-01T00:00:00Z", "lastModifiedAt": "2024-01-01T00:00:00Z" } - jsonSchema: - file: - path: "website/public/schemas/yaml/FormResponseBase.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/form-response.tsp" - startLine: 3 - endLine: 27 formResponseStatus: example: code: | @@ -44,25 +36,9 @@ formResponseStatus: "value": "complete", "description": "The form response is complete" } - jsonSchema: - file: - path: "website/public/schemas/yaml/FormResponseStatus.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/form-response.tsp" - startLine: 33 - endLine: 36 formResponseStatusOptions: example: code: '"inProgress"' - jsonSchema: - file: - path: "website/public/schemas/yaml/FormResponseStatusOptions.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/form-response.tsp" - startLine: 42 - endLine: 56 --- import SchemaFormatTabs from "@/components/SchemaFormatTabs.astro"; @@ -75,14 +51,14 @@ Base model for a form response. ### Table - + ### Formats ### Changelog @@ -95,14 +71,14 @@ The status of a form response. ### Table - + ### Formats ### Changelog @@ -115,16 +91,14 @@ The options for the status of a form response. ### Table - + ### Formats ### Changelog diff --git a/website/src/content/docs/protocol/models/form.mdx b/website/src/content/docs/protocol/models/form.mdx index b3d9bd847..579c4e32b 100644 --- a/website/src/content/docs/protocol/models/form.mdx +++ b/website/src/content/docs/protocol/models/form.mdx @@ -57,17 +57,6 @@ form: "createdAt": "2025-01-01T17:01:01Z", "lastModifiedAt": "2025-01-02T17:30:00Z" } - table: - file: - path: "website/public/schemas/yaml/versions/v0.5.0/FormBase.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/FormBase.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/form.tsp" - startLine: 9 - endLine: 51 formJsonSchema: example: code: | @@ -83,14 +72,6 @@ formJsonSchema: "phone": { "type": "string" } } } - jsonSchema: - file: - path: "website/public/schemas/yaml/FormJsonSchema.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/form.tsp" - startLine: 57 - endLine: 62 formUISchema: example: code: | @@ -109,14 +90,6 @@ formUISchema: { "type": "Control", "scope": "#/properties/phone" } ] } - jsonSchema: - file: - path: "website/public/schemas/yaml/FormUISchema.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/form.tsp" - startLine: 68 - endLine: 73 --- import SchemaFormatTabs from "@/components/SchemaFormatTabs.astro"; @@ -133,16 +106,16 @@ The table and the example below show the v0.5 payload. To validate a payload, us ### Table - + ### Formats The JSON Schema tab shows the unversioned authoring schema, not a v0.5 payload schema. It combines every version's fields, so it requires both `name` and `title`. ### Changelog @@ -195,9 +168,9 @@ The TypeSpec model declares every version's fields at once: `name` is removed in A JSON schema used to validate form responses. ### Changelog @@ -209,9 +182,9 @@ A JSON schema used to validate form responses. A UI schema used to render the form in the browser. ### Changelog diff --git a/website/src/content/docs/protocol/models/mapping.mdx b/website/src/content/docs/protocol/models/mapping.mdx index 8a2ba22af..e20f6834b 100644 --- a/website/src/content/docs/protocol/models/mapping.mdx +++ b/website/src/content/docs/protocol/models/mapping.mdx @@ -19,14 +19,6 @@ mappingSchema: "amount": { "field": "summary.opportunity_amount" } } } - jsonSchema: - file: - path: "website/public/schemas/yaml/MappingSchema.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/mapping.tsp" - startLine: 54 - endLine: 58 mappingFunction: example: code: | @@ -37,42 +29,18 @@ mappingFunction: "lastName": {"field": "last_name"}, }, } - jsonSchema: - file: - path: "website/public/schemas/yaml/MappingFunction.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/mapping.tsp" - startLine: 64 - endLine: 73 mappingConstantFunction: example: code: | { "const": "123", } - jsonSchema: - file: - path: "website/public/schemas/yaml/MappingConstantFunction.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/mapping.tsp" - startLine: 79 - endLine: 84 mappingFieldFunction: example: code: | { "field": "opportunity_status", } - jsonSchema: - file: - path: "website/public/schemas/yaml/MappingFieldFunction.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/mapping.tsp" - startLine: 90 - endLine: 95 mappingSwitchFunction: example: code: | @@ -86,14 +54,6 @@ mappingSwitchFunction: "default": "custom" } } - jsonSchema: - file: - path: "website/public/schemas/yaml/MappingSwitchFunction.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/mapping.tsp" - startLine: 101 - endLine: 115 --- import SchemaFormatTabs from "@/components/SchemaFormatTabs.astro"; @@ -165,9 +125,9 @@ To the following output: ### Formats ### Changelog @@ -189,9 +149,9 @@ A function for mapping data from one schema to another. ### Formats {/* TODO: Add changelog once unions are supported */} @@ -202,16 +162,14 @@ Returns a constant value. ### Table - + ### Formats ### Changelog @@ -224,14 +182,14 @@ Returns the value of a field in the source data. ### Table - + ### Formats ### Changelog @@ -244,16 +202,14 @@ Returns a new value based on the value of a field in the source data using a swi ### Table - + ### Formats ### Changelog diff --git a/website/src/content/docs/protocol/models/opportunity.mdx b/website/src/content/docs/protocol/models/opportunity.mdx index f408cb196..e65e9e7c8 100644 --- a/website/src/content/docs/protocol/models/opportunity.mdx +++ b/website/src/content/docs/protocol/models/opportunity.mdx @@ -3,28 +3,6 @@ title: Opportunity description: The data models for a funding opportunity sidebar: order: 1 -opportunityBase: - example: - file: - path: "website/public/schemas/yaml/OpportunityBase.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/OpportunityBase.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/opportunity/base.tsp" - startLine: 45 - endLine: 80 - python: - file: - path: "lib/python-sdk/common_grants_sdk/schemas/pydantic/models/opp_base.py" - startLine: 15 - endLine: 42 - typescript: - file: - path: "lib/ts-sdk/src/schemas/zod/models.ts" - startLine: 115 - endLine: 162 opportunityDetails: example: code: | @@ -226,150 +204,6 @@ opportunityDetails: "createdAt": "2019-08-24T14:15:22Z", "lastModifiedAt": "2019-08-24T14:15:22Z" } - jsonSchema: - file: - path: "website/public/schemas/yaml/OpportunityDetails.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/opportunity/base.tsp" - startLine: 140 - endLine: 162 -oppRef: - example: - file: - path: "website/public/schemas/yaml/OppRef.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/OppRef.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/opportunity/base.tsp" - startLine: 115 - endLine: 134 -oppIds: - example: - file: - path: "website/public/schemas/yaml/OppIds.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/OppIds.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/opportunity/base.tsp" - startLine: 96 - endLine: 109 -oppIdFon: - example: - file: - path: "website/public/schemas/yaml/OppIdFon.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/OppIdFon.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/opportunity/base.tsp" - startLine: 86 - endLine: 89 -oppIdAln: - example: - file: - path: "website/public/schemas/yaml/OppIdAln.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/OppIdAln.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/opportunity/base.tsp" - startLine: 91 - endLine: 94 -oppStatus: - example: - file: - path: "website/public/schemas/yaml/OppStatus.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/OppStatus.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/opportunity/status.tsp" - startLine: 25 - endLine: 29 - python: - file: - path: "lib/python-sdk/common_grants_sdk/schemas/pydantic/models/opp_status.py" - startLine: 30 - endLine: 45 - typescript: - file: - path: "lib/ts-sdk/src/schemas/zod/models.ts" - startLine: 17 - endLine: 26 -oppStatusOptions: - example: - file: - path: "website/public/schemas/yaml/OppStatusOptions.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/OppStatusOptions.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/opportunity/status.tsp" - startLine: 7 - endLine: 19 - python: - file: - path: "lib/python-sdk/common_grants_sdk/schemas/pydantic/models/opp_status.py" - startLine: 11 - endLine: 27 - typescript: - file: - path: "lib/ts-sdk/src/schemas/zod/models.ts" - startLine: 15 - endLine: 15 -oppFunding: - example: - file: - path: "website/public/schemas/yaml/OppFunding.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/OppFunding.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/opportunity/funding.tsp" - startLine: 12 - endLine: 44 - python: - file: - path: "lib/python-sdk/common_grants_sdk/schemas/pydantic/models/opp_funding.py" - startLine: 11 - endLine: 47 - typescript: - file: - path: "lib/ts-sdk/src/schemas/zod/models.ts" - startLine: 73 - endLine: 96 -oppTimeline: - example: - file: - path: "website/public/schemas/yaml/OppTimeline.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/OppTimeline.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/opportunity/timeline.tsp" - startLine: 13 - endLine: 28 - python: - file: - path: "lib/python-sdk/common_grants_sdk/schemas/pydantic/models/opp_timeline.py" - startLine: 11 - endLine: 28 - typescript: - file: - path: "lib/ts-sdk/src/schemas/zod/models.ts" - startLine: 102 - endLine: 113 --- import SchemaFormatTabs from "@/components/SchemaFormatTabs.astro"; @@ -382,17 +216,11 @@ A funding opportunity, such as a grant or loan. It shares its identity fields wi ### Table - + ### Formats - + ### Changelog @@ -406,15 +234,14 @@ An entry is a reference, not the award record: `GET /awards/` is the canonic ### Table - + ### Formats ### Changelog @@ -427,15 +254,11 @@ A reference to an opportunity, previewing the key fields a consumer needs to ide ### Table - + ### Formats - + ### Changelog @@ -447,15 +270,11 @@ A collection of identifiers associated with an opportunity, keyed by registry co ### Table - + ### Formats - + ### Changelog @@ -467,15 +286,11 @@ An opportunity's Federal Opportunity Number (FON), assigned by the awarding agen ### Table - + ### Formats - + ### Changelog @@ -487,15 +302,11 @@ An opportunity's Assistance Listing Number (ALN), formerly the CFDA number, whic ### Table - + ### Formats - + ### Changelog @@ -507,17 +318,11 @@ The status of an opportunity, such as whether it is accepting applications. ### Table - + ### Formats - + ### Changelog @@ -529,16 +334,15 @@ The set of values accepted for opportunity status. ### Table - + ### Formats ### Changelog @@ -551,17 +355,11 @@ Details about the funding available for an opportunity. ### Table - + ### Formats - + ### Changelog @@ -573,17 +371,11 @@ Key dates in the opportunity's timeline, such as when the application opens and ### Table - + ### Formats - + ### Changelog diff --git a/website/src/content/docs/protocol/models/organization.mdx b/website/src/content/docs/protocol/models/organization.mdx index 74f660acc..e5ee9423c 100644 --- a/website/src/content/docs/protocol/models/organization.mdx +++ b/website/src/content/docs/protocol/models/organization.mdx @@ -126,206 +126,6 @@ organizationBase: ] } } - jsonSchema: - file: - path: "website/public/schemas/yaml/OrganizationBase.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/organization.tsp" - startLine: 5 - endLine: 60 -orgIds: - example: - file: - path: "website/public/schemas/yaml/OrgIds.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/OrgIds.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/organization.tsp" - startLine: 81 - endLine: 96 -orgIdEin: - example: - file: - path: "website/public/schemas/yaml/OrgIdEin.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/OrgIdEin.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/organization.tsp" - startLine: 66 - endLine: 69 -orgIdUei: - example: - file: - path: "website/public/schemas/yaml/OrgIdUei.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/OrgIdUei.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/organization.tsp" - startLine: 71 - endLine: 74 -orgIdDuns: - example: - file: - path: "website/public/schemas/yaml/OrgIdDuns.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/OrgIdDuns.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/organization.tsp" - startLine: 76 - endLine: 79 -orgRef: - example: - file: - path: "website/public/schemas/yaml/OrgRef.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/OrgRef.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/organization.tsp" - startLine: 102 - endLine: 120 -orgRefCollection: - example: - file: - path: "website/public/schemas/yaml/OrgRefCollection.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/OrgRefCollection.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/organization.tsp" - startLine: 122 - endLine: 134 -orgRelationships: - example: - file: - path: "website/public/schemas/yaml/OrgRelationships.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/OrgRelationships.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/organization.tsp" - startLine: 257 - endLine: 288 -orgHierarchyRelationship: - example: - file: - path: "website/public/schemas/yaml/OrgHierarchyRelationship.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/OrgHierarchyRelationship.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/organization.tsp" - startLine: 205 - endLine: 240 -orgSuccessionRelationship: - example: - file: - path: "website/public/schemas/yaml/OrgSuccessionRelationship.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/OrgSuccessionRelationship.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/organization.tsp" - startLine: 242 - endLine: 245 -orgRecordRelationship: - example: - file: - path: "website/public/schemas/yaml/OrgRecordRelationship.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/OrgRecordRelationship.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/organization.tsp" - startLine: 247 - endLine: 250 -orgOtherRelationship: - example: - file: - path: "website/public/schemas/yaml/OrgOtherRelationship.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/OrgOtherRelationship.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/organization.tsp" - startLine: 252 - endLine: 255 -orgHierarchyKindOptions: - example: - file: - path: "website/public/schemas/yaml/OrgHierarchyKindOptions.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/OrgHierarchyKindOptions.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/organization.tsp" - startLine: 140 - endLine: 158 -orgSuccessionKindOptions: - example: - file: - path: "website/public/schemas/yaml/OrgSuccessionKindOptions.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/OrgSuccessionKindOptions.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/organization.tsp" - startLine: 160 - endLine: 174 -orgRecordKindOptions: - example: - file: - path: "website/public/schemas/yaml/OrgRecordKindOptions.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/OrgRecordKindOptions.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/organization.tsp" - startLine: 176 - endLine: 187 -orgOtherKindOptions: - example: - file: - path: "website/public/schemas/yaml/OrgOtherKindOptions.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/OrgOtherKindOptions.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/organization.tsp" - startLine: 189 - endLine: 193 -orgRelationshipStatus: - example: - file: - path: "website/public/schemas/yaml/OrgRelationshipStatus.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/OrgRelationshipStatus.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/organization.tsp" - startLine: 195 - endLine: 203 orgSocialLinks: example: code: | @@ -341,50 +141,6 @@ orgSocialLinks: "tiktok": "https://tiktok.com/example" } } - jsonSchema: - file: - path: "website/public/schemas/yaml/OrgSocialLinks.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/organization.tsp" - startLine: 294 - endLine: 318 -orgStatus: - example: - file: - path: "website/public/schemas/yaml/OrgStatus.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/OrgStatus.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/organization.tsp" - startLine: 336 - endLine: 341 -orgStatusOptions: - example: - file: - path: "website/public/schemas/yaml/OrgStatusOptions.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/OrgStatusOptions.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/organization.tsp" - startLine: 324 - endLine: 334 -orgPatchData: - example: - file: - path: "website/public/schemas/yaml/OrgPatchData.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/OrgPatchData.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/organization-sync.tsp" - startLine: 277 - endLine: 289 --- import SchemaFormatTabs from "@/components/SchemaFormatTabs.astro"; @@ -419,9 +175,9 @@ An organization that can apply to or host funding opportunities. ### Formats ### Changelog @@ -437,15 +193,11 @@ published under `otherIds`. ### Table - + ### Formats - + ### Changelog @@ -459,15 +211,11 @@ An organization's Employer Identification Number (EIN), assigned by the IRS. It ### Table - + ### Formats - + ### Changelog @@ -481,15 +229,11 @@ An organization's Unique Entity Identifier (UEI) from SAM.gov. It pins `registry ### Table - + ### Formats - + ### Changelog @@ -503,15 +247,11 @@ An organization's Data Universal Numbering System (DUNS) number. It pins `regist ### Table - + ### Formats - + ### Changelog @@ -523,15 +263,11 @@ A reference to an organization, previewing the key fields a consumer needs to id ### Table - + ### Formats - + ### Changelog @@ -543,15 +279,11 @@ A group of organization references, with a primary organization and optional oth ### Table - + ### Formats - + ### Changelog @@ -575,15 +307,11 @@ On reads, `relationships`, each list, `aliases`, and an entry's optional members ### Table - + ### Formats - + ### Changelog @@ -603,16 +331,13 @@ An entry with only `org` is valid. Parents and children cover more than containm ### Table - + ### Formats ### Changelog @@ -625,17 +350,11 @@ A succession relationship, added in v0.5.0, with the same shape as [OrgHierarchy ### Table - + ### Formats - + ### Changelog @@ -647,17 +366,11 @@ A record replacement relationship, added in v0.5.0, with the same shape as [OrgH ### Table - + ### Formats - + ### Changelog @@ -669,15 +382,11 @@ A relationship outside the named categories, added in v0.5.0, with the same shap ### Table - + ### Formats - + ### Changelog @@ -689,17 +398,11 @@ The standard subtypes of a parent or child relationship, added in v0.5.0. `dba` ### Table - + ### Formats - + ### Changelog @@ -711,17 +414,11 @@ The standard subtypes of organizational succession, added in v0.5.0. ### Table - + ### Formats - + ### Changelog @@ -733,15 +430,11 @@ The standard subtypes of record replacement, added in v0.5.0. A provider's workf ### Table - + ### Formats - + ### Changelog @@ -753,15 +446,11 @@ The subtypes of an [OrgOtherRelationship](#orgotherrelationship), added in v0.5. ### Table - + ### Formats - + ### Changelog @@ -773,17 +462,11 @@ Whether a relationship is in effect, as stated by the provider, added in v0.5.0. ### Table - + ### Formats - + ### Changelog @@ -808,9 +491,9 @@ A collection of social media and web presence links for an organization. ### Formats ### Changelog @@ -827,15 +510,11 @@ The status of an organization: ### Table - + ### Formats - + ### Changelog @@ -847,15 +526,11 @@ The set of values accepted for organization status. ### Table - + ### Formats - + ### Changelog @@ -869,15 +544,11 @@ From v0.5.0, `relationships` follows the same rules. Each relationship list is a ### Table - + ### Formats - + ### Changelog diff --git a/website/src/content/docs/protocol/models/person.mdx b/website/src/content/docs/protocol/models/person.mdx index 375742f44..227a155f9 100644 --- a/website/src/content/docs/protocol/models/person.mdx +++ b/website/src/content/docs/protocol/models/person.mdx @@ -56,14 +56,6 @@ personBase: } } } - jsonSchema: - file: - path: "website/public/schemas/yaml/PersonBase.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/person.tsp" - startLine: 6 - endLine: 30 --- import SchemaFormatTabs from "@/components/SchemaFormatTabs.astro"; @@ -76,14 +68,14 @@ A person affiliated with an organization or grant application. ### Table - + ### Formats ### Changelog diff --git a/website/src/content/docs/protocol/models/proposal.mdx b/website/src/content/docs/protocol/models/proposal.mdx index 83b2fa2a9..6df33da70 100644 --- a/website/src/content/docs/protocol/models/proposal.mdx +++ b/website/src/content/docs/protocol/models/proposal.mdx @@ -108,14 +108,6 @@ proposalBase: } } } - jsonSchema: - file: - path: "website/public/schemas/yaml/ProposalBase.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/proposal.tsp" - startLine: 7 - endLine: 34 proposalOpportunity: example: code: | @@ -132,14 +124,6 @@ proposalOpportunity: } } } - jsonSchema: - file: - path: "website/public/schemas/yaml/ProposalOpportunity.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/proposal.tsp" - startLine: 40 - endLine: 51 projectTimeline: example: code: | @@ -165,14 +149,6 @@ projectTimeline: }, "timelineDetails": "The project will be conducted over 12 months with quarterly milestones." } - jsonSchema: - file: - path: "website/public/schemas/yaml/ProjectTimeline.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/proposal.tsp" - startLine: 57 - endLine: 71 proposalContacts: example: code: | @@ -209,14 +185,6 @@ proposalContacts: } } } - jsonSchema: - file: - path: "website/public/schemas/yaml/ProposalContacts.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/proposal.tsp" - startLine: 77 - endLine: 85 proposalOrgs: example: code: | @@ -239,14 +207,6 @@ proposalOrgs: } } } - jsonSchema: - file: - path: "website/public/schemas/yaml/ProposalOrgs.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/proposal.tsp" - startLine: 91 - endLine: 99 --- import SchemaFormatTabs from "@/components/SchemaFormatTabs.astro"; @@ -259,14 +219,14 @@ A proposal for funding. ### Table - + ### Formats ### Changelog @@ -279,14 +239,14 @@ The opportunity to which this proposal is related. ### Table - + ### Formats ### Changelog @@ -299,14 +259,14 @@ The key dates for the project. ### Table - + ### Formats ### Changelog @@ -319,14 +279,14 @@ The point of contact for the project. ### Table - + ### Formats ### Changelog @@ -339,14 +299,14 @@ The organization that is requesting funding. ### Table - + ### Formats ### Changelog diff --git a/website/src/content/docs/protocol/models/revision.mdx b/website/src/content/docs/protocol/models/revision.mdx index 22c5f4118..940208caf 100644 --- a/website/src/content/docs/protocol/models/revision.mdx +++ b/website/src/content/docs/protocol/models/revision.mdx @@ -3,54 +3,6 @@ title: Revision description: Data models for a record of a change to a resource sidebar: order: 13 -revision: - example: - file: - path: "website/public/schemas/yaml/Revision.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/Revision.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/revision.tsp" - startLine: 48 - endLine: 98 -revisionStatus: - example: - file: - path: "website/public/schemas/yaml/RevisionStatus.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/RevisionStatus.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/revision.tsp" - startLine: 36 - endLine: 42 -revisionStatusOptions: - example: - file: - path: "website/public/schemas/yaml/RevisionStatusOptions.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/RevisionStatusOptions.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/revision.tsp" - startLine: 13 - endLine: 34 -orgRevision: - example: - file: - path: "website/public/schemas/yaml/OrgRevision.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/OrgRevision.yaml" - typeSpec: - file: - path: "lib/core/lib/core/models/organization-sync.tsp" - startLine: 291 - endLine: 298 --- import SchemaFormatTabs from "@/components/SchemaFormatTabs.astro"; @@ -67,15 +19,11 @@ The generic, untyped record of a change, where `patch` and `snapshot` are open o ### Table - + ### Formats - + ### Changelog @@ -99,15 +47,11 @@ How a receiver resolves a `pending` change (a human review, a policy engine, a b ### Table - + ### Formats - + ### Changelog @@ -119,11 +63,7 @@ The fixed set of values a [RevisionStatus](#revisionstatus) can take: `pending`, ### Formats - + ### Changelog @@ -135,15 +75,11 @@ A [Revision](#revision) bound to organization profiles, where `patch` is an [Org ### Table - + ### Formats - + ### Changelog diff --git a/website/src/content/docs/protocol/pagination.mdx b/website/src/content/docs/protocol/pagination.mdx index 6e8bd0aae..ded8d7e12 100644 --- a/website/src/content/docs/protocol/pagination.mdx +++ b/website/src/content/docs/protocol/pagination.mdx @@ -1,72 +1,6 @@ --- title: Pagination description: Defines a set of parameters and patterns for paginated routes -paginatedQueryParams: - example: - file: - path: "website/public/schemas/yaml/PaginatedQueryParams.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/PaginatedQueryParams.yaml" - typeSpec: - file: - path: "lib/core/lib/core/pagination.tsp" - startLine: 10 - endLine: 24 - python: - file: - path: "lib/python-sdk/common_grants_sdk/schemas/pydantic/pagination.py" - startLine: 28 - endLine: 29 - typescript: - file: - path: "lib/ts-sdk/src/schemas/zod/pagination.ts" - startLine: 16 - endLine: 22 -paginatedBodyParams: - example: - file: - path: "website/public/schemas/yaml/PaginatedBodyParams.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/PaginatedBodyParams.yaml" - typeSpec: - file: - path: "lib/core/lib/core/pagination.tsp" - startLine: 26 - endLine: 38 - python: - file: - path: "lib/python-sdk/common_grants_sdk/schemas/pydantic/pagination.py" - startLine: 24 - endLine: 25 - typescript: - file: - path: "lib/ts-sdk/src/schemas/zod/pagination.ts" - startLine: 29 - endLine: 35 -paginatedResultsInfo: - example: - file: - path: "website/public/schemas/yaml/PaginatedResultsInfo.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/PaginatedResultsInfo.yaml" - typeSpec: - file: - path: "lib/core/lib/core/pagination.tsp" - startLine: 40 - endLine: 60 - python: - file: - path: "lib/python-sdk/common_grants_sdk/schemas/pydantic/pagination.py" - startLine: 32 - endLine: 46 - typescript: - file: - path: "lib/ts-sdk/src/schemas/zod/pagination.ts" - startLine: 42 - endLine: 54 --- import SchemaFormatTabs from "@/components/SchemaFormatTabs.astro"; @@ -85,13 +19,7 @@ Query parameters for paginated routes. These parameters should be used on GET ro ### Formats - + ### Changelog @@ -110,13 +38,7 @@ Body parameters for paginated routes. These parameters should be used on POST an ### Formats - + ### Changelog @@ -137,13 +59,7 @@ Details about the paginated results. This model should included in the response ### Formats - + ### Changelog diff --git a/website/src/content/docs/protocol/responses/error.mdx b/website/src/content/docs/protocol/responses/error.mdx index fc31e765a..d941efb4f 100644 --- a/website/src/content/docs/protocol/responses/error.mdx +++ b/website/src/content/docs/protocol/responses/error.mdx @@ -3,45 +3,6 @@ title: Errors description: A standard error response schema, used to create custom error responses sidebar: order: 5 -error: - example: - file: - path: "website/public/schemas/yaml/Error.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/Error.yaml" - typeSpec: - file: - path: "lib/core/lib/core/responses/error.tsp" - startLine: 15 - endLine: 27 - python: - file: - path: "lib/python-sdk/common_grants_sdk/schemas/pydantic/responses/error.py" - startLine: 10 - endLine: 26 - typescript: - file: - path: "lib/ts-sdk/src/schemas/zod/responses.ts" - startLine: 170 - endLine: 179 -applicationSubmissionError: - example: - file: - path: "website/public/schemas/yaml/ApplicationSubmissionError.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/ApplicationSubmissionError.yaml" - typeSpec: - file: - path: "lib/core/lib/core/responses/error.tsp" - startLine: 32 - endLine: 43 - typescript: - file: - path: "lib/ts-sdk/src/schemas/zod/responses.ts" - startLine: 192 - endLine: 194 --- import SchemaFormatTabs from "@/components/SchemaFormatTabs.astro"; @@ -63,13 +24,7 @@ Default response schema for 4xx and 5xx HTTP status codes. ### Formats - + ### Usage @@ -106,12 +61,7 @@ A failure to submit an application due to validation errors. ### Formats - + ### Changelog diff --git a/website/src/content/docs/protocol/responses/filtered.mdx b/website/src/content/docs/protocol/responses/filtered.mdx index 387fea1b6..3c25f9197 100644 --- a/website/src/content/docs/protocol/responses/filtered.mdx +++ b/website/src/content/docs/protocol/responses/filtered.mdx @@ -45,24 +45,6 @@ filtered: } } } - jsonSchema: - file: - path: "website/public/schemas/yaml/Filtered.yaml" - typeSpec: - file: - path: "lib/core/lib/core/responses/success.tsp" - startLine: 177 - endLine: 198 - python: - file: - path: "lib/python-sdk/common_grants_sdk/schemas/pydantic/responses/success.py" - startLine: 57 - endLine: 78 - typescript: - file: - path: "lib/ts-sdk/src/schemas/zod/responses.ts" - startLine: 126 - endLine: 140 --- import SchemaFormatTabs from "@/components/SchemaFormatTabs.astro"; @@ -86,11 +68,11 @@ A 200 response with a paginated list of filtered items. ### Formats ### Usage diff --git a/website/src/content/docs/protocol/responses/paginated.mdx b/website/src/content/docs/protocol/responses/paginated.mdx index 537707e35..d25a70cf3 100644 --- a/website/src/content/docs/protocol/responses/paginated.mdx +++ b/website/src/content/docs/protocol/responses/paginated.mdx @@ -26,24 +26,6 @@ paginated: "totalPages": 3 } } - jsonSchema: - file: - path: "website/public/schemas/yaml/Paginated.yaml" - typeSpec: - file: - path: "lib/core/lib/core/responses/success.tsp" - startLine: 72 - endLine: 90 - python: - file: - path: "lib/python-sdk/common_grants_sdk/schemas/pydantic/responses/success.py" - startLine: 32 - endLine: 42 - typescript: - file: - path: "lib/ts-sdk/src/schemas/zod/responses.ts" - startLine: 71 - endLine: 78 --- import SchemaFormatTabs from "@/components/SchemaFormatTabs.astro"; @@ -65,11 +47,11 @@ A 200 response with a paginated list of items. ### Formats ### Usage diff --git a/website/src/content/docs/protocol/responses/sorted.mdx b/website/src/content/docs/protocol/responses/sorted.mdx index 640467a18..796c7e493 100644 --- a/website/src/content/docs/protocol/responses/sorted.mdx +++ b/website/src/content/docs/protocol/responses/sorted.mdx @@ -30,24 +30,6 @@ sorted: "direction": "asc" } } - jsonSchema: - file: - path: "website/public/schemas/yaml/Sorted.yaml" - typeSpec: - file: - path: "lib/core/lib/core/responses/success.tsp" - startLine: 125 - endLine: 141 - python: - file: - path: "lib/python-sdk/common_grants_sdk/schemas/pydantic/responses/success.py" - startLine: 45 - endLine: 54 - typescript: - file: - path: "lib/ts-sdk/src/schemas/zod/responses.ts" - startLine: 97 - endLine: 101 --- import SchemaFormatTabs from "@/components/SchemaFormatTabs.astro"; @@ -70,11 +52,11 @@ A 200 response with a paginated list of sorted items. ### Formats ### Usage diff --git a/website/src/content/docs/protocol/responses/success.mdx b/website/src/content/docs/protocol/responses/success.mdx index 731a4ef8c..e70254588 100644 --- a/website/src/content/docs/protocol/responses/success.mdx +++ b/website/src/content/docs/protocol/responses/success.mdx @@ -14,14 +14,6 @@ ok: "name": "Test 1" } } - jsonSchema: - file: - path: "website/public/schemas/yaml/Ok.yaml" - typeSpec: - file: - path: "lib/core/lib/core/responses/success.tsp" - startLine: 31 - endLine: 36 created: example: code: | @@ -33,14 +25,6 @@ created: "name": "Test 1" } } - jsonSchema: - file: - path: "website/public/schemas/yaml/Created.yaml" - typeSpec: - file: - path: "lib/core/lib/core/responses/success.tsp" - startLine: 239 - endLine: 244 accepted: example: code: | @@ -52,36 +36,6 @@ accepted: "name": "Test 1" } } - jsonSchema: - file: - path: "website/public/schemas/yaml/Accepted.yaml" - typeSpec: - file: - path: "lib/core/lib/core/responses/success.tsp" - startLine: 268 - endLine: 273 -success: - example: - file: - path: "website/public/schemas/yaml/Success.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/Success.yaml" - typeSpec: - file: - path: "lib/core/lib/core/responses/success.tsp" - startLine: 14 - endLine: 21 - python: - file: - path: "lib/python-sdk/common_grants_sdk/schemas/pydantic/responses/success.py" - startLine: 17 - endLine: 29 - typescript: - file: - path: "lib/ts-sdk/src/schemas/zod/responses.ts" - startLine: 19 - endLine: 25 --- import SchemaFormatTabs from "@/components/SchemaFormatTabs.astro"; @@ -100,13 +54,7 @@ Base model for all successful responses. ### Formats - + ### Changelog @@ -126,13 +74,7 @@ A 200 response with data. ### Formats - + ### Usage @@ -175,9 +117,9 @@ A 201 response with data. ### Formats ### Usage @@ -223,9 +165,9 @@ Returned when a request is accepted for processing but may not be applied immedi ### Formats ### Usage diff --git a/website/src/content/docs/protocol/sorting.mdx b/website/src/content/docs/protocol/sorting.mdx index 68c94bde9..fe6e885dc 100644 --- a/website/src/content/docs/protocol/sorting.mdx +++ b/website/src/content/docs/protocol/sorting.mdx @@ -1,94 +1,6 @@ --- title: Sorting description: Defines a set of parameters and patterns for sorting routes -sortOrder: - example: - file: - path: "website/public/schemas/yaml/SortOrder.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/SortOrder.yaml" - typeSpec: - file: - path: "lib/core/lib/core/sorting.tsp" - startLine: 21 - endLine: 25 - python: - file: - path: "lib/python-sdk/common_grants_sdk/schemas/pydantic/sorting.py" - startLine: 9 - endLine: 13 - typescript: - file: - path: "lib/ts-sdk/src/schemas/zod/sorting.ts" - startLine: 16 - endLine: 16 -sortQueryParams: - example: - file: - path: "website/public/schemas/yaml/SortQueryParams.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/SortQueryParams.yaml" - typeSpec: - file: - path: "lib/core/lib/core/sorting.tsp" - startLine: 27 - endLine: 44 - python: - file: - path: "lib/python-sdk/common_grants_sdk/schemas/pydantic/sorting.py" - startLine: 35 - endLine: 43 - typescript: - file: - path: "lib/ts-sdk/src/schemas/zod/sorting.ts" - startLine: 23 - endLine: 32 -sortBodyParams: - example: - file: - path: "website/public/schemas/yaml/SortBodyParams.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/SortBodyParams.yaml" - typeSpec: - file: - path: "lib/core/lib/core/sorting.tsp" - startLine: 46 - endLine: 60 - python: - file: - path: "lib/python-sdk/common_grants_sdk/schemas/pydantic/sorting.py" - startLine: 46 - endLine: 54 - typescript: - file: - path: "lib/ts-sdk/src/schemas/zod/sorting.ts" - startLine: 39 - endLine: 48 -sortedResultsInfo: - example: - file: - path: "website/public/schemas/yaml/SortedResultsInfo.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/SortedResultsInfo.yaml" - typeSpec: - file: - path: "lib/core/lib/core/sorting.tsp" - startLine: 62 - endLine: 79 - python: - file: - path: "lib/python-sdk/common_grants_sdk/schemas/pydantic/sorting.py" - startLine: 57 - endLine: 69 - typescript: - file: - path: "lib/ts-sdk/src/schemas/zod/sorting.ts" - startLine: 55 - endLine: 67 --- import SchemaFormatTabs from "@/components/SchemaFormatTabs.astro"; @@ -108,11 +20,10 @@ The order or direction to sort results by. ### Formats ### Changelog @@ -133,13 +44,7 @@ Query parameters for sorting. These parameters should be used on GET routes that ### Formats - + ### Changelog @@ -159,13 +64,7 @@ Body parameters for sorting. These parameters should be used on POST and PUT rou ### Formats - + ### Changelog @@ -186,13 +85,7 @@ Information about the sort order of the items returned. This model should be inc ### Formats - + ### Changelog diff --git a/website/src/content/docs/protocol/types/date.mdx b/website/src/content/docs/protocol/types/date.mdx index d0f398ca3..c562add22 100644 --- a/website/src/content/docs/protocol/types/date.mdx +++ b/website/src/content/docs/protocol/types/date.mdx @@ -3,40 +3,6 @@ title: Date and time types description: Date and time types used throughout the protocol. sidebar: order: 3 -isoDate: - example: - file: - path: "website/public/schemas/yaml/isoDate.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/isoDate.yaml" - typeSpec: - file: - path: "lib/core/lib/core/types.tsp" - startLine: 88 - endLine: 91 - typescript: - file: - path: "lib/ts-sdk/src/schemas/zod/types.ts" - startLine: 49 - endLine: 52 -isoTime: - example: - file: - path: "website/public/schemas/yaml/isoTime.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/isoTime.yaml" - typeSpec: - file: - path: "lib/core/lib/core/types.tsp" - startLine: 83 - endLine: 86 - typescript: - file: - path: "lib/ts-sdk/src/schemas/zod/types.ts" - startLine: 55 - endLine: 62 utcDateTime: example: code: '"2024-02-28T17:00:00Z"' @@ -47,11 +13,6 @@ utcDateTime: type: string format: date-time description: A date and time with timezone in ISO 8601 format YYYY-MM-DDThh:mm:ssZ - typescript: - file: - path: "lib/ts-sdk/src/schemas/zod/types.ts" - startLine: 46 - endLine: 46 offsetDateTime: example: code: '"2024-02-28T17:00:00+01:00"' @@ -62,23 +23,6 @@ offsetDateTime: type: string format: date-time description: A date and time with timezone in ISO 8601 format YYYY-MM-DDThh:mm:ss±hh:mm - typescript: - file: - path: "lib/ts-sdk/src/schemas/zod/types.ts" - startLine: 65 - endLine: 68 -calendarYear: - example: - file: - path: "website/public/schemas/yaml/calendarYear.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/calendarYear.yaml" - typeSpec: - file: - path: "lib/core/lib/core/types.tsp" - startLine: 93 - endLine: 97 --- import SchemaFormatTabs from "@/components/SchemaFormatTabs.astro"; @@ -87,12 +31,7 @@ import SchemaFormatTabs from "@/components/SchemaFormatTabs.astro"; A date on a calendar in ISO 8601 format YYYY-MM-DD. - + ## isoTime @@ -102,12 +41,7 @@ A time on a clock, without a timezone, in ISO 8601 format HH:mm:ss. The `isoTime` type does not include timezone information. When representing a time in a specific timezone, use `utcDateTime` or `offsetDateTime` instead. ::: - + ## utcDateTime @@ -116,7 +50,7 @@ A date and time with timezone in ISO 8601 format YYYY-MM-DDThh:mm:ssZ. ## offsetDateTime @@ -126,15 +60,11 @@ A date and time with timezone in ISO 8601 format YYYY-MM-DDThh:mm:ss±hh:mm. ## calendarYear A calendar year in the format YYYY. - + diff --git a/website/src/content/docs/protocol/types/numeric.mdx b/website/src/content/docs/protocol/types/numeric.mdx index 4d2224054..3780caff5 100644 --- a/website/src/content/docs/protocol/types/numeric.mdx +++ b/website/src/content/docs/protocol/types/numeric.mdx @@ -45,19 +45,6 @@ decimalString: // Negative, scale 2 "-100.50" - jsonSchema: - file: - path: "website/public/schemas/yaml/decimalString.yaml" - typeSpec: - file: - path: "lib/core/lib/core/types.tsp" - startLine: 68 - endLine: 77 - typescript: - file: - path: "lib/ts-sdk/src/schemas/zod/types.ts" - startLine: 21 - endLine: 23 --- import SchemaFormatTabs from "@/components/SchemaFormatTabs.astro"; @@ -85,10 +72,10 @@ A whole number without decimals, equivalent to `integer` in JSON Schema. A decimal number (with variable scale) encoded as a string, to avoid floating point issues. ## Other numeric types diff --git a/website/src/content/docs/protocol/types/string.mdx b/website/src/content/docs/protocol/types/string.mdx index b8960e7f8..08b43c5d8 100644 --- a/website/src/content/docs/protocol/types/string.mdx +++ b/website/src/content/docs/protocol/types/string.mdx @@ -22,83 +22,6 @@ url: type: string format: uri description: A Uniform Resource Locator (URL) -uuid: - example: - file: - path: "website/public/schemas/yaml/uuid.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/uuid.yaml" - typeSpec: - file: - path: "lib/core/lib/core/types.tsp" - startLine: 28 - endLine: 32 - typescript: - file: - path: "lib/ts-sdk/src/schemas/zod/types.ts" - startLine: 15 - endLine: 15 -email: - example: - file: - path: "website/public/schemas/yaml/email.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/email.yaml" - typeSpec: - file: - path: "lib/core/lib/core/types.tsp" - startLine: 34 - endLine: 38 -employerTaxId: - example: - file: - path: "website/public/schemas/yaml/employerTaxId.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/employerTaxId.yaml" - typeSpec: - file: - path: "lib/core/lib/core/types.tsp" - startLine: 40 - endLine: 44 -samUEI: - example: - file: - path: "website/public/schemas/yaml/samUEI.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/samUEI.yaml" - typeSpec: - file: - path: "lib/core/lib/core/types.tsp" - startLine: 46 - endLine: 50 -duns: - example: - file: - path: "website/public/schemas/yaml/duns.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/duns.yaml" - typeSpec: - file: - path: "lib/core/lib/core/types.tsp" - startLine: 52 - endLine: 56 -nonEmptyString: - example: - file: - path: "website/public/schemas/yaml/nonEmptyString.yaml" - jsonSchema: - file: - path: "website/public/schemas/yaml/nonEmptyString.yaml" - typeSpec: - file: - path: "lib/core/lib/core/types.tsp" - startLine: 58 - endLine: 62 --- import SchemaFormatTabs from "@/components/SchemaFormatTabs.astro"; @@ -125,59 +48,34 @@ A Uniform Resource Locator (URL). A universally unique identifier. - + ## email An email address. - + ## employerTaxId An Employer Identification Number (EIN). - + ## samUEI A Unique Entity Identifier (UEI). - + ## duns A Data Universal Numbering System (DUNS) number. - + ## nonEmptyString A string with at least one character, added in v0.5.0. Used for an organization's [`aliases`](/protocol/models/organization#organizationbase). - + diff --git a/website/src/lib/schema/schema-doc-mapper.ts b/website/src/lib/schema/schema-doc-mapper.ts index e3f218f69..ce368c976 100644 --- a/website/src/lib/schema/schema-doc-mapper.ts +++ b/website/src/lib/schema/schema-doc-mapper.ts @@ -1,56 +1,128 @@ -import { readFileSync } from "fs"; +import { readdirSync, readFileSync } from "fs"; +import * as path from "path"; +import yaml from "js-yaml"; import { Paths } from "./paths"; +/** A `` or `` tag's `schema="Name"` attribute */ +const SCHEMA_ATTRIBUTE = + /]*?\bschema="([^"]+)"/g; + +/** A frontmatter entry holding an inline JSON Schema */ +interface InlineSchemaEntry { + jsonSchema?: { code?: string }; +} + /** - * Schema documentation mapping service + * Maps each schema to the docs page that documents it, by reading which + * schemas each protocol page names. Schema tables use it to link a property's + * type to its page. + * + * Pages name a schema with `schema="Name"` on `` or + * ``. A section whose JSON Schema is written inline in the + * frontmatter (the basic types) maps under its frontmatter key and under the + * schema's JSON `type`. When two pages name a schema, the later page wins. + * + * @param protocolDocsDir - Directory of protocol pages to read + * @param contentDocsDir - Root of the docs content, which page URLs are relative to */ -export class SchemaDocMapper { - private static cache: Map | null = null; +export function buildSchemaDocMap( + protocolDocsDir: string, + contentDocsDir: string, +): Map { + const map = new Map(); - /** - * Gets the schema documentation mapping with memoization - * Loads pre-computed mapping and fails if not available - */ - static getSchemaDocMap(): Map { - if (this.cache) { - return this.cache; + for (const file of listPages(protocolDocsDir)) { + const content = readFileSync(file, "utf-8"); + const docPath = + "/" + + path + .relative(contentDocsDir, file) + .split(path.sep) + .join("/") + .replace(/\.mdx$/, ""); + + for (const match of content.matchAll(SCHEMA_ATTRIBUTE)) { + map.set(match[1], docPath); } - const mappingPath = Paths.SCHEMA_DOCS_MAPPING; + for (const [name, type] of inlineSchemas(content, file)) { + map.set(name, docPath); + if (type) map.set(type, docPath); + } + } - try { - const mappingContent = readFileSync(mappingPath, "utf-8"); - const mappingObject = JSON.parse(mappingContent); + return map; +} - const map = new Map(); - for (const [schemaName, docPath] of Object.entries(mappingObject)) { - map.set(schemaName, docPath as string); - } +/** Lists the inline JSON Schemas in a page's frontmatter, with their types. */ +function inlineSchemas( + content: string, + file: string, +): Array<[string, string | undefined]> { + const frontmatter = content.match(/^---\n([\s\S]*?)\n---/)?.[1]; + if (!frontmatter) return []; - this.cache = map; - console.log( - `Loaded pre-computed schema documentation mapping (${map.size} entries)`, - ); - return map; + const data = yaml.load(frontmatter) as Record; + const result: Array<[string, string | undefined]> = []; + for (const [name, entry] of Object.entries(data ?? {})) { + const code = (entry as InlineSchemaEntry | null)?.jsonSchema?.code; + if (typeof code !== "string") continue; + + let type: string | undefined; + try { + const schema = yaml.load(code) as { type?: unknown }; + if (typeof schema?.type === "string") type = schema.type; } catch (error) { - throw new Error( - `Failed to load schema documentation mapping from ${mappingPath}: ${error}`, - { cause: error }, + throw new Error(`Inline JSON Schema "${name}" in ${file} isn't YAML`, { + cause: error, + }); + } + result.push([name, type]); + } + return result; +} + +/** Lists the MDX pages under a directory, in a stable order. */ +function listPages(dir: string): string[] { + const files: string[] = []; + const entries = readdirSync(dir, { withFileTypes: true }).sort((a, b) => + a.name < b.name ? -1 : a.name > b.name ? 1 : 0, + ); + for (const entry of entries) { + const fullPath = path.join(dir, entry.name); + if (entry.isDirectory()) { + files.push(...listPages(fullPath)); + } else if (entry.isFile() && entry.name.endsWith(".mdx")) { + files.push(fullPath); + } + } + return files; +} + +/** + * Schema documentation mapping service. Builds the map from the protocol + * pages the first time it's asked, once per build. + */ +export class SchemaDocMapper { + private static cache: Map | null = null; + + /** Gets the schema documentation mapping, building it on first use */ + static getSchemaDocMap(): Map { + if (!this.cache) { + this.cache = buildSchemaDocMap( + Paths.PROTOCOL_DOCS_DIR, + Paths.CONTENT_DOCS_DIR, ); } + return this.cache; } - /** - * Gets documentation path for a specific schema name - */ + /** Gets documentation path for a specific schema name */ static getSchemaDocPath(schemaName: string): string | undefined { - const map = this.getSchemaDocMap(); - return map.get(schemaName); + return this.getSchemaDocMap().get(schemaName); } - /** - * Clears the cache (useful for testing) - */ + /** Clears the cache (useful for testing) */ static clearCache(): void { this.cache = null; } From f463bb1a41fde31b72d7b2e784b9fc219c227676 Mon Sep 17 00:00:00 2001 From: Bryan Thompson Date: Thu, 19 Nov 2026 14:05:13 -0800 Subject: [PATCH 3/3] fix(website): re-read sources on dev reload and show inherited Python 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. --- .../lib/schema/source-declarations.spec.ts | 50 +++++++++ website/src/components/SchemaFormatTabs.astro | 26 +++-- .../src/content/docs/protocol/pagination.mdx | 21 +++- website/src/content/docs/protocol/sorting.mdx | 21 +++- website/src/lib/schema/schema-doc-mapper.ts | 22 +--- website/src/lib/schema/source-declarations.ts | 101 +++++++++--------- 6 files changed, 159 insertions(+), 82 deletions(-) diff --git a/website/__tests__/lib/schema/source-declarations.spec.ts b/website/__tests__/lib/schema/source-declarations.spec.ts index 8e645a6c6..045518319 100644 --- a/website/__tests__/lib/schema/source-declarations.spec.ts +++ b/website/__tests__/lib/schema/source-declarations.spec.ts @@ -1,4 +1,6 @@ import { describe, it, expect } from "vitest"; +import { readFileSync } from "fs"; +import * as path from "path"; import { listTypeSpecDeclarations, listPythonDeclarations, @@ -6,9 +8,13 @@ import { findDeclaration, findSchemaDeclaration, findSnippet, + refreshDeclarationsForRender, sourceUrl, type Declaration, } from "@/lib/schema/source-declarations"; +import { Paths } from "@/lib/schema/paths"; + +const REPO_ROOT = Paths.REPO_ROOT; /** Picks one declaration out of a listing by name. */ function pick(declarations: Declaration[], name: string): Declaration { @@ -505,6 +511,30 @@ describe("findSnippet", () => { expect(snippet.endLine).toBe(model.endLine); }); + it("separates declarations shown together by the blank lines the source has above the later one", () => { + // Python classes sit two blank lines apart (PEP 8); FilterInfo is directly + // above Filtered, so the tab is an exact excerpt of the source. + const snippet = findSnippet("python", ["FilterInfo", "Filtered"]); + const source = readFileSync(path.join(REPO_ROOT, snippet.path), "utf-8") + .split("\n") + .slice(snippet.startLine - 1, snippet.endLine) + .join("\n"); + expect(snippet.code).toBe(source); + expect(snippet.code).toMatch(/\n\n\nclass Filtered\(/); + }); + + it("uses the later declaration's own spacing when other code sits between them", () => { + // PaginatedBodyParams sits between PaginatedBase and PaginatedQueryParams. + const snippet = findSnippet("python", [ + "PaginatedBase", + "PaginatedQueryParams", + ]); + const base = findDeclaration("python", "PaginatedBase"); + const params = findDeclaration("python", "PaginatedQueryParams"); + expect(snippet.code).toBe(`${base.code}\n\n\n${params.code}`); + expect(snippet.code).not.toMatch(/PaginatedBodyParams/); + }); + it("fails when declarations shown together are in different files", () => { expect(() => findSnippet("typeSpec", ["Money", "AwardBase"])).toThrow( /must be in one file/, @@ -518,6 +548,26 @@ describe("findSnippet", () => { }); }); +describe("refreshDeclarationsForRender", () => { + it("re-reads the sources once for each new render, and not again within it", () => { + const first = findDeclaration("python", "Money"); + expect(findDeclaration("python", "Money")).toBe(first); + + const render = {}; + refreshDeclarationsForRender(render); + const reread = findDeclaration("python", "Money"); + expect(reread).not.toBe(first); + expect(reread).toEqual(first); + + // Further components on the same page reuse what that render read. + refreshDeclarationsForRender(render); + expect(findDeclaration("python", "Money")).toBe(reread); + + refreshDeclarationsForRender({}); + expect(findDeclaration("python", "Money")).not.toBe(reread); + }); +}); + describe("sourceUrl", () => { it("links to the declaration's lines on GitHub", () => { expect(sourceUrl({ path: "lib/a.tsp", startLine: 3, endLine: 9 })).toBe( diff --git a/website/src/components/SchemaFormatTabs.astro b/website/src/components/SchemaFormatTabs.astro index 1b66a7854..a2977f028 100644 --- a/website/src/components/SchemaFormatTabs.astro +++ b/website/src/components/SchemaFormatTabs.astro @@ -8,19 +8,24 @@ import { generateSchemaExample } from "../lib/schema/example-generator"; import { schemaFilePath } from "../lib/schema/schema-files"; import { findSnippet, + refreshDeclarationsForRender, sourceUrl, type SourceLanguage, } from "../lib/schema/source-declarations"; /** * A literal code block, or a file to read whole. Pages give literal code for - * hand-written examples and inline JSON Schemas; the custom field catalog - * gives a file. + * hand-written examples and inline JSON Schemas. */ interface CodeBlockConfig { /** A literal code block to display. If provided, file is ignored. */ code?: string; - /** A file to display, by its path relative to the repository root */ + /** + * A JSON Schema file to display, by its path relative to the repository + * root. Only `jsonSchema` reads it: the custom field catalog passes its + * extension schema this way. Examples are literal code or generated from + * `schema`. + */ file?: { path: string; }; @@ -46,7 +51,7 @@ interface Props { /** The schema's name, which is also the name of its generated JSON Schema file */ schema?: string; /** Example JSON: literal code overrides the example generated from the schema */ - example?: CodeBlockConfig; + example?: Pick; /** JSON Schema: literal code for schemas with no generated file */ jsonSchema?: CodeBlockConfig; /** TypeSpec tab */ @@ -72,16 +77,19 @@ if (!example && !jsonSchemaConfig && !typeSpec && !python && !typescript) { const exampleCode = example?.code ? example.code - : example?.file?.path - ? await generateSchemaExample(example.file.path) - : schemaPath - ? await generateSchemaExample(schemaPath) - : null; + : schemaPath + ? await generateSchemaExample(schemaPath) + : null; const jsonSchemaCode = jsonSchemaConfig ? extractCode(jsonSchemaConfig) : null; const jsonSchemaUrl = jsonSchemaConfig ? extractSchemaUrl(jsonSchemaConfig) : null; +// In the dev server, re-read the sources once per page render so a source +// edit shows on reload; a production build reads them once. +if (import.meta.env.DEV) { + refreshDeclarationsForRender(Astro.locals); +} const typeSpecSnippet = snippet("typeSpec", typeSpec); const pythonSnippet = snippet("python", python); const typescriptSnippet = snippet("typescript", typescript); diff --git a/website/src/content/docs/protocol/pagination.mdx b/website/src/content/docs/protocol/pagination.mdx index ded8d7e12..fb956ab03 100644 --- a/website/src/content/docs/protocol/pagination.mdx +++ b/website/src/content/docs/protocol/pagination.mdx @@ -19,7 +19,12 @@ Query parameters for paginated routes. These parameters should be used on GET ro ### Formats - + ### Changelog @@ -38,7 +43,12 @@ Body parameters for paginated routes. These parameters should be used on POST an ### Formats - + ### Changelog @@ -59,7 +69,12 @@ Details about the paginated results. This model should included in the response ### Formats - + ### Changelog diff --git a/website/src/content/docs/protocol/sorting.mdx b/website/src/content/docs/protocol/sorting.mdx index fe6e885dc..bd135911a 100644 --- a/website/src/content/docs/protocol/sorting.mdx +++ b/website/src/content/docs/protocol/sorting.mdx @@ -44,7 +44,12 @@ Query parameters for sorting. These parameters should be used on GET routes that ### Formats - + ### Changelog @@ -64,7 +69,12 @@ Body parameters for sorting. These parameters should be used on POST and PUT rou ### Formats - + ### Changelog @@ -85,7 +95,12 @@ Information about the sort order of the items returned. This model should be inc ### Formats - + ### Changelog diff --git a/website/src/lib/schema/schema-doc-mapper.ts b/website/src/lib/schema/schema-doc-mapper.ts index ce368c976..ebecf760c 100644 --- a/website/src/lib/schema/schema-doc-mapper.ts +++ b/website/src/lib/schema/schema-doc-mapper.ts @@ -1,7 +1,8 @@ -import { readdirSync, readFileSync } from "fs"; +import { readFileSync } from "fs"; import * as path from "path"; import yaml from "js-yaml"; import { Paths } from "./paths"; +import { listFilesByExtension } from "./source-declarations"; /** A `` or `` tag's `schema="Name"` attribute */ const SCHEMA_ATTRIBUTE = @@ -31,7 +32,7 @@ export function buildSchemaDocMap( ): Map { const map = new Map(); - for (const file of listPages(protocolDocsDir)) { + for (const file of listFilesByExtension(protocolDocsDir, ".mdx")) { const content = readFileSync(file, "utf-8"); const docPath = "/" + @@ -82,23 +83,6 @@ function inlineSchemas( return result; } -/** Lists the MDX pages under a directory, in a stable order. */ -function listPages(dir: string): string[] { - const files: string[] = []; - const entries = readdirSync(dir, { withFileTypes: true }).sort((a, b) => - a.name < b.name ? -1 : a.name > b.name ? 1 : 0, - ); - for (const entry of entries) { - const fullPath = path.join(dir, entry.name); - if (entry.isDirectory()) { - files.push(...listPages(fullPath)); - } else if (entry.isFile() && entry.name.endsWith(".mdx")) { - files.push(fullPath); - } - } - return files; -} - /** * Schema documentation mapping service. Builds the map from the protocol * pages the first time it's asked, once per build. diff --git a/website/src/lib/schema/source-declarations.ts b/website/src/lib/schema/source-declarations.ts index fcd8399ad..52ea162c0 100644 --- a/website/src/lib/schema/source-declarations.ts +++ b/website/src/lib/schema/source-declarations.ts @@ -70,6 +70,21 @@ const SOURCES: Record< const indexes = new Map>(); +/** The render the indexes were last read for, if any */ +let indexedForRender: object | undefined; + +/** + * Makes the next lookup re-read the sources, once per render. The dev server + * calls this with the request's `Astro.locals`, so a page reload shows a + * source edit while the several tabs on one page still share one read. A + * production build never calls it, so it reads the sources once per build. + */ +export function refreshDeclarationsForRender(render: object): void { + if (render === indexedForRender) return; + indexedForRender = render; + indexes.clear(); +} + /** * TypeSpec namespaces whose declarations a bare name never refers to. * `CommonGrants.Patch` holds compile-time mirrors of the organization models @@ -136,7 +151,7 @@ function matchDeclarations( * its Zod schemas `Schema`. A page names the declaration explicitly * when an SDK doesn't follow this (its enums, for example, end in `Enum`). */ -export function conventionalName( +function conventionalName( language: SourceLanguage, schemaName: string, ): string { @@ -161,7 +176,8 @@ export function findSchemaDeclaration( * declaration's name, for an SDK that names it differently; or lists several * names, to show a template with the model built from it. Several * declarations must be in one file; each is shown whole, in the order listed, - * separated by a blank line. + * separated by as many blank lines as the source has above each later one + * (two between Python classes, one in TypeSpec). * * @throws if a declaration can't be found */ @@ -183,7 +199,7 @@ export function findSnippet( path: found[0].path, startLine: Math.min(...found.map((d) => d.startLine)), endLine: Math.max(...found.map((d) => d.endLine)), - code: found.map((d) => d.code).join("\n\n"), + code: joinAsInSource(found), }; } if (typeof requested === "string") { @@ -197,6 +213,25 @@ export function findSnippet( return findSchemaDeclaration(language, schemaName); } +/** Joins declarations from one file with the blank lines above each in the source. */ +function joinAsInSource(found: FoundDeclaration[]): string { + const lines = readFileSync( + path.join(Paths.REPO_ROOT, found[0].path), + "utf-8", + ).split("\n"); + return found + .map((declaration, i) => { + if (i === 0) return declaration.code; + let blanks = 0; + for (let line = declaration.startLine - 2; line >= 0; line--) { + if (lines[line].trim() !== "") break; + blanks++; + } + return "\n".repeat(Math.max(blanks, 1)) + declaration.code; + }) + .join("\n"); +} + /** * Links to a declaration's lines in the repository on GitHub. Keeps the * double slash the docs have always published. @@ -210,7 +245,7 @@ export function sourceUrl( return `https://github.com/HHS/simpler-grants-protocol/tree/main//${filePath}${lines}`; } -/** Lists every declaration in a language's source, by name, once per build. */ +/** Lists every declaration in a language's source, by name, until the next refresh. */ function getIndex(language: SourceLanguage): Map { const cached = indexes.get(language); if (cached) return cached; @@ -218,7 +253,7 @@ function getIndex(language: SourceLanguage): Map { const { dir, extension, list } = SOURCES[language]; const index = new Map(); - for (const file of listFiles(dir, extension)) { + for (const file of listFilesByExtension(dir, extension)) { const relativePath = path .relative(Paths.REPO_ROOT, file) .split(path.sep) @@ -242,47 +277,21 @@ function getIndex(language: SourceLanguage): Map { return index; } -/** Lists files with an extension under a directory, in a stable order. */ -function listFiles(dir: string, extension: string): string[] { - const files: string[] = []; - const entries = readdirSync(dir, { withFileTypes: true }).sort((a, b) => - a.name.localeCompare(b.name), - ); - for (const entry of entries) { - const fullPath = path.join(dir, entry.name); - if (entry.isDirectory()) { - files.push(...listFiles(fullPath, extension)); - } else if (entry.isFile() && entry.name.endsWith(extension)) { - files.push(fullPath); - } - } - return files; +/** + * Lists the files with an extension under a directory, recursively, sorted by + * path in code-point order so the result is the same on every machine. + */ +export function listFilesByExtension(dir: string, extension: string): string[] { + return readdirSync(dir, { recursive: true, withFileTypes: true }) + .filter((entry) => entry.isFile() && entry.name.endsWith(extension)) + .map((entry) => path.join(entry.parentPath, entry.name)) + .sort((a, b) => (a < b ? -1 : a > b ? 1 : 0)); } // ############################################################################ // Shared helpers // ############################################################################ -/** Converts a character offset to a 1-based line number. */ -function lineAt(lineStarts: number[], offset: number): number { - let low = 0; - let high = lineStarts.length - 1; - while (low < high) { - const mid = Math.ceil((low + high) / 2); - if (lineStarts[mid] <= offset) low = mid; - else high = mid - 1; - } - return low + 1; -} - -function getLineStarts(source: string): number[] { - const starts = [0]; - for (let i = 0; i < source.length; i++) { - if (source[i] === "\n") starts.push(i + 1); - } - return starts; -} - /** Builds a declaration from whole lines of the source. */ function fromLines( lines: string[], @@ -330,7 +339,8 @@ export function listTypeSpecDeclarations(source: string): Declaration[] { throw new Error(`TypeSpec source doesn't parse: ${messages}`); } - const lineStarts = getLineStarts(source); + const lineOf = (offset: number) => + ast.file.getLineAndCharacterOfPosition(offset).line + 1; const lines = source.split("\n"); const declarations: Declaration[] = []; @@ -364,8 +374,8 @@ export function listTypeSpecDeclarations(source: string): Declaration[] { ...fromLines( lines, name, - lineAt(lineStarts, statement.pos), - lineAt(lineStarts, statement.end - 1), + lineOf(statement.pos), + lineOf(statement.end - 1), ), namespace: current.join(".") || undefined, }); @@ -531,8 +541,3 @@ export function listPythonDeclarations(source: string): Declaration[] { return declarations; } - -/** Clears the cached source indexes (for tests). */ -export function clearDeclarationCache(): void { - indexes.clear(); -}