earldouglas / swagger-test

Specification-driven REST API testing
MIT License
113 stars 19 forks source link

optional query parameter specification #24

Closed JoeCarlson closed 4 years ago

JoeCarlson commented 4 years ago

Thank you for providing swagger-test. I had a problem with optional query parameters. I don't know if this is an issue of me not understanding x-amples well enough or a request for a new feature. My endpoint is /api/call/{id} with

...
  parameters:
  - name: id
    in: path
    required: true
  - name: option1
    in: query
    required: false
...

I'd like to execute my tests with and without option1. I hoped that an x-amples entry: request:

...
           params:
             id: 123456
             option1: 10
...

would have generated ?option1=10 to the URL. But this is not the case and I don't see a mechanism for adding query parameters in url-template.js. Is there a mechanism for optional query parameters in swagger-test?

earldouglas commented 4 years ago

Is there a mechanism for optional query parameters in swagger-test?

I can't remember, but that's a great idea. I'll take a look and see if/how that might be supported.

earldouglas commented 4 years ago

You're right; this isn't supported by the current version of swagger-test. #25 is a start at adding support.

earldouglas commented 4 years ago

Optional query parameters in declared x-amples are now supported by swagger-test 0.8.0. Here's an example: https://github.com/earldouglas/swagger-test/blob/0.8.0/test/swagger.json#L34

A follow-up will add support for optional query parameters in inferred x-amples.

JoeCarlson commented 4 years ago

This is working for me. Thanks for the update.