express -swagger-generator: определение моделей для чванства - PullRequest
0 голосов
/ 04 августа 2020

Согласно документам для определения модели чванства, внешний вид кода

/**
 * @typedef Product
 * @property {integer} id
 * @property {string} name.required - Some description for product
 * @property {Array.<Point>} Point
 */

/**
 * @typedef Point
 * @property {integer} x.required
 * @property {integer} y.required - Some description for point - eg: 1234
 * @property {string} color
 * @property {enum} status - Status values that need to be considered for filter - eg: available,pending
 */

/**
 * @typedef Error
 * @property {string} code.required
 */

/**
 * @typedef Response
 * @property {[integer]} code
 */


/**
 * This function comment is parsed by doctrine
 * sdfkjsldfkj
 * @route POST /users
 * @param {Point.model} point.body.required - the new point
 * @group foo - Operations about user
 * @param {string} email.query.required - username or email
 * @param {string} password.query.required - user's password.
 * @param {enum} status.query.required - Status values that need to be considered for filter - eg: available,pending
 * @operationId retrieveFooInfo
 * @produces application/json application/xml
 * @consumes application/json application/xml
 * @returns {Response.model} 200 - An array of user info
 * @returns {Product.model}  default - Unexpected error
 * @returns {Array.<Point>} Point - Some description for point
 * @headers {integer} 200.X-Rate-Limit - calls per hour allowed by the user
 * @headers {string} 200.X-Expires-After -  date in UTC when token expires
 * @security JWT
 */

Есть ли способ разделить модели в другом файле? как будто я могу импортировать его в свой маршрут. Я бы хотел избежать заполнения своих маршрутов моделями для определения чванства.

1 Ответ

0 голосов
/ 19 августа 2020

В параметрах expressSwagger вы можете определить несколько мест, откуда будет читаться документация:

(...)
files: ['./routes/**/*.js', './yourModelPath/*.js'] //Path to the API handle folder

Затем вы можете ссылаться на модель, которая определена в другом файле, как в примере с Продукт ссылка на Точка , которая может быть определена в другом месте:

Файл A:

 /**
 * @typedef Product
 * @property {integer} id
 * @property {string} name.required - Some description for product
 * @property {Array.<Point>} Point
 */

Файл B:

/**
 * @typedef Point
 * @property {integer} x.required
 * @property {integer} y.required - Some description for point - eg: 1234
 * @property {string} color
 * @property {enum} status - Status values that need to be considered for filter - eg: available,pending
 */
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...