Skip to content

Commit

Permalink
Add pathMetadata
Browse files Browse the repository at this point in the history
  • Loading branch information
razor-x committed Oct 10, 2024
1 parent 53d6fe3 commit 7727d7a
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/data/paths.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
/acs/systems:
description: null
5 changes: 4 additions & 1 deletion src/lib/blueprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ export const blueprint = async (
const codeSampleDefinitions =
'codeSampleDefinitions' in metadata ? metadata.codeSampleDefinitions : []

// UPSTREAM: Ideally, path metadata would be unnecessary and contained inside the blueprint.
const pathMetadata = 'pathMetadata' in metadata ? metadata.pathMetadata : {}

const typesModule = TypesModuleSchema.parse({
...types,
codeSampleDefinitions,
})

const blueprint = await createBlueprint(typesModule, { formatCode })
Object.assign(metadata, blueprint)
Object.assign(metadata, { ...blueprint, pathMetadata })
}
5 changes: 5 additions & 0 deletions src/lib/layout-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import type {
} from '@seamapi/blueprint'
import { pascalCase } from 'change-case'

import type { PathMetadata } from './reference.js'

const supportedSdks: CodeSampleSdk[] = [
'javascript',
'python',
Expand Down Expand Up @@ -113,6 +115,7 @@ interface ContextResource {
type ContextEndpoint = Pick<Endpoint, 'path' | 'description'>

export interface RouteLayoutContext {
description: string | null
resources: ContextResource[]
endpoints: ContextEndpoint[]
}
Expand All @@ -121,7 +124,9 @@ export function setApiRouteLayoutContext(
file: Partial<RouteLayoutContext>,
route: Route,
blueprint: Blueprint,
pathMetadata: PathMetadata,
): void {
file.description = pathMetadata[route.path]?.description ?? null
file.endpoints = route.endpoints.map(({ path, name, description }) => ({
path,
name,
Expand Down
18 changes: 14 additions & 4 deletions src/lib/reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,28 @@ type Metadata = Partial<Pick<Blueprint, 'routes' | 'resources'>>

type File = EndpointLayoutContext & RouteLayoutContext & { layout: string }

export type PathMetadata = Record<
string,
{
description?: string | null
}
>

export const reference = (
files: Metalsmith.Files,
metalsmith: Metalsmith,
): void => {
const metadata = {
const { pathMetadata = {}, ...metadata } =
metalsmith.metadata() as Metadata & { pathMetadata: PathMetadata }

const blueprint = {
title: '',
routes: [],
resources: {},
...(metalsmith.metadata() as Metadata),
...metadata,
}

for (const route of metadata.routes ?? []) {
for (const route of blueprint.routes ?? []) {
if (route.isUndocumented) continue

if (!route.path.startsWith('/acs/systems')) {
Expand All @@ -38,7 +48,7 @@ export const reference = (
}
const file = files[k] as unknown as File
file.layout = 'api-route.hbs'
setApiRouteLayoutContext(file, route, metadata)
setApiRouteLayoutContext(file, route, blueprint, pathMetadata)

for (const endpoint of route.endpoints) {
if (endpoint.isUndocumented) continue
Expand Down
1 change: 1 addition & 0 deletions src/metalsmith.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Metalsmith(rootDir)
.use(
metadata({
codeSampleDefinitions: './data/code-sample-definitions',
pathMetadata: './data/paths.yaml',
}),
)
.use(blueprint)
Expand Down

0 comments on commit 7727d7a

Please sign in to comment.