Skip to content

Parameters can't be overridden  #382

@panush

Description

@panush

When I'm trying to validate an openapi v3 yaml file with "parameters:" section under the path (with a single parameter)
and "parameters:" section under the operation (method) that should override the "global" parameter I'm getting this error:
"operation %s %s must define exactly all path parameters".

The bug is in "func (paths Paths) Validate(c context.Context)" at paths.go
The error is because code counts how many path parameters there is in the path (i.e. "pathParamsCount"),
the global parameters at the path level (i.e. "globalCount")
and the local parameters at the operation level (i.e. "count"),
but the comparison between those counters is wrong:

if count+globalCount != pathParamsCount {
return fmt.Errorf("operation %s %s must define exactly all path parameters", method, path)
}

in the attached example you can see that I have:
1 path parameter (customer_id) - "pathParamsCount" = 1
1 global parameter - "globalCount" = 1
1 local parameter (that should override the global definition) - "count" = 1

therefore, the right comparison should be:
if count+globalCount < pathParamsCount {
return fmt.Errorf("operation %s %s must define exactly all path parameters", method, path)
}

Test_param_override.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions