我如何表示“授权:持有者<令牌>"在 Swagger 规范 (swagger.json) 中 [英] How can I represent 'Authorization: Bearer <token>' in a Swagger Spec (swagger.json)
本文介绍了我如何表示“授权:持有者<令牌>"在 Swagger 规范 (swagger.json) 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图传达身份验证/安全方案需要如下设置标头:
I am trying to convey that the authentication/security scheme requires setting a header as follows:
Authorization: Bearer <token>
这是我基于 swagger 文档:
securityDefinitions:
APIKey:
type: apiKey
name: Authorization
in: header
security:
- APIKey: []
推荐答案
也许这会有所帮助:
swagger: '2.0'
info:
version: 1.0.0
title: Based on "Basic Auth Example"
description: >
An example for how to use Auth with Swagger.
host: basic-auth-server.herokuapp.com
schemes:
- http
- https
securityDefinitions:
Bearer:
type: apiKey
name: Authorization
in: header
paths:
/:
get:
security:
- Bearer: []
responses:
'200':
description: 'Will send `Authenticated`'
'403':
description: 'You do not have necessary permissions for the resource'
您可以在此处复制并粘贴:http://editor.swagger.io/#/ 以查看结果.
You can copy&paste it out here: http://editor.swagger.io/#/ to check out the results.
swagger editor web 中还有几个示例,其中包含更复杂的安全配置,可以帮助您.
There are also several examples in the swagger editor web with more complex security configurations which could help you.
这篇关于我如何表示“授权:持有者<令牌>"在 Swagger 规范 (swagger.json) 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文