-
Notifications
You must be signed in to change notification settings - Fork 18
[OpenAPI] Add endpoint for list of events #179 #259
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
Merged
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
4258bf6
Add EventListEntity
Capella87 6a2d022
Implement EventEndpoint
Capella87 c8947ea
Add comments and set class properties as nullable
Capella87 70134ac
Add XML comment description support in Swagger
Capella87 461d6bc
Merge branch 'main' into list-events
Capella87 8e1e71a
Remove duplicate configurations from ApiApp
Capella87 bf5c999
Fix comments to standard in EventEndpoint
Capella87 78927ac
Remove HttpRequest from EventEndpoint handler parameter
Capella87 2326d7e
Clean GET implementation in EventEndpoint
Capella87 86ed5ec
Update OpenAPI response annotations on EventEndpoint handler
Capella87 343db20
Update OpenAPI description and summary of EventEndpoint
Capella87 946c381
Rename EventListEntity to EventDetails
Capella87 99616eb
Remove redundant UseSwagger()
Capella87 c03c5d1
Remove XML comment configuration for Swagger
Capella87 fb3e867
Fix Azure namespace problem in ServiceCollectionExtensions
Capella87 2876447
Rename AddEventEndpoint to AddEvents
Capella87 f598197
Remove JSON attributes from EventDetails
Capella87 f46d996
Remove redundant namespaces
Capella87 e4c9859
Refactor AdminEventDetails to inherit from EventDetails
Capella87 9517b68
Merge branch 'main' into list-events
Capella87 dc5ef51
Move less important properties from EventDetails to AdminEventDetails
Capella87 d08fad5
Merge branch 'main' of github.com:aliencube/azure-openai-sdk-proxy in…
Capella87 4922541
Change to AddEventList() in EventEndpoint
Capella87 3ef176a
Rearrange AdminEventDetails
Capella87 00d1401
Revert property comments
Capella87 3509aa7
Update OpenAPI metadata for AddEventList
Capella87 9cf1748
Add events OpenAPI tag
Capella87 8748a55
Merge branch 'main' of github.com:aliencube/azure-openai-sdk-proxy in…
Capella87 0baa716
Add 4 tests for EventEndpoint in GetEventsOpenApiTests.cs
Capella87 4a42151
Add object, response tests in GetEventsOpenApiTests.cs
Capella87 2783a16
Merge branch 'main' into list-events
Capella87 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
justinyoo marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
justinyoo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
/// <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; } | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
test/AzureOpenAIProxy.AppHost.Tests/ApiApp/Endpoints/GetEventsOpenApiTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.