Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Access request data from inside JSON schema or keyword validator

オープン
#1,007 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
20/100
issue の種類
機能追加
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
javascript, node.js
領域
api, backend

調査の方向性

ファイル、テスト、またはエントリーポイントは指定されていません。まず、Fastify のスキーマ検証ライフサイクルとカスタムキーワードのドキュメントを確認し、次にそこでリクエストスコープのデータを使用できるかどうかを判断します。完了条件は、スキーマ検証エラーを保持したまま、先行するフックのデータにアクセスするためのサポートされたアプローチを文書化または確認することです。

索引モデルが issue の本文から書いたものです。

説明

help wanted

💬 Question here

I'd like to use data from an earlier hook as part of the schema for a later route. Is this possible to do? For example:

fastify.post(
  '/',
  {
    schema: {
      body: {
        type: 'object',
        properties: {
          myCoolProp: { enum: req.arrayValueFromEarlierHook },
        },
        required: ['myCoolProp'],
      },
    },
  },
  async (req, res) => {
    // bleh
  },
);

I know I could also do the validation manually in the route handler itself, but it'd be nice to get the built-in error messaging, etc. by using a schema. I realize it's not possible to simply declare it the way I did in the example above since they're compiled on server start, but the example is just to get the use case across. I was looking at adding a custom keyword as well, but it doesn't appear the keyword validate function has access to the request object either. Is there a straightforward way to achieve this, or is this simply not possible?

Your Environment

  • node version: latest
  • fastify version: latest
  • os: Mac and Linux
主要言語
言語のデータがありません
スター
68
フォーク
8
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

fastify/help のほかの issue

fastify/help の issue をすべて見る

似ている issue

Backend & API Design の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。