Swagger 如何在openapi 3.0中定义引用组件的必需属性?

Swagger 如何在openapi 3.0中定义引用组件的必需属性?,swagger,openapi,Swagger,Openapi,我引用了另一个组件,它的一些字段成为必需的 QuestionPost: allOf: - $ref: '#/components/schemas/AbstractQuestion' required: - title - label - required - question_type - answer_type - modeli

我引用了另一个组件,它的一些字段成为必需的

    QuestionPost:
      allOf:
        - $ref: '#/components/schemas/AbstractQuestion'
      required:
          - title
          - label
          - required
          - question_type
          - answer_type
          - modelizable
带有AbstractQuestion的示例,我稍后将提及该组件:

  AbstractQuestion:
        type: object
        properties:
            title:
                description: Question statement
                type: string
            label:
                description: Question label
                type: string
            required:
                description: whether an answer is required for this question or if it could be left blank
                type: boolean
            question_type:
                description: campaign type
                enum:
                    - profile
                    - feeling
                type: string
            answer_type:
                enum:
                    - string
                    - list
                    - date
                type: string
            max_length:
                description: >-
                    for open ended questions this is the max characters possible. for list type questions
                    this would be the max number of options to select when multiple answers are accepted
                type: integer
            modelizable:
                description: 'whether the questions'' answers are suitable for feeding ML models (e.g. 1,2,3,4)'
                type: boolean
            choices:
                $ref: '#/components/schemas/QuestionChoices'
现在,我将使用它定义一个Post请求主体,指定需要哪个字段。注意:我没有在前面的对象中指定这个,因为它也用于其他上下文(例如GET或PUT请求),其中这些字段不是必需的

    QuestionPost:
      allOf:
        - $ref: '#/components/schemas/AbstractQuestion'
      required:
          - title
          - label
          - required
          - question_type
          - answer_type
          - modelizable
当我尝试此解决方案时,我的测试没有通过,因为它们将yaml文件与我的api匹配,并发现以下错误:

openapi_spec_validator.exceptions.ExtraParametersError: Required list has not defined properties: ['label', 'title', 'answer_type', 'question_type', 'modelizable', 'required']
似乎无法在引用的组件中找到所需的属性

当我尝试此解决方案时:

    QuestionPost:
      $ref: '#/components/schemas/AbstractQuestion'
      required:
          - title
          - label
          - required
          - question_type
          - answer_type
          - modelizable
我的编辑给了我一个警告。我对文档的理解是,必填字段将被忽略


也许我想要达到的目标是不可能的?你会怎么做?

你对
allOf
required
的定义是正确的。以防万一,尝试将
required
移动到
allOf
中作为第二项,有些工具不喜欢在
allOf
旁边添加关键字。如果这没有帮助,请向openapi_spec_validator项目提交错误报告。在allof中需要movin解决问题。相应问题:您对
allof
required
的定义是正确的。以防万一,尝试将
required
移动到
allOf
中作为第二项,有些工具不喜欢在
allOf
旁边添加关键字。如果这样做没有帮助,请使用openapi_spec_validator project.movin在解决问题的所有文件中提交错误报告。相应问题: