我有一个openapi.yml,我用IntelliJ编辑。
当我使用OpenApi编辑器插件(与redoc一起)预览文件时,有一个身份验证部分(字面意思是<div id="section/authentication" ...)显示来自components/securitySchemes的auth选项。
当我使用独立的html页面查看同一个文件时,此部分不会出现。
<!DOCTYPE html>
<html>
<head>
<title>Redoc</title>
<!-- needed for adaptive design -->
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link
href="https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:300,400,700"
rel="stylesheet"
/>
<!--
Redoc doesn't change outer page styles
-->
<style>
body {
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<!--
Redoc element with link to your OpenAPI definition
-->
<redoc spec-url="openapi.yml"></redoc>
<!--
Link to Redoc JavaScript on CDN for rendering standalone element
-->
<script src="https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js"></script>
</body>
</html>MWE openapi.yml
openapi: '3.0.3'
info:
version: '2.0.0'
title: My Api
paths:
/bob:
get:
responses:
'200':
description: ok
components:
securitySchemes:
Basic:
type: http
scheme: basic
OAuth2:
type: oauth2
flows:
clientCredentials:
tokenUrl: /oauth2
refreshUrl: /oauth2
scopes:
bob: bob
security:
- Basic: []
- OAuth2:
- bob是什么导致了这一切?我怎样才能使这部分出现?
发布于 2022-07-04 14:06:46
安全定义部分已移至每个操作。若要使用旧行为(在“身份验证”部分下有安全定义),必须在全局描述字段中添加以下标记:<SecurityDefinitions />
发布于 2022-06-20 18:55:50
单靠securitySchemes是不够的,本节定义了可用的安全方案,但没有应用它们。
要将安全方案实际应用于API,您需要在根级或在单个操作中添加security部分:
openapi: 3.0.3
...
components:
securitySchemes:
...
# Either Basic auth or OAuth 2.0 is required
security:
- Basic: []
- OAuth2:
- bobhttps://stackoverflow.com/questions/72690501
复制相似问题