Search in sources :

Example 36 with ConjureDefinition

use of com.palantir.conjure.spec.ConjureDefinition 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 37 with ConjureDefinition

use of com.palantir.conjure.spec.ConjureDefinition in project conjure by palantir.

the class Conjure method parse.

/**
 * Deserializes {@link ConjureDefinition} from their YAML representations in the given files.
 */
public static ConjureDefinition parse(ConjureArgs args) {
    Map<String, AnnotatedConjureSourceFile> sourceFiles = ConjureParser.parseAnnotated(args.definitions());
    ConjureDefinition ir = ConjureParserUtils.parseConjureDef(sourceFiles, args.safetyDeclarations());
    return NormalizeDefinition.normalize(ir);
}
Also used : AnnotatedConjureSourceFile(com.palantir.conjure.parser.AnnotatedConjureSourceFile) ConjureDefinition(com.palantir.conjure.spec.ConjureDefinition)

Example 38 with ConjureDefinition

use of com.palantir.conjure.spec.ConjureDefinition in project conjure by palantir.

the class ConjureParserUtils method parseConjureDef.

static ConjureDefinition parseConjureDef(Map<String, AnnotatedConjureSourceFile> annotatedParsedDefs, SafetyDeclarationRequirements safetyDeclarations) {
    ImmutableList.Builder<ServiceDefinition> servicesBuilder = ImmutableList.builder();
    ImmutableList.Builder<ErrorDefinition> errorsBuilder = ImmutableList.builder();
    ImmutableList.Builder<TypeDefinition> typesBuilder = ImmutableList.builder();
    annotatedParsedDefs.values().forEach(annotatedParsed -> {
        ConjureSourceFile parsed = annotatedParsed.conjureSourceFile();
        try {
            ConjureTypeParserVisitor.ReferenceTypeResolver typeResolver = new ConjureTypeParserVisitor.ByParsedRepresentationTypeNameResolver(parsed.types(), annotatedParsed.importProviders(), annotatedParsedDefs);
            // Resolve objects first, so we can use them in service validations
            Map<TypeName, TypeDefinition> objects = parseObjects(parsed.types(), typeResolver);
            Map<TypeName, TypeDefinition> importedObjects = parseImportObjects(parsed.types().conjureImports(), annotatedParsedDefs);
            Map<TypeName, TypeDefinition> allObjects = new HashMap<>();
            allObjects.putAll(objects);
            allObjects.putAll(importedObjects);
            DealiasingTypeVisitor dealiasingVisitor = new DealiasingTypeVisitor(allObjects);
            parsed.services().forEach((serviceName, service) -> {
                servicesBuilder.add(parseService(service, TypeName.of(serviceName.name(), parseConjurePackage(service.conjurePackage())), typeResolver, dealiasingVisitor));
            });
            typesBuilder.addAll(objects.values());
            errorsBuilder.addAll(parseErrors(parsed.types().definitions(), typeResolver));
        } catch (RuntimeException e) {
            throw new ConjureRuntimeException(String.format("Encountered error trying to parse file '%s'", annotatedParsed.sourceFile()), e);
        }
    });
    ConjureDefinition definition = ConjureDefinition.builder().version(Conjure.SUPPORTED_IR_VERSION).types(typesBuilder.build()).errors(errorsBuilder.build()).services(servicesBuilder.build()).build();
    ConjureDefinitionValidator.validateAll(definition, safetyDeclarations);
    return definition;
}
Also used : ErrorDefinition(com.palantir.conjure.spec.ErrorDefinition) AnnotatedConjureSourceFile(com.palantir.conjure.parser.AnnotatedConjureSourceFile) ConjureSourceFile(com.palantir.conjure.parser.ConjureSourceFile) TypeName(com.palantir.conjure.spec.TypeName) ReferenceTypeResolver(com.palantir.conjure.defs.ConjureTypeParserVisitor.ReferenceTypeResolver) HashMap(java.util.HashMap) ImmutableList(com.google.common.collect.ImmutableList) ConjureRuntimeException(com.palantir.conjure.exceptions.ConjureRuntimeException) DealiasingTypeVisitor(com.palantir.conjure.visitor.DealiasingTypeVisitor) TypeDefinition(com.palantir.conjure.spec.TypeDefinition) ConjureRuntimeException(com.palantir.conjure.exceptions.ConjureRuntimeException) ConjureDefinition(com.palantir.conjure.spec.ConjureDefinition) ServiceDefinition(com.palantir.conjure.spec.ServiceDefinition)

Example 39 with ConjureDefinition

use of com.palantir.conjure.spec.ConjureDefinition in project conjure by palantir.

the class ImportSetPrefixTest method parsesImportsWithWrapperPrefixes.

@Test
public void parsesImportsWithWrapperPrefixes() {
    ConjureDefinition normalized = Conjure.parse(ImmutableSet.of(new File("src/test/resources/import-set-prefix.yml")));
    assertThat(normalized.getErrors()).hasSize(1);
    assertThat(normalized.getTypes()).hasSize(2);
}
Also used : ConjureDefinition(com.palantir.conjure.spec.ConjureDefinition) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 40 with ConjureDefinition

use of com.palantir.conjure.spec.ConjureDefinition in project conjure by palantir.

the class NormalizeDefinitionTest method sort_types_services_and_errors.

@Test
public void sort_types_services_and_errors() throws IOException {
    ConjureDefinition normalized = Conjure.parse(ImmutableSet.of(new File("src/test/resources/normalize-me.yml")));
    String actual = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(normalized);
    File file = new File("src/test/resources/normalized.conjure.json");
    if (Boolean.valueOf(System.getProperty("recreate", "false"))) {
        objectMapper.writerWithDefaultPrettyPrinter().writeValue(file, normalized);
    }
    assertThat(file).hasContent(actual);
}
Also used : ConjureDefinition(com.palantir.conjure.spec.ConjureDefinition) File(java.io.File) Test(org.junit.jupiter.api.Test)

Aggregations

ConjureDefinition (com.palantir.conjure.spec.ConjureDefinition)65 Test (org.junit.jupiter.api.Test)49 File (java.io.File)40 Path (java.nio.file.Path)30 ConjureIllegalStateException (com.palantir.conjure.exceptions.ConjureIllegalStateException)13 JerseyServiceGenerator (com.palantir.conjure.java.services.JerseyServiceGenerator)9 UndertowServiceGenerator (com.palantir.conjure.java.services.UndertowServiceGenerator)9 GenerationCoordinator (com.palantir.conjure.java.GenerationCoordinator)8 Retrofit2ServiceGenerator (com.palantir.conjure.java.services.Retrofit2ServiceGenerator)4 DialogueServiceGenerator (com.palantir.conjure.java.services.dialogue.DialogueServiceGenerator)4 AnnotatedConjureSourceFile (com.palantir.conjure.parser.AnnotatedConjureSourceFile)4 TypeDefinition (com.palantir.conjure.spec.TypeDefinition)4 BeforeAll (org.junit.jupiter.api.BeforeAll)4 TypeName (com.palantir.conjure.spec.TypeName)3 ImmutableList (com.google.common.collect.ImmutableList)2 ReferenceTypeResolver (com.palantir.conjure.defs.ConjureTypeParserVisitor.ReferenceTypeResolver)2 ConjureRuntimeException (com.palantir.conjure.exceptions.ConjureRuntimeException)2 ConjureSourceFile (com.palantir.conjure.parser.ConjureSourceFile)2 DefaultPostmanCollectionFileWriter (com.palantir.conjure.postman.writer.DefaultPostmanCollectionFileWriter)2 PostmanCollectionFileWriter (com.palantir.conjure.postman.writer.PostmanCollectionFileWriter)2