use-validated-body-or-query - ESLint plugin rules

This rule requires using req.validatedBody or req.validatedQuery when a validation middleware is applied to the route.

Severity#

warn. This rule is enabled in the strict preset.

By default, Medusa projects use the recommended preset, which doesn't enable this rule. To use it, switch to the strict preset.

What it Targets#

This rule targets route.ts and route.js files in your project's src/api directory. It reports access to req.body or req.query in a handler when a validateAndTransformBody or validateAndTransformQuery middleware is applied to the route.

The following code is reported by the rule when body validation is applied to the route:

src/api/admin/customers/route.ts
1export const POST = async (req, res) => {2  res.json(req.body)3}

Instead, use the validated property:

src/api/admin/customers/route.ts
1export const POST = async (req, res) => {2  res.json(req.validatedBody)3}

Why it's Important#

A validation middleware populates req.validatedBody and req.validatedQuery with the parsed and transformed data. Reading the raw req.body or req.query skips that validation and transformation.

Learn more in the Validation documentation.

Fixable#

This rule is auto-fixable. Run the linter with the --fix option to apply the fix automatically.

Turn it Off#

To turn off this rule, set it to off in your ESLint configuration:

eslint.config.ts
1import { defineConfig } from "eslint/config"2import medusa from "@medusajs/eslint-plugin"3
4export default defineConfig([5  ...medusa.configs.strict,6  {7    rules: {8      "@medusajs/use-validated-body-or-query": "off",9    },10  },11])

Or disable it for a single line using an inline comment:

Code
1// eslint-disable-next-line @medusajs/use-validated-body-or-query2  res.json(req.body)
Was this page helpful?
Ask Bloom
For assistance in your development, use Claude Code Plugins or Docs MCP server in Cursor, VSCode, etc...FAQ
What is Medusa?
How can I create a module?
How can I create a data model?
How do I create a workflow?
How can I extend a data model in the Product Module?
Recipes
How do I build a marketplace with Medusa?
How do I build digital products with Medusa?
How do I build subscription-based purchases with Medusa?
What other recipes are available in the Medusa documentation?
Chat is cleared on refresh
Line break
⇧↵