0

私のサーバーアプリケーションjsonは、次の形式で応答を送信します

{
result: ... //this could be success or error
additional-info: ... //this is a wrapper and could contains information depending the the operation
}

additional-info成功メッセージ (「操作が成功しました」など)、エラー メッセージ (「操作が失敗しました」など)、または文字列形式のオブジェクト ( {user-name: manu}.

swagger上記のオブジェクトの定義を次のように作成しました。

ServerSuccessResponse:
      type: object
      properties:
        result:
          type: string
          enum:
            - success
        additional-info:
          type: string
          enum:
            - SuccessMessages
            - UserResponse
      required:
        - result
        - additional-info

    ServerFailureResponse:
      type: object
      properties:
        result:
          type: string
          enum:
            - error
        additional-info:
          type: string
          enum:
            - FailureMessages

次に、次のようにAPIで上記の定義を使用しようとしています

  /user/username:
    post:
      tags:
        - new user
      summary: Add a new user to the database
      description: Use this path to add a new user
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/NewUser'
      responses:
        '200':
          description: means the user was added successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ServerSuccessResponse'#BUT ITS NOT CLEAR WHAT ADDITIONAL-INFO CONTAINS
        '404':
          description: >-
            Only a signed in user can add a question. This response means that
            the user isn't signed in.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ServerFailureResponse' #BUT ITS NOT CLEAR WHAT ADDITIONAL-INFO CONTAINS
        '500':
          description: >-
            means some internal error occur on the server while doing the
            operation. The state of the operation if un-determined and the
            operation could be successful, failed or partially successful
            (because some database operations are not rolled back if error
            occurs!
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ServerFailureResponse'#BUT ITS NOT CLEAR WHAT ADDITIONAL-INFO CONTAINS

私の問題は、現時点では、ServerFailureResponseまたは何が含まれるServerSuccessResponseかわかりません. additional-infoに含まれるものも明確になるように API 定義を再設計したいと考えていますadditional-info。私ができる方法はありますか?additional-infoコードでは、まだラッパーとして使用したいです。私が欲しいのは、各応答Swaggerの内容が明確であることだけです。additional-info

4

0 に答える 0