Skip to content

Commit

Permalink
.Net: Prepare OpenApi model classes to changes in OpenApi.NET v2 SDK (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
SergeyMenshykh authored Nov 7, 2024
1 parent c9ef719 commit d48e17a
Show file tree
Hide file tree
Showing 5 changed files with 412 additions and 288 deletions.
22 changes: 11 additions & 11 deletions dotnet/src/Functions/Functions.OpenApi/Model/RestApiOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ public sealed class RestApiOperation
/// <summary>
/// The operation identifier.
/// </summary>
public string Id { get; }
public string? Id { get; }

/// <summary>
/// The operation description.
/// </summary>
public string Description { get; }
public string? Description { get; }

/// <summary>
/// The operation path.
Expand All @@ -59,7 +59,7 @@ public sealed class RestApiOperation
/// <summary>
/// The security requirements.
/// </summary>
public IReadOnlyList<RestApiSecurityRequirement>? SecurityRequirements { get; }
public IReadOnlyList<RestApiSecurityRequirement> SecurityRequirements { get; }

/// <summary>
/// The operation parameters.
Expand Down Expand Up @@ -90,29 +90,29 @@ public sealed class RestApiOperation
/// <param name="method">The operation method.</param>
/// <param name="description">The operation description.</param>
/// <param name="parameters">The operation parameters.</param>
/// <param name="payload">The operation payload.</param>
/// <param name="responses">The operation responses.</param>
/// <param name="securityRequirements">The operation security requirements.</param>
/// <param name="payload">The operation payload.</param>
internal RestApiOperation(
string id,
string? id,
IReadOnlyList<RestApiOperationServer> servers,
string path,
HttpMethod method,
string description,
string? description,
IReadOnlyList<RestApiOperationParameter> parameters,
RestApiOperationPayload? payload = null,
IReadOnlyDictionary<string, RestApiOperationExpectedResponse>? responses = null,
IReadOnlyList<RestApiSecurityRequirement>? securityRequirements = null)
IReadOnlyDictionary<string, RestApiOperationExpectedResponse> responses,
IReadOnlyList<RestApiSecurityRequirement> securityRequirements,
RestApiOperationPayload? payload = null)
{
this.Id = id;
this.Servers = servers;
this.Path = path;
this.Method = method;
this.Description = description;
this.Parameters = parameters;
this.Payload = payload;
this.Responses = responses ?? new Dictionary<string, RestApiOperationExpectedResponse>();
this.Responses = responses;
this.SecurityRequirements = securityRequirements;
this.Payload = payload;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ private static string ConvertOperationToValidFunctionName(RestApiOperation opera
{
if (!string.IsNullOrWhiteSpace(operation.Id))
{
return ConvertOperationIdToValidFunctionName(operationId: operation.Id, logger: logger);
return ConvertOperationIdToValidFunctionName(operationId: operation.Id!, logger: logger);
}

// Tokenize operation path on forward and back slashes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using Microsoft.SemanticKernel.Plugins.OpenApi;
Expand Down Expand Up @@ -255,13 +256,15 @@ public void ItShouldSetAlternativeNameToParametersForPutAndPostOperation(string
private static RestApiOperation CreateTestOperation(string method, RestApiOperationPayload? payload = null, Uri? url = null)
{
return new RestApiOperation(
id: "fake-id",
servers: [new(url?.AbsoluteUri)],
path: "fake-path",
method: new HttpMethod(method),
description: "fake-description",
parameters: [],
payload: payload);
id: "fake-id",
servers: [new(url?.AbsoluteUri)],
path: "fake-path",
method: new HttpMethod(method),
description: "fake-description",
parameters: [],
responses: new Dictionary<string, RestApiOperationExpectedResponse>(),
securityRequirements: [],
payload: payload);
}

private static RestApiOperationPayload CreateTestJsonPayload()
Expand Down
Loading

0 comments on commit d48e17a

Please sign in to comment.