如何通过Swagger将参数传递给Express / Node中的req.body?

时间:2018-04-20 10:37:43

标签: swagger

<html>
 <body>
  <iframe src="http://www.youtube.com/embed/YOUR-YOUTUBE_VIDEO_CODE"
   width="560" height="315" frameborder="0" allowfullscreen></iframe>
 </body>
</html>

上面你可以看到我的swagger.json路线(作为我的代码的一个例子)。我需要找出如何在req.body中发送值(通过使用swagger)。我看到我们可以在 "/auth/sign-in": { "post": { "summary": "Sign-in on the site.", "description": "You can sign in on the site by using login and password.", "parameters": [ { "in": "query", "name": "email", "description": "You should pass here email", "required": true, "schema": { "type": "string" } }, { "in": "query", "name": "password", "description": "You should pass here password", "required": true, "schema": { "type": "string" } } ], "responses": { "200": { "description": "Here you will get token", "example": { "token": "token" } }, 中传递参数(直接链接,我们也可以在pathcookieheader中传递

query

我需要帮助创建此对象以便以下一种方式获取参数电子邮件( { "in": "query", "name": "email", "description": "You should pass here email", "required": true, "schema": { "type": "string" } } )。我该怎么做?

3 个答案:

答案 0 :(得分:1)

elyas-bhy对我帮助很大。我会给你更多关于这个答案的信息。

typedef unsigned __int64 u64;

auto toolbarGL::Slide() -> void
{
    LARGE_INTEGER li = {};
    QueryPerformanceFrequency(&li);
    u64 freq = static_cast<u64>(li.QuadPart); // clock ticks per second
    u64 period = 60;  // fps
    u64 delay = freq / period;    // clock ticks between frame paints

    u64 start = 0, now = 0;
    QueryPerformanceCounter(&li);
    start = static_cast<u64>(li.QuadPart);

    while (true)
    {
        // Waits to be ready to slide
        // Keeps looping till stopped then starts to wait again
        SlideEvent.wait();

        QueryPerformanceCounter(&li);
        now = static_cast<u64>(li.QuadPart);
        if (now - start >= delay)
        {
            if (slideDir == SlideFlag::Right)
            {
                if (this->x < 0)
                {
                    this->x += 5;
                    this->controller->Paint();
                }
                else
                    SlideEvent.stop();
            }
            else if (slideDir == SlideFlag::Left)
            {
                if (this->x > -90)
                {
                    this->x -= 5;
                    this->controller->Paint();
                }
                else
                    SlideEvent.stop();
            }
            else
                SlideEvent.stop();

            start = now;
        }

    }
}

它看起来像这样:

get the image

希望别人能提供帮助

答案 1 :(得分:0)

如果您使用的是OpenAPI 2.0:

{
  "in": "body",
  "name": "body",
  "description": "Resource payload",
  "required": true,
  "schema": {
    "type": "object",
    "properties": {
      "email": {
        "type": "string"
      }
    },
    "required": ["email"]
  }
}

来源:https://swagger.io/docs/specification/2-0/describing-request-body/

答案 2 :(得分:0)

/**
 * @swagger
 *    produces:
 *      - "application/xml"
 *      - "application/json"
 *    parameters:
 *      - name: level_id
 *        in: path
 *        required: true
 *      - name: body
 *        description: Please enter an email here
 *        in: body
 *        required: true
 *        schema:
 *          $ref: '#/definitions/levels'
 *    responses:
 *      201:
 *        description: updated
 *      404:
 *        description: Not found
 *      500:
 *        description: Internal Server error
 */