Skip to content

Commit

Permalink
feat: generate /events and event resource (#79)
Browse files Browse the repository at this point in the history
* feat: generate /events and event resource

* update test snapshot

* ci: Generate code

* ci: Generate code

* ci: Format code

---------

Co-authored-by: Seam Bot <devops@getseam.com>
  • Loading branch information
mikewuu and seambot authored Sep 11, 2024
1 parent 158bcd6 commit 2468558
Show file tree
Hide file tree
Showing 5 changed files with 1,513 additions and 140 deletions.
33 changes: 18 additions & 15 deletions src/lib/blueprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ export const createBlueprint = async (
const openapi = typesModule.openapi as Openapi

const isFakeData = openapi.info.title === 'Foo'
const targetPath = '/acs'
const targetPaths = ['/acs', '/events']
const targetSchemas = [
'acs_access_group',
'acs_credential',
Expand All @@ -254,6 +254,7 @@ export const createBlueprint = async (
'acs_entrance',
'acs_system',
'acs_user',
'event',
]

const context = {
Expand All @@ -263,7 +264,7 @@ export const createBlueprint = async (

return {
title: openapi.info.title,
routes: await createRoutes(openapi.paths, isFakeData, targetPath, context),
routes: await createRoutes(openapi.paths, isFakeData, targetPaths, context),
resources: createResources(
openapi.components.schemas,
isFakeData,
Expand All @@ -275,27 +276,29 @@ export const createBlueprint = async (
const createRoutes = async (
paths: OpenapiPaths,
isFakeData: boolean,
targetPath: string,
targetPaths: string[],
context: Context,
): Promise<Route[]> => {
const routeMap = new Map<string, Route>()

const pathEntries = Object.entries(paths).filter(
([path]) => isFakeData || path.startsWith(targetPath),
)
for (const targetPath of targetPaths) {
const pathEntries = Object.entries(paths).filter(
([path]) => isFakeData || path.startsWith(targetPath),
)

for (const [path, pathItem] of pathEntries) {
const namespace = getNamespace(path, paths)
for (const [path, pathItem] of pathEntries) {
const namespace = getNamespace(path, paths)

const route = await createRoute(namespace, path, pathItem, context)
const route = await createRoute(namespace, path, pathItem, context)

const existingRoute = routeMap.get(route.path)
if (existingRoute != null) {
existingRoute.endpoints.push(...route.endpoints)
continue
}
const existingRoute = routeMap.get(route.path)
if (existingRoute != null) {
existingRoute.endpoints.push(...route.endpoints)
continue
}

routeMap.set(route.path, route)
routeMap.set(route.path, route)
}
}

return Array.from(routeMap.values())
Expand Down
Loading

0 comments on commit 2468558

Please sign in to comment.