Skip to content

Commit d48e17a

Browse files
.Net: Prepare OpenApi model classes to changes in OpenApi.NET v2 SDK (#9603)
### Motivation, Context and Description The new version, V2, of the [OpenAPI.NET](microsoft/OpenAPI.NET#1906) SDK comes with changes to its model classes. This PR updates the SK OpenAPI model classes to match the SDK's ones. The goal is to reduce breaking changes from the update. Similar changes were done in this PR - [.Net: Rename OpenAPI model classes](#9595) where 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. Related task: #6884
1 parent c9ef719 commit d48e17a

File tree

5 files changed

+412
-288
lines changed

5 files changed

+412
-288
lines changed

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ public sealed class RestApiOperation
3434
/// <summary>
3535
/// The operation identifier.
3636
/// </summary>
37-
public string Id { get; }
37+
public string? Id { get; }
3838

3939
/// <summary>
4040
/// The operation description.
4141
/// </summary>
42-
public string Description { get; }
42+
public string? Description { get; }
4343

4444
/// <summary>
4545
/// The operation path.
@@ -59,7 +59,7 @@ public sealed class RestApiOperation
5959
/// <summary>
6060
/// The security requirements.
6161
/// </summary>
62-
public IReadOnlyList<RestApiSecurityRequirement>? SecurityRequirements { get; }
62+
public IReadOnlyList<RestApiSecurityRequirement> SecurityRequirements { get; }
6363

6464
/// <summary>
6565
/// The operation parameters.
@@ -90,29 +90,29 @@ public sealed class RestApiOperation
9090
/// <param name="method">The operation method.</param>
9191
/// <param name="description">The operation description.</param>
9292
/// <param name="parameters">The operation parameters.</param>
93-
/// <param name="payload">The operation payload.</param>
9493
/// <param name="responses">The operation responses.</param>
9594
/// <param name="securityRequirements">The operation security requirements.</param>
95+
/// <param name="payload">The operation payload.</param>
9696
internal RestApiOperation(
97-
string id,
97+
string? id,
9898
IReadOnlyList<RestApiOperationServer> servers,
9999
string path,
100100
HttpMethod method,
101-
string description,
101+
string? description,
102102
IReadOnlyList<RestApiOperationParameter> parameters,
103-
RestApiOperationPayload? payload = null,
104-
IReadOnlyDictionary<string, RestApiOperationExpectedResponse>? responses = null,
105-
IReadOnlyList<RestApiSecurityRequirement>? securityRequirements = null)
103+
IReadOnlyDictionary<string, RestApiOperationExpectedResponse> responses,
104+
IReadOnlyList<RestApiSecurityRequirement> securityRequirements,
105+
RestApiOperationPayload? payload = null)
106106
{
107107
this.Id = id;
108108
this.Servers = servers;
109109
this.Path = path;
110110
this.Method = method;
111111
this.Description = description;
112112
this.Parameters = parameters;
113-
this.Payload = payload;
114-
this.Responses = responses ?? new Dictionary<string, RestApiOperationExpectedResponse>();
113+
this.Responses = responses;
115114
this.SecurityRequirements = securityRequirements;
115+
this.Payload = payload;
116116
}
117117

118118
/// <summary>

dotnet/src/Functions/Functions.OpenApi/OpenApiKernelPluginFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ private static string ConvertOperationToValidFunctionName(RestApiOperation opera
325325
{
326326
if (!string.IsNullOrWhiteSpace(operation.Id))
327327
{
328-
return ConvertOperationIdToValidFunctionName(operationId: operation.Id, logger: logger);
328+
return ConvertOperationIdToValidFunctionName(operationId: operation.Id!, logger: logger);
329329
}
330330

331331
// Tokenize operation path on forward and back slashes

dotnet/src/Functions/Functions.UnitTests/OpenApi/Extensions/RestApiOperationExtensionsTests.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft. All rights reserved.
22

33
using System;
4+
using System.Collections.Generic;
45
using System.Linq;
56
using System.Net.Http;
67
using Microsoft.SemanticKernel.Plugins.OpenApi;
@@ -255,13 +256,15 @@ public void ItShouldSetAlternativeNameToParametersForPutAndPostOperation(string
255256
private static RestApiOperation CreateTestOperation(string method, RestApiOperationPayload? payload = null, Uri? url = null)
256257
{
257258
return new RestApiOperation(
258-
id: "fake-id",
259-
servers: [new(url?.AbsoluteUri)],
260-
path: "fake-path",
261-
method: new HttpMethod(method),
262-
description: "fake-description",
263-
parameters: [],
264-
payload: payload);
259+
id: "fake-id",
260+
servers: [new(url?.AbsoluteUri)],
261+
path: "fake-path",
262+
method: new HttpMethod(method),
263+
description: "fake-description",
264+
parameters: [],
265+
responses: new Dictionary<string, RestApiOperationExpectedResponse>(),
266+
securityRequirements: [],
267+
payload: payload);
265268
}
266269

267270
private static RestApiOperationPayload CreateTestJsonPayload()

0 commit comments

Comments
 (0)