How to use OpenAPI / Swagger by authenticating endpoints? - swagger

We use swagger in our project and while testing endpoints I need to authenticate in Swagger page (https://localhost:5001/api/index.html). As far as I remember, there was a way to copy the jwt of the current session and paste it to request header, etc. But I have not succeeded with this approach. Is there a proper way e.g. using Swagger Inspector as mentioned on How to Perform a Basic API Test In 3 Steps? Or a smarter way?

Related

Setup google login with swagger UI in Nest.js Project

I have a Nest JS API project in which I've done all my normal auth and CRUD endpoints working good! I have all the endpoints shown in Swagger UI using Nest JS's SwaggerModule. Now I have to add google login to the Swagger UI of this project but IDK how to do it?? I haven't found a clear setup explanation on the web so I can understand how to do this?
This project does not have a front end, so I need like a button from the Swagger UI to access the google login page and then redirect to an endpoint into my project so I can return the token generated by google, copy it and add it into the authorization token in Swagger UI.
Here are some pictures of what I have and what I need so you can better understand in what I need help, please guys:
Here is my Swagger Setup:
Nest JS main.ts file wit Swagger Setup
Here we have:
Normal auth endpoints working.
Button to add auth token so I can use protected endpoints.
What I need, like a google login button that allows me to use a google account and redirect to an endpoint of my API to get the auth token and add it into the 2. button so I can use my protected endpoints.
What I have and what I need
Is it possible to achieve what I'm asking for? This is the first time I'm using Nest JS and Swagger UI.
Thanks!

How can I exclude certain operations/HTTP Verbs with Swagger Codegen?

I'm using Swagger w/ AWS API Gateway. In order to fully support CORS, I have several OPTIONS methods in my swagger file; they exist only to tell API Gateway to return CORS headers so that preflight requests from my Angular app succeed.
However, when I use Swagger codegen to generate the API, all of those OPTIONS methods come across in my service as real methods. I don't want this to be the case.
How can I tell Swagger Code Gen to skip over certain, specific methods; for instance, putting a tag on the OPTIONS methods so that Swagger CodeGen doesn't generate code for those particular HTTP verbs?

How to generate Java REST client from Spring REST Docs like it is generated from swagger.json?

My team used swagger for documenting REST API.
As a QA engineer I was able to generate rest client from swagger.json that was published on remote server upon deploy and use the client for REST API integration testing.
Now we are about to switch from swagger to Spring REST Docs.
QUESTION:
Is there a way to generate java rest client from Spring REST Docs like it was possible for swagger?
If yes - how to do that?
If no - are there any alternative ways to get/generate REST API client.
There's actually a Spring Rest Docs extension now that generates an OpenAPI 2/3 spec which you can then use to do additional things - like generate a client
https://github.com/ePages-de/restdocs-api-spec

Swagger with AWS IAM user Access Key/Secret

I am trying out AWS API Gateway, and it's very easy to import/export API definition from Swagger.
However, I've set my API to require AWS_IAM authorization so it's not public. But I cannot find how to make it work with Swagger UI. It seems Swagger UI only takes API Key, instead of IAM user's Access Key and Secret for Sigv4 signing.
Does anyone know is there a way to configure Swagger UI to take in Access Key/Secret, and sign the request for AWS_IAM auth?
Any direction would be appreciated.
Thanks,
Swagger UI OOTB does not support AWS_IAM auth, however, there you can still accomplish Sigv4 Signing. How to calculate AWS signature V4 in Swagger before request gives two good examples on how to accomplish this.
I used the second example, in conjunction with the author's blog post to test with multiple user Access Key/Secrets. The blog post also goes into more detail on using the AWS JS SDK for this purpose.

Generating Swagger for one service only with Swashbuckle

Is it possible to get the Swagger for an individual endpoint from Swashbuckle? I would like to be able to build individual Swagger documents from each endpoint in my API solution, rather than including all operations in all endpoints.

Resources