在运行我们的RESTful Web服务的QA和Prod环境中,端口80未打开。所以,目前,当我试图去扬鞭UI在QA,我得到这个消息,它只是挂起:如何让Swagger UI使用带有Swashbuckle的端口443?
fetching resource list: http://qa-server:80/product-catalog-api/swagger/docs/v1; Please wait.
我使用Swashbuckle配置扬鞭。我也在配置中更改了这一行,但它仍然不起作用。
// 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
再扬鞭会列出我的网络的方法,但它挂起当我点击Try it out!
这是从控制台输出:SCRIPT5: Access is denied. File: swagger-ui-min-js, Line: 10, Column: 4300
编辑:
所以我一直在挖还有一些,已经变得更远了,但仍然不在我想要的位置。如果我对扬鞭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。
EDIT 2
嗯,我想我有Swashbuckle正确配置,因为它正确生成我们的开发服务器上的index.html,但不是质量检查,以便我想这个问题的其余部分是归因于某种差异在环境中或我的软件包没有正确安装在qa中。
DEV:
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('{}')
};
QA:
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。
请看看我的答案在这里:http://stackoverflow.com/questions/36527586/swagger-multiple -hosts-in-same-json-spec/36542927#36542927。可以帮助你。 – Sampada
@Sampada这有助于我更好地理解问题。但是,我仍然不知道如何更改Swagger的index.html或json文件。它看起来像Swashbuckle动态创建它们,所以可能有一些我缺少的Swashbuckle配置。在阅读你的答案之后,我确实收到了一些我将添加到我的问题中的信息。谢谢! –
很高兴帮助!虽然我不知道有什么不对。祝你好运。 – Sampada