Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Access request data from inside JSON schema or keyword validator

Aperta
#1,007 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
20/100
Tipo di issue
Funzionalità
Chiarezza
Da chiarire
Stato di attività
Ferma
Stack tecnologico
javascript, node.js
Ambito
api, backend

Direzione di ricerca

Non vengono indicati file, test o punti di ingresso. Inizia esaminando il ciclo di vita della validazione dello schema di Fastify e la documentazione sulle parole chiave personalizzate, quindi determina se in quel punto è possibile utilizzare dati con ambito della richiesta. Il lavoro è completo quando viene documentato o confermato un approccio supportato per accedere ai dati degli hook precedenti mantenendo gli errori di validazione dello schema.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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
Lingua principale
Nessun dato sulla lingua
Stelle
68
Fork
8
Merge medio
11h 2m
PR unite (30g)
2

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di fastify/help

Tutte le issue di fastify/help

Issue simili

Altre issue su Backend & API Design

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.