Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add description for /acs/systems #375

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/api/acs/systems/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
---
description: Access Control Systems
---
```
/acs/systems
```
Comment on lines +4 to +6
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DebbieAtSeam Thoughts on putting the route on the page somewhere? I don't like this format, but how else to show it?
image


# `acs_system`

Represents an [access control system](https://docs.seam.co/latest/capability-guides/access-systems).
Expand Down
3 changes: 3 additions & 0 deletions docs/api/acs/systems/get.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
---
description: Get an ACS System
---
# Get an ACS System

```
Expand Down
3 changes: 3 additions & 0 deletions docs/api/acs/systems/list.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
---
description: List ACS Systems
---
# List ACS Systems

```
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
---
description: List Compatible Credential Manager ACS Systems
---
# List Compatible Credential Manager ACS Systems

```
Expand Down
3 changes: 2 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
"execa": "^9.3.1",
"jstransformer-handlebars": "^1.2.0",
"metalsmith": "^2.6.3",
"prettier": "^3.0.0"
"prettier": "^3.0.0",
"zod": "^3.23.8"
},
"devDependencies": {
"@types/command-exists": "^1.2.3",
Expand Down
19 changes: 18 additions & 1 deletion src/data/paths.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
---
/acs/systems:
description: null
page:
title: Systems
description: Access Control Systems

/acs/systems/get:
page:
title: Get an ACS System
description: Get an ACS System

/acs/systems/list:
page:
title: List ACS Systems
description: List ACS Systems

/acs/systems/list_compatible_credential_manager_acs_systems:
page:
title: List Compatible Credential Manager ACS Systems
description: List Compatible Credential Manager ACS Systems
Comment on lines +3 to +20
Copy link
Contributor Author

@razor-x razor-x Oct 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DebbieAtSeam Can you suggest descriptions here? The page titles need to match what is in SUMMARY.md and will be used later to generate that section of SUMMARY.md.

The page descriptions are for SEO. We can't use the long form descriptions because they may be too long or contain markdown formatting.

I am somewhat concerned about duplicated content.

image

3 changes: 3 additions & 0 deletions src/layouts/api-endpoint.hbs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
---
description: {{page.description}}
---
# {{title}}

```
Expand Down
7 changes: 7 additions & 0 deletions src/layouts/api-route.hbs
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
---
description: {{page.description}}
---
```
{{path}}
```

{{#each resources}}
# `{{name}}`
{{#if description}}
Expand Down
5 changes: 1 addition & 4 deletions src/lib/blueprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,11 @@ 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, pathMetadata })
Object.assign(metadata, blueprint)
}
26 changes: 23 additions & 3 deletions src/lib/layout-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
} from '@seamapi/blueprint'
import { pascalCase } from 'change-case'

import type { PathMetadata } from './reference.js'
import type { PathMetadata } from './path-metadata.js'

const supportedSdks: CodeSampleSdk[] = [
'javascript',
Expand All @@ -21,6 +21,10 @@ export interface EndpointLayoutContext {
description: string
title: string
path: string
page: {
title: string
description: string
}
request: {
preferredMethod: string
parameters: Array<{
Expand Down Expand Up @@ -54,10 +58,16 @@ export interface EndpointLayoutContext {
export function setEndpointLayoutContext(
file: Partial<EndpointLayoutContext>,
endpoint: Endpoint,
pathMetadata: PathMetadata,
): void {
file.description = endpoint.description
file.title = endpoint.title
file.path = endpoint.path
const page = pathMetadata[endpoint.path]?.page
if (page == null) {
throw new Error(`Missing page metadata for ${endpoint.path}`)
}
file.page = page

file.request = {
preferredMethod: endpoint.request?.preferredMethod ?? '',
Expand Down Expand Up @@ -115,7 +125,12 @@ interface ContextResource {
type ContextEndpoint = Pick<Endpoint, 'path' | 'description'>

export interface RouteLayoutContext {
description: string | null
page: {
title: string
description: string
}
description: string
path: string
resources: ContextResource[]
endpoints: ContextEndpoint[]
}
Expand All @@ -126,7 +141,12 @@ export function setApiRouteLayoutContext(
blueprint: Blueprint,
pathMetadata: PathMetadata,
): void {
file.description = pathMetadata[route.path]?.description ?? null
const page = pathMetadata[route.path]?.page
if (page == null) {
throw new Error(`Missing page metadata for ${route.path}`)
}
file.page = page
file.path = route.path
file.endpoints = route.endpoints.map(({ path, name, description }) => ({
path,
name,
Expand Down
13 changes: 13 additions & 0 deletions src/lib/path-metadata.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { z } from 'zod'

export const PathMetadataSchema = z.record(
z.string(),
z.object({
page: z.object({
title: z.string().trim().min(1),
description: z.string().trim().min(1),
}),
}),
)

export type PathMetadata = z.infer<typeof PathMetadataSchema>
21 changes: 10 additions & 11 deletions src/lib/reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,25 @@ import {
setApiRouteLayoutContext,
setEndpointLayoutContext,
} from './layout-context.js'
import { PathMetadataSchema } from './path-metadata.js'

const sdks: Array<'javascript'> = []

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 { pathMetadata = {}, ...metadata } =
metalsmith.metadata() as Metadata & { pathMetadata: PathMetadata }
const metadata = metalsmith.metadata() as Metadata

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

const blueprint = {
title: '',
Expand Down Expand Up @@ -59,7 +58,7 @@ export const reference = (
}
const file = files[k] as unknown as File
file.layout = 'api-endpoint.hbs'
setEndpointLayoutContext(file, endpoint)
setEndpointLayoutContext(file, endpoint, pathMetadata)

for (const sdk of sdks) {
const k = `sdk/${sdk}${endpoint.path}.md`
Expand All @@ -68,7 +67,7 @@ export const reference = (
}
const file = files[k] as unknown as File
file.layout = 'sdk-reference.hbs'
setEndpointLayoutContext(file, endpoint)
setEndpointLayoutContext(file, endpoint, pathMetadata)
}
}
}
Expand Down