java - mustache :如何将第一个字母小写

标签 java mustache swagger-codegen

我正在使用 mustache 模板以使用 Java 生成一些代码。

我想将字段的第一个字母小写。

有什么办法可以得到吗?

我需要直接转换它。我正在生成 C# 代码。

编辑

我正在使用 Swagger Codegen tool以便能够根据 API 规范生成客户端。

此工具使用 mustache 模板生成输出。因此,您需要的每种语言都有一个模板。参见 here , 为了观看 Swagger Codegen 提供的 mustache 模板。

我正在修改这些以自定义我想要访问的 C# 代码。

{{#apiInfo}}
{{#apis}}
    this.{{classname}} = new {{apiPackage}}.{{classname}}(this.Configuration);
{{/apis}}
{{/apiInfo}}

它必须生成如下内容:

this.UserAPI = new Api.UserAPI(this.Configuration);

我想得到:

this.userAPI = new Api.UserAPI(this.Configuration);

最佳答案

由于该问题特定于 swagger codegen 工具,因此他们具有用于 mustache 的 lambda 函数。

{{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}

尝试:

this.{{#lambda.camelcase_param}}{{classname}}{{/lambda.camelcase_param}} = new {{apiPackage}}.{{classname}}(this.Configuration);

在模板中查找示例: https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/resources/csharp/modelGeneric.mustache

关于java - mustache :如何将第一个字母小写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40106188/

相关文章:

java - 生成 Swagger API 的最佳方式?即 codegen 与 swagger 编辑器(Spring Boot API)

java - 如何在 jackson 反序列化过程中忽略 json 数组的类型信息?

java - Eclipse OpenNLP Java API

backbone.js - 防止 Mustache 从缓存中加载模板

javascript - mustache JS : JS not working on mustache's products?

swagger - 如何为 OpenAPI 3.0.0 运行 swagger-codegen

java - Apache CXF - JAX-RS 安全

java - 为什么这是 `hashCode()` 的一个很好的实现

javascript - mustache + 嵌套对象

java - 如何覆盖默认的 swagger-code-gen 服务实现?