private string GetParameterBindingAttribute(OperationModel operation, ParameterModel parameter) { if (parameter.GetParameterSettings().Source().IsDefault()) { if ((operation.GetHttpSettings().Verb().IsGET() || operation.GetHttpSettings().Verb().IsDELETE()) && (!parameter.TypeReference.Element.IsTypeDefinitionModel())) { return("[FromQuery]"); } if ((operation.GetHttpSettings().Verb().IsPOST() || operation.GetHttpSettings().Verb().IsPUT()) && (!parameter.TypeReference.Element.IsTypeDefinitionModel())) { return("[FromBody]"); } if (parameter.TypeReference.Element.IsTypeDefinitionModel() && operation.GetHttpSettings().Route()?.Contains($"{{{parameter.Name}}}") == true) { return("[FromRoute]"); } return(""); } if (parameter.GetParameterSettings().Source().IsFromBody()) { return("[FromBody]"); } if (parameter.GetParameterSettings().Source().IsFromHeader()) { return("[FromHeader]"); } if (parameter.GetParameterSettings().Source().IsFromQuery()) { return("[FromQuery]"); } if (parameter.GetParameterSettings().Source().IsFromRoute()) { return("[FromRoute]"); } return(""); }
private string GetParameterBindingAttribute(OperationModel operation, ParameterModel parameter) { if (parameter.GetParameterSettings().Source().IsDefault()) { if ((GetTypeInfo(parameter.TypeReference).IsPrimitive || GetTypeInfo(parameter.TypeReference).Name == "String") && !parameter.TypeReference.IsCollection) { if (GetPath(operation) != null && GetPath(operation).Split('/', StringSplitOptions.RemoveEmptyEntries).Any(x => x.Contains('{') && x.Contains('}') && x.Split(new[] { '{', '}' }, StringSplitOptions.RemoveEmptyEntries).Any(i => i == parameter.Name))) { return($"@PathVariable(value = \"{parameter.Name}\"{(parameter.Type.IsNullable ? $", required = {parameter.TypeReference.IsNullable.ToString().ToLower()}" : "")}) "); } return($"@RequestParam(value = \"{parameter.Name}\"{(parameter.Type.IsNullable ? $", required = {parameter.TypeReference.IsNullable.ToString().ToLower()}" : "")}) "); } if (GetHttpVerb(operation) == HttpVerb.POST || GetHttpVerb(operation) == HttpVerb.PUT) { return("@RequestBody "); } return(""); } if (parameter.GetParameterSettings().Source().IsFromBody()) { return(""); } if (parameter.GetParameterSettings().Source().IsFromHeader()) { return("@RequestHeader "); } if (parameter.GetParameterSettings().Source().IsFromQuery()) { return($"@RequestParam(value = \"{parameter.Name}\"{(parameter.Type.IsNullable ? $", required = {parameter.TypeReference.IsNullable.ToString().ToLower()}" : "")}) "); } if (parameter.GetParameterSettings().Source().IsFromRoute()) { return($"@PathVariable(value = \"{parameter.Name}\"{(parameter.Type.IsNullable ? $", required = {parameter.TypeReference.IsNullable.ToString().ToLower()}" : "")}) "); } return(""); }