Swagger 3.0.1 服务器生成器

编程入门 行业动态 更新时间:2024-10-23 07:15:35
本文介绍了Swagger 3.0.1 服务器生成器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

当我在在线工具

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

解决方案

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

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

要解决此问题:

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

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

    要解决此问题:

  • 在您生成的服务器的 index.js 文件中,将字符串 'api/openapi.yaml' 更改为 'api/swagger.yaml'
  • 可能的额外问题:

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

    ,请参阅下面的@Alex 评论
    • 此处发布了 Swagger 编辑器错误:github/swagger-api/swagger-editor/issues/2086
    • Oas3-tools 错误发布在这里:github/漏洞猎人/oas3-tools/issues/17

    When I generate a nodejs-server with swagger 3.0.1 in the online tool 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:

  • Start your generated server (this will run npm install and create the dist folder in node_modules/oas3-tools)
  • Go into ./node_modules/oas3-tools and manually copy the missing src/middleware to the dist folder.
  • 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:

  • 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 Editor bug posted here: github/swagger-api/swagger-editor/issues/2086
    • Oas3-tools bug posted here: github/bug-hunters/oas3-tools/issues/17

    更多推荐

    Swagger 3.0.1 服务器生成器

    本文发布于:2023-11-17 12:00:31,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1609933.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:生成器   服务器   Swagger

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!