@Override public void validate(ServiceDefinition definition) { Multimap<String, String> pathToEndpoints = ArrayListMultimap.create(); definition.getEndpoints().stream().forEach(entry -> { String methodPath = entry.getHttpMethod().get() + " " + entry.getHttpPath().get(); // normalize all path parameter variables and regular expressions because all path args are treated // as identical for comparisons (paths cannot differ only in the name/regular expression of a path // variable) methodPath = PATHVAR_PATTERN.matcher(methodPath).replaceAll("{arg}"); pathToEndpoints.put(methodPath, entry.getEndpointName().get()); }); pathToEndpoints.keySet().stream().sorted().forEachOrdered(key -> { Collection<String> endpoints = pathToEndpoints.get(key); Preconditions.checkState(endpoints.size() <= 1, "Endpoint \"%s\" is defined by multiple endpoints: %s", key, endpoints.toString()); }); } }
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)) .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; }
private EndpointDefinition.Builder createEndpoint(String paramName) { ArgumentDefinition arg = ArgumentDefinition.builder() .paramType(ParameterType.body(BodyParameterType.of())) .type(Type.primitive(PrimitiveType.STRING)) .argName(ArgumentName.of(paramName)) .build(); return EndpointDefinition.builder() .httpMethod(HttpMethod.POST) .httpPath(HttpPath.of("/a/path")) .args(ImmutableList.of(arg)) .endpointName(EndpointName.of("test")); } }
private EndpointDefinition createEndpoint(ParameterType paramType) { ArgumentDefinition arg = ArgumentDefinition.builder() .argName(PARAMETER_NAME) .paramType(paramType) .type(Type.primitive(PrimitiveType.INTEGER)) .build(); EndpointDefinition definition = EndpointDefinition.builder() .httpMethod(HttpMethod.POST) .httpPath(HttpPath.of("/a/path")) .args(arg) .endpointName(EndpointName.of("test")) .build(); EndpointDefinitionValidator.validateAll(definition, dealiasingVisitor); return definition; } }
private static void validateServiceDefinition(ServiceDefinition serviceDef, Map<TypeName, TypeDefinition> definitionMap) { serviceDef.getEndpoints().stream().forEach(endpoint -> { endpoint.getArgs().stream() .filter(arg -> recursivelyFindNestedOptionals(arg.getType(), definitionMap, false)) .findAny() .ifPresent(arg -> { throw new IllegalStateException( "Illegal nested optionals found in one of the arguments of endpoint " + endpoint.getEndpointName().get()); }); endpoint.getReturns().ifPresent(returnType -> { if (recursivelyFindNestedOptionals(returnType, definitionMap, false)) { throw new IllegalStateException( "Illegal nested optionals found in return type of endpoint " + endpoint.getEndpointName().get()); } }); }); }