dredd icon indicating copy to clipboard operation
dredd copied to clipboard

Skipped tests when using square brackets in get parameter name

Open fessmage opened this issue 3 years ago • 5 comments

Describe the bug Skipped tests when using square brackets in get parameter name

warn: API description URI template expansion warning in /api/api.apib (FooBar API > Foo > Foo): Ambiguous URI parameter in template: /foo{?bar%5B%5D}
Parameter not defined in API description document: bar[]
complete: Tests took 1ms

To Reproduce docker image apiaryio/dredd:14.0.0

api blueprint:

FORMAT: 1A

# FooBar API

## Foo [/foo{?bar%5B%5D}]

+ Parameters
    + bar%5B%5D: `foobar`

### Foo [GET /foo{?bar%5B%5D}]

+ Response 200

Expected behavior Successful test run with output

pass: GET (200) /foo?bar%5B%5D=foobar duration: 504ms
complete: 1 passing, 0 failing, 0 errors, 0 skipped, 1 total
complete: Tests took 509ms

What's your dredd --version output?

dredd v14.0.0 (Linux 5.4.72-microsoft-standard-WSL2; x64)

fessmage avatar Mar 11 '21 10:03 fessmage

Got the same issue for the description below using dredd v14.1.0 (Linux 5.10.102.1-microsoft-standard-WSL2; x64)

FORMAT: 1A

# Foo API

## Group Pagination

### Get paginate foos [GET /foos{?page%5Bnumber%5D}{&page%5Bsize%5D}]

+ Parameters

    + page%5Bnumber%5D: `1` (number, optional) - Number of the page.
        + Default: `1`
    + page%5Bsize%5D: `2` (number, optional) - Number of items in each page.
        + Default: `50`

Changed the description to:

FORMAT: 1A

# Foo API

## Group Pagination

### Get paginated foos [GET /foos{?page%5Bnumber%5D}{&page%5Bsize%5D}]

+ Parameters

    + page[number]: `1` (number, optional) - Number of the page.
        + Default: `1`
    + page[size]: `2` (number, optional) - Number of items in each page.
        + Default: `50`

The warning was still logged but the tests were able to run.

image

But then it as aglio who was not happy with that change, even though the html file was properly generated 🤷🏼‍♂️

>> Line 7: parameter 'page[number]' is not found within the URI template '/foos{?page%5Bnumber%5D}{&page%5Bsize%5D}' for 'Get paginated foos'  (warning code 8)
>> Context
...
>> Line 7: parameter 'page[size]' is not found within the URI template '/foos{?page%5Bnumber%5D}{&page%5Bsize%5D}' for 'Get paginated foos'  (warning code 8)
>> Context
...

jmendes92 avatar Apr 14 '22 13:04 jmendes92

My bad the test success was pure luck. The parameters were missing in the query, just forgot to update the response body 🤦🏼‍♂️.

jmendes92 avatar Apr 14 '22 14:04 jmendes92

Looks like there was a "related" fix to allow dots on request parameters but it does not actually fix this bug.

deivid11 avatar Dec 28 '22 18:12 deivid11

The issue is affecting Open Api v3, on swagger 2.0 is working fine.

deivid11 avatar Dec 28 '22 19:12 deivid11

The openApi parser (@apielements/openapi3-parser) is encoding the parameter name, so the parameter is never found on the available parameters.

One solution could be changing the openapi3-parse to return the parameters as the openapi2 parser, this could have more implications I don't already know. Another solution is to decode the parameter names after getting the parsing result, maybe on this line

deivid11 avatar Dec 28 '22 21:12 deivid11