I am currently using ajv to validate some API inputs in node/express. The expected data is described in a .json schema file.
Now I would like to re-use this file to document my API, relying on swagger-ui-express and swagger-jsdoc.
There are quite many references to how to re-use an object definition in swagger, but all these descriptions suppose that definition is given in a "@swagger" comment block.
I simply don't see how to point to a local JSON file.
If my comment is shaped like this:
/**
* @swagger
* /init/user:
* post:
* description: Creates a user
* produces:
* - application/json
* parameters:
* - in: body
* name: create user
* required: true
* schema:
* $ref: 'schemas/initUserApi.json'
*/
(note this is an incomplete template, I want to focus on the problem), then the ultimate swagger output will throw an error:
Could not resolve reference: Tried to resolve a relative URL, without having a basePath. path: 'schemas/initUserApi.json' basePath: 'undefined'
I tried defining a 'components' section as described in this issue: Cannot reference a component schema defined in a separate file in Swagger, this does nothing.
I tried using absolute/relative file names, etc (also another suggestion here: How to use $ref in swagger file properly while working with swagger-ui-express and swagger-jsdoc), to no avail.
Is this possible? The goal is really to use a separate json file as a schema, as I would like to have a single source of information. I am not clear on how the swagger-ui-express/swagger-jsdoc chain works, would this json file need somehow to be served by my swagger web server (this is really for documentation running on localhost for now, no public/intranet publishing) ?