Ejemplo n.º 1
0
        protected override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            var response = await base.SendAsync(request, cancellationToken);

            var url       = request.RequestUri.AbsolutePath;
            var operation = _openApiDocument.FindOperation(url, request.Method.Method);

            if (operation == null)
            {
                throw new Exception("operation not present on the api specs");
            }

            var validator  = new RequestValidator();
            var validation = validator.Validate(operation, new HttpMessageAdapter(response, request));

            if (validation.Errors.Any())
            {
                throw new Exception("validation failed");
            }

            return(response);
        }