1

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 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.

If somebody could explain, or provide a small example of adding the authorization bearer token to the request above that be fantastic and greatly appreciated.

Thanks all.

user.io
  • 396
  • 1
  • 6
  • 17
  • 1
    Here are some docs for `.execute`: https://github.com/swagger-api/swagger-js/blob/master/docs/usage/try-it-out-executor.md – Helen Sep 25 '20 at 06:54
  • Thank you Helen! This really helped. I couldn't find these, and I think the 'TryItOutExecutor' title sounds very misleading. I can see the authorization header now, although get a 403 CORS issue which is being investigated by the person responsible to fix it. Thank you! – user.io Sep 25 '20 at 12:46

1 Answers1

0

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

Vladimír Gorej
  • 217
  • 2
  • 7