项目作者: anonrig

项目描述 :
Opinionated AJV input validation support for Mali.js microservices
高级语言: JavaScript
项目地址: git://github.com/anonrig/mali-ajv.git
创建时间: 2021-07-24T09:47:47Z
项目社区:https://github.com/anonrig/mali-ajv

开源协议:

下载


Ajv validation for Mali.js gRPC microservices

This package adds opinionated Ajv input validation support for Mali.js gRPC microservices.

Install

  1. npm i --save mali-ajv

Setup

  1. import Mali from 'mali'
  2. import { addSchemas } from 'mali-ajv'
  3. import * as accounts from './endpoints/accounts.schema.js'
  4. import * as memberships from './endpoints/memberships.schema.js'
  5. const app = new Mali()
  6. app.use(addSchemas(app, { accounts, memberships }))
  7. app.addService(file, 'Memberships', {})
  8. app.addService(file, 'Accounts', {})
  9. app.use('Accounts', { findOne: (ctx) => (ctx.res = 'hello world' ) })

Usage

Example request:

  1. {
  2. "identity_id": "45670d4a-1185-4e5a-bd3",
  3. "name": ""
  4. }

Throws the following error:

  1. {
  2. "error": "9 FAILED_PRECONDITION: data.identity_id should match format \"uuid\""
  3. }