-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0f9f82b
commit 9ef50fc
Showing
7 changed files
with
444 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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 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,30 @@ | ||
using System.Text.Json; | ||
using System.Text.Json.Nodes; | ||
|
||
namespace Microsoft.OpenApi.ApiManifest; | ||
|
||
public class Extensions : Dictionary<string, JsonNode> | ||
{ | ||
public static Extensions Load(JsonElement value) | ||
{ | ||
var extensions = new Extensions(); | ||
foreach(var property in value.EnumerateObject()) | ||
{ | ||
if (property.Value.ValueKind != JsonValueKind.Null) { | ||
extensions.Add(property.Name, JsonSerializer.Deserialize<JsonObject>(property.Value.GetRawText())); | ||
} | ||
} | ||
return extensions; | ||
} | ||
|
||
public void Write(Utf8JsonWriter writer) | ||
{ | ||
writer.WriteStartObject(); | ||
foreach(var extension in this) | ||
{ | ||
writer.WritePropertyName(extension.Key); | ||
writer.WriteRawValue(extension.Value.ToJsonString()); | ||
} | ||
writer.WriteEndObject(); | ||
} | ||
} |
This file contains 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,36 @@ | ||
|
||
using System.Text.Json; | ||
|
||
namespace Microsoft.OpenApi.ApiManifest.OpenAI; | ||
|
||
public class Api { | ||
public string? Type { get; set; } | ||
public string? Url { get; set; } | ||
public bool? IsUserAuthenticated { get; set; } | ||
|
||
public static Api Load(JsonElement value) | ||
{ | ||
var api = new Api(); | ||
ParsingHelpers.ParseMap(value, api, handlers); | ||
return api; | ||
} | ||
|
||
// Create handlers FixedFieldMap for Api | ||
private static FixedFieldMap<Api> handlers = new() | ||
{ | ||
{ "type", (o,v) => {o.Type = v.GetString(); } }, | ||
{ "url", (o,v) => {o.Url = v.GetString(); } }, | ||
{ "is_user_authenticated", (o,v) => {o.IsUserAuthenticated = v.GetBoolean(); }}, | ||
}; | ||
|
||
public void Write(Utf8JsonWriter writer) | ||
{ | ||
writer.WriteStartObject(); | ||
writer.WriteString("type", Type); | ||
writer.WriteString("url", Url); | ||
writer.WriteBoolean("is_user_authenticated", IsUserAuthenticated ?? false); | ||
writer.WriteEndObject(); | ||
} | ||
} | ||
|
||
|
This file contains 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,140 @@ | ||
|
||
using System.Text.Json; | ||
|
||
namespace Microsoft.OpenApi.ApiManifest.OpenAI; | ||
|
||
public abstract class BaseManifestAuth | ||
{ | ||
public string? Type { get; set; } | ||
public string? Instructions { get; set; } | ||
|
||
public static BaseManifestAuth? Load(JsonElement value) | ||
{ | ||
BaseManifestAuth? auth = null; | ||
|
||
switch(value.GetProperty("type").GetString()) { | ||
case "none": | ||
auth = new ManifestNoAuth(); | ||
ParsingHelpers.ParseMap<ManifestNoAuth>(value, (ManifestNoAuth)auth, ManifestNoAuth.handlers); | ||
break; | ||
case "user_http": | ||
auth = new ManifestUserHttpAuth(); | ||
ParsingHelpers.ParseMap<ManifestUserHttpAuth>(value, (ManifestUserHttpAuth)auth, ManifestUserHttpAuth.handlers); | ||
break; | ||
case "service_http": | ||
auth = new ManifestServiceHttpAuth(); | ||
ParsingHelpers.ParseMap<ManifestServiceHttpAuth>(value, (ManifestServiceHttpAuth)auth, ManifestServiceHttpAuth.handlers); | ||
break; | ||
case "oauth": | ||
auth = new ManifestOAuthAuth(); | ||
ParsingHelpers.ParseMap<ManifestOAuthAuth>(value, (ManifestOAuthAuth)auth, ManifestOAuthAuth.handlers); | ||
break; | ||
} | ||
|
||
return auth; | ||
} | ||
|
||
// Create handlers FixedFieldMap for ManifestAuth | ||
|
||
public virtual void Write(Utf8JsonWriter writer) {} | ||
|
||
} | ||
|
||
public class ManifestNoAuth : BaseManifestAuth | ||
{ | ||
public ManifestNoAuth() | ||
{ | ||
Type = "none"; | ||
} | ||
|
||
internal static FixedFieldMap<ManifestNoAuth> handlers = new() | ||
{ | ||
{ "type", (o,v) => {o.Type = v.GetString(); } }, | ||
{ "instructions", (o,v) => {o.Instructions = v.GetString(); } }, | ||
}; | ||
|
||
public override void Write(Utf8JsonWriter writer) { | ||
writer.WriteStartObject(); | ||
writer.WriteString("type", Type); | ||
if(Instructions != null) writer.WriteString("instructions", Instructions); | ||
writer.WriteEndObject(); | ||
} | ||
} | ||
|
||
public class ManifestOAuthAuth : BaseManifestAuth | ||
{ | ||
public string? ClientUrl { get; set; } | ||
public string? Scope { get; set; } | ||
public string? AuthorizationUrl { get; set; } | ||
public string? AuthorizationContentType { get; set; } | ||
public Dictionary<string, string>? VerificationTokens { get; set; } | ||
|
||
public ManifestOAuthAuth() | ||
{ | ||
Type = "oauth"; | ||
} | ||
internal static FixedFieldMap<ManifestOAuthAuth> handlers = new() | ||
{ | ||
{ "type", (o,v) => {o.Type = v.GetString(); } }, | ||
{ "instructions", (o,v) => {o.Instructions = v.GetString(); } }, | ||
{ "client_url", (o,v) => {o.ClientUrl = v.GetString(); } }, | ||
{ "scope", (o,v) => {o.Scope = v.GetString(); } }, | ||
{ "authorization_url", (o,v) => {o.AuthorizationUrl = v.GetString(); } }, | ||
{ "authorization_content_type", (o,v) => {o.AuthorizationContentType = v.GetString(); } }, | ||
{ "verification_tokens", (o,v) => { o.VerificationTokens = ParsingHelpers.GetMap<string>(v,(e) => e.GetString() ); } }, | ||
}; | ||
|
||
public override void Write(Utf8JsonWriter writer) { | ||
writer.WriteStartObject(); | ||
writer.WriteString("type", Type); | ||
|
||
if(Instructions != null) writer.WriteString("instructions", Instructions); | ||
if(ClientUrl != null) writer.WriteString("client_url", ClientUrl); | ||
if(Scope != null) writer.WriteString("scope", Scope); | ||
if(AuthorizationUrl != null) writer.WriteString("authorization_url", AuthorizationUrl); | ||
if(AuthorizationContentType != null) writer.WriteString("authorization_content_type", AuthorizationContentType); | ||
writer.WriteEndObject(); | ||
} | ||
} | ||
|
||
public class ManifestUserHttpAuth : BaseManifestAuth | ||
{ | ||
public ManifestUserHttpAuth() | ||
{ | ||
Type = "user_http"; | ||
} | ||
internal static FixedFieldMap<ManifestUserHttpAuth> handlers = new() | ||
{ | ||
{ "type", (o,v) => {o.Type = v.GetString(); } }, | ||
{ "instructions", (o,v) => {o.Instructions = v.GetString(); } }, | ||
}; | ||
public override void Write(Utf8JsonWriter writer) { | ||
writer.WriteStartObject(); | ||
writer.WriteString("type", Type); | ||
writer.WriteString("instructions", Instructions); | ||
writer.WriteEndObject(); | ||
} | ||
} | ||
|
||
public class ManifestServiceHttpAuth : BaseManifestAuth | ||
{ | ||
public ManifestServiceHttpAuth() | ||
{ | ||
Type = "service_http"; | ||
} | ||
internal static FixedFieldMap<ManifestServiceHttpAuth> handlers = new() | ||
{ | ||
{ "type", (o,v) => {o.Type = v.GetString(); } }, | ||
{ "instructions", (o,v) => {o.Instructions = v.GetString(); } }, | ||
}; | ||
public override void Write(Utf8JsonWriter writer) { | ||
writer.WriteStartObject(); | ||
writer.WriteString("type", Type); | ||
writer.WriteString("instructions", Instructions); | ||
writer.WriteEndObject(); | ||
} | ||
} | ||
|
||
|
||
|
||
|
This file contains 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,66 @@ | ||
|
||
using System.Text.Json; | ||
|
||
namespace Microsoft.OpenApi.ApiManifest.OpenAI; | ||
|
||
public class OpenAIPluginManifest | ||
{ | ||
public string? SchemaVersion { get; set; } | ||
public string? NameForHuman { get; set; } | ||
public string? NameForModel { get; set; } | ||
public string? DescriptionForHuman { get; set; } | ||
public string? DescriptionForModel { get; set; } | ||
public BaseManifestAuth? Auth { get; set; } | ||
public Api? Api { get; set; } | ||
public string? LogoUrl { get; set; } | ||
public string? ContactEmail { get; set; } | ||
public string? LegalInfoUrl { get; set; } | ||
|
||
|
||
public static OpenAIPluginManifest Load(JsonElement value) | ||
{ | ||
var manifest = new OpenAIPluginManifest(); | ||
ParsingHelpers.ParseMap(value, manifest, handlers); | ||
return manifest; | ||
} | ||
|
||
// Create handlers FixedFieldMap for OpenAIPluginManifest | ||
private static FixedFieldMap<OpenAIPluginManifest> handlers = new() | ||
{ | ||
{ "schema_version", (o,v) => {o.SchemaVersion = v.GetString(); } }, | ||
{ "name_for_human", (o,v) => {o.NameForHuman = v.GetString(); } }, | ||
{ "name_for_model", (o,v) => {o.NameForModel = v.GetString(); } }, | ||
{ "description_for_human", (o,v) => {o.DescriptionForHuman = v.GetString(); } }, | ||
{ "description_for_model", (o,v) => {o.DescriptionForModel = v.GetString(); } }, | ||
{ "auth", (o,v) => {o.Auth = BaseManifestAuth.Load(v); } }, | ||
{ "api", (o,v) => {o.Api = Api.Load(v); } }, | ||
{ "logo_url", (o,v) => {o.LogoUrl = v.GetString(); } }, | ||
{ "contact_email", (o,v) => {o.ContactEmail = v.GetString(); } }, | ||
{ "legal_info_url", (o,v) => {o.LegalInfoUrl = v.GetString(); } }, | ||
}; | ||
|
||
//Write method | ||
public void Write(Utf8JsonWriter writer) | ||
{ | ||
writer.WriteStartObject(); | ||
writer.WriteString("schema_version", SchemaVersion); | ||
writer.WriteString("name_for_human", NameForHuman); | ||
writer.WriteString("name_for_model", NameForModel); | ||
writer.WriteString("description_for_human", DescriptionForHuman); | ||
writer.WriteString("description_for_model", DescriptionForModel); | ||
if (Auth != null) { | ||
writer.WritePropertyName("auth"); | ||
Auth.Write(writer); | ||
} | ||
if (Api != null) { | ||
writer.WritePropertyName("api"); | ||
Api?.Write(writer); | ||
} | ||
if (LogoUrl != null)writer.WriteString("logo_url", LogoUrl); | ||
if (ContactEmail != null) writer.WriteString("contact_email", ContactEmail); | ||
if (LegalInfoUrl != null) writer.WriteString("legal_info_url", LegalInfoUrl); | ||
writer.WriteEndObject(); | ||
} | ||
} | ||
|
||
|
Oops, something went wrong.