Skip to content

Commit

Permalink
Omit path parmaeters from queryParms
Browse files Browse the repository at this point in the history
Closes #62.

Depends on #83.
  • Loading branch information
codetheweb committed Jul 13, 2023
1 parent 6d24e35 commit 7b5da6b
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/nextlove/src/generate-route-types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,21 @@ export const generateRouteTypes = async (opts: GenerateRouteTypesOpts) => {
// TODO when less lazy, use ts-morph for better generation
const routeDefs: string[] = []
for (const [_, { route, routeSpec, setupParams }] of filteredRoutes) {
const queryKeys = Object.keys(routeSpec.queryParams?.shape ?? {})
const pathParameters = queryKeys.filter((key) => route.includes(`[${key}]`))

const queryParamsSchemaWithoutPathParameters = routeSpec.queryParams?.omit(
Object.fromEntries(pathParameters.map((param) => [param, true]))
)

routeDefs.push(
`
"${route}": {
route: "${route}",
method: ${routeSpec.methods.map((m) => `"${m}"`).join(" | ")},
queryParams: ${
routeSpec.queryParams
? printNode(zodToTs(routeSpec.queryParams).node)
queryParamsSchemaWithoutPathParameters
? printNode(zodToTs(queryParamsSchemaWithoutPathParameters).node)
: "{}"
},
jsonBody: ${
Expand Down

0 comments on commit 7b5da6b

Please sign in to comment.