我正在寻找一种从Swagger架构生成简单TypeScript接口的方法.我发现的大多数解决方案都是不必要的复杂.
我想生成这样的接口:
export interface IBar {
a?: string;
b: number;
c: Date;
baz?: IBaz;
}
export interface IBaz {
d: number;
color: Color;
}
export enum Color {
RED = 0,
GREEN = 1,
BLUE = 2,
}
Run Code Online (Sandbox Code Playgroud)
从这样的架构:
{
"x-generator": "NSwag v11.14.0.0 (NJsonSchema v9.10.24.0 (Newtonsoft.Json v9.0.0.0))",
"swagger": "2.0",
"info": {
"title": "",
"version": ""
},
"schemes": [],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"paths": {
"/api/Foo/GetBarDescriptions": {
"get": {
"tags": [
"Foo"
],
"operationId": "Foo_GetBarDescriptions",
"parameters": [], …Run Code Online (Sandbox Code Playgroud) 我是用TypeScipt编写的项目的一部分,我正在尝试添加与Swagger兼容的TypeScript Web Server.
考虑到易维护性,实施它的最基本策略是什么.
对于Typescript,我注意到存在'Typson'库,用于从TypeScript接口生成JSON模型.
对于Swagger,我尝试使用'swagger-node-restify'库,因为它支持添加JSON模型swagger.
但是,我遇到了一些问题:
import {Server} from "restify")的typeScript 语法{"apiVersion":"0.1","swaggerVersion":"1.1","basePath":"http://localhost:8080","apis":[{"path":"/api-docs.{format}/pet","description":"none"}]}