Skip to content

Commit ea7dcd0

Browse files
authored
Merge pull request #1795 from microsoft/vnext
Release libs.
2 parents 5842eff + 9a5a415 commit ea7dcd0

File tree

16 files changed

+295
-21
lines changed

16 files changed

+295
-21
lines changed

.github/workflows/docker.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ jobs:
3030
id: getversion
3131
- name: Push to GitHub Packages - Nightly
3232
if: ${{ github.ref == 'refs/heads/vnext' }}
33-
uses: docker/build-push-action@v6.5.0
33+
uses: docker/build-push-action@v6.7.0
3434
with:
3535
push: true
3636
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:nightly
3737
- name: Push to GitHub Packages - Release
3838
if: ${{ github.ref == 'refs/heads/master' }}
39-
uses: docker/build-push-action@v6.5.0
39+
uses: docker/build-push-action@v6.7.0
4040
with:
4141
push: true
4242
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest,${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.getversion.outputs.version }}

src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<Nullable>enable</Nullable>
1010
<ToolCommandName>hidi</ToolCommandName>
1111
<PackageOutputPath>./../../artifacts</PackageOutputPath>
12-
<Version>1.4.7</Version>
12+
<Version>1.4.8</Version>
1313
<Description>OpenAPI.NET CLI tool for slicing OpenAPI documents</Description>
1414
<SignAssembly>true</SignAssembly>
1515
<!-- https://github.com/dotnet/sourcelink/blob/main/docs/README.md#embeduntrackedsources -->
@@ -34,8 +34,8 @@
3434
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
3535
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
3636
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
37-
<PackageReference Include="Microsoft.OData.Edm" Version="7.21.3" />
38-
<PackageReference Include="Microsoft.OpenApi.OData" Version="1.6.8" />
37+
<PackageReference Include="Microsoft.OData.Edm" Version="8.0.1" />
38+
<PackageReference Include="Microsoft.OpenApi.OData" Version="2.0.0-preview.2" />
3939
<PackageReference Include="Microsoft.OpenApi.ApiManifest" Version="0.5.0-preview" />
4040
<PackageReference Include="System.CommandLine.Hosting" Version="0.4.0-alpha.22272.1" />
4141
</ItemGroup>

src/Microsoft.OpenApi.Workbench/Microsoft.OpenApi.Workbench.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<EnableWindowsTargeting>true</EnableWindowsTargeting>
99
</PropertyGroup>
1010
<ItemGroup>
11-
<PackageReference Include="Microsoft.Windows.Compatibility" Version="8.0.7" />
11+
<PackageReference Include="Microsoft.Windows.Compatibility" Version="8.0.8" />
1212
</ItemGroup>
1313
<ItemGroup>
1414
<Resource Include="Themes\Metro\HowToApplyTheme.txt" />
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Microsoft.OpenApi.Models;
4+
using Microsoft.OpenApi.Properties;
5+
6+
namespace Microsoft.OpenApi.Extensions;
7+
8+
/// <summary>
9+
/// Extension methods for <see cref="OpenApiServer"/> serialization.
10+
/// </summary>
11+
public static class OpenApiServerExtensions
12+
{
13+
/// <summary>
14+
/// Replaces URL variables in a server's URL
15+
/// </summary>
16+
/// <param name="server">The OpenAPI server object</param>
17+
/// <param name="values">The server variable values that will be used to replace the default values.</param>
18+
/// <returns>A URL with the provided variables substituted.</returns>
19+
/// <exception cref="ArgumentException">
20+
/// Thrown when:
21+
/// 1. A substitution has no valid value in both the supplied dictionary and the default
22+
/// 2. A substitution's value is not available in the enum provided
23+
/// </exception>
24+
public static string ReplaceServerUrlVariables(this OpenApiServer server, IDictionary<string, string> values = null)
25+
{
26+
var parsedUrl = server.Url;
27+
foreach (var variable in server.Variables)
28+
{
29+
// Try to get the value from the provided values
30+
if (values is not { } v || !v.TryGetValue(variable.Key, out var value) || string.IsNullOrEmpty(value))
31+
{
32+
// Fall back to the default value
33+
value = variable.Value.Default;
34+
}
35+
36+
// Validate value
37+
if (string.IsNullOrEmpty(value))
38+
{
39+
// According to the spec, the variable's default value is required.
40+
// This code path should be hit when a value isn't provided & a default value isn't available
41+
throw new ArgumentException(
42+
string.Format(SRResource.ParseServerUrlDefaultValueNotAvailable, variable.Key), nameof(server));
43+
}
44+
45+
// If an enum is provided, the array should not be empty & the value should exist in the enum
46+
if (variable.Value.Enum is {} e && (e.Count == 0 || !e.Contains(value)))
47+
{
48+
throw new ArgumentException(
49+
string.Format(SRResource.ParseServerUrlValueNotValid, value, variable.Key), nameof(values));
50+
}
51+
52+
parsedUrl = parsedUrl.Replace($"{{{variable.Key}}}", value);
53+
}
54+
55+
return parsedUrl;
56+
}
57+
}

src/Microsoft.OpenApi/Models/OpenApiDocument.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Security.Cryptography;
99
using System.Text;
1010
using Microsoft.OpenApi.Exceptions;
11+
using Microsoft.OpenApi.Extensions;
1112
using Microsoft.OpenApi.Interfaces;
1213
using Microsoft.OpenApi.Services;
1314
using Microsoft.OpenApi.Writers;
@@ -283,14 +284,7 @@ public void SerializeAsV2(IOpenApiWriter writer)
283284

284285
private static string ParseServerUrl(OpenApiServer server)
285286
{
286-
var parsedUrl = server.Url;
287-
288-
var variables = server.Variables;
289-
foreach (var variable in variables.Where(static x => !string.IsNullOrEmpty(x.Value.Default)))
290-
{
291-
parsedUrl = parsedUrl.Replace($"{{{variable.Key}}}", variable.Value.Default);
292-
}
293-
return parsedUrl;
287+
return server.ReplaceServerUrlVariables(new Dictionary<string, string>(0));
294288
}
295289

296290
private static void WriteHostInfoV2(IOpenApiWriter writer, IList<OpenApiServer> servers)

src/Microsoft.OpenApi/Models/OpenApiServerVariable.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ public class OpenApiServerVariable : IOpenApiSerializable, IOpenApiExtensible
2626
/// <summary>
2727
/// An enumeration of string values to be used if the substitution options are from a limited set.
2828
/// </summary>
29-
public List<string> Enum { get; set; } = new();
29+
/// <remarks>
30+
/// If the server variable in the OpenAPI document has no <code>enum</code> member, this property will be null.
31+
/// </remarks>
32+
public List<string> Enum { get; set; }
3033

3134
/// <summary>
3235
/// This object MAY be extended with Specification Extensions.

src/Microsoft.OpenApi/Properties/SRResource.Designer.cs

Lines changed: 18 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Microsoft.OpenApi/Properties/SRResource.resx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,4 +225,10 @@
225225
<data name="WorkspaceRequredForExternalReferenceResolution" xml:space="preserve">
226226
<value>OpenAPI document must be added to an OpenApiWorkspace to be able to resolve external references.</value>
227227
</data>
228+
<data name="ParseServerUrlDefaultValueNotAvailable" xml:space="preserve">
229+
<value>Invalid server variable '{0}'. A value was not provided and no default value was provided.</value>
230+
</data>
231+
<data name="ParseServerUrlValueNotValid" xml:space="preserve">
232+
<value>Value '{0}' is not a valid value for variable '{1}'. If an enum is provided, it should not be empty and the value provided should exist in the enum</value>
233+
</data>
228234
</root>

src/Microsoft.OpenApi/Validations/Rules/OpenApiServerRules.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,32 @@ public static class OpenApiServerRules
2626
context.CreateError(nameof(ServerRequiredFields),
2727
String.Format(SRResource.Validation_FieldIsRequired, "url", "server"));
2828
}
29+
30+
context.Exit();
31+
context.Enter("variables");
32+
foreach (var variable in server.Variables)
33+
{
34+
context.Enter(variable.Key);
35+
ValidateServerVariableRequiredFields(context, variable.Key, variable.Value);
36+
context.Exit();
37+
}
2938
context.Exit();
3039
});
3140

3241
// add more rules
42+
43+
/// <summary>
44+
/// Validate required fields in server variable
45+
/// </summary>
46+
private static void ValidateServerVariableRequiredFields(IValidationContext context, string key, OpenApiServerVariable item)
47+
{
48+
context.Enter("default");
49+
if (string.IsNullOrEmpty(item.Default))
50+
{
51+
context.CreateError("ServerVariableMustHaveDefaultValue",
52+
String.Format(SRResource.Validation_FieldIsRequired, "default", key));
53+
}
54+
context.Exit();
55+
}
3356
}
3457
}

test/Microsoft.OpenApi.Hidi.Tests/Microsoft.OpenApi.Hidi.Tests.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212

1313
<ItemGroup>
1414
<PackageReference Include="coverlet.msbuild" Version="6.0.2" PrivateAssets="all" />
15-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
15+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
1616
<PackageReference Include="Moq" Version="4.20.70" />
17+
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
1718
<PackageReference Include="xunit" Version="2.9.0" />
1819
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" PrivateAssets="all" />
1920
<PackageReference Include="coverlet.collector" Version="6.0.2" PrivateAssets="all" />

0 commit comments

Comments
 (0)