private static void validate(String path) { HttpPathValidator.validate(HttpPath.of(path)); } }
@Override public void validate(EndpointDefinition 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", entry.getArgName().get()); }); 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.", extraParams); Set<ArgumentName> missingParams = Sets.difference(pathArgs, pathParamIds); Preconditions.checkState(missingParams.isEmpty(), "Path parameters defined path template but not present in endpoint: %s", missingParams); } }
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; }
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(id -> id.name()).orElse(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(id -> id.name()).orElse(argName.get()); return ParameterType.query(QueryParameterType.of(ParameterId.of(queryParamId))); default: throw new IllegalArgumentException("Unknown parameter type: " + argumentDef.paramType()); } }