2017-05-30 80 views

回答

0
window.swaggerUi.api.clientAuthorizations.add(swashbuckleConfig.apiKeyName, new SwaggerClient.ApiKeyAuthorization(swashbuckleConfig.apiKeyName, key, "header")); 
     window.swaggerUi.api.clientAuthorizations.add(swashbuckleConfig.apiKeyName + " query", new SwaggerClient.ApiKeyAuthorization(swashbuckleConfig.apiKeyName, key, "query")); 
0

同時定義頁眉和您的API SPEC在securityDefinitions查詢參數:

securityDefinitions: 
    apiKeyHeader: 
    type: apiKey 
    in: header 
    name: X-EGEN-AccessTokenID 
    apiKeyQueryParam: 
    type: apiKey 
    in: query 
    name: api_key # replace with your query param name 

然後,如果你需要頭和查詢參數傳遞在同一個請求中:

security: 
    - apiKeyHeader: [] 
    apiKeyQueryParam: [] 

或者如果無論是頭或查詢參數應使用,但不能同時:

security: 
    - apiKeyHeader: [] 
    - apiKeyQueryParam: [] 

此處瞭解詳情: http://swagger.io/docs/specification/authentication/api-keys/

在揚鞭UI,當你點擊「授權」,您將進入值用於標題和查詢參數。

+0

請問你能否幫助我,不能添加apiKey作爲查詢參數在swagger 3.x即最新版本... https://stackoverflow.com/questions/49050969/setting-swagger-apikey-in-版本2-0?noredirect = 1#comment85145482_49050969 – user3252097