← Back to nodox
Generate Swagger Docs from
Generate Swagger Docs from
Joi Schemas: Zero Config
Already using Joi to validate your Express routes? nodox-cli reads those schemas automatically and generates a live Swagger UI, no JSDoc, no YAML files, no extra setup.
Get started: npx nodox initBefore vs. after
Without nodox-cli
// You write your Joi schema...
const CreateUser = Joi.object({
name: Joi.string().min(1).required(),
email: Joi.string().email().required(),
age: Joi.number().integer().min(0),
})
// ...then write it AGAIN in YAML
// or JSDoc comments for Swagger:
/**
* @swagger
* /users:
* post:
* requestBody:
* content:
* application/json:
* schema:
* type: object
* properties:
* name:
* type: string
* ...20 more lines
*/
app.post('/users', validate, handler)
With nodox-cli
import nodox from 'nodox-cli'
import Joi from 'joi'
const app = express()
app.use(express.json())
app.use(nodox(app)) // ← one line, that's it
const CreateUser = Joi.object({
name: Joi.string().min(1).required(),
email: Joi.string().email().required(),
age: Joi.number().integer().min(0),
})
// nodox reads the Joi schema automatically; no extra code needed
app.post('/users', (req, res) => {
const { error, value } = CreateUser.validate(req.body)
if (error) return res.status(400).json({ error: error.message })
res.status(201).json({ id: 1, ...value })
})
// Visit /__nodox; docs are live.
Joi features nodox-cli detects
- ✓ Primitives:
Joi.string(),Joi.number(),Joi.boolean(),Joi.date() - ✓ Constraints:
.min(),.max(),.email(),.uri(),.uuid(),.pattern() - ✓ Optional / required:
.optional(),.required() - ✓ Nested objects:
Joi.object({ address: Joi.object({...}) }) - ✓ Arrays:
Joi.array().items(Joi.string()) - ✓ Enums:
Joi.string().valid('admin', 'user') - ✓ Alternatives:
Joi.alternatives().try(...) - ✓ Response schemas:
validate(Input, { responses: { 200: Output } }) - ✓ Joi ≥ 17
Setup in 30 seconds
Also supports
nodox-cli reads Zod, express-validator, and yup with the same zero-config approach.