mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-24 10:22:13 +01:00
some code refactorings for WireMock.Net.OpenApiParser
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -8,6 +8,7 @@ using Microsoft.OpenApi.Models;
|
|||||||
using Microsoft.OpenApi.Writers;
|
using Microsoft.OpenApi.Writers;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
using Stef.Validation;
|
||||||
using WireMock.Admin.Mappings;
|
using WireMock.Admin.Mappings;
|
||||||
using WireMock.Net.OpenApiParser.Extensions;
|
using WireMock.Net.OpenApiParser.Extensions;
|
||||||
using WireMock.Net.OpenApiParser.Settings;
|
using WireMock.Net.OpenApiParser.Settings;
|
||||||
@@ -23,7 +24,7 @@ namespace WireMock.Net.OpenApiParser.Mappers
|
|||||||
|
|
||||||
public OpenApiPathsMapper(WireMockOpenApiParserSettings settings)
|
public OpenApiPathsMapper(WireMockOpenApiParserSettings settings)
|
||||||
{
|
{
|
||||||
_settings = settings ?? throw new ArgumentNullException(nameof(settings));
|
_settings = Guard.NotNull(settings, nameof(settings));
|
||||||
_exampleValueGenerator = new ExampleValueGenerator(settings);
|
_exampleValueGenerator = new ExampleValueGenerator(settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -243,7 +244,7 @@ namespace WireMock.Net.OpenApiParser.Mappers
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
bool propertyIsNullable = openApiSchema.Nullable || (openApiSchema.TryGetXNullable(out bool x) && x);
|
// bool propertyIsNullable = openApiSchema.Nullable || (openApiSchema.TryGetXNullable(out bool x) && x);
|
||||||
return new JProperty(key, _exampleValueGenerator.GetExampleValue(openApiSchema));
|
return new JProperty(key, _exampleValueGenerator.GetExampleValue(openApiSchema));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -271,11 +272,11 @@ namespace WireMock.Net.OpenApiParser.Mappers
|
|||||||
}
|
}
|
||||||
|
|
||||||
OpenApiServer server = servers.First();
|
OpenApiServer server = servers.First();
|
||||||
Uri uriResult;
|
if (Uri.TryCreate(server.Url, UriKind.RelativeOrAbsolute, out Uri uriResult))
|
||||||
if (Uri.TryCreate(server.Url, UriKind.RelativeOrAbsolute, out uriResult))
|
|
||||||
{
|
{
|
||||||
return uriResult.IsAbsoluteUri ? uriResult.AbsolutePath : uriResult.ToString();
|
return uriResult.IsAbsoluteUri ? uriResult.AbsolutePath : uriResult.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -105,6 +105,7 @@ namespace WireMock.Net.OpenApiParser.Utils
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IOpenApiAny GetRandomEnumValue(IList<IOpenApiAny> schemaEnum)
|
private static IOpenApiAny GetRandomEnumValue(IList<IOpenApiAny> schemaEnum)
|
||||||
{
|
{
|
||||||
if (schemaEnum?.Count > 0)
|
if (schemaEnum?.Count > 0)
|
||||||
@@ -113,7 +114,8 @@ namespace WireMock.Net.OpenApiParser.Utils
|
|||||||
int randomEnum = new Random().Next(0, maxValue);
|
int randomEnum = new Random().Next(0, maxValue);
|
||||||
return schemaEnum[randomEnum];
|
return schemaEnum[randomEnum];
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user