簡體   English   中英

如何使用Swagger express在我的Swagger UI中添加數組和示例?

[英]how to add arrays and examples in my Swagger UI using Swagger express?

總而言之,我基本上是在嘗試根據這個“教程”制作一個招搖的Ui: https//github.com/fliptoo/swagger-express

不幸的是,它根本沒有描述如何為正文添加示例以及如何添加數組。

我現在的文檔代碼是:

/**
* @swagger
* path: /animal/dogs
* operations: 
*   -  httpMethod: POST
*      summary: Add several dogs to the animal shelter
*      notes: Returns results of the post
*      responseClass: Shelter
*      nickname : shelterPostWithDogs
*      consumes: 
*        - application/json
*      parameters:
*        - name: body
*          schema: true
*          description: Dogs object that needs to be added
*          paramType: body
*          required: true
*          dataType: Dog
*/

而我在底部:

/**
* @swagger
* models:
*  Dog:
*      id: Dog
*      properties:
*          dog_id:
*              required: true
*              type: int
*  Shelter:
*      id: Shelter
*      properties:
*          shelter_id:
*              type: int
*          location:
*              type: string                             
*/

不幸的是,有了這個,我在我的模型中有這個:

Dog {
    dog_id (int)
}

我想改為:

Dog {
    [
        { dog_id(int)}
    ]
}

我需要更改才能獲得此結果?

額外獎勵:如何在模型中添加示例? 我想要類似這樣的東西: http//petstore.swagger.io/#!/pet/addPet不幸的是,我不知道如何在招搖快遞中做到這一點

我也很喜歡swagger-express,但有一點我建議,你必須在模型定義中使用type作為“數組”:

Dog:
   id: Dog
      properties:
          dog_id:
              required: true
              type: **array**

希望這會幫助你。

謝謝!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM