Skip to content

Commit 13148df

Browse files
committed
Merge branch 'master' into stef-aspire
2 parents c76b76d + 926eaae commit 13148df

File tree

22 files changed

+38871
-85
lines changed

22 files changed

+38871
-85
lines changed

CHANGELOG.md

+12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
# 1.5.61 (22 July 2024)
2+
- [#1122](https://github.com/WireMock-Net/WireMock.Net/pull/1122) - Fix OpenApiPathsMapper [bug] contributed by [StefH](https://github.com/StefH)
3+
- [#1135](https://github.com/WireMock-Net/WireMock.Net/pull/1135) - Bump System.Text.Json from 4.7.2 to 8.0.4 in /examples/WireMock.Net.Console.Net472.Classic [dependencies] contributed by [dependabot[bot]](https://github.com/apps/dependabot)
4+
- [#1136](https://github.com/WireMock-Net/WireMock.Net/pull/1136) - Bump System.Text.Json from 8.0.0 to 8.0.4 in /src/dotnet-WireMock.Net [dependencies] contributed by [dependabot[bot]](https://github.com/apps/dependabot)
5+
- [#1137](https://github.com/WireMock-Net/WireMock.Net/pull/1137) - Add link to TIOBE Index on main page + fix issues [refactor] contributed by [StefH](https://github.com/StefH)
6+
- [#1138](https://github.com/WireMock-Net/WireMock.Net/pull/1138) - Fix some SonarCloud warnings [refactor] contributed by [StefH](https://github.com/StefH)
7+
- [#1141](https://github.com/WireMock-Net/WireMock.Net/pull/1141) - Update WireMockContainerBuilder.WithMappings for "includeSubDirectories" [feature] contributed by [StefH](https://github.com/StefH)
8+
- [#1142](https://github.com/WireMock-Net/WireMock.Net/pull/1142) - Make property FromConfiguredStub nullable (for WireMock.Org) [bug] contributed by [StefH](https://github.com/StefH)
9+
- [#1118](https://github.com/WireMock-Net/WireMock.Net/issues/1118) - Generating mappings from Payroc open-api file gives ArgumentException: Property with the same name already exists on object [bug]
10+
- [#1139](https://github.com/WireMock-Net/WireMock.Net/issues/1139) - Allow WithMappings to support scanning SubDirectories when building a WireMockContainer [feature]
11+
- [#1140](https://github.com/WireMock-Net/WireMock.Net/issues/1140) - WireMock.Org nullable properties and defaults [bug]
12+
113
# 1.5.60 (09 July 2024)
214
- [#1128](https://github.com/WireMock-Net/WireMock.Net/pull/1128) - Add Handlebars.Net.Helpers.Xslt [feature] contributed by [StefH](https://github.com/StefH)
315
- [#1130](https://github.com/WireMock-Net/WireMock.Net/pull/1130) - Add AdminPath to WireMockServerSettings [feature] contributed by [StefH](https://github.com/StefH)

Directory.Build.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
</PropertyGroup>
55

66
<PropertyGroup>
7-
<VersionPrefix>1.5.60</VersionPrefix>
7+
<VersionPrefix>1.5.61</VersionPrefix>
88
<PackageIcon>WireMock.Net-Logo.png</PackageIcon>
99
<PackageProjectUrl>https://github.com/WireMock-Net/WireMock.Net</PackageProjectUrl>
1010
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>

Generate-ReleaseNotes.cmd

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
rem https://github.com/StefH/GitHubReleaseNotes
22

3-
SET version=1.5.60
3+
SET version=1.5.61
44

55
GitHubReleaseNotes --output CHANGELOG.md --skip-empty-releases --exclude-labels question invalid doc duplicate example environment --version %version% --token %GH_TOKEN%
66

PackageReleaseNotes.txt

+11-9
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
# 1.5.60 (09 July 2024)
2-
- #1128 Add Handlebars.Net.Helpers.Xslt [feature]
3-
- #1130 Add AdminPath to WireMockServerSettings [feature]
4-
- #1131 Add unit tests for AdminApiMappingBuilder [test]
5-
- #1132 Multipart Matcher Fix [bug]
6-
- #1133 Add unit tests for AdminApiMappingBuilder_ [test]
7-
- #1134 Remove some files and folders [refactor]
8-
- #1119 Error in RequestMessageMultiPartMatcher [bug]
9-
- #1121 XML transformation [feature]
1+
# 1.5.61 (22 July 2024)
2+
- #1122 Fix OpenApiPathsMapper [bug]
3+
- #1135 Bump System.Text.Json from 4.7.2 to 8.0.4 in /examples/WireMock.Net.Console.Net472.Classic [dependencies]
4+
- #1136 Bump System.Text.Json from 8.0.0 to 8.0.4 in /src/dotnet-WireMock.Net [dependencies]
5+
- #1137 Add link to TIOBE Index on main page + fix issues [refactor]
6+
- #1138 Fix some SonarCloud warnings [refactor]
7+
- #1141 Update WireMockContainerBuilder.WithMappings for &quot;includeSubDirectories&quot; [feature]
8+
- #1142 Make property FromConfiguredStub nullable (for WireMock.Org) [bug]
9+
- #1118 Generating mappings from Payroc open-api file gives ArgumentException: Property with the same name already exists on object [bug]
10+
- #1139 Allow WithMappings to support scanning SubDirectories when building a WireMockContainer [feature]
11+
- #1140 WireMock.Org nullable properties and defaults [bug]
1012

1113
The full release notes can be found here: https://github.com/WireMock-Net/WireMock.Net/blob/master/CHANGELOG.md

examples/WireMock.Net.Client/Program.cs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Copyright © WireMock.Net
2+
13
using System;
24
using System.Net.Http.Headers;
35
using System.Text;
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
// Copyright © WireMock.Net
2+
13
// C# Hello
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
// Copyright © WireMock.Net
2+
13
// C# Hello

hdr.ps1

+5-4
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ function Write-Header ($file) {
77
$content = Get-Content $file -Raw # Using -Raw to read the entire file as a single string
88
$filename = Split-Path -Leaf $file
99

10-
# Check if the file content starts with the auto-generated line
11-
if ($content.TrimStart().StartsWith("// <auto-generated>")) {
12-
Write-Host "Skipping auto-generated file: $filename"
10+
if ($content.TrimStart().StartsWith($header.Trim())) {
11+
# Write-Host "Skipping existing: $filename"
12+
} elseif ($content.TrimStart().StartsWith("// <auto-generated>")) {
13+
# Write-Host "Skipping auto-generated file: $filename"
1314
} else {
14-
# If not an auto-generated file, prepend the header
15+
Write-Host "Prepend the header for file: $filename"
1516
Set-Content $file $header
1617
Add-Content $file $content -NoNewline # Writing back to the file without an extra newline
1718
}

src/Directory.Build.props

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
<PrivateAssets>all</PrivateAssets>
1010
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1111
</PackageReference>
12+
<!-- <PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556">
13+
<PrivateAssets>all</PrivateAssets>
14+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
15+
</PackageReference> -->
1216
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0" PrivateAssets="All" />
1317
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
1418
</ItemGroup>

src/WireMock.Net.OpenApiParser/Extensions/OpenApiSchemaExtensions.cs

+23-24
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Copyright © WireMock.Net
22

3+
using System.Linq;
34
using Microsoft.OpenApi.Any;
45
using Microsoft.OpenApi.Interfaces;
56
using Microsoft.OpenApi.Models;
@@ -16,7 +17,7 @@ public static bool TryGetXNullable(this OpenApiSchema schema, out bool value)
1617
{
1718
value = false;
1819

19-
if (schema.Extensions.TryGetValue("x-nullable", out IOpenApiExtension e) && e is OpenApiBoolean openApiBoolean)
20+
if (schema.Extensions.TryGetValue("x-nullable", out var e) && e is OpenApiBoolean openApiBoolean)
2021
{
2122
value = openApiBoolean.Value;
2223
return true;
@@ -27,32 +28,30 @@ public static bool TryGetXNullable(this OpenApiSchema schema, out bool value)
2728

2829
public static SchemaType GetSchemaType(this OpenApiSchema? schema)
2930
{
30-
switch (schema?.Type)
31+
if (schema == null)
3132
{
32-
case "object":
33-
return SchemaType.Object;
34-
35-
case "array":
36-
return SchemaType.Array;
37-
38-
case "integer":
39-
return SchemaType.Integer;
40-
41-
case "number":
42-
return SchemaType.Number;
43-
44-
case "boolean":
45-
return SchemaType.Boolean;
46-
47-
case "string":
48-
return SchemaType.String;
49-
50-
case "file":
51-
return SchemaType.File;
33+
return SchemaType.Unknown;
34+
}
5235

53-
default:
54-
return SchemaType.Unknown;
36+
if (schema.Type == null)
37+
{
38+
if (schema.AllOf.Any() || schema.AnyOf.Any())
39+
{
40+
return SchemaType.Object;
41+
}
5542
}
43+
44+
return schema.Type switch
45+
{
46+
"object" => SchemaType.Object,
47+
"array" => SchemaType.Array,
48+
"integer" => SchemaType.Integer,
49+
"number" => SchemaType.Number,
50+
"boolean" => SchemaType.Boolean,
51+
"string" => SchemaType.String,
52+
"file" => SchemaType.File,
53+
_ => SchemaType.Unknown
54+
};
5655
}
5756

5857
public static SchemaFormat GetSchemaFormat(this OpenApiSchema? schema)

src/WireMock.Net.OpenApiParser/Mappers/OpenApiPathsMapper.cs

+4-6
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ private static bool TryGetContent(IDictionary<string, OpenApiMediaType>? content
193193
}
194194
else
195195
{
196-
jArray.Add(MapSchemaToObject(schema.Items, name));
196+
var arrayItem = MapSchemaToObject(schema.Items, name: null); // Set name to null to force JObject instead of JProperty
197+
jArray.Add(arrayItem);
197198
}
198199
}
199200

@@ -219,12 +220,9 @@ private static bool TryGetContent(IDictionary<string, OpenApiMediaType>? content
219220

220221
if (schema.AllOf.Count > 0)
221222
{
222-
foreach (var property in schema.AllOf)
223+
foreach (var group in schema.AllOf.SelectMany(p => p.Properties).GroupBy(x => x.Key))
223224
{
224-
foreach (var item in property.Properties)
225-
{
226-
propertyAsJObject.Add(MapPropertyAsJObject(item.Value, item.Key));
227-
}
225+
propertyAsJObject.Add(MapPropertyAsJObject(group.First().Value, group.Key));
228226
}
229227
}
230228

src/WireMock.Net.OpenApiParser/Settings/WireMockOpenApiParserSettings.cs

+14-6
Original file line numberDiff line numberDiff line change
@@ -39,27 +39,35 @@ public class WireMockOpenApiParserSettings
3939
public IWireMockOpenApiParserExampleValues? ExampleValues { get; set; }
4040

4141
/// <summary>
42-
/// Is a Header match case insensitive? (default is true).
42+
/// Is a Header match case-insensitive?
43+
///
44+
/// Default is <c>true</c>.
4345
/// </summary>
4446
public bool HeaderPatternIgnoreCase { get; set; } = true;
4547

4648
/// <summary>
47-
/// Is a Query Parameter match case insensitive? (default is true).
49+
/// Is a Query Parameter match case-insensitive?
50+
///
51+
/// Default is <c>true</c>.
4852
/// </summary>
4953
public bool QueryParameterPatternIgnoreCase { get; set; } = true;
5054

5155
/// <summary>
52-
/// Is a Request Body match case insensitive? (default is true).
56+
/// Is a Request Body match case-insensitive?
57+
///
58+
/// Default is <c>true</c>.
5359
/// </summary>
5460
public bool RequestBodyIgnoreCase { get; set; } = true;
5561

5662
/// <summary>
57-
/// Is a ExampleValue match case insensitive? (default is true).
63+
/// Is a ExampleValue match case-insensitive?
64+
///
65+
/// Default is <c>true</c>.
5866
/// </summary>
5967
public bool IgnoreCaseExampleValues { get; set; } = true;
6068

6169
/// <summary>
62-
/// Are examples generated dynamically? (default is false).
70+
/// Are examples generated dynamically?
6371
/// </summary>
64-
public bool DynamicExamples { get; set; } = false;
72+
public bool DynamicExamples { get; set; }
6573
}

src/WireMock.Net.Testcontainers/WireMockContainerBuilder.cs

+8-8
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
namespace WireMock.Net.Testcontainers;
1414

1515
/// <summary>
16-
/// An specific fluent Docker container builder for WireMock.Net
16+
/// A specific fluent Docker container builder for WireMock.Net
1717
/// </summary>
1818
public sealed class WireMockContainerBuilder : ContainerBuilder<WireMockContainerBuilder, WireMockContainer, WireMockConfiguration>
1919
{
@@ -101,6 +101,7 @@ public WireMockContainerBuilder WithReadStaticMappings()
101101
/// <summary>
102102
/// Watch the static mapping files + folder for changes when running.
103103
/// </summary>
104+
/// <param name="includeSubDirectories">Also look in SubDirectories.</param>
104105
/// <returns>A configured instance of <see cref="WireMockContainerBuilder"/></returns>
105106
[PublicAPI]
106107
public WireMockContainerBuilder WithWatchStaticMappings(bool includeSubDirectories)
@@ -112,21 +113,20 @@ public WireMockContainerBuilder WithWatchStaticMappings(bool includeSubDirectori
112113
/// Specifies the path for the (static) mapping json files.
113114
/// </summary>
114115
/// <param name="path">The path</param>
115-
/// <returns></returns>
116+
/// <param name="includeSubDirectories">Also look in SubDirectories.</param>
117+
/// <returns>A configured instance of <see cref="WireMockContainerBuilder"/></returns>
116118
[PublicAPI]
117-
public WireMockContainerBuilder WithMappings(string path)
119+
public WireMockContainerBuilder WithMappings(string path, bool includeSubDirectories = false)
118120
{
119121
Guard.NotNullOrEmpty(path);
120122

121123
var isWindows = _isWindowsAsLazy.Value.GetAwaiter().GetResult();
122124

123-
return WithReadStaticMappings().WithBindMount(path, _info[isWindows].MappingsPath);
125+
return WithReadStaticMappings()
126+
.WithCommand($"--WatchStaticMappingsInSubdirectories {includeSubDirectories}")
127+
.WithBindMount(path, _info[isWindows].MappingsPath);
124128
}
125129

126-
/// <summary>
127-
/// Initializes a new instance of the <see cref="WireMockContainerBuilder" /> class.
128-
/// </summary>
129-
/// <param name="dockerResourceConfiguration">The Docker resource configuration.</param>
130130
private WireMockContainerBuilder(WireMockConfiguration dockerResourceConfiguration) : base(dockerResourceConfiguration)
131131
{
132132
DockerResourceConfiguration = dockerResourceConfiguration;

src/WireMock.Net/Transformers/Handlebars/IHandlebarsContext.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace WireMock.Transformers.Handlebars;
66

7-
interface IHandlebarsContext : ITransformerContext
7+
internal interface IHandlebarsContext : ITransformerContext
88
{
99
IHandlebars Handlebars { get; }
1010
}
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,58 @@
11
// Copyright © WireMock.Net
22

3+
using System;
34
using System.Collections.Generic;
5+
using System.Diagnostics;
46
using System.IO;
5-
using System.Linq;
67
using System.Reflection;
78
using HandlebarsDotNet;
89
using HandlebarsDotNet.Helpers;
910
using HandlebarsDotNet.Helpers.Helpers;
1011
using WireMock.Handlers;
1112

12-
namespace WireMock.Transformers.Handlebars
13+
namespace WireMock.Transformers.Handlebars;
14+
15+
internal static class WireMockHandlebarsHelpers
1316
{
14-
internal static class WireMockHandlebarsHelpers
17+
public static void Register(IHandlebars handlebarsContext, IFileSystemHandler fileSystemHandler)
1518
{
16-
public static void Register(IHandlebars handlebarsContext, IFileSystemHandler fileSystemHandler)
19+
// Register https://github.com/StefH/Handlebars.Net.Helpers
20+
HandlebarsHelpers.Register(handlebarsContext, o =>
1721
{
18-
// Register https://github.com/StefH/Handlebars.Net.Helpers
19-
HandlebarsHelpers.Register(handlebarsContext, o =>
22+
var paths = new List<string>
23+
{
24+
Directory.GetCurrentDirectory(),
25+
GetBaseDirectory(),
26+
};
27+
28+
#if !NETSTANDARD1_3_OR_GREATER
29+
void Add(string? path, ICollection<string> customHelperPaths)
2030
{
21-
o.CustomHelperPaths = new string[]
31+
if (!string.IsNullOrEmpty(path))
2232
{
23-
Directory.GetCurrentDirectory()
24-
#if !NETSTANDARD1_3
25-
, Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)
26-
#endif
33+
customHelperPaths.Add(path!);
2734
}
28-
.Distinct()
29-
.ToList();
35+
}
36+
Add(Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location), paths);
37+
Add(Path.GetDirectoryName(Assembly.GetCallingAssembly().Location), paths);
38+
Add(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), paths);
39+
Add(Path.GetDirectoryName(Process.GetCurrentProcess().MainModule?.FileName), paths);
40+
#endif
41+
o.CustomHelperPaths = paths;
3042

31-
o.CustomHelpers = new Dictionary<string, IHelpers>
32-
{
33-
{ "File", new FileHelpers(handlebarsContext, fileSystemHandler) }
34-
};
35-
});
36-
}
43+
o.CustomHelpers = new Dictionary<string, IHelpers>
44+
{
45+
{ "File", new FileHelpers(handlebarsContext, fileSystemHandler) }
46+
};
47+
});
48+
}
49+
50+
private static string GetBaseDirectory()
51+
{
52+
#if NETSTANDARD1_3_OR_GREATER || NET6_0_OR_GREATER
53+
return AppContext.BaseDirectory.TrimEnd(Path.DirectorySeparatorChar);
54+
#else
55+
return AppDomain.CurrentDomain.BaseDirectory.TrimEnd(Path.DirectorySeparatorChar);
56+
#endif
3757
}
3858
}

src/WireMock.Net/Util/StringUtils.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ namespace WireMock.Util;
1111
internal static class StringUtils
1212
{
1313
private static readonly string[] ValidUriSchemes =
14-
{
14+
[
1515
"ftp://",
1616
"http://",
1717
"https://"
18-
};
18+
];
1919

2020
private static readonly Func<string, (bool IsConverted, object ConvertedValue)>[] ConversionsFunctions =
21-
{
21+
[
2222
s => bool.TryParse(s, out var result) ? (true, result) : (false, s),
2323
s => int.TryParse(s, out var result) ? (true, result) : (false, s),
2424
s => long.TryParse(s, out var result) ? (true, result) : (false, s),
@@ -36,7 +36,7 @@ internal static class StringUtils
3636

3737
return (false, s);
3838
}
39-
};
39+
];
4040

4141
public static (bool IsConverted, object ConvertedValue) TryConvertToKnownType(string value)
4242
{

0 commit comments

Comments
 (0)