mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-16 00:23:35 +01:00
* wip * . * . * nuget * . * . * WithMappingModel * tests * json * codefactor * sign * . * interface * sln * comments
51 lines
1.5 KiB
C#
51 lines
1.5 KiB
C#
using System;
|
|
using Microsoft.OpenApi.Models;
|
|
using WireMock.Net.OpenApiParser.Extensions;
|
|
using WireMock.Net.OpenApiParser.Types;
|
|
|
|
namespace WireMock.Net.OpenApiParser.Utils
|
|
{
|
|
internal static class ExampleValueGenerator
|
|
{
|
|
public static object GetExampleValue(OpenApiSchema schema)
|
|
{
|
|
switch (schema?.GetSchemaType())
|
|
{
|
|
case SchemaType.Boolean:
|
|
return true;
|
|
|
|
case SchemaType.Integer:
|
|
return 42;
|
|
|
|
case SchemaType.Number:
|
|
switch (schema?.GetSchemaFormat())
|
|
{
|
|
case SchemaFormat.Float:
|
|
return 4.2f;
|
|
|
|
default:
|
|
return 4.2d;
|
|
}
|
|
|
|
default:
|
|
switch (schema?.GetSchemaFormat())
|
|
{
|
|
case SchemaFormat.Date:
|
|
return DateTimeUtils.ToRfc3339Date(DateTime.UtcNow);
|
|
|
|
case SchemaFormat.DateTime:
|
|
return DateTimeUtils.ToRfc3339DateTime(DateTime.UtcNow);
|
|
|
|
case SchemaFormat.Byte:
|
|
return new byte[] { 48, 49, 50 };
|
|
|
|
case SchemaFormat.Binary:
|
|
return "example-object";
|
|
|
|
default:
|
|
return "example-string";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |