建议始终仅返回一个响应吗?

时间:2019-06-18 11:05:29

标签: swagger-2.0

我正在尝试使用招摇工具,我需要提供以下建议:

在所有情况下,我都将返回一个带有对象的响应。在登录部分,我感到困惑,并开始对我的代码产生疑问。

建议始终只返回一个单一的响应,并提供一个提供响应类型和详细信息的详细信息的对象吗? 因此,如果我失败了,则类型为“失败”,否则为“通过”,并在文本部分输入相应的消息。

以下内容是否可以改善?

swagger: '2.0'
info:
version: 0.0.1

paths:
  /user/Save:
    post:
      tags:
        - user
      summary: Register user
      description: ''
      operationId: Save
      consumes:
        - application/json
      produces:
        - application/json
      parameters:
        - in: body
          name: body
          description: User details
          required: true
          schema:
            $ref: '#/definitions/Credentials
          responses:
            '200':
              description: Message
              schema:
                $ref: '#/definitions/Message'
              headers:
                Access-Control-Allow-Origin:
                  type: string
        /user/forgotpassword:
        get:
          tags:
            - user
          summary: forgot password
          description: forgot password
          operationId: forgotPassword
          consumes:
            - application/json
          produces:
            - application/json
          parameters:
            - name: email
              in: query
              required: true
              description: User email
              type: string
          responses:
            '200':
              description: Message
              schema:
                $ref: '#/definitions/Message'
              headers:
                Access-Control-Allow-Origin:
                  type: string

      /user/login:
        post:
          tags:
            - user
          summary: Logs user into the system
          description: ''
          operationId: userLogin
          produces:
            - application/json
          parameters:
            - in: body
              name: body
              description: User login details
              required: true
              schema:
                $ref: '#/definitions/User
             responses:
            '200': 
                $ref: "#/definitions/ProfileResponse"


    securityDefinitions:
      api_key:
        type: apiKey
        name: Authorization
        in: header

    definitions:
      Credentials:
        type: object
        properties:
          firstName:
            type: string
          lastName:
            type: string
          email:
            type: string
          password:
            type: string
            format: password
          company:
            type: string
      User:
        type: object
        properties:
          login:
            type: string
          passsword:
            type: string

     Message:
        type: object
        properties:
          text:
            type: string
          type:
            type: string
      ProfileResponse:
        type: object
        properties:
          id:
            type: number
          name:
            type: string
         text:
            type: string
          type:
            type: string     

0 个答案:

没有答案