2017-03-14 14 views
0

私はallOfを使用して、このswagger API継承のものを理解しようとしています。これは私のすばらしいyamlファイルです。スワッガー:追加のプロパティは許可されていません:allOf

swagger: '2.0' 
info: 
    title: Test API 
    version: '1' 
basePath: /api/v1 
schemes: 
    - https 
produces: 
    - application/json 

paths: 
    /users: 
    get: 
     summary: Collection of users 
     tags: 
     - users 
     responses: 
     200: 
      description: A list of Users 
      schema: 
      $ref: "#/definitions/Users"   
     500: 
      $ref: "#/responses/BadRequest" 

definitions: 
    User: 
    required: 
     - username 
    properties: 
     firstName: 
     type: string 
     lastName: 
     type: string 
     username: 
     type: string 
    Users: 
    type: array 
    items: 
     $ref: "#/definitions/User" 

responses: 
    NonSuccess: 
    description: Generic response for all non-success responses 
    schema: 
     type: object 
     required: 
     - code 
     - message 
     properties: 
     code: 
      type: integer 
      description: The success code, 0 or -1. 
     message: 
      type: string 
      description: The description message for this success code 
     errors: 
      type: array 
      description: A map of errors within the request. Keyed by the parameter name and the values are the error details 

    BadRequest: 
    description: Invalid request parameters 
    allOf: 
     - $ref: "#/responses/NonSuccess" 

私はonline editorにこれを貼り付けるとき、私は私が把握しようと本当の苦労を抱えている、次のエラーが発生します。

✖ Swagger Error 
Additional properties not allowed: allOf 
Jump to line 60 

✖ Swagger Error 
Not a valid response definition 
Jump to line 22 

主な問題Additional properties not allowed: allOfのようだと私は、私はこのケースでは間違ってやっているかを把握するように見えることはできません。私は基本的な不成功応答を宣言しようとしていたので、200以外のすべての応答が継承され、APIは非常に標準的な見えない不成功応答を持つようになりました。私はallOfとこれを行うことができた印象の下にあったし、その応答からフィールドを追加または上書きします。私は間違って何をしているのですか?

答えて

3

allOfタグは、スキーマオブジェクトでのみ使用できます。あなたは確かにそれをレスポンスのスキーマ部分で使うことができます。ここにその例があります。

swagger: '2.0' 
info: 
    title: Test API 
    version: '1' 
basePath: /api/v1 
schemes: 
    - https 
produces: 
    - application/json 

paths: 
    /users: 
    get: 
     summary: Collection of users 
     tags: 
     - users 
     responses: 
     200: 
      description: A list of Users 
      schema: 
      $ref: "#/definitions/Users"   
     500: 
      $ref: "#/responses/BadRequest" 

definitions: 
    User: 
    required: 
     - username 
    properties: 
     firstName: 
     type: string 
     lastName: 
     type: string 
     username: 
     type: string 
    Users: 
    type: array 
    items: 
     $ref: "#/definitions/User" 

    Response: 
    type: object 
    required: 
     - code 
     - message 
    properties: 
     code: 
     type: integer 
     description: The success code, 0 or -1. 
     message: 
     type: string 
     description: The description message for this success code 
     errors: 
     type: array 
     description: A map of errors within the request. Keyed by the parameter name and the values are the error details 

    BadRequest: 
    type: object 
    required: 
     - validationErrors 
    properties: 
     validationErrors: 
     type: array 
     items: 
      type: string 

responses: 
    NonSuccess: 
    description: Generic response for a non-success 
    schema: 
     $ref: "#/definitions/Response" 

    BadRequest: 
    description: Invalid request parameters 
    schema: 
     allOf: 
     - $ref: "#/definitions/Response" 
     - $ref: "#/definitions/BadRequest" 
+0

ええと、これは私が終わった場所です。 – SynackSA

関連する問題