python-openapi/openapi-schema-validator

Inner any of type mismatch not raising error

Diacrome opened this issue · 0 comments

If we have stacked any of and on the second level send strring, not an object, validator doesn't react.
If we do so on the top any of validator will find error as intended.
python 3.11.2
openapi_schema_validator 0.6.0

Expect error on validation, but there was not.

Object:

        {
            "animals_top_any_of": {
                "milk_product_additional_field": {
                    "product_spec_inner_any_of": "string_not_object_under_any_of_expect_error_but_there_is_not"
                }
            }
        }

Schema:

{
  "type": "object",
  "title": "Farm - top level",
  "allOf": [
    {
      "$ref": "#/components/schemas/Schema"
    }
  ],
  "components":{
    "schemas": {
      "Schema": {
        "properties":{
          "animals_top_any_of": {
            "type": "object",
            "description": "Animals top any Of",
            "anyOf": [
              {
                "$ref": "#/components/schemas/Mammal"
              },
              {
                "$ref": "#/components/schemas/Bird"
              }
            ]
          }
        },
        "required":[
          "animals_top_any_of"
        ]
      },
      "Mammal": {
        "title": "mammal - under to animals_top_any_of",
        "type": "object",
        "properties": {
          "milk_product_additional_field": {
            "$ref": "#/components/schemas/Dairy"
          }
        }
      },
      "Bird": {
        "title": "under animals_top_any_of",
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          }
        }
      },
      "Dairy": {
        "properties": {
          "product_spec_inner_any_of": {
            "type": "object",
            "description": "inner any of",
            "anyOf": [
              {
                "$ref": "#/components/schemas/Milk"
              },
              {
                "$ref": "#/components/schemas/Cream"
              }
            ]
          }
        },
        "required":[
          "product_spec_inner_any_of"
        ]
      },
      "Milk": {
        "title": "milk element inner any of",
        "type": "object",
        "properties": {
          "fat_percentage_int": {
            "type": "integer"
          }
        }
      },
      "Cream": {
        "title": "cream element inner any of",
        "type": "object",
        "properties": {
          "cream_only_viscosity_int": {
            "type": "integer"
          }
        }
      }
    }
  }
}


Top level any of type missmatch works as intended:
object:

            {
                "animals_top_any_of": "string_not_object_under_any_of_correctly_finds_error"
            }