https://github.com/anonrig/mali-ajv
Opinionated AJV input validation support for Mali.js microservices
https://github.com/anonrig/mali-ajv
ajv input mali microservices
Last synced: 6 months ago
JSON representation
Opinionated AJV input validation support for Mali.js microservices
- Host: GitHub
- URL: https://github.com/anonrig/mali-ajv
- Owner: anonrig
- Created: 2021-07-24T09:47:47.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2023-02-11T19:53:25.000Z (over 2 years ago)
- Last Synced: 2025-03-13T10:11:35.237Z (7 months ago)
- Topics: ajv, input, mali, microservices
- Language: JavaScript
- Homepage:
- Size: 1.25 MB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Ajv validation for Mali.js gRPC microservices
This package adds **opinionated** [Ajv](https://ajv.js.org) input validation support for [Mali.js](https://mali.js.org) gRPC microservices.
## Install
```bash
npm i --save mali-ajv
```## Setup
```javascript
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' ) })
```## Usage
Example request:
```json
{
"identity_id": "45670d4a-1185-4e5a-bd3",
"name": ""
}
```Throws the following error:
```json
{
"error": "9 FAILED_PRECONDITION: data.identity_id should match format \"uuid\""
}
```