Skip to content

rcsiit1/swagger-api-testing-boilerplate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 

Repository files navigation

swagger-api-testing-boilerplate

Swagger is an open source tool to test the APIs made in javascript.The api can be tested based on the paramters set in the datastore.The complete body of the response with the headers and response code is shown on the user interface.Integrating this wonderful tool helps you test and debug your apis quickly in your project.Here is the boiler plate to include in your sails project to start running with the swagger tool.

Additional Plugins

  • Swagger Generator Sails Hook - This sails hook generates swag.json file from the routes mentioned in the route.js file in the config directory.

Installation

  • Clone the git repository.

  • Keep the docs folder in assets directory of your sails project.
    assests hierarchy

  • Then change in swag.json

"host": "localhost:1337",
  "basePath": "/",
  • Add the api routes you want to test in swag.json
"paths": {  
//this the route to check api
    "/students/createStudent": {
      "post": {
        "tags": [
          "User"
        ],
        "summary": "Signup API",
        "produces": [
          "application/xml"
        ],
        // the parameters that the api uses
        "parameters": [
          {
            "name": "name",
            "in": "formData",
            "description": "Fullname",
            "required": true,
            "type": "string"
          },
          {
            "name": "roll_number",
            "in": "formData",
            "description": "roll_number",
            "type": "integer"
          },
          {
            "name": "profile_pic",
            "in": "formData",
            "description": "Profil Picture",
            "required": true,
            "type": "string"
          }
        ]
      }
    },
    "/login": {
      "post": {
        "tags": [
          "User"
        ],
        "summary": "Signin API",
        "produces": [
          "application/json"
        ],
        "parameters": [
          {
            "name": "email",
            "in": "formData",
            "description": "Email",
            "type": "string"
          },
          {
            "name": "password",
            "in": "formData",
            "description": "Password",
            "type": "string"
          }
        ]
      }
    }
  • Run your project in terminal with sails lift command.

  • Hit the following URL in your browser window http://localhost:1337/docs/


    swagger-ui

  • Enjoy testing your APIs with swagger on sails js.

  • For more details on the paramters that can be used in swag.json and to know more about Open API 3.0 specifications, please visit Swagger

About

Swagger user interface boiler plate code for sails JS

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published