Please see the swagger-output.json. In a response section of this json you will see error code with description as well . So to keep error documentation’s you need to handle all the errors explicitly in your api route with error code and description. And you will start seeing the same on swagger UI. I have covered 500 error code .
in my swagger-output.json it is like "201":{ "description":"Created" }, I need the Description as "User Registred Successfully" back-end code is this export const register = async (req, res) => { try { // Destructuring const { name, password, email } = req.body; // Validating input if (!name || !password || !email) { return res .status(400) .json({ message: "Please provide name, password, and email" }); } // Checking if user already exists const existUser = await User.findOne({ email: email }); if (existUser) { return res .status(409) .json({ message: "User already exists. Please Login" }); } // Hashing the password only when user exists const salt = await bcrypt.genSalt(10); const hashPassword = await bcrypt.hash(password, salt); // Creating new User const user = new User({ name, email, password:hashPassword, }); // Save the user to the database const userRegistered = await user .save() .then(console.log("user registered")); // if any error in registration if (!userRegistered) { res .status(500) .json({ message: "Something went wrong Please Try Again" }); } // New User created Successfully res.status(201).json({ message: "User Registred Successfully" }); } catch (error) { console.log(error.message); } }; @@proguru_gyan
Hi, can you help me with my swagger integration? i have integrated swagger using your tutorial and now the swagger ui is generating successfully but the parameters of any routes are not getting generated. How to fix this?
Bhaiya agar mera backend Typescript par bana hua he toh yahi same procedure rahega kya ? Ya phir swagger ke kuch types hote h jo install karne padh the h ?
Hi. Go with type packages as well npm install ts-node swagger-autogen swagger-ui-express express @types/express @types/swagger-ui-express I will create separate session for typescript as well . Thanks
Thank you Sir💌
great help. thanks.
Sir now we need to fill the response message in that documentation ? After getting the documentation with error code !
Please see the swagger-output.json. In a response section of this json you will see error code with description as well . So to keep error documentation’s you need to handle all the errors explicitly in your api route with error code and description. And you will start seeing the same on swagger UI. I have covered 500 error code .
in my swagger-output.json it is like "201":{
"description":"Created"
},
I need the Description as "User Registred Successfully"
back-end code is this
export const register = async (req, res) => {
try {
// Destructuring
const { name, password, email } = req.body;
// Validating input
if (!name || !password || !email) {
return res
.status(400)
.json({ message: "Please provide name, password, and email" });
}
// Checking if user already exists
const existUser = await User.findOne({ email: email });
if (existUser) {
return res
.status(409)
.json({ message: "User already exists. Please Login" });
}
// Hashing the password only when user exists
const salt = await bcrypt.genSalt(10);
const hashPassword = await bcrypt.hash(password, salt);
// Creating new User
const user = new User({
name,
email,
password:hashPassword,
});
// Save the user to the database
const userRegistered = await user
.save()
.then(console.log("user registered"));
// if any error in registration
if (!userRegistered) {
res
.status(500)
.json({ message: "Something went wrong Please Try Again" });
}
// New User created Successfully
res.status(201).json({ message: "User Registred Successfully" });
} catch (error) {
console.log(error.message);
}
};
@@proguru_gyan
good effort , and explaination is also smoth easy to understand as well as implement , thanks! man
Thanks 🙏
Good efforts bro and try to record videos with more clearity voice then i think you will get more subscribers
Hi, can you help me with my swagger integration? i have integrated swagger using your tutorial and now the swagger ui is generating successfully but the parameters of any routes are not getting generated. How to fix this?
same bro , if i am using controller in the same route file , parameter's will reflect but when on another file it is not reflecting
Bhaiya agar mera backend Typescript par bana hua he toh yahi same procedure rahega kya ? Ya phir swagger ke kuch types hote h jo install karne padh the h ?
Hi. Go with type packages as well npm install ts-node swagger-autogen swagger-ui-express express @types/express @types/swagger-ui-express
I will create separate session for typescript as well . Thanks
@@proguru_gyan Thanks so much.
nice
😊😊