Search in sources :

Example 1 with ReferenceTypeResolver

use of com.palantir.conjure.defs.ConjureTypeParserVisitor.ReferenceTypeResolver in project conjure by palantir.

the class ConjureParserUtils method innerParseImportObjects.

private static Map<TypeName, TypeDefinition> innerParseImportObjects(Map<Namespace, ConjureImports> conjureImports, Map<String, AnnotatedConjureSourceFile> externalTypes, Set<String> loadedFiles) {
    Map<TypeName, TypeDefinition> allDefinitions = new HashMap<>();
    conjureImports.values().forEach(conjureImport -> {
        String pathKey = conjureImport.absoluteFile().orElseThrow(() -> new SafeIllegalStateException("Absolute file MUST be resolved as part of parsing stage")).getAbsolutePath();
        // These structures are potentially recursive; load in any given conjure file once
        if (loadedFiles.contains(pathKey)) {
            return;
        }
        loadedFiles.add(pathKey);
        AnnotatedConjureSourceFile annotatedConjureSourceFile = externalTypes.get(pathKey);
        Preconditions.checkNotNull(annotatedConjureSourceFile, "Couldn't find import", UnsafeArg.of("file", conjureImport.file()));
        ConjureSourceFile conjureDef = annotatedConjureSourceFile.conjureSourceFile();
        Map<Namespace, String> importProviders = annotatedConjureSourceFile.importProviders();
        ReferenceTypeResolver importTypeResolver = new ConjureTypeParserVisitor.ByParsedRepresentationTypeNameResolver(conjureDef.types(), importProviders, externalTypes);
        allDefinitions.putAll(parseObjects(conjureDef.types(), importTypeResolver));
        allDefinitions.putAll(innerParseImportObjects(conjureDef.types().conjureImports(), externalTypes, loadedFiles));
    });
    return allDefinitions;
}
Also used : TypeName(com.palantir.conjure.spec.TypeName) AnnotatedConjureSourceFile(com.palantir.conjure.parser.AnnotatedConjureSourceFile) ConjureSourceFile(com.palantir.conjure.parser.ConjureSourceFile) ReferenceTypeResolver(com.palantir.conjure.defs.ConjureTypeParserVisitor.ReferenceTypeResolver) HashMap(java.util.HashMap) AnnotatedConjureSourceFile(com.palantir.conjure.parser.AnnotatedConjureSourceFile) PathString(com.palantir.conjure.parser.services.PathString) SafeIllegalStateException(com.palantir.logsafe.exceptions.SafeIllegalStateException) Namespace(com.palantir.conjure.parser.types.names.Namespace) ErrorNamespace(com.palantir.conjure.spec.ErrorNamespace) TypeDefinition(com.palantir.conjure.spec.TypeDefinition)

Example 2 with ReferenceTypeResolver

use of com.palantir.conjure.defs.ConjureTypeParserVisitor.ReferenceTypeResolver in project conjure by palantir.

the class ConjureParserUtils method parseEndpoint.

private static EndpointDefinition parseEndpoint(String name, com.palantir.conjure.parser.services.EndpointDefinition def, PathString basePath, Optional<AuthType> defaultAuth, ReferenceTypeResolver typeResolver, DealiasingTypeVisitor dealiasingVisitor) {
    HttpPath httpPath = parseHttpPath(def, basePath);
    EndpointDefinition endpoint = EndpointDefinition.builder().endpointName(EndpointName.of(name)).httpMethod(HttpMethod.valueOf(def.http().method())).httpPath(httpPath).auth(def.auth().map(ConjureParserUtils::parseAuthType).orElse(defaultAuth)).args(parseArgs(def.args(), httpPath, typeResolver)).tags(def.tags().stream().peek(tag -> Preconditions.checkArgument(!tag.isEmpty(), "tag must not be empty")).collect(Collectors.toSet())).markers(parseMarkers(def.markers(), typeResolver)).returns(def.returns().map(t -> t.visit(new ConjureTypeParserVisitor(typeResolver)))).docs(def.docs().map(Documentation::of)).deprecated(def.deprecated().map(Documentation::of)).build();
    EndpointDefinitionValidator.validateAll(endpoint, dealiasingVisitor);
    return endpoint;
}
Also used : HeaderAuthType(com.palantir.conjure.spec.HeaderAuthType) PathString(com.palantir.conjure.parser.services.PathString) SafeIllegalStateException(com.palantir.logsafe.exceptions.SafeIllegalStateException) ConjureDefinition(com.palantir.conjure.spec.ConjureDefinition) ServiceDefinitionValidator(com.palantir.conjure.defs.validator.ServiceDefinitionValidator) ServiceDefinition(com.palantir.conjure.spec.ServiceDefinition) EnumValueDefinitionValidator(com.palantir.conjure.defs.validator.EnumValueDefinitionValidator) ConjureDefinitionValidator(com.palantir.conjure.defs.validator.ConjureDefinitionValidator) NamedTypesDefinition(com.palantir.conjure.parser.types.NamedTypesDefinition) Map(java.util.Map) ObjectDefinitionValidator(com.palantir.conjure.defs.validator.ObjectDefinitionValidator) ArgumentName(com.palantir.conjure.spec.ArgumentName) AnnotatedConjureSourceFile(com.palantir.conjure.parser.AnnotatedConjureSourceFile) ParameterId(com.palantir.conjure.spec.ParameterId) EndpointDefinitionValidator(com.palantir.conjure.defs.validator.EndpointDefinitionValidator) LogSafetyDefinition(com.palantir.conjure.parser.LogSafetyDefinition) ObjectDefinition(com.palantir.conjure.spec.ObjectDefinition) ConjureImports(com.palantir.conjure.parser.types.reference.ConjureImports) AuthType(com.palantir.conjure.spec.AuthType) Collection(java.util.Collection) SafeIllegalArgumentException(com.palantir.logsafe.exceptions.SafeIllegalArgumentException) Set(java.util.Set) BodyParameterType(com.palantir.conjure.spec.BodyParameterType) FieldDefinition(com.palantir.conjure.spec.FieldDefinition) Collectors(java.util.stream.Collectors) FieldDefinitionValidator(com.palantir.conjure.defs.validator.FieldDefinitionValidator) ParameterType(com.palantir.conjure.spec.ParameterType) List(java.util.List) AliasDefinition(com.palantir.conjure.spec.AliasDefinition) UnsafeArg(com.palantir.logsafe.UnsafeArg) ReferenceTypeResolver(com.palantir.conjure.defs.ConjureTypeParserVisitor.ReferenceTypeResolver) Documentation(com.palantir.conjure.spec.Documentation) ConjureRuntimeException(com.palantir.conjure.exceptions.ConjureRuntimeException) Optional(java.util.Optional) HttpPathValidator(com.palantir.conjure.defs.validator.HttpPathValidator) PrimitiveType(com.palantir.conjure.spec.PrimitiveType) EndpointDefinition(com.palantir.conjure.spec.EndpointDefinition) HttpMethod(com.palantir.conjure.spec.HttpMethod) LogSafety(com.palantir.conjure.spec.LogSafety) EnumDefinitionValidator(com.palantir.conjure.defs.validator.EnumDefinitionValidator) FieldNameValidator(com.palantir.conjure.defs.validator.FieldNameValidator) ErrorDefinition(com.palantir.conjure.spec.ErrorDefinition) Type(com.palantir.conjure.spec.Type) PathParameterType(com.palantir.conjure.spec.PathParameterType) TypeDefinitionVisitor(com.palantir.conjure.visitor.TypeDefinitionVisitor) HashMap(java.util.HashMap) Namespace(com.palantir.conjure.parser.types.names.Namespace) HttpPath(com.palantir.conjure.spec.HttpPath) ConjureIllegalArgumentException(com.palantir.conjure.exceptions.ConjureIllegalArgumentException) Function(java.util.function.Function) ArrayList(java.util.ArrayList) UnionDefinition(com.palantir.conjure.spec.UnionDefinition) HashSet(java.util.HashSet) ImmutableList(com.google.common.collect.ImmutableList) ErrorNamespace(com.palantir.conjure.spec.ErrorNamespace) TypeNameValidator(com.palantir.conjure.defs.validator.TypeNameValidator) PackageValidator(com.palantir.conjure.defs.validator.PackageValidator) TypeDefinition(com.palantir.conjure.spec.TypeDefinition) EnumDefinition(com.palantir.conjure.spec.EnumDefinition) CookieAuthType(com.palantir.conjure.spec.CookieAuthType) EnumValueDefinition(com.palantir.conjure.spec.EnumValueDefinition) ErrorDefinitionValidator(com.palantir.conjure.defs.validator.ErrorDefinitionValidator) ParameterName(com.palantir.conjure.parser.services.ParameterName) EndpointName(com.palantir.conjure.spec.EndpointName) QueryParameterType(com.palantir.conjure.spec.QueryParameterType) TypeName(com.palantir.conjure.spec.TypeName) FieldName(com.palantir.conjure.spec.FieldName) ConjureSourceFile(com.palantir.conjure.parser.ConjureSourceFile) DealiasingTypeVisitor(com.palantir.conjure.visitor.DealiasingTypeVisitor) ConjurePackage(com.palantir.conjure.parser.types.names.ConjurePackage) UnionDefinitionValidator(com.palantir.conjure.defs.validator.UnionDefinitionValidator) HeaderParameterType(com.palantir.conjure.spec.HeaderParameterType) Preconditions(com.palantir.logsafe.Preconditions) ArgumentDefinition(com.palantir.conjure.spec.ArgumentDefinition) HttpPath(com.palantir.conjure.spec.HttpPath) Documentation(com.palantir.conjure.spec.Documentation) EndpointDefinition(com.palantir.conjure.spec.EndpointDefinition)

Aggregations

ReferenceTypeResolver (com.palantir.conjure.defs.ConjureTypeParserVisitor.ReferenceTypeResolver)2 AnnotatedConjureSourceFile (com.palantir.conjure.parser.AnnotatedConjureSourceFile)2 ConjureSourceFile (com.palantir.conjure.parser.ConjureSourceFile)2 PathString (com.palantir.conjure.parser.services.PathString)2 Namespace (com.palantir.conjure.parser.types.names.Namespace)2 ErrorNamespace (com.palantir.conjure.spec.ErrorNamespace)2 TypeDefinition (com.palantir.conjure.spec.TypeDefinition)2 TypeName (com.palantir.conjure.spec.TypeName)2 SafeIllegalStateException (com.palantir.logsafe.exceptions.SafeIllegalStateException)2 HashMap (java.util.HashMap)2 ImmutableList (com.google.common.collect.ImmutableList)1 ConjureDefinitionValidator (com.palantir.conjure.defs.validator.ConjureDefinitionValidator)1 EndpointDefinitionValidator (com.palantir.conjure.defs.validator.EndpointDefinitionValidator)1 EnumDefinitionValidator (com.palantir.conjure.defs.validator.EnumDefinitionValidator)1 EnumValueDefinitionValidator (com.palantir.conjure.defs.validator.EnumValueDefinitionValidator)1 ErrorDefinitionValidator (com.palantir.conjure.defs.validator.ErrorDefinitionValidator)1 FieldDefinitionValidator (com.palantir.conjure.defs.validator.FieldDefinitionValidator)1 FieldNameValidator (com.palantir.conjure.defs.validator.FieldNameValidator)1 HttpPathValidator (com.palantir.conjure.defs.validator.HttpPathValidator)1 ObjectDefinitionValidator (com.palantir.conjure.defs.validator.ObjectDefinitionValidator)1