在swagger ui中对标记和操作进行排序

yv5phkfx  于 2021-10-10  发布在  Java
关注(0)|答案(0)|浏览(294)

在我的node.js/express应用程序中,我使用swagger ui编写了文档,我想按照操作的字母顺序对标记进行排序,但它不起作用,正在设置默认顺序。如何修复?

const swaggerOptions = {
  swaggerDefinition: {
    info: {
      version: "1.0.0",
      title: "test APIs",
      description: "test API Information",
      apisSorter: "alpha",
      operationsSorter: "alpha",
      contact: {
        name: "test",
      },
      servers: ["http://localhost:3000"],
    },
  },
  operationsSorter: (a, b) => {
    var methodsOrder = [
      "get",
      "post",
      "put",
      "patch",
      "delete",
      "options",
      "trace",
    ];
    var result =
      methodsOrder.indexOf(a.get("method")) -
      methodsOrder.indexOf(b.get("method"));

    if (result === 0) {
      result = a.get("path").localeCompare(b.get("path"));
    }

    return result;
  },
  // ['.routes/*.js']
  apis: ["app.js", "./routes/*.js"],
};

const swaggerDocs = swaggerJsDoc(swaggerOptions);
app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerDocs));

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题