Use swagger codegen cli to generate Node.js server

2019-09-20 03:58发布

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

and

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:

enter image description here

What is wrong?

1条回答
唯我独甜
2楼-- · 2019-09-20 04:33

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.

查看更多
登录 后发表回答