Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
* @seamapi/sdk
/docs/ @seamapi/docs
/src/data/code-sample-definitions @seamapi/docs
/src/data @seamapi/docs
8 changes: 4 additions & 4 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"@metalsmith/metadata": "^0.3.0",
"@prettier/plugin-php": "^0.22.2",
"@prettier/plugin-ruby": "^4.0.4",
"@seamapi/blueprint": "^0.40.2",
"@seamapi/blueprint": "^0.41.0",
"@seamapi/types": "1.392.1",
"change-case": "^5.4.4",
"command-exists": "^1.2.9",
Expand Down
6 changes: 6 additions & 0 deletions src/data/resource-sample-definitions/acs-system.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- title: ACS System
description: A basic system.
resource_type: acs_system
properties:
acs_system_id: 'bbcea306-7201-4d85-b527-3abc55277203'
6 changes: 6 additions & 0 deletions src/lib/blueprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@ export const blueprint =
const codeSampleDefinitions =
'codeSampleDefinitions' in metadata ? metadata.codeSampleDefinitions : []

const resourceSampleDefinitions =
'resourceSampleDefinitions' in metadata
? metadata.resourceSampleDefinitions
: []

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

const blueprint = await createBlueprint(typesModule, {
Expand Down
6 changes: 3 additions & 3 deletions src/lib/format-code.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import * as prettierPluginPhp from '@prettier/plugin-php/standalone'
import * as prettierPluginRuby from '@prettier/plugin-ruby'
import type { CodeSampleSyntax } from '@seamapi/blueprint'
import type { SyntaxName } from '@seamapi/blueprint'
import commandExists from 'command-exists'
import { execa } from 'execa'
import { format as prettier } from 'prettier'

export const formatCode = async (
content: string,
syntax: CodeSampleSyntax,
syntax: SyntaxName,
): Promise<string> => {
const output = await formatCodeForSyntax(content, syntax)
return output.trim()
}

const formatCodeForSyntax = async (
content: string,
syntax: CodeSampleSyntax,
syntax: SyntaxName,
): Promise<string> => {
switch (syntax) {
case 'javascript':
Expand Down
6 changes: 3 additions & 3 deletions src/lib/layout/api-endpoint.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type {
ActionAttempt,
CodeSampleSdk,
Endpoint,
Parameter,
SdkName,
SeamAuthMethod,
SeamWorkspaceScope,
} from '@seamapi/blueprint'
Expand All @@ -14,7 +14,7 @@ import {
normalizePropertyFormatForDocs,
} from './api-route.js'

const supportedSdks: CodeSampleSdk[] = [
const supportedSdks: SdkName[] = [
'javascript',
'python',
'php',
Expand Down Expand Up @@ -195,7 +195,7 @@ const mapBlueprintParamToEndpointParam = (

const mapCodeSample = (sample: CodeSample): CodeSampleContext => {
const codeEntries = Object.entries(sample.code).filter(([k]) =>
supportedSdks.includes(k as CodeSampleSdk),
supportedSdks.includes(k as SdkName),
)
return {
title: sample.title,
Expand Down
31 changes: 31 additions & 0 deletions src/lib/layout/api-route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import type {
Route,
} from '@seamapi/blueprint'
import { pascalCase } from 'change-case'
import type {
SdkName,
SyntaxName,
} from 'node_modules/@seamapi/blueprint/dist/index.cjs'
import type { ResourceSample } from 'node_modules/@seamapi/blueprint/lib/samples/resource-sample.js'

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

Expand All @@ -18,6 +23,7 @@ export interface ApiRouteLayoutContext {
ApiRouteResource & {
warnings: ApiWarning[]
errors: ApiError[]
resourceSamples: ResourceSampleContext[]
}
>
endpoints: ApiRouteEndpoint[]
Expand All @@ -30,6 +36,12 @@ interface ApiRouteEvent {
properties: ApiRouteProperty[]
}

interface ResourceSampleContext {
title: string
resourceData: string
resourceDataSyntax: SyntaxName
}

type ApiRouteProperty = Pick<
Property,
'name' | 'description' | 'isDeprecated' | 'deprecationMessage'
Expand Down Expand Up @@ -144,6 +156,7 @@ export function setApiRouteLayoutContext(
errors: resourceErrors,
warnings: resourceWarnings,
events: resourceEvents,
resourceSamples: resource.resourceSamples.map(mapResourceSample),
})
}
}
Expand Down Expand Up @@ -337,3 +350,21 @@ function addLinkTargetsToProperties(
}
}
}

const mapResourceSample = (sample: ResourceSample): ResourceSampleContext => {
const jsonSample = Object.entries(sample.resource).find(
([k]) => (k as SdkName) === 'seam_cli',
)?.[1]

if (jsonSample == null) {
throw new Error(
`Missing seam_cli for ${sample.resource_type} resource sample: ${sample.title}`,
)
}

return {
title: sample.title,
resourceData: jsonSample.resource_data,
resourceDataSyntax: jsonSample.resource_data_syntax,
}
}
1 change: 1 addition & 0 deletions src/metalsmith.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Metalsmith(rootDir)
.use(
metadata({
codeSampleDefinitions: './data/code-sample-definitions',
resourceSampleDefinitions: './data/resource-sample-definitions',
pathMetadata: './data/paths.yaml',
}),
)
Expand Down
Loading