Node.js API Documentation Made Easy with Swagger | Complete Tutorial

Поділитися
Вставка
  • Опубліковано 2 січ 2025

КОМЕНТАРІ • 15

  • @minhaj99466
    @minhaj99466 10 місяців тому +2

    Thank you Sir💌

  • @bhanuchowhan6312
    @bhanuchowhan6312 17 днів тому

    great help. thanks.

  • @minhaj99466
    @minhaj99466 10 місяців тому +1

    Sir now we need to fill the response message in that documentation ? After getting the documentation with error code !

    • @proguru_gyan
      @proguru_gyan  10 місяців тому

      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 .

    • @minhaj99466
      @minhaj99466 10 місяців тому

      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

  • @kirtanraval3672
    @kirtanraval3672 6 місяців тому +1

    good effort , and explaination is also smoth easy to understand as well as implement , thanks! man

  • @NaeemRaza-z8m
    @NaeemRaza-z8m 5 місяців тому +1

    Good efforts bro and try to record videos with more clearity voice then i think you will get more subscribers

  • @sidheartx
    @sidheartx 6 місяців тому

    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?

    • @LadduGopal-jw8rk
      @LadduGopal-jw8rk 3 місяці тому

      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

  • @UditNagar-of5su
    @UditNagar-of5su 3 місяці тому

    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 ?

    • @proguru_gyan
      @proguru_gyan  3 місяці тому +1

      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

    • @UditNagar-of5su
      @UditNagar-of5su 3 місяці тому

      @@proguru_gyan Thanks so much.

  • @ankitsain-m5r
    @ankitsain-m5r 8 місяців тому +1

    nice

  • @vishalgarna12
    @vishalgarna12 4 місяці тому

    😊😊