Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OpenAPI] Add endpoint for list of deployment models #294

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,12 @@ public static class PlaygroundEndpointUrls
/// - GET method for listing all events
/// </remarks>
public const string Events = "/events";

/// <summary>
/// Declares the deployment models list endpoint.
/// </summary>
/// <remarks>
/// - GET method for listing all deployment models
/// </remarks>
public const string DeploymentModels = "/events/{eventId}/deployment-models";
}
34 changes: 34 additions & 0 deletions src/AzureOpenAIProxy.ApiApp/Endpoints/PlaygroundEndpoints.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Microsoft.AspNetCore.Mvc;
justinyoo marked this conversation as resolved.
Show resolved Hide resolved

namespace AzureOpenAIProxy.ApiApp.Endpoints;

/// <summary>
Expand Down Expand Up @@ -32,4 +34,36 @@ public static RouteHandlerBuilder AddListEvents(this WebApplication app)

return builder;
}


/// <summary>
/// Adds the get deployment models
/// </summary>
/// <param name="app"><see cref="WebApplication"/> instance.</param>
/// <returns>Returns <see cref="RouteHandlerBuilder"/> instance.</returns>
public static RouteHandlerBuilder AddListDeploymentModels(this WebApplication app)
{
// Todo: Issue #170 https://github.com/aliencube/azure-openai-sdk-proxy/issues/170
var builder = app.MapGet(PlaygroundEndpointUrls.DeploymentModels, (
[FromRoute] string eventId
) =>
{
return Results.Ok();
})
.Produces<List<DeploymentModelDetails>>(statusCode: StatusCodes.Status200OK, contentType: "application/json")
.Produces(statusCode: StatusCodes.Status401Unauthorized)
jihyunmoon16 marked this conversation as resolved.
Show resolved Hide resolved
.Produces(statusCode: StatusCodes.Status404NotFound)
.Produces<string>(statusCode: StatusCodes.Status500InternalServerError, contentType: "text/plain")
.WithTags("events")
.WithName("GetDeploymentModels")
.WithOpenApi(operation =>
{
operation.Summary = "Gets all deployment models";
operation.Description = "This endpoint gets all deployment models avaliable";

return operation;
});

return builder;
}
}
14 changes: 14 additions & 0 deletions src/AzureOpenAIProxy.ApiApp/Models/DeploymentModelDetails.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Text.Json.Serialization;

/// <summary>
/// This represent the event detail data for response by admin event endpoint.
/// </summary>
public class DeploymentModelDetails
{
/// <summary>
/// Gets or sets the deployment model name.
/// </summary>
[JsonRequired]
public string Name { get; set; } = string.Empty;

}
1 change: 1 addition & 0 deletions src/AzureOpenAIProxy.ApiApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@

// Playground endpoints
app.AddListEvents();
app.AddListDeploymentModels();

// Admin endpoints
app.AddNewAdminEvent();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
using System.Text.Json;

using AzureOpenAIProxy.AppHost.Tests.Fixtures;

using FluentAssertions;

using IdentityModel.Client;


namespace AzureOpenAIProxy.AppHost.Tests.ApiApp.Endpoints;

public class GetDeploymentModelsOpenApiTests(AspireAppHostFixture host) : IClassFixture<AspireAppHostFixture>
{
[Fact]
public async Task Given_Resource_When_Invoked_Endpoint_Then_It_Should_Return_Path()
{
// Arrange
using var httpClient = host.App!.CreateHttpClient("apiapp");

// Act
var json = await httpClient.GetStringAsync("/swagger/v1.0.0/swagger.json");
var apiDocument = JsonSerializer.Deserialize<JsonDocument>(json);

// Assert
var result = apiDocument!.RootElement.GetProperty("paths")
.TryGetProperty("/events/{eventId}/deployment-models", out var property) ? property : default;
result.ValueKind.Should().Be(JsonValueKind.Object);
}

[Fact]
public async Task Given_Resource_When_Invoked_Endpoint_Then_It_Should_Return_Verb()
{
// Arrange
using var httpClient = host.App!.CreateHttpClient("apiapp");

// Act
var json = await httpClient.GetStringAsync("/swagger/v1.0.0/swagger.json");
var apiDocument = JsonSerializer.Deserialize<JsonDocument>(json);

// Assert
var result = apiDocument!.RootElement.GetProperty("paths")
.GetProperty("/events/{eventId}/deployment-models")
.TryGetProperty("get", out var property) ? property : default;
result.ValueKind.Should().Be(JsonValueKind.Object);
}

[Theory]
[InlineData("events")]
public async Task Given_Resource_When_Invoked_Endpoint_Then_It_Should_Return_Tags(string tag)
{
// Arrange
using var httpClient = host.App!.CreateHttpClient("apiapp");

// Act
var json = await httpClient.GetStringAsync("/swagger/v1.0.0/swagger.json");
var apiDocument = JsonSerializer.Deserialize<JsonDocument>(json);

// Assert
var result = apiDocument!.RootElement.GetProperty("paths")
.GetProperty("/events/{eventId}/deployment-models")
.GetProperty("get")
.TryGetProperty("tags", out var property) ? property : default;
result.ValueKind.Should().Be(JsonValueKind.Array);
result.EnumerateArray().Select(p => p.GetString()).Should().Contain(tag);
}

[Theory]
[InlineData("summary")]
[InlineData("description")]
[InlineData("operationId")]
public async Task Given_Resource_When_Invoked_Endpoint_Then_It_Should_Return_Value(string attribute)
{
// Arrange
using var httpClient = host.App!.CreateHttpClient("apiapp");

// Act
var json = await httpClient.GetStringAsync("/swagger/v1.0.0/swagger.json");
var apiDocument = JsonSerializer.Deserialize<JsonDocument>(json);

// Assert
var result = apiDocument!.RootElement.GetProperty("paths")
.GetProperty("/events/{eventId}/deployment-models")
.GetProperty("get")
.TryGetProperty(attribute, out var property) ? property : default;
result.ValueKind.Should().Be(JsonValueKind.String);
}


[Theory]
[InlineData("eventId")]
public async Task Given_Resource_When_Invoked_Endpoint_Then_It_Should_Return_Path_Parameter(string name)
{
// Arrange
using var httpClient = host.App!.CreateHttpClient("apiapp");

// Act
var json = await httpClient.GetStringAsync("/swagger/v1.0.0/swagger.json");
var openapi = JsonSerializer.Deserialize<JsonDocument>(json);

// Assert
var result = openapi!.RootElement.GetProperty("paths")
.GetProperty("/events/{eventId}/deployment-models")
.GetProperty("get")
.GetProperty("parameters")
.EnumerateArray()
.Where(p => p.GetProperty("in").GetString() == "path")
.Select(p => p.GetProperty("name").ToString());
result.Should().Contain(name);
}

[Theory]
[InlineData("responses")]
public async Task Given_Resource_When_Invoked_Endpoint_Then_It_Should_Return_Object(string attribute)
{
// Arrange
using var httpClient = host.App!.CreateHttpClient("apiapp");

// Act
var json = await httpClient.GetStringAsync("/swagger/v1.0.0/swagger.json");
var apiDocument = JsonSerializer.Deserialize<JsonDocument>(json);

// Assert
var result = apiDocument!.RootElement.GetProperty("paths")
.GetProperty("/events/{eventId}/deployment-models")
.GetProperty("get")
.TryGetProperty(attribute, out var property) ? property : default;
result.ValueKind.Should().Be(JsonValueKind.Object);
}

[Theory]
[InlineData("200")]
[InlineData("401")]
[InlineData("404")]
jihyunmoon16 marked this conversation as resolved.
Show resolved Hide resolved
[InlineData("500")]
public async Task Given_Resource_When_Invoked_Endpoint_Then_It_Should_Return_Response(string attribute)
{
// Arrange
using var httpClient = host.App!.CreateHttpClient("apiapp");

// Act
var json = await httpClient.GetStringAsync("/swagger/v1.0.0/swagger.json");
var apiDocument = JsonSerializer.Deserialize<JsonDocument>(json);

// Assert
var result = apiDocument!.RootElement.GetProperty("paths")
.GetProperty("/events/{eventId}/deployment-models")
.GetProperty("get")
.GetProperty("responses")
.TryGetProperty(attribute, out var property) ? property : default;
result.ValueKind.Should().Be(JsonValueKind.Object);
}


[Fact]
public async Task Given_Resource_When_Invoked_Endpoint_Then_It_Should_Return_Model()
{
// Arrange
using var httpClient = host.App!.CreateHttpClient("apiapp");

// Act
var json = await httpClient.GetStringAsync("/swagger/v1.0.0/swagger.json");
var openapi = JsonSerializer.Deserialize<JsonDocument>(json);

// Assert
var result = openapi!.RootElement.GetProperty("components")
.GetProperty("schemas")
.TryGetProperty("DeploymentModelDetails", out var property) ? property : default;
result.ValueKind.Should().Be(JsonValueKind.Object);
}

[Theory]
[InlineData("name", true)]
public async Task Given_Resource_When_Invoked_Endpoint_Then_It_Should_Return_Required(string attribute, bool isRequired)
{
// Arrange
using var httpClient = host.App!.CreateHttpClient("apiapp");

// Act
var json = await httpClient.GetStringAsync("/swagger/v1.0.0/swagger.json");
var openapi = JsonSerializer.Deserialize<JsonDocument>(json);

// Assert
var result = openapi!.RootElement.GetProperty("components")
.GetProperty("schemas")
.GetProperty("DeploymentModelDetails")
.TryGetStringArray("required")
.ToList();
result.Contains(attribute).Should().Be(isRequired);
}

[Theory]
[InlineData("name")]
public async Task Given_Resource_When_Invoked_Endpoint_Then_It_Should_Return_Property(string attribute)
{
// Arrange
using var httpClient = host.App!.CreateHttpClient("apiapp");

// Act
var json = await httpClient.GetStringAsync("/swagger/v1.0.0/swagger.json");
var openapi = JsonSerializer.Deserialize<JsonDocument>(json);

// Assert
var result = openapi!.RootElement.GetProperty("components")
.GetProperty("schemas")
.GetProperty("DeploymentModelDetails")
jihyunmoon16 marked this conversation as resolved.
Show resolved Hide resolved
.GetProperty("properties")
.TryGetProperty(attribute, out var property) ? property : default;
result.ValueKind.Should().Be(JsonValueKind.Object);
}

[Theory]
[InlineData("name", "string")]
public async Task Given_Resource_When_Invoked_Endpoint_Then_It_Should_Return_Type(string attribute, string type)
{
// Arrange
using var httpClient = host.App!.CreateHttpClient("apiapp");

// Act
var json = await httpClient.GetStringAsync("/swagger/v1.0.0/swagger.json");
var openapi = JsonSerializer.Deserialize<JsonDocument>(json);

// Assert
var result = openapi!.RootElement.GetProperty("components")
.GetProperty("schemas")
.GetProperty("DeploymentModelDetails")
.GetProperty("properties")
.GetProperty(attribute);
result.TryGetString("type").Should().Be(type);
}
}
jihyunmoon16 marked this conversation as resolved.
Show resolved Hide resolved
Loading