Skip to content

Commit d1aacf9

Browse files
committed
expose enum description in openapi
1 parent b1ba4ea commit d1aacf9

File tree

6 files changed

+17
-12
lines changed

6 files changed

+17
-12
lines changed

tools/EVA.SDK.Generator.V2/Commands/Generate/Outputs/apidocs/ApiDocsOutput.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ private static (string type, string? properties, List<OneOf>? oneof, string? des
513513
{
514514

515515
var totals = targetType.EnumValues.ToTotals();
516-
var possibleValues = string.Join('\n', totals.OrderBy(kv => kv.Value).Select(kv => $"* `{kv.Value}` - {kv.Key}"));
516+
var possibleValues = string.Join('\n', totals.Select(kv => $"* `{kv.value}` - {kv.name}"));
517517

518518
if (enumIsFlag)
519519
{

tools/EVA.SDK.Generator.V2/Commands/Generate/Outputs/openapi/OpenApiOutput.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ private static OpenApiSchema ToSchema(ApiDefinitionModel input, TypeSpecificatio
363363
if (type.EnumIsFlag.HasValue)
364364
{
365365
var totals = type.EnumValues.ToTotals();
366-
var possibleValues = string.Join('\n', totals.OrderBy(kv => kv.Value).Select(kv => $"* `{kv.Value}` - {kv.Key}"));
366+
var possibleValues = string.Join('\n', totals.Select(x => $"* `{x.value}` - {x.name}{(x.description is {} d ? $" - {d}" : "")}"));
367367

368368
if (type.EnumIsFlag is true)
369369
{
@@ -379,7 +379,7 @@ private static OpenApiSchema ToSchema(ApiDefinitionModel input, TypeSpecificatio
379379
return new OpenApiSchema
380380
{
381381
Type = "integer",
382-
Enum = totals.Select(kv => new OpenApiInteger((int)kv.Value) as IOpenApiAny).ToList(),
382+
Enum = totals.Select(kv => new OpenApiInteger((int)kv.value) as IOpenApiAny).ToList(),
383383
Description = $"Possible values:\n\n{possibleValues}"
384384
};
385385
}

tools/EVA.SDK.Generator.V2/Commands/Generate/Outputs/swift/SwiftOutput.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ private static void WriteFlagsEnum(TypeSpecification type, string typename, Inde
624624
output.WriteLine("}");
625625
output.WriteLine();
626626

627-
foreach (var (name, value) in type.EnumValues.ToTotals().OrderBy(v => v.Value))
627+
foreach (var (value, name, _) in type.EnumValues.ToTotals())
628628
{
629629
if (value == 0) continue;
630630
output.WriteLine($"public static let {name} = {typename}(rawValue: {value})");

tools/EVA.SDK.Generator.V2/Commands/Generate/Outputs/typescript/TypescriptOutput.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ private static void WriteTypes(ApiDefinitionModelExtensions.GroupedApiDefinition
231231

232232
using (o.Indentation)
233233
{
234-
foreach (var (name, value) in type.EnumValues.ToTotals().OrderBy(x => x.Value))
234+
foreach (var (value, name, _) in type.EnumValues.ToTotals())
235235
{
236236
o.WriteLine($"{name} = {value},");
237237
}

tools/EVA.SDK.Generator.V2/Commands/Generate/Outputs/zod/ZodOutput.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ private static void WriteType(string id, TypeSpecification type, IndentedStringB
4949
}
5050
else
5151
{
52-
var values = type.EnumValues.ToTotals().Select(x => x.Value).Order().Select(x => $"z.literal({x})");
52+
var values = type.EnumValues.ToTotals().Select(x => x.value).Order().Select(x => $"z.literal({x})");
5353

5454
if (values.Count() == 1)
5555
{

tools/EVA.SDK.Generator.V2/Helpers/ApiDefinitionModelExtensions.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,20 +176,25 @@ internal static PrefixGroupedErrors GroupByPrefix(this IEnumerable<ErrorSpecific
176176
);
177177
}
178178

179-
internal static Dictionary<string, long> ToTotals(this ImmutableSortedDictionary<string, EnumValueSpecification> source)
179+
internal static List<(long value, string name, string? description)> ToTotals(this ImmutableSortedDictionary<string, EnumValueSpecification> source)
180180
{
181-
var result = new Dictionary<string, long>();
181+
var result = new List<(long value, string name, string? description)>();
182182

183183
long GetVal(string s)
184184
{
185-
if (result.TryGetValue(s, out var v)) return v;
185+
if (result.FirstOrDefault(x => x.name == s) is { } v)
186+
{
187+
return v.value;
188+
}
189+
186190
var spec = source[s];
187-
result[s] = v = spec.Extends.Aggregate(spec.Value, (a, b) => a | GetVal(b));
188-
return v;
191+
var total = spec.Extends.Aggregate(spec.Value, (a, b) => a | GetVal(b));
192+
result.Add((total, s, spec.Description));
193+
return total;
189194
}
190195

191196
foreach (var x in source.Keys) GetVal(x);
192-
return result;
197+
return result.OrderBy(x => x.value).ToList();
193198
}
194199

195200
internal static TypeReference CloneAsNotNull(this TypeReference reference)

0 commit comments

Comments
 (0)