Search in sources :

Example 1 with CodeGenerator

use of com.spectralogic.ds3autogen.api.CodeGenerator 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 CodeGenerator

use of com.spectralogic.ds3autogen.api.CodeGenerator in project ds3_autogen by SpectraLogic.

the class JavaFunctionalTests method wholeXmlDoc.

@Test
public void wholeXmlDoc() throws IOException, TemplateModelException {
    final FileUtils fileUtils = new TestFileUtilsImpl();
    final Ds3SpecParser parser = new Ds3SpecParserImpl();
    final Ds3ApiSpec spec = parser.getSpec(JavaFunctionalTests.class.getResourceAsStream("/input/fullXml.xml"));
    final CodeGenerator codeGenerator = new JavaCodeGenerator();
    codeGenerator.generate(spec, fileUtils, Paths.get("."), new Ds3DocSpecEmptyImpl());
}
Also used : TestFileUtilsImpl(com.spectralogic.ds3autogen.utils.TestFileUtilsImpl) Ds3SpecParser(com.spectralogic.ds3autogen.api.Ds3SpecParser) FileUtils(com.spectralogic.ds3autogen.api.FileUtils) Ds3DocSpecEmptyImpl(com.spectralogic.ds3autogen.docspec.Ds3DocSpecEmptyImpl) Ds3SpecParserImpl(com.spectralogic.ds3autogen.Ds3SpecParserImpl) CodeGenerator(com.spectralogic.ds3autogen.api.CodeGenerator) Ds3ApiSpec(com.spectralogic.ds3autogen.api.models.apispec.Ds3ApiSpec) Test(org.junit.Test)

Example 3 with CodeGenerator

use of com.spectralogic.ds3autogen.api.CodeGenerator in project ds3_autogen by SpectraLogic.

the class TestPythonGeneratedCode method generateCode.

/**
         * Generates the python code associated with an input file. This allows
         * for a Ds3DocSpec to be specified
         * Captured code: ds3.py
         */
public void generateCode(final FileUtils fileUtils, final String inputFileName, final Ds3DocSpec docSpec) throws IOException, TemplateModelException {
    final Ds3SpecParser parser = new Ds3SpecParserImpl();
    final Ds3ApiSpec spec = parser.getSpec(TestPythonGeneratedCode.class.getResourceAsStream(inputFileName));
    final CodeGenerator codeGenerator = new PythonCodeGenerator();
    codeGenerator.generate(spec, fileUtils, Paths.get("."), docSpec);
    ds3Code = new String(ds3OutputStream.toByteArray());
}
Also used : PythonCodeGenerator(com.spectralogic.ds3autogen.python.PythonCodeGenerator) Ds3SpecParser(com.spectralogic.ds3autogen.api.Ds3SpecParser) Ds3SpecParserImpl(com.spectralogic.ds3autogen.Ds3SpecParserImpl) PythonCodeGenerator(com.spectralogic.ds3autogen.python.PythonCodeGenerator) CodeGenerator(com.spectralogic.ds3autogen.api.CodeGenerator) Ds3ApiSpec(com.spectralogic.ds3autogen.api.models.apispec.Ds3ApiSpec)

Example 4 with CodeGenerator

use of com.spectralogic.ds3autogen.api.CodeGenerator in project ds3_autogen by SpectraLogic.

the class TestPython3GeneratedCode method generateCode.

/**
     * Generates the Python 3 code associated with an input file. This allows
     * for a Ds3DocSpec to be specified
     * Captured code: ds3.py
     */
public void generateCode(final FileUtils fileUtils, final String inputFileName, final Ds3DocSpec docSpec) throws IOException, TemplateModelException {
    final Ds3SpecParser parser = new Ds3SpecParserImpl();
    final Ds3ApiSpec spec = parser.getSpec(TestPython3GeneratedCode.class.getResourceAsStream(inputFileName));
    final CodeGenerator codeGenerator = new Python3CodeGenerator();
    codeGenerator.generate(spec, fileUtils, Paths.get("."), docSpec);
    ds3Code = new String(ds3OutputStream.toByteArray());
}
Also used : Ds3SpecParser(com.spectralogic.ds3autogen.api.Ds3SpecParser) Python3CodeGenerator(com.spectralogic.ds3autogen.python3.Python3CodeGenerator) Ds3SpecParserImpl(com.spectralogic.ds3autogen.Ds3SpecParserImpl) Python3CodeGenerator(com.spectralogic.ds3autogen.python3.Python3CodeGenerator) CodeGenerator(com.spectralogic.ds3autogen.api.CodeGenerator) Ds3ApiSpec(com.spectralogic.ds3autogen.api.models.apispec.Ds3ApiSpec)

Example 5 with CodeGenerator

use of com.spectralogic.ds3autogen.api.CodeGenerator in project ds3_autogen by SpectraLogic.

the class Main method run.

public void run() throws Exception {
    final Ds3SpecParser parser = new Ds3SpecParserImpl();
    System.out.println("Generating " + args.getType().toString() + " ds3 sdk code for the spec " + args.getInputSpec());
    //TODO make the input file also accept a url that we can read from
    final Ds3ApiSpec spec = parser.getSpec(Files.newInputStream(Paths.get(args.getInputSpec())), args.generateInternal());
    final CodeGenerator generator;
    switch(args.getType()) {
        case C:
            generator = new CCodeGenerator();
            break;
        case JAVA:
            generator = new JavaCodeGenerator();
            break;
        case NET:
            generator = new NetCodeGenerator();
            break;
        case PYTHON:
            generator = new PythonCodeGenerator();
            break;
        case PYTHON3:
            generator = new Python3CodeGenerator();
            break;
        case GO:
            generator = new GoCodeGenerator();
            break;
        default:
            throw new IllegalArgumentException("Unknown generator typeName " + args.getType().toString());
    }
    final FileUtils fileUtils = new FileUtilsImpl();
    final Ds3DocSpec docSpec;
    if (args.isNoDoc()) {
        docSpec = new Ds3DocSpecEmptyImpl();
    } else {
        final Ds3DocSpecParser docSpecParser = new Ds3DocSpecParserImpl(new NameMapper());
        docSpec = docSpecParser.getDocSpec();
    }
    generator.generate(spec, fileUtils, Paths.get(args.getTargetDir()), docSpec);
}
Also used : PythonCodeGenerator(com.spectralogic.ds3autogen.python.PythonCodeGenerator) FileUtilsImpl(com.spectralogic.ds3autogen.utils.FileUtilsImpl) Ds3SpecParser(com.spectralogic.ds3autogen.api.Ds3SpecParser) FileUtils(com.spectralogic.ds3autogen.api.FileUtils) NetCodeGenerator(com.spectralogic.ds3autogen.net.NetCodeGenerator) Ds3DocSpecParserImpl(com.spectralogic.ds3autogen.docspec.Ds3DocSpecParserImpl) Ds3DocSpec(com.spectralogic.ds3autogen.api.models.docspec.Ds3DocSpec) Ds3SpecParserImpl(com.spectralogic.ds3autogen.Ds3SpecParserImpl) JavaCodeGenerator(com.spectralogic.ds3autogen.java.JavaCodeGenerator) Python3CodeGenerator(com.spectralogic.ds3autogen.python3.Python3CodeGenerator) PythonCodeGenerator(com.spectralogic.ds3autogen.python.PythonCodeGenerator) CodeGenerator(com.spectralogic.ds3autogen.api.CodeGenerator) NetCodeGenerator(com.spectralogic.ds3autogen.net.NetCodeGenerator) CCodeGenerator(com.spectralogic.ds3autogen.c.CCodeGenerator) GoCodeGenerator(com.spectralogic.ds3autogen.go.GoCodeGenerator) GoCodeGenerator(com.spectralogic.ds3autogen.go.GoCodeGenerator) Ds3ApiSpec(com.spectralogic.ds3autogen.api.models.apispec.Ds3ApiSpec) Python3CodeGenerator(com.spectralogic.ds3autogen.python3.Python3CodeGenerator) NameMapper(com.spectralogic.ds3autogen.NameMapper) Ds3DocSpecEmptyImpl(com.spectralogic.ds3autogen.docspec.Ds3DocSpecEmptyImpl) CCodeGenerator(com.spectralogic.ds3autogen.c.CCodeGenerator) Ds3DocSpecParser(com.spectralogic.ds3autogen.api.Ds3DocSpecParser) JavaCodeGenerator(com.spectralogic.ds3autogen.java.JavaCodeGenerator)

Aggregations

Ds3SpecParserImpl (com.spectralogic.ds3autogen.Ds3SpecParserImpl)5 CodeGenerator (com.spectralogic.ds3autogen.api.CodeGenerator)5 Ds3SpecParser (com.spectralogic.ds3autogen.api.Ds3SpecParser)5 Ds3ApiSpec (com.spectralogic.ds3autogen.api.models.apispec.Ds3ApiSpec)5 Ds3DocSpecEmptyImpl (com.spectralogic.ds3autogen.docspec.Ds3DocSpecEmptyImpl)3 FileUtils (com.spectralogic.ds3autogen.api.FileUtils)2 Ds3DocSpec (com.spectralogic.ds3autogen.api.models.docspec.Ds3DocSpec)2 GoCodeGenerator (com.spectralogic.ds3autogen.go.GoCodeGenerator)2 PythonCodeGenerator (com.spectralogic.ds3autogen.python.PythonCodeGenerator)2 Python3CodeGenerator (com.spectralogic.ds3autogen.python3.Python3CodeGenerator)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 NameMapper (com.spectralogic.ds3autogen.NameMapper)1 Ds3DocSpecParser (com.spectralogic.ds3autogen.api.Ds3DocSpecParser)1 HttpVerb (com.spectralogic.ds3autogen.api.models.enums.HttpVerb)1 CCodeGenerator (com.spectralogic.ds3autogen.c.CCodeGenerator)1 Ds3DocSpecParserImpl (com.spectralogic.ds3autogen.docspec.Ds3DocSpecParserImpl)1 JavaCodeGenerator (com.spectralogic.ds3autogen.java.JavaCodeGenerator)1 NetCodeGenerator (com.spectralogic.ds3autogen.net.NetCodeGenerator)1 FileUtilsImpl (com.spectralogic.ds3autogen.utils.FileUtilsImpl)1 TestFileUtilsImpl (com.spectralogic.ds3autogen.utils.TestFileUtilsImpl)1