fastify/fastify

Option to align route params with schema at startup

开放

#5,215 创建于 2023年12月15日

 (23 条评论) (0 个反应) (0 位负责人)JavaScript (2,683 个派生)batch import
good first issueplugin suggestion

仓库指标

星标
 (36,241 个星标)
PR 合并指标
 (PR 指标待抓取)

描述

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the feature has not already been requested

🚀 Feature Proposal

Introduce startup validation in Fastify to check consistency between route parameters in path strings and schema definitions.

Motivation

Ensuring route parameter consistency to prevent runtime errors

Example

// Inconsistent route params and schema could lead to unnoticed issues until runtime
fastify.get('/item/:itemId', {
  schema: {
    params: {
      type: 'object',
      properties: {
        id: { type: 'string' } // Potential issue: 'itemId' in route vs 'id' in schema
      }
    }
  },
  handler: (request, reply) => { /* ... */ }
});

A pre-runtime check could catch these mismatches early, enhancing developer experience and application stability.

贡献者指南