为什么 swagger 不直接指向我在 yaml 文件中指定的 url?

Why swagger not direct to the url i specified in yaml file?

我正在尝试在 express 和 node 中创建一个 swagger API 文档。这是我完成的部分代码。

index.js 文件

const express = require('express');
const swaggerJSDoc = require('swagger-jsdoc');
const swaggerUi = require('swagger-ui-express');
const http = require('http')

const app = express();
http.createServer(app).listen(3001)
console.log("Listening at:// port:%s (HTTP)", 3001)

const swaggerDefinition = {
    info: {
      title: 'REST API for my App', // Title of the documentation
      version: '1.0.0', // Version of the app
      description: 'This is the REST API for my product', // short description of the app
    },
  };

  const options = {
    // import swaggerDefinitions
    swaggerDefinition,
    // path to the API docs
    apis: ['./docs/*.yaml'],
  };
  // initialize swagger-jsdoc
  const swaggerSpec = swaggerJSDoc(options);
  
  // use swagger-Ui-express for your app documentation endpoint
  app.use('/docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec));

我的 .yaml 文件

host: localhost:3016
basePath: "/productRule"
schemes:
- http
consumes: []
produces: []
paths:
  "/search":
    post:
      tags:               # Tag property
        - search            # Value of the tag
      summary: search
      produces:
      - application/json
      parameters:         # request parameters
      - in: body          # request body
        name: search
      
            # name of request, can be any name
        description: It enables a user to create an account
        required: false   # can also be true depending on user preference
        schema:           # Schema definition
          $ref: '#/definitions/search' 
      responses:          # server responses
        200:
          description: An object with user details
definitions:        # Schema defination for request body
  search:
    type: object
    properties:
      search:
        type: object
        properties:
          pageSize:
            type: string
          sortBy:
            type: string
          searchQuery:
            type: string

在这里我想在端口 3016 中调用一个 api 即 运行。 但是当我 运行 这个脚本 swagger 调用端口 3001 时,我在其中定义了 swagger 脚本,如屏幕截图所示。

你能帮我找出哪里出错了吗?

基本路径和 URL 应该在 swagger 定义中定义,否则基本路径 \ 的默认端口将被视为 api 路径。

const swaggerDefinition = {
    info: {
      title: 'REST API for my App', // Title of the documentation
      version: '1.0.0', // Version of the app
      description: 'This is the REST API for my product', // short description of the app
    },
   host: localhost:3016
   basePath: "/productRule"
  };