使用swagger codegen cli生成带有模型的Node.js服务器 [英] Use swagger codegen cli to generate Node.js server with models
问题描述
我有一个 swagger.yaml ,并且刚刚在Mac上安装了 swagger-codegen .我想从命令行生成一个包含swagger.yaml中描述的模型的Node.js服务器.我试过了:
I have a swagger.yaml and just installed the swagger-codegen on my Mac. I want to generate a Node.js server including the models described in the swagger.yaml from the command line. I tried:
java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -i swagger.yaml -l nodejs -o export/nodejs -Dmodels
和
java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -i swagger.yaml -l nodejs -o export/nodejs -Dmodels -DsupportingFiles
但是输出始终与模型相同没有:
But the output is always the same WITHOUT the models:
怎么了?
推荐答案
与早期版本的swagger-node(fka swagger-node-express)相比,swagger定义被用作事实的来源.应用程序中没有为每个模型生成模型文件.因此,-Dmodels将无效.
As opposed to previous versions of swagger-node (fka swagger-node-express), the swagger definition is used as the source of truth. There is no model file generated for each model in the application. So the -Dmodels will have no effect.
您可以生成响应有效负载并将其发送回,甚至可以配置框架以验证其是否符合定义.
You can generate the response payload and send it back, and even configure the framework to validate that it follows the definition.
这篇关于使用swagger codegen cli生成带有模型的Node.js服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!