diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 6f17d73c1..c22e15ffd 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,3 +1,3 @@ * @seamapi/sdk /docs/ @seamapi/docs -/src/data/code-sample-definitions @seamapi/docs +/src/data @seamapi/docs diff --git a/package-lock.json b/package-lock.json index 6290d72a5..2ba89457d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,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", @@ -767,9 +767,9 @@ "peer": true }, "node_modules/@seamapi/blueprint": { - "version": "0.40.2", - "resolved": "https://registry.npmjs.org/@seamapi/blueprint/-/blueprint-0.40.2.tgz", - "integrity": "sha512-LNJIZ+E8urW4SZWVe94/7+ESo+cbjEoqeZIWQyCEj2q/mv2XX8xpXkQE0uvfj/gu31A3tYIBE0HHfs456RQ/Yw==", + "version": "0.41.0", + "resolved": "https://registry.npmjs.org/@seamapi/blueprint/-/blueprint-0.41.0.tgz", + "integrity": "sha512-kf//qq3tA1xFvNMJrO4V0rN7x2FHEDGKiCQafzI6keTKhQtjghZl1M8hS64QicuQG7DrcUZXiVQS7ZexSLeGGw==", "license": "MIT", "dependencies": { "change-case": "^5.4.4", diff --git a/package.json b/package.json index de9a95f4a..0ed9c0736 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/data/resource-sample-definitions/acs-system.yaml b/src/data/resource-sample-definitions/acs-system.yaml new file mode 100644 index 000000000..e6f82cdfa --- /dev/null +++ b/src/data/resource-sample-definitions/acs-system.yaml @@ -0,0 +1,6 @@ +--- +- title: ACS System + description: A basic system. + resource_type: acs_system + properties: + acs_system_id: 'bbcea306-7201-4d85-b527-3abc55277203' diff --git a/src/lib/blueprint.ts b/src/lib/blueprint.ts index bb339aa39..a521c753e 100644 --- a/src/lib/blueprint.ts +++ b/src/lib/blueprint.ts @@ -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, { diff --git a/src/lib/format-code.ts b/src/lib/format-code.ts index 261864a0b..b64850aff 100644 --- a/src/lib/format-code.ts +++ b/src/lib/format-code.ts @@ -1,13 +1,13 @@ 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 => { const output = await formatCodeForSyntax(content, syntax) return output.trim() @@ -15,7 +15,7 @@ export const formatCode = async ( const formatCodeForSyntax = async ( content: string, - syntax: CodeSampleSyntax, + syntax: SyntaxName, ): Promise => { switch (syntax) { case 'javascript': diff --git a/src/lib/layout/api-endpoint.ts b/src/lib/layout/api-endpoint.ts index eb71feae9..5d32f965d 100644 --- a/src/lib/layout/api-endpoint.ts +++ b/src/lib/layout/api-endpoint.ts @@ -1,8 +1,8 @@ import type { ActionAttempt, - CodeSampleSdk, Endpoint, Parameter, + SdkName, SeamAuthMethod, SeamWorkspaceScope, } from '@seamapi/blueprint' @@ -14,7 +14,7 @@ import { normalizePropertyFormatForDocs, } from './api-route.js' -const supportedSdks: CodeSampleSdk[] = [ +const supportedSdks: SdkName[] = [ 'javascript', 'python', 'php', @@ -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, diff --git a/src/lib/layout/api-route.ts b/src/lib/layout/api-route.ts index db8c1d043..6fcf63398 100644 --- a/src/lib/layout/api-route.ts +++ b/src/lib/layout/api-route.ts @@ -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' @@ -18,6 +23,7 @@ export interface ApiRouteLayoutContext { ApiRouteResource & { warnings: ApiWarning[] errors: ApiError[] + resourceSamples: ResourceSampleContext[] } > endpoints: ApiRouteEndpoint[] @@ -30,6 +36,12 @@ interface ApiRouteEvent { properties: ApiRouteProperty[] } +interface ResourceSampleContext { + title: string + resourceData: string + resourceDataSyntax: SyntaxName +} + type ApiRouteProperty = Pick< Property, 'name' | 'description' | 'isDeprecated' | 'deprecationMessage' @@ -144,6 +156,7 @@ export function setApiRouteLayoutContext( errors: resourceErrors, warnings: resourceWarnings, events: resourceEvents, + resourceSamples: resource.resourceSamples.map(mapResourceSample), }) } } @@ -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, + } +} diff --git a/src/metalsmith.ts b/src/metalsmith.ts index e6ba876dd..4e2ee9990 100644 --- a/src/metalsmith.ts +++ b/src/metalsmith.ts @@ -29,6 +29,7 @@ Metalsmith(rootDir) .use( metadata({ codeSampleDefinitions: './data/code-sample-definitions', + resourceSampleDefinitions: './data/resource-sample-definitions', pathMetadata: './data/paths.yaml', }), )