diff --git a/packages/core/server/src/routes/web/api/sidebar.ts b/packages/core/server/src/routes/web/api/sidebar.ts index 99f96f16d..b82b0c8e7 100644 --- a/packages/core/server/src/routes/web/api/sidebar.ts +++ b/packages/core/server/src/routes/web/api/sidebar.ts @@ -14,20 +14,55 @@ import { const debug = buildDebug('verdaccio:web:api:sidebar'); export type $SidebarPackage = Package & { latest: Version }; +const stringType = { type: 'string' }; +const packageNameSchema = { packageName: stringType }; +const paramsSchema = { + scope: stringType, + packageName: stringType, +}; async function sidebarRoute(fastify: FastifyInstance) { - fastify.get('/sidebar/(@:scope/)?:packageName', async (request, reply) => { - // @ts-ignore - const { packageName, scope } = request.params; - debug('pkg name %s, scope %s ', packageName, scope); - getSidebar(fastify, request, packageName, (err, sidebar) => { - if (err) { - reply.send(err); - } else { - reply.code(fastify.statusCode.OK).send(sidebar); - } - }); - }); + fastify.get( + '/sidebar/:scope/:packageName', + { + schema: { + params: paramsSchema, + }, + }, + async (request, reply) => { + // @ts-ignore + const { packageName, scope } = request.params; + debug('pkg name %s, scope %s ', packageName, scope); + getSidebar(fastify, request, packageName, (err, sidebar) => { + if (err) { + reply.send(err); + } else { + reply.code(fastify.statusCode.OK).send(sidebar); + } + }); + } + ); + + fastify.get( + '/sidebar/:packageName', + { + schema: { + params: packageNameSchema, + }, + }, + async (request, reply) => { + // @ts-ignore + const { packageName, scope } = request.params; + debug('pkg name %s, scope %s ', packageName, scope); + getSidebar(fastify, request, packageName, (err, sidebar) => { + if (err) { + reply.send(err); + } else { + reply.code(fastify.statusCode.OK).send(sidebar); + } + }); + } + ); } function getSidebar(fastify: FastifyInstance, request: any, packageName, callback) {