code
stringlengths
23
201k
docstring
stringlengths
17
96.2k
func_name
stringlengths
0
235
language
stringclasses
1 value
repo
stringlengths
8
72
path
stringlengths
11
317
url
stringlengths
57
377
license
stringclasses
7 values
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); }
Deserializes {@link ConjureDefinition} from their YAML representations in the given files.
parse
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/Conjure.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/Conjure.java
Apache-2.0
static Builder builder() { return new Builder(); }
If {@link SafetyDeclarationRequirements#REQUIRED}, all components which allow safety declarations must declare safety.
builder
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/ConjureArgs.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/ConjureArgs.java
Apache-2.0
public static String parseConjurePackage(ConjurePackage parsed) { return parsed.name(); }
Utility methods used to parse {@code com.palantir.conjure.parser} definitions into {@code com.palantir.conjure.defs} definitions.
parseConjurePackage
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/ConjureParserUtils.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/ConjureParserUtils.java
Apache-2.0
public static String parsePackageOrElseThrow( Optional<ConjurePackage> conjurePackage, Optional<String> defaultPackage) { String packageName = conjurePackage .map(ConjurePackage::name) .orElseGet(() -> defaultPackage.orElseThrow(() -> new SafeIllegalArgumentException( // TODO(rfink): Better errors: Can we provide context on where exactly no package was provided? "Must provide default conjure package or " + "explicit conjure package for every object and service"))); PackageValidator.validate(packageName); return packageName; }
Utility methods used to parse {@code com.palantir.conjure.parser} definitions into {@code com.palantir.conjure.defs} definitions.
parsePackageOrElseThrow
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/ConjureParserUtils.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/ConjureParserUtils.java
Apache-2.0
public static ErrorDefinition parseErrorType( TypeName name, com.palantir.conjure.parser.types.complex.ErrorTypeDefinition def, ConjureTypeParserVisitor.ReferenceTypeResolver typeResolver) { ErrorDefinition errorType = ErrorDefinition.builder() .errorName(name) .namespace(ErrorNamespace.of(def.namespace().name())) .code(def.code().asSpecErrorCode()) .safeArgs(parseField(def.safeArgs(), typeResolver)) .unsafeArgs(parseField(def.unsafeArgs(), typeResolver)) .docs(def.docs().map(Documentation::of)) .build(); ErrorDefinitionValidator.validate(errorType); return errorType; }
Utility methods used to parse {@code com.palantir.conjure.parser} definitions into {@code com.palantir.conjure.defs} definitions.
parseErrorType
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/ConjureParserUtils.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/ConjureParserUtils.java
Apache-2.0
public static TypeDefinition parseEnumType( TypeName name, com.palantir.conjure.parser.types.complex.EnumTypeDefinition def) { EnumDefinition enumType = EnumDefinition.builder() .typeName(name) .values(def.values().stream() .map(ConjureParserUtils::parseEnumValue) .collect(Collectors.toList())) .docs(def.docs().map(Documentation::of)) .build(); EnumDefinitionValidator.validateAll(enumType); return TypeDefinition.enum_(enumType); }
Utility methods used to parse {@code com.palantir.conjure.parser} definitions into {@code com.palantir.conjure.defs} definitions.
parseEnumType
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/ConjureParserUtils.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/ConjureParserUtils.java
Apache-2.0
public static TypeDefinition parseUnionType( TypeName name, com.palantir.conjure.parser.types.complex.UnionTypeDefinition def, ConjureTypeParserVisitor.ReferenceTypeResolver typeResolver) { UnionDefinition unionType = UnionDefinition.builder() .typeName(name) .union(parseField(def.union(), typeResolver)) .docs(def.docs().map(Documentation::of)) .build(); UnionDefinitionValidator.validateAll(unionType); return TypeDefinition.union(unionType); }
Utility methods used to parse {@code com.palantir.conjure.parser} definitions into {@code com.palantir.conjure.defs} definitions.
parseUnionType
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/ConjureParserUtils.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/ConjureParserUtils.java
Apache-2.0
public static TypeDefinition parseObjectType( TypeName name, com.palantir.conjure.parser.types.complex.ObjectTypeDefinition def, ConjureTypeParserVisitor.ReferenceTypeResolver typeResolver) { ObjectDefinition objectType = ObjectDefinition.builder() .typeName(name) .fields(parseField(def.fields(), typeResolver)) .docs(def.docs().map(Documentation::of)) .build(); ObjectDefinitionValidator.validate(objectType); return TypeDefinition.object(objectType); }
Utility methods used to parse {@code com.palantir.conjure.parser} definitions into {@code com.palantir.conjure.defs} definitions.
parseObjectType
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/ConjureParserUtils.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/ConjureParserUtils.java
Apache-2.0
public static TypeDefinition parseAliasType( TypeName name, com.palantir.conjure.parser.types.reference.AliasTypeDefinition def, ConjureTypeParserVisitor.ReferenceTypeResolver typeResolver) { return TypeDefinition.alias(AliasDefinition.builder() .typeName(name) .alias(def.alias().visit(new ConjureTypeParserVisitor(typeResolver))) .docs(def.docs().map(Documentation::of)) .safety(def.safety().map(ConjureParserUtils::parseLogSafety)) .build()); }
Utility methods used to parse {@code com.palantir.conjure.parser} definitions into {@code com.palantir.conjure.defs} definitions.
parseAliasType
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/ConjureParserUtils.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/ConjureParserUtils.java
Apache-2.0
public static Type parsePrimitiveType(com.palantir.conjure.parser.types.primitive.PrimitiveType primitiveType) { return Type.primitive(PrimitiveType.valueOf(primitiveType.name())); }
Utility methods used to parse {@code com.palantir.conjure.parser} definitions into {@code com.palantir.conjure.defs} definitions.
parsePrimitiveType
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/ConjureParserUtils.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/ConjureParserUtils.java
Apache-2.0
static Type parseExternalType(ExternalTypeDefinition externalType, String conjurePackage, String typeName) { if (isBearerToken(externalType) && externalType.safety().isPresent()) { throw new ConjureRuntimeException( "Cannot mark safety of external import with base type BearerToken. BearerToken assumes Do Not" + " Log."); } return Type.external(ExternalReference.builder() .externalReference(TypeName.of(typeName, conjurePackage)) .fallback(ConjureParserUtils.parsePrimitiveType(externalType.baseType())) .safety(externalType.safety().map(ConjureParserUtils::parseLogSafety)) .build()); }
Utility methods used to parse {@code com.palantir.conjure.parser} definitions into {@code com.palantir.conjure.defs} definitions.
parseExternalType
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/ConjureParserUtils.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/ConjureParserUtils.java
Apache-2.0
private static boolean isBearerToken(ExternalTypeDefinition externalTypeDefinition) { return externalTypeDefinition .baseType() .equals(com.palantir.conjure.parser.types.primitive.PrimitiveType.BEARERTOKEN); }
Utility methods used to parse {@code com.palantir.conjure.parser} definitions into {@code com.palantir.conjure.defs} definitions.
isBearerToken
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/ConjureParserUtils.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/ConjureParserUtils.java
Apache-2.0
public static TypeName createTypeName( String name, com.palantir.conjure.parser.types.BaseObjectTypeDefinition def, Optional<String> defaultPackage) { TypeName type = TypeName.of(name, parsePackageOrElseThrow(def.conjurePackage(), defaultPackage)); TypeNameValidator.validate(type); return type; }
Utility methods used to parse {@code com.palantir.conjure.parser} definitions into {@code com.palantir.conjure.defs} definitions.
createTypeName
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/ConjureParserUtils.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/ConjureParserUtils.java
Apache-2.0
@Deprecated static ConjureDefinition parseConjureDef(Collection<AnnotatedConjureSourceFile> annotatedParsedDefs) { return parseConjureDef(annotatedParsedDefs.stream() .collect(Collectors.toMap(source -> source.sourceFile().getAbsolutePath(), Function.identity()))); }
Utility methods used to parse {@code com.palantir.conjure.parser} definitions into {@code com.palantir.conjure.defs} definitions.
parseConjureDef
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/ConjureParserUtils.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/ConjureParserUtils.java
Apache-2.0
@Deprecated static ConjureDefinition parseConjureDef(Map<String, AnnotatedConjureSourceFile> annotatedParsedDefs) { return parseConjureDef(annotatedParsedDefs, SafetyDeclarationRequirements.ALLOWED); }
Utility methods used to parse {@code com.palantir.conjure.parser} definitions into {@code com.palantir.conjure.defs} definitions.
parseConjureDef
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/ConjureParserUtils.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/ConjureParserUtils.java
Apache-2.0
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); EndpointErrorResolver endpointErrorResolver = new EndpointErrorResolver( parsed.types().definitions().errors(), parsed.types().definitions().defaultConjurePackage(), 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, endpointErrorResolver, 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; }
Utility methods used to parse {@code com.palantir.conjure.parser} definitions into {@code com.palantir.conjure.defs} definitions.
parseConjureDef
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/ConjureParserUtils.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/ConjureParserUtils.java
Apache-2.0
private static Map<TypeName, TypeDefinition> parseImportObjects( Map<Namespace, ConjureImports> conjureImports, Map<String, AnnotatedConjureSourceFile> externalTypes) { return innerParseImportObjects(conjureImports, externalTypes, new HashSet<>()); }
Utility methods used to parse {@code com.palantir.conjure.parser} definitions into {@code com.palantir.conjure.defs} definitions.
parseImportObjects
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/ConjureParserUtils.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/ConjureParserUtils.java
Apache-2.0
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; }
Utility methods used to parse {@code com.palantir.conjure.parser} definitions into {@code com.palantir.conjure.defs} definitions.
innerParseImportObjects
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/ConjureParserUtils.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/ConjureParserUtils.java
Apache-2.0
static ServiceDefinition parseService( com.palantir.conjure.parser.services.ServiceDefinition parsed, TypeName serviceName, ReferenceTypeResolver typeResolver, EndpointErrorResolver endpointErrorResolver, DealiasingTypeVisitor dealiasingVisitor) { List<EndpointDefinition> endpoints = new ArrayList<>(); parsed.endpoints() .forEach((name, def) -> endpoints.add(ConjureParserUtils.parseEndpoint( name, def, parsed.basePath(), parseAuthType(parsed.defaultAuth()), typeResolver, endpointErrorResolver, dealiasingVisitor))); ServiceDefinition service = ServiceDefinition.builder() .serviceName(serviceName) .docs(parsed.docs().map(Documentation::of)) .addAllEndpoints(endpoints) .build(); ServiceDefinitionValidator.validateAll(service); return service; }
Utility methods used to parse {@code com.palantir.conjure.parser} definitions into {@code com.palantir.conjure.defs} definitions.
parseService
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/ConjureParserUtils.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/ConjureParserUtils.java
Apache-2.0
static Map<TypeName, TypeDefinition> parseObjects( com.palantir.conjure.parser.types.TypesDefinition parsed, ConjureTypeParserVisitor.ReferenceTypeResolver typeResolver) { Optional<String> defaultPackage = parsed.definitions().defaultConjurePackage().map(ConjurePackage::name); // no need to use validator here since TypeDefinitionParserVisitor calls each TypeDefinition parser that // validates its type. return parsed.definitions().objects().entrySet().stream() .map(entry -> entry.getValue() .visit(new TypeDefinitionParserVisitor(entry.getKey().name(), defaultPackage, typeResolver))) .collect(Collectors.toMap(td -> td.accept(TypeDefinitionVisitor.TYPE_NAME), td -> td)); }
Utility methods used to parse {@code com.palantir.conjure.parser} definitions into {@code com.palantir.conjure.defs} definitions.
parseObjects
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/ConjureParserUtils.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/ConjureParserUtils.java
Apache-2.0
static List<ErrorDefinition> parseErrors( NamedTypesDefinition defs, ConjureTypeParserVisitor.ReferenceTypeResolver typeResolver) { Optional<String> defaultPackage = defs.defaultConjurePackage().map(ConjurePackage::name); ImmutableList.Builder<ErrorDefinition> errorsBuidler = ImmutableList.builder(); errorsBuidler.addAll(defs.errors().entrySet().stream() .map(entry -> { TypeName typeName = TypeName.of( entry.getKey().name(), parsePackageOrElseThrow(entry.getValue().conjurePackage(), defaultPackage)); return parseErrorType(typeName, entry.getValue(), typeResolver); }) .collect(Collectors.toList())); return errorsBuidler.build(); }
Utility methods used to parse {@code com.palantir.conjure.parser} definitions into {@code com.palantir.conjure.defs} definitions.
parseErrors
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/ConjureParserUtils.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/ConjureParserUtils.java
Apache-2.0
private static EnumValueDefinition parseEnumValue( com.palantir.conjure.parser.types.complex.EnumValueDefinition def) { EnumValueDefinition enumValue = EnumValueDefinition.builder() .value(def.value()) .docs(def.docs().map(Documentation::of)) .deprecated(def.deprecated().map(Documentation::of)) .build(); EnumValueDefinitionValidator.validateAll(enumValue); return enumValue; }
Utility methods used to parse {@code com.palantir.conjure.parser} definitions into {@code com.palantir.conjure.defs} definitions.
parseEnumValue
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/ConjureParserUtils.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/ConjureParserUtils.java
Apache-2.0
static List<FieldDefinition> parseField( Map< com.palantir.conjure.parser.types.names.FieldName, com.palantir.conjure.parser.types.complex.FieldDefinition> def, ConjureTypeParserVisitor.ReferenceTypeResolver typeResolver) { return def.entrySet().stream() .map(entry -> { FieldDefinition fieldDefinition = FieldDefinition.builder() .fieldName(parseFieldName(entry.getKey())) .type(entry.getValue().type().visit(new ConjureTypeParserVisitor(typeResolver))) .docs(entry.getValue().docs().map(Documentation::of)) .deprecated(entry.getValue().deprecated().map(Documentation::of)) .safety(entry.getValue().safety().map(ConjureParserUtils::parseLogSafety)) .build(); FieldDefinitionValidator.validate(fieldDefinition); return fieldDefinition; }) .collect(Collectors.toList()); }
Utility methods used to parse {@code com.palantir.conjure.parser} definitions into {@code com.palantir.conjure.defs} definitions.
parseField
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/ConjureParserUtils.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/ConjureParserUtils.java
Apache-2.0
@SuppressWarnings("for-rollout:StatementSwitchToExpressionSwitch") private static LogSafety parseLogSafety(LogSafetyDefinition def) { switch (def) { case SAFE: return LogSafety.SAFE; case UNSAFE: return LogSafety.UNSAFE; case DO_NOT_LOG: return LogSafety.DO_NOT_LOG; } throw new ConjureIllegalArgumentException("Unknown log safety type: " + def); }
Utility methods used to parse {@code com.palantir.conjure.parser} definitions into {@code com.palantir.conjure.defs} definitions.
parseLogSafety
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/ConjureParserUtils.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/ConjureParserUtils.java
Apache-2.0
private static FieldName parseFieldName(com.palantir.conjure.parser.types.names.FieldName parserFieldName) { FieldName fieldName = FieldName.of(parserFieldName.name()); FieldNameValidator.validate(fieldName); return fieldName; }
Utility methods used to parse {@code com.palantir.conjure.parser} definitions into {@code com.palantir.conjure.defs} definitions.
parseFieldName
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/ConjureParserUtils.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/ConjureParserUtils.java
Apache-2.0
private static EndpointDefinition parseEndpoint( String name, com.palantir.conjure.parser.services.EndpointDefinition def, PathString basePath, Optional<AuthType> defaultAuth, ReferenceTypeResolver typeResolver, EndpointErrorResolver endpointErrorResolver, 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)))) .errors(def.errors().stream() .map(endpointError -> EndpointError.builder() .error(endpointErrorResolver.resolve(endpointError.error())) .docs(endpointError.docs().map(Documentation::of)) .build()) .toList()) .docs(def.docs().map(Documentation::of)) .deprecated(def.deprecated().map(Documentation::of)) .build(); EndpointDefinitionValidator.validateAll(endpoint, dealiasingVisitor); return endpoint; }
Utility methods used to parse {@code com.palantir.conjure.parser} definitions into {@code com.palantir.conjure.defs} definitions.
parseEndpoint
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/ConjureParserUtils.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/ConjureParserUtils.java
Apache-2.0
private static HttpPath parseHttpPath( com.palantir.conjure.parser.services.EndpointDefinition def, PathString basePath) { HttpPath httpPath = HttpPath.of(basePath.resolve(def.http().path()).toString()); HttpPathValidator.validate(httpPath); return httpPath; }
Utility methods used to parse {@code com.palantir.conjure.parser} definitions into {@code com.palantir.conjure.defs} definitions.
parseHttpPath
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/ConjureParserUtils.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/ConjureParserUtils.java
Apache-2.0
@SuppressWarnings({"for-rollout:StatementSwitchToExpressionSwitch", "for-rollout:UnnecessaryDefaultInEnumSwitch"}) private static Optional<AuthType> parseAuthType( com.palantir.conjure.parser.services.AuthDefinition authDefinition) { switch (authDefinition.type()) { case HEADER: return Optional.of(AuthType.header(HeaderAuthType.of())); case COOKIE: return Optional.of(AuthType.cookie(CookieAuthType.of(authDefinition.id()))); case NONE: return Optional.empty(); default: throw new ConjureIllegalArgumentException("Unrecognized auth type."); } }
Utility methods used to parse {@code com.palantir.conjure.parser} definitions into {@code com.palantir.conjure.defs} definitions.
parseAuthType
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/ConjureParserUtils.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/ConjureParserUtils.java
Apache-2.0
private static List<ArgumentDefinition> parseArgs( Map<ParameterName, com.palantir.conjure.parser.services.ArgumentDefinition> args, HttpPath httpPath, ReferenceTypeResolver typeResolver) { ImmutableList.Builder<ArgumentDefinition> resultBuilder = ImmutableList.builder(); for (Map.Entry<ParameterName, com.palantir.conjure.parser.services.ArgumentDefinition> entry : args.entrySet()) { com.palantir.conjure.parser.services.ArgumentDefinition original = entry.getValue(); ArgumentName argName = ArgumentName.of(entry.getKey().name()); ParameterType paramType = parseParameterType(original, argName, httpPath); ArgumentDefinition.Builder builder = ArgumentDefinition.builder() .argName(argName) .type(original.type().visit(new ConjureTypeParserVisitor(typeResolver))) .paramType(paramType) .docs(original.docs().map(Documentation::of)) .safety(original.safety().map(ConjureParserUtils::parseLogSafety)) .markers(parseMarkers(original.markers(), typeResolver)) .tags(original.tags().stream() .peek(tag -> Preconditions.checkArgument(!tag.isEmpty(), "tag must not be empty")) .collect(Collectors.toSet())); resultBuilder.add(builder.build()); } return resultBuilder.build(); }
Utility methods used to parse {@code com.palantir.conjure.parser} definitions into {@code com.palantir.conjure.defs} definitions.
parseArgs
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/ConjureParserUtils.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/ConjureParserUtils.java
Apache-2.0
@SuppressWarnings({"for-rollout:StatementSwitchToExpressionSwitch", "for-rollout:UnnecessaryDefaultInEnumSwitch"}) private static ParameterType parseParameterType( com.palantir.conjure.parser.services.ArgumentDefinition argumentDef, ArgumentName argName, HttpPath httpPath) { Set<ArgumentName> args = HttpPathValidator.pathArgs(httpPath.get()); switch (argumentDef.paramType()) { case AUTO: // AUTO type if (args.contains(argName)) { // argument exists in request line -- it is a path arg return ParameterType.path(PathParameterType.of()); } else { // argument does not exist in request line -- it is a body arg return ParameterType.body(BodyParameterType.of()); } case HEADER: String headerParamId = argumentDef.paramId().map(ParameterName::name).orElseGet(argName::get); return ParameterType.header(HeaderParameterType.of(ParameterId.of(headerParamId))); case PATH: return ParameterType.path(PathParameterType.of()); case BODY: return ParameterType.body(BodyParameterType.of()); case QUERY: String queryParamId = argumentDef.paramId().map(ParameterName::name).orElseGet(argName::get); return ParameterType.query(QueryParameterType.of(ParameterId.of(queryParamId))); default: throw new ConjureIllegalArgumentException("Unknown parameter type: " + argumentDef.paramType()); } }
Utility methods used to parse {@code com.palantir.conjure.parser} definitions into {@code com.palantir.conjure.defs} definitions.
parseParameterType
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/ConjureParserUtils.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/ConjureParserUtils.java
Apache-2.0
private static Set<Type> parseMarkers( Set<com.palantir.conjure.parser.types.ConjureType> markers, ConjureTypeParserVisitor.ReferenceTypeResolver typeResolver) { return markers.stream() .map(m -> m.visit(new ConjureTypeParserVisitor(typeResolver))) .collect(Collectors.toSet()); }
Utility methods used to parse {@code com.palantir.conjure.parser} definitions into {@code com.palantir.conjure.defs} definitions.
parseMarkers
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/ConjureParserUtils.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/ConjureParserUtils.java
Apache-2.0
@Override public Type resolve(LocalReferenceType reference) { return resolveFromTypeName(reference.type(), types); }
The core translator between parsed/raw types and the IR spec representation exposed to compilers.
resolve
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/ConjureTypeParserVisitor.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/ConjureTypeParserVisitor.java
Apache-2.0
@Override public Type resolve(ForeignReferenceType reference) { String namespaceFile = importProviders.get(reference.namespace()); Preconditions.checkNotNull(namespaceFile, "Import not found for namespace: %s", reference.namespace()); AnnotatedConjureSourceFile externalFile = externalTypes.get(namespaceFile); Preconditions.checkNotNull( externalFile, "File not found for namespace: %s @ %s", reference.namespace(), namespaceFile); return resolveFromTypeName( reference.type(), externalFile.conjureSourceFile().types()); }
The core translator between parsed/raw types and the IR spec representation exposed to compilers.
resolve
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/ConjureTypeParserVisitor.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/ConjureTypeParserVisitor.java
Apache-2.0
private static Type resolveFromTypeName( com.palantir.conjure.parser.types.names.TypeName name, TypesDefinition types) { Optional<String> defaultPackage = types.definitions().defaultConjurePackage().map(ConjureParserUtils::parseConjurePackage); BaseObjectTypeDefinition maybeDirectDef = types.definitions().objects().get(name); String conjurePackage; if (maybeDirectDef == null) { ExternalTypeDefinition maybeExternalDef = types.imports().get(name); if (maybeExternalDef == null) { throw new ConjureIllegalStateException("Unknown LocalReferenceType: " + name); } String externalPath = maybeExternalDef.external().java(); int lastIndex = externalPath.lastIndexOf("."); conjurePackage = externalPath.substring(0, lastIndex); String typeName = externalPath.substring(lastIndex + 1); return ConjureParserUtils.parseExternalType(maybeExternalDef, conjurePackage, typeName); } else { // Conjure-defined object conjurePackage = ConjureParserUtils.parsePackageOrElseThrow(maybeDirectDef.conjurePackage(), defaultPackage); return Type.reference(TypeName.of(name.name(), conjurePackage)); } }
The core translator between parsed/raw types and the IR spec representation exposed to compilers.
resolveFromTypeName
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/ConjureTypeParserVisitor.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/ConjureTypeParserVisitor.java
Apache-2.0
@Override public Type visitAny(AnyType _type) { return Type.primitive(com.palantir.conjure.spec.PrimitiveType.ANY); }
The core translator between parsed/raw types and the IR spec representation exposed to compilers.
visitAny
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/ConjureTypeParserVisitor.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/ConjureTypeParserVisitor.java
Apache-2.0
@Override public Type visitList(ListType type) { return Type.list(com.palantir.conjure.spec.ListType.of(type.itemType().visit(this))); }
The core translator between parsed/raw types and the IR spec representation exposed to compilers.
visitList
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/ConjureTypeParserVisitor.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/ConjureTypeParserVisitor.java
Apache-2.0
@Override public Type visitMap(MapType type) { return Type.map(com.palantir.conjure.spec.MapType.of( type.keyType().visit(this), type.valueType().visit(this))); }
The core translator between parsed/raw types and the IR spec representation exposed to compilers.
visitMap
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/ConjureTypeParserVisitor.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/ConjureTypeParserVisitor.java
Apache-2.0
@Override public Type visitOptional(OptionalType type) { return Type.optional( com.palantir.conjure.spec.OptionalType.of(type.itemType().visit(this))); }
The core translator between parsed/raw types and the IR spec representation exposed to compilers.
visitOptional
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/ConjureTypeParserVisitor.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/ConjureTypeParserVisitor.java
Apache-2.0
@Override public Type visitPrimitive(PrimitiveType type) { return ConjureParserUtils.parsePrimitiveType(type); }
The core translator between parsed/raw types and the IR spec representation exposed to compilers.
visitPrimitive
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/ConjureTypeParserVisitor.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/ConjureTypeParserVisitor.java
Apache-2.0
@Override public Type visitLocalReference(LocalReferenceType type) { return nameResolver.resolve(type); }
The core translator between parsed/raw types and the IR spec representation exposed to compilers.
visitLocalReference
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/ConjureTypeParserVisitor.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/ConjureTypeParserVisitor.java
Apache-2.0
@Override public Type visitForeignReference(ForeignReferenceType type) { return nameResolver.resolve(type); }
The core translator between parsed/raw types and the IR spec representation exposed to compilers.
visitForeignReference
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/ConjureTypeParserVisitor.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/ConjureTypeParserVisitor.java
Apache-2.0
@Override public Type visitSet(SetType type) { return Type.set(com.palantir.conjure.spec.SetType.of(type.itemType().visit(this))); }
The core translator between parsed/raw types and the IR spec representation exposed to compilers.
visitSet
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/ConjureTypeParserVisitor.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/ConjureTypeParserVisitor.java
Apache-2.0
@Override public Type visitBinary(BinaryType _type) { return Type.primitive(com.palantir.conjure.spec.PrimitiveType.BINARY); }
The core translator between parsed/raw types and the IR spec representation exposed to compilers.
visitBinary
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/ConjureTypeParserVisitor.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/ConjureTypeParserVisitor.java
Apache-2.0
@Override public Type visitDateTime(DateTimeType _type) { return Type.primitive(com.palantir.conjure.spec.PrimitiveType.DATETIME); }
The core translator between parsed/raw types and the IR spec representation exposed to compilers.
visitDateTime
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/ConjureTypeParserVisitor.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/ConjureTypeParserVisitor.java
Apache-2.0
ErrorTypeName resolve(ConjureType conjureType) { return conjureType.visit(this); }
Endpoint error definitions are either references to errors defined in the same file as the endpoint definition, or in imported Conjure files. This class creates a {@link com.palantir.conjure.spec.ErrorTypeName} object from a {@link com.palantir.conjure.parser.types.reference.ReferenceType} to a Conjure defined error definition.
resolve
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/EndpointErrorResolver.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/EndpointErrorResolver.java
Apache-2.0
private ErrorTypeName resolveReferenceType(LocalReferenceType localReferenceType) { return resolveInternal(localReferenceType.type(), parsedErrors, defaultConjurePackage); }
Endpoint error definitions are either references to errors defined in the same file as the endpoint definition, or in imported Conjure files. This class creates a {@link com.palantir.conjure.spec.ErrorTypeName} object from a {@link com.palantir.conjure.parser.types.reference.ReferenceType} to a Conjure defined error definition.
resolveReferenceType
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/EndpointErrorResolver.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/EndpointErrorResolver.java
Apache-2.0
private ErrorTypeName resolveReferenceType(ForeignReferenceType foreignReferenceType) { String namespaceFile = importProviders.get(foreignReferenceType.namespace()); Preconditions.checkNotNull( namespaceFile, "Import not found for namespace: %s", foreignReferenceType.namespace()); AnnotatedConjureSourceFile externalFile = externalTypes.get(namespaceFile); Preconditions.checkNotNull( externalFile, "File not found for namespace: %s @ %s", foreignReferenceType.namespace(), namespaceFile); return resolveInternal( foreignReferenceType.type(), externalFile.conjureSourceFile().types().definitions().errors(), externalFile.conjureSourceFile().types().definitions().defaultConjurePackage()); }
Endpoint error definitions are either references to errors defined in the same file as the endpoint definition, or in imported Conjure files. This class creates a {@link com.palantir.conjure.spec.ErrorTypeName} object from a {@link com.palantir.conjure.parser.types.reference.ReferenceType} to a Conjure defined error definition.
resolveReferenceType
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/EndpointErrorResolver.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/EndpointErrorResolver.java
Apache-2.0
private static ErrorTypeName resolveInternal( TypeName name, Map<TypeName, ErrorTypeDefinition> parsedErrorDefinitions, Optional<ConjurePackage> defaultConjurePackage) { ErrorTypeDefinition errorDefinition = parsedErrorDefinitions.get(name); if (errorDefinition == null) { throw new SafeIllegalArgumentException("Unknown error", SafeArg.of("error", name.name())); } return ErrorTypeName.builder() .name(name.name()) .package_(ConjureParserUtils.parsePackageOrElseThrow( errorDefinition.conjurePackage(), defaultConjurePackage.map(ConjureParserUtils::parseConjurePackage))) .namespace(com.palantir.conjure.spec.ErrorNamespace.of( errorDefinition.namespace().name())) .build(); }
Endpoint error definitions are either references to errors defined in the same file as the endpoint definition, or in imported Conjure files. This class creates a {@link com.palantir.conjure.spec.ErrorTypeName} object from a {@link com.palantir.conjure.parser.types.reference.ReferenceType} to a Conjure defined error definition.
resolveInternal
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/EndpointErrorResolver.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/EndpointErrorResolver.java
Apache-2.0
@Override public ErrorTypeName visitAny(AnyType type) { throw new SafeIllegalArgumentException(UNSUPPORTED_TYPE_MESSAGE, SafeArg.of("type", type)); }
Endpoint error definitions are either references to errors defined in the same file as the endpoint definition, or in imported Conjure files. This class creates a {@link com.palantir.conjure.spec.ErrorTypeName} object from a {@link com.palantir.conjure.parser.types.reference.ReferenceType} to a Conjure defined error definition.
visitAny
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/EndpointErrorResolver.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/EndpointErrorResolver.java
Apache-2.0
@Override public ErrorTypeName visitList(ListType type) { throw new SafeIllegalArgumentException(UNSUPPORTED_TYPE_MESSAGE, SafeArg.of("type", type)); }
Endpoint error definitions are either references to errors defined in the same file as the endpoint definition, or in imported Conjure files. This class creates a {@link com.palantir.conjure.spec.ErrorTypeName} object from a {@link com.palantir.conjure.parser.types.reference.ReferenceType} to a Conjure defined error definition.
visitList
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/EndpointErrorResolver.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/EndpointErrorResolver.java
Apache-2.0
@Override public ErrorTypeName visitMap(MapType type) { throw new SafeIllegalArgumentException(UNSUPPORTED_TYPE_MESSAGE, SafeArg.of("type", type)); }
Endpoint error definitions are either references to errors defined in the same file as the endpoint definition, or in imported Conjure files. This class creates a {@link com.palantir.conjure.spec.ErrorTypeName} object from a {@link com.palantir.conjure.parser.types.reference.ReferenceType} to a Conjure defined error definition.
visitMap
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/EndpointErrorResolver.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/EndpointErrorResolver.java
Apache-2.0
@Override public ErrorTypeName visitOptional(OptionalType type) { throw new SafeIllegalArgumentException(UNSUPPORTED_TYPE_MESSAGE, SafeArg.of("type", type)); }
Endpoint error definitions are either references to errors defined in the same file as the endpoint definition, or in imported Conjure files. This class creates a {@link com.palantir.conjure.spec.ErrorTypeName} object from a {@link com.palantir.conjure.parser.types.reference.ReferenceType} to a Conjure defined error definition.
visitOptional
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/EndpointErrorResolver.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/EndpointErrorResolver.java
Apache-2.0
@Override public ErrorTypeName visitPrimitive(PrimitiveType type) { throw new SafeIllegalArgumentException(UNSUPPORTED_TYPE_MESSAGE, SafeArg.of("type", type)); }
Endpoint error definitions are either references to errors defined in the same file as the endpoint definition, or in imported Conjure files. This class creates a {@link com.palantir.conjure.spec.ErrorTypeName} object from a {@link com.palantir.conjure.parser.types.reference.ReferenceType} to a Conjure defined error definition.
visitPrimitive
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/EndpointErrorResolver.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/EndpointErrorResolver.java
Apache-2.0
@Override public ErrorTypeName visitLocalReference(LocalReferenceType type) { return resolveReferenceType(type); }
Endpoint error definitions are either references to errors defined in the same file as the endpoint definition, or in imported Conjure files. This class creates a {@link com.palantir.conjure.spec.ErrorTypeName} object from a {@link com.palantir.conjure.parser.types.reference.ReferenceType} to a Conjure defined error definition.
visitLocalReference
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/EndpointErrorResolver.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/EndpointErrorResolver.java
Apache-2.0
@Override public ErrorTypeName visitForeignReference(ForeignReferenceType type) { return resolveReferenceType(type); }
Endpoint error definitions are either references to errors defined in the same file as the endpoint definition, or in imported Conjure files. This class creates a {@link com.palantir.conjure.spec.ErrorTypeName} object from a {@link com.palantir.conjure.parser.types.reference.ReferenceType} to a Conjure defined error definition.
visitForeignReference
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/EndpointErrorResolver.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/EndpointErrorResolver.java
Apache-2.0
@Override public ErrorTypeName visitSet(SetType type) { throw new SafeIllegalArgumentException(UNSUPPORTED_TYPE_MESSAGE, SafeArg.of("type", type)); }
Endpoint error definitions are either references to errors defined in the same file as the endpoint definition, or in imported Conjure files. This class creates a {@link com.palantir.conjure.spec.ErrorTypeName} object from a {@link com.palantir.conjure.parser.types.reference.ReferenceType} to a Conjure defined error definition.
visitSet
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/EndpointErrorResolver.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/EndpointErrorResolver.java
Apache-2.0
@Override public ErrorTypeName visitBinary(BinaryType type) { throw new SafeIllegalArgumentException(UNSUPPORTED_TYPE_MESSAGE, SafeArg.of("type", type)); }
Endpoint error definitions are either references to errors defined in the same file as the endpoint definition, or in imported Conjure files. This class creates a {@link com.palantir.conjure.spec.ErrorTypeName} object from a {@link com.palantir.conjure.parser.types.reference.ReferenceType} to a Conjure defined error definition.
visitBinary
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/EndpointErrorResolver.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/EndpointErrorResolver.java
Apache-2.0
@Override public ErrorTypeName visitDateTime(DateTimeType type) { throw new SafeIllegalArgumentException(UNSUPPORTED_TYPE_MESSAGE, SafeArg.of("type", type)); }
Endpoint error definitions are either references to errors defined in the same file as the endpoint definition, or in imported Conjure files. This class creates a {@link com.palantir.conjure.spec.ErrorTypeName} object from a {@link com.palantir.conjure.parser.types.reference.ReferenceType} to a Conjure defined error definition.
visitDateTime
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/EndpointErrorResolver.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/EndpointErrorResolver.java
Apache-2.0
@Override public TypeDefinition visit(AliasTypeDefinition def) { return ConjureParserUtils.parseAliasType( ConjureParserUtils.createTypeName(name, def, defaultPackage), def, typeResolver); }
The core translator between parsed/raw type definitions and the IR spec representation exposed to compilers.
visit
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/TypeDefinitionParserVisitor.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/TypeDefinitionParserVisitor.java
Apache-2.0
@Override public TypeDefinition visit(EnumTypeDefinition def) { return ConjureParserUtils.parseEnumType(ConjureParserUtils.createTypeName(name, def, defaultPackage), def); }
The core translator between parsed/raw type definitions and the IR spec representation exposed to compilers.
visit
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/TypeDefinitionParserVisitor.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/TypeDefinitionParserVisitor.java
Apache-2.0
@Override public TypeDefinition visit(ObjectTypeDefinition def) { return ConjureParserUtils.parseObjectType( ConjureParserUtils.createTypeName(name, def, defaultPackage), def, typeResolver); }
The core translator between parsed/raw type definitions and the IR spec representation exposed to compilers.
visit
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/TypeDefinitionParserVisitor.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/TypeDefinitionParserVisitor.java
Apache-2.0
@Override public TypeDefinition visit(UnionTypeDefinition def) { return ConjureParserUtils.parseUnionType( ConjureParserUtils.createTypeName(name, def, defaultPackage), def, typeResolver); }
The core translator between parsed/raw type definitions and the IR spec representation exposed to compilers.
visit
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/TypeDefinitionParserVisitor.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/TypeDefinitionParserVisitor.java
Apache-2.0
@Override public void validate(EndpointDefinition definition, DealiasingTypeVisitor dealiasingTypeVisitor) { validator.validate(definition, dealiasingTypeVisitor); }
Simplified constructor for validators that don't need to look at the context.
validate
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/validator/EndpointDefinitionValidator.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/validator/EndpointDefinitionValidator.java
Apache-2.0
@Override public void validate(EndpointDefinition definition, DealiasingTypeVisitor dealiasingTypeVisitor) { definition.getArgs().stream() .filter(arg -> !arg.getParamType().accept(ParameterTypeVisitor.IS_BODY)) .forEach(arg -> Preconditions.checkArgument( validateType(arg.getType(), dealiasingTypeVisitor), "Non body parameters cannot contain the 'binary' type. " + "Parameter '%s' from endpoint '%s' violates this constraint.", arg.getArgName(), describe(definition))); }
Simplified constructor for validators that don't need to look at the context.
validate
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/validator/EndpointDefinitionValidator.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/validator/EndpointDefinitionValidator.java
Apache-2.0
private static boolean validateType(Type input, DealiasingTypeVisitor dealiasingTypeVisitor) { Optional<Type> dealiased = dealiasingTypeVisitor.dealias(input).fold(_typeDefinition -> Optional.empty(), Optional::of); // typeDef isn't binary if (!dealiased.isPresent()) { return true; } Type type = dealiased.get(); if (input.accept(TypeVisitor.IS_OPTIONAL)) { return validateType(input.accept(TypeVisitor.OPTIONAL).getItemType(), dealiasingTypeVisitor); } if (input.accept(TypeVisitor.IS_LIST)) { return validateType(input.accept(TypeVisitor.LIST).getItemType(), dealiasingTypeVisitor); } if (input.accept(TypeVisitor.IS_SET)) { return validateType(input.accept(TypeVisitor.SET).getItemType(), dealiasingTypeVisitor); } return !type.accept(TypeVisitor.IS_BINARY) && !type.accept(TypeVisitor.IS_ANY); }
Simplified constructor for validators that don't need to look at the context.
validateType
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/validator/EndpointDefinitionValidator.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/validator/EndpointDefinitionValidator.java
Apache-2.0
@Override public void validate(EndpointDefinition definition) { List<ArgumentDefinition> bodyParams = definition.getArgs().stream() .filter(entry -> entry.getParamType().accept(ParameterTypeVisitor.IS_BODY)) .collect(Collectors.toList()); Preconditions.checkState( bodyParams.size() <= 1, "Endpoint '%s' cannot have multiple body parameters: %s", describe(definition), bodyParams.stream().map(ArgumentDefinition::getArgName).collect(Collectors.toList())); }
Simplified constructor for validators that don't need to look at the context.
validate
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/validator/EndpointDefinitionValidator.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/validator/EndpointDefinitionValidator.java
Apache-2.0
@Override public void validate(EndpointDefinition definition) { HttpMethod method = definition.getHttpMethod(); if (method.equals(HttpMethod.GET)) { boolean hasBody = definition.getArgs().stream() .anyMatch(entry -> entry.getParamType().accept(ParameterTypeVisitor.IS_BODY)); Preconditions.checkState( !hasBody, "Endpoint '%s' cannot be a GET and contain a body", describe(definition)); } }
Simplified constructor for validators that don't need to look at the context.
validate
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/validator/EndpointDefinitionValidator.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/validator/EndpointDefinitionValidator.java
Apache-2.0
@Override public void validate(EndpointDefinition definition, DealiasingTypeVisitor dealiasingTypeVisitor) { definition.getArgs().stream() .filter(entry -> entry.getParamType().accept(ParameterTypeVisitor.IS_BODY)) .forEach(entry -> { boolean isOptionalBinary = dealiasingTypeVisitor .dealias(entry.getType()) .fold( _typeDef -> false, // typeDef cannot resolve to optional<binary> NoOptionalBinaryBodyParamValidator::isOptionalBinary); Preconditions.checkState( !isOptionalBinary, "Endpoint BODY argument must not be optional<binary> or alias thereof: %s", describe(definition)); }); }
Simplified constructor for validators that don't need to look at the context.
validate
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/validator/EndpointDefinitionValidator.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/validator/EndpointDefinitionValidator.java
Apache-2.0
private static boolean isOptionalBinary(Type type) { return type.accept(TypeVisitor.IS_OPTIONAL) ? type.accept(TypeVisitor.OPTIONAL).getItemType().accept(TypeVisitor.IS_BINARY) : false; }
Simplified constructor for validators that don't need to look at the context.
isOptionalBinary
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/validator/EndpointDefinitionValidator.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/validator/EndpointDefinitionValidator.java
Apache-2.0
@Override public void validate(EndpointDefinition definition) { String description = describe(definition); Set<ArgumentName> pathParamIds = new HashSet<>(); definition.getArgs().stream() .filter(entry -> entry.getParamType().accept(ParameterTypeVisitor.IS_PATH)) .forEach(entry -> { boolean added = pathParamIds.add(entry.getArgName()); Preconditions.checkState( added, "Path parameter with identifier \"%s\" is defined multiple times for endpoint %s", entry.getArgName().get(), description); }); Set<ArgumentName> pathArgs = HttpPathValidator.pathArgs(definition.getHttpPath().get()); Set<ArgumentName> extraParams = Sets.difference(pathParamIds, pathArgs); Preconditions.checkState( extraParams.isEmpty(), "Path parameters defined in endpoint but not present in path template: %s. " + "Note that the `param-id` is no longer supported and the path template name is always " + "used instead. So make sure the path template name matches the path parameter defined " + "in endpoint %s.", extraParams, description); Set<ArgumentName> missingParams = Sets.difference(pathArgs, pathParamIds); Preconditions.checkState( missingParams.isEmpty(), "Path parameters %s defined path template but not present in endpoint: %s", missingParams, description); }
Simplified constructor for validators that don't need to look at the context.
validate
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/validator/EndpointDefinitionValidator.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/validator/EndpointDefinitionValidator.java
Apache-2.0
@Override public void validate(EndpointDefinition definition, DealiasingTypeVisitor dealiasingTypeVisitor) { definition.getArgs().stream() .filter(entry -> entry.getParamType().accept(ParameterTypeVisitor.IS_PATH)) .forEach(entry -> { Either<TypeDefinition, Type> resolvedType = dealiasingTypeVisitor.dealias(entry.getType()); Boolean isValid = resolvedType.fold( typeDefinition -> typeDefinition.accept(TypeDefinitionVisitor.IS_ENUM), type -> type.accept(TypeVisitor.IS_PRIMITIVE)); Preconditions.checkState( isValid, "Path parameters must be primitives or aliases: \"%s\" is not allowed on endpoint %s", entry.getArgName(), describe(definition)); }); }
Simplified constructor for validators that don't need to look at the context.
validate
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/validator/EndpointDefinitionValidator.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/validator/EndpointDefinitionValidator.java
Apache-2.0
@Override public void validate(EndpointDefinition definition, DealiasingTypeVisitor dealiasingTypeVisitor) { definition.getArgs().stream() .filter(entry -> entry.getParamType().accept(ParameterTypeVisitor.IS_HEADER)) .forEach(headerArgDefinition -> { boolean isValid = recursivelyValidate(headerArgDefinition.getType(), dealiasingTypeVisitor); Preconditions.checkState( isValid, "Header parameters must be enums, primitives, aliases or optional primitive:" + " \"%s\" is not allowed on endpoint %s", headerArgDefinition.getArgName(), describe(definition)); }); }
Simplified constructor for validators that don't need to look at the context.
validate
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/validator/EndpointDefinitionValidator.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/validator/EndpointDefinitionValidator.java
Apache-2.0
private static Boolean recursivelyValidate(Type type, DealiasingTypeVisitor visitor) { return visitor.dealias(type) .fold(typeDefinition -> typeDefinition.accept(TypeDefinitionVisitor.IS_ENUM), subType -> { boolean definedPrimitive = subType.accept(TypeVisitor.IS_PRIMITIVE); boolean optionalPrimitive = subType.accept(TypeVisitor.IS_OPTIONAL) && recursivelyValidate( subType.accept(TypeVisitor.OPTIONAL).getItemType(), visitor); return definedPrimitive || optionalPrimitive; }); }
Simplified constructor for validators that don't need to look at the context.
recursivelyValidate
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/validator/EndpointDefinitionValidator.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/validator/EndpointDefinitionValidator.java
Apache-2.0
@Override public void validate(EndpointDefinition definition, DealiasingTypeVisitor dealiasingTypeVisitor) { definition.getArgs().stream() .filter(entry -> entry.getParamType().accept(ParameterTypeVisitor.IS_QUERY)) .forEach(argDefinition -> { boolean isValid = recursivelyValidate(argDefinition.getType(), dealiasingTypeVisitor, false); Preconditions.checkArgument( isValid, "Query parameters must be enums or primitives when de-aliased, or containers of these" + " (list, sets, optionals): '%s' is not allowed on endpoint '%s'", argDefinition.getArgName(), describe(definition)); }); }
Simplified constructor for validators that don't need to look at the context.
validate
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/validator/EndpointDefinitionValidator.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/validator/EndpointDefinitionValidator.java
Apache-2.0
private static Boolean recursivelyValidate(Type type, DealiasingTypeVisitor visitor, boolean isNested) { return visitor.dealias(type) .fold( typeDefinition -> typeDefinition.accept(TypeDefinitionVisitor.IS_ENUM), subType -> subType.accept(new Type.Visitor<Boolean>() { @Override public Boolean visitPrimitive(PrimitiveType value) { return value.get() != PrimitiveType.Value.ANY; } @Override public Boolean visitOptional(OptionalType value) { return !isNested && recursivelyValidate(value.getItemType(), visitor, true); } @Override public Boolean visitList(ListType value) { return !isNested && recursivelyValidate(value.getItemType(), visitor, true); } @Override public Boolean visitSet(SetType value) { return !isNested && recursivelyValidate(value.getItemType(), visitor, true); } @Override public Boolean visitMap(MapType _value) { return false; } // The cases below should not be handled here, since they implicitly handled by the // DealiasingTypeVisitor above @Override public Boolean visitReference(TypeName _value) { throw new ConjureRuntimeException( "Unexpected type when validating query parameters"); } @Override public Boolean visitExternal(ExternalReference _value) { throw new ConjureRuntimeException( "Unexpected type when validating query parameters"); } @Override public Boolean visitUnknown(String _unknownType) { throw new ConjureRuntimeException( "Unexpected type when validating query parameters"); } })); }
Simplified constructor for validators that don't need to look at the context.
recursivelyValidate
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/validator/EndpointDefinitionValidator.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/validator/EndpointDefinitionValidator.java
Apache-2.0
@Override public Boolean visitPrimitive(PrimitiveType value) { return value.get() != PrimitiveType.Value.ANY; }
Simplified constructor for validators that don't need to look at the context.
visitPrimitive
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/validator/EndpointDefinitionValidator.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/validator/EndpointDefinitionValidator.java
Apache-2.0
@Override public Boolean visitOptional(OptionalType value) { return !isNested && recursivelyValidate(value.getItemType(), visitor, true); }
Simplified constructor for validators that don't need to look at the context.
visitOptional
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/validator/EndpointDefinitionValidator.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/validator/EndpointDefinitionValidator.java
Apache-2.0
@Override public Boolean visitList(ListType value) { return !isNested && recursivelyValidate(value.getItemType(), visitor, true); }
Simplified constructor for validators that don't need to look at the context.
visitList
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/validator/EndpointDefinitionValidator.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/validator/EndpointDefinitionValidator.java
Apache-2.0
@Override public Boolean visitSet(SetType value) { return !isNested && recursivelyValidate(value.getItemType(), visitor, true); }
Simplified constructor for validators that don't need to look at the context.
visitSet
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/validator/EndpointDefinitionValidator.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/validator/EndpointDefinitionValidator.java
Apache-2.0
@Override public Boolean visitMap(MapType _value) { return false; }
Simplified constructor for validators that don't need to look at the context.
visitMap
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/validator/EndpointDefinitionValidator.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/validator/EndpointDefinitionValidator.java
Apache-2.0
@Override public Boolean visitReference(TypeName _value) { throw new ConjureRuntimeException( "Unexpected type when validating query parameters"); }
Simplified constructor for validators that don't need to look at the context.
visitReference
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/validator/EndpointDefinitionValidator.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/validator/EndpointDefinitionValidator.java
Apache-2.0
@Override public Boolean visitExternal(ExternalReference _value) { throw new ConjureRuntimeException( "Unexpected type when validating query parameters"); }
Simplified constructor for validators that don't need to look at the context.
visitExternal
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/validator/EndpointDefinitionValidator.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/validator/EndpointDefinitionValidator.java
Apache-2.0
@Override public Boolean visitUnknown(String _unknownType) { throw new ConjureRuntimeException( "Unexpected type when validating query parameters"); }
Simplified constructor for validators that don't need to look at the context.
visitUnknown
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/validator/EndpointDefinitionValidator.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/validator/EndpointDefinitionValidator.java
Apache-2.0
@Override public void validate(EndpointDefinition definition, DealiasingTypeVisitor dealiasingTypeVisitor) { definition.getArgs().stream() .filter(entry -> entry.getParamType().accept(ParameterTypeVisitor.IS_PATH) || entry.getParamType().accept(ParameterTypeVisitor.IS_QUERY)) .forEach(entry -> Preconditions.checkState( validateType(entry.getType(), dealiasingTypeVisitor), "Path or query parameters of type 'bearertoken' are not allowed as this " + "would introduce a security vulnerability: \"%s\" endpoint \"%s\"", entry.getArgName(), describe(definition))); }
Simplified constructor for validators that don't need to look at the context.
validate
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/validator/EndpointDefinitionValidator.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/validator/EndpointDefinitionValidator.java
Apache-2.0
private static boolean validateType(Type input, DealiasingTypeVisitor dealiasingTypeVisitor) { Optional<Type> dealiased = dealiasingTypeVisitor.dealias(input).fold(_typeDefinition -> Optional.empty(), Optional::of); // typeDef isn't bearertoken if (!dealiased.isPresent()) { return true; } Type type = dealiased.get(); if (input.accept(TypeVisitor.IS_OPTIONAL)) { return validateType(input.accept(TypeVisitor.OPTIONAL).getItemType(), dealiasingTypeVisitor); } if (input.accept(TypeVisitor.IS_LIST)) { return validateType(input.accept(TypeVisitor.LIST).getItemType(), dealiasingTypeVisitor); } if (input.accept(TypeVisitor.IS_SET)) { return validateType(input.accept(TypeVisitor.SET).getItemType(), dealiasingTypeVisitor); } return !type.accept(TypeVisitor.IS_PRIMITIVE) || type.accept(TypeVisitor.PRIMITIVE).get() != PrimitiveType.Value.BEARERTOKEN; }
Simplified constructor for validators that don't need to look at the context.
validateType
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/validator/EndpointDefinitionValidator.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/validator/EndpointDefinitionValidator.java
Apache-2.0
@Override public void validate(EndpointDefinition definition) { definition.getArgs().forEach(arg -> { boolean matches = CaseConverter.CAMEL_CASE_PATTERN.matches( arg.getArgName().get()); Preconditions.checkState( matches, "Parameter names in endpoint paths and service definitions " + "must match pattern %s: %s on endpoint %s", CaseConverter.CAMEL_CASE_PATTERN, arg.getArgName().get(), describe(definition)); }); }
Simplified constructor for validators that don't need to look at the context.
validate
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/validator/EndpointDefinitionValidator.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/validator/EndpointDefinitionValidator.java
Apache-2.0
@Override @SuppressWarnings("Slf4jLogsafeArgs") public void validate(EndpointDefinition definition) { definition.getArgs().forEach(arg -> { ParameterType paramType = arg.getParamType(); if (paramType.accept(ParameterTypeVisitor.IS_BODY) || paramType.accept(ParameterTypeVisitor.IS_PATH)) { // No validation for param-id of body and path parameters, as it is never (de)serialized. } else if (paramType.accept(ParameterTypeVisitor.IS_HEADER)) { ParameterId paramId = paramType.accept(ParameterTypeVisitor.HEADER).getParamId(); Preconditions.checkState( HEADER_PATTERN.matcher(paramId.get()).matches(), "Header parameter id %s on endpoint %s must match pattern %s", paramId.get(), describe(definition), HEADER_PATTERN); Preconditions.checkState( !PROTOCOL_HEADERS.contains(paramId.get()), "Header parameter id %s on endpoint %s should not be one of the protocol headers %s", paramId.get(), describe(definition), PROTOCOL_HEADERS); } else if (paramType.accept(ParameterTypeVisitor.IS_QUERY)) { ParameterId paramId = paramType.accept(ParameterTypeVisitor.QUERY).getParamId(); boolean paramIdIsCamelCase = CaseConverter.CAMEL_CASE_PATTERN.matches(paramId.get()); Preconditions.checkState( paramIdIsCamelCase || CaseConverter.KEBAB_CASE_PATTERN.matches(paramId.get()) || CaseConverter.SNAKE_CASE_PATTERN.matches(paramId.get()), "Query param id %s on endpoint %s must match one of the following patterns: %s", paramId.get(), describe(definition), Arrays.toString(CaseConverter.Case.values())); if (!paramIdIsCamelCase) { log.warn( "Query param ids should be camelCase. kebab-case and snake_case are supported for " + "legacy endpoints only: {} on endpoint {}", paramId.get(), describe(definition)); } } else { throw new IllegalStateException("Validation for paramType does not exist: " + arg.getParamType()); } }); }
Simplified constructor for validators that don't need to look at the context.
validate
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/validator/EndpointDefinitionValidator.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/validator/EndpointDefinitionValidator.java
Apache-2.0
@Override public void validate(EndpointDefinition definition) { Preconditions.checkState( !HttpMethod.Value.UNKNOWN.equals(definition.getHttpMethod().get()), "HTTP method must be (%s), but received '%s' in endpoint '%s'.", HttpMethod.values().stream().map(HttpMethod::toString).collect(Collectors.joining("|")), definition.getHttpMethod().toString(), describe(definition)); }
Simplified constructor for validators that don't need to look at the context.
validate
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/validator/EndpointDefinitionValidator.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/validator/EndpointDefinitionValidator.java
Apache-2.0
@Override public void validate(EndpointDefinition definition) { Set<String> endpointErrorNameAndNamespaces = new HashSet<>(); for (EndpointError endpointErrorDef : definition.getErrors()) { ErrorTypeName errorTypeName = endpointErrorDef.getError(); String errorName = errorTypeName.getName(); String errorNamespace = errorTypeName.getNamespace().get(); String errorUniqueId = errorName + ":" + errorNamespace; Preconditions.checkArgument( endpointErrorNameAndNamespaces.add(errorUniqueId), "Error '%s' with namespace '%s' is declared multiple times in endpoint '%s'", errorName, errorNamespace, describe(definition)); } }
Simplified constructor for validators that don't need to look at the context.
validate
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/validator/EndpointDefinitionValidator.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/validator/EndpointDefinitionValidator.java
Apache-2.0
private static String describe(EndpointDefinition endpoint) { return String.format( "%s{http: %s %s}", endpoint.getEndpointName(), endpoint.getHttpMethod(), endpoint.getHttpPath()); }
Simplified constructor for validators that don't need to look at the context.
describe
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/validator/EndpointDefinitionValidator.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/validator/EndpointDefinitionValidator.java
Apache-2.0
public static String capitalize(FieldName fieldName) { return StringUtils.capitalize(fieldName.get()); }
Converts this {@link FieldName} to an upper camel case string (e.g. myVariant -> MyVariant). Note that the resultant string is no longer a valid {@link FieldName}.
capitalize
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/validator/FieldNameValidator.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/validator/FieldNameValidator.java
Apache-2.0
public static FieldName toCase(FieldName fieldName, CaseConverter.Case targetCase) { return FieldName.of(nameCase(fieldName).convertTo(fieldName.get(), targetCase)); }
Converts this {@link FieldName} to a {@link FieldName} with the given case.
toCase
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/validator/FieldNameValidator.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/validator/FieldNameValidator.java
Apache-2.0
@SuppressWarnings("Slf4jLogsafeArgs") public static void validate(FieldName fieldName) { boolean matchesCamelCase = CaseConverter.CAMEL_CASE_PATTERN.matches(fieldName.get()); if (!matchesCamelCase && !CaseConverter.KEBAB_CASE_PATTERN.matches(fieldName.get()) && !CaseConverter.SNAKE_CASE_PATTERN.matches(fieldName.get())) { // using if-throw instead of Preconditions to avoid recomputing the `Arrays.toString()` every time throw new IllegalArgumentException(String.format( "FieldName \"%s\" must follow one of the following patterns: %s", fieldName, Arrays.toString(Case.values()))); } if (!matchesCamelCase) { log.warn( "{} should be specified in lowerCamelCase. kebab-case and snake_case are supported for " + "legacy endpoints only: {}", FieldName.class, fieldName.get()); } }
Converts this {@link FieldName} to a {@link FieldName} with the given case.
validate
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/validator/FieldNameValidator.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/validator/FieldNameValidator.java
Apache-2.0
private static CaseConverter.Case nameCase(FieldName fieldName) { for (CaseConverter.Case nameCase : CaseConverter.Case.values()) { if (nameCase.getPattern().matches(fieldName.get())) { return nameCase; } } throw new IllegalStateException("Could not find case for FieldName, this is a bug: " + fieldName.get()); }
Converts this {@link FieldName} to a {@link FieldName} with the given case.
nameCase
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/validator/FieldNameValidator.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/validator/FieldNameValidator.java
Apache-2.0
public static Set<ArgumentName> pathArgs(String httpPath) { UriTemplate uriTemplate = new UriTemplate(httpPath); return uriTemplate.getTemplateVariables().stream().map(ArgumentName::of).collect(Collectors.toSet()); }
returns path arguments of the http path.
pathArgs
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/validator/HttpPathValidator.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/validator/HttpPathValidator.java
Apache-2.0
public static void validate(HttpPath httpPath) { Path path = Paths.get(httpPath.get()); Preconditions.checkArgument( path.isAbsolute(), "Conjure paths must be absolute, i.e., start with '/': %s", path); Preconditions.checkArgument( path.getSegments().isEmpty() || !path.isFolder(), "Conjure paths must not end with a '/': %s", path); for (String segment : path.getSegments()) { Preconditions.checkArgument( SEGMENT_PATTERN.matcher(segment).matches() || PARAM_SEGMENT_PATTERN.matcher(segment).matches() || PARAM_REGEX_SEGMENT_PATTERN.matcher(segment).matches(), "Segment %s of path %s did not match required segment patterns %s or parameter name " + "patterns %s or %s", segment, path, SEGMENT_PATTERN, PARAM_SEGMENT_PATTERN, PARAM_REGEX_SEGMENT_PATTERN); } // verify that path template variables are unique Set<String> templateVars = new HashSet<>(); new UriTemplate(path.toString()).getTemplateVariables().forEach(var -> { Preconditions.checkState( !templateVars.contains(var), "Path parameter %s appears more than once in path %s", var, path); templateVars.add(var); }); UriTemplateParser uriTemplateParser = new UriTemplateParser(path.toString()); Map<String, Pattern> nameToPattern = uriTemplateParser.getNameToPattern(); List<String> segments = Splitter.on('/').splitToList(uriTemplateParser.getNormalizedTemplate()); for (int i = 0; i < segments.size(); i++) { String segment = segments.get(i); if (!(segment.startsWith("{") && segment.endsWith("}"))) { // path literal continue; } // variable Pattern varPattern = nameToPattern.get(segment.substring(1, segment.length() - 1)); if (varPattern.equals(UriTemplateParser.TEMPLATE_VALUE_PATTERN)) { // no regular expression specified -- OK continue; } // if regular expression was specified, it must be ".+" or ".*" based on invariant previously enforced Preconditions.checkState( i == segments.size() - 1 || !varPattern.pattern().equals(".*"), "Path parameter %s in path %s specifies regular expression %s, but this regular " + "expression is only permitted if the path parameter is the last segment", segment, path, varPattern); } }
validates if a new instance has the correct syntax.
validate
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/validator/HttpPathValidator.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/validator/HttpPathValidator.java
Apache-2.0
public static String withoutLeadingSlash(String httpPath) { if (httpPath.startsWith("/")) { return httpPath.substring(1); } else { return httpPath; } }
validates if a new instance has the correct syntax.
withoutLeadingSlash
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/validator/HttpPathValidator.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/validator/HttpPathValidator.java
Apache-2.0
@Override public Boolean visitString() { return true; }
Returns whether the type allows safety information.
visitString
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/validator/SafetyValidator.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/validator/SafetyValidator.java
Apache-2.0
@Override public Boolean visitDatetime() { return true; }
Returns whether the type allows safety information.
visitDatetime
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/validator/SafetyValidator.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/validator/SafetyValidator.java
Apache-2.0
@Override public Boolean visitInteger() { return true; }
Returns whether the type allows safety information.
visitInteger
java
palantir/conjure
conjure-core/src/main/java/com/palantir/conjure/defs/validator/SafetyValidator.java
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/validator/SafetyValidator.java
Apache-2.0