Skip to content

Check that something is a hash ref before you use it as a hashref #1

@briandfoy

Description

@briandfoy

I have a file that passes the other linters, including the one from Swagger, but openapi-linter blows up:

$ openapi-linter --spec some_file.yml

I get:

Not a HASH reference at /usr/local/perls/perl-5.42.0/lib/site_perl/5.42.0/OpenAPI/Linter.pm line 185.

This comes from code like:

        for my $method (sort keys %{$spec->{paths}{$path}}) {
            my $op = $spec->{paths}{$path}{$method};
            push @issues, {
                level   => 'WARN',
                message => "Missing description for $method $path"
            } unless $op->{description};
        }

You assume that the value in $op is a hash reference. If it isn't, there should be a different validation error. Once you have verified that $op is a hashref, you can move on to the other checks. This is especially important when you expect malformed formats.

There are several other areas in the code where this is also a problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions