Желательно ли всегда возвращать только один единственный ответ? - PullRequest
0 голосов
/ 18 июня 2019

Я пытаюсь использовать сваггер, и мне нужно посоветовать следующее:

Я возвращаю один ответ во всех случаях с объектом.В части входа в систему я запутался и начал сомневаться в своем коде.

Желательно ли всегда возвращать только один единственный ответ с объектом, который предоставляет детали для типа ответа и детали?Итак, если у меня есть сбой, типом является «сбой», иначе это «проход» с соответствующими сообщениями в текстовой части.

Можно ли улучшить следующее?

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     
...