如何给出对象列表和不同对象作为API的响应

时间:2019-07-04 05:16:39

标签: swagger swagger-codegen swagger-editor

我想为API编写openapi规范,它将以对象集或另一个对象的形式返回响应。我不确定如何尝试过很多方法,但是我为规范运行代码生成时,却收到错误的类OneOfConnectionDTOConnectionPaginatedResponseDTO。

我正在使用下面的代码,我想在200响应中设置Set或ConnectionPaginatedResponseDTO

openapi: 3.0.0
servers:
  - url: /
info:
  title: OIM Manage Connection
  version: '1.0'
paths:
  '/ManageConnection/viewUserConnection/{oimid}':
    get:
      tags:
        - View Connection
      parameters:
        - description: OIMID of user
          in: path
          name: oimid
          required: true
          schema:
            type: string
            example: 1234
        - description: content type
          in: header
          name: Content-Type
          required: true
          schema:
            type: string
            example: application/json
        - description: Start Index of records to be fetched
          in: query
          name: startIndex
          required: false
          schema:
            type: string
            example: 1
        - description: Start Index of records to be fetched
          in: query
          name: count
          required: false
          schema:
            type: string
            example: 5
      responses:
        '200':
          description: Connection list returned
          content:
            application/json:
              schema:
                oneOf:
                - $ref: '#/components/schemas/ConnectionDTO'
                - $ref: '#/components/schemas/ConnectionPaginatedResponseDTO'
        '401':
          $ref: '#/components/responses/UnAuthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '500':
          $ref: '#/components/responses/DataBaseError'
        '501':
          $ref: '#/components/responses/MethodError'
components:
  responses:
    UnAuthorized:
      description: Not authorized to access the specified resource
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/OIMException'
    MandatoryAttributeNotPassedException:
      description: Requested resource can't be accessed
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/OIMException'
    Forbidden:
      description: Requested resource can't be accessed
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/OIMException'
    DataBaseError:
      description: Unable to connect to database
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/OIMException'
    MethodError:
      description: Method not implemented
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/OIMException'
  schemas:
    ConnectionDTO:
      required:
        - access_type
        - access_identifier
      properties:
        add_access_date:
          type: string
          format: date
        access_identifier:
          type: string
        access_type:
          type: string
        PIN:
          type: string
        is_primary_access:
          type: string
        valid_state:
          type: string
        friendly_name:
          type: string
        oimid:
          type: string
        auth_count:
          type: string
      type: object
    ConnectionPaginatedResponseDTO:
      properties:
        totalResults:
          type: integer
        itemsPerPage:
          type: integer
        startIndex:
          type: integer
        connections:
          $ref: '#/components/schemas/ConnectionDTO'
      type: object

    OIMException:
      properties:
        errorMessage:
          type: array
          items:
            type: string
        message:
          type: string
        httpStatus:
          type: string
        code:
          type: integer
      type: object

0 个答案:

没有答案