{"id":112378,"date":"2021-12-29T07:00:00","date_gmt":"2021-12-29T05:00:00","guid":{"rendered":"https:\/\/www.javacodegeeks.com\/?p=112378"},"modified":"2021-12-15T17:10:23","modified_gmt":"2021-12-15T15:10:23","slug":"api-documentation-in-node-js-using-swagger","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/api-documentation-in-node-js-using-swagger.html","title":{"rendered":"API Documentation in Node.js Using Swagger"},"content":{"rendered":"<p>Hello. In this tutorial, we will understand how to write API documentation in Node.js using Swagger.<\/p>\n<h2>1. Introduction<\/h2>\n<p>A <strong>swagger<\/strong> is a popular tool used for generating interactive API documentation. In this tutorial, we will see how to write swagger api documentation in the nodejs application.<\/p>\n<h3>1.1 Setting up Node.js<\/h3>\n<p>To set up <strong>Node.js<\/strong> on windows you will need to download the installer from <a href=\"https:\/\/nodejs.org\/en\/download\/\" target=\"_blank\" rel=\"noopener\">this<\/a> link. Click on the installer (also include the NPM package manager) for your platform and run the installer to start with the Node.js setup wizard. Follow the wizard steps and click on Finish when it is done. If everything goes well you can navigate to the command prompt to verify if the installation was successful as shown in Fig. 1.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2021\/12\/node-npm-installation-img1-1.jpg\"><img decoding=\"async\" width=\"480\" height=\"91\" src=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2021\/12\/node-npm-installation-img1-1.jpg\" alt=\"API Documentation in Node.js - npm installation\" class=\"wp-image-112379\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2021\/12\/node-npm-installation-img1-1.jpg 480w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2021\/12\/node-npm-installation-img1-1-300x57.jpg 300w\" sizes=\"(max-width: 480px) 100vw, 480px\" \/><\/a><figcaption>Fig. 1: Verifying node and npm installation<\/figcaption><\/figure>\n<\/div>\n<h2>2. API Documentation in Node.js Using Swagger<\/h2>\n<p>To set up the application, we will need to navigate to a path where our project will reside. For programming stuff, I am using <a href=\"https:\/\/code.visualstudio.com\/\" target=\"_blank\" rel=\"noopener\">Visual Studio Code<\/a> as my preferred IDE. You&#8217;re free to choose the IDE of your choice.<\/p>\n<h3>2.1 Setting up the implementation<\/h3>\n<p>Let us write the different files which will be required for practical learning.<\/p>\n<h4>2.1.1 Setting up dependencies<\/h4>\n<p>Navigate to the project directory and run <code>npm init -y<\/code> to create a <code>package.json<\/code> file. This <a href=\"https:\/\/docs.npmjs.com\/creating-a-package-json-file\" target=\"_blank\" rel=\"noopener\">file<\/a> holds the metadata relevant to the project and is used for managing the project dependencies, script, version, etc. Add the following code to the file wherein we will specify the required dependencies.<\/p>\n<p><span style=\"text-decoration: underline\"><em>package.json<\/em><\/span><\/p>\n<pre class=\"brush:json;\">{\n  \"name\": \"swagger\",\n  \"version\": \"1.0.0\",\n  \"description\": \"api documentation via swagger in nodejs application\",\n  \"main\": \"index.js\",\n  \"scripts\": {\n    \"dev\": \"nodemon index.js\",\n    \"test\": \"echo \\\"Error: no test specified\\\" &amp;&amp; exit 1\"\n  },\n  \"keywords\": [\n    \"nodejs\",\n    \"expressjs\",\n    \"apidocumentation\",\n    \"swagger\"\n  ],\n  \"author\": \"javacodegeeks\",\n  \"license\": \"MIT\",\n  \"dependencies\": {\n    \"express\": \"^4.17.1\",\n    \"swagger-ui-express\": \"^4.2.0\"\n  },\n  \"devDependencies\": {\n    \"nodemon\": \"^2.0.15\"\n  }\n}\n<\/pre>\n<p>To download the dependencies navigate to the directory path containing the file and use the <code>npm install<\/code> command. If everything goes well the dependencies will be loaded inside the <code>node_modules<\/code> folder and you are good to go with the further steps.<\/p>\n<h4>2.1.2 Creating swagger.json file<\/h4>\n<p>Creating a swagger.json file in the project\u2019s root directory that will be responsible to create the description of the entire api. For this tutorial, we will be exposing two points and the entity\/dto object which will be used in response for the client.<\/p>\n<ul>\n<li>Get all users<\/li>\n<li>Get user by id<\/li>\n<\/ul>\n<p><span style=\"text-decoration: underline\"><em>swagger.json<\/em><\/span><\/p>\n<pre class=\"brush:json;\">{\n  \"swagger\": \"2.0\",\n  \"info\": {\n    \"version\": \"1.0.0\",\n    \"title\": \"API Documentation in Node.js Using Swagger\",\n    \"description\": \"User Restful webservice application\",\n    \"license\": {\n      \"name\": \"MIT\",\n      \"url\": \"https:\/\/opensource.org\/licenses\/MIT\"\n    }\n  },\n  \"basePath\": \"\/\",\n  \"tags\": [\n    {\n      \"name\": \"Users\",\n      \"description\": \"API for users\"\n    }\n  ],\n  \"produces\": [\"application\/json\"],\n  \"paths\": {\n    \"\/users\": {\n      \"get\": {\n        \"tags\": [\"Users\"],\n        \"summary\": \"Get all users\",\n        \"responses\": {\n          \"200\": {\n            \"description\": \"ok\",\n            \"schema\": {\n              \"$ref\": \"#\/definitions\/Users\"\n            }\n          }\n        }\n      }\n    },\n    \"\/user\": {\n      \"parameters\": [\n        {\n          \"name\": \"id\",\n          \"in\": \"query\",\n          \"required\": true,\n          \"description\": \"Id of the user which is to be searched\",\n          \"type\": \"integer\"\n        }\n      ],\n      \"produces\": [\"application\/json\"],\n      \"get\": {\n        \"tags\": [\"Users\"],\n        \"summary\": \"Get user by id\",\n        \"responses\": {\n          \"200\": {\n            \"description\": \"ok\",\n            \"schema\": {\n              \"$ref\": \"#\/definitions\/User\"\n            }\n          },\n          \"404\": {\n            \"description\": \"not found\"\n          }\n        }\n      }\n    }\n  },\n  \"definitions\": {\n    \"User\": {\n      \"required\": [\"name\", \"_id\", \"companies\"],\n      \"properties\": {\n        \"id\": {\n          \"type\": \"integer\",\n          \"uniqueItems\": true\n        },\n        \"name\": {\n          \"type\": \"string\"\n        },\n        \"username\": {\n          \"type\": \"string\"\n        },\n        \"email\": {\n          \"type\": \"string\"\n        },\n        \"address\": {\n          \"type\": \"object\",\n          \"properties\": {\n            \"street\": {\n              \"type\": \"string\"\n            },\n            \"suite\": {\n              \"type\": \"string\"\n            },\n            \"city\": {\n              \"type\": \"string\"\n            },\n            \"zipcode\": {\n              \"type\": \"string\"\n            }\n          }\n        },\n        \"phone\": {\n          \"type\": \"string\"\n        },\n        \"website\": {\n          \"type\": \"string\"\n        },\n        \"company\": {\n          \"type\": \"object\",\n          \"properties\": {\n            \"name\": {\n              \"type\": \"string\"\n            },\n            \"catchPhrase\": {\n              \"type\": \"string\"\n            },\n            \"bs\": {\n              \"type\": \"string\"\n            }\n          }\n        }\n      }\n    },\n    \"Users\": {\n      \"type\": \"array\",\n      \"$ref\": \"#\/definitions\/User\"\n    }\n  }\n}\n<\/pre>\n<h4>2.1.3 Creating a service class<\/h4>\n<p>Create a service file in the <code>service<\/code> folder which will be responsible to send the response to the user for the get all users endpoint and get user by id endpoint. Here we are sending the mock data but in an ideal application, this data would be fetched from the database.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p><span style=\"text-decoration: underline\"><em>user.js<\/em><\/span><\/p>\n<pre class=\"brush:js;\">const getUsers = () =&gt; {\n  return [\n    {\n      id: 1,\n      name: \"Leanne Graham\",\n      username: \"Bret\",\n      email: \"Sincere@april.biz\",\n      address: {\n        street: \"Kulas Light\",\n        suite: \"Apt. 556\",\n        city: \"Gwenborough\",\n        zipcode: \"92998-3874\"\n      },\n      phone: \"1-770-736-8031 x56442\",\n      website: \"hildegard.org\",\n      company: {\n        name: \"Romaguera-Crona\",\n        catchPhrase: \"Multi-layered client-server neural-net\",\n        bs: \"harness real-time e-markets\"\n      }\n    },\n    {\n      id: 2,\n      name: \"Ervin Howell\",\n      username: \"Antonette\",\n      email: \"Shanna@melissa.tv\",\n      address: {\n        street: \"Victor Plains\",\n        suite: \"Suite 879\",\n        city: \"Wisokyburgh\",\n        zipcode: \"90566-7771\"\n      },\n      phone: \"010-692-6593 x09125\",\n      website: \"anastasia.net\",\n      company: {\n        name: \"Deckow-Crist\",\n        catchPhrase: \"Proactive didactic contingency\",\n        bs: \"synergize scalable supply-chains\"\n      }\n    },\n    {\n      id: 3,\n      name: \"Clementine Bauch\",\n      username: \"Samantha\",\n      email: \"Nathan@yesenia.net\",\n      address: {\n        street: \"Douglas Extension\",\n        suite: \"Suite 847\",\n        city: \"McKenziehaven\",\n        zipcode: \"59590-4157\"\n      },\n      phone: \"1-463-123-4447\",\n      website: \"ramiro.info\",\n      company: {\n        name: \"Romaguera-Jacobson\",\n        catchPhrase: \"Face to face bifurcated interface\",\n        bs: \"e-enable strategic applications\"\n      }\n    },\n    {\n      id: 4,\n      name: \"Patricia Lebsack\",\n      username: \"Karianne\",\n      email: \"Julianne.OConner@kory.org\",\n      address: {\n        street: \"Hoeger Mall\",\n        suite: \"Apt. 692\",\n        city: \"South Elvis\",\n        zipcode: \"53919-4257\"\n      },\n      phone: \"493-170-9623 x156\",\n      website: \"kale.biz\",\n      company: {\n        name: \"Robel-Corkery\",\n        catchPhrase: \"Multi-tiered zero tolerance productivity\",\n        bs: \"transition cutting-edge web services\"\n      }\n    },\n    {\n      id: 5,\n      name: \"Chelsey Dietrich\",\n      username: \"Kamren\",\n      email: \"Lucio_Hettinger@annie.ca\",\n      address: {\n        street: \"Skiles Walks\",\n        suite: \"Suite 351\",\n        city: \"Roscoeview\",\n        zipcode: \"33263\"\n      },\n      phone: \"(254)954-1289\",\n      website: \"demarco.info\",\n      company: {\n        name: \"Keebler LLC\",\n        catchPhrase: \"User-centric fault-tolerant solution\",\n        bs: \"revolutionize end-to-end systems\"\n      }\n    }\n  ];\n};\n\nconst getUserById = (key) =&gt; {\n  console.log(\"Search key = \" + key);\n  const item = getUsers().filter((user) =&gt; {\n    if (user.id == key) {\n      return user;\n    }\n  });\n\n  if (item.length &gt; 0) {\n    console.log(\"User found!\");\n    return item;\n  } else {\n    return false;\n  }\n};\n\nmodule.exports = {\n  getUsers,\n  getUserById\n};\n<\/pre>\n<h4>2.1.4 Creating the index file<\/h4>\n<p>Create the file that will act as a welcome point for the application. The file will be responsible to handle the incoming request from the client and initialize the swagger configuration. During the swagger configuration initialization, it will parse the <code>swagger.json<\/code> file and will expose an <code>api-docs<\/code> endpoint.<\/p>\n<p><span style=\"text-decoration: underline\"><em>user.js<\/em><\/span><\/p>\n<pre class=\"brush:js;\">\/\/ application\nconst express = require(\"express\");\n\nconst app = express();\napp.use(express.json());\n\nconst { getUsers, getUserById } = require(\".\/service\/user\");\n\n\/\/ swagger config\nconst swaggerUi = require(\"swagger-ui-express\"),\n  swaggerDoc = require(\".\/swagger.json\");\n\n\/\/ application routes\n\n\/\/ get all users\n\/\/ endpoint = http:\/\/localhost:6001\/users\napp.get(\"\/users\", (req, res) =&gt; {\n  return res.status(200).json({\n    status: \"ok\",\n    item: getUsers()\n  });\n});\n\n\/\/ get user by id\n\/\/ endpoint = http:\/\/localhost:6001\/user?id=1\napp.get(\"\/user\", (req, res) =&gt; {\n  let id = req.query.id;\n  const user = getUserById(id);\n  if (!user) {\n    return res.status(404).json({\n      status: \"not found\",\n      message: \"resource not found\"\n    });\n  } else {\n    return res.status(200).json({\n      status: \"ok\",\n      item: user\n    });\n  }\n});\n\n\/\/ setting up swagger\n\/\/ endpoint = http:\/\/localhost:6001\/api-docs\/\napp.use(\"\/api-docs\", swaggerUi.serve, swaggerUi.setup(swaggerDoc));\n\n\/\/ start application\nconst port = process.env.PORT || 6001;\napp.listen(port, () =&gt; {\n  console.log(`Service endpoint = http:\/\/localhost:${port}`);\n});\n<\/pre>\n<h2>3. Run the Application<\/h2>\n<p>To run the application navigate to the project directory and enter the following command as shown below.<\/p>\n<p><span style=\"text-decoration: underline\"><em>Command<\/em><\/span><\/p>\n<pre class=\"brush:plain;\">$ nodemon\n<\/pre>\n<p>If everything goes well the application will be started successfully on port &#8211; <code>6001<\/code> as shown in Fig. 2.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2021\/12\/localhost-appstart-img1.jpg\"><img decoding=\"async\" width=\"601\" height=\"204\" src=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2021\/12\/localhost-appstart-img1.jpg\" alt=\"API Documentation in Node.js - app run\" class=\"wp-image-112380\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2021\/12\/localhost-appstart-img1.jpg 601w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2021\/12\/localhost-appstart-img1-300x102.jpg 300w\" sizes=\"(max-width: 601px) 100vw, 601px\" \/><\/a><figcaption>Fig. 2: Application run<\/figcaption><\/figure>\n<\/div>\n<h2>4. Demo<\/h2>\n<p>Open up the browser and hit the endpoints to confirm that the application is running fine. But in this tutorial, we have an extra thing wherein one can also check the swagger documentation generated at the below link \u2013<\/p>\n<p><span style=\"text-decoration: underline\"><em>Swagger endpoint<\/em><\/span><\/p>\n<pre class=\"brush:plain;\">http:\/\/localhost:6001\/api-docs\/\n<\/pre>\n<p>If everything goes the swagger documentation will be generated as shown in Fig. 3.<\/p>\n<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2021\/12\/swagger_documentation_img1.jpg\"><img decoding=\"async\" width=\"708\" height=\"499\" src=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2021\/12\/swagger_documentation_img1.jpg\" alt=\"API Documentation in Node.js - swagger\" class=\"wp-image-112381\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2021\/12\/swagger_documentation_img1.jpg 708w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2021\/12\/swagger_documentation_img1-300x211.jpg 300w\" sizes=\"(max-width: 708px) 100vw, 708px\" \/><\/a><figcaption>Fig. 3: Swagger documentation<\/figcaption><\/figure>\n<\/div>\n<p>That is all for this tutorial and I hope the article served you with whatever you were looking for. Happy Learning and do not forget to share!<\/p>\n<h2>5. Summary<\/h2>\n<p>In this tutorial, we saw how to set up swagger documentation in a nodejs application for the api. You can download the source code and the postman collection from the <a href=\"#projectDownload\">Downloads<\/a> section.<\/p>\n<h2><a name=\"projectDownload\"><\/a>6. Download the Project<\/h2>\n<p>This was a tutorial to set up swagger documentation in a nodejs application for the api.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>You can download the full source code of this example here: <a href=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2021\/12\/API-Documentation-in-Node.js-Using-Swagger.zip\"><strong>API Documentation in Node.js Using Swagger<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Hello. In this tutorial, we will understand how to write API documentation in Node.js using Swagger. 1. Introduction A swagger is a popular tool used for generating interactive API documentation. In this tutorial, we will see how to write swagger api documentation in the nodejs application. 1.1 Setting up Node.js To set up Node.js on &hellip;<\/p>\n","protected":false},"author":26931,"featured_media":20900,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1879],"tags":[2065,1029],"class_list":["post-112378","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript","tag-nodejs","tag-swagger"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>API Documentation in Node.js Using Swagger - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"Hello. In this tutorial, we will understand how to write API documentation in Node.js using Swagger. 1. Introduction A swagger is a popular tool used for\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/api-documentation-in-node-js-using-swagger.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"API Documentation in Node.js Using Swagger - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"Hello. In this tutorial, we will understand how to write API documentation in Node.js using Swagger. 1. Introduction A swagger is a popular tool used for\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/api-documentation-in-node-js-using-swagger.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2021-12-29T05:00:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/01\/javascript-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Yatin Batra\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Yatin Batra\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/api-documentation-in-node-js-using-swagger.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/api-documentation-in-node-js-using-swagger.html\"},\"author\":{\"name\":\"Yatin Batra\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/cda31a4c1965373fed40c8907dc09b8d\"},\"headline\":\"API Documentation in Node.js Using Swagger\",\"datePublished\":\"2021-12-29T05:00:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/api-documentation-in-node-js-using-swagger.html\"},\"wordCount\":655,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/api-documentation-in-node-js-using-swagger.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2014\\\/01\\\/javascript-logo.jpg\",\"keywords\":[\"nodejs\",\"Swagger\"],\"articleSection\":[\"JavaScript\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/api-documentation-in-node-js-using-swagger.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/api-documentation-in-node-js-using-swagger.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/api-documentation-in-node-js-using-swagger.html\",\"name\":\"API Documentation in Node.js Using Swagger - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/api-documentation-in-node-js-using-swagger.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/api-documentation-in-node-js-using-swagger.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2014\\\/01\\\/javascript-logo.jpg\",\"datePublished\":\"2021-12-29T05:00:00+00:00\",\"description\":\"Hello. In this tutorial, we will understand how to write API documentation in Node.js using Swagger. 1. Introduction A swagger is a popular tool used for\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/api-documentation-in-node-js-using-swagger.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/api-documentation-in-node-js-using-swagger.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/api-documentation-in-node-js-using-swagger.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2014\\\/01\\\/javascript-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2014\\\/01\\\/javascript-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/api-documentation-in-node-js-using-swagger.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Web Development\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/web-development\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"JavaScript\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/web-development\\\/javascript\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"API Documentation in Node.js Using Swagger\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/cda31a4c1965373fed40c8907dc09b8d\",\"name\":\"Yatin Batra\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/12\\\/Yatin.batra_.jpg\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/12\\\/Yatin.batra_.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/12\\\/Yatin.batra_.jpg\",\"caption\":\"Yatin Batra\"},\"description\":\"An experience full-stack engineer well versed with Core Java, Spring\\\/Springboot, MVC, Security, AOP, Frontend (Angular &amp; React), and cloud technologies (such as AWS, GCP, Jenkins, Docker, K8).\",\"sameAs\":[\"https:\\\/\\\/www.javacodegeeks.com\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/yatin-batra\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"API Documentation in Node.js Using Swagger - Java Code Geeks","description":"Hello. In this tutorial, we will understand how to write API documentation in Node.js using Swagger. 1. Introduction A swagger is a popular tool used for","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/api-documentation-in-node-js-using-swagger.html","og_locale":"en_US","og_type":"article","og_title":"API Documentation in Node.js Using Swagger - Java Code Geeks","og_description":"Hello. In this tutorial, we will understand how to write API documentation in Node.js using Swagger. 1. Introduction A swagger is a popular tool used for","og_url":"https:\/\/www.javacodegeeks.com\/api-documentation-in-node-js-using-swagger.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2021-12-29T05:00:00+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/01\/javascript-logo.jpg","type":"image\/jpeg"}],"author":"Yatin Batra","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Yatin Batra","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/api-documentation-in-node-js-using-swagger.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/api-documentation-in-node-js-using-swagger.html"},"author":{"name":"Yatin Batra","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/cda31a4c1965373fed40c8907dc09b8d"},"headline":"API Documentation in Node.js Using Swagger","datePublished":"2021-12-29T05:00:00+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/api-documentation-in-node-js-using-swagger.html"},"wordCount":655,"commentCount":1,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/api-documentation-in-node-js-using-swagger.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/01\/javascript-logo.jpg","keywords":["nodejs","Swagger"],"articleSection":["JavaScript"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/api-documentation-in-node-js-using-swagger.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/api-documentation-in-node-js-using-swagger.html","url":"https:\/\/www.javacodegeeks.com\/api-documentation-in-node-js-using-swagger.html","name":"API Documentation in Node.js Using Swagger - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/api-documentation-in-node-js-using-swagger.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/api-documentation-in-node-js-using-swagger.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/01\/javascript-logo.jpg","datePublished":"2021-12-29T05:00:00+00:00","description":"Hello. In this tutorial, we will understand how to write API documentation in Node.js using Swagger. 1. Introduction A swagger is a popular tool used for","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/api-documentation-in-node-js-using-swagger.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/api-documentation-in-node-js-using-swagger.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/api-documentation-in-node-js-using-swagger.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/01\/javascript-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/01\/javascript-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/api-documentation-in-node-js-using-swagger.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Web Development","item":"https:\/\/www.javacodegeeks.com\/category\/web-development"},{"@type":"ListItem","position":3,"name":"JavaScript","item":"https:\/\/www.javacodegeeks.com\/category\/web-development\/javascript"},{"@type":"ListItem","position":4,"name":"API Documentation in Node.js Using Swagger"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/cda31a4c1965373fed40c8907dc09b8d","name":"Yatin Batra","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/12\/Yatin.batra_.jpg","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/12\/Yatin.batra_.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/12\/Yatin.batra_.jpg","caption":"Yatin Batra"},"description":"An experience full-stack engineer well versed with Core Java, Spring\/Springboot, MVC, Security, AOP, Frontend (Angular &amp; React), and cloud technologies (such as AWS, GCP, Jenkins, Docker, K8).","sameAs":["https:\/\/www.javacodegeeks.com"],"url":"https:\/\/www.javacodegeeks.com\/author\/yatin-batra"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/112378","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/26931"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=112378"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/112378\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/20900"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=112378"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=112378"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=112378"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}