private RouteParamAttribute ConvertModelPropertyToQueryStringParamAttribute(SwaggerModelPropertyData modelPropertyData) { RouteParamAttribute routeParamAttribute = new RouteParamAttribute { Description = modelPropertyData.Description, Enum = modelPropertyData.Enum?.ToArray(), Name = modelPropertyData.Name, Required = modelPropertyData.Required, UniqueItems = modelPropertyData.UniqueItems, ParamType = modelPropertyData.Type, ParamIn = ParameterIn.Query, }; if (modelPropertyData.DefaultValue != null) { routeParamAttribute.DefaultValue = modelPropertyData.DefaultValue.ToString(); } if (modelPropertyData.Maximum != null) { routeParamAttribute.Maximum = modelPropertyData.Maximum.Value; } if (modelPropertyData.Minimum != null) { routeParamAttribute.Minimum = modelPropertyData.Minimum.Value; } return(routeParamAttribute); }
public AnnotatedParameter(string name, Type paramType, RouteParamAttribute attr) { Name = attr.Name ?? name; In = attr.GetNullableParamType() ?? In; Required = attr.GetNullableRequired() ?? Required; Description = attr.Description ?? Description; Default = attr.DefaultValue ?? Default; Type = Primitive.IsPrimitive(paramType) ? Primitive.FromType(paramType).Type : "string"; }
public AnnotatedParameter(string name, Type paramType, RouteParamAttribute attr) { Name = attr.Name ?? name; In = attr.GetNullableParamType() ?? In; Required = attr.GetNullableRequired() ?? Required; Description = attr.Description ?? Description; Default = attr.DefaultValue ?? Default; Minimum = attr.GetNullableMinimum() ?? Minimum; Maximum = attr.GetNullableMaximum() ?? Maximum; UniqueItems = attr.GetNullableUniqueItems() ?? UniqueItems; Enum = attr.Enum ?? Enum; if (Primitive.IsPrimitive(paramType)) { Type = Primitive.FromType(paramType).Type; Format = Primitive.FromType(paramType).Format; } else { Type = "string"; } }
public AnnotatedBodyParameter(string name, Type paramType, RouteParamAttribute attrib, ISwaggerModelCatalog modelCatalog) { Name = attrib.Name ?? name; this.AddBodySchema(paramType, modelCatalog); }
private IEnumerable <AnnotatedParameter> CreateAnnotatedParameter(string name, Type paramType, RouteParamAttribute routeParamAttribute) { // Non Query Parameter && Primitive parameter type would default to original behavior, which is to return an instance of AnnotatedParameter if (routeParamAttribute.ParamIn != ParameterIn.Query || Primitive.IsPrimitive(paramType)) { return(new List <AnnotatedParameter> { new AnnotatedParameter(name, paramType, routeParamAttribute) }); } List <AnnotatedParameter> annotatedParameters = new List <AnnotatedParameter>(); var modelAttr = paramType.GetTypeInfo().GetCustomAttribute <ModelAttribute>(); var paramModel = modelAttr != null ? new AnnotatedModel(paramType, modelAttr) : _modelCatalog.GetModelForType(paramType); // populate the data type properties into a list of AnnotatedParameter. return(paramModel.Properties.Select(property => { var routeParamProperty = ConvertModelPropertyToQueryStringParamAttribute(property); return new AnnotatedParameter( routeParamProperty.Name, routeParamProperty.ParamType ?? Type.GetType("System.Object"), routeParamProperty); })); }