如何在swagger codegen中生成构造函数? [英] How to generate constructors in swagger codegen?

查看:562
本文介绍了如何在swagger codegen中生成构造函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

codegen没有生成任何构造函数。
我提到了petstore swagger文件,使用了最新的swagger codegen jar文件。

The codegen did not generate any constructor. I referred to petstore swagger file, used latest swagger codegen jar file.

但是只生成了默认构造函数。

But only default constructor was generated.

它不会根据其字段生成构造函数。

It is not generating constructor based on its fields.

如何启用它?

推荐答案

如果你真的需要一个带参数的构造函数,你可以通过修改以.moustache结尾的模板文件来实现。

If you really need a constructor with parameters you can do so by modifying the template file(s) that end with .moustache.

启用/使用/修改模板

我将假设您将编辑现有模板,并希望每个模型都有构造函数。

I'm going to assume you're going to be editing an existing template and want a constructor for each model.

以下是模型模板文件中构造函数的一个简单示例:

Here is a simple example of a constructor inside the model template file:

public {{classname}}( {{#vars}} {{datatype}} {{baseName}}{{^-last}},{{/-last}} {{#-last}}){
construct code here
}{{/-last}}{{/vars}}

请注意,这应该介于{{#model}} {{/ model}}代码

note that this should go between the {{#model}} {{/model}} tags

有关胡子模板的更多信息,请参阅

for more information about the moustache templates refer to

https://mustache.github.io/mustache.5.html

模板变量列表

codegen的模板示例

这篇关于如何在swagger codegen中生成构造函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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