All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.openapitools.codegen.mustache.CaseFormatLambda Maven / Gradle / Ivy

There is a newer version: 7.8.0
Show newest version
package org.openapitools.codegen.mustache;

import com.google.common.base.CaseFormat;
import com.samskivert.mustache.Mustache;
import com.samskivert.mustache.Template;
import org.openapitools.codegen.CodegenConfig;

import java.io.IOException;
import java.io.Writer;

/**
 * Converts text from CaseFormat to another CaseFormat
 *
 * Register:
 * 
 * additionalProperties.put("convert", new CaseFormatLambda(LOWER_CAMEL, UPPER_UNDERSCORE));
 * 
* * Use: *
 * {{#convert}}{{name}}{{/convert}}
 * 
*/ public class CaseFormatLambda implements Mustache.Lambda { private CodegenConfig generator = null; private CaseFormat initialFormat; private CaseFormat targetFormat; public CaseFormatLambda(CaseFormat target, CaseFormat targetFormat) { this.initialFormat = target; this.targetFormat = targetFormat; } public CaseFormatLambda generator(final CodegenConfig generator) { this.generator = generator; return this; } @Override public void execute(Template.Fragment fragment, Writer writer) throws IOException { String text = initialFormat.converterTo(targetFormat).convert(fragment.execute()); if (generator != null && generator.reservedWords().contains(text)) { text = generator.escapeReservedWord(text); } writer.write(text); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy