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();
}
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);
}
}
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();
}
Aggregations