diff --git a/src/lib/syncPagePath.ts b/src/lib/syncPagePath.ts index ddd02f420..c84098db6 100644 --- a/src/lib/syncPagePath.ts +++ b/src/lib/syncPagePath.ts @@ -3,6 +3,8 @@ import type { GuidesRequestRepresentation, GuidesResponseRepresentation, ProjectRepresentation, + ReferenceRequestRepresentation, + ReferenceResponseRepresentation, } from './types/index.js'; import chalk from 'chalk'; @@ -15,9 +17,8 @@ import { findPages, type PageMetadata } from './readPage.js'; import { categoryUriRegexPattern, parentUriRegexPattern } from './types/index.js'; import { validateFrontmatter } from './validateFrontmatter.js'; -// todo: eventually this type will be used for other page types (e.g., API Reference) -type PageRequestRepresentation = GuidesRequestRepresentation; -type PageResponseRepresentation = GuidesResponseRepresentation['data']; +type PageRequestRepresentation = GuidesRequestRepresentation | ReferenceRequestRepresentation; +type PageResponseRepresentation = GuidesResponseRepresentation['data'] | ReferenceResponseRepresentation['data']; interface BasePushResult { filePath: string; diff --git a/src/lib/types/index.ts b/src/lib/types/index.ts index 8c96d2306..401e83f25 100644 --- a/src/lib/types/index.ts +++ b/src/lib/types/index.ts @@ -10,17 +10,36 @@ export const parentUriRegexPattern = readmeAPIv2Oas.paths['/branches/{branch}/guides'].post.requestBody.content['application/json'].schema.properties .parent.properties.uri.pattern; +type projectSchema = + (typeof readmeAPIv2Oas)['paths']['/projects/me']['get']['responses']['200']['content']['application/json']['schema']; + +type apiKeySchema = + (typeof readmeAPIv2Oas)['paths']['/projects/{subdomain}/apikeys/{api_key_id}']['get']['responses']['200']['content']['application/json']['schema']; + +/** Page schemas */ type guidesRequestBodySchema = (typeof readmeAPIv2Oas)['paths']['/branches/{branch}/guides/{slug}']['patch']['requestBody']['content']['application/json']['schema']; type guidesResponseBodySchema = (typeof readmeAPIv2Oas)['paths']['/branches/{branch}/guides/{slug}']['patch']['responses']['200']['content']['application/json']['schema']; -type projectSchema = - (typeof readmeAPIv2Oas)['paths']['/projects/me']['get']['responses']['200']['content']['application/json']['schema']; +type referenceRequestBodySchema = + (typeof readmeAPIv2Oas)['paths']['/branches/{branch}/reference/{slug}']['patch']['requestBody']['content']['application/json']['schema']; -type apiKeySchema = - (typeof readmeAPIv2Oas)['paths']['/projects/{subdomain}/apikeys/{api_key_id}']['get']['responses']['200']['content']['application/json']['schema']; +type referenceResponseBodySchema = + (typeof readmeAPIv2Oas)['paths']['/branches/{branch}/reference/{slug}']['patch']['responses']['200']['content']['application/json']['schema']; + +/** + * Derived from our API documentation, this is the schema for the `project` object + * as we receive it to the ReadMe API. + */ +export type ProjectRepresentation = FromSchema; + +/** + * Derived from our API documentation, this is the schema for the API key object + * as we receive it to the ReadMe API. + */ +export type APIKeyRepresentation = FromSchema; /** * Derived from our API documentation, this is the schema for the `guides` object @@ -44,13 +63,22 @@ export type GuidesResponseRepresentation = FromSchema< >; /** - * Derived from our API documentation, this is the schema for the `project` object - * as we receive it to the ReadMe API. + * Derived from our API documentation, this is the schema for the `reference` object + * as we send it to the ReadMe API. + * + * This is only for TypeScript type-checking purposes — we use ajv + * to validate the user's schema during runtime. */ -export type ProjectRepresentation = FromSchema; +export type ReferenceRequestRepresentation = FromSchema< + referenceRequestBodySchema, + { keepDefaultedPropertiesOptional: true } +>; /** - * Derived from our API documentation, this is the schema for the API key object + * Derived from our API documentation, this is the schema for the `reference` object * as we receive it to the ReadMe API. */ -export type APIKeyRepresentation = FromSchema; +export type ReferenceResponseRepresentation = FromSchema< + referenceResponseBodySchema, + { keepDefaultedPropertiesOptional: true } +>;