2015-07-21 68 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