Skip to content

Commit

Permalink
Merge pull request #75 from trojs/feature/all-errors
Browse files Browse the repository at this point in the history
Allow more ajv options
  • Loading branch information
w3nl authored Jun 19, 2024
2 parents 746971c + b5ef99b commit 2bdd058
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const api = new Api({
controllers,
secret: 'test',
logger: console,
allErrors: true
ajvOptions: { allErrors: true }
})
const { app } = await setupServer({
env: process.env,
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@trojs/openapi-server",
"description": "OpenAPI Server",
"version": "1.0.6",
"version": "1.0.7",
"author": {
"name": "Pieter Wigboldus",
"url": "https://trojs.org/"
Expand Down
8 changes: 4 additions & 4 deletions src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { setupRouter } from './router.js'
* @property {SecurityHandler[]=} securityHandlers
* @property {boolean=} swagger
* @property {boolean=} apiDocs
* @property {boolean=} allErrors
* @property {object=} ajvOptions
*/

/**
Expand All @@ -36,7 +36,7 @@ export class Api {
/**
* @param {ApiSchema} params
*/
constructor ({ version, specification, controllers, secret, apiRoot, strictSpecification, errorDetails, logger, meta, securityHandlers, swagger, apiDocs, allErrors }) {
constructor ({ version, specification, controllers, secret, apiRoot, strictSpecification, errorDetails, logger, meta, securityHandlers, swagger, apiDocs, ajvOptions }) {
this.version = version
this.specification = specification
this.controllers = controllers
Expand All @@ -49,7 +49,7 @@ export class Api {
this.securityHandlers = securityHandlers || []
this.swagger = swagger ?? true
this.apiDocs = apiDocs ?? true
this.allErrors = allErrors ?? false
this.ajvOptions = ajvOptions ?? { allErrors: false }
}

setup () {
Expand All @@ -74,7 +74,7 @@ export class Api {
logger: this.logger,
meta: this.meta,
securityHandlers: this.securityHandlers,
allErrors: this.allErrors
ajvOptions: this.ajvOptions
})
api.init()

Expand Down
6 changes: 3 additions & 3 deletions src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ import { unauthorized } from './handlers/unauthorized.js'
* @param {Logger=} params.logger
* @param {object=} params.meta
* @param {SecurityHandler[]=} params.securityHandlers
* @param {boolean=} params.allErrors
* @param {object=} params.ajvOptions
* @returns {{ api, openAPISpecification: object }}
*/
export const setupRouter = ({ secret, openAPISpecification, controllers, apiRoot, strictSpecification, errorDetails, logger, meta, securityHandlers = [], allErrors = false }) => {
export const setupRouter = ({ secret, openAPISpecification, controllers, apiRoot, strictSpecification, errorDetails, logger, meta, securityHandlers = [], ajvOptions = {} }) => {
const api = new OpenAPIBackend({
definition: openAPISpecification,
apiRoot,
strict: strictSpecification,
ajvOpts: { allErrors },
ajvOpts: ajvOptions,
customizeAjv: (originalAjv) => {
addFormats(originalAjv)
return originalAjv
Expand Down
2 changes: 1 addition & 1 deletion src/server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const api = new Api({
controllers,
secret: envExample.SECRET,
securityHandlers,
allErrors: true
ajvOptions: { allErrors: true }
})
const { app } = await setupServer({
env: envExample,
Expand Down

0 comments on commit 2bdd058

Please sign in to comment.