kogosoftwarellc / open-api

A Monorepo of various packages to power OpenAPI in node
MIT License
892 stars 235 forks source link

[PENDING #737 MERGE] Express openapi/add request ajv options and response ajv options #738

Closed nicofuccella closed 2 years ago

nicofuccella commented 3 years ago

Add requestAjvOptions and responseAjvOptions to express-frameworks constructor args. This way you can easily set separate ajv params for request and response validations. This is useful for example when you want to set removeAdditional for responses or requests (fixes #65):

openapi.initialize({
  apiDoc: require('./api-doc.js'),
  app: app,
  paths: path.resolve(__dirname, 'api-routes'),
  requestAjvOptions: { removeAdditional: true }
});

Add two more tests in express-openapi to look at the usage.

giowe commented 3 years ago

awesome! need this!

jsdevel commented 3 years ago

please update with the latest from master. ajv was bumped.

nicofuccella commented 3 years ago

@jsdevel done

jsdevel commented 3 years ago

@nicofuccella sorry for the delay here. @asarver and i ran into issues getting the ajv bump published, but it should be good now with the latest. can you update again please? i'll merge as soon as you do so and the build is passing. thanks!

jsdevel commented 3 years ago

@nicofuccella can you update with the latest from master? need to trigger a build with github actions

iggh commented 2 years ago

I'm of the opinion https://github.com/kogosoftwarellc/open-api/pull/785 would be a cleaner way of providing your own defaults for request/response ajv options (and other features).

By being able to interrogate the args passed in on instantiation using your own class, it would be infinitely flexible to say, only use specific options for different base paths, or special case a single path that needs specific ajv options as part of the validation.

jsdevel commented 2 years ago

@nicofuccella please consider what @iggh is suggesting and make a case for the approach outlined in this PR.