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
31 changes: 8 additions & 23 deletions codegen/lib/resource-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,36 +33,26 @@ export const createResourceObjectModel = (
const baseResources = new Map<string, Property[]>()

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),
),
)
}
Expand Down Expand Up @@ -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)
Expand All @@ -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),
)
: []

Expand All @@ -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<string, Property>()

Expand Down
13 changes: 3 additions & 10 deletions codegen/lib/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
Expand Down Expand Up @@ -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,
Expand Down
9 changes: 7 additions & 2 deletions codegen/smith.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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({
Expand Down
Loading