Skip to content

Commit

Permalink
feat: Added Artifact API support.
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed Sep 17, 2024
1 parent 1f010a8 commit 392b4f0
Show file tree
Hide file tree
Showing 102 changed files with 6,489 additions and 526 deletions.
28 changes: 26 additions & 2 deletions src/helpers/FixOpenApiSpec/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,44 @@
using Microsoft.OpenApi.Readers;

var path = args[0];
var artifactPath = args[1];
var text = await File.ReadAllTextAsync(path);
var artifactText = await File.ReadAllTextAsync(artifactPath);

text = text
.Replace(" v1beta", " ")
.Replace("#/definitions/v1beta", "#/definitions/")
.Replace("MgmtPublicService_", string.Empty)
;
artifactText = artifactText
.Replace(" v1alpha", " ")
.Replace("#/definitions/v1alpha", "#/definitions/")
.Replace(" ArtifactPublicService", " ")
.Replace("#/definitions/ArtifactPublicService", "#/definitions/")
.Replace("ArtifactPublicService_", string.Empty)
;

var openApiDocument = new OpenApiStringReader().Read(text, out var diagnostics);
var artifactOpenApiDocument = new OpenApiStringReader().Read(artifactText, out var artifactDiagnostics);

foreach (var (_, operation) in openApiDocument.Paths.SelectMany(x => x.Value.Operations))
foreach (var pair in artifactOpenApiDocument.Components.Schemas)
{
if (openApiDocument.Components.Schemas.ContainsKey(pair.Key))
{
Console.WriteLine($"Removing {pair.Key} because it already exists in the document");
openApiDocument.Components.Schemas.Remove(pair.Key);
}

openApiDocument.Components.Schemas.Add(pair);
}
foreach (var pair in artifactOpenApiDocument.Paths)
{
operation.OperationId = operation.OperationId.Replace("MgmtPublicService_", string.Empty);
openApiDocument.Paths.Add(pair.Key, pair.Value);
}

openApiDocument.Components.SecuritySchemes["Bearer"].Type = SecuritySchemeType.Http;
openApiDocument.Components.SecuritySchemes["Bearer"].Scheme = "bearer";

//openApiDocument.Components.Schemas["GenerateCompletionRequest"]!.Properties["stream"]!.Default = new OpenApiBoolean(true);

text = openApiDocument.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0);
Expand Down
138 changes: 138 additions & 0 deletions src/libs/Instill/Generated/Instill.CatalogClient.CreateCatalog.g.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@

#nullable enable

namespace Instill
{
public partial class CatalogClient
{
partial void PrepareCreateCatalogArguments(
global::System.Net.Http.HttpClient httpClient,
ref string namespaceId,
global::Instill.CreateCatalogBody request);
partial void PrepareCreateCatalogRequest(
global::System.Net.Http.HttpClient httpClient,
global::System.Net.Http.HttpRequestMessage httpRequestMessage,
string namespaceId,
global::Instill.CreateCatalogBody request);
partial void ProcessCreateCatalogResponse(
global::System.Net.Http.HttpClient httpClient,
global::System.Net.Http.HttpResponseMessage httpResponseMessage);

partial void ProcessCreateCatalogResponseContent(
global::System.Net.Http.HttpClient httpClient,
global::System.Net.Http.HttpResponseMessage httpResponseMessage,
ref string content);

/// <summary>
/// Create a catalog
/// </summary>
/// <param name="namespaceId"></param>
/// <param name="request"></param>
/// <param name="cancellationToken">The token to cancel the operation with</param>
/// <exception cref="global::System.InvalidOperationException"></exception>
public async global::System.Threading.Tasks.Task<global::Instill.CreateCatalogResponse> CreateCatalogAsync(
string namespaceId,
global::Instill.CreateCatalogBody request,
global::System.Threading.CancellationToken cancellationToken = default)
{
request = request ?? throw new global::System.ArgumentNullException(nameof(request));

PrepareArguments(
client: _httpClient);
PrepareCreateCatalogArguments(
httpClient: _httpClient,
namespaceId: ref namespaceId,
request: request);

using var httpRequest = new global::System.Net.Http.HttpRequestMessage(
method: global::System.Net.Http.HttpMethod.Post,
requestUri: new global::System.Uri(_httpClient.BaseAddress?.AbsoluteUri.TrimEnd('/') + $"/v1alpha/namespaces/{namespaceId}/catalogs", global::System.UriKind.RelativeOrAbsolute));
var __httpRequestContentBody = global::System.Text.Json.JsonSerializer.Serialize(request, request.GetType(), JsonSerializerContext);
var __httpRequestContent = new global::System.Net.Http.StringContent(
content: __httpRequestContentBody,
encoding: global::System.Text.Encoding.UTF8,
mediaType: "application/json");
httpRequest.Content = __httpRequestContent;

PrepareRequest(
client: _httpClient,
request: httpRequest);
PrepareCreateCatalogRequest(
httpClient: _httpClient,
httpRequestMessage: httpRequest,
namespaceId: namespaceId,
request: request);

using var response = await _httpClient.SendAsync(
request: httpRequest,
completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead,
cancellationToken: cancellationToken).ConfigureAwait(false);

ProcessResponse(
client: _httpClient,
response: response);
ProcessCreateCatalogResponse(
httpClient: _httpClient,
httpResponseMessage: response);

var __content = await response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);

ProcessResponseContent(
client: _httpClient,
response: response,
content: ref __content);
ProcessCreateCatalogResponseContent(
httpClient: _httpClient,
httpResponseMessage: response,
content: ref __content);

try
{
response.EnsureSuccessStatusCode();
}
catch (global::System.Net.Http.HttpRequestException ex)
{
throw new global::System.InvalidOperationException(__content, ex);
}

return
global::System.Text.Json.JsonSerializer.Deserialize(__content, typeof(global::Instill.CreateCatalogResponse), JsonSerializerContext) as global::Instill.CreateCatalogResponse ??
throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" ");
}

/// <summary>
/// Create a catalog
/// </summary>
/// <param name="namespaceId"></param>
/// <param name="name">
/// The catalog name.
/// </param>
/// <param name="description">
/// The catalog description.
/// </param>
/// <param name="tags">
/// The catalog tags.
/// </param>
/// <param name="cancellationToken">The token to cancel the operation with</param>
/// <exception cref="global::System.InvalidOperationException"></exception>
public async global::System.Threading.Tasks.Task<global::Instill.CreateCatalogResponse> CreateCatalogAsync(
string namespaceId,
string? name = default,
string? description = default,
global::System.Collections.Generic.IList<string>? tags = default,
global::System.Threading.CancellationToken cancellationToken = default)
{
var request = new global::Instill.CreateCatalogBody
{
Name = name,
Description = description,
Tags = tags,
};

return await CreateCatalogAsync(
namespaceId: namespaceId,
request: request,
cancellationToken: cancellationToken).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@

#nullable enable

namespace Instill
{
public partial class CatalogClient
{
partial void PrepareDeleteCatalogArguments(
global::System.Net.Http.HttpClient httpClient,
ref string namespaceId,
ref string catalogId);
partial void PrepareDeleteCatalogRequest(
global::System.Net.Http.HttpClient httpClient,
global::System.Net.Http.HttpRequestMessage httpRequestMessage,
string namespaceId,
string catalogId);
partial void ProcessDeleteCatalogResponse(
global::System.Net.Http.HttpClient httpClient,
global::System.Net.Http.HttpResponseMessage httpResponseMessage);

partial void ProcessDeleteCatalogResponseContent(
global::System.Net.Http.HttpClient httpClient,
global::System.Net.Http.HttpResponseMessage httpResponseMessage,
ref string content);

/// <summary>
/// Delete a catalog
/// </summary>
/// <param name="namespaceId"></param>
/// <param name="catalogId"></param>
/// <param name="cancellationToken">The token to cancel the operation with</param>
/// <exception cref="global::System.InvalidOperationException"></exception>
public async global::System.Threading.Tasks.Task<global::Instill.DeleteCatalogResponse> DeleteCatalogAsync(
string namespaceId,
string catalogId,
global::System.Threading.CancellationToken cancellationToken = default)
{
PrepareArguments(
client: _httpClient);
PrepareDeleteCatalogArguments(
httpClient: _httpClient,
namespaceId: ref namespaceId,
catalogId: ref catalogId);

using var httpRequest = new global::System.Net.Http.HttpRequestMessage(
method: global::System.Net.Http.HttpMethod.Delete,
requestUri: new global::System.Uri(_httpClient.BaseAddress?.AbsoluteUri.TrimEnd('/') + $"/v1alpha/namespaces/{namespaceId}/catalogs/{catalogId}", global::System.UriKind.RelativeOrAbsolute));

PrepareRequest(
client: _httpClient,
request: httpRequest);
PrepareDeleteCatalogRequest(
httpClient: _httpClient,
httpRequestMessage: httpRequest,
namespaceId: namespaceId,
catalogId: catalogId);

using var response = await _httpClient.SendAsync(
request: httpRequest,
completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead,
cancellationToken: cancellationToken).ConfigureAwait(false);

ProcessResponse(
client: _httpClient,
response: response);
ProcessDeleteCatalogResponse(
httpClient: _httpClient,
httpResponseMessage: response);

var __content = await response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);

ProcessResponseContent(
client: _httpClient,
response: response,
content: ref __content);
ProcessDeleteCatalogResponseContent(
httpClient: _httpClient,
httpResponseMessage: response,
content: ref __content);

try
{
response.EnsureSuccessStatusCode();
}
catch (global::System.Net.Http.HttpRequestException ex)
{
throw new global::System.InvalidOperationException(__content, ex);
}

return
global::System.Text.Json.JsonSerializer.Deserialize(__content, typeof(global::Instill.DeleteCatalogResponse), JsonSerializerContext) as global::Instill.DeleteCatalogResponse ??
throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" ");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@

#nullable enable

namespace Instill
{
public partial class CatalogClient
{
partial void PrepareDeleteCatalogFileArguments(
global::System.Net.Http.HttpClient httpClient,
ref string fileUid);
partial void PrepareDeleteCatalogFileRequest(
global::System.Net.Http.HttpClient httpClient,
global::System.Net.Http.HttpRequestMessage httpRequestMessage,
string fileUid);
partial void ProcessDeleteCatalogFileResponse(
global::System.Net.Http.HttpClient httpClient,
global::System.Net.Http.HttpResponseMessage httpResponseMessage);

partial void ProcessDeleteCatalogFileResponseContent(
global::System.Net.Http.HttpClient httpClient,
global::System.Net.Http.HttpResponseMessage httpResponseMessage,
ref string content);

/// <summary>
/// Delete a file
/// </summary>
/// <param name="fileUid"></param>
/// <param name="cancellationToken">The token to cancel the operation with</param>
/// <exception cref="global::System.InvalidOperationException"></exception>
public async global::System.Threading.Tasks.Task<global::Instill.DeleteCatalogFileResponse> DeleteCatalogFileAsync(
string fileUid,
global::System.Threading.CancellationToken cancellationToken = default)
{
PrepareArguments(
client: _httpClient);
PrepareDeleteCatalogFileArguments(
httpClient: _httpClient,
fileUid: ref fileUid);

using var httpRequest = new global::System.Net.Http.HttpRequestMessage(
method: global::System.Net.Http.HttpMethod.Delete,
requestUri: new global::System.Uri(_httpClient.BaseAddress?.AbsoluteUri.TrimEnd('/') + $"/v1alpha/catalogs/files?fileUid={fileUid}", global::System.UriKind.RelativeOrAbsolute));

PrepareRequest(
client: _httpClient,
request: httpRequest);
PrepareDeleteCatalogFileRequest(
httpClient: _httpClient,
httpRequestMessage: httpRequest,
fileUid: fileUid);

using var response = await _httpClient.SendAsync(
request: httpRequest,
completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead,
cancellationToken: cancellationToken).ConfigureAwait(false);

ProcessResponse(
client: _httpClient,
response: response);
ProcessDeleteCatalogFileResponse(
httpClient: _httpClient,
httpResponseMessage: response);

var __content = await response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);

ProcessResponseContent(
client: _httpClient,
response: response,
content: ref __content);
ProcessDeleteCatalogFileResponseContent(
httpClient: _httpClient,
httpResponseMessage: response,
content: ref __content);

try
{
response.EnsureSuccessStatusCode();
}
catch (global::System.Net.Http.HttpRequestException ex)
{
throw new global::System.InvalidOperationException(__content, ex);
}

return
global::System.Text.Json.JsonSerializer.Deserialize(__content, typeof(global::Instill.DeleteCatalogFileResponse), JsonSerializerContext) as global::Instill.DeleteCatalogFileResponse ??
throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" ");
}
}
}
Loading

0 comments on commit 392b4f0

Please sign in to comment.