Swagger 3.0.1 服务器生成器 [英] Swagger 3.0.1 server generator

查看:59
本文介绍了Swagger 3.0.1 服务器生成器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在在线工具

错误:找不到模块./middleware/swagger.router"

解决方案

短期修复:您可以让它运行,直到 oas3-tools 和 Smartbear(对于此服务器生成器)的维护者修复它们各自的部分.

问题 A:oas3-tools 构建脚本没有将中间件"复制到dist"目录.

要解决此问题:

  1. 启动您生成的服务器(这将运行 npm install 并在 node_modules/oas3-tools 中创建 dist 文件夹)
  2. 进入./node_modules/oas3-tools并手动将丢失的src/middleware复制到dist文件夹.
  3. 既然您的 dist 文件夹中有一个 middleware 文件夹,请对其运行以下打字稿编译命令:tsc dist/middleware/

问题 B:

下一个问题是 swagger 文档路径上的拼写错误.

要解决此问题:

  1. 在您生成的服务器的 index.js 文件中,将字符串 'api/openapi.yaml' 更改为 'api/swagger.yaml'

可能的额外问题:

您可能需要手动转换 .ts 文件.如果您也遇到此问题(即 error TS6053: File 'dist/middleware/.ts' not found. Found 1 error)

,请参阅下面的@Alex 评论

When I generate a nodejs-server with swagger 3.0.1 in the online tool https://editor.swagger.io/ and try to npm start the project I always get the following error:

Error: Cannot find module './middleware/swagger.router'

解决方案

Short-term fix: you can get it to run until the maintainer of oas3-tools and Smartbear (for this server generator) fixes their respective parts.

PROBLEM A: oas3-tools build script isn't copying the 'middleware' over to the 'dist' directory.

To fix this:

  1. Start your generated server (this will run npm install and create the dist folder in node_modules/oas3-tools)
  2. Go into ./node_modules/oas3-tools and manually copy the missing src/middleware to the dist folder.
  3. Now that you have a middleware folder in your dist folder, run the following typescript compile command against it: tsc dist/middleware/

PROBLEM B:

The next issue is a typo on the path to the swagger document is incorrect.

To fix this:

  1. In the index.js file of your generated server, change the string 'api/openapi.yaml' to 'api/swagger.yaml'

POSSIBLE EXTRA PROBLEM:

You may need to manually transpile your .ts files. Please see @Alex's comment below if you also run into this (i.e. error TS6053: File 'dist/middleware/.ts' not found. Found 1 error)


这篇关于Swagger 3.0.1 服务器生成器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆