Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: Cannot read properties of undefined (reading 'schemas')

So I am implementing swagger ui and I want to add response body as content for code 200, which is success. But I am keep on getting this TypeError again and again and I have tried almost many things,but I couldn't solve it. This is the js files which I am adding the swagger. While I am trying to add schemas, it isn't reading and throwing me this error:

.paths\node_modules\swagger-jsdoc\src\specification.js:157
        swaggerObject[property][definition],
                               ^

TypeError: Cannot read properties of undefined (reading 'schemas')

The Code is like this:

/**
 * @swagger
 * components:
 *      schemas:
 *          Accounttypes:
 *              type: string
 */

/**
 * @swagger
 * paths:
 *  /api/accounttypes/:
 *      get:
 *          summary : Some summary
 *          tags:
 *              - Account Types
 *          description: Some description
 *          responses:
 *              '200':
 *                  description: Success Description
 *                  content:
 *                      application/json:
 *                          schema:
 *                              type: array
 *                              items:
 *                                  $ref: #/components/schemas/Accounttypes
 */

Can anyone help me with this?

like image 664
Quick Hotshot Avatar asked Feb 01 '26 19:02

Quick Hotshot


1 Answers

I recently ran into similar problem, a workaround for this is to use 'definitions' instead of 'components'.

Something like this:

/**
 * @swagger
 * definitions:
 *     Accounttypes:
 *         type: string
 */

/**
 * @swagger
 * paths:
 *  /api/accounttypes/:
 *      get:
 *          summary : Some summary
 *          tags:
 *              - Account Types
 *          description: Some description
 *          responses:
 *              '200':
 *                  description: Success Description
 *                  content:
 *                      application/json:
 *                          schema:
 *                              type: array
 *                              items:
 *                                  $ref: #/definitions/Accounttypes
 */
like image 116
Dpk Avatar answered Feb 04 '26 14:02

Dpk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!