Add copy Swagger URL context flyout

This commit is contained in:
estrogen elf
2025-05-05 02:55:36 -05:00
parent b18f425257
commit 68e5abd1d1
4 changed files with 38 additions and 23 deletions

View File

@@ -36,10 +36,10 @@ public class OpenApiDocumentWrapper
{ {
pluginsKey = "default"; pluginsKey = "default";
if (plugins.TryGetValue(pluginsKey, out var p)) if (plugins.TryGetValue(pluginsKey, out var p))
p.Add(new(method.ToString(), path, operation)); p.Add(new(method.ToString(), path, pluginsKey, operation));
else else
{ {
operations.Add(new(method.ToString(), path, operation)); operations.Add(new(method.ToString(), path, pluginsKey, operation));
plugins[pluginsKey] = operations; plugins[pluginsKey] = operations;
} }
} }
@@ -53,10 +53,10 @@ public class OpenApiDocumentWrapper
pluginsKey = tag.Name; pluginsKey = tag.Name;
if (plugins.TryGetValue(pluginsKey, out var p)) if (plugins.TryGetValue(pluginsKey, out var p))
p.Add(new(method.ToString(), path, operation)); p.Add(new(method.ToString(), path, tag.Name, operation));
else else
{ {
operations.Add(new(method.ToString(), path, operation)); operations.Add(new(method.ToString(), path, tag.Name, operation));
plugins[pluginsKey] = operations; plugins[pluginsKey] = operations;
} }
} }

View File

@@ -2,4 +2,4 @@ using Microsoft.OpenApi.Models;
namespace Needlework.Net.Models; namespace Needlework.Net.Models;
public record PathOperation(string Method, string Path, OpenApiOperation Operation); public record PathOperation(string Method, string Path, string Tag, OpenApiOperation Operation);

View File

@@ -1,4 +1,5 @@
using CommunityToolkit.Mvvm.ComponentModel; using Avalonia.Controls;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input; using CommunityToolkit.Mvvm.Input;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Needlework.Net.Models; using Needlework.Net.Models;
@@ -14,6 +15,8 @@ public partial class PathOperationViewModel : ObservableObject
public string Path { get; } public string Path { get; }
public OperationViewModel Operation { get; } public OperationViewModel Operation { get; }
public string Url { get; }
[ObservableProperty] private bool _isBusy; [ObservableProperty] private bool _isBusy;
[ObservableProperty] private Lazy<LcuRequestViewModel> _lcuRequest; [ObservableProperty] private Lazy<LcuRequestViewModel> _lcuRequest;
@@ -25,6 +28,7 @@ public partial class PathOperationViewModel : ObservableObject
{ {
Method = pathOperation.Method.ToUpper() Method = pathOperation.Method.ToUpper()
}); });
Url = $"https://swagger.dysolix.dev/lcu/#/{pathOperation.Tag}/{pathOperation.Operation.OperationId}";
} }
[RelayCommand] [RelayCommand]
@@ -50,4 +54,10 @@ public partial class PathOperationViewModel : ObservableObject
LcuRequest.Value.RequestPath = sb.ToString(); LcuRequest.Value.RequestPath = sb.ToString();
await LcuRequest.Value.ExecuteAsync(); await LcuRequest.Value.ExecuteAsync();
} }
[RelayCommand]
private void CopyUrl()
{
App.MainWindow?.Clipboard?.SetTextAsync(Url);
}
} }

View File

@@ -55,23 +55,28 @@
<Grid <Grid
RowDefinitions="*" RowDefinitions="*"
ColumnDefinitions="auto,*"> ColumnDefinitions="auto,*">
<TextBlock <Grid.ContextFlyout>
VerticalAlignment="Center" <MenuFlyout>
TextAlignment="Center" <MenuItem Header="Copy Swagger URL" Command="{Binding CopyUrlCommand}"/>
Margin="0 0 8 0" </MenuFlyout>
Text="{Binding LcuRequest.Value.Method}" </Grid.ContextFlyout>
Background="{Binding LcuRequest.Value.Color}" <TextBlock
FontSize="8" VerticalAlignment="Center"
Width="50" TextAlignment="Center"
Padding="10 2 10 2" Margin="0 0 8 0"
Grid.Row="0" Text="{Binding LcuRequest.Value.Method}"
Grid.Column="0"/> Background="{Binding LcuRequest.Value.Color}"
<TextBlock FontSize="8"
VerticalAlignment="Center" Width="50"
Text="{Binding Path}" Padding="10 2 10 2"
FontSize="11" Grid.Row="0"
Grid.Row="0" Grid.Column="0"/>
Grid.Column="1"/> <TextBlock
VerticalAlignment="Center"
Text="{Binding Path}"
FontSize="11"
Grid.Row="0"
Grid.Column="1"/>
</Grid> </Grid>
</DataTemplate> </DataTemplate>
</ListBox.ItemTemplate> </ListBox.ItemTemplate>