Skip to content

docs(guide): match response, binding and validation examples to Echo v5 - #472

Open
yxshee wants to merge 1 commit into
labstack:masterfrom
yxshee:fix/response-binding-examples
Open

yxshee wants to merge 1 commit into
labstack:masterfrom
yxshee:fix/response-binding-examples

Conversation

@yxshee

@yxshee yxshee commented Oct 26, 2026

Copy link
Copy Markdown

Several examples in the Response, Binding and Request guides show output that Echo v5 does not produce. I ran each one with httptest and e.ServeHTTP against Echo v5.4.0 (the version in go.mod) and against the current labstack/echo master. Both gave the same results.

Fixes

  1. JSONPretty output (guide/response.md). The sample listed "email" before "name". encoding/json keeps struct field order, so the real output is:
    {
      "name": "Jon",
      "email": "[email protected]"
    }
  2. XMLPretty output (guide/response.md). The sample used <Name> and <Email>. The User struct in the same page has xml:"name" and xml:"email" tags, so the real elements are <name> and <email>.
  3. ?pretty tip (guide/response.md). The tip said Context#XML() indents its output when the URL has ?pretty. v5 has no such check. GET /users/1?pretty still returns <User><name>Jon</name><email>[email protected]</email></User> on one line. I removed the tip.
  4. After hooks (guide/response.md). The page said "If the Content-Length is unknown, no after functions run". Response.Write calls the after functions on every write. The page's own /hooks example prints "after response" with no Content-Length header, and so does a handler that writes the body directly. I removed the sentence.
  5. Binding precedence (guide/binding.md). The list said query parameters are bound for GET / DELETE only. DefaultBinder.Bind also binds them for HEAD and QUERY. With ?id=fromquery, GET, DELETE, HEAD and QUERY all set the field, while POST and PUT leave it empty.
  6. Validation response (guide/request.md). The curl sample showed the validator message in the body. echo.ErrBadRequest.Wrap(err) keeps that message as the wrapped error, and the default error handler does not expose it, so the response is 400 {"message":"Bad Request"}. I also checked that the validator does reject joe@invalid-domain, so the request does fail.

The same code blocks and sentences are in the es, ja, pt-br and zh-cn pages. I applied the same change there. The code blocks are identical across locales, and the prose changes only delete a sentence or a tip, or add HEAD / QUERY to the method list, so nothing new needed translating. I ran npm run security-translations:accept because guide/response.md is in that list. The baseline diff only touches the guide/response.md hashes.

How I checked

  • A Go test module with github.com/labstack/echo/v5 v5.4.0 and go-playground/validator/v10. It registers each example handler and prints the response body. I ran it again with a replace pointing at labstack/echo master (7c312e0) and got the same output.
  • node scripts/security-translation-status.mjs and node scripts/translation-status.mjs pass.
  • node --test scripts/*.test.mjs has the same result as on master. One source-check CLI test fails on both because of my local environment (it could not write its summary file to /tmp).
  • I could not run npm install and the full site build locally, so I did not run the plugins/*.test.mjs tests that need unified and remark-parse. This change only edits Markdown text.

Several guide examples showed output that Echo v5 does not produce.
I ran each one with httptest against Echo v5.4.0 and the current
labstack/echo master, and both give the same results.

- JSONPretty output listed "email" before "name". encoding/json keeps
  struct field order, so "name" comes first.
- XMLPretty output used <Name> and <Email>. The User struct has
  xml:"name" and xml:"email" tags, so the elements are lowercase.
- Removed the tip about adding ?pretty to make Context#XML indent its
  output. v5 has no such query parameter and the response stays on one
  line.
- Removed "If the Content-Length is unknown, no after functions run".
  After hooks run on every Write, with or without Content-Length.
- Binding precedence said query parameters are bound for GET / DELETE
  only. DefaultBinder.Bind also binds them for HEAD and QUERY.
- The validation example claimed the response body contains the
  validator message. ErrBadRequest.Wrap keeps that as the internal
  error, and the default error handler sends {"message":"Bad Request"}.

The same code blocks and sentences are fixed in the es, ja, pt-br and
zh-cn pages, and the security translation baseline is updated for the
response page.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01NQDmA3mwGfL83pbg9WQ6ey

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant