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); }
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); }
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); }
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); }
internal SwaggerRouteBuilder(SwaggerRoute swaggerRoute) { Contract.Requires(swaggerRoute != null); _swaggerRoute = swaggerRoute; }