Adding bearer token to swagger requests using swagger-client

950 Views Asked by At

I'm trying to add a bearer JWT token to a swagger request upon login of an account but I can't seem to get it working. The documentation leaves a lot to be desired.

const SWAGGER_CLIENT = SwaggerClient(".../api.yml");

const carsResponse = await SWAGGER_CLIENT.client.execute({ operationId: "getCars" }); // I need { Authorizations: Bearer ${token}} here

If it's not possible to add it there then I can always create the client above with the token upon a successful login.

I think the issue is the syntax more than anything. There is virtually no documentation on how to use the .execute() method which is very frustrating. FWIW; I'm using the execute method and passing in tag names to make it more reusable than using the generated functions e.g., getCars(), addCar() etc. I don't know if this is the "right" way to use Swagger but it makes sense to me.

Is possible to add it globally so I needn't include it in every request? The token will need to be added upon a successful login. It's a CRA application using Redux.

1

There are 1 best solutions below

0
On

We will be renaming Try It Out Executor to HTTP client for OAS operations. Thanks for your input!