Search in sources :

Example 1 with TypeDescriptor

use of com.spectralogic.ds3autogen.python.model.type.TypeDescriptor in project ds3_autogen by SpectraLogic.

the class PythonCodeGenerator_Test method toTypeDescriptorList_FullMap_Test.

@Test
public void toTypeDescriptorList_FullMap_Test() {
    final Ds3Type ds3Type = createDs3TypeTestData("com.test.SimpleType", createDs3ElementListTestData("ElementName", "ElementType"));
    final ImmutableMap<String, Ds3Type> testTypeMap = ImmutableMap.of(ds3Type.getName(), ds3Type);
    final ImmutableList<TypeDescriptor> result = toTypeDescriptorList(testTypeMap);
    assertThat(result.size(), is(1));
    assertThat(result.get(0).getName(), is("SimpleType"));
}
Also used : TypeDescriptor(com.spectralogic.ds3autogen.python.model.type.TypeDescriptor) Ds3Type(com.spectralogic.ds3autogen.api.models.apispec.Ds3Type) Test(org.junit.Test)

Example 2 with TypeDescriptor

use of com.spectralogic.ds3autogen.python.model.type.TypeDescriptor in project ds3_autogen by SpectraLogic.

the class PythonCodeGenerator method generateCommands.

/**
     * Generates the ds3.py python code which includes: request handlers, response handlers,
     * response payload descriptors, and the client
     */
@Override
public void generateCommands(final ImmutableList<Ds3Request> ds3Requests, final ImmutableMap<String, Ds3Type> typeMap, final Ds3DocSpec docSpec) throws IOException, TemplateException {
    if (isEmpty(ds3Requests)) {
        LOG.info("There are no requests to generate");
        return;
    }
    final ImmutableList<BaseRequest> baseRequests = toRequestModelList(ds3Requests, docSpec);
    final ImmutableList<BaseResponse> baseResponses = toResponseModelList(ds3Requests);
    final ImmutableList<TypeDescriptor> baseTypes = toTypeDescriptorList(typeMap);
    final ImmutableList<BaseClient> clientCommands = toClientCommands(ds3Requests, docSpec);
    final CommandSet commandSet = new CommandSet(baseRequests, baseResponses, baseTypes, clientCommands);
    final Template tmpl = getCommandTemplate(config);
    final Path path = toBaseProjectPath("ds3.py");
    LOG.info("Getting OutputStream for file: " + path.toString());
    try (final OutputStream outStream = fileUtils.getOutputFile(path);
        final Writer writer = new OutputStreamWriter(outStream)) {
        tmpl.process(commandSet, writer);
    }
}
Also used : Path(java.nio.file.Path) OutputStream(java.io.OutputStream) BaseClient(com.spectralogic.ds3autogen.python.model.client.BaseClient) BaseResponse(com.spectralogic.ds3autogen.python.model.response.BaseResponse) TypeDescriptor(com.spectralogic.ds3autogen.python.model.type.TypeDescriptor) BaseRequest(com.spectralogic.ds3autogen.python.model.request.BaseRequest) CommandSet(com.spectralogic.ds3autogen.python.model.commands.CommandSet) OutputStreamWriter(java.io.OutputStreamWriter) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer)

Example 3 with TypeDescriptor

use of com.spectralogic.ds3autogen.python.model.type.TypeDescriptor in project ds3_autogen by SpectraLogic.

the class PythonCodeGenerator_Test method toTypeDescriptor_Test.

@Test
public void toTypeDescriptor_Test() {
    final Ds3Type ds3Type = createDs3TypeTestData("com.test.SimpleType", createDs3ElementListTestData("ElementName", "None"));
    final ImmutableMap<String, Ds3Type> testTypeMap = ImmutableMap.of(ds3Type.getName(), ds3Type);
    final TypeDescriptor result = toTypeDescriptor(ds3Type, testTypeMap);
    assertThat(result.getName(), is("SimpleType"));
    assertThat(result.getAttributes().size(), is(0));
    assertThat(result.getElementLists().size(), is(0));
    assertThat(result.getElements().size(), is(1));
    assertThat(result.getElements().get(0), is("'ElementName' : None"));
}
Also used : TypeDescriptor(com.spectralogic.ds3autogen.python.model.type.TypeDescriptor) Ds3Type(com.spectralogic.ds3autogen.api.models.apispec.Ds3Type) Test(org.junit.Test)

Aggregations

TypeDescriptor (com.spectralogic.ds3autogen.python.model.type.TypeDescriptor)3 Ds3Type (com.spectralogic.ds3autogen.api.models.apispec.Ds3Type)2 Test (org.junit.Test)2 BaseClient (com.spectralogic.ds3autogen.python.model.client.BaseClient)1 CommandSet (com.spectralogic.ds3autogen.python.model.commands.CommandSet)1 BaseRequest (com.spectralogic.ds3autogen.python.model.request.BaseRequest)1 BaseResponse (com.spectralogic.ds3autogen.python.model.response.BaseResponse)1 OutputStream (java.io.OutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 Path (java.nio.file.Path)1