mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-15 23:03:55 +01:00
* Provide open api schema to dynamic examples generator so you can generate accurate data using settings like max-length in case of a string * Rename Schema Property and add a dynamic examples generator with properties from settings like max-length * Remove blank lines * Add virtual to all public method in WireMockOpenApiParserExampleValues and ireMockOpenApiParserDynamicExampleValues to extend and overrides examples values
27 lines
866 B
C#
27 lines
866 B
C#
using System;
|
|
using Microsoft.OpenApi.Models;
|
|
using RandomDataGenerator.FieldOptions;
|
|
using RandomDataGenerator.Randomizers;
|
|
using WireMock.Net.OpenApiParser.Settings;
|
|
|
|
namespace WireMock.Net.OpenApiParser.ConsoleApp
|
|
{
|
|
public class DynamicDataGeneration : WireMockOpenApiParserDynamicExampleValues
|
|
{
|
|
public override string String
|
|
{
|
|
get
|
|
{
|
|
//Since you have your Schema, you can get if max-lenght is set. You can generate accurate examples with this settings
|
|
var maxLength = this.Schema.MaxLength ?? 9;
|
|
|
|
return RandomizerFactory.GetRandomizer(new FieldOptionsTextRegex
|
|
{
|
|
Pattern = $"[0-9A-Z]{{{maxLength}}}"
|
|
}).Generate() ?? "example-string";
|
|
}
|
|
set { }
|
|
}
|
|
}
|
|
}
|