是否有任何工具可以从 YAML 生成 JavaScript 类?
我有一个 Swagger 的 YAML,我想生成如下所示的 javascript 模型:
'use strict';
function Product(name,description){
this.name = name;
this.description = description;
this.toString = function(){
return this.name+" : "+this.description;
}
使用 Swagger 的 YAML:
.
.
.
definitions:
product:
properties:
name:
type: string
description:
type: string
required:
- name
- description
.
.
.
最佳答案
您可以使用 Swagger Codegen生成 JS API 客户端(带有模型)、其他语言的客户端(例如 Ruby、Typescript 等)、服务器 stub (例如 NodeJS、Java Spring 等)和 API 文档。
鉴于您已经拥有 OpenAPI/Swagger 规范,您可以执行以下操作:
- 转到 https://editor.swagger.io
- 在顶部菜单中选择"file",然后选择“导入文件”以加载您的规范
- 然后在顶部菜单中选择“生成客户端”并单击“Javascript”
关于javascript - 从 YAML 生成 javascript 类/对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40977638/