mirror of
https://github.com/unclshura/BlazorOpenApi.git
synced 2025-12-21 09:51:53 +00:00
Better array UI (skip object level)
This commit is contained in:
parent
b8602b8e71
commit
16c5d2e85b
@ -5,9 +5,24 @@
|
|||||||
@if (Value.Type == "array")
|
@if (Value.Type == "array")
|
||||||
{
|
{
|
||||||
<Expander HeaderClass="s-type" Class="s-bg-odd" Title="@ArrayText" Collapsed="@Collapsed">
|
<Expander HeaderClass="s-type" Class="s-bg-odd" Title="@ArrayText" Collapsed="@Collapsed">
|
||||||
|
@if (Value.Items?.Type == "object" && SchemaControl.Resolve(Value.Items, Api)?.Properties != null)
|
||||||
|
{
|
||||||
|
@* Skip one level *@
|
||||||
|
<div class="s-props s-nested">
|
||||||
|
<table class="schema">
|
||||||
|
@foreach (var p in SchemaControl.Resolve(Value.Items, Api)!.Properties)
|
||||||
|
{
|
||||||
|
<SchemaChildControl Value="@p.Value" Title="@p.Key" Required="@IsRequired(p.Key)" />
|
||||||
|
}
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
<div class="s-nested">
|
<div class="s-nested">
|
||||||
<SchemaControl Value="@Value.Items" />
|
<SchemaControl Value="@Value.Items" />
|
||||||
</div>
|
</div>
|
||||||
|
}
|
||||||
</Expander>
|
</Expander>
|
||||||
}
|
}
|
||||||
else if (Value.Type == "object")
|
else if (Value.Type == "object")
|
||||||
@ -55,6 +70,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
|
[CascadingParameter]
|
||||||
|
public OpenApiDocument? Api { get; set; }
|
||||||
[Parameter]
|
[Parameter]
|
||||||
public OpenApiSchema? Value { get; set; }
|
public OpenApiSchema? Value { get; set; }
|
||||||
[Parameter]
|
[Parameter]
|
||||||
@ -73,11 +90,15 @@
|
|||||||
if (Value?.Type != "array")
|
if (Value?.Type != "array")
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
|
string arrayType = Value.Items?.Type ?? "";
|
||||||
|
if ( Value.Items?.Type != "array" && Value.Items?.Type != "object")
|
||||||
|
arrayType = Value.Items?.Type ?? "array";
|
||||||
|
|
||||||
var nullable = Value.Nullable ? "?" : "";
|
var nullable = Value.Nullable ? "?" : "";
|
||||||
|
|
||||||
if (Value.MinItems != null || Value.MaxItems != null)
|
if (Value.MinItems != null || Value.MaxItems != null)
|
||||||
return $"array{nullable} [{(Value.MinItems == null ? "" : Value.MinItems.Value)}..{(Value.MaxItems == null ? "" : Value.MaxItems.Value)}]";
|
return $"{arrayType}{nullable} [{(Value.MinItems == null ? "" : Value.MinItems.Value)}..{(Value.MaxItems == null ? "" : Value.MaxItems.Value)}]";
|
||||||
return $"array{nullable} []";
|
return $"{arrayType}{nullable} []";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -19,15 +19,17 @@
|
|||||||
[CascadingParameter]
|
[CascadingParameter]
|
||||||
public OpenApiDocument? Api { get; set; }
|
public OpenApiDocument? Api { get; set; }
|
||||||
|
|
||||||
private OpenApiSchema? ResolvedValue
|
private OpenApiSchema? ResolvedValue => Resolve(Value, Api) ?? Value;
|
||||||
|
|
||||||
|
public static OpenApiSchema? Resolve(OpenApiSchema? schema, OpenApiDocument? api)
|
||||||
{
|
{
|
||||||
get
|
if (schema == null)
|
||||||
|
return null;
|
||||||
|
if (schema.Reference != null && api != null)
|
||||||
{
|
{
|
||||||
if (Api == null || Value?.Reference == null )
|
if (api.Components.Schemas.TryGetValue(schema.Reference.Id, out var resolved))
|
||||||
return Value;
|
|
||||||
if (!Api.Components.Schemas.TryGetValue(Value.Reference.Id, out var resolved))
|
|
||||||
return Value;
|
|
||||||
return resolved;
|
return resolved;
|
||||||
}
|
}
|
||||||
|
return schema;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user