Skip to content

Commit daafde4

Browse files
.Net: Rename OpenAPI model classes (#9595)
### Motivation, Context and Description The public OpenAPI model classes that have "operation" in their name were renamed to align with the other classes that do not have the word in their name. Additionally, the `RestApiPayloadProperty.Type`, `RestApiParameter.Type`, and `RestApiParameter.ArrayItemType` were made internal to simplify the update to OpenAPI.NET v2, where their types have been changed.
1 parent 3888c8e commit daafde4

31 files changed

+460
-458
lines changed

dotnet/src/Functions/Functions.OpenApi/Extensions/OpenApiFunctionExecutionParameters.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ public class OpenApiFunctionExecutionParameters
2323
public AuthenticateRequestAsyncCallback? AuthCallback { get; set; }
2424

2525
/// <summary>
26-
/// Override for REST API operation server url.
26+
/// Override for REST API server url.
2727
/// </summary>
2828
public Uri? ServerUrlOverride { get; set; }
2929

3030
/// <summary>
31-
/// Flag indicating whether to ignore non-compliant errors or not.
32-
/// If set to true, the operation execution will not throw exceptions for non-compliant documents.
31+
/// Flag indicating whether to ignore non-compliant errors of the OpenAPI document or not.
32+
/// If set to true, the execution will not throw exceptions for non-compliant documents.
3333
/// Please note that enabling this option may result in incomplete or inaccurate execution results.
3434
/// </summary>
3535
public bool IgnoreNonCompliantErrors { get; set; }
@@ -40,8 +40,8 @@ public class OpenApiFunctionExecutionParameters
4040
public string UserAgent { get; set; }
4141

4242
/// <summary>
43-
/// Determines whether the operation payload is constructed dynamically based on operation payload metadata.
44-
/// If false, the operation payload must be provided via the 'payload' context variable.
43+
/// Determines whether the REST API operation payload is constructed dynamically based on payload metadata.
44+
/// If false, the payload must be provided via the 'payload' argument.
4545
/// </summary>
4646
public bool EnableDynamicPayload { get; set; }
4747

@@ -75,13 +75,13 @@ public class OpenApiFunctionExecutionParameters
7575
/// </summary>
7676
/// <param name="httpClient">The HttpClient to use for sending HTTP requests.</param>
7777
/// <param name="authCallback">The callback for adding authentication data to HTTP requests.</param>
78-
/// <param name="serverUrlOverride">The override for the REST API operation server URL.</param>
78+
/// <param name="serverUrlOverride">The override for the REST API server URL.</param>
7979
/// <param name="userAgent">Optional user agent header value.</param>
80-
/// <param name="ignoreNonCompliantErrors">A flag indicating whether to ignore non-compliant errors or not
81-
/// If set to true, the operation execution will not throw exceptions for non-compliant documents.
80+
/// <param name="ignoreNonCompliantErrors">A flag indicating whether to ignore non-compliant errors of the OpenAPI document or not
81+
/// If set to true, the execution will not throw exceptions for non-compliant documents.
8282
/// Please note that enabling this option may result in incomplete or inaccurate execution results.</param>
83-
/// <param name="enableDynamicOperationPayload">Determines whether the operation payload is constructed dynamically based on operation payload metadata.
84-
/// If false, the operation payload must be provided via the 'payload' context variable.</param>
83+
/// <param name="enableDynamicOperationPayload">Determines whether the REST API operation payload is constructed dynamically based on payload metadata.
84+
/// If false, the REST API payload must be provided via the 'payload' argument.</param>
8585
/// <param name="enablePayloadNamespacing">Determines whether payload parameter names are augmented with namespaces.
8686
/// Namespaces prevent naming conflicts by adding the parent parameter name as a prefix, separated by dots.</param>
8787
/// <param name="operationsToExclude">Optional list of operations not to import, e.g. in case they are not supported</param>

dotnet/src/Functions/Functions.OpenApi/Extensions/RestApiOperationExtensions.cs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ internal static partial class RestApiOperationExtensions
2525
/// the parameters 'sender.email' and 'receiver.mail' will be correctly resolved from arguments with the same names.
2626
/// </param>
2727
/// <returns>The list of parameters.</returns>
28-
public static IReadOnlyList<RestApiOperationParameter> GetParameters(
28+
public static IReadOnlyList<RestApiParameter> GetParameters(
2929
this RestApiOperation operation,
3030
bool addPayloadParamsFromMetadata = true,
3131
bool enablePayloadNamespacing = false)
3232
{
33-
var parameters = new List<RestApiOperationParameter>(operation.Parameters);
33+
var parameters = new List<RestApiParameter>(operation.Parameters);
3434

3535
// Add payload parameters
3636
if (operation.Payload is not null)
@@ -55,7 +55,7 @@ public static IReadOnlyList<RestApiOperationParameter> GetParameters(
5555
/// <returns>The default return parameter metadata, if any.</returns>
5656
public static KernelReturnParameterMetadata? GetDefaultReturnParameter(this RestApiOperation operation, string[]? preferredResponses = null)
5757
{
58-
RestApiOperationExpectedResponse? restOperationResponse = GetDefaultResponse(operation.Responses, preferredResponses ??= s_preferredResponses);
58+
RestApiExpectedResponse? restOperationResponse = GetDefaultResponse(operation.Responses, preferredResponses ??= s_preferredResponses);
5959

6060
var returnParameter =
6161
restOperationResponse is not null ? new KernelReturnParameterMetadata { Description = restOperationResponse.Description, Schema = restOperationResponse.Schema } : null;
@@ -64,12 +64,12 @@ public static IReadOnlyList<RestApiOperationParameter> GetParameters(
6464
}
6565

6666
/// <summary>
67-
/// Retrieves the default response for a given REST API operation.
67+
/// Retrieves the default response.
6868
/// </summary>
69-
/// <param name="responses">The REST API operation responses to parse.</param>
69+
/// <param name="responses">Possible REST API responses.</param>
7070
/// <param name="preferredResponses">The preferred response codes to use when selecting the default response.</param>
7171
/// <returns>The default response, if any.</returns>
72-
private static RestApiOperationExpectedResponse? GetDefaultResponse(IReadOnlyDictionary<string, RestApiOperationExpectedResponse> responses, string[] preferredResponses)
72+
private static RestApiExpectedResponse? GetDefaultResponse(IReadOnlyDictionary<string, RestApiExpectedResponse> responses, string[] preferredResponses)
7373
{
7474
foreach (var code in preferredResponses)
7575
{
@@ -90,8 +90,8 @@ public static IReadOnlyList<RestApiOperationParameter> GetParameters(
9090
/// <param name="useParametersFromMetadata">Flag indicating whether to include parameters from metadata.
9191
/// If false or not specified, the 'payload' and 'content-type' parameters are added instead.</param>
9292
/// <param name="enableNamespacing">Flag indicating whether to namespace payload parameter names.</param>
93-
/// <returns>A list of <see cref="RestApiOperationParameter"/> representing the payload parameters.</returns>
94-
private static List<RestApiOperationParameter> GetPayloadParameters(RestApiOperation operation, bool useParametersFromMetadata, bool enableNamespacing)
93+
/// <returns>A list of <see cref="RestApiParameter"/> representing the payload parameters.</returns>
94+
private static List<RestApiParameter> GetPayloadParameters(RestApiOperation operation, bool useParametersFromMetadata, bool enableNamespacing)
9595
{
9696
if (useParametersFromMetadata)
9797
{
@@ -122,15 +122,15 @@ private static List<RestApiOperationParameter> GetPayloadParameters(RestApiOpera
122122
/// </summary>
123123
/// <param name="operation">The REST API operation.</param>
124124
/// <returns>The 'content-type' artificial parameter.</returns>
125-
private static RestApiOperationParameter CreateContentTypeArtificialParameter(RestApiOperation operation)
125+
private static RestApiParameter CreateContentTypeArtificialParameter(RestApiOperation operation)
126126
{
127-
return new RestApiOperationParameter(
127+
return new RestApiParameter(
128128
RestApiOperation.ContentTypeArgumentName,
129129
"string",
130130
isRequired: false,
131131
expand: false,
132-
RestApiOperationParameterLocation.Body,
133-
RestApiOperationParameterStyle.Simple,
132+
RestApiParameterLocation.Body,
133+
RestApiParameterStyle.Simple,
134134
description: "Content type of REST API request body.");
135135
}
136136

@@ -139,45 +139,45 @@ private static RestApiOperationParameter CreateContentTypeArtificialParameter(Re
139139
/// </summary>
140140
/// <param name="operation">The REST API operation.</param>
141141
/// <returns>The 'payload' artificial parameter.</returns>
142-
private static RestApiOperationParameter CreatePayloadArtificialParameter(RestApiOperation operation)
142+
private static RestApiParameter CreatePayloadArtificialParameter(RestApiOperation operation)
143143
{
144-
return new RestApiOperationParameter(
144+
return new RestApiParameter(
145145
RestApiOperation.PayloadArgumentName,
146146
operation.Payload?.MediaType == MediaTypeTextPlain ? "string" : "object",
147147
isRequired: true,
148148
expand: false,
149-
RestApiOperationParameterLocation.Body,
150-
RestApiOperationParameterStyle.Simple,
149+
RestApiParameterLocation.Body,
150+
RestApiParameterStyle.Simple,
151151
description: operation.Payload?.Description ?? "REST API request body.",
152152
schema: operation.Payload?.Schema);
153153
}
154154

155155
/// <summary>
156-
/// Retrieves parameters from REST API operation payload metadata.
156+
/// Retrieves parameters from REST API payload metadata.
157157
/// </summary>
158-
/// <param name="properties">The REST API operation payload properties.</param>
158+
/// <param name="properties">The REST API payload properties.</param>
159159
/// <param name="enableNamespacing">Determines whether property names are augmented with namespaces.
160160
/// Namespaces are created by prefixing property names with their root property names.
161161
/// </param>
162162
/// <param name="rootPropertyName">The root property name.</param>
163163
/// <returns>The list of payload parameters.</returns>
164-
private static List<RestApiOperationParameter> GetParametersFromPayloadMetadata(IReadOnlyList<RestApiOperationPayloadProperty> properties, bool enableNamespacing = false, string? rootPropertyName = null)
164+
private static List<RestApiParameter> GetParametersFromPayloadMetadata(IReadOnlyList<RestApiPayloadProperty> properties, bool enableNamespacing = false, string? rootPropertyName = null)
165165
{
166-
var parameters = new List<RestApiOperationParameter>();
166+
var parameters = new List<RestApiParameter>();
167167

168168
foreach (var property in properties)
169169
{
170170
var parameterName = GetPropertyName(property, rootPropertyName, enableNamespacing);
171171

172172
if (!property.Properties.Any())
173173
{
174-
parameters.Add(new RestApiOperationParameter(
174+
parameters.Add(new RestApiParameter(
175175
name: parameterName,
176176
type: property.Type,
177177
isRequired: property.IsRequired,
178178
expand: false,
179-
location: RestApiOperationParameterLocation.Body,
180-
style: RestApiOperationParameterStyle.Simple,
179+
location: RestApiParameterLocation.Body,
180+
style: RestApiParameterStyle.Simple,
181181
defaultValue: property.DefaultValue,
182182
description: property.Description,
183183
format: property.Format,
@@ -197,7 +197,7 @@ private static List<RestApiOperationParameter> GetParametersFromPayloadMetadata(
197197
/// <param name="rootPropertyName">The root property name to be used for constructing the full property name.</param>
198198
/// <param name="enableNamespacing">Determines whether to add namespace to property name or not.</param>
199199
/// <returns>The property name.</returns>
200-
private static string GetPropertyName(RestApiOperationPayloadProperty property, string? rootPropertyName, bool enableNamespacing = false)
200+
private static string GetPropertyName(RestApiPayloadProperty property, string? rootPropertyName, bool enableNamespacing = false)
201201
{
202202
if (enableNamespacing)
203203
{

dotnet/src/Functions/Functions.OpenApi/HttpContentFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ namespace Microsoft.SemanticKernel.Plugins.OpenApi;
1111
/// <param name="payload">The operation payload metadata.</param>
1212
/// <param name="arguments">The operation arguments.</param>
1313
/// <returns>The object and HttpContent representing the operation payload.</returns>
14-
internal delegate (object? Payload, HttpContent Content) HttpContentFactory(RestApiOperationPayload? payload, IDictionary<string, object?> arguments);
14+
internal delegate (object? Payload, HttpContent Content) HttpContentFactory(RestApiPayload? payload, IDictionary<string, object?> arguments);

dotnet/src/Functions/Functions.OpenApi/Model/RestApiOperationExpectedResponse.cs renamed to dotnet/src/Functions/Functions.OpenApi/Model/RestApiExpectedResponse.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
namespace Microsoft.SemanticKernel.Plugins.OpenApi;
66

77
/// <summary>
8-
/// The REST API operation response.
8+
/// REST API response.
99
/// </summary>
1010
[Experimental("SKEXP0040")]
11-
public sealed class RestApiOperationExpectedResponse
11+
public sealed class RestApiExpectedResponse
1212
{
1313
/// <summary>
1414
/// Gets the description of the response.
@@ -26,12 +26,12 @@ public sealed class RestApiOperationExpectedResponse
2626
public KernelJsonSchema? Schema { get; }
2727

2828
/// <summary>
29-
/// Initializes a new instance of the <see cref="RestApiOperationResponse"/> class.
29+
/// Initializes a new instance of the <see cref="RestApiExpectedResponse"/> class.
3030
/// </summary>
3131
/// <param name="description">The description of the response.</param>
3232
/// <param name="mediaType">The media type of the response.</param>
3333
/// <param name="schema">The schema against which the response body should be validated.</param>
34-
internal RestApiOperationExpectedResponse(string description, string mediaType, KernelJsonSchema? schema = null)
34+
internal RestApiExpectedResponse(string description, string mediaType, KernelJsonSchema? schema = null)
3535
{
3636
this.Description = description;
3737
this.MediaType = mediaType;

dotnet/src/Functions/Functions.OpenApi/Model/RestApiOperation.cs

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public sealed class RestApiOperation
5454
/// <summary>
5555
/// The server.
5656
/// </summary>
57-
public IReadOnlyList<RestApiOperationServer> Servers { get; }
57+
public IReadOnlyList<RestApiServer> Servers { get; }
5858

5959
/// <summary>
6060
/// The security requirements.
@@ -64,17 +64,17 @@ public sealed class RestApiOperation
6464
/// <summary>
6565
/// The operation parameters.
6666
/// </summary>
67-
public IReadOnlyList<RestApiOperationParameter> Parameters { get; }
67+
public IReadOnlyList<RestApiParameter> Parameters { get; }
6868

6969
/// <summary>
7070
/// The list of possible operation responses.
7171
/// </summary>
72-
public IReadOnlyDictionary<string, RestApiOperationExpectedResponse> Responses { get; }
72+
public IReadOnlyDictionary<string, RestApiExpectedResponse> Responses { get; }
7373

7474
/// <summary>
7575
/// The operation payload.
7676
/// </summary>
77-
public RestApiOperationPayload? Payload { get; }
77+
public RestApiPayload? Payload { get; }
7878

7979
/// <summary>
8080
/// Additional unstructured metadata about the operation.
@@ -95,14 +95,14 @@ public sealed class RestApiOperation
9595
/// <param name="payload">The operation payload.</param>
9696
internal RestApiOperation(
9797
string? id,
98-
IReadOnlyList<RestApiOperationServer> servers,
98+
IReadOnlyList<RestApiServer> servers,
9999
string path,
100100
HttpMethod method,
101101
string? description,
102-
IReadOnlyList<RestApiOperationParameter> parameters,
103-
IReadOnlyDictionary<string, RestApiOperationExpectedResponse> responses,
102+
IReadOnlyList<RestApiParameter> parameters,
103+
IReadOnlyDictionary<string, RestApiExpectedResponse> responses,
104104
IReadOnlyList<RestApiSecurityRequirement> securityRequirements,
105-
RestApiOperationPayload? payload = null)
105+
RestApiPayload? payload = null)
106106
{
107107
this.Id = id;
108108
this.Servers = servers;
@@ -113,6 +113,8 @@ internal RestApiOperation(
113113
this.Responses = responses;
114114
this.SecurityRequirements = securityRequirements;
115115
this.Payload = payload;
116+
this.Responses = responses ?? new Dictionary<string, RestApiExpectedResponse>();
117+
this.SecurityRequirements = securityRequirements;
116118
}
117119

118120
/// <summary>
@@ -140,7 +142,7 @@ internal IDictionary<string, string> BuildHeaders(IDictionary<string, object?> a
140142
{
141143
var headers = new Dictionary<string, string>();
142144

143-
var parameters = this.Parameters.Where(p => p.Location == RestApiOperationParameterLocation.Header);
145+
var parameters = this.Parameters.Where(p => p.Location == RestApiParameterLocation.Header);
144146

145147
foreach (var parameter in parameters)
146148
{
@@ -156,7 +158,7 @@ internal IDictionary<string, string> BuildHeaders(IDictionary<string, object?> a
156158
continue;
157159
}
158160

159-
var parameterStyle = parameter.Style ?? RestApiOperationParameterStyle.Simple;
161+
var parameterStyle = parameter.Style ?? RestApiParameterStyle.Simple;
160162

161163
if (!s_parameterSerializers.TryGetValue(parameterStyle, out var serializer))
162164
{
@@ -181,7 +183,7 @@ internal string BuildQueryString(IDictionary<string, object?> arguments)
181183
{
182184
var segments = new List<string>();
183185

184-
var parameters = this.Parameters.Where(p => p.Location == RestApiOperationParameterLocation.Query);
186+
var parameters = this.Parameters.Where(p => p.Location == RestApiParameterLocation.Query);
185187

186188
foreach (var parameter in parameters)
187189
{
@@ -197,7 +199,7 @@ internal string BuildQueryString(IDictionary<string, object?> arguments)
197199
continue;
198200
}
199201

200-
var parameterStyle = parameter.Style ?? RestApiOperationParameterStyle.Form;
202+
var parameterStyle = parameter.Style ?? RestApiParameterStyle.Form;
201203

202204
if (!s_parameterSerializers.TryGetValue(parameterStyle, out var serializer))
203205
{
@@ -223,7 +225,7 @@ internal string BuildQueryString(IDictionary<string, object?> arguments)
223225
/// <returns>The path.</returns>
224226
private string BuildPath(string pathTemplate, IDictionary<string, object?> arguments)
225227
{
226-
var parameters = this.Parameters.Where(p => p.Location == RestApiOperationParameterLocation.Path);
228+
var parameters = this.Parameters.Where(p => p.Location == RestApiParameterLocation.Path);
227229

228230
foreach (var parameter in parameters)
229231
{
@@ -239,7 +241,7 @@ private string BuildPath(string pathTemplate, IDictionary<string, object?> argum
239241
continue;
240242
}
241243

242-
var parameterStyle = parameter.Style ?? RestApiOperationParameterStyle.Simple;
244+
var parameterStyle = parameter.Style ?? RestApiParameterStyle.Simple;
243245

244246
if (!s_parameterSerializers.TryGetValue(parameterStyle, out var serializer))
245247
{
@@ -307,12 +309,12 @@ private Uri GetServerUrl(Uri? serverUrlOverride, Uri? apiHostUrl, IDictionary<st
307309
return new Uri(serverUrlString);
308310
}
309311

310-
private static readonly Dictionary<RestApiOperationParameterStyle, Func<RestApiOperationParameter, JsonNode, string>> s_parameterSerializers = new()
312+
private static readonly Dictionary<RestApiParameterStyle, Func<RestApiParameter, JsonNode, string>> s_parameterSerializers = new()
311313
{
312-
{ RestApiOperationParameterStyle.Simple, SimpleStyleParameterSerializer.Serialize },
313-
{ RestApiOperationParameterStyle.Form, FormStyleParameterSerializer.Serialize },
314-
{ RestApiOperationParameterStyle.SpaceDelimited, SpaceDelimitedStyleParameterSerializer.Serialize },
315-
{ RestApiOperationParameterStyle.PipeDelimited, PipeDelimitedStyleParameterSerializer.Serialize }
314+
{ RestApiParameterStyle.Simple, SimpleStyleParameterSerializer.Serialize },
315+
{ RestApiParameterStyle.Form, FormStyleParameterSerializer.Serialize },
316+
{ RestApiParameterStyle.SpaceDelimited, SpaceDelimitedStyleParameterSerializer.Serialize },
317+
{ RestApiParameterStyle.PipeDelimited, PipeDelimitedStyleParameterSerializer.Serialize }
316318
};
317319

318320
# endregion

0 commit comments

Comments
 (0)