问题描述
我正在使用swagger 2.0,并希望使用Bearer Authentication安全机制,在该机制中,我想在标头中传递访问令牌。我尝试使用oauth
安全机制,但无法在API中获得授权。
在下面的代码中,我尝试使用api_Key
,但即使这样也无法正常工作。
swagger: "2.0"
info:
description: ""
version: "1.0.0"
title: "Example Application"
host: "host.com"
basePath: "/dev"
tags:
- name: "company"
description: "All company related endpoints"
schemes:
- "https"
- "http"
paths:
/companies:
post:
tags:
- "company"
summary: "Create a new company"
security:
- api_key: []
description: ""
operationId: "addCompany"
produces:
- "application/json"
parameters:
- in: "body"
name: "body"
description: ""
required: true
schema:
type: "object"
required:
- name
properties:
name:
type: "string"
email:
type: "string"
responses:
"200":
description: "successful operation"
schema:
$ref: "#/definitions/Company"
"400":
description: "Invalid Company"
securityDefinitions:
api_key:
type: "apiKey"
name: "api_key"
in: "header"
definitions:
Company:
type: "object"
required:
- "name"
properties:
id:
type: "string"
name:
type: string
email:
type: string
externalDocs:
description: "Find out more about Swagger"
url: "http://swagger.io"
生成的curl请求如下:-
curl -X POST "https://host.com/dev/companies" -H "accept: application/json" -H "api_key: jnhgvfctrdyuiojnkbhgvcftyuijnkbvfytguhi" -H "Content-Type: application/json" -d "{ \"name\": \"string\",\"email\": \"string\"}"
我希望拥有api_Key
,而不是--header 'Authorization: Bearer access_token
。
任何输入都将非常有帮助。 TIA
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)