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