Skip to content

Commit

Permalink
feat: Updated OpenAPI spec
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Sep 20, 2024
1 parent 4f2f241 commit f022ea8
Showing 1 changed file with 98 additions and 0 deletions.
98 changes: 98 additions & 0 deletions src/libs/OpenAI/Generated/OpenAI.PathBuilder.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,20 @@

namespace OpenAI
{
/// <summary>
/// A helper class to build URL paths with optional and required parameters.
/// </summary>
public class PathBuilder
{
private readonly global::System.Text.StringBuilder _stringBuilder =
new global::System.Text.StringBuilder(capacity: 256);
private bool _firstParameter = true;

/// <summary>
/// Initializes a new instance of the <see cref="PathBuilder"/> class.
/// </summary>
/// <param name="path">The base path for the URL.</param>
/// <param name="baseUri">The base URI to prepend to the path, if any.</param>
public PathBuilder(
string path,
global::System.Uri? baseUri = null)
Expand All @@ -17,8 +26,16 @@ public PathBuilder(
{
_stringBuilder.Append(baseUri.AbsoluteUri.TrimEnd('/'));
}

_stringBuilder.Append(path);
}

/// <summary>
/// Adds a required parameter to the URL.
/// </summary>
/// <param name="name">The name of the parameter.</param>
/// <param name="value">The value of the parameter.</param>
/// <returns>The current <see cref="PathBuilder"/> instance.</returns>
public PathBuilder AddRequiredParameter(
string name,
string value)
Expand All @@ -36,8 +53,18 @@ public PathBuilder AddRequiredParameter(
_stringBuilder.Append(global::System.Uri.EscapeDataString(name));
_stringBuilder.Append('=');
_stringBuilder.Append(global::System.Uri.EscapeDataString(value));

return this;
}

/// <summary>
/// Adds a required parameter with multiple values to the URL.
/// </summary>
/// <param name="name">The name of the parameter.</param>
/// <param name="value">The values of the parameter.</param>
/// <param name="delimiter">The delimiter to use between values.</param>
/// <param name="explode">Whether to explode the values into separate parameters.</param>
/// <returns>The current <see cref="PathBuilder"/> instance.</returns>
public PathBuilder AddRequiredParameter(
string name,
global::System.Collections.Generic.IEnumerable<string> value,
Expand All @@ -53,9 +80,22 @@ public PathBuilder AddRequiredParameter(

return this;
}

AddRequiredParameter(name, string.Join(delimiter, value));

return this;
}

/// <summary>
/// Adds a required parameter with multiple values to the URL, using a selector function.
/// </summary>
/// <typeparam name="T">The type of the values.</typeparam>
/// <param name="name">The name of the parameter.</param>
/// <param name="value">The values of the parameter.</param>
/// <param name="selector">The function to select the string representation of each value.</param>
/// <param name="delimiter">The delimiter to use between values.</param>
/// <param name="explode">Whether to explode the values into separate parameters.</param>
/// <returns>The current <see cref="PathBuilder"/> instance.</returns>
public PathBuilder AddRequiredParameter<T>(
string name,
global::System.Collections.Generic.IEnumerable<T> value,
Expand All @@ -64,8 +104,16 @@ public PathBuilder AddRequiredParameter<T>(
bool explode = false)
{
AddRequiredParameter(name, value.Select(selector).ToArray(), delimiter, explode);

return this;
}

/// <summary>
/// Adds an optional parameter to the URL.
/// </summary>
/// <param name="name">The name of the parameter.</param>
/// <param name="value">The value of the parameter, or null if not present.</param>
/// <returns>The current <see cref="PathBuilder"/> instance.</returns>
public PathBuilder AddOptionalParameter(
string name,
string? value)
Expand All @@ -74,8 +122,18 @@ public PathBuilder AddOptionalParameter(
{
AddRequiredParameter(name, value);
}

return this;
}

/// <summary>
/// Adds an optional parameter with multiple values to the URL.
/// </summary>
/// <param name="name">The name of the parameter.</param>
/// <param name="value">The values of the parameter, or null if not present.</param>
/// <param name="delimiter">The delimiter to use between values.</param>
/// <param name="explode">Whether to explode the values into separate parameters.</param>
/// <returns>The current <see cref="PathBuilder"/> instance.</returns>
public PathBuilder AddOptionalParameter(
string name,
global::System.Collections.Generic.IEnumerable<string>? value,
Expand All @@ -86,8 +144,20 @@ public PathBuilder AddOptionalParameter(
{
AddRequiredParameter(name, value, delimiter, explode);
}

return this;
}

/// <summary>
/// Adds an optional parameter with multiple values to the URL, using a selector function.
/// </summary>
/// <typeparam name="T">The type of the values.</typeparam>
/// <param name="name">The name of the parameter.</param>
/// <param name="value">The values of the parameter, or null if not present.</param>
/// <param name="selector">The function to select the string representation of each value.</param>
/// <param name="delimiter">The delimiter to use between values.</param>
/// <param name="explode">Whether to explode the values into separate parameters.</param>
/// <returns>The current <see cref="PathBuilder"/> instance.</returns>
public PathBuilder AddOptionalParameter<T>(
string name,
global::System.Collections.Generic.IEnumerable<T>? value,
Expand All @@ -99,8 +169,19 @@ public PathBuilder AddOptionalParameter<T>(
{
AddRequiredParameter(name, value.Select(selector).ToArray(), delimiter, explode);
}

return this;
}

/// <summary>
/// Adds a required parameter to the URL, using a formattable value.
/// </summary>
/// <typeparam name="T">The type of the value.</typeparam>
/// <param name="name">The name of the parameter.</param>
/// <param name="value">The value of the parameter.</param>
/// <param name="format">The format string.</param>
/// <param name="formatProvider">The format provider.</param>
/// <returns>The current <see cref="PathBuilder"/> instance.</returns>
public PathBuilder AddRequiredParameter<T>(
string name,
T value,
Expand All @@ -109,8 +190,19 @@ public PathBuilder AddRequiredParameter<T>(
where T : global::System.IFormattable
{
AddRequiredParameter(name, value.ToString(format, formatProvider));

return this;
}

/// <summary>
/// Adds an optional parameter to the URL, using a formattable value.
/// </summary>
/// <typeparam name="T">The type of the value.</typeparam>
/// <param name="name">The name of the parameter.</param>
/// <param name="value">The value of the parameter, or null if not present.</param>
/// <param name="format">The format string.</param>
/// <param name="formatProvider">The format provider.</param>
/// <returns>The current <see cref="PathBuilder"/> instance.</returns>
public PathBuilder AddOptionalParameter<T>(
string name,
T? value,
Expand All @@ -122,8 +214,14 @@ public PathBuilder AddOptionalParameter<T>(
{
AddOptionalParameter(name, value.ToString(format, formatProvider));
}

return this;
}

/// <summary>
/// Returns the constructed URL as a string.
/// </summary>
/// <returns>The constructed URL.</returns>
public override string ToString() => _stringBuilder.ToString();
}
}

0 comments on commit f022ea8

Please sign in to comment.