Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schema array type with anyOf and discriminator not validate items in the array #208

Open
apiotrowski opened this issue Aug 29, 2023 · 0 comments

Comments

@apiotrowski
Copy link

apiotrowski commented Aug 29, 2023

I am writing api which define response, and one of the property in the response is "filters" property (array type), which has reference to property which use anyOf functionality with discriminator with defined mapping.

Unfortunately my response with array values it is not validate properly. During validation it's validate array using schema choosen by discriminator, but choose constantly first schema.

My expected behaviour is: If i define discriminator property with mapping, it should use schema defined by discriminator.

Example:

...
"filters": {
   "type": "array",
   "items": {
         "$ref": "#/components/schemas/SearchFilter"
   }
}
...

when SearchFilter:

"SearchFilter": {
        "discriminator": {
          "propertyName": "type",
          "mapping": {
            "QUERY": "#/components/schemas/QuerySearchFilter",
            "PRICE": "#/components/schemas/PriceSearchFilter",
            ...            
          }
        },
        "anyOf": [
          {
            "$ref": "#/components/schemas/QuerySearchFilter"
          },
          {
            "$ref": "#/components/schemas/PriceSearchFilter"
          },
          ...          
        ]
      },
     "SearchFilterType": {
        "type": "string",
        "enum": [
          "QUERY",
          "PRICE",
          "CATEGORY",
          "COLOR",
          ...
        ],        
      }

and QuerySearchFilter and PriceSearchFilter are:

"QuerySearchFilter": {
        "type": "object",
        "required": [
          "type"
        ],       
        "properties": {
          "type": {
            "$ref": "#/components/schemas/SearchFilterType"          
          }
        }
      },
"PriceSearchFilter": {
        "type": "object",
        "required": [
          "type",
          "minPrice",
          "maxPrice",
          "discount"
        ],       
        "properties": {
          "type": {
            "$ref": "#/components/schemas/SearchFilterType"
          },
          "minPrice": {
            "$ref": "product.json#/components/schemas/Decimal"
          },
          "maxPrice": {
            "$ref": "product.json#/components/schemas/Decimal"
          },
          "discount": {
            "type": "boolean"
          }
        }
      }

for example my response contains response:

...
"filters": [
  [
       "type": "QUERY
   ],
   [
       "type": "PRICE",
       "minPrice": "10.00"
       "maxPrice": "100.00",
       "discount": true
    ]
]
...

Is anybody could help me, did I deine something in wrong way or is a bug in the validator. I think there is an issue in the validator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant