in src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiParameterGenerator.cs [67:147]
public static IList<OpenApiParameter> CreateParameters(this ODataContext context, IEdmFunction function,
IDictionary<string, string> parameterNameMapping = null)
{
Utils.CheckArgumentNull(context, nameof(context));
Utils.CheckArgumentNull(function, nameof(function));
IList<OpenApiParameter> parameters = new List<OpenApiParameter>();
int skip = function.IsBound ? 1 : 0;
foreach (IEdmOperationParameter edmParameter in function.Parameters.Skip(skip))
{
if (parameterNameMapping != null)
{
if (!parameterNameMapping.ContainsKey(edmParameter.Name))
{
continue;
}
}
OpenApiParameter parameter;
// Structured or collection-valued parameters are represented as a parameter alias
// in the path template and the parameters array contains a Parameter Object for
// the parameter alias as a query option of type string.
if (edmParameter.Type.IsStructured() ||
edmParameter.Type.IsCollection())
{
parameter = new OpenApiParameter
{
Name = parameterNameMapping == null ? edmParameter.Name : parameterNameMapping[edmParameter.Name],
In = ParameterLocation.Query, // as query option
Required = true,
// Create schema in the Content property to indicate that the parameters are serialized as JSON
Content = new Dictionary<string, OpenApiMediaType>
{
{
Constants.ApplicationJsonMediaType,
new OpenApiMediaType
{
Schema = new OpenApiSchema
{
Type = "array",
Items = new OpenApiSchema
{
Type = "string"
},
// These Parameter Objects optionally can contain the field description,
// whose value is the value of the unqualified annotation Core.Description of the parameter.
Description = context.Model.GetDescriptionAnnotation(edmParameter)
}
}
}
},
// The parameter description describes the format this URL-encoded JSON object or array, and/or reference to [OData-URL].
Description = "The URL-encoded JSON " + (edmParameter.Type.IsStructured() ? "array" : "object")
};
}
else
{
// Primitive parameters use the same type mapping as described for primitive properties.
parameter = new OpenApiParameter
{
Name = parameterNameMapping == null ? edmParameter.Name : parameterNameMapping[edmParameter.Name],
In = ParameterLocation.Path,
Required = true,
Schema = context.CreateEdmTypeSchema(edmParameter.Type)
};
}
if (parameterNameMapping != null)
{
var quote = edmParameter.Type.Definition.ShouldPathParameterBeQuoted(context.Settings) ? "'" : string.Empty;
parameter.Description = $"Usage: {edmParameter.Name}={quote}{{{parameterNameMapping[edmParameter.Name]}}}{quote}";
}
parameters.Add(parameter);
}
return parameters;
}