public static string GetModelBinder(ParameterLocation loc) { switch (loc) { case ParameterLocation.None: return(string.Empty); case ParameterLocation.Query: return("FromQuery"); case ParameterLocation.Header: return("FromHeader"); case ParameterLocation.Path: return("FromRoute"); case ParameterLocation.FormData: return("FromForm"); case ParameterLocation.Body: return("FromBody"); default: return(string.Empty); } }
/// <summary> /// Adds <see cref="OpenApiParameter"/> instance to the collection of parameters. /// </summary> /// <param name="type">Type of parameter.</param> /// <param name="parameters">List of <see cref="OpenApiParameter"/> instances.</param> /// <param name="name">Parameter name.</param> /// <param name="description">Parameter description.</param> /// <param name="required">Value indicating whether this parameter is required or not. Default is <c>false</c>.</param> /// <param name="in"><see cref="ParameterLocation"/> value. Default is <see cref="ParameterLocation.Query"/>.</param> /// <returns>List of <see cref="OpenApiParameter"/> instances.</returns> public static List <OpenApiParameter> AddOpenApiParameter( this List <OpenApiParameter> parameters, Type type, string name, string description = null, bool required = false, ParameterLocation @in = ParameterLocation.Query) { parameters.ThrowIfNullOrDefault(); type.ThrowIfNullOrDefault(); name.ThrowIfNullOrWhiteSpace(); var typeCode = Type.GetTypeCode(type); var schema = new OpenApiSchema() { Type = typeCode.ToDataType(), Format = typeCode.ToDataFormat() }; var parameter = new OpenApiParameter() { Name = name, Description = description, Required = required, In = @in, Schema = schema }; parameters.Add(parameter); return(parameters); }
public static bool HasMatchingParameter(this List<ParameterDefinition> parameters, string name, ParameterLocation loc) { var existingParameter = (from p in parameters where p.Name == name && p.Location == loc select p); return existingParameter.FirstOrDefault() != null; }
public ParameterInRouteEqualsPredicate(IRouteTemplate routeOwningUrl, Func <T, bool> predicate, ParameterLocation parameterLocation, string parameterName) { _routeOwningUrl = routeOwningUrl; _predicate = predicate; _parameterLocation = parameterLocation; _parameterName = parameterName; }
public ParameterInRouteEqualsValue(IRouteTemplate routeOwningUrl, T expectedValue, string parameterName, ParameterLocation parameterLocation) { _routeOwningUrl = routeOwningUrl; _expectedValue = expectedValue; _parameterName = parameterName; _parameterLocation = parameterLocation; }
public void Given_Properties_When_Instantiated_It_Should_Return_Value( string summary, string description, Type type, ParameterLocation @in, OpenApiParameterCollectionDelimiterType delimiter, bool explode, bool required, OpenApiVisibilityType visibility, bool deprecated) { var attribute = new OpenApiParameterAttribute("Name") { Summary = summary, Description = description, Type = type, In = @in, CollectionDelimiter = delimiter, Explode = explode, Required = required, Visibility = visibility, Deprecated = deprecated, }; attribute.Summary.Should().Be(summary); attribute.Description.Should().Be(description); attribute.Type.Should().Be(type); attribute.In.Should().Be(@in); attribute.CollectionDelimiter.Should().Be(delimiter); attribute.Explode.Should().Be(explode); attribute.Required.Should().Be(required); attribute.Visibility.Should().Be(visibility); attribute.Deprecated.Should().Be(deprecated); }
public void GetSwagger_GeneratesParameters_ForApiParametersThatAreNotBoundToBodyOrForm( string bindingSourceId, ParameterLocation expectedParameterLocation) { var subject = Subject( apiDescriptions: new[] { ApiDescriptionFactory.Create <FakeController>( c => nameof(c.ActionWithParameter), groupName: "v1", httpMethod: "POST", relativePath: "resource", parameterDescriptions: new [] { new ApiParameterDescription { Name = "param", Source = (bindingSourceId != null) ? new BindingSource(bindingSourceId, null, false, true) : null } }) } ); var document = subject.GetSwagger("v1"); var operation = document.Paths["/resource"].Operations[OperationType.Post]; Assert.Equal(1, operation.Parameters.Count); Assert.Equal(expectedParameterLocation, operation.Parameters.First().In); }
new public void RemoveAt(int id) { Binding binding = this[id]; if (binding is ParameterBinding) { foreach (IParameter parameter in ((ParameterBinding)binding).Parameters) { ParameterLocation pl = _parent.GetParameterLocation(parameter); ISpectraContainer container = _parent.Containers[pl.docId]; IParameter topParameter = null; for (int specId = 0; specId < container.Spectra.Count; specId++) { pl.specId = specId; IParameter p = _parent.GetParameter(pl); p.Status &= ~ParameterStatus.Binding; p.ReferencedParameter = topParameter; if (specId == 0) { topParameter = p; } } } } binding.Dispose(); base.RemoveAt(id); }
private OpenApiParameter CreateParameter( string name, ParameterLocation loc = ParameterLocation.Path, string description = "") => new OpenApiParameter() { Name = name, In = loc, Description = description };
/// <summary> /// Creates a new <see cref="ParameterKey"/> value. /// </summary> /// <param name="name">The name of the parameter.</param> /// <param name="location">The location of the parameter.</param> public ParameterKey( string name = default, ParameterLocation location = default) : this() { Name = name; Location = location; }
public static ParameterTS Parameter(string name = null, ParameterLocation location = ParameterLocation.None) { ParameterTS parameter = DependencyInjection.New <ParameterTS>(); parameter.Name = name; parameter.Location = location; return(parameter); }
/// <summary> /// Adds <see cref="OpenApiParameter"/> instance to the collection of parameters. /// </summary> /// <typeparam name="T">Type of parameter.</typeparam> /// <param name="parameters">List of <see cref="OpenApiParameter"/> instances.</param> /// <param name="name">Parameter name.</param> /// <param name="description">Parameter description.</param> /// <param name="required">Value indicating whether this parameter is required or not. Default is <c>false</c>.</param> /// <param name="in"><see cref="ParameterLocation"/> value. Default is <see cref="ParameterLocation.Query"/>.</param> /// <returns>List of <see cref="OpenApiParameter"/> instances.</returns> public static List <OpenApiParameter> AddOpenApiParameter <T>( this List <OpenApiParameter> parameters, string name, string description = null, bool required = false, ParameterLocation @in = ParameterLocation.Query) { return(AddOpenApiParameter(parameters, typeof(T), name, description, required, @in)); }
/// <summary> /// Creates a new instance of the <see cref="ApiKeySecurityScheme"/> class. /// </summary> /// <param name="description">The short description for security scheme.</param> /// <param name="name">The name of the header, query or cookie parameter to be used.</param> /// <param name="location">The location of the API key.</param> public ApiKeySecurityScheme( string description = default, string name = default, ParameterLocation location = default) : base(description) { Name = name; Location = location; }
private void RestoreParameter(byte[] sdata, ISpectrum spectrum, ParameterLocation loc) { uint size; using (MemoryStream stream = new MemoryStream(sdata)) { BinaryReader reader = new BinaryReader(stream); try { size = reader.ReadUInt32(); reader.ReadString(); reader.ReadSingle(); //chisq byte g, c, p, cc, cs; while (stream.Position < size) { g = reader.ReadByte(); // sdata[position++]; if (spectrum.Parameters[g] is ContributedGroup && loc.compId == -1 && loc.parId == -1 && loc.groupId == g) { ReadParameter(reader, ((ContributedGroup)spectrum.Parameters[g]).contribution, 0); break; } else { ReadParameter(reader, null, 0); } cc = reader.ReadByte(); cs = reader.ReadByte(); if (spectrum.Parameters[g].Components.Size > 0) { for (c = 0; c < cc && size > 0u; c++) { for (p = 0; p < cs; p++) { if (loc.compId == c && loc.parId == p && loc.groupId == g) { ReadParameter(reader, spectrum.Parameters[g].Components[c][p], 0); size = 0u; break; } else { ReadParameter(reader, spectrum.Parameters[g].Components[c][p], ~ParameterStatus.None); } } } } else { reader.ReadBytes(6 * cc * cs); //position += (sizeof(float) + sizeof(byte) + sizeof(byte)) * cc * cs; } } } catch (EndOfStreamException) { } finally { reader.Close(); } } }
public ParameterModel(string name, bool required, ParameterLocation location, TypeReference type) { Name = name; Required = required; Location = location; Type = type; Verifyable = type is TypeReference.TypeModelReference typeModelRef && typeModelRef.Model is ClassTypeModel classModel && classModel.Verifyable; }
public void ParsingAttributeElsewhereThanInPathOrQueryShouldReturnNull(ParameterLocation parameterLocation) { OpenApiParameter parameter = new OpenApiParameter { In = parameterLocation }; var parsedAttribute = AttributeParser.ParseAttribute(parameter); Assert.IsNull(parsedAttribute); }
/// <summary> /// Creates a new instance of the <see cref="ApiKeySecuritySchemeBuilder"/> class. /// </summary> /// <param name="value">The <see cref="ApiKeySecurityScheme"/> to copy values from.</param> public ApiKeySecuritySchemeBuilder(ApiKeySecurityScheme value) : base(value) { if (value is null) { throw new ArgumentNullException(nameof(value)); } Name = value.Name; Location = value.Location; }
/// <summary> /// Creates a new instance of the <see cref="ParameterBuilder"/> class. /// </summary> /// <param name="value">The <see cref="Parameter"/> to copy values from.</param> public ParameterBuilder(Parameter value) : base(value) { if (value is null) { throw new ArgumentNullException(nameof(value)); } Name = value.Name; Location = value.Location; }
private IParameter getParameter(ref ParameterLocation location) { if (location.compId == -1) { return(((ContributedGroup)_spectra[location.specId].Parameters[location.groupId]).contribution); } else { return(_spectra[location.specId].Parameters[location.groupId].Components[location.compId][location.parId]); } }
public static string ImportFrom(this ParameterLocation parameterLocation) { if (parameterLocation != ParameterLocation.None && parameterLocation != ParameterLocation.FormData) { return("retrofit2.http." + parameterLocation.ToString()); } else { return(null); } }
protected void InitializeBindings() { //int refGroup; //int parametersLeft; ParameterLocation l = default(ParameterLocation); //int groupId, componentId, parameterId; if (Spectra.Count > 1) { //ISpectrum firstSpectrum = Spectra[0]; //IParameter rp, p; for (l.groupId = 0; l.groupId < Spectra[0].Parameters.GroupCount; l.groupId++) { for (l.compId = 0; l.compId < Spectra[0].Parameters[l.groupId].Components.Size; l.compId++) { //location.compId = componentId; for (l.parId = 0; l.parId < Spectra[0].Parameters[l.groupId].Components[l.compId].Size; l.parId++) { //location.parId = parameterId; createReferences(ref l); //refGroup = 0; //parametersLeft = Spectra.Count; //while (parametersLeft > 0) { // for (int i = 0; i < Spectra.Count; i++) { // rp = Spectra[i].Parameters[groupId].Components[componentId][parameterId]; // if ((rp.Status & ParameterStatus.Common | ParameterStatus.Free) == (ParameterStatus.Common | ParameterStatus.Free) && // rp.ReferenceGroup == refGroup && !rp.HasReferenceValue) { // parametersLeft--; // for (int j = i + 1; j < Spectra.Count; j++) // if ((p = Spectra[j].Parameters[groupId].Components[componentId][parameterId]).ReferenceGroup == refGroup && // !p.HasReferenceValue) { // p.ReferencedParameter = rp; // parametersLeft--; // } // } else if (rp.ReferenceGroup >= refGroup && // (rp.Status & ParameterStatus.Local) == ParameterStatus.Local) // parametersLeft--; // } // refGroup++; //} } } if (Spectra[0].Parameters[l.groupId] is ContributedGroup) { l.compId = -1; createReferences(ref l); //for (int spectrumId = Spectra.Count - 1; spectrumId > 0; spectrumId--) { // ((ContributedGroup)Spectra[spectrumId].Parameters[groupId]).contribution.ReferencedParameter = ((ContributedGroup)Spectra[0].Parameters[groupId]).contribution; //} } } } }
/// <summary> /// Creates a new instance of the <see cref="ParameterBody"/> class. /// </summary> /// <param name="name">The name of the parameter.</param> /// <param name="location">The location of the parameter.</param> /// <param name="description">The brief description of the parameter.</param> /// <param name="options">The parameter options.</param> /// <param name="style">The value which indicates how the parameter value will be serialized depending on the type of the parameter value.</param> /// <param name="schema">The schema defining the type used for the parameter.</param> /// <param name="examples">The list of examples of the parameter.</param> /// <param name="content">The map containing the representations for the parameter.</param> public Parameter( string name = default, ParameterLocation location = default, string description = default, ParameterOptions options = default, ParameterStyle style = default, Referable <Schema> schema = default, IReadOnlyDictionary <ContentType, Referable <Example> > examples = default, IReadOnlyDictionary <ContentType, MediaType> content = default) : base(description, options, style, schema, examples, content) { Name = name; Location = location; }
public IEnumerable <IParameter> GetParameters(IParameter parameter, bool sameReferenceGroup) { ParameterLocation pl = ParentProject.GetParameterLocation(parameter); IParameter p; for (int s = 0; s < Spectra.Count; s++) { pl.specId = s; if ((p = ParentProject.GetParameter(pl)).ReferenceGroup == parameter.ReferenceGroup || !sameReferenceGroup) { yield return(p); } } }
/// <summary> /// Converts the specified <see cref="ParameterLocation"/> to a <see cref="JsonValue"/>. /// </summary> /// <param name="parameterLocation">The <see cref="ParameterLocation"/> to convert.</param> /// <returns>The <see cref="JsonValue"/>.</returns> protected virtual JsonValue ToJsonValue(ParameterLocation parameterLocation) { switch (parameterLocation) { case ParameterLocation.Query: return(EnumConstants.Query); case ParameterLocation.Header: return(EnumConstants.Header); case ParameterLocation.Path: return(EnumConstants.Path); case ParameterLocation.Cookie: return(EnumConstants.Cookie); default: throw new ArgumentOutOfRangeException(nameof(parameterLocation)); } }
private string LocationImport(ParameterLocation parameterLocation) { if (parameterLocation == ParameterLocation.FormData) { return("retrofit2.http.Part"); } else if (parameterLocation != ParameterLocation.None) { return("retrofit2.http." + parameterLocation.ToString()); } else { return(null); } }
public IParameter GetParameter(ParameterLocation location) { if (location.compId != -1) { return(Containers[location.docId].Spectra[location.specId].Parameters[location.groupId].Components[location.compId][location.parId]); } else if (location.parName == "contribution") { return(((ContributedGroup)Containers[location.docId].Spectra[location.specId].Parameters[location.groupId]).contribution); } else { return(null); } }
/// <summary> /// Sets the custom parameters. /// </summary> /// <param name="operation">The OpenApi operation.</param> /// <param name="customParameters">The custom parameters.</param> /// <param name="location">The parameter location.</param> protected static void AppendCustomParameters(OpenApiOperation operation, IList <CustomParameter> customParameters, ParameterLocation location) { foreach (var param in customParameters) { string documentationUrl = null; if (param.DocumentationURL != null) { documentationUrl = $" Documentation URL: {param.DocumentationURL}"; } // DocumentationURL value is to be appended to // the parameter Description property string paramDescription = (param.Description == null) ? documentationUrl?.Remove(0, 1) : param.Description + documentationUrl; OpenApiParameter parameter = new() { In = location, Name = param.Name, Description = paramDescription, Schema = new OpenApiSchema { Type = "string" }, Required = param.Required ?? false }; if (param.ExampleValues != null) { parameter.Examples = new Dictionary <string, OpenApiExample>(); int index = 1; foreach (var example in param.ExampleValues) { OpenApiExample ex = new OpenApiExample { Description = example.Description }; // maybe call convert to Uri literal ex.Value = new OpenApiString(example.Value.ToString()); parameter.Examples.Add("example-" + index++, ex); } } operation.Parameters.AppendParameter(parameter); } } }
public void GetSwagger_GeneratesParameters_ForApiParametersThatAreNotBoundToBodyOrForm( string routeTemplate, string actionFixtureName, ParameterLocation expectedLocation, string expectedType) { var subject = Subject(setupApis: apis => apis.Add("POST", routeTemplate, actionFixtureName)); var swagger = subject.GetSwagger("v1"); var parameter = swagger.Paths["/" + routeTemplate].Operations[OperationType.Post].Parameters.First(); Assert.Equal(expectedLocation, parameter.In); Assert.NotNull(parameter.Schema); Assert.Equal(expectedType, parameter.Schema.Type); }
new public void Add(Binding binding) { base.Add(binding); if (binding is ParameterBinding) { foreach (IParameter parameter in ((ParameterBinding)binding).Parameters) { ParameterLocation pl = _parent.GetParameterLocation(parameter); ISpectraContainer container = _parent.Containers[pl.docId]; foreach (IParameter p in container.GetParameters(parameter, true)) { p.Status = ((ParameterBinding)binding).Source.Status; p.ReferencedParameter = ((ParameterBinding)binding).Source; } } } }
private void listBox1_DrawItem(object sender, DrawItemEventArgs e) { if (e.Index < 0) { return; } ListBoxParameterItem item = (ListBoxParameterItem)((ListBox)sender).Items[e.Index]; IParameter p = item.parameter; string compId, doc, group, spectrumName; //string info = DefaultGroupGUI.getParameterInfo(p, out compId); Evel.engine.ProjectBase.getParameterInfo(p, out doc, out group, out compId); ParameterLocation location = project.GetParameterLocation(p); compId = (location.compId + 1).ToString(); spectrumName = (p.ReferenceGroup > 0) ? String.Format("{0} ref{1}", project.Containers[location.docId].Spectra[location.specId].Name, p.ReferenceGroup) : ""; doc = (sender == lbBinding) ? project.Containers[location.docId].Name : ""; group = project.Containers[location.docId].Spectra[location.specId].Parameters[location.groupId].Definition.name; string s = DefaultGroupGUI.BuildFormatedString(p.Definition.Header, DefaultGroupGUI.StringFormatTarget.ParameterDataGrid, compId, group, doc, spectrumName); //if (sender == lbBinding) // s = DefaultGroupGUI.BuildFormatedString(p.Definition.Header, DefaultGroupGUI.StringFormatTarget.ParameterDataGrid, compId, group, doc); //else // s = DefaultGroupGUI.BuildFormatedString(p.Definition.Header, DefaultGroupGUI.StringFormatTarget.ParameterDataGrid, compId, group); if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) { if (item.inBinding && sender != lbBinding) { e.Graphics.FillRectangle((e.Index % 2 == 0) ? regWindowBrush : altWindowBrush, e.Bounds); e.Graphics.DrawRectangle(SystemPens.Highlight, new Rectangle(e.Bounds.Left, e.Bounds.Top, e.Bounds.Width - 1, e.Bounds.Height - 1)); } else { e.Graphics.FillRectangle(SystemBrushes.Highlight, e.Bounds); } DefaultGroupGUI.DrawHeaderContent(s, e.Graphics, e.Font, e.Bounds, false, (item.inBinding && sender != lbBinding) ? SystemBrushes.InactiveCaptionText : SystemBrushes.HighlightText); } else { e.Graphics.FillRectangle((e.Index % 2 == 0) ? regWindowBrush : altWindowBrush, e.Bounds); DefaultGroupGUI.DrawHeaderContent(s, e.Graphics, e.Font, e.Bounds, false, (item.inBinding && sender != lbBinding) ? SystemBrushes.InactiveCaptionText : SystemBrushes.WindowText); } }
internal static void GenerateRequestParameter(TSObject parameterObject, ParameterTS requestParameter, ParameterTransformations parameterTransformations) { GenerateRequestParameterPath(parameterObject, requestParameter, parameterTransformations); parameterObject.Property("mapper", mapper => ClientModelExtensions.ConstructMapper(mapper, requestParameter.ModelType, requestParameter.SerializedName, requestParameter, false, false, false)); ParameterLocation location = requestParameter.Location; if (location == ParameterLocation.Path || location == ParameterLocation.Query) { AddSkipEncodingProperty(parameterObject, requestParameter); } if (location == ParameterLocation.Query) { if (requestParameter.CollectionFormat != CollectionFormat.None) { parameterObject.TextProperty("collectionFormat", $"msRest.QueryCollectionFormat.{requestParameter.CollectionFormat}"); } } }
/// <summary> /// Return list of retuired parameters for specified location passed in an argument. /// </summary> /// <param name="parameters"></param> /// <param name="location"></param> /// <returns></returns> public static IEnumerable<Parameter> ByLocationAsRequired(this IEnumerable<Parameter> parameters, ParameterLocation location, bool isRequired) { return parameters .Where(p => p.Location == location && p.IsRequired == isRequired) .AsEnumerable(); }
/// <summary> /// Return list of parameters for specified location passed in an argument. /// </summary> /// <param name="parameters"></param> /// <param name="location"></param> /// <returns></returns> public static IEnumerable<Parameter> ByLocation(this IEnumerable<Parameter> parameters, ParameterLocation location) { return parameters .Where(p => p.Location == location) .AsEnumerable(); }
private string LocationImport(ParameterLocation parameterLocation) { if (parameterLocation == ParameterLocation.FormData) { return "retrofit2.http.Part"; } else if (parameterLocation != ParameterLocation.None) { return "retrofit2.http." + parameterLocation.ToString(); } else { return null; } }
private static IEnumerable<ParameterDefinition> ParseParameterTable(IMarkdownTable table, ParameterLocation location, TableDecoder decoder, bool navigationProperties = false) { var records = from r in table.RowValues select new ParameterDefinition { Name = r.ValueForColumn(table, decoder.ParseRule.ColumnNames["name"]), Type = r.ValueForColumn(table, decoder.ParseRule.ColumnNames["type"]).ParseParameterDataType(defaultValue: ParameterDataType.String), Description = r.ValueForColumn(table, decoder.ParseRule.ColumnNames["description"]), Required = r.ValueForColumn(table, decoder.ParseRule.ColumnNames["description"]).IsRequired(), Location = location, IsNavigatable = navigationProperties }; return records; }
private static IEnumerable<ParameterDefinition> ParseParameterTable(IMarkdownTable table, ParameterLocation location) { var records = from r in table.RowValues select new ParameterDefinition { Name = r.ValueForColumn(table, "Parameter Name", "Property Name", "Name"), Type = r.ValueForColumn(table, "Type", "Value").ToDataType(), Description = r.ValueForColumn(table, "Description"), Location = location, Required = r.ValueForColumn(table, "Description").IsRequired() }; return records; }
protected Parameter(string name, ParameterLocation location) { this.In = location; this.Name = name; }