在 TypeScript 中创建 swagger web 服务的正确方法是什么 [英] what is the proper way to create a swagger web service in TypeScript

查看:31
本文介绍了在 TypeScript 中创建 swagger web 服务的正确方法是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我参与了一个用 TypeScipt 编写的项目,我正在尝试添加与 Swagger 兼容的 TypeScript Web Server.
考虑到易维护性,实现它的最基本策略是什么.

I am part of a project written in TypeScipt and I am trying to add TypeScript Web Server which will be compatible with Swagger.
What is the most basic strategy to implement it, considering easy maintainability.

  • 对于 Typescript,我注意到存在用于从 TypeScript 接口生成 JSON 模型的Typson"库.

  • For Typescript I have notice that exists 'Typson' library for generating a JSON Model from TypeScript Interface.

对于 Swagger,我尝试使用 'swagger-node-restify' 库,因为它支持将 JSON 模型添加到 swagger.

For Swagger, I have tried using 'swagger-node-restify' library, since it supports adding JSON models to swagger.

但是,我遇到了一些问题:

However, I encounter some problems:

  1. Typson 不支持 typeScript 导入的语法 -(从restify"导入{Server})
  2. 我尝试实现 'swagger-node-restify' 示例(Pet 示例),但是 localhost:8080/api-docs.json GET 请求的响应缺少 API 的所有 SPEC 数据.{"apiVersion":"0.1","swaggerVersion":"1.1","basePath":"http://localhost:8080","apis":[{"path":"/api-docs.{format}/pet","description":"none"}]}

推荐答案

我建议使用 yamljson 描述一个 Swagger 兼容 API并从中生成服务器.

I suggest to describe a Swagger compliant API using yaml or json and to generate the server from that.

swagger-server 可以在 express 之上构建 API实时(无源代码生成).

swagger-server can build APIs on top of express in real time (no source code generation).

JavaScript 代码生成器:

There are JavaScript code generators :

  • 使用 -l nodejs-server

swagger-node 是一个不错的选择,但似乎很难与TypeScript

swagger-node is a great alternative but seems hard to integrate with TypeScript

这篇关于在 TypeScript 中创建 swagger web 服务的正确方法是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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