Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
4258bf6
Add EventListEntity
Capella87 Aug 21, 2024
6a2d022
Implement EventEndpoint
Capella87 Aug 22, 2024
c8947ea
Add comments and set class properties as nullable
Capella87 Aug 22, 2024
70134ac
Add XML comment description support in Swagger
Capella87 Aug 22, 2024
461d6bc
Merge branch 'main' into list-events
Capella87 Aug 23, 2024
8e1e71a
Remove duplicate configurations from ApiApp
Capella87 Aug 23, 2024
bf5c999
Fix comments to standard in EventEndpoint
Capella87 Aug 23, 2024
78927ac
Remove HttpRequest from EventEndpoint handler parameter
Capella87 Aug 23, 2024
2326d7e
Clean GET implementation in EventEndpoint
Capella87 Aug 23, 2024
86ed5ec
Update OpenAPI response annotations on EventEndpoint handler
Capella87 Aug 23, 2024
343db20
Update OpenAPI description and summary of EventEndpoint
Capella87 Aug 23, 2024
946c381
Rename EventListEntity to EventDetails
Capella87 Aug 23, 2024
99616eb
Remove redundant UseSwagger()
Capella87 Aug 23, 2024
c03c5d1
Remove XML comment configuration for Swagger
Capella87 Aug 23, 2024
fb3e867
Fix Azure namespace problem in ServiceCollectionExtensions
Capella87 Aug 23, 2024
2876447
Rename AddEventEndpoint to AddEvents
Capella87 Aug 24, 2024
f598197
Remove JSON attributes from EventDetails
Capella87 Aug 24, 2024
f46d996
Remove redundant namespaces
Capella87 Aug 24, 2024
e4c9859
Refactor AdminEventDetails to inherit from EventDetails
Capella87 Aug 24, 2024
9517b68
Merge branch 'main' into list-events
Capella87 Aug 24, 2024
dc5ef51
Move less important properties from EventDetails to AdminEventDetails
Capella87 Aug 24, 2024
d08fad5
Merge branch 'main' of github.com:aliencube/azure-openai-sdk-proxy in…
Capella87 Aug 24, 2024
4922541
Change to AddEventList() in EventEndpoint
Capella87 Aug 24, 2024
3ef176a
Rearrange AdminEventDetails
Capella87 Aug 24, 2024
00d1401
Revert property comments
Capella87 Aug 24, 2024
3509aa7
Update OpenAPI metadata for AddEventList
Capella87 Aug 24, 2024
9cf1748
Add events OpenAPI tag
Capella87 Aug 24, 2024
8748a55
Merge branch 'main' of github.com:aliencube/azure-openai-sdk-proxy in…
Capella87 Aug 25, 2024
0baa716
Add 4 tests for EventEndpoint in GetEventsOpenApiTests.cs
Capella87 Aug 25, 2024
4a42151
Add object, response tests in GetEventsOpenApiTests.cs
Capella87 Aug 25, 2024
2783a16
Merge branch 'main' into list-events
Capella87 Aug 27, 2024
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
9 changes: 7 additions & 2 deletions src/AzureOpenAIProxy.ApiApp/Endpoints/EndpointUrls.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace AzureOpenAIProxy.ApiApp.Endpoints;
namespace AzureOpenAIProxy.ApiApp.Endpoints;

/// <summary>
/// This represents the collection of the endpoint URLs.
Expand All @@ -14,4 +14,9 @@ public static class EndpointUrls
/// Declares the chat completions endpoint.
/// </summary>
public const string ChatCompletions = "/openai/deployments/{deploymentName}/chat/completions";
}

/// <summary>
/// Declares the event endpoint.
/// </summary>
public const string Events = "/events";
}
39 changes: 39 additions & 0 deletions src/AzureOpenAIProxy.ApiApp/Endpoints/EventEndpoint.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System.Text.Json;

using AzureOpenAIProxy.ApiApp.Models;

namespace AzureOpenAIProxy.ApiApp.Endpoints;

/// <summary>
/// This represents the endpoint entity for events that the logged user joined.
/// </summary>
public static class EventEndpoint
{
/// <summary>
/// Adds the event endpoint.
/// </summary>
/// <param name="app"><see cref="WebApplication"/> instance.</param>
/// <returns>Returns <see cref="RouteHandlerBuilder"/> instance.</returns>
public static RouteHandlerBuilder AddEventList(this WebApplication app)
{
var builder = app.MapGet(EndpointUrls.Events, () =>
{
// TODO: Issue #179 https://github.com/aliencube/azure-openai-sdk-proxy/issues/179
return Results.Ok();
})
.Produces<List<EventDetails>>(statusCode: StatusCodes.Status200OK, contentType: "application/json")
.Produces(statusCode: StatusCodes.Status401Unauthorized)
.Produces<string>(statusCode: StatusCodes.Status500InternalServerError, contentType: "text/plain")
.WithTags("events")
.WithName("GetEvents")
.WithOpenApi(operation =>
{
operation.Description = "Gets all events' details that the user joined.";
operation.Summary = "This endpoint gets all events' details that the user joined.";

return operation;
});

return builder;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Azure.Identity;
using Azure.Identity;
using Azure.Security.KeyVault.Secrets;

using AzureOpenAIProxy.ApiApp.Builders;
Expand Down Expand Up @@ -132,4 +132,4 @@ public static IServiceCollection AddOpenApiService(this IServiceCollection servi

return services;
}
}
}
3 changes: 2 additions & 1 deletion src/AzureOpenAIProxy.ApiApp/Filters/OpenApiTagFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context)
[
new OpenApiTag { Name = "weather", Description = "Weather forecast operations" },
new OpenApiTag { Name = "openai", Description = "Azure OpenAI operations" },
new OpenApiTag { Name = "admin", Description = "Admin for organizing events" }
new OpenApiTag { Name = "admin", Description = "Admin for organizing events" },
new OpenApiTag { Name = "events", Description = "User events" }
];
}
}
33 changes: 4 additions & 29 deletions src/AzureOpenAIProxy.ApiApp/Models/AdminEventDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,15 @@
/// <summary>
/// This represent the event detail data for response by admin event endpoint.
/// </summary>
public class AdminEventDetails
public class AdminEventDetails : EventDetails
{
/// <summary>
/// Gets or sets the event id.
/// </summary>
public required string? EventId { get; set; }

/// <summary>
/// Gets or sets the event title name.
/// </summary>
public required string? Title { get; set; }

/// <summary>
/// Gets or sets the event summary.
/// </summary>
public required string? Summary { get; set; }

/// <summary>
/// Gets or sets the event description.
/// Gets or sets the event description.
/// </summary>
public string? Description { get; set; }

/// <summary>
/// Gets or sets the event start date.
/// Gets or sets the event start date.
/// </summary>
public required DateTimeOffset? DateStart { get; set; }

Expand All @@ -46,7 +31,7 @@ public class AdminEventDetails
public required bool? IsActive { get; set; }

/// <summary>
/// Gets or sets the event organizer name.
/// Gets or sets the event organizer name.
/// </summary>
public required string? OrganizerName { get; set; }

Expand All @@ -64,14 +49,4 @@ public class AdminEventDetails
/// Gets or sets the event coorganizer email.
/// </summary>
public string? CoorganizerEmail { get; set; }

/// <summary>
/// Gets or sets the Azure OpenAI Service request max token capacity.
/// </summary>
public required int? MaxTokenCap { get; set; }

/// <summary>
/// Gets or sets the Azure OpenAI Service daily request capacity.
/// </summary>
public required int? DailyRequestCap { get; set; }
}
35 changes: 35 additions & 0 deletions src/AzureOpenAIProxy.ApiApp/Models/EventDetails.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.ComponentModel.DataAnnotations;
using System.Text.Json.Serialization;

using AzureOpenAIProxy.ApiApp.Models;

/// <summary>
/// This represents the event's detailed data for response by EventEndpoint.
/// </summary>
public class EventDetails
{
/// <summary>
/// Gets or sets the event id.
/// </summary>
public required string? EventId { get; set; }

/// <summary>
/// Gets or sets the event title name.
/// </summary>
public required string? Title { get; set; }

/// <summary>
/// Gets or sets the event summary.
/// </summary>
public required string? Summary { get; set; }

/// <summary>
/// Gets or sets the Azure OpenAI Service request max token capacity.
/// </summary>
public required int? MaxTokenCap { get; set; }

/// <summary>
/// Gets or sets the Azure OpenAI Service daily request capacity.
/// </summary>
public required int? DailyRequestCap { get; set; }
}
3 changes: 3 additions & 0 deletions src/AzureOpenAIProxy.ApiApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
app.AddWeatherForecast();
app.AddChatCompletions();

// Event Endpoints
app.AddEventList();

// Admin Endpoints
app.AddAdminEvents();
app.AddAdminEventList();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
using System.Text.Json;

using AzureOpenAIProxy.AppHost.Tests.Fixtures;

using FluentAssertions;

using IdentityModel.Client;

namespace AzureOpenAIProxy.AppHost.Tests.ApiApp.Endpoints;

public class GetEventsOpenApiTests(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", 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")
.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")
.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("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")
.GetProperty("get")
.TryGetProperty(attribute, out var property) ? property : default;
result.ValueKind.Should().Be(JsonValueKind.String);
}

[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")
.GetProperty("get")
.TryGetProperty(attribute, out var property) ? property : default;
result.ValueKind.Should().Be(JsonValueKind.Object);
}

[Theory]
[InlineData("200")]
[InlineData("401")]
[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")
.GetProperty("get")
.GetProperty("responses")
.TryGetProperty(attribute, out var property) ? property : default;
result.ValueKind.Should().Be(JsonValueKind.Object);
}
}