Skip to content

Commit b8da9f5

Browse files
committed
test: Added Polymorphism tests.
1 parent 8c8ebf6 commit b8da9f5

17 files changed

+1404
-648
lines changed

specs/cohere.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7486,6 +7486,15 @@ components:
74867486
type: string
74877487
x-fern-audiences:
74887488
- public
7489+
discriminator:
7490+
propertyName: event_type
7491+
mapping:
7492+
stream-start: '#/components/schemas/ChatStreamStartEvent'
7493+
search-queries-generation: '#/components/schemas/ChatSearchQueriesGenerationEvent'
7494+
search-results: '#/components/schemas/ChatSearchResultsEvent'
7495+
text-generation: '#/components/schemas/ChatTextGenerationEvent'
7496+
citation-generation: '#/components/schemas/ChatCitationGenerationEvent'
7497+
stream-end: '#/components/schemas/ChatStreamEndEvent'
74897498
ChatStreamStartEvent:
74907499
allOf:
74917500
- $ref: '#/components/schemas/ChatStreamEvent'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
//HintName: G.Models.ChatStreamEventDiscriminator.Json.g.cs
2+
#nullable enable
3+
4+
namespace G
5+
{
6+
public sealed partial class ChatStreamEventDiscriminator
7+
{
8+
/// <summary>
9+
/// Serializes the current instance to a JSON string using the provided JsonSerializerOptions.
10+
/// </summary>
11+
#if NET8_0_OR_GREATER
12+
[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.")]
13+
[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.")]
14+
#endif
15+
public string ToJson(
16+
global::Newtonsoft.Json.JsonSerializerSettings? jsonSerializerOptions = null)
17+
{
18+
return global::Newtonsoft.Json.JsonConvert.SerializeObject(
19+
this,
20+
jsonSerializerOptions);
21+
}
22+
23+
/// <summary>
24+
/// Deserializes a JSON string using the provided JsonSerializerOptions.
25+
/// </summary>
26+
#if NET8_0_OR_GREATER
27+
[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.")]
28+
[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.")]
29+
#endif
30+
public static global::G.ChatStreamEventDiscriminator? FromJson(
31+
string json,
32+
global::Newtonsoft.Json.JsonSerializerSettings? jsonSerializerOptions = null)
33+
{
34+
return global::Newtonsoft.Json.JsonConvert.DeserializeObject<global::G.ChatStreamEventDiscriminator>(
35+
json,
36+
jsonSerializerOptions);
37+
}
38+
39+
/// <summary>
40+
/// Deserializes a JSON stream using the provided JsonSerializerOptions.
41+
/// </summary>
42+
#if NET8_0_OR_GREATER
43+
[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.")]
44+
[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.")]
45+
#endif
46+
public static global::System.Threading.Tasks.ValueTask<global::G.ChatStreamEventDiscriminator?> FromJsonStreamAsync(
47+
global::System.IO.Stream jsonStream,
48+
global::Newtonsoft.Json.JsonSerializerSettings? jsonSerializerOptions = null)
49+
{
50+
using var streamReader = new global::System.IO.StreamReader(jsonStream);
51+
using var jsonReader = new global::Newtonsoft.Json.JsonTextReader(streamReader);
52+
var serializer = global::Newtonsoft.Json.JsonSerializer.Create(jsonSerializerOptions);
53+
return new global::System.Threading.Tasks.ValueTask<global::G.ChatStreamEventDiscriminator?>(serializer.Deserialize<global::G.ChatStreamEventDiscriminator>(jsonReader));
54+
}
55+
}
56+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//HintName: G.Models.ChatStreamEventDiscriminator.g.cs
2+
3+
#nullable enable
4+
5+
namespace G
6+
{
7+
/// <summary>
8+
///
9+
/// </summary>
10+
public sealed partial class ChatStreamEventDiscriminator
11+
{
12+
/// <summary>
13+
///
14+
/// </summary>
15+
[global::Newtonsoft.Json.JsonProperty("event_type")]
16+
public global::G.ChatStreamEventDiscriminatorEventType? EventType { get; set; }
17+
18+
/// <summary>
19+
/// Additional properties that are not explicitly defined in the schema
20+
/// </summary>
21+
[global::Newtonsoft.Json.JsonExtensionData]
22+
public global::System.Collections.Generic.IDictionary<string, object> AdditionalProperties { get; set; } = new global::System.Collections.Generic.Dictionary<string, object>();
23+
24+
/// <summary>
25+
/// Initializes a new instance of the <see cref="ChatStreamEventDiscriminator" /> class.
26+
/// </summary>
27+
/// <param name="eventType"></param>
28+
public ChatStreamEventDiscriminator(
29+
global::G.ChatStreamEventDiscriminatorEventType? eventType)
30+
{
31+
this.EventType = eventType;
32+
}
33+
34+
/// <summary>
35+
/// Initializes a new instance of the <see cref="ChatStreamEventDiscriminator" /> class.
36+
/// </summary>
37+
public ChatStreamEventDiscriminator()
38+
{
39+
}
40+
}
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
//HintName: G.Models.ChatStreamEventDiscriminatorEventType.g.cs
2+
3+
#nullable enable
4+
5+
namespace G
6+
{
7+
/// <summary>
8+
///
9+
/// </summary>
10+
[global::System.Runtime.Serialization.DataContract]
11+
public enum ChatStreamEventDiscriminatorEventType
12+
{
13+
/// <summary>
14+
///
15+
/// </summary>
16+
[global::System.Runtime.Serialization.EnumMember(Value="stream-start")]
17+
StreamStart,
18+
/// <summary>
19+
///
20+
/// </summary>
21+
[global::System.Runtime.Serialization.EnumMember(Value="search-queries-generation")]
22+
SearchQueriesGeneration,
23+
/// <summary>
24+
///
25+
/// </summary>
26+
[global::System.Runtime.Serialization.EnumMember(Value="search-results")]
27+
SearchResults,
28+
/// <summary>
29+
///
30+
/// </summary>
31+
[global::System.Runtime.Serialization.EnumMember(Value="text-generation")]
32+
TextGeneration,
33+
/// <summary>
34+
///
35+
/// </summary>
36+
[global::System.Runtime.Serialization.EnumMember(Value="citation-generation")]
37+
CitationGeneration,
38+
/// <summary>
39+
///
40+
/// </summary>
41+
[global::System.Runtime.Serialization.EnumMember(Value="stream-end")]
42+
StreamEnd,
43+
}
44+
45+
/// <summary>
46+
/// Enum extensions to do fast conversions without the reflection.
47+
/// </summary>
48+
public static class ChatStreamEventDiscriminatorEventTypeExtensions
49+
{
50+
/// <summary>
51+
/// Converts an enum to a string.
52+
/// </summary>
53+
public static string ToValueString(this ChatStreamEventDiscriminatorEventType value)
54+
{
55+
return value switch
56+
{
57+
ChatStreamEventDiscriminatorEventType.StreamStart => "stream-start",
58+
ChatStreamEventDiscriminatorEventType.SearchQueriesGeneration => "search-queries-generation",
59+
ChatStreamEventDiscriminatorEventType.SearchResults => "search-results",
60+
ChatStreamEventDiscriminatorEventType.TextGeneration => "text-generation",
61+
ChatStreamEventDiscriminatorEventType.CitationGeneration => "citation-generation",
62+
ChatStreamEventDiscriminatorEventType.StreamEnd => "stream-end",
63+
_ => throw new global::System.ArgumentOutOfRangeException(nameof(value), value, null),
64+
};
65+
}
66+
/// <summary>
67+
/// Converts an string to a enum.
68+
/// </summary>
69+
public static ChatStreamEventDiscriminatorEventType? ToEnum(string value)
70+
{
71+
return value switch
72+
{
73+
"stream-start" => ChatStreamEventDiscriminatorEventType.StreamStart,
74+
"search-queries-generation" => ChatStreamEventDiscriminatorEventType.SearchQueriesGeneration,
75+
"search-results" => ChatStreamEventDiscriminatorEventType.SearchResults,
76+
"text-generation" => ChatStreamEventDiscriminatorEventType.TextGeneration,
77+
"citation-generation" => ChatStreamEventDiscriminatorEventType.CitationGeneration,
78+
"stream-end" => ChatStreamEventDiscriminatorEventType.StreamEnd,
79+
_ => null,
80+
};
81+
}
82+
}
83+
}

src/tests/AutoSDK.SnapshotTests/Snapshots/cohere/SystemTextJson/_#G.Api.g.verified.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ public sealed partial class Api : global::G.IApi, global::System.IDisposable
5151
new global::G.JsonConverters.FinishReasonNullableJsonConverter(),
5252
new global::G.JsonConverters.ChatStreamEventEventTypeJsonConverter(),
5353
new global::G.JsonConverters.ChatStreamEventEventTypeNullableJsonConverter(),
54+
new global::G.JsonConverters.ChatStreamEventDiscriminatorEventTypeJsonConverter(),
55+
new global::G.JsonConverters.ChatStreamEventDiscriminatorEventTypeNullableJsonConverter(),
5456
new global::G.JsonConverters.ChatStreamEndEventVariant2FinishReasonJsonConverter(),
5557
new global::G.JsonConverters.ChatStreamEndEventVariant2FinishReasonNullableJsonConverter(),
5658
new global::G.JsonConverters.TextContentTypeJsonConverter(),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
//HintName: G.Models.ChatStreamEventDiscriminator.Json.g.cs
2+
#nullable enable
3+
4+
namespace G
5+
{
6+
public sealed partial class ChatStreamEventDiscriminator
7+
{
8+
/// <summary>
9+
/// Serializes the current instance to a JSON string using the provided JsonSerializerContext.
10+
/// </summary>
11+
public string ToJson(
12+
global::System.Text.Json.Serialization.JsonSerializerContext jsonSerializerContext)
13+
{
14+
return global::System.Text.Json.JsonSerializer.Serialize(
15+
this,
16+
this.GetType(),
17+
jsonSerializerContext);
18+
}
19+
20+
/// <summary>
21+
/// Serializes the current instance to a JSON string using the provided JsonSerializerOptions.
22+
/// </summary>
23+
#if NET8_0_OR_GREATER
24+
[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.")]
25+
[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.")]
26+
#endif
27+
public string ToJson(
28+
global::System.Text.Json.JsonSerializerOptions? jsonSerializerOptions = null)
29+
{
30+
return global::System.Text.Json.JsonSerializer.Serialize(
31+
this,
32+
jsonSerializerOptions);
33+
}
34+
35+
/// <summary>
36+
/// Deserializes a JSON string using the provided JsonSerializerContext.
37+
/// </summary>
38+
public static global::G.ChatStreamEventDiscriminator? FromJson(
39+
string json,
40+
global::System.Text.Json.Serialization.JsonSerializerContext jsonSerializerContext)
41+
{
42+
return global::System.Text.Json.JsonSerializer.Deserialize(
43+
json,
44+
typeof(global::G.ChatStreamEventDiscriminator),
45+
jsonSerializerContext) as global::G.ChatStreamEventDiscriminator;
46+
}
47+
48+
/// <summary>
49+
/// Deserializes a JSON string using the provided JsonSerializerOptions.
50+
/// </summary>
51+
#if NET8_0_OR_GREATER
52+
[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.")]
53+
[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.")]
54+
#endif
55+
public static global::G.ChatStreamEventDiscriminator? FromJson(
56+
string json,
57+
global::System.Text.Json.JsonSerializerOptions? jsonSerializerOptions = null)
58+
{
59+
return global::System.Text.Json.JsonSerializer.Deserialize<global::G.ChatStreamEventDiscriminator>(
60+
json,
61+
jsonSerializerOptions);
62+
}
63+
64+
/// <summary>
65+
/// Deserializes a JSON stream using the provided JsonSerializerContext.
66+
/// </summary>
67+
public static async global::System.Threading.Tasks.ValueTask<global::G.ChatStreamEventDiscriminator?> FromJsonStreamAsync(
68+
global::System.IO.Stream jsonStream,
69+
global::System.Text.Json.Serialization.JsonSerializerContext jsonSerializerContext)
70+
{
71+
return (await global::System.Text.Json.JsonSerializer.DeserializeAsync(
72+
jsonStream,
73+
typeof(global::G.ChatStreamEventDiscriminator),
74+
jsonSerializerContext).ConfigureAwait(false)) as global::G.ChatStreamEventDiscriminator;
75+
}
76+
77+
/// <summary>
78+
/// Deserializes a JSON stream using the provided JsonSerializerOptions.
79+
/// </summary>
80+
#if NET8_0_OR_GREATER
81+
[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.")]
82+
[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.")]
83+
#endif
84+
public static global::System.Threading.Tasks.ValueTask<global::G.ChatStreamEventDiscriminator?> FromJsonStreamAsync(
85+
global::System.IO.Stream jsonStream,
86+
global::System.Text.Json.JsonSerializerOptions? jsonSerializerOptions = null)
87+
{
88+
return global::System.Text.Json.JsonSerializer.DeserializeAsync<global::G.ChatStreamEventDiscriminator?>(
89+
jsonStream,
90+
jsonSerializerOptions);
91+
}
92+
}
93+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//HintName: G.Models.ChatStreamEventDiscriminator.g.cs
2+
3+
#nullable enable
4+
5+
namespace G
6+
{
7+
/// <summary>
8+
///
9+
/// </summary>
10+
public sealed partial class ChatStreamEventDiscriminator
11+
{
12+
/// <summary>
13+
///
14+
/// </summary>
15+
[global::System.Text.Json.Serialization.JsonPropertyName("event_type")]
16+
[global::System.Text.Json.Serialization.JsonConverter(typeof(global::G.JsonConverters.ChatStreamEventDiscriminatorEventTypeJsonConverter))]
17+
public global::G.ChatStreamEventDiscriminatorEventType? EventType { get; set; }
18+
19+
/// <summary>
20+
/// Additional properties that are not explicitly defined in the schema
21+
/// </summary>
22+
[global::System.Text.Json.Serialization.JsonExtensionData]
23+
public global::System.Collections.Generic.IDictionary<string, object> AdditionalProperties { get; set; } = new global::System.Collections.Generic.Dictionary<string, object>();
24+
25+
/// <summary>
26+
/// Initializes a new instance of the <see cref="ChatStreamEventDiscriminator" /> class.
27+
/// </summary>
28+
/// <param name="eventType"></param>
29+
[global::System.Diagnostics.CodeAnalysis.SetsRequiredMembers]
30+
public ChatStreamEventDiscriminator(
31+
global::G.ChatStreamEventDiscriminatorEventType? eventType)
32+
{
33+
this.EventType = eventType;
34+
}
35+
36+
/// <summary>
37+
/// Initializes a new instance of the <see cref="ChatStreamEventDiscriminator" /> class.
38+
/// </summary>
39+
public ChatStreamEventDiscriminator()
40+
{
41+
}
42+
}
43+
}

0 commit comments

Comments
 (0)