首页 > 解决方案 > Swagger yaml/yml oneOf 不起作用

问题描述

我目前正在构建我们的 REST API,但在实现我们的文件类型时我被卡住了。文件可以来自用户或组,我尝试过此操作,oneOf但出现错误。这是我的代码和错误:

File:
  type: object
  properties:
    owner:
      oneOf:
        - $ref: "#/definitions/User"
        - $ref: "#/definitions/Group"
      description: Owner of the File

错误:

swagger_spec_validator.common.SwaggerValidationError: ("'oneOf' does not match any of the regexes: '^x-'\n\nFailed validating 'additionalProperties' in schema['properties']['definitions']['additionalProperties']['properties']['properties']['additionalProperties']:\n    {'additionalProperties': False,\n     'description': 'A deterministic version of a JSON Schema object.',\n     'patternProperties': {'^x-': {'$ref': '#/definitions/vendorExtension'}},\n     'properties': {'$ref': {'type': 'string'},\n                    'additionalProperties': {'anyOf': [{'$ref': '#/definitions/schema'},\n                                                       {'type': 'boolean'}],\n                                             'default': {}},\n             'allOf': {'items': {'$ref': '#/definitions/schema'},\n                              'minItems': 1,\n                              'type': 'array'},\n                    'default': {'$ref': 'http://json-schema.org/draft-04/schema#/properties/default'},\n                    'description': {'$ref': 'http://json-schema.org/draft-04/schema#/properties/description'},\n                    'discriminator': {'type': 'string'},\n                    'enum': {'$ref': 'http://json-schema.org/draft-04/schema#/properties/enum'},\n                    'example': {},\n                    'exclusiveMaximum': {'$ref': 'http://json-schema.org/draft-04/schema#/properties/exclusiveMaximum'},\n                    'exclusiveMinimum': {'$ref':'http://json-schema.org/draft-04/schema#/properties/exclusiveMinimum'},\n                    'externalDocs': {'$ref': '#/definitions/externalDocs'},\n                    'format': {'type': 'string'},\n                    'items': {'anyOf': [{'$ref': '#/definitions/schema'},\n                                        {'items': {'$ref': '#/definitions/schema'},\n                                         'minItems': 1,\n                                         'type': 'array'}],\n               'default': {}},\n                    'maxItems': {'$ref': 'http://json-schema.org/draft-04/schema#/definitions/positiveInteger'},\n                    'maxLength': {'$ref': 'http://json-schema.org/draft-04/schema#/definitions/positiveInteger'},\n                    'maxProperties': {'$ref': 'http://json-schema.org/draft-04/schema#/definitions/positiveInteger'},\n                    'maximum': {'$ref': 'http://json-schema.org/draft-04/schema#/properties/maximum'},\n          'minItems': {'$ref': 'http://json-schema.org/draft-04/schema#/definitions/positiveIntegerDefault0'},\n                    'minLength': {'$ref': 'http://json-schema.org/draft-04/schema#/definitions/positiveIntegerDefault0'},\n        'minProperties': {'$ref': 'http://json-schema.org/draft-04/schema#/definitions/positiveIntegerDefault0'},\n                    'minimum': {'$ref': 'http://json-schema.org/draft-04/schema#/properties/minimum'},\n                    'multipleOf': {'$ref': 'http://json-schema.org/draft-04/schema#/properties/multipleOf'},\n                    'pattern': {'$ref': 'http://json-schema.org/draft-04/schema#/properties/pattern'},\n                    'properties': {'additionalProperties': {'$ref': '#/definitions/schema'},\n                                   'default': {},\n                                   'type': 'object'},\n                    'readOnly': {'default': False, 'type': 'boolean'},\n                    'required': {'$ref': 'http://json-schema.org/draft-04/schema#/definitions/stringArray'},\n                    'title': {'$ref': 'http://json-schema.org/draft-04/schema#/properties/title'},\n                    'type': {'$ref': 'http://json-schema.org/draft-04/schema#/properties/type'},\n                    'uniqueItems': {'$ref': 'http://json-schema.org/draft-04/schema#/properties/uniqueItems'},\n                    'xml': {'$ref': '#/definitions/xml'}},\n     'type': 'object'}\n\nOn instance['definitions']['File']['properties']['owner']:\n    {'description': 'Owner of the File',\n     'oneOf': {'schema': [{'$ref': '#/definitions/User'},\n                          {'$ref': '#/definitions/Group'}]}}", <ValidationError: "'oneOf' does not match any of the regexes: '^x-'">)
The terminal process terminated with exit code: 1

抱歉格式,但这是错误消息...当我是对的时,它失败了,因为oneOf但如here oneOf所述,它在这里完全可用。

请帮我解决这个问题,因为我现在坐了一个小时

编辑:我正在使用 2.0 版的招摇

标签: pythonpython-3.xyamlswagger

解决方案


推荐阅读