Skip to content

Commit

Permalink
test: Added Polymorphism tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed Dec 17, 2024
1 parent 8c8ebf6 commit b8da9f5
Show file tree
Hide file tree
Showing 17 changed files with 1,404 additions and 648 deletions.
9 changes: 9 additions & 0 deletions specs/cohere.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7486,6 +7486,15 @@ components:
type: string
x-fern-audiences:
- public
discriminator:
propertyName: event_type
mapping:
stream-start: '#/components/schemas/ChatStreamStartEvent'
search-queries-generation: '#/components/schemas/ChatSearchQueriesGenerationEvent'
search-results: '#/components/schemas/ChatSearchResultsEvent'
text-generation: '#/components/schemas/ChatTextGenerationEvent'
citation-generation: '#/components/schemas/ChatCitationGenerationEvent'
stream-end: '#/components/schemas/ChatStreamEndEvent'
ChatStreamStartEvent:
allOf:
- $ref: '#/components/schemas/ChatStreamEvent'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//HintName: G.Models.ChatStreamEventDiscriminator.Json.g.cs
#nullable enable

namespace G
{
public sealed partial class ChatStreamEventDiscriminator
{
/// <summary>
/// Serializes the current instance to a JSON string using the provided JsonSerializerOptions.
/// </summary>
#if NET8_0_OR_GREATER
[global::System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")]
[global::System.Diagnostics.CodeAnalysis.RequiresDynamicCode("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.")]
#endif
public string ToJson(
global::Newtonsoft.Json.JsonSerializerSettings? jsonSerializerOptions = null)
{
return global::Newtonsoft.Json.JsonConvert.SerializeObject(
this,
jsonSerializerOptions);
}

/// <summary>
/// Deserializes a JSON string using the provided JsonSerializerOptions.
/// </summary>
#if NET8_0_OR_GREATER
[global::System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")]
[global::System.Diagnostics.CodeAnalysis.RequiresDynamicCode("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.")]
#endif
public static global::G.ChatStreamEventDiscriminator? FromJson(
string json,
global::Newtonsoft.Json.JsonSerializerSettings? jsonSerializerOptions = null)
{
return global::Newtonsoft.Json.JsonConvert.DeserializeObject<global::G.ChatStreamEventDiscriminator>(
json,
jsonSerializerOptions);
}

/// <summary>
/// Deserializes a JSON stream using the provided JsonSerializerOptions.
/// </summary>
#if NET8_0_OR_GREATER
[global::System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")]
[global::System.Diagnostics.CodeAnalysis.RequiresDynamicCode("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.")]
#endif
public static global::System.Threading.Tasks.ValueTask<global::G.ChatStreamEventDiscriminator?> FromJsonStreamAsync(
global::System.IO.Stream jsonStream,
global::Newtonsoft.Json.JsonSerializerSettings? jsonSerializerOptions = null)
{
using var streamReader = new global::System.IO.StreamReader(jsonStream);
using var jsonReader = new global::Newtonsoft.Json.JsonTextReader(streamReader);
var serializer = global::Newtonsoft.Json.JsonSerializer.Create(jsonSerializerOptions);
return new global::System.Threading.Tasks.ValueTask<global::G.ChatStreamEventDiscriminator?>(serializer.Deserialize<global::G.ChatStreamEventDiscriminator>(jsonReader));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//HintName: G.Models.ChatStreamEventDiscriminator.g.cs

#nullable enable

namespace G
{
/// <summary>
///
/// </summary>
public sealed partial class ChatStreamEventDiscriminator
{
/// <summary>
///
/// </summary>
[global::Newtonsoft.Json.JsonProperty("event_type")]
public global::G.ChatStreamEventDiscriminatorEventType? EventType { get; set; }

/// <summary>
/// Additional properties that are not explicitly defined in the schema
/// </summary>
[global::Newtonsoft.Json.JsonExtensionData]
public global::System.Collections.Generic.IDictionary<string, object> AdditionalProperties { get; set; } = new global::System.Collections.Generic.Dictionary<string, object>();

/// <summary>
/// Initializes a new instance of the <see cref="ChatStreamEventDiscriminator" /> class.
/// </summary>
/// <param name="eventType"></param>
public ChatStreamEventDiscriminator(
global::G.ChatStreamEventDiscriminatorEventType? eventType)
{
this.EventType = eventType;
}

/// <summary>
/// Initializes a new instance of the <see cref="ChatStreamEventDiscriminator" /> class.
/// </summary>
public ChatStreamEventDiscriminator()
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
//HintName: G.Models.ChatStreamEventDiscriminatorEventType.g.cs

#nullable enable

namespace G
{
/// <summary>
///
/// </summary>
[global::System.Runtime.Serialization.DataContract]
public enum ChatStreamEventDiscriminatorEventType
{
/// <summary>
///
/// </summary>
[global::System.Runtime.Serialization.EnumMember(Value="stream-start")]
StreamStart,
/// <summary>
///
/// </summary>
[global::System.Runtime.Serialization.EnumMember(Value="search-queries-generation")]
SearchQueriesGeneration,
/// <summary>
///
/// </summary>
[global::System.Runtime.Serialization.EnumMember(Value="search-results")]
SearchResults,
/// <summary>
///
/// </summary>
[global::System.Runtime.Serialization.EnumMember(Value="text-generation")]
TextGeneration,
/// <summary>
///
/// </summary>
[global::System.Runtime.Serialization.EnumMember(Value="citation-generation")]
CitationGeneration,
/// <summary>
///
/// </summary>
[global::System.Runtime.Serialization.EnumMember(Value="stream-end")]
StreamEnd,
}

/// <summary>
/// Enum extensions to do fast conversions without the reflection.
/// </summary>
public static class ChatStreamEventDiscriminatorEventTypeExtensions
{
/// <summary>
/// Converts an enum to a string.
/// </summary>
public static string ToValueString(this ChatStreamEventDiscriminatorEventType value)
{
return value switch
{
ChatStreamEventDiscriminatorEventType.StreamStart => "stream-start",
ChatStreamEventDiscriminatorEventType.SearchQueriesGeneration => "search-queries-generation",
ChatStreamEventDiscriminatorEventType.SearchResults => "search-results",
ChatStreamEventDiscriminatorEventType.TextGeneration => "text-generation",
ChatStreamEventDiscriminatorEventType.CitationGeneration => "citation-generation",
ChatStreamEventDiscriminatorEventType.StreamEnd => "stream-end",
_ => throw new global::System.ArgumentOutOfRangeException(nameof(value), value, null),
};
}
/// <summary>
/// Converts an string to a enum.
/// </summary>
public static ChatStreamEventDiscriminatorEventType? ToEnum(string value)
{
return value switch
{
"stream-start" => ChatStreamEventDiscriminatorEventType.StreamStart,
"search-queries-generation" => ChatStreamEventDiscriminatorEventType.SearchQueriesGeneration,
"search-results" => ChatStreamEventDiscriminatorEventType.SearchResults,
"text-generation" => ChatStreamEventDiscriminatorEventType.TextGeneration,
"citation-generation" => ChatStreamEventDiscriminatorEventType.CitationGeneration,
"stream-end" => ChatStreamEventDiscriminatorEventType.StreamEnd,
_ => null,
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public sealed partial class Api : global::G.IApi, global::System.IDisposable
new global::G.JsonConverters.FinishReasonNullableJsonConverter(),
new global::G.JsonConverters.ChatStreamEventEventTypeJsonConverter(),
new global::G.JsonConverters.ChatStreamEventEventTypeNullableJsonConverter(),
new global::G.JsonConverters.ChatStreamEventDiscriminatorEventTypeJsonConverter(),
new global::G.JsonConverters.ChatStreamEventDiscriminatorEventTypeNullableJsonConverter(),
new global::G.JsonConverters.ChatStreamEndEventVariant2FinishReasonJsonConverter(),
new global::G.JsonConverters.ChatStreamEndEventVariant2FinishReasonNullableJsonConverter(),
new global::G.JsonConverters.TextContentTypeJsonConverter(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
//HintName: G.Models.ChatStreamEventDiscriminator.Json.g.cs
#nullable enable

namespace G
{
public sealed partial class ChatStreamEventDiscriminator
{
/// <summary>
/// Serializes the current instance to a JSON string using the provided JsonSerializerContext.
/// </summary>
public string ToJson(
global::System.Text.Json.Serialization.JsonSerializerContext jsonSerializerContext)
{
return global::System.Text.Json.JsonSerializer.Serialize(
this,
this.GetType(),
jsonSerializerContext);
}

/// <summary>
/// Serializes the current instance to a JSON string using the provided JsonSerializerOptions.
/// </summary>
#if NET8_0_OR_GREATER
[global::System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")]
[global::System.Diagnostics.CodeAnalysis.RequiresDynamicCode("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.")]
#endif
public string ToJson(
global::System.Text.Json.JsonSerializerOptions? jsonSerializerOptions = null)
{
return global::System.Text.Json.JsonSerializer.Serialize(
this,
jsonSerializerOptions);
}

/// <summary>
/// Deserializes a JSON string using the provided JsonSerializerContext.
/// </summary>
public static global::G.ChatStreamEventDiscriminator? FromJson(
string json,
global::System.Text.Json.Serialization.JsonSerializerContext jsonSerializerContext)
{
return global::System.Text.Json.JsonSerializer.Deserialize(
json,
typeof(global::G.ChatStreamEventDiscriminator),
jsonSerializerContext) as global::G.ChatStreamEventDiscriminator;
}

/// <summary>
/// Deserializes a JSON string using the provided JsonSerializerOptions.
/// </summary>
#if NET8_0_OR_GREATER
[global::System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")]
[global::System.Diagnostics.CodeAnalysis.RequiresDynamicCode("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.")]
#endif
public static global::G.ChatStreamEventDiscriminator? FromJson(
string json,
global::System.Text.Json.JsonSerializerOptions? jsonSerializerOptions = null)
{
return global::System.Text.Json.JsonSerializer.Deserialize<global::G.ChatStreamEventDiscriminator>(
json,
jsonSerializerOptions);
}

/// <summary>
/// Deserializes a JSON stream using the provided JsonSerializerContext.
/// </summary>
public static async global::System.Threading.Tasks.ValueTask<global::G.ChatStreamEventDiscriminator?> FromJsonStreamAsync(
global::System.IO.Stream jsonStream,
global::System.Text.Json.Serialization.JsonSerializerContext jsonSerializerContext)
{
return (await global::System.Text.Json.JsonSerializer.DeserializeAsync(
jsonStream,
typeof(global::G.ChatStreamEventDiscriminator),
jsonSerializerContext).ConfigureAwait(false)) as global::G.ChatStreamEventDiscriminator;
}

/// <summary>
/// Deserializes a JSON stream using the provided JsonSerializerOptions.
/// </summary>
#if NET8_0_OR_GREATER
[global::System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")]
[global::System.Diagnostics.CodeAnalysis.RequiresDynamicCode("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.")]
#endif
public static global::System.Threading.Tasks.ValueTask<global::G.ChatStreamEventDiscriminator?> FromJsonStreamAsync(
global::System.IO.Stream jsonStream,
global::System.Text.Json.JsonSerializerOptions? jsonSerializerOptions = null)
{
return global::System.Text.Json.JsonSerializer.DeserializeAsync<global::G.ChatStreamEventDiscriminator?>(
jsonStream,
jsonSerializerOptions);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//HintName: G.Models.ChatStreamEventDiscriminator.g.cs

#nullable enable

namespace G
{
/// <summary>
///
/// </summary>
public sealed partial class ChatStreamEventDiscriminator
{
/// <summary>
///
/// </summary>
[global::System.Text.Json.Serialization.JsonPropertyName("event_type")]
[global::System.Text.Json.Serialization.JsonConverter(typeof(global::G.JsonConverters.ChatStreamEventDiscriminatorEventTypeJsonConverter))]
public global::G.ChatStreamEventDiscriminatorEventType? EventType { get; set; }

/// <summary>
/// Additional properties that are not explicitly defined in the schema
/// </summary>
[global::System.Text.Json.Serialization.JsonExtensionData]
public global::System.Collections.Generic.IDictionary<string, object> AdditionalProperties { get; set; } = new global::System.Collections.Generic.Dictionary<string, object>();

/// <summary>
/// Initializes a new instance of the <see cref="ChatStreamEventDiscriminator" /> class.
/// </summary>
/// <param name="eventType"></param>
[global::System.Diagnostics.CodeAnalysis.SetsRequiredMembers]
public ChatStreamEventDiscriminator(
global::G.ChatStreamEventDiscriminatorEventType? eventType)
{
this.EventType = eventType;
}

/// <summary>
/// Initializes a new instance of the <see cref="ChatStreamEventDiscriminator" /> class.
/// </summary>
public ChatStreamEventDiscriminator()
{
}
}
}
Loading

0 comments on commit b8da9f5

Please sign in to comment.