From 07b2d899d40720aa9e0ab1528eaf8e03c73ef59b Mon Sep 17 00:00:00 2001 From: themooks Date: Tue, 27 Oct 2026 17:43:48 +0100 Subject: [PATCH 1/2] Add GoCase lambda --- .../openapitools/codegen/DefaultCodegen.java | 1 + .../templating/mustache/GocaseLambda.java | 51 +++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 modules/openapi-generator/src/main/java/org/openapitools/codegen/templating/mustache/GocaseLambda.java diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java index 48e4794eaca6..3763d93b1e5a 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java @@ -378,6 +378,7 @@ protected ImmutableMap.Builder addMustacheLambdas() { .put("uppercase", new UppercaseLambda()) .put("titlecase", new TitlecaseLambda()) .put("snakecase", new SnakecaseLambda()) + .put("gocase", new GocaseLambda()) .put("camelcase", new CamelCaseLambda(true).generator(this)) .put("pascalcase", new CamelCaseLambda(false).generator(this)) .put("indented", new IndentedLambda()) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/templating/mustache/GocaseLambda.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/templating/mustache/GocaseLambda.java new file mode 100644 index 000000000000..19b17189ae6b --- /dev/null +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/templating/mustache/GocaseLambda.java @@ -0,0 +1,51 @@ +/* + * Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech) + * Copyright 2018 SmartBear Software + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.openapitools.codegen.templating.mustache; + +import com.samskivert.mustache.Mustache; +import com.samskivert.mustache.Template; + +import java.io.IOException; +import java.io.Writer; +import java.util.Locale; + +import static org.openapitools.codegen.utils.StringUtils.underscore; + +/** + * Converts text in a fragment to snake case. + *

+ * Register: + *

+ * additionalProperties.put("gocase", new GocaseLambda());
+ * 
+ *

+ * Use: + *

+ * {{#gocase}}{{summary}}{{/gocase}}
+ * 
+ */ +public class GocaseLambda implements Mustache.Lambda { + @Override + public void execute(Template.Fragment fragment, Writer writer) throws IOException { + String text = fragment.execute().toLowerCase(Locale.ROOT); + if (!text.isEmpty()) { + text = text.substring(0, 1).toUpperCase(Locale.ROOT) + text.substring(1); + } + writer.write(text); + } +} From bb9a1081649826d57824cac86734b38080a29525 Mon Sep 17 00:00:00 2001 From: themooks Date: Wed, 28 Oct 2026 11:11:52 +0100 Subject: [PATCH 2/2] Remove unused import --- .../openapitools/codegen/templating/mustache/GocaseLambda.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/templating/mustache/GocaseLambda.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/templating/mustache/GocaseLambda.java index 19b17189ae6b..5380e809d97b 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/templating/mustache/GocaseLambda.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/templating/mustache/GocaseLambda.java @@ -24,8 +24,6 @@ import java.io.Writer; import java.util.Locale; -import static org.openapitools.codegen.utils.StringUtils.underscore; - /** * Converts text in a fragment to snake case. *