Adding validation support with AJV inside Mali.js
Initially I wanted to add Ajv support just like Fastify to Mali.js but before that I released it on Github on https://github.com/anonrig/mali-ajv.
I wanted to ask the community whether having JSON schema validation support for Mali.js inputs/requests would be a good idea.
Initially I wanted to add Ajv support just like Fastify to Mali.js but before that I released it on Github on https://github.com/anonrig/mali-ajv.
I wanted to ask the community whether having JSON schema validation support for Mali.js inputs/requests would be a good idea.
Yes, I currently use Ajv in Mali as request validation. Official Document point that use single instance & cache pre-compile schema will more memory efficiency.
@HsinHeng I've updated mali-ajv to use pre-compiled schemas and released 0.2.0 version (https://github.com/anonrig/mali-ajv/releases/tag/0.2.0).
Would you like us to add a default support for Ajv inside Mali?
@HsinHeng I've updated mali-ajv to use pre-compiled schemas and released 0.2.0 version (https://github.com/anonrig/mali-ajv/releases/tag/0.2.0).
Would you like us to add a default support for Ajv inside Mali?
It sounds great to support request validation & you pick a good validation lib.
@HsinHeng I've updated mali-ajv to use pre-compiled schemas and released 0.2.0 version (https://github.com/anonrig/mali-ajv/releases/tag/0.2.0).
Would you like us to add a default support for Ajv inside Mali?
A small request is, can we pass customized grpc status code or error object if failed validation.
maybe INVALID_ARGUMENT, FAILED_PRECONDITION are suits for several use cases.
Hey @HsinHeng
Just released 0.3.0 with the following feature. (https://github.com/anonrig/mali-ajv/releases/tag/0.3.0)
Hey @HsinHeng
Just released 0.3.0 with the following feature. (https://github.com/anonrig/mali-ajv/releases/tag/0.3.0)
It looks great. Thanks for your help. Another request is, could it support customized ajv instance options like fastify.io provided,
const fastify = require('fastify')({
ajv: {
customOptions: {
nullable: false // Refer to [ajv options](https://ajv.js.org/#options)
},
plugins: [
require('ajv-merge-patch')
[require('ajv-keywords'), 'instanceof'];
// Usage: [plugin, pluginOptions] - Plugin with options
// Usage: plugin - Plugin without options
]
}
})
details document is here.
because i used some options in my projects.
maybe interface of options parameter could like fastify.io.
app.ajv = { customOptions, plugins };
or
const app = new Mali({
ajv: {
customOptions,
plugins,
},
})
Thanks your kindly help again.
Any update on this issue? Seems like a good idea to have validation with AJV 🤗
I've built a separate package to support this called mali-ajv but I'm not really quite sure to integrate it into the core of Mali.