OpenAPI 解析器 (Light-4J) 不适用于“oneOf”标准

问题描述 投票:0回答:1

以下是架构。

components:
  schemas:
    GroupHeader114:
      type: object
      properties:
        Authstn:
          type: object
          oneOf:
            - type: object
              properties:
                Cd:
                  type: string
                  enum:
                    - AUTH
                    - FDET
            - type: object
              properties:
                Prtry:
                  type: string
                  enum:
                    - ABC
                    - DDD

有效负载:

{
       “GroupHeader114”: {
               “Authstn”: {
                    “Cd”: “AUTH”,
                    “Prtry”: “DDD”
               }
        }
}

结果:验证在不应该通过的时候通过了,因为它满足两个模式的标准。解析器或验证器中似乎存在错误。

感谢任何帮助。
发送

ps:Light-4J - 2.0.10

openapi json-schema-validator light-4j
1个回答
0
投票

按如下方式更改

Authstn
架构。您需要为每个子模式指定必填字段,并禁止其他属性 - 这将使子模式具有唯一可识别性。如果没有明确定义所需的属性,即使是空对象
{}
也将成功匹配这些子模式。

        Authstn:
          oneOf:
            - type: object
              required: [Cd]
              properties:
                Cd:
                  type: string
                  enum:
                    - AUTH
                    - FDET
              additionalProperties: false
            - type: object
              required: [Prtry]
              properties:
                Prtry:
                  type: string
                  enum:
                    - ABC
                    - DDD
              additionalProperties: false

您还可以按如下方式重写

Authstn
模式,将
Cd
Prtry
定义为互斥属性而不是互斥子模式(如果对您的情况有意义):

        Authstn:
          type: object
          properties:
            Cd:
              type: string
              enum:
                - AUTH
                - FDET
            Prtry:
              type: string
              enum:
                - ABC
                - DDD
          additionalProperties: false

          oneOf:
            - required: [Cd]
            - required: [Prtry]
          # Or, instead of oneOf (if suitable):
          # minProperties: 1
          # maxProperties: 1
© www.soinside.com 2019 - 2024. All rights reserved.