pyopenapi/pyswagger

Is there a way to specify an HTTP header to be included in a request?

MartinDelVecchio opened this issue · 7 comments

I can't find any examples of this.

Thanks.

@MartinDelVecchio

  • Did you mean a header parameter declared in Swagger (Open API) spec, or not ?
  • Which header do you want to set ?

I guess you mean headers not declared in spec, then the answer is no, and I can add some way to specify them.

Ah, there is my solution. This is for our API, and I forgot that I could just add an optional header to our Swagger.

So no need for any work on your part; the Swagger standard has what I need.

Thanks!

I was able to add a header parameter to my Swagger, and set it via the pyswagger API.

But now I need to do the same thing for another Swagger, which I do not control.

So I would like to renew my request for a way to specify an arbitrary HTTP header to be included in the request.

I am currently creating an app and a client this way:

    self.app = pyswagger.App._create_ (swagger_location)

    self.auth = pyswagger.Security (self.app)
    self.client = Client (self.auth, send_opt={'verify': False})

And then executing the operation with this call:

    response = self.client.request (self.app.op[operation_id](**kwargs), opt=opt)

I see that the requet() method does not allow me to specify an HTTP header to include. If there is a different way to use pyswagger that would allow me to add a header, I will gladly use it.

But if there is not, I would appreciate a way to do so. Perhaps something like this:

response = self.client.request (self.app.opoperation_id, opt=opt, _headers={"X-My-Header-Name": "Header.Value"})

Thank you.

@MartinDelVecchio I plan to add an additional parameter headers when making request:

# valid headers:
# - {'X-TEST-HEADER': 'aaa'}
# - [('X-TEST-HEADER', 'aaa'), ('X-TEST-HEADER', 'bbb')]  <-- multiple header values for one key
self.client.request (self.app.op[operation_id](**kwargs), opt=opt, headers=headers)

The fix is still ongoing, would let you know once finished.

Thank you!

@MartinDelVecchio the functionality is added in v0.8.33 and the related document is here, please let me know if it doesn't work for you.

I finally got a chance to test this today, and it works as advertised.

Thanks again for being so responsive!