using EonaCat.DoxaApi.Models;
namespace EonaCat.DoxaApi.Generation
{
// This file is part of the EonaCat project(s) which is released under the Apache License.
// See the LICENSE file or go to https://EonaCat.com/license for full license details.
///
/// Produces schema-shaped, deterministic-but-plausible fake JSON values for a given
/// . Used by the built-in mock server so that frontend teams
/// can develop against an API before its real implementation exists.
///
public static class MockResponseGenerator
{
public static object? Generate(SchemaModel? schema, ApiDocument doc, int depth = 0, HashSet? seen = null)
{
seen ??= new HashSet();
if (schema is null || depth > 8)
{
return null;
}
if (schema.RefName is not null)
{
if (!seen.Add(schema.RefName))
{
return new Dictionary();
}
if (doc.Schemas.TryGetValue(schema.RefName, out var resolved))
{
return Generate(resolved, doc, depth + 1, seen);
}
return new Dictionary();
}
switch (schema.Type)
{
case "string":
return MockString(schema.Format);
case "integer":
return RandomInt(depth);
case "number":
return Math.Round(RandomInt(depth) + 0.5, 2);
case "boolean":
return depth % 2 == 0;
case "enum":
return schema.EnumValues?.Count > 0 ? schema.EnumValues[0] : "value";
case "array":
return new List