-
Notifications
You must be signed in to change notification settings - Fork 18
[OpenAPI] Add endpoint for list of deployment models #294
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
justinyoo
merged 15 commits into
aliencube:main
from
jihyunmoon16:feature/169-deployment-models-endpoint
Sep 18, 2024
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
a8685bb
add endpoint for list of deployment models
jihyunmoon16 0844926
fix typo
jihyunmoon16 549bd95
add path variable to api doc
jihyunmoon16 6d9356f
Add test code for getDeploymentModels open api endpoint
jihyunmoon16 99e9c30
Fix field name to meet the coding convention
jihyunmoon16 6750d41
Merge branch 'aliencube:main' into feature/169-deployment-models-endp…
jihyunmoon16 433a867
Merge branch 'aliencube:main' into feature/169-deployment-models-endp…
jihyunmoon16 4f2befc
Fix DeploymentModelDetails class to have only Name field
jihyunmoon16 69290d0
Merge branch 'aliencube:main' into feature/169-deployment-models-endp…
jihyunmoon16 9d87a67
Merge branch 'feature/169-deployment-models-endpoint' of https://gith…
jihyunmoon16 831ef9d
Add response entity test
jihyunmoon16 ac237a7
Add properties 테스트
jihyunmoon16 b4e6e46
Merge branch 'aliencube:main' into feature/169-deployment-models-endp…
jihyunmoon16 b298981
Merge branch 'aliencube:main' into feature/169-deployment-models-endp…
jihyunmoon16 86ee842
Refactor memberData to inlineData
jihyunmoon16 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
14 changes: 14 additions & 0 deletions
14
src/AzureOpenAIProxy.ApiApp/Models/DeploymentModelDetails.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,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; | ||
|
||
} |
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
230 changes: 230 additions & 0 deletions
230
test/AzureOpenAIProxy.AppHost.Tests/ApiApp/Endpoints/GetDeploymentModelsOpenApiTest.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,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
|
Oops, something went wrong.
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.