英文:
Is it possible to emulate remote URL behavior using local browser object?
问题
我正在使用Redoc独立版与我们的API服务器。在加载redoc.standalone.js
后,redoc
尝试从API服务器获取schema.yaml
。然而,我们的服务器需要一个带有令牌的Authorization
头,而Redoc
默认不包括这个头部。我正在寻找一种解决方案,要么将模式文件下载并保存到本地,要么将Authorization
头部添加为页面发送的所有请求的默认头部。是否有另一种方法可以在不向私有API服务器发出请求的情况下由Redoc
本地读取schema.yaml
?以下是我正在使用Redoc的当前HTML代码:
<!DOCTYPE html>
<html>
<head>
<title>示例API</title>
<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">
<style>
body {
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<redoc spec-url='https://api.example.com/schema.yaml'></redoc>
<script src="redoc.standalone.js"></script>
</body>
</html>
英文:
I am using Redoc standalone with our API server. After redoc.standalone.js
is loaded, redoc
tries to fetch schema.yaml
from the API server. However, our server needs an Authorization
header with token, which Redoc
does not include by default. I am looking for a solution to either download and save the schema file locally or add the Authorization
header as a default header for all requests sent from the page. Is there another way to read schema.yaml
locally by Redoc
without making a request to the private API server? Below is the current HTML code I am using with Redoc:
<!DOCTYPE html>
<html>
<head>
<title>Example API</title>
<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">
<style>
body {
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<redoc spec-url='https://api.example.com/schema.yaml'></redoc>
<script src="redoc.standalone.js"></script>
</body>
</html>
答案1
得分: 1
我认为可以用一种不同的方法来完成这个任务。不要使用React渲染Redoc,而是使用redocly build-docs
命令(查看文档:https://redocly.com/docs/cli/commands/build-docs/)在一个可以访问模式架构或在生成文档之前可以下载它的位置来构建HTML文档。然后发布HTML输出。
(免责声明,我在Redocly工作,他们制作了Redoc)
英文:
I think this can be done with a different approach. Instead of using the react rendering with Redoc, build the HTML documentation with the redocly build-docs
command (see docs: https://redocly.com/docs/cli/commands/build-docs/) from a location where you do have access to the schema, or can download it before generating the docs. Then publish the HTML output.
(disclaimer, I work at Redocly, who make Redoc)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论