Fix web API documentation inaccuracies

* Resolves #1644
This commit is contained in:
ds5678 2025-01-15 15:23:23 -08:00
parent 42f2c09942
commit 7797ecf836
3 changed files with 21 additions and 9 deletions

View File

@ -1,4 +1,5 @@
using System.Text.Json.Serialization;
using AssetRipper.GUI.Web.Pages;
using System.Text.Json.Serialization;
namespace AssetRipper.GUI.Web;
@ -7,6 +8,7 @@ namespace AssetRipper.GUI.Web;
[JsonSerializable(typeof(bool))]
[JsonSerializable(typeof(int))]
[JsonSerializable(typeof(byte[]))]
[JsonSerializable(typeof(Commands.PathFormData))]
internal partial class AppJsonSerializerContext : JsonSerializerContext
{
}

View File

@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Primitives;
namespace AssetRipper.GUI.Web.Pages;
@ -8,6 +9,17 @@ public static class Commands
private const string RootPath = "/";
private const string CommandsPath = "/Commands";
/// <summary>
/// For documentation purposes
/// </summary>
/// <param name="Path">The file system path.</param>
internal record PathFormData(string Path);
internal static RouteHandlerBuilder AcceptsFormDataContainingPath(this RouteHandlerBuilder builder)
{
return builder.Accepts<PathFormData>("application/x-www-form-urlencoded");
}
public readonly struct LoadFile : ICommand
{
static async Task<string?> ICommand.Execute(HttpRequest request)

View File

@ -292,20 +292,18 @@ public static class WebApplicationLauncher
//Commands
app.MapPost("/Export/UnityProject", Commands.HandleCommand<Commands.ExportUnityProject>)
.WithQueryStringParameter("Path")
.AcceptsFormDataContainingPath()
.Produces(StatusCodes.Status302Found);
app.MapPost("/Export/PrimaryContent", Commands.HandleCommand<Commands.ExportPrimaryContent>)
.WithQueryStringParameter("Path")
.AcceptsFormDataContainingPath()
.Produces(StatusCodes.Status302Found);
app.MapPost("/LoadFile", Commands.HandleCommand<Commands.LoadFile>)
.WithQueryStringParameter("Path")
.AcceptsFormDataContainingPath()
.Produces(StatusCodes.Status302Found);
app.MapPost("/LoadFolder", Commands.HandleCommand<Commands.LoadFolder>)
.WithQueryStringParameter("Path")
.Produces(StatusCodes.Status302Found);
app.MapPost("/Reset", Commands.HandleCommand<Commands.Reset>)
.WithQueryStringParameter("Path")
.AcceptsFormDataContainingPath()
.Produces(StatusCodes.Status302Found);
app.MapPost("/Reset", Commands.HandleCommand<Commands.Reset>);
//Dialogs
app.MapGet("/Dialogs/SaveFile", Dialogs.SaveFile.HandleGetRequest).Produces<string>();