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

io.swagger.codegen.v3.generators.handlebars.ExtensionHelper Maven / Gradle / Ivy

There is a newer version: 1.0.54
Show newest version
package io.swagger.codegen.v3.generators.handlebars;

import com.github.jknack.handlebars.Helper;
import com.github.jknack.handlebars.Options;
import com.github.jknack.handlebars.Options.Buffer;
import io.swagger.codegen.v3.VendorExtendable;

import java.io.IOException;
import java.util.Map;

public abstract class ExtensionHelper implements Helper {

    public abstract String getPreffix();

    @Override
    public Object apply(VendorExtendable vendor, Options options) throws IOException {
        final Buffer buffer = options.buffer();

        if (vendor == null) {
            buffer.append(options.inverse());
            return buffer;
        }
        final String param = options.param(0);
        String extension = getPreffix() + param;

        if (!getBooleanValue(vendor, extension)) {
            buffer.append(options.inverse());
        } else {
            buffer.append(options.fn());
        }
        return buffer;
    }

    public static boolean getBooleanValue(VendorExtendable vendorExtendable, String extensionKey) {
        if (vendorExtendable == null) {
            return false;
        }
        Map vendorExtensions = vendorExtendable.getVendorExtensions();
        if (vendorExtensions.get(extensionKey) == null) {
            return false;
        }
        return Boolean.parseBoolean(vendorExtensions.get(extensionKey).toString());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy