예제 #1
0
        private static IEnumerable <ODataActionDescriptor> GetActionDescriptors(SwaggerRoute potentialSwaggerRoute, HttpConfiguration httpConfig)
        {
            Contract.Requires(potentialSwaggerRoute != null);
            Contract.Requires(httpConfig != null);

            var oDataActionDescriptors = new List <ODataActionDescriptor>();

            oDataActionDescriptors.AddIfNotNull(GetActionDescriptors(new HttpMethod("DELETE"), potentialSwaggerRoute.PathItem.delete, potentialSwaggerRoute, httpConfig));
            oDataActionDescriptors.AddIfNotNull(GetActionDescriptors(new HttpMethod("GET"), potentialSwaggerRoute.PathItem.get, potentialSwaggerRoute, httpConfig));
            oDataActionDescriptors.AddIfNotNull(GetActionDescriptors(new HttpMethod("POST"), potentialSwaggerRoute.PathItem.post, potentialSwaggerRoute, httpConfig));
            oDataActionDescriptors.AddIfNotNull(GetActionDescriptors(new HttpMethod("PUT"), potentialSwaggerRoute.PathItem.put, potentialSwaggerRoute, httpConfig));
            oDataActionDescriptors.AddIfNotNull(GetActionDescriptors(new HttpMethod("PATCH"), potentialSwaggerRoute.PathItem.patch, potentialSwaggerRoute, httpConfig));

            return(oDataActionDescriptors);
        }
예제 #2
0
        private static ODataPath GenerateSampleODataPath(Operation operation, SwaggerRoute swaggerRoute, IServiceProvider rootContainer)
        {
            Contract.Requires(operation != null);
            Contract.Requires(swaggerRoute != null);
            Contract.Requires(swaggerRoute.ODataRoute.Constraints != null);
            Contract.Ensures(Contract.Result <ODataPath>() != null);

            var pathHandler = rootContainer.GetRequiredService <IODataPathHandler>();

            Contract.Assume(pathHandler != null);

            var odataPath = operation.GenerateSampleODataUri(ServiceRoot, swaggerRoute.Template).Replace(ServiceRoot, string.Empty);

            var result = pathHandler.Parse(ServiceRoot, odataPath, rootContainer);

            Contract.Assume(result != null);
            return(result);
        }
예제 #3
0
        private static HttpRequestMessage CreateHttpRequestMessage(HttpMethod httpMethod, Operation potentialOperation, SwaggerRoute potentialSwaggerRoute, HttpConfiguration httpConfig)
        {
            Contract.Requires(httpConfig != null);
            Contract.Requires(potentialSwaggerRoute != null);
            Contract.Ensures(Contract.Result <HttpRequestMessage>() != null);

            Contract.Assume(potentialSwaggerRoute.ODataRoute.Constraints != null);

            var oDataAbsoluteUri = potentialOperation.GenerateSampleODataUri(ServiceRoot, potentialSwaggerRoute.PrefixedTemplate);
            var oDataRoute       = potentialSwaggerRoute.ODataRoute;

            var httpRequestMessage = new HttpRequestMessage(httpMethod, oDataAbsoluteUri);
            var odataPath          = GenerateSampleODataPath(potentialOperation, potentialSwaggerRoute, httpConfig.GetODataRootContainer(oDataRoute));

            var requestContext = new HttpRequestContext {
                Configuration = httpConfig
            };

            httpRequestMessage.SetConfiguration(httpConfig);
            httpRequestMessage.SetRequestContext(requestContext);
            var httpRequestMessageProperties = httpRequestMessage.ODataProperties();

            Contract.Assume(httpRequestMessageProperties != null);
            httpRequestMessageProperties.Path = odataPath;

            httpRequestMessage.SetRouteData(BuildRouteData(oDataRoute, httpRequestMessage));
            return(httpRequestMessage);
        }
예제 #4
0
        private static ODataActionDescriptor GetActionDescriptors(HttpMethod httpMethod, Operation potentialOperation, SwaggerRoute potentialSwaggerRoute, HttpConfiguration httpConfig)
        {
            Contract.Requires(potentialOperation == null || httpConfig != null);
            Contract.Requires(potentialSwaggerRoute != null);

            if (potentialOperation != null)
            {
                var request = CreateHttpRequestMessage(httpMethod, potentialOperation, potentialSwaggerRoute, httpConfig);

                var actionDescriptor = request.GetHttpActionDescriptor(httpConfig);

                if (actionDescriptor != null)
                {
                    actionDescriptor = MapForRestierIfNecessary(request, actionDescriptor);

                    return(new ODataActionDescriptor(actionDescriptor, potentialSwaggerRoute.ODataRoute, potentialSwaggerRoute.PrefixedTemplate, request, potentialOperation));
                }
            }

            return(null);
        }
예제 #5
0
        internal SwaggerRouteBuilder(SwaggerRoute swaggerRoute)
        {
            Contract.Requires(swaggerRoute != null);

            _swaggerRoute = swaggerRoute;
        }