Skip to content

no-invalid-media-type-examples not working in a basic case with anyOf #1737

@LasneF

Description

@LasneF

Describe the bug

given a sample with anyOf and required statement example validation fails whereas it is valid

To Reproduce
validate the below OAS Spec (in the Additional context section)
launching redocly lint spec.yml

validation fails with the error
failed with 2 errors and 9 warnings.

it shoot about
schema: must NOT have unevaluated properties lastName

and
Example value must conform to the schema: must NOT have unevaluated properties address.

29 | },
30 | "example": {
31 | "address": "someWhere",

vs address is mentioned as required , looks it does not like the anyOf syntax

dropping the anyOf make it ok

Expected behavior

no validation warning toward this sample
sample has been tested with several json schema validator ( json-schema.hyperjump.io , json-everything.net , liquid'

Logs

Redocly Version(s)
redocly 1.25.2 ( on Windows)

Additional context

{
    "openapi": "3.1.0",
    "info": {
        "title": "this is the title",
        "description": "this is the description",
        "version": "1.0"
    },
    "license": {
        "description": "dd"
    },
    "servers": [
        {
            "url": "https://api.server.test/v1"
        }
    ],
    "paths": {
        "/v1/users": {
            "get": {
                "summary": "Get user info",
                "description": "Returns all details about a given user.",
                "operationId": "getUser",
                "responses": {
                    "200": {
                        "description": "Success",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/User"
                                },
                                "example": {
                                    "address": "someWhere",
                                    "firstName": "John",
                                    "lastName": "Doe"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "empty"
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "User": {
                "description": "Details of a user",
                "type": "object",
                "required": [
                    "address"
                ],
                "properties": {
                    "address": {
                        "type": "string"
                    }
                },
                "anyOf": [
                    {
                        "type": "object",
                        "required": [
                            "firstName",
                            "lastName"
                        ],
                        "properties": {
                            "firstName": {
                                "type": "string"
                            },
                            "lastName": {
                                "type": "string"
                            }
                        }
                    },
                    {
                        "type": "object",
                        "required": [
                            "name"
                        ],
                        "properties": {
                            "name": {
                                "type": "string"
                            }
                        }
                    }
                ]
            }
        }
    }
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions