2015-07-21 75 views
0

我正在定義一個資源,您使用非JSON主體進行POST。它只是一個像表單參數那樣的字符串。類似於OAuth發生的情況: grant_type = & code = & redirect_uri =Swagger POST與非json主體

如何在Swagger上記錄該文件?我必須使用formParam格式而不是正文嗎?我將它放入正文中的所有內容都轉換爲JSON示例。

TokenRequest: 
    properties: 
     grant_type: 
     type: string 
     description: OAuth Grant Type 
     enum: 
     - authorization_code 
     - refresh 
     code: 
     type: string 
     description: Authorization Code obtained from /authorize required if grant_type = au 
     redirect_uri: 
     type: string 
     description: Defined Redirect URI Example - https://example.com/callback 
     refresh_token: 
     type: string 
     description: Required if grant_type = refresh 

回答

1

這裏是如何記錄表單數據的例子:

post: 
    tags: 
    - pet 
    summary: Updates a pet in the store with form data 
    description: '' 
    operationId: updatePetWithForm 
    consumes: 
    - application/x-www-form-urlencoded 
    produces: 
    - application/xml 
    - application/json 
    parameters: 
    - name: petId 
     in: path 
     description: ID of pet that needs to be updated 
     required: true 
     type: integer 
     format: int64 
    - name: name 
     in: formData 
     description: Updated name of the pet 
     required: false 
     type: string 
    - name: status 
     in: formData 
     description: Updated status of the pet 
     required: false 
     type: string 
    responses: 
    '405': 
     description: Invalid input 
    security: 
    - petstore_auth: 
     - 'write:pets' 
     - 'read:pets' 

但在你的情況,似乎要定義OAuth的設置,請參閱Swagger Spec 2.0以獲取更多信息。這裏是一個PetStore的例子:

securityDefinitions: 
    petstore_auth: 
    type: oauth2 
    authorizationUrl: 'http://petstore.swagger.io/api/oauth/dialog' 
    flow: implicit 
    scopes: 
     'write:pets': modify pets in your account 
     'read:pets': read your pets 
    api_key: 
    type: apiKey 
    name: api_key 
    in: header 
+0

是的,我也試過這種方式,它的工作原理。只是表現不同(我不太喜歡它)。但我會處理它。謝謝! – SuperGeek133