schemator middleware for nanoexpress
You can think this middleware combine of Swagger documentation and Ajv validation like original nanoexpress built-in feature + swagger-ui middleware
npm i @nanoexpress/middleware-schemator
# or
yarn add @nanoexpress/middleware-schemator
- YML (preferred)
- JSON
- RAW JS Object
const schematorInstance = schemator({ swaggerPath: './swagger.yml' });
app.define(schematorInstance.define);
/// auth/index.js
app.get(
'/auth',
// Here any body-parser, form-data logic (all preprocess middlewares)
schematorInstance.load({
attach: '/auth',
method: 'get',
path: './auth/docs.yml'
}),
async (req) => {
// your logic here
}
);
const schematorInstance = schemator({ swaggerPath: './swagger.json' });
app.define(schematorInstance.define);
/// auth/index.js
app.get(
'/auth',
// Here any body-parser, form-data logic (all preprocess middlewares)
schematorInstance.load({
attach: '/auth',
method: 'get',
path: './auth/docs.json'
}),
async (req) => {
// your logic here
}
);
const schematorInstance = schemator({ swaggerRAW: {} });
app.define(schematorInstance.define);
/// auth/index.js
app.get(
'/auth',
// Here any body-parser, form-data logic (all preprocess middlewares)
schematorInstance.load({
attach: '/auth',
method: 'get',
raw: {
path: {
'/': {
/* infos here */
}
}
}
}),
async (req) => {
// your logic here
}
);
See the examples directory
import schemator from '@nanoexpress/middleware-schemator';
const schematorInstance = schemator({ swaggerPath: './swagger.yml' });
app.define(schematorInstance.define);
app.get(
'/auth',
// Here any body-parser, form-data logic (all preprocess middlewares)
schematorInstance.load({
attach: '/auth',
method: 'get',
path: './auth/docs.yml'
}),
async (req) => {
// your logic here
}
);
const bodyParser = require('@nanoexpress/middleware-schemator/cjs');
const schematorInstance = schemator({ swaggerPath: './swagger.yml' });
app.define(schematorInstance.define);
app.get(
'/auth',
// Here any body-parser, form-data logic (all preprocess middlewares)
schematorInstance.load({
attach: '/auth',
method: 'get',
path: './auth/docs.yml'
}),
async (req) => {
// your logic here
}
);
Options name | Default | Required | Description |
---|---|---|---|
options.swaggerPath |
- | Yes or options.swaggerRAW |
Swagger schema file path |
options.swaggerRAW |
- | Yes or options.swaggerPath |
Swagger schema RAW Object |
Options name | Default | Required | Description |
---|---|---|---|
options.method |
- | Yes | Your router method (lowercase) |
options.attach |
- | Yes | Your router path (with Swagger path format) |
options.path |
- | Yes or options.raw |
Route Swagger schema file path |
options.raw |
- | Yes or options.path |
Route Swagger schema RAW Object |
See Ajv configurations for more customization
Options name | Default | Required | Description |
---|---|---|---|
options.title |
Schemator | Yes | Swagger UI Title |
options.exposePath |
- | Yes | schematorInstance.expose() path |
MIT