Search in sources :

Example 1 with DefaultPostmanCollectionFileWriter

use of com.palantir.conjure.postman.writer.DefaultPostmanCollectionFileWriter in project conjure-postman by palantir.

the class ConjurePostmanCli method generate.

static void generate(File target, File outputDirectory, GeneratorConfiguration config) {
    try {
        ConjureDefinition conjureDefinition = OBJECT_MAPPER.readValue(target, ConjureDefinition.class);
        PostmanCollectionFileWriter writer = new DefaultPostmanCollectionFileWriter(outputDirectory.toPath());
        PostmanCollectionGenerator generator = new PostmanCollectionGenerator(config);
        writer.write(generator.generate(conjureDefinition));
    } catch (IOException e) {
        throw new RuntimeException(String.format("Error parsing definition: %s", e.toString()));
    }
}
Also used : PostmanCollectionGenerator(com.palantir.conjure.postman.PostmanCollectionGenerator) DefaultPostmanCollectionFileWriter(com.palantir.conjure.postman.writer.DefaultPostmanCollectionFileWriter) PostmanCollectionFileWriter(com.palantir.conjure.postman.writer.PostmanCollectionFileWriter) DefaultPostmanCollectionFileWriter(com.palantir.conjure.postman.writer.DefaultPostmanCollectionFileWriter) ConjureDefinition(com.palantir.conjure.spec.ConjureDefinition) IOException(java.io.IOException)

Example 2 with DefaultPostmanCollectionFileWriter

use of com.palantir.conjure.postman.writer.DefaultPostmanCollectionFileWriter in project conjure-postman by palantir.

the class ConjurePostmanGeneratorTest method maybeResetExpectedDirectory.

private void maybeResetExpectedDirectory(Path expected, ConjureDefinition definition) throws IOException {
    if (Boolean.valueOf(System.getProperty("recreate", "false")) || !expected.toFile().isDirectory()) {
        Files.createDirectories(expected);
        try (Stream<Path> walk = Files.walk(expected)) {
            walk.filter(path -> path.toFile().isFile()).forEach(path -> path.toFile().delete());
        }
        try (Stream<Path> walk = Files.walk(expected)) {
            walk.forEach(path -> path.toFile().delete());
        }
        Files.createDirectories(expected);
        PostmanCollectionFileWriter defaultWriter = new DefaultPostmanCollectionFileWriter(expected);
        defaultWriter.write(generator.generate(definition));
    }
}
Also used : Path(java.nio.file.Path) Files(java.nio.file.Files) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) Set(java.util.Set) Conjure(com.palantir.conjure.defs.Conjure) IOException(java.io.IOException) ConjureDefinition(com.palantir.conjure.spec.ConjureDefinition) Collectors(java.util.stream.Collectors) File(java.io.File) DefaultPostmanCollectionFileWriter(com.palantir.conjure.postman.writer.DefaultPostmanCollectionFileWriter) List(java.util.List) Stream(java.util.stream.Stream) PostmanCollectionFileWriter(com.palantir.conjure.postman.writer.PostmanCollectionFileWriter) Strings(org.assertj.core.util.Strings) Path(java.nio.file.Path) DefaultPostmanCollectionFileWriter(com.palantir.conjure.postman.writer.DefaultPostmanCollectionFileWriter) PostmanCollectionFileWriter(com.palantir.conjure.postman.writer.PostmanCollectionFileWriter) DefaultPostmanCollectionFileWriter(com.palantir.conjure.postman.writer.DefaultPostmanCollectionFileWriter)

Aggregations

DefaultPostmanCollectionFileWriter (com.palantir.conjure.postman.writer.DefaultPostmanCollectionFileWriter)2 PostmanCollectionFileWriter (com.palantir.conjure.postman.writer.PostmanCollectionFileWriter)2 ConjureDefinition (com.palantir.conjure.spec.ConjureDefinition)2 IOException (java.io.IOException)2 Conjure (com.palantir.conjure.defs.Conjure)1 PostmanCollectionGenerator (com.palantir.conjure.postman.PostmanCollectionGenerator)1 File (java.io.File)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 List (java.util.List)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Strings (org.assertj.core.util.Strings)1 RunWith (org.junit.runner.RunWith)1