1

openapi: "3.0.0"
Swagger-jsdoc: "^6.2.5",
Swagger-ui-express: "^4.3.0",
Node: v18.8.0

I have a payload with a field called raw_data who is super long. So I decided to use an external value and call it in swaggerUI 

I'm using this URL: https://mywebsite/tremorData.json which its being called. It is just a JSON file. Is possible that the problems is caused by the JSON file not being parsed? 

I tried several things but it never works. In case you know how to add big payload in swaggerUI I'm open to other options.

this is my code:

/**
 * @swagger
 * /data/tremor:
 *   post:
 *
 *     security:
 *     -  bearerAuth: []
 *
 *     tags: [data/ Tremor]
 *
 *     requestBody:
 *        required: true
 *        content:
 *           application/json:
 *              examples:
 *               jsonObject:
 *                 summary: A sample object
 *                 externalValue: 'https://mywebsite/tremorData.json'
 *            
 *     responses:
 *       200:
 *         description: Successful operation
 *       400:
 *         description: validation Fail /or/ Unexpected token, in JSON at position 108
 */

the render in swaggerUI : enter image description here

enter image description here

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Momo
  • 67
  • 7

1 Answers1

1

The "could not render" error happens because the requestBody does not have a schema. Adding a minimal schema, e.g. just type: object without any properties (which means "arbitrary object") will avoid the rendering error.

 *     requestBody:
 *        required: true
 *        content:
 *           application/json:
 *              schema:         # <-----
 *                type: object  # <-----
 *              examples:
...

As for externalValue, it's the correct way to reference external examples, but unfortunately it's not supported by Swagger UI yet. You can track this issue for status updates:
https://github.com/swagger-api/swagger-ui/issues/5433

Helen
  • 87,344
  • 17
  • 243
  • 314
  • Thanks a lot i will try that and let you know what happend :) – Momo Jan 19 '23 at 08:50
  • Hi @Helen, I add the lines and also i tried calling a schema. In both cases is not working and is loggin the same error. Is possible that my URL is only a JSON file.. Should i add a parsed object ? – Momo Jan 19 '23 at 08:59