use of com.palantir.conjure.spec.ConjureDefinition in project conjure-java by palantir.
the class DialogueServiceGeneratorTests method generateEteServices.
@Test
public void generateEteServices() throws IOException {
ConjureDefinition def = Conjure.parse(ImmutableList.of(new File("src/test/resources/cookie-service.yml"), new File("src/test/resources/ete-service.yml"), new File("src/test/resources/ete-binary.yml")));
List<Path> files = new GenerationCoordinator(MoreExecutors.directExecutor(), ImmutableSet.of(new DialogueServiceGenerator(Options.builder().apiVersion("1.2.3").build()))).emit(def, folder);
validateGeneratorOutput(files, Paths.get("src/integrationInput/java/com/palantir/product"));
}
use of com.palantir.conjure.spec.ConjureDefinition in project conjure by palantir.
the class ConjureParserUtils method parseConjureDef.
static ConjureDefinition parseConjureDef(Map<String, AnnotatedConjureSourceFile> annotatedParsedDefs) {
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);
return definition;
}
use of com.palantir.conjure.spec.ConjureDefinition in project conjure by palantir.
the class ConjureSourceFileValidatorTest method testTypeMissingRequiredSafetyInformation.
@Test
public void testTypeMissingRequiredSafetyInformation() {
ConjureDefinition conjureDef = ConjureDefinition.builder().version(1).types(TypeDefinition.object(ObjectDefinition.builder().typeName(FOO).fields(FieldDefinition.builder().fieldName(FieldName.of("bad")).type(Type.primitive(PrimitiveType.STRING)).docs(DOCS).build()).build())).build();
assertThatThrownBy(() -> ConjureDefinitionValidator.validateAll(conjureDef, SafetyDeclarationRequirements.REQUIRED)).isInstanceOf(ConjureIllegalStateException.class).hasMessageContaining("package.Foo::bad must declare log safety");
}
use of com.palantir.conjure.spec.ConjureDefinition in project conjure by palantir.
the class ConjureSourceFileValidatorTest method testNoIllegalMapKeys_field.
@Test
public void testNoIllegalMapKeys_field() {
ConjureDefinition conjureDef = ConjureDefinition.builder().version(1).types(TypeDefinition.object(ObjectDefinition.builder().typeName(FOO).fields(FieldDefinition.builder().fieldName(FieldName.of("bad")).type(Type.map(MapType.of(Type.list(ListType.of(Type.primitive(PrimitiveType.STRING))), Type.primitive(PrimitiveType.STRING)))).docs(DOCS).build()).build())).build();
assertThatThrownBy(() -> ConjureDefinitionValidator.ILLEGAL_MAP_KEYS.validate(conjureDef)).isInstanceOf(IllegalStateException.class).hasMessageStartingWith("Illegal map key found in object Foo");
}
use of com.palantir.conjure.spec.ConjureDefinition in project conjure by palantir.
the class ConjureSourceFileValidatorTest method testNoSelfRecursiveType.
@Test
public void testNoSelfRecursiveType() {
ConjureDefinition conjureDef = ConjureDefinition.builder().version(1).types(ImmutableList.of(TypeDefinition.object(ObjectDefinition.builder().typeName(FOO).fields(FieldDefinition.builder().fieldName(FieldName.of("self")).type(Type.reference(FOO)).docs(DOCS).build()).build()))).build();
assertThatThrownBy(() -> ConjureDefinitionValidator.NO_RECURSIVE_TYPES.validate(conjureDef)).isInstanceOf(IllegalStateException.class).hasMessage("Illegal recursive data type: Foo -> Foo");
}
Aggregations