Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding validation support with AJV inside Mali.js #273

Open
anonrig opened this issue Jul 24, 2021 · 8 comments
Open

Adding validation support with AJV inside Mali.js #273

anonrig opened this issue Jul 24, 2021 · 8 comments
Assignees

Comments

@anonrig
Copy link
Member

anonrig commented Jul 24, 2021

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.

@anonrig anonrig self-assigned this Jul 24, 2021
@anonrig anonrig pinned this issue Jul 24, 2021
@HsinHeng
Copy link

HsinHeng commented Jul 26, 2021

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.

@anonrig
Copy link
Member Author

anonrig commented Jul 26, 2021

@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
Copy link

@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
Copy link

@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.

@anonrig
Copy link
Member Author

anonrig commented Jul 26, 2021

Hey @HsinHeng

Just released 0.3.0 with the following feature. (https://github.com/anonrig/mali-ajv/releases/tag/0.3.0)

@HsinHeng
Copy link

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.

@jscek
Copy link

jscek commented Sep 21, 2021

Any update on this issue? Seems like a good idea to have validation with AJV 🤗

@anonrig
Copy link
Member Author

anonrig commented Sep 21, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants