1

I am new to node js and swagger-ui.

I want to pass below input body to my web service using swagger-ui,

I am able to pass normal json like:

{
"username":"abc",
"password":"******"
}

but I want to give following input to my web service using swagger-ui.

{
"data":
{"username":"abc",
"password":"******"
}
}

my api-docs.json file is below:

{
  "info": {
    "title": "Node Swagger API",
    "version": "1.0.0",
    "description": "Demonstrating how to describe a RESTful API with Swagger"
  },
  "host": "localhost:5002",
  "basePath": "/",
  "swagger": "2.0",
  "paths": {

    "/login": {
      "post": {
        "description": "user login",
        "produces": [
          "application/json"
        ],
        "parameters": [
          {
            "name": "userName",
            "description": "username to get userType",
            "required": true,
            "type": "string",
            "in": "formData"
          },
          {
            "name": "password",
            "description": "password to get userType",
            "required": true,
            "type": "string",
            "in": "formData"
          }



        ],
        "responses": {
          "0": {
            "description": "Access token has been expired. Please login again."
          },
          "200": {
            "description": "Successfully returns the response"
          },
          "400": {
            "description": "Invalid input Parameters"
          },
          "401": {
            "description": "Invalid Access Token"
          },
          "404": {
            "description": "No data found"
          },
          "500": {
            "description": "Internal Server Error"
          }
        }
      }
    }
  },
  "definitions": {},
  "responses": {},
  "parameters": {},
  "securityDefinitions": {},
  "tags": []
}

So How can pass below input using swagger-ui to my web service:

{
    "data":
    {"username":"abc",
    "password":"******"
    }
    }

Any Help will be appreciable.

Thanks In Advance.

1 Answer 1

2

I always use the yml format. Try this. should work. Now you will get the details in the req.body.

{
"info": {
"title": "Node Swagger API",
"version": "1.0.0",
"description": "Demonstrating how to describe a RESTful API with Swagger"
},
"host": "localhost:5002",
"basePath": "/",
"swagger": "2.0",
"paths": {

"/login": {
"post": {
"description": "user login",
"produces": [
  "application/json"
],
"parameters": [
  {
    "name": "userDetails",
    "description": "username to get userType",
    "required": true,
    "in": "body",
    "schema": {
      "$ref": "#/definitions/User"
    }
  }
],
"responses": {
  "0": {
    "description": "Access token has been expired. Please login again."
  },
  "200": {
    "description": "Successfully returns the response"
  },
  "400": {
    "description": "Invalid input Parameters"
  },
  "401": {
    "description": "Invalid Access Token"
  },
  "404": {
    "description": "No data found"
  },
  "500": {
    "description": "Internal Server Error"
  }
}
  }
}
 },
 "definitions": {
 "User" : {
    "type":"object",
    "properties": {
      "data": {
        "type": "object",
        "properties": {
        "username": {
          "type": "string"
        },
        "password": {
          "type": "string"
        }
      }
    }
  }
 }
 },
 "responses": {},
"parameters": {},
"securityDefinitions": {},
"tags": []
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.