From b60919109587cf9c261b20af071947a556d0f741 Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Thu, 1 Jun 2023 21:14:13 +0200 Subject: [PATCH] . --- .../WireMock.Net.OpenApiParser.ConsoleApp/Program.cs | 3 ++- .../WireMock.Net.OpenApiParser.ConsoleApp/Run.cs | 4 ++-- .../Utils/RegexExampleValueGenerator.cs | 2 +- .../WireMockOpenApiParser.cs | 12 ++++++++++-- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/examples/WireMock.Net.OpenApiParser.ConsoleApp/Program.cs b/examples/WireMock.Net.OpenApiParser.ConsoleApp/Program.cs index fa4e9293..7647666c 100644 --- a/examples/WireMock.Net.OpenApiParser.ConsoleApp/Program.cs +++ b/examples/WireMock.Net.OpenApiParser.ConsoleApp/Program.cs @@ -1,5 +1,6 @@ using System; using System.IO; +using WireMock.Net.OpenApiParser.Types; using WireMock.RequestBuilders; using WireMock.ResponseBuilders; @@ -18,7 +19,7 @@ class Program private static void RunMockServerWithDynamicExampleGeneration() { // Run your mocking framework specifying your Example Values generator class. - var serverCustomer_V2_json = Run.RunServer(Path.Combine(Folder, "Swagger_Customer_V2.0.json"), "http://localhost:8090/", true, new DynamicDataGeneration(), Types.PatternType.Value, Types.PatternType.Value); + var serverCustomer_V2_json = Run.RunServer(Path.Combine(Folder, "Swagger_Customer_V2.0.json"), "http://localhost:8090/", true, new DynamicDataGeneration(), ExampleValueType.Value, ExampleValueType.Value); Console.WriteLine("Press any key to stop the servers"); Console.ReadKey(); diff --git a/examples/WireMock.Net.OpenApiParser.ConsoleApp/Run.cs b/examples/WireMock.Net.OpenApiParser.ConsoleApp/Run.cs index f8eb7c81..4ff3f775 100644 --- a/examples/WireMock.Net.OpenApiParser.ConsoleApp/Run.cs +++ b/examples/WireMock.Net.OpenApiParser.ConsoleApp/Run.cs @@ -18,8 +18,8 @@ public static class Run string url, bool dynamicExamples = true, IWireMockOpenApiParserExampleValues? examplesValuesGenerator = null, - PatternType pathPatternToUse = PatternType.Wildcard, - PatternType headerPatternToUse = PatternType.Wildcard + ExampleValueType pathPatternToUse = ExampleValueType.Wildcard, + ExampleValueType headerPatternToUse = ExampleValueType.Wildcard ) { var server = WireMockServer.Start(new WireMockServerSettings diff --git a/src/WireMock.Net.OpenApiParser/Utils/RegexExampleValueGenerator.cs b/src/WireMock.Net.OpenApiParser/Utils/RegexExampleValueGenerator.cs index e2a63f52..a1d6e432 100644 --- a/src/WireMock.Net.OpenApiParser/Utils/RegexExampleValueGenerator.cs +++ b/src/WireMock.Net.OpenApiParser/Utils/RegexExampleValueGenerator.cs @@ -21,7 +21,7 @@ internal class RegexExampleValueGenerator : IExampleValueGenerator return @"(true|false)"; case SchemaType.Integer: - return @"-?\d+$"; + return @"-?\d+"; case SchemaType.Number: return @"[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?"; diff --git a/src/WireMock.Net.OpenApiParser/WireMockOpenApiParser.cs b/src/WireMock.Net.OpenApiParser/WireMockOpenApiParser.cs index d690f8cb..52daa140 100644 --- a/src/WireMock.Net.OpenApiParser/WireMockOpenApiParser.cs +++ b/src/WireMock.Net.OpenApiParser/WireMockOpenApiParser.cs @@ -9,6 +9,7 @@ using RamlToOpenApiConverter; using WireMock.Admin.Mappings; using WireMock.Net.OpenApiParser.Mappers; using WireMock.Net.OpenApiParser.Settings; +using WireMock.Net.OpenApiParser.Types; namespace WireMock.Net.OpenApiParser; @@ -17,13 +18,20 @@ namespace WireMock.Net.OpenApiParser; /// public class WireMockOpenApiParser : IWireMockOpenApiParser { + private readonly WireMockOpenApiParserSettings _wireMockOpenApiParserSettings = new WireMockOpenApiParserSettings + { + HeaderPatternToUse = ExampleValueType.Regex, + QueryParameterPatternToUse = ExampleValueType.Regex, + PathPatternToUse = ExampleValueType.Regex + }; + private readonly OpenApiStreamReader _reader = new(); /// [PublicAPI] public IReadOnlyList FromFile(string path, out OpenApiDiagnostic diagnostic) { - return FromFile(path, new WireMockOpenApiParserSettings(), out diagnostic); + return FromFile(path, _wireMockOpenApiParserSettings, out diagnostic); } /// @@ -49,7 +57,7 @@ public class WireMockOpenApiParser : IWireMockOpenApiParser [PublicAPI] public IReadOnlyList FromDocument(OpenApiDocument openApiDocument, WireMockOpenApiParserSettings? settings = null) { - return new OpenApiPathsMapper(settings ?? new WireMockOpenApiParserSettings()).ToMappingModels(openApiDocument.Paths, openApiDocument.Servers); + return new OpenApiPathsMapper(settings ?? _wireMockOpenApiParserSettings).ToMappingModels(openApiDocument.Paths, openApiDocument.Servers); } ///