lightsofapollo / joi-to-json-schema

140 stars 39 forks source link

Swagger failed to load after using joi lazy(fn) #36

Open ganeshkharche12 opened 6 years ago

ganeshkharche12 commented 6 years ago

Using JOI validation with lazy(fn) to check recursive validation. In this case swagger failed to load routes even all routes are working. Below are all the generated logs.

Failed to build API documentation for "/Demo"! This is likely a bug in your Foxx service. Check the route methods you are using to document your API. via Error: sorry, do not know how to convert unknown joi type: "lazy" at convert (/usr/share/arangodb3/js/node/node_modules/joi-to-json-schema/build/index.js:186:11) at Array.forEach (native) at Object.array (/usr/share/arangodb3/js/node/node_modules/joi-to-json-schema/build/index.js:87:14) at convert (/usr/share/arangodb3/js/node/node_modules/joi-to-json-schema/build/index.js:225:32) at /usr/share/arangodb3/js/node/node_modules/joi-to-json-schema/build/index.js:167:43 at Array.forEach (native) at Object.object (/usr/share/arangodb3/js/node/node_modules/joi-to-json-schema/build/index.js:165:25) at joi2schema (/usr/share/arangodb3/js/server/modules/@arangodb/foxx/router/swagger-context.js:568:10)

i already had opened this issue on github ArangoDB issues https://github.com/arangodb/arangodb/issues/6132

pluma commented 6 years ago

Specifically the schema in question looks like this:

const Person = Joi.object({
    firstName: Joi.string().required(),
    lastName: Joi.string().required(),
    children: Joi.array().items(Joi.lazy(() => Person).description('Person schema'))
});

The relevant part of the stack trace is this:

Error: sorry, do not know how to convert unknown joi type: "lazy"
at convert (joi-to-json-schema/build/index.js:186:11)
at Array.forEach (native)
at Object.array (joi-to-json-schema/build/index.js:87:14)
at convert (joi-to-json-schema/build/index.js:225:32)
at joi-to-json-schema/build/index.js:167:43
at Array.forEach (native)
at Object.object (joi-to-json-schema/build/index.js:165:25)

ArangoDB is using joi 9.2.0 with version 2.3.0 of this library (but AFAICT 3.x also doesn't support lazy).

lightsofapollo commented 6 years ago

Yeah all but certain lazy was not a thing when we wrote the initial version. I will take a look but this is an area where we could honestly use some help.

jeremymelchor commented 1 year ago

Hi, any news on this issue ?