Skip to content

Commit

Permalink
fix(openapi): multi-level group route .openapi() parsing (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrsafalpiya authored Nov 23, 2024
1 parent ab51d40 commit 58f94ad
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/neat-planets-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tuyau/openapi': patch
---

Fixed multi-level group route `.openapi()` parsing.
10 changes: 9 additions & 1 deletion packages/openapi/src/bindings/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function registerRouteMacros(metaStore: MetaStore) {
)

RouteGroup.macro('openapi', function (this: RouteGroup, detail: OpenAPIV3_1.OperationObject) {
this.routes.forEach((route) => {
function handleAnyRouteType(route: Route | RouteGroup | RouteResource | BriskRoute) {
if (route instanceof Route) {
metaStore.set(route, { ...detail, ...metaStore.get(route) })
} else if (route instanceof RouteResource) {
Expand All @@ -40,7 +40,15 @@ export function registerRouteMacros(metaStore: MetaStore) {
)
} else if (route instanceof BriskRoute) {
metaStore.set(route.route!, { ...detail, ...metaStore.get(route.route!) })
} else if (route instanceof RouteGroup) {
route.routes.forEach((route) => {
handleAnyRouteType(route)
})
}
}

this.routes.forEach((route) => {
handleAnyRouteType(route)
})
return this
})
Expand Down

0 comments on commit 58f94ad

Please sign in to comment.