From 27fc1da9a934964cb4f4bb88b1ad32a768615671 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 24 Jul 2026 15:12:02 +0000 Subject: [PATCH] refactor(codegen): use blueprint omitUndocumented option Enable the `omitUndocumented` option when creating the blueprint so undocumented routes, endpoints, parameters, resources, events, action attempts, and properties are stripped upstream. This removes the need for the manual `isUndocumented` filters scattered throughout the codegen. Since @seamapi/smith's blueprint plugin does not forward this option, build the blueprint directly with `createBlueprint` and pass it in via Metalsmith metadata. Generated output is unchanged. Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01BrQiAv7j9XMWD12S9ax9Bt --- codegen/lib/resource-model.ts | 31 ++++++++----------------------- codegen/lib/routes.ts | 13 +++---------- codegen/smith.ts | 9 +++++++-- 3 files changed, 18 insertions(+), 35 deletions(-) diff --git a/codegen/lib/resource-model.ts b/codegen/lib/resource-model.ts index ac8ff30..d09fe76 100644 --- a/codegen/lib/resource-model.ts +++ b/codegen/lib/resource-model.ts @@ -33,36 +33,26 @@ export const createResourceObjectModel = ( const baseResources = new Map() for (const resource of blueprint.resources) { - if (resource.isUndocumented) continue - baseResources.set( - resource.resourceType, - documentedProperties(resource.properties), - ) + baseResources.set(resource.resourceType, resource.properties) } // The blueprint models events and action attempts as one resource per // variant. The PHP SDK has a single class for each, so the variants are // merged into one schema. - const events = blueprint.events.filter((event) => !event.isUndocumented) + const { events } = blueprint if (events.length > 0) { baseResources.set( 'event', - mergeProperties( - events.map((event) => documentedProperties(event.properties)), - ), + mergeProperties(events.map((event) => event.properties)), ) } - const actionAttempts = blueprint.actionAttempts.filter( - (actionAttempt) => !actionAttempt.isUndocumented, - ) + const { actionAttempts } = blueprint if (actionAttempts.length > 0) { baseResources.set( 'action_attempt', mergeProperties( - actionAttempts.map((actionAttempt) => - documentedProperties(actionAttempt.properties), - ), + actionAttempts.map((actionAttempt) => actionAttempt.properties), ), ) } @@ -107,7 +97,7 @@ const createResourceObjectProperty = ( const referenceName = pascalCase(`${baseName}_${property.name}`) if (property.format === 'object') { - const properties = documentedProperties(property.properties) + const { properties } = property if (properties.length > 0) { addSchema(referenceName, properties, baseName) @@ -118,12 +108,10 @@ const createResourceObjectProperty = ( if (property.format === 'list') { const itemProperties = property.itemFormat === 'object' - ? documentedProperties(property.itemProperties) + ? property.itemProperties : property.itemFormat === 'discriminated_object' ? mergeProperties( - property.variants.map((variant) => - documentedProperties(variant.properties), - ), + property.variants.map((variant) => variant.properties), ) : [] @@ -140,9 +128,6 @@ const createResourceObjectProperty = ( } } -const documentedProperties = (properties: Property[]): Property[] => - properties.filter((property) => !property.isUndocumented) - const mergeProperties = (propertyLists: Property[][]): Property[] => { const merged = new Map() diff --git a/codegen/lib/routes.ts b/codegen/lib/routes.ts index 0869564..4e7e359 100644 --- a/codegen/lib/routes.ts +++ b/codegen/lib/routes.ts @@ -70,17 +70,12 @@ export const routes = ( } for (const route of blueprint.routes) { - if (route.isUndocumented) continue - - const endpoints = route.endpoints.filter( - (endpoint) => !endpoint.isUndocumented, - ) - if (endpoints.length === 0) continue + if (route.endpoints.length === 0) continue const namespaceSegments = route.path.split('/').filter((s) => s.length > 0) const client = ensureClient(namespaceSegments) - for (const endpoint of endpoints) { + for (const endpoint of route.endpoints) { client.methods.push(createClientMethod(endpoint)) } } @@ -114,9 +109,7 @@ const createClientMethod = (endpoint: Endpoint): PhpClientMethod => { return { methodName: endpoint.name, path: endpoint.path, - parameters: endpoint.request.parameters - .filter((parameter) => !parameter.isUndocumented) - .map((parameter) => ({ + parameters: endpoint.request.parameters.map((parameter) => ({ name: parameter.name, type: getPhpType(parameter), required: parameter.isRequired, diff --git a/codegen/smith.ts b/codegen/smith.ts index 53f4a02..5e9099c 100644 --- a/codegen/smith.ts +++ b/codegen/smith.ts @@ -2,7 +2,8 @@ import { dirname } from 'node:path' import { fileURLToPath } from 'node:url' import layouts from '@metalsmith/layouts' -import { blueprint, getHandlebarsPartials } from '@seamapi/smith' +import { createBlueprint } from '@seamapi/blueprint' +import { getHandlebarsPartials } from '@seamapi/smith' import * as types from '@seamapi/types/connect' import { deleteAsync } from 'del' import Metalsmith from 'metalsmith' @@ -15,11 +16,15 @@ await Promise.all([deleteAsync(['./src/Objects', './src/SeamClient.php'])]) const partials = await getHandlebarsPartials(`${rootDir}/layouts/partials`) +// Generate the blueprint with undocumented endpoints, resources, parameters, +// and properties already omitted, so the codegen only sees the public API. +const blueprint = await createBlueprint({ ...types }, { omitUndocumented: true }) + Metalsmith(rootDir) .source('./content') .destination('../') .clean(false) - .use(blueprint({ types })) + .metadata({ blueprint }) .use(routes) .use( layouts({