Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License.

using System;
using System.ClientModel;
using System.ClientModel.Primitives;
using System.Text.Json;
using System.Threading;
Expand Down Expand Up @@ -66,5 +67,8 @@ public static ParameterProvider ClientOptions(CSharpType clientOptionsType)

public static readonly ParameterProvider NextPage =
new ParameterProvider("nextPage", $"The url of the next page of responses.", typeof(Uri));

public static readonly ParameterProvider KeyCredential = new("credential", FormattableStringHelpers.Empty, typeof(ApiKeyCredential));
public static readonly ParameterProvider TokenCredential = new("credential", FormattableStringHelpers.Empty, typeof(AuthenticationTokenProvider));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Microsoft.TypeSpec.Generator.Expressions;
using Microsoft.TypeSpec.Generator.Input;
using Microsoft.TypeSpec.Generator.Primitives;

namespace Microsoft.TypeSpec.Generator.ClientModel.Providers.Samples
{
/// <summary>
/// Represents a parameter value in a sample. Supports two modes:
/// - <see cref="Value"/>: raw example data that will be converted to a C# expression later
/// - <see cref="Expression"/>: a pre-built C# expression (used for known parameters like credentials, endpoints)
/// </summary>
public class ExampleParameterValue
{
public ExampleParameterValue(string name, CSharpType type, InputExampleValue value)
{
Name = name;
Type = type;
Value = value;
}

public ExampleParameterValue(string name, CSharpType type, ValueExpression expression)
{
Name = name;
Type = type;
Expression = expression;
}

/// <summary>
/// The parameter name.
/// </summary>
public string Name { get; }

/// <summary>
/// The C# type of the parameter.
/// </summary>
public CSharpType Type { get; }

/// <summary>
/// Raw example data from the spec or mock builder. Will be converted to a
/// <see cref="ValueExpression"/> via <see cref="ExampleValueExpressionBuilder"/>.
/// Mutually exclusive with <see cref="Expression"/>.
/// </summary>
public InputExampleValue? Value { get; }

/// <summary>
/// A pre-built C# expression. Used for known parameters (credentials, endpoints)
/// where the expression is fixed regardless of example data.
/// Mutually exclusive with <see cref="Value"/>.
/// </summary>
public ValueExpression? Expression { get; }
}
}
Loading
Loading