Skip to content

Commit

Permalink
Add NotificationUrl to ConnectorParameters
Browse files Browse the repository at this point in the history
  • Loading branch information
LucGenetier committed Oct 23, 2024
1 parent 738ef27 commit 3ccb917
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public static class Constants
public const string XMsKeyOrder = "x-ms-keyOrder";
public const string XMsKeyType = "x-ms-keyType";
public const string XMsMediaKind = "x-ms-media-kind";
public const string XMsNotificationUrl = "x-ms-notification-url";
public const string XMsNotificationContent = "x-ms-notification-content";
public const string XMsPageable = "x-ms-pageable";
public const string XMsPermission = "x-ms-permission";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,8 @@ internal static bool TryGetOpenApiValue(IOpenApiAny openApiAny, FormulaType form

internal static string GetMediaKind(this ISwaggerExtensions schema) => schema.Extensions.TryGetValue(XMsMediaKind, out IOpenApiExtension openApiExt) && openApiExt is OpenApiString openApiStr ? openApiStr.Value : null;

internal static bool? GetNotificationUrl(this ISwaggerExtensions schema) => schema.Extensions.TryGetValue(XMsNotificationUrl, out IOpenApiExtension openApiExt) && openApiExt is OpenApiBoolean openApiBool ? openApiBool.Value : null;

internal static (bool IsPresent, string Value) GetString(this IDictionary<string, IOpenApiAny> apiObj, string str) => apiObj.TryGetValue(str, out IOpenApiAny openApiAny) && openApiAny is OpenApiString openApiStr ? (true, openApiStr.Value) : (false, null);

internal static void WhenPresent(this IDictionary<string, IOpenApiAny> apiObj, string propName, Action<string> action)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public class ConnectorSchema : SupportsConnectorErrors
public string Summary => ConnectorExtensions.Summary;

public bool SupportsDynamicIntellisense => ConnectorType.SupportsDynamicIntellisense;

public bool? NotificationUrl => ConnectorType.NotificationUrl;

internal ConnectorSchema(ISwaggerParameter openApiParameter, ISwaggerExtensions bodyExtensions, bool useHiddenTypes, ConnectorCompatibility compatibility)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ public class ConnectorType : SupportsConnectorErrors

public ConnectorPermission Permission { get; }

// Supports x-ms-notification-url
public bool? NotificationUrl { get; }

internal RecordType HiddenRecordType { get; }

// Supports x-ms-dynamic-values or -list locally
Expand Down Expand Up @@ -126,6 +129,7 @@ internal ConnectorType(ISwaggerSchema schema, ISwaggerParameter openApiParameter
Schema = schema;
Binary = schema.Format == "binary" || schema.Format == "no_format";
MediaKind = openApiParameter?.GetMediaKind().ToMediaKind() ?? (Binary ? MediaKind.File : MediaKind.NotBinary);
NotificationUrl = openApiParameter?.GetNotificationUrl();

if (schema != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1838,10 +1838,10 @@ public async Task SharePointOnlineTest()
}

[Theory]
[InlineData(ConnectorCompatibility.SwaggerCompatibility, true, 4, "poster, location, notificationUrl, body")]
[InlineData(ConnectorCompatibility.PowerAppsCompatibility, false, 4, "poster, location, notificationUrl, body")]
[InlineData(ConnectorCompatibility.SwaggerCompatibility, false, 3, "poster, location, body")]
public void ExposeInternalParamsWithoutDefaultValueTest(ConnectorCompatibility compatibility, bool exposeInternalParamsWithoutDefaultValue, int expectedCount, string expectedParamaeters)
[InlineData(ConnectorCompatibility.SwaggerCompatibility, true, 4, "poster, location, notificationUrl, body", "<null>, <null>, True, <null>")]
[InlineData(ConnectorCompatibility.PowerAppsCompatibility, false, 4, "poster, location, notificationUrl, body", "<null>, <null>, True, <null>")]
[InlineData(ConnectorCompatibility.SwaggerCompatibility, false, 3, "poster, location, body", "<null>, <null>, <null>")]
public void ExposeInternalParamsWithoutDefaultValueTest(ConnectorCompatibility compatibility, bool exposeInternalParamsWithoutDefaultValue, int expectedCount, string expectedParameters, string expectedNotificationUrls)
{
using LoggingTestServer testConnector = new LoggingTestServer(@"Swagger\Teams.json", _output);
OpenApiDocument apiDoc = testConnector._apiDocument;
Expand All @@ -1858,7 +1858,8 @@ public void ExposeInternalParamsWithoutDefaultValueTest(ConnectorCompatibility c
ConnectorFunction function = OpenApiParser.GetFunctions(connectorSettings, apiDoc).First(f => f.Name == "PostCardAndWaitForResponse");

Assert.Equal(expectedCount, function.RequiredParameters.Length);
Assert.Equal(expectedParamaeters, string.Join(", ", function.RequiredParameters.Select(rp => rp.Name)));
Assert.Equal(expectedParameters, string.Join(", ", function.RequiredParameters.Select(rp => rp.Name)));
Assert.Equal(expectedNotificationUrls, string.Join(", ", function.RequiredParameters.Select(rp => rp.NotificationUrl.HasValue ? rp.NotificationUrl.ToString() : "<null>")));
}

[Fact]
Expand Down

0 comments on commit 3ccb917

Please sign in to comment.