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

JavaClientCli.api.mustache Maven / Gradle / Ivy

Go to download

This artefact generates other artefacts such as API client, API server out of API Model

There is a newer version: 1.1.1
Show newest version
{{>licenseInfo}}
package {{package}};

import au.org.consumerdatastandards.client.api.*;
import au.org.consumerdatastandards.client.cli.support.*;
import au.org.consumerdatastandards.client.model.*;
import au.org.consumerdatastandards.conformance.*;
import au.org.consumerdatastandards.support.ResponseCode;
{{#imports}}
import {{import}};
{{/imports}}
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.shell.standard.ShellCommandGroup;
import org.springframework.shell.standard.ShellComponent;
import org.springframework.shell.standard.ShellMethod;
import org.springframework.shell.standard.ShellOption;
import java.util.List;

{{#operations}}
@ShellComponent
@ShellCommandGroup("{{classname}}")
public class {{classname}} extends ApiCliBase {

    private static final Logger LOGGER = LoggerFactory.getLogger({{classname}}.class);

    @Autowired
    ApiClientOptions apiClientOptions;

    private PayloadValidator payloadValidator = new PayloadValidator();
    private final {{classname}}API api = new {{classname}}API();
    {{#operation}}

    @ShellMethod("{{operationDesc}}")
    public String {{operationId}}(@ShellOption(defaultValue = ShellOption.NULL) Boolean check{{#nonHeaderParams}},
        @ShellOption(defaultValue = ShellOption.NULL) {{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}} {{paramName}}{{/nonHeaderParams}}) throws Exception {

        LOGGER.info("{{operationDesc}} CLI initiated{{#hasNonHeaderParams}} with {{#nonHeaderParams}}{{baseName}}: {{openBracket}}{{closeBracket}}{{^-last}}, {{last}}{{/-last}}{{/nonHeaderParams}}",{{#nonHeaderParams}}
            {{paramName}}{{^-last}},{{/-last}}{{/nonHeaderParams}}{{/hasNonHeaderParams}}{{^hasNonHeaderParams}}"{{/hasNonHeaderParams}});

        if (apiClientOptions.getUserAgent() != null) {
            LOGGER.info("User agent specified as {}", apiClientOptions.getUserAgent());
        }
        api.setApiClient(ApiUtil.createApiClient(apiClientOptions));

        {{{returnType}}} response = api.{{operationId}}({{#nonHeaderParams}}{{paramName}}{{^-last}}, {{/-last}}{{/nonHeaderParams}});
        if (apiClientOptions.isValidationEnabled() || (check != null && check)) {
            LOGGER.info("Payload validation is enabled");
            okhttp3.Call call = api.{{operationId}}Call({{#nonHeaderParams}}{{paramName}}, {{/nonHeaderParams}}null);
            List conformanceErrors = payloadValidator
                .validateResponse(call.request().url().toString(), response, "{{operationId}}", ResponseCode.OK);
            if (!conformanceErrors.isEmpty()) {
                throwConformanceErrors(conformanceErrors);
            }
        }
        return JsonPrinter.toJson(response);
    }
    {{/operation}}
}
{{/operations}}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy