在運行我們的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