在 Swagger 中更改为 Url-Form-Encoded Post 请求 [英] Changing to Url-Form-Encoded Post Request in Swagger
问题描述
我想知道是否可以在 Swagger 中创建一个 url-form-encoded post 请求?例如:
I was wondering is it possible to create a url-form-encoded post request within Swagger? For example:
POST https://url.co.uk
Host: server.example.com
Authorization: Bearer <Initial Access Token>
Content-Type: application/x-www-form-urlencoded
&grant_type=password
&client_id=<client id>
&client_secret=<client secret>
目前我们有以下各种参数的布局,但不确定如何更改为 url-form-encoded.我们尝试更改为 in:body
而不是 header,但这不起作用.请参阅授予类型参数的示例
Currently we have the layout below for our various parameters but are not sure how to change to url-form-encoded. We have tried changing toin:body
instead of header but this does not work. See example for grant-type parameter
"parameters": [
{
"in": "header",
"name": "grant_type",
"description": "Indicates that the app is using the Resource Owner Password \"password\".",
"required": true,
"type": "string",
"enum": [
"password"
]
},
当前返回这个:
Accept: application/json
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8,fa;q=0.6,sv;q=0.4
Cache-Control: no-cache
Connection: keep-alive
Origin: http://editor.swagger.io
Referer: http://editor.swagger.io/
User-Agent: Mozilla/5.0
grant_type: password
client_id: xxx-xxx-xxx
client_secret: <client_secret>
对此的任何帮助/见解将不胜感激 - 甚至让我知道是否有可能?
Any help/insight on this would be greatly appreciated - even to let me know if it is even possible?
推荐答案
有可能,你只需要按照 OpenAPI 中的说明将参数的 in
值设置为 formData
Parameter
对象中的 (fka. Swagger) 规范 描述:
It's possible, you just need to set parameter's in
value to formData
as explained in in the OpenAPI (fka. Swagger) specification in the Parameter
object description:
当 application/x-www-form-urlencoded 或 multipart/form-data 用作请求的内容类型时,用于描述 HTTP 请求的负载(在 OpenAPI 的定义中,操作的消耗属性)
Used to describe the payload of an HTTP request when either application/x-www-form-urlencoded or multipart/form-data are used as the content type of the request (in OpenAPI's definition, the consumes property of an operation)
您还可以阅读我的 OpenAPI 规范教程的第 5 部分第 1.7 节
这是一个例子:
swagger: '2.0'
info:
version: 1.0.0
title: Form data API
description: Using form data body parameters
paths:
/examples:
post:
consumes:
- application/x-www-form-urlencoded
parameters:
- name: grant_type
type: string
in: formData
- name: client_id
type: string
in: formData
- name: client_secret
type: string
in: formData
responses:
200:
description: OK
这篇关于在 Swagger 中更改为 Url-Form-Encoded Post 请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!