Skip to content

docs: fix incorrect code examples in Reply and Request reference#6582

Merged
mcollina merged 1 commit intofastify:mainfrom
mahmoodhamdi:docs/fix-code-examples
Mar 16, 2026
Merged

docs: fix incorrect code examples in Reply and Request reference#6582
mcollina merged 1 commit intofastify:mainfrom
mahmoodhamdi:docs/fix-code-examples

Conversation

@mahmoodhamdi
Copy link
Copy Markdown
Contributor

What

Fixed three incorrect code examples in the Reply and Request reference documentation:

  1. Reply.md line 311reply.getTrailer('server-timing') replaced with reply.hasTrailer('server-timing'). The getTrailer() method does not exist on the Reply prototype — only trailer(), hasTrailer(), and removeTrailer() are implemented.

  2. Reply.md line 499 — Fixed syntax error schema1.properties.foo.type. = 'integer' (extra dot before assignment operator).

  3. Request.md line 237 — Same syntax error fix as above in the compileValidationSchema example.

Why

While working with Fastify, I noticed the removeTrailer example references a non-existent getTrailer() method, which would throw a TypeError at runtime if a user copied this code. The schema mutation examples also have a syntax error that would cause a SyntaxError if used directly.

How

  • Verified getTrailer does not exist in lib/reply.js — only trailer, hasTrailer, and removeTrailer are defined
  • Replaced with hasTrailer() which correctly demonstrates verifying the trailer was removed
  • Removed the extra dot in the assignment to fix the syntax errors

Checklist

- Replace non-existent `reply.getTrailer()` with `reply.hasTrailer()`
  in the removeTrailer example
- Fix syntax errors in schema mutation examples where an extra dot
  before the assignment operator made the code invalid
  (`schema1.properties.foo.type. = 'integer'`)
@github-actions github-actions bot added the documentation Improvements or additions to documentation label Mar 15, 2026
@mcollina mcollina merged commit a1413de into fastify:main Mar 16, 2026
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants