mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 22:30:41 +01:00
Include WireMockOpenApiParser project (#916)
* Fix some nullability warnings for WireMockOpenApiParser * . * . * . * opt * FromText * ab * . * private const string AdminOpenApi = "/__admin/openapi"; * fix test * rnd * . * urldetails * 0 * , * . * tests * . * CompressionUtilsTests * ut * .
This commit is contained in:
@@ -11,7 +11,7 @@ public class DynamicDataGeneration : WireMockOpenApiParserDynamicExampleValues
|
||||
get
|
||||
{
|
||||
// Since you have your Schema, you can get if max-length is set. You can generate accurate examples with this settings
|
||||
var maxLength = Schema.MaxLength ?? 9;
|
||||
var maxLength = Schema?.MaxLength ?? 9;
|
||||
|
||||
return RandomizerFactory.GetRandomizer(new FieldOptionsTextRegex
|
||||
{
|
||||
|
||||
@@ -17,7 +17,7 @@ class Program
|
||||
|
||||
private static void RunMockServerWithDynamicExampleGeneration()
|
||||
{
|
||||
//Run your mocking framework specifieing youur Example Values generator class.
|
||||
// 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.ExampleValueType.Value, Types.ExampleValueType.Value);
|
||||
Console.WriteLine("Press any key to stop the servers");
|
||||
|
||||
@@ -27,15 +27,15 @@ class Program
|
||||
|
||||
private static void RunOthersOpenApiParserExample()
|
||||
{
|
||||
var serverOpenAPIExamples = Run.RunServer(Path.Combine(Folder, "openAPIExamples.yaml"), "https://localhost:9091/");
|
||||
var serverPetstore_V2_json = Run.RunServer(Path.Combine(Folder, "Swagger_Petstore_V2.0.json"), "https://localhost:9092/");
|
||||
var serverPetstore_V2_yaml = Run.RunServer(Path.Combine(Folder, "Swagger_Petstore_V2.0.yaml"), "https://localhost:9093/");
|
||||
var serverPetstore_V300_yaml = Run.RunServer(Path.Combine(Folder, "Swagger_Petstore_V3.0.0.yaml"), "https://localhost:9094/");
|
||||
var serverPetstore_V302_json = Run.RunServer(Path.Combine(Folder, "Swagger_Petstore_V3.0.2.json"), "https://localhost:9095/");
|
||||
var testopenapifile_json = Run.RunServer(Path.Combine(Folder, "testopenapifile.json"), "https://localhost:9096/");
|
||||
var file_errorYaml = Run.RunServer(Path.Combine(Folder, "file_error.yaml"), "https://localhost:9097/");
|
||||
var file_petJson = Run.RunServer(Path.Combine(Folder, "pet.json"), "https://localhost:9098/");
|
||||
var refsYaml = Run.RunServer(Path.Combine(Folder, "refs.yaml"), "https://localhost:9099/");
|
||||
var serverOpenAPIExamples = Run.RunServer(Path.Combine(Folder, "openAPIExamples.yaml"), "http://localhost:9091/");
|
||||
var serverPetstore_V2_json = Run.RunServer(Path.Combine(Folder, "Swagger_Petstore_V2.0.json"), "http://localhost:9092/");
|
||||
var serverPetstore_V2_yaml = Run.RunServer(Path.Combine(Folder, "Swagger_Petstore_V2.0.yaml"), "http://localhost:9093/");
|
||||
var serverPetstore_V300_yaml = Run.RunServer(Path.Combine(Folder, "Swagger_Petstore_V3.0.0.yaml"), "http://localhost:9094/");
|
||||
var serverPetstore_V302_json = Run.RunServer(Path.Combine(Folder, "Swagger_Petstore_V3.0.2.json"), "http://localhost:9095/");
|
||||
var testopenapifile_json = Run.RunServer(Path.Combine(Folder, "testopenapifile.json"), "http://localhost:9096/");
|
||||
var file_errorYaml = Run.RunServer(Path.Combine(Folder, "file_error.yaml"), "http://localhost:9097/");
|
||||
var file_petJson = Run.RunServer(Path.Combine(Folder, "pet.json"), "http://localhost:9098/");
|
||||
var refsYaml = Run.RunServer(Path.Combine(Folder, "refs.yaml"), "http://localhost:9099/");
|
||||
|
||||
testopenapifile_json
|
||||
.Given(Request.Create().WithPath("/x").UsingGet())
|
||||
|
||||
@@ -9,64 +9,70 @@ using WireMock.Net.OpenApiParser.Types;
|
||||
using WireMock.Server;
|
||||
using WireMock.Settings;
|
||||
|
||||
namespace WireMock.Net.OpenApiParser.ConsoleApp
|
||||
namespace WireMock.Net.OpenApiParser.ConsoleApp;
|
||||
|
||||
public static class Run
|
||||
{
|
||||
public static class Run
|
||||
public static WireMockServer RunServer(
|
||||
string path,
|
||||
string url,
|
||||
bool dynamicExamples = true,
|
||||
IWireMockOpenApiParserExampleValues? examplesValuesGenerator = null,
|
||||
ExampleValueType pathPatternToUse = ExampleValueType.Wildcard,
|
||||
ExampleValueType headerPatternToUse = ExampleValueType.Wildcard
|
||||
)
|
||||
{
|
||||
public static WireMockServer RunServer(string path, string url, bool dynamicExamples = true, IWireMockOpenApiParserExampleValues examplesValuesGenerator = null, ExampleValueType pathPatternToUse = ExampleValueType.Wildcard, ExampleValueType headerPatternToUse = ExampleValueType.Wildcard)
|
||||
var server = WireMockServer.Start(new WireMockServerSettings
|
||||
{
|
||||
var server = WireMockServer.Start(new WireMockServerSettings
|
||||
{
|
||||
AllowCSharpCodeMatcher = true,
|
||||
Urls = new[] { url },
|
||||
StartAdminInterface = true,
|
||||
ReadStaticMappings = true,
|
||||
WatchStaticMappings = false,
|
||||
WatchStaticMappingsInSubdirectories = false,
|
||||
Logger = new WireMockConsoleLogger(),
|
||||
SaveUnmatchedRequests = true
|
||||
});
|
||||
AllowCSharpCodeMatcher = true,
|
||||
Urls = new[] { url },
|
||||
StartAdminInterface = true,
|
||||
ReadStaticMappings = true,
|
||||
WatchStaticMappings = false,
|
||||
WatchStaticMappingsInSubdirectories = false,
|
||||
Logger = new WireMockConsoleLogger(),
|
||||
SaveUnmatchedRequests = true
|
||||
});
|
||||
|
||||
Console.WriteLine("WireMockServer listening at {0}", string.Join(",", server.Urls));
|
||||
Console.WriteLine("WireMockServer listening at {0}", string.Join(",", server.Urls));
|
||||
|
||||
//server.SetBasicAuthentication("a", "b");
|
||||
//server.SetBasicAuthentication("a", "b");
|
||||
|
||||
var settings = new WireMockOpenApiParserSettings
|
||||
{
|
||||
DynamicExamples = dynamicExamples,
|
||||
ExampleValues = examplesValuesGenerator,
|
||||
PathPatternToUse = pathPatternToUse,
|
||||
HeaderPatternToUse = headerPatternToUse,
|
||||
};
|
||||
|
||||
server.WithMappingFromOpenApiFile(path, settings, out var diag);
|
||||
|
||||
return server;
|
||||
}
|
||||
|
||||
public static void RunServer(IEnumerable<MappingModel> mappings)
|
||||
var settings = new WireMockOpenApiParserSettings
|
||||
{
|
||||
string url1 = "http://localhost:9091/";
|
||||
DynamicExamples = dynamicExamples,
|
||||
ExampleValues = examplesValuesGenerator,
|
||||
PathPatternToUse = pathPatternToUse,
|
||||
HeaderPatternToUse = headerPatternToUse,
|
||||
};
|
||||
|
||||
var server = WireMockServer.Start(new WireMockServerSettings
|
||||
{
|
||||
AllowCSharpCodeMatcher = true,
|
||||
Urls = new[] { url1 },
|
||||
StartAdminInterface = true,
|
||||
ReadStaticMappings = false,
|
||||
WatchStaticMappings = false,
|
||||
WatchStaticMappingsInSubdirectories = false,
|
||||
Logger = new WireMockConsoleLogger(),
|
||||
});
|
||||
Console.WriteLine("WireMockServer listening at {0}", string.Join(",", server.Urls));
|
||||
server.WithMappingFromOpenApiFile(path, settings, out var diag);
|
||||
|
||||
server.SetBasicAuthentication("a", "b");
|
||||
return server;
|
||||
}
|
||||
|
||||
server.WithMapping(mappings.ToArray());
|
||||
public static void RunServer(IEnumerable<MappingModel> mappings)
|
||||
{
|
||||
string url1 = "http://localhost:9091/";
|
||||
|
||||
Console.WriteLine("Press any key to stop the server");
|
||||
System.Console.ReadKey();
|
||||
server.Stop();
|
||||
}
|
||||
var server = WireMockServer.Start(new WireMockServerSettings
|
||||
{
|
||||
AllowCSharpCodeMatcher = true,
|
||||
Urls = new[] { url1 },
|
||||
StartAdminInterface = true,
|
||||
ReadStaticMappings = false,
|
||||
WatchStaticMappings = false,
|
||||
WatchStaticMappingsInSubdirectories = false,
|
||||
Logger = new WireMockConsoleLogger(),
|
||||
});
|
||||
Console.WriteLine("WireMockServer listening at {0}", string.Join(",", server.Urls));
|
||||
|
||||
server.SetBasicAuthentication("a", "b");
|
||||
|
||||
server.WithMapping(mappings.ToArray());
|
||||
|
||||
Console.WriteLine("Press any key to stop the server");
|
||||
System.Console.ReadKey();
|
||||
server.Stop();
|
||||
}
|
||||
}
|
||||
@@ -24,8 +24,8 @@ static class Program
|
||||
|
||||
static async Task Main(string[] args)
|
||||
{
|
||||
await TestAsync().ConfigureAwait(false);
|
||||
return;
|
||||
//await TestAsync().ConfigureAwait(false);
|
||||
//return;
|
||||
|
||||
XmlConfigurator.Configure(LogRepository, new FileInfo("log4net.config"));
|
||||
|
||||
|
||||
@@ -1,44 +1,43 @@
|
||||
using System;
|
||||
using System;
|
||||
using log4net;
|
||||
using Newtonsoft.Json;
|
||||
using WireMock.Admin.Requests;
|
||||
using WireMock.Logging;
|
||||
|
||||
namespace WireMock.Net.StandAlone.NETCoreApp
|
||||
namespace WireMock.Net.StandAlone.NETCoreApp;
|
||||
|
||||
internal class WireMockLog4NetLogger : IWireMockLogger
|
||||
{
|
||||
internal class WireMockLog4NetLogger : IWireMockLogger
|
||||
private static readonly ILog Log = LogManager.GetLogger(typeof(Program));
|
||||
|
||||
public void Debug(string formatString, params object[] args)
|
||||
{
|
||||
private static readonly ILog Log = LogManager.GetLogger(typeof(Program));
|
||||
Log.DebugFormat(formatString, args);
|
||||
}
|
||||
|
||||
public void Debug(string formatString, params object[] args)
|
||||
{
|
||||
Log.DebugFormat(formatString, args);
|
||||
}
|
||||
public void Info(string formatString, params object[] args)
|
||||
{
|
||||
Log.InfoFormat(formatString, args);
|
||||
}
|
||||
|
||||
public void Info(string formatString, params object[] args)
|
||||
{
|
||||
Log.InfoFormat(formatString, args);
|
||||
}
|
||||
public void Warn(string formatString, params object[] args)
|
||||
{
|
||||
Log.WarnFormat(formatString, args);
|
||||
}
|
||||
|
||||
public void Warn(string formatString, params object[] args)
|
||||
{
|
||||
Log.WarnFormat(formatString, args);
|
||||
}
|
||||
public void Error(string formatString, params object[] args)
|
||||
{
|
||||
Log.ErrorFormat(formatString, args);
|
||||
}
|
||||
|
||||
public void Error(string formatString, params object[] args)
|
||||
{
|
||||
Log.ErrorFormat(formatString, args);
|
||||
}
|
||||
public void Error(string message, Exception exception)
|
||||
{
|
||||
Log.Error(message, exception);
|
||||
}
|
||||
|
||||
public void Error(string message, Exception exception)
|
||||
{
|
||||
Log.Error(message, exception);
|
||||
}
|
||||
|
||||
public void DebugRequestResponse(LogEntryModel logEntryModel, bool isAdminRequest)
|
||||
{
|
||||
string message = JsonConvert.SerializeObject(logEntryModel, Formatting.Indented);
|
||||
Log.DebugFormat("Admin[{0}] {1}", isAdminRequest, message);
|
||||
}
|
||||
public void DebugRequestResponse(LogEntryModel logEntryModel, bool isAdminRequest)
|
||||
{
|
||||
string message = JsonConvert.SerializeObject(logEntryModel, Formatting.Indented);
|
||||
Log.DebugFormat("Admin[{0}] {1}", isAdminRequest, message);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user