Gi60s / openapi-enforcer

Apache License 2.0
94 stars 22 forks source link

Property not allowed: required #102

Closed malkevych closed 3 years ago

malkevych commented 3 years ago

I have such schema:

type: object
properties:
  search_text:
    description: Title of station, city etc can be used as a search text
    type: string
    minLength: 4
    maxLength: 30
  bounding_box:
    description: Returns only stantions that fit in this bounding box
    $ref: bounding-box.yaml
anyOf:
  - required: [search_text]
  - required: [bounding_box]

It means that one of search_text or bounding_box must be provided. (oas 3). After running validation the poenapi-encofrcer says next error:

      at: /v1/stations > get
        at: parameters > 0 > schema > anyOf
          at: 0
            Property not allowed: required
          at: 1
            Property not allowed: required
Gi60s commented 3 years ago

Hello @malkevych. Thank you for the issue.

There might be a few problems here but let's start with anyOf. If I'm reading your example correctly then anyOf should not have any sibling properties. In this case that means it should not have the type and properties siblings. Also, any object with a $ref is not allowed to have sibling properties.

Maybe your schema should look like this?

anyOf:
  - type: object
    required:
      - search_text
    properties:
      search_text:
        description: Title of station, city etc can be used as a search text
        type: string
        minLength: 4
        maxLength: 30
  - type: object
    required:
      - bounding_box
    properties:
      bounding_box:
        $ref: bounding-box.yaml

I hope that helps. I'm going to close this issue for now but if it's still a problem comment here and I'll help out and potentially reopen the issue.

Thank you.