Skip to content
This repository was archived by the owner on Feb 23, 2024. It is now read-only.

Commit 43e6806

Browse files
f-alizadaFarhad Alizada
andauthored
Add parameterExampleContract definition for API request/response Models (#706)
Co-authored-by: Farhad Alizada <falizada@microsoft.com>
1 parent f394e5c commit 43e6806

File tree

5 files changed

+44
-3
lines changed

5 files changed

+44
-3
lines changed

src/ArmTemplates/Common/Templates/ApiOperations/ApiOperationRepresentation.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Copyright (c) Microsoft Corporation. All rights reserved.
33
// Licensed under the MIT License.
44
// --------------------------------------------------------------------------
5+
using System.Collections.Generic;
56

67
namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.ApiOperations
78
{
@@ -14,5 +15,7 @@ public class ApiOperationRepresentation
1415
public string TypeName { get; set; }
1516

1617
public string Sample { get; set; }
18+
19+
public IDictionary<string, ParameterExampleContract> Examples { get; set; }
1720
}
1821
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// --------------------------------------------------------------------------
2+
// Copyright (c) Microsoft Corporation. All rights reserved.
3+
// Licensed under the MIT License.
4+
// --------------------------------------------------------------------------
5+
6+
namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.ApiOperations
7+
{
8+
public class ParameterExampleContract
9+
{
10+
public string Description { get; set; }
11+
12+
public string ExternalValue { get; set; }
13+
14+
public string Summary { get; set; }
15+
16+
public object Value { get; set; }
17+
}
18+
}

tests/ArmTemplates.Tests/Extractor/Scenarios/ApiExtractorTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ public async Task GenerateApiTemplates_ProperlyLaysTheInformation()
125125
apiTemplate.TypedResources.ApiOperations.All(x => x.Properties is not null).Should().BeTrue();
126126
apiTemplate.TypedResources.ApiOperations.SelectMany(x => x.DependsOn).Any(x => x.Contains($"'{ResourceTypeConstants.API}'")).Should().BeTrue();
127127
apiTemplate.TypedResources.ApiOperations.SelectMany(x => x.DependsOn).Any(x => x.Contains($"'{ResourceTypeConstants.APIOperation}'")).Should().BeFalse();
128+
apiTemplate.TypedResources.ApiOperations.All(x => x.Properties.Request.Representations.Count() == 1).Should().BeTrue();
129+
apiTemplate.TypedResources.ApiOperations.All(x => x.Properties.Responses.Count() == 1).Should().BeTrue();
130+
apiTemplate.TypedResources.ApiOperations.All(x => x.Properties.Request.Representations.All(o => o.Examples.Count > 0)).Should().BeTrue();
131+
apiTemplate.TypedResources.ApiOperations.All(x => x.Properties.Request.Representations.All(o => o.Examples.ContainsKey("default"))).Should().BeTrue();
128132

129133
// api operations policies
130134
apiTemplate.TypedResources.ApiOperationsPolicies.Count().Should().Be(2);

tests/ArmTemplates.Tests/Moqs/ApiClients/MockApiOperationClient.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ public class MockApiOperationClient
4646
{
4747
ContentType = "application/json",
4848
SchemaId = "api-operation-representation-schema-id",
49-
TypeName = "api-operation-representation-type-name"
49+
TypeName = "api-operation-representation-type-name",
50+
Examples = new Dictionary<string, ParameterExampleContract>() {
51+
{"default", new ParameterExampleContract { Description = "description", Value = new object(), Summary = "summary" } }
52+
}
5053
}
5154
}
5255
};
@@ -70,7 +73,11 @@ public class MockApiOperationClient
7073
{
7174
ContentType = "application/json",
7275
SchemaId = "api-operation-representation-schema-id",
73-
TypeName = "api-operation-representation-type-name"
76+
TypeName = "api-operation-representation-type-name",
77+
Examples = new Dictionary<string, ParameterExampleContract>() {
78+
{"default", new ParameterExampleContract { Description = "description", Value = "plain value", Summary = "summary" } },
79+
{"not default", new ParameterExampleContract { Description = "description", Value = new object(), Summary = "summary" } }
80+
}
7481
}
7582
}
7683
};

tests/ArmTemplates.Tests/Moqs/ApiClients/MockApisClient.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,23 @@ public static IApisClient GetMockedApiClientWithDefaultValues()
8585
});
8686

8787
mockServiceApiProductsApiClient
88-
.Setup(x => x.GetSingleAsync(It.IsAny<string>(), It.IsAny<ExtractorParameters>()))
88+
.Setup(x => x.GetSingleAsync(It.Is<string>((o => o.Equals(ServiceApiName1))), It.IsAny<ExtractorParameters>()))
8989
.ReturnsAsync(new ApiTemplateResource
9090
{
9191
Name = ServiceApiName1,
9292
Type = TemplateType,
9393
Properties = ServiceApiProperties1
9494
});
9595

96+
mockServiceApiProductsApiClient
97+
.Setup(x => x.GetSingleAsync(It.Is<string>((o => o.Equals(ServiceApiName2))), It.IsAny<ExtractorParameters>()))
98+
.ReturnsAsync(new ApiTemplateResource
99+
{
100+
Name = ServiceApiName2,
101+
Type = TemplateType,
102+
Properties = ServiceApiProperties2
103+
});
104+
96105

97106

98107
mockServiceApiProductsApiClient

0 commit comments

Comments
 (0)