This package adds opinionated Ajv input validation support for Mali.js gRPC microservices.
npm i --save mali-ajv
import Mali from 'mali'
import { addSchemas } from 'mali-ajv'
import * as accounts from './endpoints/accounts.schema.js'
import * as memberships from './endpoints/memberships.schema.js'
const app = new Mali()
app.use(addSchemas(app, { accounts, memberships }))
app.addService(file, 'Memberships', {})
app.addService(file, 'Accounts', {})
app.use('Accounts', { findOne: (ctx) => (ctx.res = 'hello world' ) })
Example request:
{
"identity_id": "45670d4a-1185-4e5a-bd3",
"name": ""
}
Throws the following error:
{
"error": "9 FAILED_PRECONDITION: data.identity_id should match format \"uuid\""
}