/// <summary>
 /// Initializes a new instance of the <see cref="DefaultOperationLocator"/> class.
 /// </summary>
 /// <param name="services">The registered Open API Service.</param>
 /// <param name="configuration">The Open API configuration.</param>
 /// <param name="logger">The logger.</param>
 public DefaultOperationLocator(IEnumerable <IOpenApiService> services, IOpenApiConfiguration configuration, ILogger <DefaultOperationLocator> logger)
 {
     this.logger        = logger;
     this.services      = services;
     this.configuration = configuration;
     this.operations    = new Lazy <IDictionary <string, OpenApiServiceOperation> >(() => this.LocateOperations());
 }
 /// <summary>
 /// Creates an instance of the <see cref="OpenApiOperationInvoker{TRequest, TResponse}"/>.
 /// </summary>
 /// <param name="operationLocator">The operation locator.</param>
 /// <param name="parameterBuilder">The parameter builder.</param>
 /// <param name="accessChecker">The access checker.</param>
 /// <param name="exceptionMapper">The exception mapper.</param>
 /// <param name="resultBuilder">The result builder.</param>
 /// <param name="configuration">The <see cref="IOpenApiConfiguration"/>.</param>
 /// <param name="auditContext">The audit context.</param>
 /// <param name="logger">The logger.</param>
 /// <param name="operationsInstrumentation">Operations instrumentation.</param>
 /// <param name="exceptionsInstrumentation">Exceptions instrumentation.</param>
 public OpenApiOperationInvoker(
     IOpenApiServiceOperationLocator operationLocator,
     IOpenApiParameterBuilder <TRequest> parameterBuilder,
     IOpenApiAccessChecker accessChecker,
     IOpenApiExceptionMapper exceptionMapper,
     IOpenApiResultBuilder <TResponse> resultBuilder,
     IOpenApiConfiguration configuration,
     IAuditContext auditContext,
     ILogger <OpenApiOperationInvoker <TRequest, TResponse> > logger,
     IOperationsInstrumentation <OpenApiOperationInvoker <TRequest, TResponse> > operationsInstrumentation,
     IExceptionsInstrumentation <OpenApiOperationInvoker <TRequest, TResponse> > exceptionsInstrumentation)
 {
     this.operationLocator          = operationLocator;
     this.parameterBuilder          = parameterBuilder;
     this.accessChecker             = accessChecker;
     this.exceptionMapper           = exceptionMapper;
     this.resultBuilder             = resultBuilder;
     this.auditContext              = auditContext;
     this.logger                    = logger;
     this.operationsInstrumentation = operationsInstrumentation;
     this.configuration             = configuration;
     this.exceptionsInstrumentation = exceptionsInstrumentation;
 }
        public async Task WhenIHandleARequestFor(string method, string path)
        {
            var parameterBuilder = new Mock <IOpenApiParameterBuilder <object> >();

            parameterBuilder
            .Setup(m => m.BuildParametersAsync(It.IsAny <object>(), this.operationPathTemplate !))
            .Returns(Task.FromResult <IDictionary <string, object> >(new Dictionary <string, object>()));

            this.InvokerContext.ExceptionMapper
            .Setup(m => m.GetResponse(It.IsAny <Exception>(), It.IsAny <OpenApiOperation>()))
            .Returns(this.exceptionMapperResult);

            this.InvokerContext.ResultBuilder
            .Setup(m => m.BuildResult(It.IsAny <object>(), this.openApiOperation !))
            .Returns(this.resultBuilderResult);
            this.InvokerContext.ResultBuilder
            .Setup(m => m.BuildErrorResult(It.IsAny <int>()))
            .Returns(this.resultBuilderErrorResult);

            IOpenApiConfiguration configuration = ContainerBindings.GetServiceProvider(this.scenarioContext).GetRequiredService <IOpenApiConfiguration>();

            if (this.responseWhenUnauthenticated.HasValue)
            {
                configuration.AccessPolicyUnauthenticatedResponse = this.responseWhenUnauthenticated.Value;
            }

            this.InvokerContext.UseManualAccessChecks();

            this.invokerResultTask = this.Invoker.InvokeAsync(
                path,
                method,
                new object(),
                this.operationPathTemplate !,
                this.openApiContext.Object);

            await this.InvokerContext.AccessCheckCalls !.WaitAsync().WithTimeout().ConfigureAwait(false);
        }
Exemple #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="OpenApiServiceOperation"/> class.
        /// </summary>
        /// <param name="service">The service hosting the operation.</param>
        /// <param name="operation">The operation.</param>
        /// <param name="configuration">The OpenAPI configuration.</param>
        public OpenApiServiceOperation(IOpenApiService service, MethodInfo operation, IOpenApiConfiguration configuration)
        {
            this.service       = service ?? throw new ArgumentNullException(nameof(service));
            this.operation     = operation ?? throw new ArgumentNullException(nameof(operation));
            this.configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
            ParameterInfo[] parameters = this.operation.GetParameters();
            this.defaultValues    = new object[parameters.Length];
            this.hasDefaultValues = new bool[parameters.Length];
            this.parameterNames   = new string[parameters.Length];

            for (int i = 0; i < parameters.Length; ++i)
            {
                ParameterInfo parameter = parameters[i];

                if (parameter.HasDefaultValue)
                {
                    this.hasDefaultValues[i] = true;
                    this.defaultValues[i]    = parameter.DefaultValue;
                }

                OpenApiParameterAttribute parameterAttribute = parameter.GetCustomAttribute <OpenApiParameterAttribute>();
                this.parameterNames[i] = parameterAttribute?.ParameterName ?? parameter.Name;
            }
        }
Exemple #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FloatConverter"/> class.
 /// </summary>
 /// <param name="validator">The <see cref="OpenApiSchemaValidator"/>.</param>
 /// <param name="configuration">The OpenAPI host configuration.</param>
 public FloatConverter(OpenApiSchemaValidator validator, IOpenApiConfiguration configuration)
 {
     this.validator     = validator;
     this.configuration = configuration;
 }
Exemple #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ObjectConverter"/> class.
 /// </summary>
 /// <param name="serviceProvider">The service provider that can supply type information.</param>
 /// <param name="validator">The <see cref="OpenApiSchemaValidator"/>.</param>
 /// <param name="configuration">The OpenAPI host configuration.</param>
 public ObjectConverter(IServiceProvider serviceProvider, OpenApiSchemaValidator validator, IOpenApiConfiguration configuration)
 {
     this.serviceProvider = serviceProvider;
     this.validator       = validator;
     this.configuration   = configuration;
 }
Exemple #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ConsoleAuditLogSink"/> class.
 /// </summary>
 /// <param name="openApiConfiguration">The OpenApi configuration.</param>
 public ConsoleAuditLogSink(IOpenApiConfiguration openApiConfiguration)
 {
     this.openApiConfiguration = openApiConfiguration;
 }