Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: generate /events and event resource #79

Merged
merged 6 commits into from
Sep 11, 2024
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
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