An OpenApi (swagger) parser to generate MappingModel or mapping.json file (#479)

* wip

* .

* .

* nuget

* .

* .

* WithMappingModel

* tests

* json

* codefactor

* sign

* .

* interface

* sln

* comments
This commit is contained in:
Stef Heyenrath
2020-07-01 09:57:52 +02:00
committed by GitHub
parent 769ddc1fd3
commit e2fbfda3f0
31 changed files with 4907 additions and 646 deletions

View File

@@ -0,0 +1,51 @@
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";
}
}
}
}
}