Hi everyone.
In this video let me show you how we can do the swagger UI.
Okay?
Right here inside the post and create a post, we have something called example value okay.
Right now we don't have any idea about what's inside the value right here.
And for that reason I will show you how we can do that over the open APIs and click on Type and Parameters
okay and reading the topic right here.
Now you can see inside the DTO we will add something called @ApiProperty okay.
So let use that.
I will copy the @ApiProperty here and go back.
And I will go to DTO.
And import that and use the @ApiProperty right here.
So now if I refresh, let's see and let wait a bit to restart the server.
Now you can see. In the post, we already have something called title and description with a string.
Right.
Now I will show you how we can customize the string right here.
We can scroll down and we can provide a description right here.
Okay.
And the default
Let me try to copy everything and open the API property.
paste it
And we will use description.
The title of description.
Uh, sorry.
The title of post, okay
Minimum and default.
And let me refresh to see, right here you can see.
The title will be one, right?
So for that reason easily found here, we can change that.
We can change.
So for example: "title 1"
If I refresh again.
And let wait a bit to server restart.
And you can see it has something like this.
If I click on check out and you can see like we can customize this and send a request.
Right.
Let me custom. I think I don't need the minimum.
In here copy and replace with description right here I will name the description post.
Or actually if you don't want you can try to remove this okay.
Maybe if you lazy, you can remove that.
And right here I will description one for example.
Let me refresh again.
Now you can see it already changed right now.
And I want notice about some notes for you.
Now when you create a DTO when you create a new DTO.
Make sure we add the @ApiProperty in the beginning okay.
Don't try to create 100 DTOS.
And afterwards go back and add it one by one okay.
It's a little bit silly right?
So for that reason, if you want use the swagger at the beginning of the project, you must put it right
at the beginning.
Okay.
But I think in the next project I will not use swagger because I.
I like using the postman rather than the swagger
Okay, so but anyway, you can try to do that.
And the one more reason in the next video I will not show, because it will take a little bit of time
for me to add something like @ApiProperty and something like API description and default.
Right.
So for that reason, I will not do that in the next video in the next project.
But if you want, you can feel free to do that.
And let me show you one more thing will be the the tag.
Okay.
When.
We use the
When we use the swagger UI, it will auto generate for you the the tags.
Okay.
This here will be called the tags.
Now, for example, if you want to rename the tags you can feel free to do that.
Click on operations right here.
And now you can see it will mark the controller with the @ApiTags right here.
Let me try to copy that and I will open the post.
Open the post right here.
I will close everything.
And inside the post I will create a post.
I will go to the post controller and paste it directly right here.
Okay.
If I use the "cats" right here, let's see what happens if I refresh now you can see it rename for me,
right.
Renamed from the posts to the "cats".
Right here.
I pass
The boss for example like this
Now it will have a posts, right?
And let me change the name to.
From the user to users.
Right here.
The default
default
It will use the entity I think.
But let me rename it to the users.
Refresh
Okay.
It already renamed.
And that is.
So now let me try to open the @Put right here.
And sorry here I will @Get
It will have some {id} like that, right
You can try to do that if I try to create, for example, with this here I will excute.
And now you can see, we already have status code and some ID right here and description.
Right.
Let me copy.
And if I go back here I will click on try out and paste the ID and excute, it say not found
Hmm
Let me try to get all the posts.
Let me copy here.
Copy the URL and here excute.
I don't know why it's not found
Maybe I make some wrong
But if I look at the real database, I think it must work.
Okay, you can try to open a new database.
And we also have a @Put. If I open the @Put
You can see in the PUT we doesn't have any example value right.
So the reason because if I open the DTO and open the UpdatePostPatchDTO, we have a PartialType
Okay.
The PartialType will not work in this case for that reason.
Sorry, I think this here
So if you open the Patch it work right.
It work because in the PartialType, we already import it from swagger
Okay.
For that reason, with the PartialType from swagger, it will inherit form for you.
And we also have the Delete one
Okay.
You can try a little bit with that.
So?
I think that's enough, right.
You can customize something called header if you want.
And for example API response if you want.
Okay let's read the document.
And with file upload, you can try to do that. The file upload using the @ApiConsume
with the mutipart/form-data.
And you do something like that.
Now let's look at the documentation and see and apply them into real project if you want.
Okay so I will see you in the next one.