Skip to content

No error when deserializing a wrong reference. #1693

Closed

Description

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.

Activity

  1. MaggieKimani1 commented on Jun 20, 2024

    @MaggieKimani1
    Contributor

    You're right this is a bug, this should be appended to the diagnostics object as an error. Fixing..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

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