Skip to content

No error when deserializing a wrong reference. #1693

@VisualBean

Description

@VisualBean

Describe the bug
If a specification has a wrong reference pointer (a response pointing to a schema reference for instance.) no error is pushed to diagnostics and the response will end up simply being null.

OpenApi File To Reproduce

{
    "openapi":"3.0.0",
    "info":{
        "title":"some api",
        "description":"some description",
        "version": "1"
    },
    "servers":[{"url":"https://localhost"}],
    "paths":{
        "/count":{
            "get":{
                "responses":{
                    "200":{
                        "$ref":"#/components/schemas/count"
                    },
                },
            }
        }
    },
    "components":{
        "schemas":{
            "count":{
                "type": "number"
            }
        }
    }
}

Expected behavior
An error should be pushed to Diagnostics, that the reference could not be resolved.

Notes
The behaviour stems from the as T cast in ResolveReference<T> - which for a reference that doesn't match, simply results in null.
A simple solution could be to add a null check in the ResolveReference<T>(OpenApiReference reference) method in OpenApiReferenceResolver (the base one that all of the other Resolve methods use.

Metadata

Metadata

Assignees

Labels

type:bugA broken experience

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions