Skip to content

Commit

Permalink
feat: Allow including OpenAPI excluded routes in route type generation (
Browse files Browse the repository at this point in the history
  • Loading branch information
codetheweb authored Nov 8, 2023
1 parent 99fd08f commit 1daf8e7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ interface GenerateRouteTypesOpts {
* If provided, only routes that return true will be included in the generated types.
*/
filterRoutes?: (route: string) => boolean
/**
* By default, routes that have `excludeFromOpenApi` set to true will be excluded from the generated types.
* Set this to true to include them.
*/
includeOpenApiExcludedRoutes?: boolean
}

export const generateRouteTypes = async (opts: GenerateRouteTypesOpts) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const parseRoutesInPackage = async (opts: {
pathGlob?: string
apiPrefix?: string
mapFilePathToHTTPRoute?: (file_path: string) => string
includeOpenApiExcludedRoutes?: boolean
}): Promise<Map<string, RouteInfo>> => {
const chalk = (await import("chalk")).default
const globby = (await import("globby")).globby
Expand All @@ -37,7 +38,10 @@ export const parseRoutesInPackage = async (opts: {
const { default: routeFn } = await require(path.resolve(p))

if (routeFn) {
if (routeFn._routeSpec?.excludeFromOpenApi) {
if (
routeFn._routeSpec?.excludeFromOpenApi &&
!opts.includeOpenApiExcludedRoutes
) {
console.log(
chalk.gray(
`Ignoring "${p} because it was excluded from OpenAPI generation"`
Expand Down

0 comments on commit 1daf8e7

Please sign in to comment.