How to Add API Document to Java Project using Swagger 3 | Spring-boot

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
okay so this is basically what we are going to be doing so this is our API documentation using swagger 3. so this is what we are going to be getting so I just created a dummy project where we have a safe endpoint is get single endpoint and get all I will have a schema here the person schema so yeah you just you can just see the data tabs and for the post when you if I open it is telling me that it does not require parameter this is the object that is required the body and it gets a response of so it returns a string when the response is successful so for getting a single object it requires the parameter I can pass in an ID and then get an object of this nature then to get all when you hit on the get all endpoints it does not require any parameter then it returns an array of objects so an array of this object nature so let's just test it out so we can try it out over here we can click try it out and then I go over here I can just put in the either I can see 56 each I can use for anything as a cute um I got the response successfully received person so if I want to try the get single person I will have to pass in try it out so I have to pass in the ID let's just see if it's 90. as a cute and I got the response of ID I'm getting the 890 back then the name is Dia then the age like I think that then to get all I can just try it out does not require any input you can see I'm getting a string an array of of objects so this is what we'll be covering this tutorial so see you okay so this is the dummy projects we are going to be adding swagato so what I did yeah there's nothing much I just have a controller a model and then the base application so what I did here is just to create a model that has a name and age and an ID and then the controller that has TV 8.1 is to get all you persons the other one is just to get a single person and the third one just to save a person so on my on this project I'm not connecting to the database I'm not doing anything complex I just created a dummy persons here which I'm also returning over here I just created four patients and I'm returning so whenever you hit the all endpoint I'm just going to return four persons so also over here on the same go whenever you pass in the ID in the parameter I'm going to collect the ID and I'm going to use it to create a new pet scene with the name Tia and also for the save if you pass in a depending objects I'm just going to return a successful message that it has been saved okay so that's that so let's just test our application and see how it works okay and then I will then proceed to add the Swagger 3 documentation to our project so okay let's just see if it works um okay in my application.properties there's nothing here so it's just empty okay so we can set up applications running on port 8080 so let me just go to my Postman to check so for now let me get all I'll go to look out 8080 slash all we can see we're returning 4 13s if I go to to get a single person I'm just going to pass in a parameter let's just call this ID let's call this ID and let's call it it 88 if I send I'm gonna get it I'm going to get the person here if I go to posts I'm just going to go to my body I'm going to just put Sarah if I send I'm going to get successfully received testing so let's proceed to add our Swagger documentation so to do that first of all you just go to your pump.sml okay and I will just go to the official documentation page for I'm going to leave a link to this so this is the Swagger 3 open AI official myvine repo Mervin dependency I'm going to copy it I'm just going to go to my project I'm going to paste it there I'm going to synchronize okay so why that is performing at the background I'm just going to create my config file for the Swagger 3 I'm just going here to go here I'm going to create a package this code is config Okay so I'm going to create a class just go and call this I'm going to call this class so I can three config class okay so I'm just going to annotate it as configuration configuration okay and I'm just going to create a bin I'm going to public you're just going to return and open API open API can see the open API is from Swagger 3 v3.0asm okay I'm just going to call this my API to equipment you can just call it anything you want it's not a problem okay so I'm going to return a new open API then we can add some other information then I'm just going to say dot info you can decide to add information then over here I'm going to do new info new info I think it's supposed to I don't know why it's not getting new info I'm going to do dots title you then the title of your application can give it anything let me just call it Tech with 10 then you add a description those description you can just call this Swagger 3 tutorial I'm saying okay tutorial okay so that's you can also proceed to add version you can see those version go to Fashion one night my stuff is very slow can decide to add this or not you know the norm really really very important so so that's what we are basically done here so with this alone it will automatically generate your it will just do is stuff under the hood to gather all your endpoints on the controller you just gather demand just keep them somewhere so let me run my application let me just be to ensure that there's no problem so let me run my application then to access your by default when you go to by default let me just try and run the application and see Okay so yep so my application is running so it's going to package all this for you with this single bin I created so by default when you go to your localhost localhost the tasks whatever your your application is running on if your application is on production it's going to be running on public URL ports and stuff like that but mine is on local machine so that's why is this so by default you're going to put in your your your URL and Swagger UI slash index.html so that's the default so when I go eat in you can see that it generated all our controller for us okay you can see the name is the attack within um those stuff like that okay so I think something's showing out here but if you want to configure this stuff here if you don't want this to just be the default you can just re-configure your own so how to do that is you go to your application.property you just go here and just do something like you say spring doc Dot Swagger UI dot path equals to let me see TWD dot HTML so when you go to your so when you go to your url to your the link to your application then when you just go to slash twd.html is going to is going to just show you the documentation okay let me just make sure that my spelling is correct spring UI dot Parts okay so let's just test that and see how it goes to let me go to localhost and Port is 8080 slash twd.html okay you can see it worked and it also brought us to this page so that's that and that's the does is everything
Info
Channel: Tech With Den
Views: 3
Rating: undefined out of 5
Keywords: swagger 3 spring boot, swagger 3.0 tutorial, swagger, swagger 2, java swagger ui, swagger spring boot, swagger spring boot tutorial, swagger spring boot rest api example, java swagger tutorial, traversy media, java techie, tech with den, openapi tutorial, spring boot api documentation using swagger, spring boot api documentation, java api documentation
Id: wRNtumYSiA4
Channel Id: undefined
Length: 10min 25sec (625 seconds)
Published: Thu Jun 29 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.