2017-05-30 528 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