【发布时间】:2016-08-06 02:51:48
【问题描述】:
在运行 RESTful Web 服务的 QA 和 Prod 环境中,端口 80 未打开。所以目前当我尝试在 QA 中访问 Swagger UI 时,我收到了这条消息,它只是挂起:
fetching resource list: http://qa-server:80/product-catalog-api/swagger/docs/v1; Please wait.
我正在使用 Swashbuckle 来配置 Swagger。我也在配置中更改了这一行,但它仍然不起作用。
// If schemes are not explicitly provided in a Swagger 2.0 document, then the scheme used to access
// the docs is taken as the default. If your API supports multiple schemes and you want to be explicit
// about them, you can use the "Schemes" option as shown below.
//
c.Schemes(new[] { "https" });
SSL 端口 443 已打开,因此我想访问 Swagger UI 以在其上运行。我可以手动将http://qa-server:80/product-catalog-api/swagger/docs/v1 更改为https://qa-server/product-catalog-api/swagger/docs/v1,然后Swagger 会列出我的Web 方法,但是当我单击Try it out! 时它会挂起这是控制台的输出:SCRIPT5: Access is denied. File: swagger-ui-min-js, Line: 10, Column: 4300
编辑:
所以我一直在挖掘更多内容,并且已经走得更远了,但仍然不是我想要的。如果我在 Swagger index.html 文件上查看源代码,我可以看到问题:
window.swashbuckleConfig = {
rootUrl: 'http://qa-server:80/product-catalog-api',
discoveryPaths: arrayFrom('swagger/docs/v1'),
booleanValues: arrayFrom('true|false'),
validatorUrl: stringOrNullFrom('null'),
customScripts: arrayFrom(''),
docExpansion: 'none',
oAuth2Enabled: ('false' == 'true'),
oAuth2ClientId: '',
oAuth2ClientSecret: '',
oAuth2Realm: '',
oAuth2AppName: '',
oAuth2ScopeSeperator: ' ',
oAuth2AdditionalQueryStringParams: JSON.parse('{}')
};
即使我以 https 身份导航到该站点并将 Swashbuckle 方案设置为 https,它仍然将 rootUrl 生成为 http。我想因为我使用的是 Swashbuckle,所以我必须使用它来配置 index.html,因为我的代码中没有该文件,所以我猜 Swashbuckle 正在动态生成它。
在更改 swagger.json 的路径时,我确实发现了我缺少的东西。它显然需要那里的端口号。因此,如果我导航到 swagger 索引页面并手动将 json 文件的路径更改为 https://qa-server:443/product-catalog-api/swagger/docs/v1 一切正常。所以现在我认为我已经将问题隔离为如何使用 Swashbuckle 更改 Swaggers index.html 中的 rootUrl。
编辑 2
好吧,我认为我已经正确配置了 Swashbuckle,因为它在我们的开发服务器上正确生成了 index.html,但不是 qa,所以我猜剩下的问题是由于环境的一些差异或者我的包没有得到正确安装在 qa 中。
开发者:
window.swashbuckleConfig = {
rootUrl: 'https://server-dev:443/product-catalog-api',
discoveryPaths: arrayFrom('swagger/docs/v1'),
booleanValues: arrayFrom('true|false'),
validatorUrl: stringOrNullFrom('null'),
customScripts: arrayFrom(''),
docExpansion: 'none',
oAuth2Enabled: ('false' == 'true'),
oAuth2ClientId: '',
oAuth2ClientSecret: '',
oAuth2Realm: '',
oAuth2AppName: '',
oAuth2ScopeSeperator: ' ',
oAuth2AdditionalQueryStringParams: JSON.parse('{}')
};
质量检查:
window.swashbuckleConfig = {
rootUrl: 'http://qa-server:80/product-catalog-api',
discoveryPaths: arrayFrom('swagger/docs/v1'),
booleanValues: arrayFrom('true|false'),
validatorUrl: stringOrNullFrom('null'),
customScripts: arrayFrom(''),
docExpansion: 'none',
oAuth2Enabled: ('false' == 'true'),
oAuth2ClientId: '',
oAuth2ClientSecret: '',
oAuth2Realm: '',
oAuth2AppName: '',
oAuth2ScopeSeperator: ' ',
oAuth2AdditionalQueryStringParams: JSON.parse('{}')
};
编辑 3
我们进行了测试以进一步隔离问题。我们的 QA 环境中有一个 A10 负载均衡器。我们为开发环境搭建了一个新的 A10 来看看发生了什么,现在我们在开发环境中遇到了同样的问题。 A10 正在执行一些 http 标头操作,我们将其删除以查看是否是问题所在,但仍然得到相同的结果。我相信通过服务器的设置方式,SSL 被卸载到 A10 并且实际运行我的代码的盒子正在获取 http。所以当 Swashbuckle 代码运行时,它是在 http 下运行导致问题。我想我需要一种方法来强制它始终是 https。
【问题讨论】:
-
请在此处查看我的答案:stackoverflow.com/questions/36527586/…。可能会对你有所帮助。
-
@Sampada 这有助于我更好地理解问题。但是,我仍然不知道如何更改 Swagger 的 index.html 或 json 文件。看起来 Swashbuckle 正在动态创建它们,所以我可能缺少一些 Swashbuckle 配置。阅读您的答案后,我确实获得了更多信息,这些信息将添加到我的问题中。谢谢!
-
很高兴为您提供帮助!不过,我对swashbuckle一无所知。祝你好运。
标签: swagger swashbuckle