OpenApi 3.0 oneOf 或 allOf

Wen*_*nGo 5 inheritance openapi

我一直在搜索,但没有找到很多关于何时使用allOfoneOf在 OpenApi 3.0 中的示例或明确解释。
使用allOfwith discriminator 或 有oneOf什么区别?

我的用例如下:
如果没有定义 deviceType,则无法创建设备。您应该只能创建“移动设备”/“固定设备”/“信标设备”,其中包含取决于其类型的属性以及协议中的 deviceId 和名称。

现在我已经实现了这个allOf版本,它正在运行。但我想知道这是否正是我想要的。

      Device:
        type: object
        required:
          - id
          - name
          - deviceType
        discriminator: deviceType
        properties:
          deviceId:
            type: string
            description: The id (UUID) of the device
            readOnly: true
          name:
            type: string
            description: The name of the device
          deviceType:
            type: string
            description: The type of the device
            enum:
              - MobileDevice
              - PinDevice
              - BeaconDevice
      mobileDevice:
        allOf:
          - $ref: '#/definitions/Device'
          - required:
              - platform
              - deviceToken
              - location
            properties:
              platform:
                type: string
                description: |
                  The platform of the device, this can be any string
                  representing the platform type, for instance 'iOS'
              deviceToken:
                type: string
                description: |
                  The deviceToken is the device push notification token
                  given to this device by the OS, either iOS or Android for
                  identifying the device with push notification
                  services.
              location:
                "$ref": "#/definitions/Location"
      pinDevice:
        allOf:
          - $ref: '#/definitions/Device'
          - required:
              - location
            properties:
              location:
                "$ref": "#/definitions/Location"
      beaconDevice:
        allOf:
            - $ref: '#/definitions/Device'
            - required:
                - uuid
                - major
                - minor
              properties:
                uuid:
                  type: string
                  description: |
                    The UUID of the beacon, the purpose is to distinguish iBeacons
                    in your network, from all other beacons in
                    networks outside your control.
                major:
                  type: integer
                  description: |
                    Major values are intended to identify and
                    distinguish a group
                  format: int32
                  minimum: 0
                  exclusiveMinimum: false
                  maximum: 65535
                  exclusiveMaximum: false
                minor:
                  type: integer
                  description: |
                    Minor values are intended to identify and
                    distinguish an individual
                  format: int32
                  minimum: 0
                  exclusiveMinimum: false
                  maximum: 65535
                  exclusiveMaximum: false
Run Code Online (Sandbox Code Playgroud)

我想实现的是,我不应该在不指定类型的情况下初始化设备,并且如果它具有特定类型,则它需要具有所有必需的属性。