namespace ALttPRandomizer.Model { using System; using System.Text.Json; using System.Text.Json.Nodes; using Microsoft.OpenApi; using Swashbuckle.AspNetCore.SwaggerGen; using YamlDotNet.Serialization; public class MysterySettings { public RandomizableWeights Mode { get; set; } = new(); public RandomizableWeights Weapons { get; set; } = new(); public RandomizableWeights Goal { get; set; } = new(); public RandomizableWeights CrystalsGanon { get; set; } = new(); public RandomizableWeights BossesGanon { get; set; } = new(); public RandomizableWeights TriforcePieces { get; set; } = new(); [YamlMember(Alias = "crystals_gt")] public RandomizableWeights CrystalsGT { get; set; } = new(); public RandomizableWeights GanonItem { get; set; } = new(); public RandomizableWeights EntranceShuffle { get; set; } = new(); public RandomizableWeights OverworldMapDungeons { get; set; } = new(); public RandomizableWeights LinksHouse { get; set; } = new(); public RandomizableWeights SkullWoods { get; set; } = new(); public RandomizableWeights LinkedDrops { get; set; } = new(); public RandomizableWeights BossShuffle { get; set; } = new(); public RandomizableWeights EnemyShuffle { get; set; } = new(); public RandomizableWeights DamageTableShuffle { get; set; } = new(); public RandomizableWeights SmallKeys { get; set; } = new(); public RandomizableWeights BigKeys { get; set; } = new(); public RandomizableWeights Maps { get; set; } = new(); public RandomizableWeights Compasses { get; set; } = new(); public RandomizableWeights ShowLootMap { get; set; } = new(); public RandomizableWeights ShowLootHud { get; set; } = new(); public RandomizableWeights ShowMap { get; set; } = new(); public RandomizableWeights ShopShuffle { get; set; } = new(); public RandomizableWeights DropShuffle { get; set; } = new(); public RandomizableWeights PotShuffle { get; set; } = new(); public RandomizableWeights PrizeShuffle { get; set; } = new(); public RandomizableWeights Boots { get; set; } = new(); public RandomizableWeights Flute { get; set; } = new(); public RandomizableWeights DarkRooms { get; set; } = new(); public RandomizableWeights Bombs { get; set; } = new(); public RandomizableWeights Book { get; set; } = new(); public RandomizableWeights Mirror { get; set; } = new(); public RandomizableWeights DoorShuffle { get; set; } = new(); public RandomizableWeights Lobbies { get; set; } = new(); public RandomizableWeights DoorTypeMode { get; set; } = new(); public RandomizableWeights TrapDoorMode { get; set; } = new(); public RandomizableWeights ExtraKeys { get; set; } = new(); public RandomizableWeights FollowerShuffle { get; set; } = new(); public RandomizableWeights FluteShuffle { get; set; } = new(); public RandomizableWeights OverworldLayout { get; set; } = new(); public RandomizableWeights OverworldWorldLayouts { get; set; } = new(); public RandomizableWeights OverworldLayoutTerrain { get; set; } = new(); public RandomizableWeights OverworldLayoutEdges { get; set; } = new(); public RandomizableWeights OverworldMapFog { get; set; } = new(); public RandomizableWeights TileSwap { get; set; } = new(); public RandomizableWeights DamageChallenge { get; set; } = new(); public RandomizableWeights Hints { get; set; } = new(); } public class DefaultMysterySettingsFilter : IOperationFilter { private readonly MysterySettings exampleMystery; private readonly JsonNode? exampleMysteryJson; public DefaultMysterySettingsFilter() { this.exampleMystery = new MysterySettings(); var mysteryFields = typeof(MysterySettings).GetProperties(); foreach (var field in mysteryFields) { var type = field.PropertyType; if (!type.IsGenericType || type.GetGenericTypeDefinition() != typeof(RandomizableWeights<>)) { continue; } Type itemType = type.GetGenericArguments()[0]; Type innerType = typeof(RandomizableWeights<>).MakeGenericType(itemType)!; var weights = innerType.GetProperty("EqualAll")?.GetValue(null); if (weights != null) { field.SetValue(this.exampleMystery, weights); } } this.exampleMysteryJson = JsonSerializer.SerializeToNode(this.exampleMystery, JsonOptions.Default); } public void Apply(OpenApiOperation operation, OperationFilterContext context) { foreach (var description in context.ApiDescription.ParameterDescriptions) { if (description.Type != typeof(MysterySettings)) { continue; } if (description.Source.Id == "Body") { if (operation.RequestBody != null && operation.RequestBody.Content != null) { foreach ((_, var value) in operation.RequestBody.Content) { value.Example = this.exampleMysteryJson; } } } } } } }