Search in sources :

Example 1 with HttpVerb

use of com.spectralogic.ds3autogen.api.models.enums.HttpVerb in project ds3_autogen by SpectraLogic.

the class GoTestCodeUtil method generateCode.

/**
     * Generates the Go code associated with an input file containing a contract.
     */
public void generateCode(final FileUtils fileUtils, final String inputFileName) throws IOException, TemplateModelException {
    final Ds3SpecParser parser = new Ds3SpecParserImpl();
    final Ds3ApiSpec spec = parser.getSpec(GoTestCodeUtil.class.getResourceAsStream(inputFileName));
    final CodeGenerator codeGenerator = new GoCodeGenerator();
    final Ds3DocSpec docSpec = new Ds3DocSpecEmptyImpl();
    // Generate the Go Code from the input file
    codeGenerator.generate(spec, fileUtils, Paths.get("."), docSpec);
    // Capture the generated command files
    requestCode = new String(requestOutputStream.toByteArray());
    responseCode = new String(responseOutputStream.toByteArray());
    // Capture the generate response payload type if one exists
    if (typeOutputStream != null) {
        typeCode = new String(typeOutputStream.toByteArray());
    }
    // Capture the generated client files and associate them with the HttpVerb of
    // the commands contained within the file
    final ImmutableMap.Builder<HttpVerb, String> builder = ImmutableMap.builder();
    for (final Map.Entry<HttpVerb, ByteArrayOutputStream> entry : clientOutputStreams.entrySet()) {
        builder.put(entry.getKey(), new String(entry.getValue().toByteArray()));
    }
    clientCode = builder.build();
}
Also used : Ds3SpecParser(com.spectralogic.ds3autogen.api.Ds3SpecParser) Ds3DocSpec(com.spectralogic.ds3autogen.api.models.docspec.Ds3DocSpec) Ds3SpecParserImpl(com.spectralogic.ds3autogen.Ds3SpecParserImpl) CodeGenerator(com.spectralogic.ds3autogen.api.CodeGenerator) GoCodeGenerator(com.spectralogic.ds3autogen.go.GoCodeGenerator) HttpVerb(com.spectralogic.ds3autogen.api.models.enums.HttpVerb) ByteArrayOutputStream(java.io.ByteArrayOutputStream) GoCodeGenerator(com.spectralogic.ds3autogen.go.GoCodeGenerator) ImmutableMap(com.google.common.collect.ImmutableMap) Ds3ApiSpec(com.spectralogic.ds3autogen.api.models.apispec.Ds3ApiSpec) Ds3DocSpecEmptyImpl(com.spectralogic.ds3autogen.docspec.Ds3DocSpecEmptyImpl) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map)

Example 2 with HttpVerb

use of com.spectralogic.ds3autogen.api.models.enums.HttpVerb in project ds3_autogen by SpectraLogic.

the class GoCodeGenerator method generateClient.

/**
     * Generates the client files. Each file contains the client commands separated by {@link HttpVerb}
     */
private void generateClient(final ImmutableList<Ds3Request> ds3Requests) throws IOException, TemplateException {
    for (final HttpVerb httpVerb : HttpVerb.values()) {
        final ImmutableList<Ds3Request> filteredRequests = ds3Requests.stream().filter(ds3Request -> ds3Request.getHttpVerb() == httpVerb).collect(GuavaCollectors.immutableList());
        generateClientFile(filteredRequests, httpVerb);
    }
}
Also used : Client(com.spectralogic.ds3autogen.go.models.client.Client) ConverterUtil.isEnum(com.spectralogic.ds3autogen.utils.ConverterUtil.isEnum) GetObjectResponseGenerator(com.spectralogic.ds3autogen.go.generators.response.GetObjectResponseGenerator) ResponseModelGenerator(com.spectralogic.ds3autogen.go.generators.response.ResponseModelGenerator) Ds3RequestClassificationUtil(com.spectralogic.ds3autogen.utils.Ds3RequestClassificationUtil) TypeModelGenerator(com.spectralogic.ds3autogen.go.generators.type.TypeModelGenerator) LoggerFactory(org.slf4j.LoggerFactory) NoResponseGenerator(com.spectralogic.ds3autogen.go.generators.response.NoResponseGenerator) BaseTypeGenerator(com.spectralogic.ds3autogen.go.generators.type.BaseTypeGenerator) Type(com.spectralogic.ds3autogen.go.models.type.Type) Response(com.spectralogic.ds3autogen.go.models.response.Response) StringUtils.uncapitalize(org.apache.commons.lang3.StringUtils.uncapitalize) ResponsePayloadUtil.hasResponsePayload(com.spectralogic.ds3autogen.utils.ResponsePayloadUtil.hasResponsePayload) ConverterUtil.removeUnusedTypes(com.spectralogic.ds3autogen.utils.ConverterUtil.removeUnusedTypes) CodeGenerator(com.spectralogic.ds3autogen.api.CodeGenerator) Ds3Request(com.spectralogic.ds3autogen.api.models.apispec.Ds3Request) BaseClientGenerator(com.spectralogic.ds3autogen.go.generators.client.BaseClientGenerator) ImmutableList(com.google.common.collect.ImmutableList) Request(com.spectralogic.ds3autogen.go.models.request.Request) Ds3Type(com.spectralogic.ds3autogen.api.models.apispec.Ds3Type) Ds3DocSpec(com.spectralogic.ds3autogen.api.models.docspec.Ds3DocSpec) OutputStreamWriter(java.io.OutputStreamWriter) com.spectralogic.ds3autogen.go.generators.request(com.spectralogic.ds3autogen.go.generators.request) Path(java.nio.file.Path) FileUtils(com.spectralogic.ds3autogen.api.FileUtils) OutputStream(java.io.OutputStream) Logger(org.slf4j.Logger) ImmutableMap(com.google.common.collect.ImmutableMap) BaseResponseGenerator(com.spectralogic.ds3autogen.go.generators.response.BaseResponseGenerator) IOException(java.io.IOException) Ds3ApiSpec(com.spectralogic.ds3autogen.api.models.apispec.Ds3ApiSpec) freemarker.template(freemarker.template) ClientModelGenerator(com.spectralogic.ds3autogen.go.generators.client.ClientModelGenerator) ConverterUtil.isEmpty(com.spectralogic.ds3autogen.utils.ConverterUtil.isEmpty) GuavaCollectors(com.spectralogic.ds3autogen.utils.collections.GuavaCollectors) Paths(java.nio.file.Paths) Writer(java.io.Writer) Ds3TypeClassificationUtil.isJobsApiBean(com.spectralogic.ds3autogen.utils.Ds3TypeClassificationUtil.isJobsApiBean) HttpVerb(com.spectralogic.ds3autogen.api.models.enums.HttpVerb) JobListGenerator(com.spectralogic.ds3autogen.go.generators.type.JobListGenerator) Ds3Request(com.spectralogic.ds3autogen.api.models.apispec.Ds3Request) HttpVerb(com.spectralogic.ds3autogen.api.models.enums.HttpVerb)

Example 3 with HttpVerb

use of com.spectralogic.ds3autogen.api.models.enums.HttpVerb in project ds3_autogen by SpectraLogic.

the class GoTestCodeUtil method setupClientStreams.

/**
     * Sets up output streams to capture all of the generated clients
     */
private static ImmutableMap<HttpVerb, ByteArrayOutputStream> setupClientStreams(final FileUtils fileUtils) throws IOException {
    final ImmutableMap.Builder<HttpVerb, ByteArrayOutputStream> builder = ImmutableMap.builder();
    for (final HttpVerb httpVerb : HttpVerb.values()) {
        final String name = GoCodeGenerator.getClientFileName(httpVerb);
        builder.put(httpVerb, setupOutputStream(fileUtils, BASE_PATH + name + ".go"));
    }
    return builder.build();
}
Also used : HttpVerb(com.spectralogic.ds3autogen.api.models.enums.HttpVerb) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)3 HttpVerb (com.spectralogic.ds3autogen.api.models.enums.HttpVerb)3 CodeGenerator (com.spectralogic.ds3autogen.api.CodeGenerator)2 Ds3ApiSpec (com.spectralogic.ds3autogen.api.models.apispec.Ds3ApiSpec)2 Ds3DocSpec (com.spectralogic.ds3autogen.api.models.docspec.Ds3DocSpec)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 ImmutableList (com.google.common.collect.ImmutableList)1 Ds3SpecParserImpl (com.spectralogic.ds3autogen.Ds3SpecParserImpl)1 Ds3SpecParser (com.spectralogic.ds3autogen.api.Ds3SpecParser)1 FileUtils (com.spectralogic.ds3autogen.api.FileUtils)1 Ds3Request (com.spectralogic.ds3autogen.api.models.apispec.Ds3Request)1 Ds3Type (com.spectralogic.ds3autogen.api.models.apispec.Ds3Type)1 Ds3DocSpecEmptyImpl (com.spectralogic.ds3autogen.docspec.Ds3DocSpecEmptyImpl)1 GoCodeGenerator (com.spectralogic.ds3autogen.go.GoCodeGenerator)1 BaseClientGenerator (com.spectralogic.ds3autogen.go.generators.client.BaseClientGenerator)1 ClientModelGenerator (com.spectralogic.ds3autogen.go.generators.client.ClientModelGenerator)1 com.spectralogic.ds3autogen.go.generators.request (com.spectralogic.ds3autogen.go.generators.request)1 BaseResponseGenerator (com.spectralogic.ds3autogen.go.generators.response.BaseResponseGenerator)1 GetObjectResponseGenerator (com.spectralogic.ds3autogen.go.generators.response.GetObjectResponseGenerator)1 NoResponseGenerator (com.spectralogic.ds3autogen.go.generators.response.NoResponseGenerator)1