[英]how to use an External Value (type JSON) in SwaggerUI and NodeJS
打開API:“3.0.0”
Swagger-jsdoc: "^6.2.5",
Swagger-ui-express: "^4.3.0",
節點:v18.8.0
我有一個有效載荷,其中有一個名為 raw_data 的超長字段。 所以我決定使用外部值並在 swaggerUI 中調用它
我正在使用這個 URL: https://mywebsite/tremorData.json 它被稱為。 它只是一個 JSON 文件。 問題可能是由於未解析 JSON 文件引起的嗎?
我嘗試了幾件事,但從來沒有奏效。 如果您知道如何在 swaggerUI 中添加大負載,我願意接受其他選項。
這是我的代碼:
/**
* @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
*/
“無法呈現”錯誤的發生是因為requestBody
沒有schema
。 添加一個最小模式,例如只type: object
沒有任何properties
(這意味着“任意對象”)將避免呈現錯誤。
* requestBody:
* required: true
* content:
* application/json:
* schema: # <-----
* type: object # <-----
* examples:
...
至於externalValue
,它是引用外部示例的正確方法,但不幸的是,它還沒有被 Swagger UI 支持。 您可以跟蹤此問題以獲取狀態更新:
https://github.com/swagger-api/swagger-ui/issues/5433
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.