2017-04-05 4 views
0

私はSwagger 2.0とSwagger UI 3.0.3を使用しています。Swagger UIリクエストにヘッダを追加しない

私は私のパスの前に、次のしている私の api_definition.yaml

swagger: '2.0' 

################################################################################ 
#     Host, Base Path, Schemes and Content Types     # 
################################################################################ 
# Metadata 
info: 
    version: v1 
    title: Microservice 
    description: Microservice API! 


host: sandbox 

basePath: '/apps/fiji/v1' 
schemes: 
    - http 

securityDefinitions: 
    apikey: 
    type: apiKey 
    name: X-Access-Token 
    in: header 

security: 
    - apikey: [] 

produces: 
    - application/json 
consumes: 
    - application/json 

これは承認ボタン、ユーザーが自分のAPIキーに貼り付けることができ闊歩UIを追加します。すべてのリクエストのリクエストヘッダにこのAPIキーを送信したいと思います。これは起こることはありませんし、なぜ私は確信していません。何か不足していますか?

EDIT:

リクエストが送信し、私は戻って401 Unauthorizedを取得しているようです。

クローム開発ツールには、次のリクエストヘッダを示しています。次のように

# API Paths 
paths: 
    # getCPICountries endpoint 
    /getCPICountries: 
    # HTTP operations 
    get: 
     # Describe this verb here. Note: you can use markdown 
     description: | 
     Returns a list of countries and country codes 
     produces: 
     - application/json 
     security: 
     - auth: 
      - role_admin 
     # Expected responses for this operation: 
     responses: 
     # Response code 
     200: 
      description: Successful response 
      # A schema describing your response object. 
      # Use JSON Schema format 
      schema: 
      properties: 
       data: 
       type: array 
       items: 
        $ref: '#/definitions/CPIResponse' 

と定義:

GET /apps/fiji/v1/getCPICountries HTTP/1.1 
Host: sandbox 
Connection: keep-alive 
accept: application/json 
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36 
content-type: application/json 
Referer: http://sandbox/apps/fiji/vendor/swagger-ui/dist/index.html?url=http://sandbox/apps/fiji/swagger/api_definition.yaml 
Accept-Encoding: gzip, deflate, sdch 
Accept-Language: en-US,en;q=0.8 

私はとして設定パスを持っている

definitions: 
    CPIResponse: 
    type: object 
    UserObject: 
    type: object 
    properties: 
     email: 
     type: string 
     id: 
     type: number 
     orgId: 
     type: number 
     firstName: 
     type: string 
     lastName: 
     type: string 
+0

あなたの仕様は有効で、最新のマスターで私にとって似たような設定がうまくいきます。問題のある操作の仕様を投稿できますか?リクエストは実際に送信されますか?ブラウザのdevツールの[ネットワーク]タブをチェックした場合、 – Helen

+0

@Helenリクエストヘッダーで更新されました。 '{" message ":"トークンがTokenStorageに見つかりませんでした。 "} ' –

+0

操作定義(YAML)を投稿できますか? – Helen

答えて

1

問題でした私のパスにはsecurityが上書きされています。私は以下を削除する必要があります:

security: 
    - auth: 
    - role_admin 
関連する問題