private object GetRequest(IHttpRequest httpReq, IRestPath restPath) { try { var requestDto = GetCustomRequestFromBinder(httpReq, restPath.RequestType); if (requestDto != null) { return(requestDto); } string supportedContentType = httpReq.GetSupportedContentType(ResponseContentType); requestDto = CreateContentTypeRequest(httpReq, restPath.RequestType, supportedContentType ?? httpReq.ContentType); string contentType; var pathInfo = !restPath.IsWildCardPath ? GetSanitizedPathInfo(httpReq.PathInfo, out contentType) : httpReq.PathInfo; var requestParams = httpReq.GetRequestParams(); return(restPath.CreateRequestObject(pathInfo, requestParams, requestDto)); } catch (SerializationException e) { throw new RequestBindingException("Unable to bind request: " + e, e); } catch (ArgumentException e) { throw new RequestBindingException("Unable to bind request: " + e, e); } }
private static object GetRequest(IRequest httpReq, IRestPath restPath) { var requestType = restPath.RequestType; using (Profiler.Current.Step("Deserialize Request")) { try { var requestDto = GetCustomRequestFromBinder(httpReq, requestType); if (requestDto != null) { return(requestDto); } var requestParams = httpReq.GetRequestParams(); requestDto = CreateContentTypeRequest(httpReq, requestType, httpReq.ContentType); string contentType; var pathInfo = !restPath.IsWildCardPath ? GetSanitizedPathInfo(httpReq.PathInfo, out contentType) : httpReq.PathInfo; return(restPath.CreateRequest(pathInfo, requestParams, requestDto)); } catch (SerializationException e) { throw new RequestBindingException("Unable to bind request", e); } catch (ArgumentException e) { throw new RequestBindingException("Unable to bind request", e); } } }
private OpenApiSchema GetResponseSchema(IRestPath restPath, IDictionary <string, OpenApiSchema> schemas) { // Given: class MyDto : IReturn<X>. Determine the type X. foreach (var i in restPath.RequestType.GetInterfaces()) { if (i.IsGenericType() && i.GetGenericTypeDefinition() == typeof(IReturn <>)) { var schemaType = i.GetGenericArguments()[0]; ParseDefinitions(schemas, schemaType, null, null); var schema = GetDictionarySchema(schemas, schemaType, null, null) ?? GetKeyValuePairSchema(schemas, schemaType, null, null) ?? GetListSchema(schemas, schemaType, null, null) ?? (IsSwaggerScalarType(schemaType) ? new OpenApiSchema { Type = GetSwaggerTypeName(schemaType), Format = GetSwaggerTypeFormat(schemaType) } : new OpenApiSchema { Ref = "#/definitions/" + GetSchemaTypeName(schemaType) }); return(schema); } } return(new OpenApiSchema { Ref = "#/definitions/Object" }); }
public static object CreateRequest(IRequest httpReq, IRestPath restPath) { using (Profiler.Current.Step("Deserialize Request")) { try { var dtoFromBinder = GetCustomRequestFromBinder(httpReq, restPath.RequestType); if (dtoFromBinder != null) { return(dtoFromBinder); } var requestParams = httpReq.GetRequestParams(); return(CreateRequest(httpReq, restPath, requestParams)); } catch (SerializationException e) { throw new RequestBindingException("Unable to bind request", e); } catch (ArgumentException e) { throw new RequestBindingException("Unable to bind request", e); } } }
private string GetResponseClass(IRestPath restPath, IDictionary <string, SwaggerModel> models) { var returnType = restPath.ServiceMethod.ReturnType; // Handle IReturn<List<SomeClass>> or IReturn<SomeClass[]> if (IsListType(returnType)) { var listItemType = GetListElementType(returnType); ParseResponseModel(models, listItemType); return(string.Format("List[{0}]", GetSwaggerTypeName(listItemType))); } ParseResponseModel(models, returnType); return(GetSwaggerTypeName(returnType)); //return restPath.RequestType.Name; // Given: class MyDto : IReturn<X>. Determine the type X. //foreach (var i in restPath.RequestType.GetInterfaces()) //{ // if (i.IsGenericType) // { // var returnType = i.GetGenericArguments()[0]; // // Handle IReturn<List<SomeClass>> or IReturn<SomeClass[]> // if (IsListType(returnType)) // { // var listItemType = GetListElementType(returnType); // ParseResponseModel(models, listItemType); // return string.Format("List[{0}]", GetSwaggerTypeName(listItemType)); // } // ParseResponseModel(models, returnType); // return GetSwaggerTypeName(i.GetGenericArguments()[0]); // } //} // return null; }
public static object CreateRequest(IRequest httpReq, IRestPath restPath, Dictionary <string, string> requestParams, object requestDto) { var pathInfo = !restPath.IsWildCardPath ? GetSanitizedPathInfo(httpReq.PathInfo, out _) : httpReq.PathInfo; return(restPath.CreateRequest(pathInfo, requestParams, requestDto)); }
public IRestPath GetRestPath(string httpMethod, string pathInfo) { if (this.RestPath == null) { this.RestPath = FindMatchingRestPath(httpMethod, pathInfo); } return this.RestPath; }
private static object GetRequest(IHttpRequest httpReq, IRestPath restPath) { using (Profiler.Current.Step("Deserialize Request")) { var requestParams = httpReq.GetRequestParams(); var requestDto = CreateContentTypeRequest(httpReq, restPath.RequestType, httpReq.ContentType); return(restPath.CreateRequest(httpReq.PathInfo, requestParams, requestDto)); } }
public static object CreateRequest(IRequest httpReq, IRestPath restPath, Dictionary <string, string> requestParams) { var requestDto = CreateContentTypeRequest(httpReq, restPath.RequestType, httpReq.ContentType); string contentType; var pathInfo = !restPath.IsWildCardPath ? GetSanitizedPathInfo(httpReq.PathInfo, out contentType) : httpReq.PathInfo; return(restPath.CreateRequest(pathInfo, requestParams, requestDto)); }
public static object CreateRequest(IRequest httpReq, IRestPath restPath) { using (Profiler.Current.Step("Deserialize Request")) { var dtoFromBinder = GetCustomRequestFromBinder(httpReq, restPath.RequestType); if (dtoFromBinder != null) { return(HostContext.AppHost.ApplyRequestConverters(httpReq, dtoFromBinder)); } var requestParams = httpReq.GetFlattenedRequestParams(); return(HostContext.AppHost.ApplyRequestConverters(httpReq, CreateRequest(httpReq, restPath, requestParams))); } }
public static async Task<object> CreateRequestAsync(IRequest httpReq, IRestPath restPath) { if (restPath == null) throw new ArgumentNullException(nameof(restPath)); using (Profiler.Current.Step("Deserialize Request")) { var dtoFromBinder = GetCustomRequestFromBinder(httpReq, restPath.RequestType); if (dtoFromBinder != null) return await HostContext.AppHost.ApplyRequestConvertersAsync(httpReq, dtoFromBinder); var requestParams = httpReq.GetFlattenedRequestParams(); return await HostContext.AppHost.ApplyRequestConvertersAsync(httpReq, CreateRequest(httpReq, restPath, requestParams)); } }
private static object GetRequest(IHttpRequest httpReq, IRestPath restPath) { var requestParams = httpReq.GetRequestParams(); object requestDto = null; if (!string.IsNullOrEmpty(httpReq.ContentType) && httpReq.ContentLength > 0) { var requestDeserializer = EndpointHost.AppHost.ContentTypeFilters.GetStreamDeserializer(httpReq.ContentType); if (requestDeserializer != null) { requestDto = requestDeserializer(restPath.RequestType, httpReq.InputStream); } } return(restPath.CreateRequest(httpReq.PathInfo, requestParams, requestDto)); }
private static object GetRequest(IHttpRequest httpReq, IRestPath restPath) { var requestType = restPath.RequestType; using (Profiler.Current.Step("Deserialize Request")) { var requestDto = GetCustomRequestFromBinder(httpReq, requestType); if (requestDto != null) { return(requestDto); } var requestParams = httpReq.GetRequestParams(); requestDto = CreateContentTypeRequest(httpReq, requestType, httpReq.ContentType); return(restPath.CreateRequest(httpReq.PathInfo, requestParams, requestDto)); } }
private OpenApiSchema GetResponseSchema(IRestPath restPath, IDictionary <string, OpenApiSchema> schemas, out string schemaDescription) { schemaDescription = string.Empty; // Given: class MyDto : IReturn<X>. Determine the type X. foreach (var i in restPath.RequestType.GetInterfaces()) { if (i.IsGenericType() && i.GetGenericTypeDefinition() == typeof(IReturn <>)) { var schemaType = i.GetGenericArguments()[0]; return(GetSchemaForResponseType(schemaType, schemas, out schemaDescription)); } } return(new OpenApiSchema { Ref = "#/definitions/Object" }); }
private OrderedDictionary <string, OpenApiResponse> GetMethodResponseCodes(IRestPath restPath, IDictionary <string, OpenApiSchema> schemas, Type requestType) { var responses = new OrderedDictionary <string, OpenApiResponse>(); var responseSchema = GetResponseSchema(restPath, schemas, out string schemaDescription); //schema is null when return type is IReturnVoid var statusCode = responseSchema == null && HostConfig.Instance.Return204NoContentForEmptyResponse ? ((int)HttpStatusCode.NoContent).ToString() : ((int)HttpStatusCode.OK).ToString(); responses.Add(statusCode, new OpenApiResponse { Schema = responseSchema, Description = !string.IsNullOrEmpty(schemaDescription) ? schemaDescription : "Success" }); foreach (var attr in requestType.AllAttributes <ApiResponseAttribute>()) { string apiSchemaDescription = string.Empty; var response = new OpenApiResponse { Schema = attr.ResponseType != null ? GetSchemaForResponseType(attr.ResponseType, schemas, out apiSchemaDescription) : responseSchema, Description = attr.Description ?? apiSchemaDescription }; statusCode = attr.IsDefaultResponse ? "default" : attr.StatusCode.ToString(); if (!responses.ContainsKey(statusCode)) { responses.Add(statusCode, response); } else { responses[statusCode] = response; } } return(responses); }
private OrderedDictionary <string, OpenApiResponse> GetMethodResponseCodes(IRestPath restPath, IDictionary <string, OpenApiSchema> schemas, Type requestType) { var responses = new OrderedDictionary <string, OpenApiResponse>(); var responseSchema = GetResponseSchema(restPath, schemas); responses.Add("default", new OpenApiResponse { Schema = responseSchema, Description = string.Empty //TODO: description }); foreach (var attr in requestType.AllAttributes <ApiResponseAttribute>()) { responses.Add(attr.StatusCode.ToString(), new OpenApiResponse { Description = attr.Description, }); } return(responses); }
public static async Task <object> CreateRequestAsync(IRequest httpReq, IRestPath restPath) { //using (Profiler.Current.Step("Deserialize Request")) { var dtoFromBinder = GetCustomRequestFromBinder(httpReq, restPath.RequestType); if (dtoFromBinder != null) { return(await HostContext.AppHost.ApplyRequestConvertersAsync(httpReq, dtoFromBinder)); } var requestParams = httpReq.GetFlattenedRequestParams(); if (Log.IsDebugEnabled) { Log.DebugFormat("CreateRequestAsync/requestParams:" + string.Join(",", requestParams.Keys)); } var ret = await HostContext.AppHost.ApplyRequestConvertersAsync(httpReq, await CreateRequestAsync(httpReq, restPath, requestParams)); return(ret); } }
private static string GetResponseClass(IRestPath restPath, IDictionary <string, SwaggerModel> models) { // Given: class MyDto : IReturn<X>. Determine the type X. foreach (var i in restPath.RequestType.GetInterfaces()) { if (i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IReturn <>)) { var returnType = i.GetGenericArguments()[0]; // Handle IReturn<List<SomeClass>> or IReturn<SomeClass[]> if (IsListType(returnType)) { var listItemType = GetListElementType(returnType); ParseModel(models, listItemType); return(string.Format("List[{0}]", GetSwaggerTypeName(listItemType))); } ParseModel(models, returnType); return(GetSwaggerTypeName(i.GetGenericArguments()[0])); } } return(null); }
private string GetResponseClass(IRestPath restPath, IDictionary<string, SwaggerModel> models) { // Given: class MyDto : IReturn<X>. Determine the type X. foreach (var i in restPath.RequestType.GetInterfaces()) { if (i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IReturn<>)) { var returnType = i.GetGenericArguments()[0]; // Handle IReturn<List<SomeClass>> or IReturn<SomeClass[]> if (IsListType(returnType)) { var listItemType = GetListElementType(returnType); ParseResponseModel(models, listItemType); return string.Format("List[{0}]", GetSwaggerTypeName(listItemType)); } ParseResponseModel(models, returnType); return GetSwaggerTypeName(i.GetGenericArguments()[0]); } } return null; }
private object GetRequest(IHttpRequest httpReq, IRestPath restPath) { var requestParams = httpReq.GetRequestParams(); object requestDto = null; if (!string.IsNullOrEmpty(httpReq.ContentType) && httpReq.ContentLength > 0) { var requestDeserializer = GetContentFilters().GetStreamDeserializer(httpReq.ContentType); if (requestDeserializer != null) { requestDto = requestDeserializer(restPath.RequestType, httpReq.InputStream); } } return restPath.CreateRequest(httpReq.PathInfo, requestParams, requestDto); }
public static object CreateRequest(IRequest httpReq, IRestPath restPath) { using (Profiler.Current.Step("Deserialize Request")) { var dtoFromBinder = GetCustomRequestFromBinder(httpReq, restPath.RequestType); if (dtoFromBinder != null) return HostContext.AppHost.ApplyRequestConverters(httpReq, dtoFromBinder); var requestParams = httpReq.GetFlattenedRequestParams(); return HostContext.AppHost.ApplyRequestConverters(httpReq, CreateRequest(httpReq, restPath, requestParams)); } }
private static object GetRequest(IHttpRequest httpReq, IRestPath restPath) { var requestType = restPath.RequestType; using (Profiler.Current.Step("Deserialize Request")) { var requestDto = GetCustomRequestFromBinder(httpReq, requestType); if (requestDto != null) return requestDto; var requestParams = httpReq.GetRequestParams(); requestDto = CreateContentTypeRequest(httpReq, requestType, httpReq.ContentType); return restPath.CreateRequest(httpReq.PathInfo, requestParams, requestDto); } }
public static object CreateRequest(IRequest httpReq, IRestPath restPath, Dictionary<string, string> requestParams, object requestDto) { string contentType; var pathInfo = !restPath.IsWildCardPath ? GetSanitizedPathInfo(httpReq.PathInfo, out contentType) : httpReq.PathInfo; return restPath.CreateRequest(pathInfo, requestParams, requestDto); }
public static object CreateRequest(IRequest httpReq, IRestPath restPath, Dictionary<string, string> requestParams) { var requestDto = CreateContentTypeRequest(httpReq, restPath.RequestType, httpReq.ContentType); return CreateRequest(httpReq, restPath, requestParams, requestDto); }
public static object CreateRequest(IRequest httpReq, IRestPath restPath) { using (Profiler.Current.Step("Deserialize Request")) { try { var dtoFromBinder = GetCustomRequestFromBinder(httpReq, restPath.RequestType); if (dtoFromBinder != null) return HostContext.AppHost.ApplyRequestConverters(httpReq, dtoFromBinder); var requestParams = httpReq.GetRequestParams(); return HostContext.AppHost.ApplyRequestConverters(httpReq, CreateRequest(httpReq, restPath, requestParams)); } catch (SerializationException e) { throw new RequestBindingException("Unable to bind request", e); } catch (ArgumentException e) { throw new RequestBindingException("Unable to bind request", e); } } }
private static object GetRequest(IHttpRequest httpReq, IRestPath restPath) { using (Profiler.Current.Step("Deserialize Request")) { var requestParams = httpReq.GetRequestParams(); object requestDto = null; if (!string.IsNullOrEmpty(httpReq.ContentType) && httpReq.ContentLength > 0) { var requestDeserializer = EndpointHost.AppHost.ContentTypeFilters.GetStreamDeserializer(httpReq.ContentType); if (requestDeserializer != null) { requestDto = requestDeserializer(restPath.RequestType, httpReq.InputStream); } } return restPath.CreateRequest(httpReq.PathInfo, requestParams, requestDto); } }
public static async Task <object> CreateRequestAsync(IRequest httpReq, IRestPath restPath, Dictionary <string, string> requestParams) { var requestDto = await CreateContentTypeRequestAsync(httpReq, restPath.RequestType, httpReq.ContentType); return(CreateRequest(httpReq, restPath, requestParams, requestDto)); }
public static object CreateRequest(IRequest httpReq, IRestPath restPath, Dictionary <string, string> requestParams) { var requestDto = CreateContentTypeRequest(httpReq, restPath.RequestType, httpReq.ContentType); return(CreateRequest(httpReq, restPath, requestParams, requestDto)); }
private static object GetRequest(IHttpRequest httpReq, IRestPath restPath) { var requestType = restPath.RequestType; using (Profiler.Current.Step("Deserialize Request")) { try { var requestDto = GetCustomRequestFromBinder(httpReq, requestType); if (requestDto != null) return requestDto; var requestParams = httpReq.GetRequestParams(); requestDto = CreateContentTypeRequest(httpReq, requestType, httpReq.ContentType); string contentType; var pathInfo = !restPath.IsWildCardPath ? GetSanitizedPathInfo(httpReq.PathInfo, out contentType) : httpReq.PathInfo; return restPath.CreateRequest(pathInfo, requestParams, requestDto); } catch (SerializationException e) { throw new RequestBindingException("Unable to bind request", e); } catch (ArgumentException e) { throw new RequestBindingException("Unable to bind request", e); } } }