diff --git a/CSharpToJsonSchema.sln b/CSharpToJsonSchema.sln index 3df5170..9c3eb17 100755 --- a/CSharpToJsonSchema.sln +++ b/CSharpToJsonSchema.sln @@ -97,6 +97,7 @@ Global {8AFCC30C-C59D-498D-BE68-9A328B3E5599} = {AAA11B78-2764-4520-A97E-46AA7089A588} {247C813A-9072-4DF3-B403-B35E3688DB4B} = {AAA11B78-2764-4520-A97E-46AA7089A588} {6167F915-83EB-42F9-929B-AD4719A55811} = {AAA11B78-2764-4520-A97E-46AA7089A588} + {DC07C90E-A58C-44B3-82D2-E2EB8F777B92} = {AAA11B78-2764-4520-A97E-46AA7089A588} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {CED9A020-DBA5-4BE6-8096-75E528648EC1} diff --git a/src/libs/CSharpToJsonSchema.Generators/Conversion/ToModels.cs b/src/libs/CSharpToJsonSchema.Generators/Conversion/ToModels.cs index 33f7271..f3b8a37 100644 --- a/src/libs/CSharpToJsonSchema.Generators/Conversion/ToModels.cs +++ b/src/libs/CSharpToJsonSchema.Generators/Conversion/ToModels.cs @@ -37,8 +37,6 @@ public static InterfaceData PrepareData( IsVoid: x.ReturnsVoid || x.ReturnType.MetadataName == "Task", IsStrict: isStrict, Parameters: parameters.Select(static y => y).ToArray(), - Descriptions: parameters.Select(static l => GetParameterDescriptions(l)).SelectMany(s => s) - .ToDictionary(s => s.Key, s => s.Value), ReturnType: x.ReturnType ); }) @@ -91,8 +89,6 @@ public static InterfaceData PrepareMethodData( IsVoid: x.ReturnsVoid || x.ReturnType.MetadataName == "Task", IsStrict: isStrict, Parameters: parameters.Select(static y => y).ToArray(), - Descriptions: parameters.Select(static l => GetParameterDescriptions(l)).SelectMany(s => s) - .ToDictionary(s => s.Key, s => s.Value), ReturnType:x.ReturnType ); methodList.Add(methodData); @@ -140,72 +136,6 @@ public static InterfaceData PrepareMethodData( return string.Join(".", commonParts); } - - - // private static Dictionary GetIsRequired(IParameterSymbol[] parameters, Dictionary? dics = null) - // { - // dics ??= new Dictionary(); - // - // foreach (var parameter in parameters) - // { - // if (dics.TryAdd(parameter.Name, IsRequired(parameter))) - // { - // if (parameter is IParameterSymbol namedTypeSymbol) - // { - // GetIsRequired(namedTypeSymbol.Type.GetMembers().OfType().ToArray(),dics) - // } - // } - // } - // - // return dics; - // } - // - // private static bool IsRequired(ISymbol parameter) - // { - // return false; - // //parameter.GetAttributes().OfType() - // } - - private static List> GetParameterDescriptions(IParameterSymbol parameters, - Dictionary? dics = null) - { - dics ??= new Dictionary(); - - - if (dics.TryAdd(parameters.Name.ToCamelCase(), GetDescription(parameters))) - { - if (parameters is IParameterSymbol namedTypeSymbol) - { - GetParameterDescriptions(namedTypeSymbol.Type.GetMembers().OfType().ToArray(), dics); - } - } - - return dics.Select(x => new KeyValuePair(x.Key, x.Value)).ToList(); - } - - private static Dictionary GetParameterDescriptions(IPropertySymbol[] parameters, - Dictionary? dics = null) - { - dics ??= new Dictionary(); - - foreach (var parameter in parameters) - { - var description = GetDescription(parameter); - if (string.IsNullOrWhiteSpace(description)) continue; - - if (dics.TryAdd(parameter.Name, description)) - { - if (parameter is IPropertySymbol namedTypeSymbol) - { - GetParameterDescriptions(namedTypeSymbol.Type.GetMembers().OfType().ToArray(), - dics); - } - } - } - - return dics; - } - private static OpenApiSchema ToParameterData(ITypeSymbol typeSymbol, string? name = null, string? description = null, bool isRequired = true) { diff --git a/src/libs/CSharpToJsonSchema.Generators/Models/MethodData.cs b/src/libs/CSharpToJsonSchema.Generators/Models/MethodData.cs index bdeb919..1cd7f74 100644 --- a/src/libs/CSharpToJsonSchema.Generators/Models/MethodData.cs +++ b/src/libs/CSharpToJsonSchema.Generators/Models/MethodData.cs @@ -9,7 +9,6 @@ public readonly record struct MethodData( bool IsVoid, bool IsStrict, IParameterSymbol[] Parameters, - Dictionary Descriptions, ITypeSymbol ReturnType); public readonly record struct PropertyMetadata(string Name, string Description, bool IsRequired); \ No newline at end of file diff --git a/src/libs/CSharpToJsonSchema.Generators/Sources.Tools.cs b/src/libs/CSharpToJsonSchema.Generators/Sources.Tools.cs index cf6b829..00f4c88 100644 --- a/src/libs/CSharpToJsonSchema.Generators/Sources.Tools.cs +++ b/src/libs/CSharpToJsonSchema.Generators/Sources.Tools.cs @@ -97,7 +97,7 @@ private static string GetDictionaryString(MethodData data) { StringBuilder sb = new StringBuilder(); - var methodDescriptions = data.Descriptions; + var methodDescriptions = new Dictionary(); methodDescriptions.Add("MainFunction_Desc", data.Description); sb.Append("{"); var lst = methodDescriptions.Select(s => $"\"{s.Key.ToCamelCase()}\":\"{s.Value}\""); diff --git a/src/libs/CSharpToJsonSchema/MeaiFunction.cs b/src/libs/CSharpToJsonSchema/MeaiFunction.cs index 39a8c85..b8bfe10 100644 --- a/src/libs/CSharpToJsonSchema/MeaiFunction.cs +++ b/src/libs/CSharpToJsonSchema/MeaiFunction.cs @@ -88,6 +88,8 @@ private string GetArgsString(IEnumerable> argument jsonObject[args.Key] = JsonArray.Create(element); else if (element.ValueKind == JsonValueKind.Object) jsonObject[args.Key] = JsonObject.Create(element); + else + jsonObject[args.Key] = JsonValue.Create(element); } else if (args.Value is JsonNode node) { diff --git a/src/libs/CSharpToJsonSchema/SchemaSubsetHelper.cs b/src/libs/CSharpToJsonSchema/SchemaSubsetHelper.cs index 62198a0..b4d2003 100644 --- a/src/libs/CSharpToJsonSchema/SchemaSubsetHelper.cs +++ b/src/libs/CSharpToJsonSchema/SchemaSubsetHelper.cs @@ -1,4 +1,6 @@ -using System.Text.Json.Nodes; +using System.ComponentModel; +using System.Reflection; +using System.Text.Json.Nodes; using System.Text.Json.Schema; using System.Text.Json.Serialization; using System.Text.Json.Serialization.Metadata; @@ -7,106 +9,7 @@ namespace CSharpToJsonSchema; public static class SchemaBuilder { - /// - /// Converts a JSON document that contains valid json schema as e.g. - /// generated by Microsoft.Extensions.AI.AIJsonUtilities.CreateJsonSchema or JsonSchema.Net's - /// to a subset that is compatible with LLM's APIs. - /// - /// Generated, valid json schema. - /// Subset of the given json schema in a LLM-compatible format. - public static OpenApiSchema ConvertToCompatibleSchemaSubset(JsonNode node) - { - ConvertNullableProperties(node); - var x1 = node; - var x2 = x1.ToJsonString(); - var schema = JsonSerializer.Deserialize(x2, OpenApiSchemaJsonContext.Default.OpenApiSchema); - return schema; - } - - private static void ConvertNullableProperties(JsonNode? node) - { - // If the node is an object, look for a "type" property or nested definitions - if (node is JsonObject obj) - { - // If "type" is an array, remove "null" and collapse if it leaves only one type - if (obj.TryGetPropertyValue("type", out var typeValue) && typeValue is JsonArray array) - { - if (array.Count == 2) - { - var notNullTypes = array.Where(x => x is not null && x.GetValue() != "null").ToList(); - if (notNullTypes.Count == 1) - { - obj["type"] = notNullTypes[0]!.GetValue(); - obj["nullable"] = true; - } - else - { - throw new InvalidOperationException( - $"LLM's API for strucutured output requires every property to have one defined type, not multiple options. Path: {obj.GetPath()} Schema: {obj.ToJsonString()}"); - } - } - else if (array.Count > 2) - { - throw new InvalidOperationException( - $"LLM's API for strucutured output requires every property to have one defined type, not multiple options. Path: {obj.GetPath()} Schema: {obj.ToJsonString()}"); - } - } - - // Recursively convert any nested schema in "properties" - if (obj.TryGetPropertyValue("properties", out var propertiesNode) && - propertiesNode is JsonObject propertiesObj) - { - foreach (var property in propertiesObj) - { - ConvertNullableProperties(property.Value); - } - } - - if (obj.TryGetPropertyValue("type", out var newTypeValue) - && newTypeValue is JsonNode - && newTypeValue.GetValueKind() == JsonValueKind.String - && "object".Equals(newTypeValue.GetValue(), StringComparison.OrdinalIgnoreCase) - && propertiesNode is not JsonObject) - { - throw new InvalidOperationException( - $"LLM's API for strucutured output requires every object to have predefined properties. Notably, it does not support dictionaries. Path: {obj.GetPath()} Schema: {obj.ToJsonString()}"); - } - - // Recursively convert any nested schema in "items" - if (obj.TryGetPropertyValue("items", out var itemsNode)) - { - ConvertNullableProperties(itemsNode); - } - } - - // If the node is an array, traverse each element - if (node is JsonArray arr) - { - foreach (var element in arr) - { - ConvertNullableProperties(element); - } - } - } - - public static OpenApiSchema ConvertToSchema(JsonSerializerOptions? jsonOptions = null) - { - if (jsonOptions == null && !JsonSerializer.IsReflectionEnabledByDefault) - { - throw new InvalidOperationException("Please provide a JsonSerializerOptions instance to use in AOT mode."); - } - - - var newJsonOptions = new JsonSerializerOptions(jsonOptions) - { - NumberHandling = JsonNumberHandling.Strict - }; - - var typeInfo = newJsonOptions.GetTypeInfo(typeof(T)); - - return ConvertToCompatibleSchemaSubset(typeInfo.GetJsonSchemaAsNode()); - } - + public static OpenApiSchema ConvertToSchema(JsonTypeInfo type, string descriptionString) { var typeInfo = type; @@ -114,44 +17,112 @@ public static OpenApiSchema ConvertToSchema(JsonTypeInfo type, string descriptio var dics = JsonSerializer.Deserialize(descriptionString, OpenApiSchemaJsonContext.Default.IDictionaryStringString); List required = new List(); - var x = ConvertToCompatibleSchemaSubset(typeInfo.GetJsonSchemaAsNode( + var x = typeInfo.GetJsonSchemaAsNode( exporterOptions: new JsonSchemaExporterOptions() { - TransformSchemaNode = (a, b) => + TransformSchemaNode = (context, schema) => { - if (a.TypeInfo.Type.IsEnum) + if (context.TypeInfo.Type.IsEnum) { - b["type"] = "string"; + schema["type"] = "string"; } - - if (a.PropertyInfo == null) - return b; - var propName = ToCamelCase(a.PropertyInfo.Name); - if (dics.ContainsKey(propName)) - { - b["description"] = dics[propName]; - } - - return b; + + ExtractDescription(context, schema, dics); + if (context.PropertyInfo == null) + return schema; + + return schema; }, - })); + }); + + var schema = JsonSerializer.Deserialize(x.ToJsonString(), OpenApiSchemaJsonContext.Default.OpenApiSchema); - - foreach (var re in x.Properties) + foreach (var re in schema.Properties) { required.Add(re.Key); } - var mainDescription = x.Description ?? (dics.TryGetValue("mainFunction_Desc", out var desc) ? desc : ""); + var mainDescription = schema.Description ?? (dics.TryGetValue("mainFunction_Desc", out var desc) ? desc : ""); return new OpenApiSchema() { Description = mainDescription, - Properties = x.Properties, + Properties = schema.Properties, Required = required, Type = "object" }; } + + private static void ExtractDescription(JsonSchemaExporterContext context, JsonNode schema, IDictionary dics) + { + // Determine if a type or property and extract the relevant attribute provider. + ICustomAttributeProvider? attributeProvider = context.PropertyInfo is not null + ? context.PropertyInfo.AttributeProvider + : context.TypeInfo.Type; + + // Look up any description attributes. + DescriptionAttribute? descriptionAttr = attributeProvider? + .GetCustomAttributes(inherit: true) + .Select(attr => attr as DescriptionAttribute) + .FirstOrDefault(attr => attr is not null); + + var description = descriptionAttr?.Description; + if (string.IsNullOrEmpty(description)) + { + if (context.PropertyInfo is null) + { + var propertyName = ToCamelCase(context.TypeInfo.Type.Name); + dics.TryGetValue(propertyName, out description); + } + } + FixType(schema); + + // Apply description attribute to the generated schema. + if (description is not null) + { + if (schema is not JsonObject jObj) + { + // Handle the case where the schema is a Boolean. + JsonValueKind valueKind = schema.GetValueKind(); + + schema = jObj = new JsonObject(); + if (valueKind is JsonValueKind.False) + { + jObj.Add("not", true); + } + } + + jObj.Insert(0, "description", description); + } + } + + private static void FixType(JsonNode schema) + { + // If "type" is an array, remove "null" and collapse if it leaves only one type + var typeValue = schema["type"]; + if (typeValue!= null && typeValue is JsonArray array) + { + if (array.Count == 2) + { + var notNullTypes = array.Where(x => x is not null && x.GetValue() != "null").ToList(); + if (notNullTypes.Count == 1) + { + schema["type"] = notNullTypes[0]!.GetValue(); + schema["nullable"] = true; + } + else + { + throw new InvalidOperationException( + $"LLM's API for strucutured output requires every property to have one defined type, not multiple options. Path: {schema.GetPath()} Schema: {schema.ToJsonString()}"); + } + } + else if (array.Count > 2) + { + throw new InvalidOperationException( + $"LLM's API for strucutured output requires every property to have one defined type, not multiple options. Path: {schema.GetPath()} Schema: {schema.ToJsonString()}"); + } + } + } public static string ToCamelCase(string str) { if (!string.IsNullOrEmpty(str) && str.Length > 1) @@ -161,12 +132,4 @@ public static string ToCamelCase(string str) return str.ToLowerInvariant(); } - - public static string ConvertToSchema(Type type, JsonSerializerOptions? jsonOptions) - { - var node = jsonOptions.GetJsonSchemaAsNode(type); - var x = ConvertToCompatibleSchemaSubset(node); - - return JsonSerializer.Serialize(x.Properties, OpenApiSchemaJsonContext.Default.IDictionaryStringOpenApiSchema); - } } \ No newline at end of file diff --git a/src/tests/AotConsole/Program.cs b/src/tests/AotConsole/Program.cs index 9f0f141..da5c350 100644 --- a/src/tests/AotConsole/Program.cs +++ b/src/tests/AotConsole/Program.cs @@ -9,7 +9,7 @@ if (string.IsNullOrWhiteSpace(key)) return; var prompt = "how does student john doe in senior grade is doing this year, enrollment start 01-01-2024 to 01-01-2025?"; - +//prompt = "what is written on page 96 in the book 'damdamadum'"; var client = new OpenAIClient(new ApiKeyCredential(key)); Microsoft.Extensions.AI.OpenAIChatClient openAiClient = new OpenAIChatClient(client.GetChatClient("gpt-4o-mini")); diff --git a/src/tests/CSharpToJsonSchema.AotTests/JsonSerializationTests.cs b/src/tests/CSharpToJsonSchema.AotTests/JsonSerializationTests.cs index c0bd0e9..9991eaa 100644 --- a/src/tests/CSharpToJsonSchema.AotTests/JsonSerializationTests.cs +++ b/src/tests/CSharpToJsonSchema.AotTests/JsonSerializationTests.cs @@ -127,6 +127,35 @@ public void ShouldCreateToolWithComplexStudentClass() { var service = new StudenRecordService(); var tools = service.AsTools(); + + Tool tool = tools[0]; + + + var openApiSchema = (OpenApiSchema)tool.Parameters; + tool.Description.Should().Be("Get student record for the year"); + tool.Name.Should().Be("GetStudentRecordAsync"); + openApiSchema.Properties["query"].Should().NotBeNull(); + + openApiSchema.Properties["query"].Properties["fullName"].Type.Should().Be("string"); + openApiSchema.Properties["query"].Properties["fullName"].Description.Should().Be("The student's full name."); + + openApiSchema.Properties["query"].Properties["gradeFilters"].Type.Should().Be("array"); + openApiSchema.Properties["query"].Properties["gradeFilters"].Items.Type.Should().Be("string"); + openApiSchema.Properties["query"].Properties["gradeFilters"].Description.Should() + .Be("Grade filters for querying specific grades, e.g., Freshman or Senior."); + + openApiSchema.Properties["query"].Properties["enrollmentStartDate"].Type.Should().Be("string"); + openApiSchema.Properties["query"].Properties["enrollmentStartDate"].Format.Should().Be("date-time"); + openApiSchema.Properties["query"].Properties["enrollmentStartDate"].Description.Should() + .Be("The start date for the enrollment date range. ISO 8601 standard date"); + + openApiSchema.Properties["query"].Properties["enrollmentEndDate"].Type.Should().Be("string"); + openApiSchema.Properties["query"].Properties["enrollmentEndDate"].Format.Should().Be("date-time"); + openApiSchema.Properties["query"].Properties["enrollmentEndDate"].Description.Should() + .Be("The end date for the enrollment date range. ISO 8601 standard date"); + + openApiSchema.Properties["query"].Properties["isActive"].Type.Should().Be("boolean"); + openApiSchema.Properties["query"].Properties["isActive"].Description.Should() + .Be("The flag indicating whether to include only active students."); } - } \ No newline at end of file diff --git a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.Boolean.g.verified.cs b/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.Boolean.g.verified.cs deleted file mode 100644 index c12002c..0000000 --- a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.Boolean.g.verified.cs +++ /dev/null @@ -1,37 +0,0 @@ -//HintName: IVariousTypesTools.Boolean.g.cs -// - -#nullable enable annotations -#nullable disable warnings - -// Suppress warnings about [Obsolete] member usage in generated code. -#pragma warning disable CS0612, CS0618 - -namespace CSharpToJsonSchema.IntegrationTests -{ - public partial class VariousTypesToolsExtensionsJsonSerializerContext - { - private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo? _Boolean; - - /// - /// Defines the source generated JSON serialization contract metadata for a given type. - /// - #nullable disable annotations // Marking the property type as nullable-oblivious. - public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo Boolean - #nullable enable annotations - { - get => _Boolean ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo)Options.GetTypeInfo(typeof(bool)); - } - - private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo Create_Boolean(global::System.Text.Json.JsonSerializerOptions options) - { - if (!TryGetTypeInfoForRuntimeCustomConverter(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo)) - { - jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateValueInfo(options, global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.BooleanConverter); - } - - jsonTypeInfo.OriginatingResolver = this; - return jsonTypeInfo; - } - } -} diff --git a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.Calls.generated.verified.cs b/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.Calls.generated.verified.cs deleted file mode 100644 index 8fc213e..0000000 --- a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.Calls.generated.verified.cs +++ /dev/null @@ -1,383 +0,0 @@ -//HintName: IVariousTypesTools.Calls.generated.cs -#nullable enable - -namespace CSharpToJsonSchema.IntegrationTests -{ - public class GetCurrentWeather3Args - { - - [global::System.ComponentModel.Description("")] - public long Parameter1 { get; set; } - [global::System.ComponentModel.Description("")] - public int Parameter2 { get; set; } - [global::System.ComponentModel.Description("")] - public double Parameter3 { get; set; } - [global::System.ComponentModel.Description("")] - public float Parameter4 { get; set; } - [global::System.ComponentModel.Description("")] - public bool Parameter5 { get; set; } - [global::System.ComponentModel.Description("")] - public System.DateTime DateTime { get; set; } - [global::System.ComponentModel.Description("")] - public System.DateOnly Date { get; set; } - } - - public class SetValueArgs - { - - [global::System.ComponentModel.Description("")] - public int Value { get; set; } - } - - public class GetValueArgs - { - - - } - - public class SetValueAsyncArgs - { - - [global::System.ComponentModel.Description("")] - public int Value { get; set; } - } - - public class GetValueAsyncArgs - { - - - } - - public static partial class VariousTypesToolsExtensions - { - public static global::System.Collections.Generic.IReadOnlyDictionary>> AsCalls(this IVariousTypesTools service) - { - return new global::System.Collections.Generic.Dictionary>> - { - ["GetCurrentWeather3"] = (json, _) => - { - return global::System.Threading.Tasks.Task.FromResult(service.CallGetCurrentWeather3(json)); - }, - - ["GetValue"] = (json, _) => - { - return global::System.Threading.Tasks.Task.FromResult(service.CallGetValue(json)); - }, - ["SetValue"] = (json, _) => - { - service.CallSetValue(json); - - return global::System.Threading.Tasks.Task.FromResult(string.Empty); - }, - ["GetValueAsync"] = async (json, cancellationToken) => - { - return await service.CallGetValueAsync(json, cancellationToken); - }, - ["SetValueAsync"] = async (json, cancellationToken) => - { - await service.CallSetValueAsync(json, cancellationToken); - - return string.Empty; - }, - }; - } - - #pragma warning disable IL2026, IL3050 - public static GetCurrentWeather3Args AsGetCurrentWeather3Args( - this IVariousTypesTools functions, - string json) - { - #if NET6_0_OR_GREATER - if(global::System.Text.Json.JsonSerializer.IsReflectionEnabledByDefault) - { - - return global::System.Text.Json.JsonSerializer.Deserialize(json, new global::System.Text.Json.JsonSerializerOptions - { - PropertyNamingPolicy = global::System.Text.Json.JsonNamingPolicy.CamelCase, - Converters = {{ new global::System.Text.Json.Serialization.JsonStringEnumConverter(global::System.Text.Json.JsonNamingPolicy.CamelCase) }} - }) ?? - throw new global::System.InvalidOperationException("Could not deserialize JSON."); - - } - else - { - return global::System.Text.Json.JsonSerializer.Deserialize(json, global::CSharpToJsonSchema.IntegrationTests.VariousTypesToolsExtensionsJsonSerializerContext.Default.GetCurrentWeather3Args) ?? - throw new global::System.InvalidOperationException("Could not deserialize JSON."); - } - #else - return - global::System.Text.Json.JsonSerializer.Deserialize(json, new global::System.Text.Json.JsonSerializerOptions - { - PropertyNamingPolicy = global::System.Text.Json.JsonNamingPolicy.CamelCase, - Converters = {{ new global::System.Text.Json.Serialization.JsonStringEnumConverter(global::System.Text.Json.JsonNamingPolicy.CamelCase) }} - }) ?? - throw new global::System.InvalidOperationException("Could not deserialize JSON."); - #endif - } - #pragma warning restore IL2026, IL3050 - - #pragma warning disable IL2026, IL3050 - public static SetValueArgs AsSetValueArgs( - this IVariousTypesTools functions, - string json) - { - #if NET6_0_OR_GREATER - if(global::System.Text.Json.JsonSerializer.IsReflectionEnabledByDefault) - { - - return global::System.Text.Json.JsonSerializer.Deserialize(json, new global::System.Text.Json.JsonSerializerOptions - { - PropertyNamingPolicy = global::System.Text.Json.JsonNamingPolicy.CamelCase, - Converters = {{ new global::System.Text.Json.Serialization.JsonStringEnumConverter(global::System.Text.Json.JsonNamingPolicy.CamelCase) }} - }) ?? - throw new global::System.InvalidOperationException("Could not deserialize JSON."); - - } - else - { - return global::System.Text.Json.JsonSerializer.Deserialize(json, global::CSharpToJsonSchema.IntegrationTests.VariousTypesToolsExtensionsJsonSerializerContext.Default.SetValueArgs) ?? - throw new global::System.InvalidOperationException("Could not deserialize JSON."); - } - #else - return - global::System.Text.Json.JsonSerializer.Deserialize(json, new global::System.Text.Json.JsonSerializerOptions - { - PropertyNamingPolicy = global::System.Text.Json.JsonNamingPolicy.CamelCase, - Converters = {{ new global::System.Text.Json.Serialization.JsonStringEnumConverter(global::System.Text.Json.JsonNamingPolicy.CamelCase) }} - }) ?? - throw new global::System.InvalidOperationException("Could not deserialize JSON."); - #endif - } - #pragma warning restore IL2026, IL3050 - - #pragma warning disable IL2026, IL3050 - public static GetValueArgs AsGetValueArgs( - this IVariousTypesTools functions, - string json) - { - #if NET6_0_OR_GREATER - if(global::System.Text.Json.JsonSerializer.IsReflectionEnabledByDefault) - { - - return global::System.Text.Json.JsonSerializer.Deserialize(json, new global::System.Text.Json.JsonSerializerOptions - { - PropertyNamingPolicy = global::System.Text.Json.JsonNamingPolicy.CamelCase, - Converters = {{ new global::System.Text.Json.Serialization.JsonStringEnumConverter(global::System.Text.Json.JsonNamingPolicy.CamelCase) }} - }) ?? - throw new global::System.InvalidOperationException("Could not deserialize JSON."); - - } - else - { - return global::System.Text.Json.JsonSerializer.Deserialize(json, global::CSharpToJsonSchema.IntegrationTests.VariousTypesToolsExtensionsJsonSerializerContext.Default.GetValueArgs) ?? - throw new global::System.InvalidOperationException("Could not deserialize JSON."); - } - #else - return - global::System.Text.Json.JsonSerializer.Deserialize(json, new global::System.Text.Json.JsonSerializerOptions - { - PropertyNamingPolicy = global::System.Text.Json.JsonNamingPolicy.CamelCase, - Converters = {{ new global::System.Text.Json.Serialization.JsonStringEnumConverter(global::System.Text.Json.JsonNamingPolicy.CamelCase) }} - }) ?? - throw new global::System.InvalidOperationException("Could not deserialize JSON."); - #endif - } - #pragma warning restore IL2026, IL3050 - - #pragma warning disable IL2026, IL3050 - public static SetValueAsyncArgs AsSetValueAsyncArgs( - this IVariousTypesTools functions, - string json) - { - #if NET6_0_OR_GREATER - if(global::System.Text.Json.JsonSerializer.IsReflectionEnabledByDefault) - { - - return global::System.Text.Json.JsonSerializer.Deserialize(json, new global::System.Text.Json.JsonSerializerOptions - { - PropertyNamingPolicy = global::System.Text.Json.JsonNamingPolicy.CamelCase, - Converters = {{ new global::System.Text.Json.Serialization.JsonStringEnumConverter(global::System.Text.Json.JsonNamingPolicy.CamelCase) }} - }) ?? - throw new global::System.InvalidOperationException("Could not deserialize JSON."); - - } - else - { - return global::System.Text.Json.JsonSerializer.Deserialize(json, global::CSharpToJsonSchema.IntegrationTests.VariousTypesToolsExtensionsJsonSerializerContext.Default.SetValueAsyncArgs) ?? - throw new global::System.InvalidOperationException("Could not deserialize JSON."); - } - #else - return - global::System.Text.Json.JsonSerializer.Deserialize(json, new global::System.Text.Json.JsonSerializerOptions - { - PropertyNamingPolicy = global::System.Text.Json.JsonNamingPolicy.CamelCase, - Converters = {{ new global::System.Text.Json.Serialization.JsonStringEnumConverter(global::System.Text.Json.JsonNamingPolicy.CamelCase) }} - }) ?? - throw new global::System.InvalidOperationException("Could not deserialize JSON."); - #endif - } - #pragma warning restore IL2026, IL3050 - - #pragma warning disable IL2026, IL3050 - public static GetValueAsyncArgs AsGetValueAsyncArgs( - this IVariousTypesTools functions, - string json) - { - #if NET6_0_OR_GREATER - if(global::System.Text.Json.JsonSerializer.IsReflectionEnabledByDefault) - { - - return global::System.Text.Json.JsonSerializer.Deserialize(json, new global::System.Text.Json.JsonSerializerOptions - { - PropertyNamingPolicy = global::System.Text.Json.JsonNamingPolicy.CamelCase, - Converters = {{ new global::System.Text.Json.Serialization.JsonStringEnumConverter(global::System.Text.Json.JsonNamingPolicy.CamelCase) }} - }) ?? - throw new global::System.InvalidOperationException("Could not deserialize JSON."); - - } - else - { - return global::System.Text.Json.JsonSerializer.Deserialize(json, global::CSharpToJsonSchema.IntegrationTests.VariousTypesToolsExtensionsJsonSerializerContext.Default.GetValueAsyncArgs) ?? - throw new global::System.InvalidOperationException("Could not deserialize JSON."); - } - #else - return - global::System.Text.Json.JsonSerializer.Deserialize(json, new global::System.Text.Json.JsonSerializerOptions - { - PropertyNamingPolicy = global::System.Text.Json.JsonNamingPolicy.CamelCase, - Converters = {{ new global::System.Text.Json.Serialization.JsonStringEnumConverter(global::System.Text.Json.JsonNamingPolicy.CamelCase) }} - }) ?? - throw new global::System.InvalidOperationException("Could not deserialize JSON."); - #endif - } - #pragma warning restore IL2026, IL3050 - - #pragma warning disable IL2026, IL3050 - public static string CallGetCurrentWeather3(this IVariousTypesTools functions, string json) - { - var args = functions.AsGetCurrentWeather3Args(json); - var jsonResult = functions.GetCurrentWeather3(args.Parameter1, args.Parameter2, args.Parameter3, args.Parameter4, args.Parameter5, args.DateTime, args.Date); - - #if NET6_0_OR_GREATER - if(global::System.Text.Json.JsonSerializer.IsReflectionEnabledByDefault) - { - - return global::System.Text.Json.JsonSerializer.Serialize(jsonResult, new global::System.Text.Json.JsonSerializerOptions - { - PropertyNamingPolicy = global::System.Text.Json.JsonNamingPolicy.CamelCase, - Converters = { new global::System.Text.Json.Serialization.JsonStringEnumConverter(global::System.Text.Json.JsonNamingPolicy.CamelCase) }, - }); - - } - else - { - return global::System.Text.Json.JsonSerializer.Serialize(jsonResult, global::CSharpToJsonSchema.IntegrationTests.VariousTypesToolsExtensionsJsonSerializerContext.Default.GetTypeInfo(jsonResult.GetType())); - } - #else - return global::System.Text.Json.JsonSerializer.Serialize(jsonResult, new global::System.Text.Json.JsonSerializerOptions - { - PropertyNamingPolicy = global::System.Text.Json.JsonNamingPolicy.CamelCase, - Converters = { new global::System.Text.Json.Serialization.JsonStringEnumConverter(global::System.Text.Json.JsonNamingPolicy.CamelCase) }, - }); - #endif - } - #pragma warning restore IL2026, IL3050 - - #pragma warning disable IL2026, IL3050 - public static string CallGetValue(this IVariousTypesTools functions, string json) - { - var args = functions.AsGetValueArgs(json); - var jsonResult = functions.GetValue(); - - #if NET6_0_OR_GREATER - if(global::System.Text.Json.JsonSerializer.IsReflectionEnabledByDefault) - { - - return global::System.Text.Json.JsonSerializer.Serialize(jsonResult, new global::System.Text.Json.JsonSerializerOptions - { - PropertyNamingPolicy = global::System.Text.Json.JsonNamingPolicy.CamelCase, - Converters = { new global::System.Text.Json.Serialization.JsonStringEnumConverter(global::System.Text.Json.JsonNamingPolicy.CamelCase) }, - }); - - } - else - { - return global::System.Text.Json.JsonSerializer.Serialize(jsonResult, global::CSharpToJsonSchema.IntegrationTests.VariousTypesToolsExtensionsJsonSerializerContext.Default.GetTypeInfo(jsonResult.GetType())); - } - #else - return global::System.Text.Json.JsonSerializer.Serialize(jsonResult, new global::System.Text.Json.JsonSerializerOptions - { - PropertyNamingPolicy = global::System.Text.Json.JsonNamingPolicy.CamelCase, - Converters = { new global::System.Text.Json.Serialization.JsonStringEnumConverter(global::System.Text.Json.JsonNamingPolicy.CamelCase) }, - }); - #endif - } - #pragma warning restore IL2026, IL3050 - public static void CallSetValue(this IVariousTypesTools functions, string json) - { - var args = functions.AsSetValueArgs(json); - functions.SetValue(args.Value); - } - - #pragma warning disable IL2026, IL3050 - public static async global::System.Threading.Tasks.Task CallGetValueAsync( - this IVariousTypesTools functions, - string json, - global::System.Threading.CancellationToken cancellationToken = default) - { - var args = functions.AsGetValueAsyncArgs(json); - var jsonResult = await functions.GetValueAsync(cancellationToken); - - #if NET6_0_OR_GREATER - if(global::System.Text.Json.JsonSerializer.IsReflectionEnabledByDefault) - { - - return global::System.Text.Json.JsonSerializer.Serialize(jsonResult, new global::System.Text.Json.JsonSerializerOptions - { - PropertyNamingPolicy = global::System.Text.Json.JsonNamingPolicy.CamelCase, - Converters = { new global::System.Text.Json.Serialization.JsonStringEnumConverter(global::System.Text.Json.JsonNamingPolicy.CamelCase) }, - }); - } - else - { - return global::System.Text.Json.JsonSerializer.Serialize(jsonResult, global::CSharpToJsonSchema.IntegrationTests.VariousTypesToolsExtensionsJsonSerializerContext.Default.GetTypeInfo(jsonResult.GetType())); - } - #else - return global::System.Text.Json.JsonSerializer.Serialize(jsonResult, new global::System.Text.Json.JsonSerializerOptions - { - PropertyNamingPolicy = global::System.Text.Json.JsonNamingPolicy.CamelCase, - Converters = { new global::System.Text.Json.Serialization.JsonStringEnumConverter(global::System.Text.Json.JsonNamingPolicy.CamelCase) }, - }); - #endif - - } - #pragma warning restore IL2026, IL3050 - - public static async global::System.Threading.Tasks.Task CallSetValueAsync( - this IVariousTypesTools functions, - string json, - global::System.Threading.CancellationToken cancellationToken = default) - { - var args = functions.AsSetValueAsyncArgs(json); - await functions.SetValueAsync(args.Value, cancellationToken); - - return string.Empty; - } - - public static async global::System.Threading.Tasks.Task CallAsync( - this IVariousTypesTools service, - string functionName, - string argumentsAsJson, - global::System.Threading.CancellationToken cancellationToken = default) - { - var calls = service.AsCalls(); - var func = calls[functionName]; - - return await func(argumentsAsJson, cancellationToken); - } - } - - public partial class VariousTypesToolsExtensionsJsonSerializerContext: global::System.Text.Json.Serialization.JsonSerializerContext - { - } -} \ No newline at end of file diff --git a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.DateOnly.g.verified.cs b/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.DateOnly.g.verified.cs deleted file mode 100644 index b10c67b..0000000 --- a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.DateOnly.g.verified.cs +++ /dev/null @@ -1,37 +0,0 @@ -//HintName: IVariousTypesTools.DateOnly.g.cs -// - -#nullable enable annotations -#nullable disable warnings - -// Suppress warnings about [Obsolete] member usage in generated code. -#pragma warning disable CS0612, CS0618 - -namespace CSharpToJsonSchema.IntegrationTests -{ - public partial class VariousTypesToolsExtensionsJsonSerializerContext - { - private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo? _DateOnly; - - /// - /// Defines the source generated JSON serialization contract metadata for a given type. - /// - #nullable disable annotations // Marking the property type as nullable-oblivious. - public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo DateOnly - #nullable enable annotations - { - get => _DateOnly ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo)Options.GetTypeInfo(typeof(global::System.DateOnly)); - } - - private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo Create_DateOnly(global::System.Text.Json.JsonSerializerOptions options) - { - if (!TryGetTypeInfoForRuntimeCustomConverter(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo)) - { - jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateValueInfo(options, global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.DateOnlyConverter); - } - - jsonTypeInfo.OriginatingResolver = this; - return jsonTypeInfo; - } - } -} diff --git a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.DateTime.g.verified.cs b/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.DateTime.g.verified.cs deleted file mode 100644 index 23a8cf3..0000000 --- a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.DateTime.g.verified.cs +++ /dev/null @@ -1,37 +0,0 @@ -//HintName: IVariousTypesTools.DateTime.g.cs -// - -#nullable enable annotations -#nullable disable warnings - -// Suppress warnings about [Obsolete] member usage in generated code. -#pragma warning disable CS0612, CS0618 - -namespace CSharpToJsonSchema.IntegrationTests -{ - public partial class VariousTypesToolsExtensionsJsonSerializerContext - { - private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo? _DateTime; - - /// - /// Defines the source generated JSON serialization contract metadata for a given type. - /// - #nullable disable annotations // Marking the property type as nullable-oblivious. - public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo DateTime - #nullable enable annotations - { - get => _DateTime ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo)Options.GetTypeInfo(typeof(global::System.DateTime)); - } - - private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo Create_DateTime(global::System.Text.Json.JsonSerializerOptions options) - { - if (!TryGetTypeInfoForRuntimeCustomConverter(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo)) - { - jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateValueInfo(options, global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.DateTimeConverter); - } - - jsonTypeInfo.OriginatingResolver = this; - return jsonTypeInfo; - } - } -} diff --git a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.Double.g.verified.cs b/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.Double.g.verified.cs deleted file mode 100644 index 0e044a3..0000000 --- a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.Double.g.verified.cs +++ /dev/null @@ -1,37 +0,0 @@ -//HintName: IVariousTypesTools.Double.g.cs -// - -#nullable enable annotations -#nullable disable warnings - -// Suppress warnings about [Obsolete] member usage in generated code. -#pragma warning disable CS0612, CS0618 - -namespace CSharpToJsonSchema.IntegrationTests -{ - public partial class VariousTypesToolsExtensionsJsonSerializerContext - { - private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo? _Double; - - /// - /// Defines the source generated JSON serialization contract metadata for a given type. - /// - #nullable disable annotations // Marking the property type as nullable-oblivious. - public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo Double - #nullable enable annotations - { - get => _Double ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo)Options.GetTypeInfo(typeof(double)); - } - - private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo Create_Double(global::System.Text.Json.JsonSerializerOptions options) - { - if (!TryGetTypeInfoForRuntimeCustomConverter(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo)) - { - jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateValueInfo(options, global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.DoubleConverter); - } - - jsonTypeInfo.OriginatingResolver = this; - return jsonTypeInfo; - } - } -} diff --git a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.GetCurrentWeather3Args.g.verified.cs b/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.GetCurrentWeather3Args.g.verified.cs deleted file mode 100644 index 0bf5111..0000000 --- a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.GetCurrentWeather3Args.g.verified.cs +++ /dev/null @@ -1,219 +0,0 @@ -//HintName: IVariousTypesTools.GetCurrentWeather3Args.g.cs -// - -#nullable enable annotations -#nullable disable warnings - -// Suppress warnings about [Obsolete] member usage in generated code. -#pragma warning disable CS0612, CS0618 - -namespace CSharpToJsonSchema.IntegrationTests -{ - public partial class VariousTypesToolsExtensionsJsonSerializerContext - { - private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo? _GetCurrentWeather3Args; - - /// - /// Defines the source generated JSON serialization contract metadata for a given type. - /// - #nullable disable annotations // Marking the property type as nullable-oblivious. - public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo GetCurrentWeather3Args - #nullable enable annotations - { - get => _GetCurrentWeather3Args ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo)Options.GetTypeInfo(typeof(global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeather3Args)); - } - - private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo Create_GetCurrentWeather3Args(global::System.Text.Json.JsonSerializerOptions options) - { - if (!TryGetTypeInfoForRuntimeCustomConverter(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo)) - { - var objectInfo = new global::System.Text.Json.Serialization.Metadata.JsonObjectInfoValues - { - ObjectCreator = () => new global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeather3Args(), - ObjectWithParameterizedConstructorCreator = null, - PropertyMetadataInitializer = _ => GetCurrentWeather3ArgsPropInit(options), - ConstructorParameterMetadataInitializer = null, - ConstructorAttributeProviderFactory = static () => typeof(global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeather3Args).GetConstructor(InstanceMemberBindingFlags, binder: null, global::System.Array.Empty(), modifiers: null), - SerializeHandler = GetCurrentWeather3ArgsSerializeHandler, - }; - - jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateObjectInfo(options, objectInfo); - jsonTypeInfo.NumberHandling = null; - } - - jsonTypeInfo.OriginatingResolver = this; - return jsonTypeInfo; - } - - private static global::System.Text.Json.Serialization.Metadata.JsonPropertyInfo[] GetCurrentWeather3ArgsPropInit(global::System.Text.Json.JsonSerializerOptions options) - { - var properties = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfo[7]; - - var info0 = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfoValues - { - IsProperty = true, - IsPublic = true, - IsVirtual = false, - DeclaringType = typeof(global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeather3Args), - Converter = null, - Getter = static obj => ((global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeather3Args)obj).Parameter1, - Setter = static (obj, value) => ((global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeather3Args)obj).Parameter1 = value!, - IgnoreCondition = null, - HasJsonInclude = false, - IsExtensionData = false, - NumberHandling = null, - PropertyName = "Parameter1", - JsonPropertyName = null, - AttributeProviderFactory = static () => typeof(global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeather3Args).GetProperty("Parameter1", InstanceMemberBindingFlags, null, typeof(long), global::System.Array.Empty(), null), - }; - - properties[0] = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreatePropertyInfo(options, info0); - - var info1 = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfoValues - { - IsProperty = true, - IsPublic = true, - IsVirtual = false, - DeclaringType = typeof(global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeather3Args), - Converter = null, - Getter = static obj => ((global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeather3Args)obj).Parameter2, - Setter = static (obj, value) => ((global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeather3Args)obj).Parameter2 = value!, - IgnoreCondition = null, - HasJsonInclude = false, - IsExtensionData = false, - NumberHandling = null, - PropertyName = "Parameter2", - JsonPropertyName = null, - AttributeProviderFactory = static () => typeof(global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeather3Args).GetProperty("Parameter2", InstanceMemberBindingFlags, null, typeof(int), global::System.Array.Empty(), null), - }; - - properties[1] = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreatePropertyInfo(options, info1); - - var info2 = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfoValues - { - IsProperty = true, - IsPublic = true, - IsVirtual = false, - DeclaringType = typeof(global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeather3Args), - Converter = null, - Getter = static obj => ((global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeather3Args)obj).Parameter3, - Setter = static (obj, value) => ((global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeather3Args)obj).Parameter3 = value!, - IgnoreCondition = null, - HasJsonInclude = false, - IsExtensionData = false, - NumberHandling = null, - PropertyName = "Parameter3", - JsonPropertyName = null, - AttributeProviderFactory = static () => typeof(global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeather3Args).GetProperty("Parameter3", InstanceMemberBindingFlags, null, typeof(double), global::System.Array.Empty(), null), - }; - - properties[2] = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreatePropertyInfo(options, info2); - - var info3 = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfoValues - { - IsProperty = true, - IsPublic = true, - IsVirtual = false, - DeclaringType = typeof(global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeather3Args), - Converter = null, - Getter = static obj => ((global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeather3Args)obj).Parameter4, - Setter = static (obj, value) => ((global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeather3Args)obj).Parameter4 = value!, - IgnoreCondition = null, - HasJsonInclude = false, - IsExtensionData = false, - NumberHandling = null, - PropertyName = "Parameter4", - JsonPropertyName = null, - AttributeProviderFactory = static () => typeof(global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeather3Args).GetProperty("Parameter4", InstanceMemberBindingFlags, null, typeof(float), global::System.Array.Empty(), null), - }; - - properties[3] = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreatePropertyInfo(options, info3); - - var info4 = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfoValues - { - IsProperty = true, - IsPublic = true, - IsVirtual = false, - DeclaringType = typeof(global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeather3Args), - Converter = null, - Getter = static obj => ((global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeather3Args)obj).Parameter5, - Setter = static (obj, value) => ((global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeather3Args)obj).Parameter5 = value!, - IgnoreCondition = null, - HasJsonInclude = false, - IsExtensionData = false, - NumberHandling = null, - PropertyName = "Parameter5", - JsonPropertyName = null, - AttributeProviderFactory = static () => typeof(global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeather3Args).GetProperty("Parameter5", InstanceMemberBindingFlags, null, typeof(bool), global::System.Array.Empty(), null), - }; - - properties[4] = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreatePropertyInfo(options, info4); - - var info5 = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfoValues - { - IsProperty = true, - IsPublic = true, - IsVirtual = false, - DeclaringType = typeof(global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeather3Args), - Converter = null, - Getter = static obj => ((global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeather3Args)obj).DateTime, - Setter = static (obj, value) => ((global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeather3Args)obj).DateTime = value!, - IgnoreCondition = null, - HasJsonInclude = false, - IsExtensionData = false, - NumberHandling = null, - PropertyName = "DateTime", - JsonPropertyName = null, - AttributeProviderFactory = static () => typeof(global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeather3Args).GetProperty("DateTime", InstanceMemberBindingFlags, null, typeof(global::System.DateTime), global::System.Array.Empty(), null), - }; - - properties[5] = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreatePropertyInfo(options, info5); - - var info6 = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfoValues - { - IsProperty = true, - IsPublic = true, - IsVirtual = false, - DeclaringType = typeof(global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeather3Args), - Converter = null, - Getter = static obj => ((global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeather3Args)obj).Date, - Setter = static (obj, value) => ((global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeather3Args)obj).Date = value!, - IgnoreCondition = null, - HasJsonInclude = false, - IsExtensionData = false, - NumberHandling = null, - PropertyName = "Date", - JsonPropertyName = null, - AttributeProviderFactory = static () => typeof(global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeather3Args).GetProperty("Date", InstanceMemberBindingFlags, null, typeof(global::System.DateOnly), global::System.Array.Empty(), null), - }; - - properties[6] = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreatePropertyInfo(options, info6); - - return properties; - } - - // Intentionally not a static method because we create a delegate to it. Invoking delegates to instance - // methods is almost as fast as virtual calls. Static methods need to go through a shuffle thunk. - private void GetCurrentWeather3ArgsSerializeHandler(global::System.Text.Json.Utf8JsonWriter writer, global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeather3Args? value) - { - if (value is null) - { - writer.WriteNullValue(); - return; - } - - writer.WriteStartObject(); - - writer.WriteNumber(PropName_parameter1, ((global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeather3Args)value).Parameter1); - writer.WriteNumber(PropName_parameter2, ((global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeather3Args)value).Parameter2); - writer.WriteNumber(PropName_parameter3, ((global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeather3Args)value).Parameter3); - writer.WriteNumber(PropName_parameter4, ((global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeather3Args)value).Parameter4); - writer.WriteBoolean(PropName_parameter5, ((global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeather3Args)value).Parameter5); - writer.WriteString(PropName_dateTime, ((global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeather3Args)value).DateTime); - writer.WritePropertyName(PropName_date); - global::System.Text.Json.JsonSerializer.Serialize(writer, ((global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeather3Args)value).Date, DateOnly); - - writer.WriteEndObject(); - } - } -} diff --git a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.GetJsonTypeInfo.g.verified.cs b/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.GetJsonTypeInfo.g.verified.cs deleted file mode 100644 index 1edd614..0000000 --- a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.GetJsonTypeInfo.g.verified.cs +++ /dev/null @@ -1,74 +0,0 @@ -//HintName: IVariousTypesTools.GetJsonTypeInfo.g.cs -// - -#nullable enable annotations -#nullable disable warnings - -// Suppress warnings about [Obsolete] member usage in generated code. -#pragma warning disable CS0612, CS0618 - -namespace CSharpToJsonSchema.IntegrationTests -{ - public partial class VariousTypesToolsExtensionsJsonSerializerContext : global::System.Text.Json.Serialization.Metadata.IJsonTypeInfoResolver - { - /// - public override global::System.Text.Json.Serialization.Metadata.JsonTypeInfo? GetTypeInfo(global::System.Type type) - { - Options.TryGetTypeInfo(type, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo? typeInfo); - return typeInfo; - } - - global::System.Text.Json.Serialization.Metadata.JsonTypeInfo? global::System.Text.Json.Serialization.Metadata.IJsonTypeInfoResolver.GetTypeInfo(global::System.Type type, global::System.Text.Json.JsonSerializerOptions options) - { - if (type == typeof(bool)) - { - return Create_Boolean(options); - } - if (type == typeof(double)) - { - return Create_Double(options); - } - if (type == typeof(float)) - { - return Create_Single(options); - } - if (type == typeof(global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeather3Args)) - { - return Create_GetCurrentWeather3Args(options); - } - if (type == typeof(global::CSharpToJsonSchema.IntegrationTests.GetValueArgs)) - { - return Create_GetValueArgs(options); - } - if (type == typeof(global::CSharpToJsonSchema.IntegrationTests.GetValueAsyncArgs)) - { - return Create_GetValueAsyncArgs(options); - } - if (type == typeof(global::CSharpToJsonSchema.IntegrationTests.SetValueArgs)) - { - return Create_SetValueArgs(options); - } - if (type == typeof(global::CSharpToJsonSchema.IntegrationTests.SetValueAsyncArgs)) - { - return Create_SetValueAsyncArgs(options); - } - if (type == typeof(global::System.DateOnly)) - { - return Create_DateOnly(options); - } - if (type == typeof(global::System.DateTime)) - { - return Create_DateTime(options); - } - if (type == typeof(int)) - { - return Create_Int32(options); - } - if (type == typeof(long)) - { - return Create_Int64(options); - } - return null; - } - } -} diff --git a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.GetValueArgs.g.verified.cs b/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.GetValueArgs.g.verified.cs deleted file mode 100644 index 32bb28a..0000000 --- a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.GetValueArgs.g.verified.cs +++ /dev/null @@ -1,71 +0,0 @@ -//HintName: IVariousTypesTools.GetValueArgs.g.cs -// - -#nullable enable annotations -#nullable disable warnings - -// Suppress warnings about [Obsolete] member usage in generated code. -#pragma warning disable CS0612, CS0618 - -namespace CSharpToJsonSchema.IntegrationTests -{ - public partial class VariousTypesToolsExtensionsJsonSerializerContext - { - private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo? _GetValueArgs; - - /// - /// Defines the source generated JSON serialization contract metadata for a given type. - /// - #nullable disable annotations // Marking the property type as nullable-oblivious. - public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo GetValueArgs - #nullable enable annotations - { - get => _GetValueArgs ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo)Options.GetTypeInfo(typeof(global::CSharpToJsonSchema.IntegrationTests.GetValueArgs)); - } - - private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo Create_GetValueArgs(global::System.Text.Json.JsonSerializerOptions options) - { - if (!TryGetTypeInfoForRuntimeCustomConverter(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo)) - { - var objectInfo = new global::System.Text.Json.Serialization.Metadata.JsonObjectInfoValues - { - ObjectCreator = () => new global::CSharpToJsonSchema.IntegrationTests.GetValueArgs(), - ObjectWithParameterizedConstructorCreator = null, - PropertyMetadataInitializer = _ => GetValueArgsPropInit(options), - ConstructorParameterMetadataInitializer = null, - ConstructorAttributeProviderFactory = static () => typeof(global::CSharpToJsonSchema.IntegrationTests.GetValueArgs).GetConstructor(InstanceMemberBindingFlags, binder: null, global::System.Array.Empty(), modifiers: null), - SerializeHandler = GetValueArgsSerializeHandler, - }; - - jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateObjectInfo(options, objectInfo); - jsonTypeInfo.NumberHandling = null; - } - - jsonTypeInfo.OriginatingResolver = this; - return jsonTypeInfo; - } - - private static global::System.Text.Json.Serialization.Metadata.JsonPropertyInfo[] GetValueArgsPropInit(global::System.Text.Json.JsonSerializerOptions options) - { - var properties = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfo[0]; - - return properties; - } - - // Intentionally not a static method because we create a delegate to it. Invoking delegates to instance - // methods is almost as fast as virtual calls. Static methods need to go through a shuffle thunk. - private void GetValueArgsSerializeHandler(global::System.Text.Json.Utf8JsonWriter writer, global::CSharpToJsonSchema.IntegrationTests.GetValueArgs? value) - { - if (value is null) - { - writer.WriteNullValue(); - return; - } - - writer.WriteStartObject(); - - - writer.WriteEndObject(); - } - } -} diff --git a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.GetValueAsyncArgs.g.verified.cs b/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.GetValueAsyncArgs.g.verified.cs deleted file mode 100644 index 54c8114..0000000 --- a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.GetValueAsyncArgs.g.verified.cs +++ /dev/null @@ -1,71 +0,0 @@ -//HintName: IVariousTypesTools.GetValueAsyncArgs.g.cs -// - -#nullable enable annotations -#nullable disable warnings - -// Suppress warnings about [Obsolete] member usage in generated code. -#pragma warning disable CS0612, CS0618 - -namespace CSharpToJsonSchema.IntegrationTests -{ - public partial class VariousTypesToolsExtensionsJsonSerializerContext - { - private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo? _GetValueAsyncArgs; - - /// - /// Defines the source generated JSON serialization contract metadata for a given type. - /// - #nullable disable annotations // Marking the property type as nullable-oblivious. - public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo GetValueAsyncArgs - #nullable enable annotations - { - get => _GetValueAsyncArgs ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo)Options.GetTypeInfo(typeof(global::CSharpToJsonSchema.IntegrationTests.GetValueAsyncArgs)); - } - - private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo Create_GetValueAsyncArgs(global::System.Text.Json.JsonSerializerOptions options) - { - if (!TryGetTypeInfoForRuntimeCustomConverter(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo)) - { - var objectInfo = new global::System.Text.Json.Serialization.Metadata.JsonObjectInfoValues - { - ObjectCreator = () => new global::CSharpToJsonSchema.IntegrationTests.GetValueAsyncArgs(), - ObjectWithParameterizedConstructorCreator = null, - PropertyMetadataInitializer = _ => GetValueAsyncArgsPropInit(options), - ConstructorParameterMetadataInitializer = null, - ConstructorAttributeProviderFactory = static () => typeof(global::CSharpToJsonSchema.IntegrationTests.GetValueAsyncArgs).GetConstructor(InstanceMemberBindingFlags, binder: null, global::System.Array.Empty(), modifiers: null), - SerializeHandler = GetValueAsyncArgsSerializeHandler, - }; - - jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateObjectInfo(options, objectInfo); - jsonTypeInfo.NumberHandling = null; - } - - jsonTypeInfo.OriginatingResolver = this; - return jsonTypeInfo; - } - - private static global::System.Text.Json.Serialization.Metadata.JsonPropertyInfo[] GetValueAsyncArgsPropInit(global::System.Text.Json.JsonSerializerOptions options) - { - var properties = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfo[0]; - - return properties; - } - - // Intentionally not a static method because we create a delegate to it. Invoking delegates to instance - // methods is almost as fast as virtual calls. Static methods need to go through a shuffle thunk. - private void GetValueAsyncArgsSerializeHandler(global::System.Text.Json.Utf8JsonWriter writer, global::CSharpToJsonSchema.IntegrationTests.GetValueAsyncArgs? value) - { - if (value is null) - { - writer.WriteNullValue(); - return; - } - - writer.WriteStartObject(); - - - writer.WriteEndObject(); - } - } -} diff --git a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.Int32.g.verified.cs b/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.Int32.g.verified.cs deleted file mode 100644 index 91818c8..0000000 --- a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.Int32.g.verified.cs +++ /dev/null @@ -1,37 +0,0 @@ -//HintName: IVariousTypesTools.Int32.g.cs -// - -#nullable enable annotations -#nullable disable warnings - -// Suppress warnings about [Obsolete] member usage in generated code. -#pragma warning disable CS0612, CS0618 - -namespace CSharpToJsonSchema.IntegrationTests -{ - public partial class VariousTypesToolsExtensionsJsonSerializerContext - { - private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo? _Int32; - - /// - /// Defines the source generated JSON serialization contract metadata for a given type. - /// - #nullable disable annotations // Marking the property type as nullable-oblivious. - public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo Int32 - #nullable enable annotations - { - get => _Int32 ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo)Options.GetTypeInfo(typeof(int)); - } - - private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo Create_Int32(global::System.Text.Json.JsonSerializerOptions options) - { - if (!TryGetTypeInfoForRuntimeCustomConverter(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo)) - { - jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateValueInfo(options, global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.Int32Converter); - } - - jsonTypeInfo.OriginatingResolver = this; - return jsonTypeInfo; - } - } -} diff --git a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.Int64.g.verified.cs b/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.Int64.g.verified.cs deleted file mode 100644 index 2263c42..0000000 --- a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.Int64.g.verified.cs +++ /dev/null @@ -1,37 +0,0 @@ -//HintName: IVariousTypesTools.Int64.g.cs -// - -#nullable enable annotations -#nullable disable warnings - -// Suppress warnings about [Obsolete] member usage in generated code. -#pragma warning disable CS0612, CS0618 - -namespace CSharpToJsonSchema.IntegrationTests -{ - public partial class VariousTypesToolsExtensionsJsonSerializerContext - { - private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo? _Int64; - - /// - /// Defines the source generated JSON serialization contract metadata for a given type. - /// - #nullable disable annotations // Marking the property type as nullable-oblivious. - public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo Int64 - #nullable enable annotations - { - get => _Int64 ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo)Options.GetTypeInfo(typeof(long)); - } - - private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo Create_Int64(global::System.Text.Json.JsonSerializerOptions options) - { - if (!TryGetTypeInfoForRuntimeCustomConverter(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo)) - { - jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateValueInfo(options, global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.Int64Converter); - } - - jsonTypeInfo.OriginatingResolver = this; - return jsonTypeInfo; - } - } -} diff --git a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.PropertyNames.g.verified.cs b/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.PropertyNames.g.verified.cs deleted file mode 100644 index d34ba5a..0000000 --- a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.PropertyNames.g.verified.cs +++ /dev/null @@ -1,23 +0,0 @@ -//HintName: IVariousTypesTools.PropertyNames.g.cs -// - -#nullable enable annotations -#nullable disable warnings - -// Suppress warnings about [Obsolete] member usage in generated code. -#pragma warning disable CS0612, CS0618 - -namespace CSharpToJsonSchema.IntegrationTests -{ - public partial class VariousTypesToolsExtensionsJsonSerializerContext - { - private static readonly global::System.Text.Json.JsonEncodedText PropName_parameter1 = global::System.Text.Json.JsonEncodedText.Encode("parameter1"); - private static readonly global::System.Text.Json.JsonEncodedText PropName_parameter2 = global::System.Text.Json.JsonEncodedText.Encode("parameter2"); - private static readonly global::System.Text.Json.JsonEncodedText PropName_parameter3 = global::System.Text.Json.JsonEncodedText.Encode("parameter3"); - private static readonly global::System.Text.Json.JsonEncodedText PropName_parameter4 = global::System.Text.Json.JsonEncodedText.Encode("parameter4"); - private static readonly global::System.Text.Json.JsonEncodedText PropName_parameter5 = global::System.Text.Json.JsonEncodedText.Encode("parameter5"); - private static readonly global::System.Text.Json.JsonEncodedText PropName_dateTime = global::System.Text.Json.JsonEncodedText.Encode("dateTime"); - private static readonly global::System.Text.Json.JsonEncodedText PropName_date = global::System.Text.Json.JsonEncodedText.Encode("date"); - private static readonly global::System.Text.Json.JsonEncodedText PropName_value = global::System.Text.Json.JsonEncodedText.Encode("value"); - } -} diff --git a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.SetValueArgs.g.verified.cs b/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.SetValueArgs.g.verified.cs deleted file mode 100644 index d83f8a2..0000000 --- a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.SetValueArgs.g.verified.cs +++ /dev/null @@ -1,92 +0,0 @@ -//HintName: IVariousTypesTools.SetValueArgs.g.cs -// - -#nullable enable annotations -#nullable disable warnings - -// Suppress warnings about [Obsolete] member usage in generated code. -#pragma warning disable CS0612, CS0618 - -namespace CSharpToJsonSchema.IntegrationTests -{ - public partial class VariousTypesToolsExtensionsJsonSerializerContext - { - private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo? _SetValueArgs; - - /// - /// Defines the source generated JSON serialization contract metadata for a given type. - /// - #nullable disable annotations // Marking the property type as nullable-oblivious. - public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo SetValueArgs - #nullable enable annotations - { - get => _SetValueArgs ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo)Options.GetTypeInfo(typeof(global::CSharpToJsonSchema.IntegrationTests.SetValueArgs)); - } - - private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo Create_SetValueArgs(global::System.Text.Json.JsonSerializerOptions options) - { - if (!TryGetTypeInfoForRuntimeCustomConverter(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo)) - { - var objectInfo = new global::System.Text.Json.Serialization.Metadata.JsonObjectInfoValues - { - ObjectCreator = () => new global::CSharpToJsonSchema.IntegrationTests.SetValueArgs(), - ObjectWithParameterizedConstructorCreator = null, - PropertyMetadataInitializer = _ => SetValueArgsPropInit(options), - ConstructorParameterMetadataInitializer = null, - ConstructorAttributeProviderFactory = static () => typeof(global::CSharpToJsonSchema.IntegrationTests.SetValueArgs).GetConstructor(InstanceMemberBindingFlags, binder: null, global::System.Array.Empty(), modifiers: null), - SerializeHandler = SetValueArgsSerializeHandler, - }; - - jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateObjectInfo(options, objectInfo); - jsonTypeInfo.NumberHandling = null; - } - - jsonTypeInfo.OriginatingResolver = this; - return jsonTypeInfo; - } - - private static global::System.Text.Json.Serialization.Metadata.JsonPropertyInfo[] SetValueArgsPropInit(global::System.Text.Json.JsonSerializerOptions options) - { - var properties = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfo[1]; - - var info0 = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfoValues - { - IsProperty = true, - IsPublic = true, - IsVirtual = false, - DeclaringType = typeof(global::CSharpToJsonSchema.IntegrationTests.SetValueArgs), - Converter = null, - Getter = static obj => ((global::CSharpToJsonSchema.IntegrationTests.SetValueArgs)obj).Value, - Setter = static (obj, value) => ((global::CSharpToJsonSchema.IntegrationTests.SetValueArgs)obj).Value = value!, - IgnoreCondition = null, - HasJsonInclude = false, - IsExtensionData = false, - NumberHandling = null, - PropertyName = "Value", - JsonPropertyName = null, - AttributeProviderFactory = static () => typeof(global::CSharpToJsonSchema.IntegrationTests.SetValueArgs).GetProperty("Value", InstanceMemberBindingFlags, null, typeof(int), global::System.Array.Empty(), null), - }; - - properties[0] = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreatePropertyInfo(options, info0); - - return properties; - } - - // Intentionally not a static method because we create a delegate to it. Invoking delegates to instance - // methods is almost as fast as virtual calls. Static methods need to go through a shuffle thunk. - private void SetValueArgsSerializeHandler(global::System.Text.Json.Utf8JsonWriter writer, global::CSharpToJsonSchema.IntegrationTests.SetValueArgs? value) - { - if (value is null) - { - writer.WriteNullValue(); - return; - } - - writer.WriteStartObject(); - - writer.WriteNumber(PropName_value, ((global::CSharpToJsonSchema.IntegrationTests.SetValueArgs)value).Value); - - writer.WriteEndObject(); - } - } -} diff --git a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.SetValueAsyncArgs.g.verified.cs b/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.SetValueAsyncArgs.g.verified.cs deleted file mode 100644 index 26a1458..0000000 --- a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.SetValueAsyncArgs.g.verified.cs +++ /dev/null @@ -1,92 +0,0 @@ -//HintName: IVariousTypesTools.SetValueAsyncArgs.g.cs -// - -#nullable enable annotations -#nullable disable warnings - -// Suppress warnings about [Obsolete] member usage in generated code. -#pragma warning disable CS0612, CS0618 - -namespace CSharpToJsonSchema.IntegrationTests -{ - public partial class VariousTypesToolsExtensionsJsonSerializerContext - { - private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo? _SetValueAsyncArgs; - - /// - /// Defines the source generated JSON serialization contract metadata for a given type. - /// - #nullable disable annotations // Marking the property type as nullable-oblivious. - public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo SetValueAsyncArgs - #nullable enable annotations - { - get => _SetValueAsyncArgs ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo)Options.GetTypeInfo(typeof(global::CSharpToJsonSchema.IntegrationTests.SetValueAsyncArgs)); - } - - private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo Create_SetValueAsyncArgs(global::System.Text.Json.JsonSerializerOptions options) - { - if (!TryGetTypeInfoForRuntimeCustomConverter(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo)) - { - var objectInfo = new global::System.Text.Json.Serialization.Metadata.JsonObjectInfoValues - { - ObjectCreator = () => new global::CSharpToJsonSchema.IntegrationTests.SetValueAsyncArgs(), - ObjectWithParameterizedConstructorCreator = null, - PropertyMetadataInitializer = _ => SetValueAsyncArgsPropInit(options), - ConstructorParameterMetadataInitializer = null, - ConstructorAttributeProviderFactory = static () => typeof(global::CSharpToJsonSchema.IntegrationTests.SetValueAsyncArgs).GetConstructor(InstanceMemberBindingFlags, binder: null, global::System.Array.Empty(), modifiers: null), - SerializeHandler = SetValueAsyncArgsSerializeHandler, - }; - - jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateObjectInfo(options, objectInfo); - jsonTypeInfo.NumberHandling = null; - } - - jsonTypeInfo.OriginatingResolver = this; - return jsonTypeInfo; - } - - private static global::System.Text.Json.Serialization.Metadata.JsonPropertyInfo[] SetValueAsyncArgsPropInit(global::System.Text.Json.JsonSerializerOptions options) - { - var properties = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfo[1]; - - var info0 = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfoValues - { - IsProperty = true, - IsPublic = true, - IsVirtual = false, - DeclaringType = typeof(global::CSharpToJsonSchema.IntegrationTests.SetValueAsyncArgs), - Converter = null, - Getter = static obj => ((global::CSharpToJsonSchema.IntegrationTests.SetValueAsyncArgs)obj).Value, - Setter = static (obj, value) => ((global::CSharpToJsonSchema.IntegrationTests.SetValueAsyncArgs)obj).Value = value!, - IgnoreCondition = null, - HasJsonInclude = false, - IsExtensionData = false, - NumberHandling = null, - PropertyName = "Value", - JsonPropertyName = null, - AttributeProviderFactory = static () => typeof(global::CSharpToJsonSchema.IntegrationTests.SetValueAsyncArgs).GetProperty("Value", InstanceMemberBindingFlags, null, typeof(int), global::System.Array.Empty(), null), - }; - - properties[0] = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreatePropertyInfo(options, info0); - - return properties; - } - - // Intentionally not a static method because we create a delegate to it. Invoking delegates to instance - // methods is almost as fast as virtual calls. Static methods need to go through a shuffle thunk. - private void SetValueAsyncArgsSerializeHandler(global::System.Text.Json.Utf8JsonWriter writer, global::CSharpToJsonSchema.IntegrationTests.SetValueAsyncArgs? value) - { - if (value is null) - { - writer.WriteNullValue(); - return; - } - - writer.WriteStartObject(); - - writer.WriteNumber(PropName_value, ((global::CSharpToJsonSchema.IntegrationTests.SetValueAsyncArgs)value).Value); - - writer.WriteEndObject(); - } - } -} diff --git a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.Single.g.verified.cs b/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.Single.g.verified.cs deleted file mode 100644 index 60b90d8..0000000 --- a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.Single.g.verified.cs +++ /dev/null @@ -1,37 +0,0 @@ -//HintName: IVariousTypesTools.Single.g.cs -// - -#nullable enable annotations -#nullable disable warnings - -// Suppress warnings about [Obsolete] member usage in generated code. -#pragma warning disable CS0612, CS0618 - -namespace CSharpToJsonSchema.IntegrationTests -{ - public partial class VariousTypesToolsExtensionsJsonSerializerContext - { - private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo? _Single; - - /// - /// Defines the source generated JSON serialization contract metadata for a given type. - /// - #nullable disable annotations // Marking the property type as nullable-oblivious. - public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo Single - #nullable enable annotations - { - get => _Single ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo)Options.GetTypeInfo(typeof(float)); - } - - private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo Create_Single(global::System.Text.Json.JsonSerializerOptions options) - { - if (!TryGetTypeInfoForRuntimeCustomConverter(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo)) - { - jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateValueInfo(options, global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.SingleConverter); - } - - jsonTypeInfo.OriginatingResolver = this; - return jsonTypeInfo; - } - } -} diff --git a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.Tools.generated.verified.cs b/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.Tools.generated.verified.cs deleted file mode 100644 index e7aa097..0000000 --- a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.Tools.generated.verified.cs +++ /dev/null @@ -1,55 +0,0 @@ -//HintName: IVariousTypesTools.Tools.generated.cs - -#nullable enable - -namespace CSharpToJsonSchema.IntegrationTests -{ - public static partial class VariousTypesToolsExtensions - { - public static global::System.Collections.Generic.IList AsTools(this IVariousTypesTools functions) - { - return new global::System.Collections.Generic.List - { - new global::CSharpToJsonSchema.Tool - { - Name = "GetCurrentWeather3", - Description = "Get the current weather in a given location", - Strict = false, - Parameters = global::CSharpToJsonSchema.SchemaBuilder.ConvertToSchema(global::CSharpToJsonSchema.IntegrationTests.VariousTypesToolsExtensionsJsonSerializerContext.Default.GetCurrentWeather3Args,"{\"parameter1\":\"\", \"parameter2\":\"\", \"parameter3\":\"\", \"parameter4\":\"\", \"parameter5\":\"\", \"dateTime\":\"\", \"date\":\"\", \"mainFunction_Desc\":\"Get the current weather in a given location\"}"), - }, - - new global::CSharpToJsonSchema.Tool - { - Name = "SetValue", - Description = "Sets the value", - Strict = false, - Parameters = global::CSharpToJsonSchema.SchemaBuilder.ConvertToSchema(global::CSharpToJsonSchema.IntegrationTests.VariousTypesToolsExtensionsJsonSerializerContext.Default.SetValueArgs,"{\"value\":\"\", \"mainFunction_Desc\":\"Sets the value\"}"), - }, - - new global::CSharpToJsonSchema.Tool - { - Name = "GetValue", - Description = "Gets the value", - Strict = false, - Parameters = global::CSharpToJsonSchema.SchemaBuilder.ConvertToSchema(global::CSharpToJsonSchema.IntegrationTests.VariousTypesToolsExtensionsJsonSerializerContext.Default.GetValueArgs,"{\"mainFunction_Desc\":\"Gets the value\"}"), - }, - - new global::CSharpToJsonSchema.Tool - { - Name = "SetValueAsync", - Description = "Sets the value", - Strict = false, - Parameters = global::CSharpToJsonSchema.SchemaBuilder.ConvertToSchema(global::CSharpToJsonSchema.IntegrationTests.VariousTypesToolsExtensionsJsonSerializerContext.Default.SetValueAsyncArgs,"{\"value\":\"\", \"mainFunction_Desc\":\"Sets the value\"}"), - }, - - new global::CSharpToJsonSchema.Tool - { - Name = "GetValueAsync", - Description = "Gets the value", - Strict = false, - Parameters = global::CSharpToJsonSchema.SchemaBuilder.ConvertToSchema(global::CSharpToJsonSchema.IntegrationTests.VariousTypesToolsExtensionsJsonSerializerContext.Default.GetValueAsyncArgs,"{\"mainFunction_Desc\":\"Gets the value\"}"), - }, - }; - } - } -} \ No newline at end of file diff --git a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.g.verified.cs b/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.g.verified.cs deleted file mode 100644 index 5032b6d..0000000 --- a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.g.verified.cs +++ /dev/null @@ -1,111 +0,0 @@ -//HintName: IVariousTypesTools.g.cs -// - -#nullable enable annotations -#nullable disable warnings - -// Suppress warnings about [Obsolete] member usage in generated code. -#pragma warning disable CS0612, CS0618 - -namespace CSharpToJsonSchema.IntegrationTests -{ - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("CSharpToJsonSchema.Generators", "3.0.0.0")] - public partial class VariousTypesToolsExtensionsJsonSerializerContext - { - private readonly static global::System.Text.Json.JsonSerializerOptions s_defaultOptions = new(global::System.Text.Json.JsonSerializerDefaults.Web) - { - AllowOutOfOrderMetadataProperties = true, - AllowTrailingCommas = false, - DefaultBufferSize = 1024, - DefaultIgnoreCondition = global::System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull, - RespectNullableAnnotations = true, - RespectRequiredConstructorParameters = false, - IgnoreReadOnlyFields = false, - IgnoreReadOnlyProperties = false, - IncludeFields = false, - MaxDepth = 64, - NewLine = "\n", - NumberHandling = global::System.Text.Json.Serialization.JsonNumberHandling.Strict, - PreferredObjectCreationHandling = global::System.Text.Json.Serialization.JsonObjectCreationHandling.Replace, - PropertyNameCaseInsensitive = true, - PropertyNamingPolicy = global::System.Text.Json.JsonNamingPolicy.CamelCase, - ReadCommentHandling = global::System.Text.Json.JsonCommentHandling.Disallow, - UnknownTypeHandling = global::System.Text.Json.Serialization.JsonUnknownTypeHandling.JsonElement, - UnmappedMemberHandling = global::System.Text.Json.Serialization.JsonUnmappedMemberHandling.Skip, - WriteIndented = false, - IndentCharacter = ' ', - IndentSize = 2, - }; - - private const global::System.Reflection.BindingFlags InstanceMemberBindingFlags = - global::System.Reflection.BindingFlags.Instance | - global::System.Reflection.BindingFlags.Public | - global::System.Reflection.BindingFlags.NonPublic; - - /// - /// The default associated with a default instance. - /// - public static global::CSharpToJsonSchema.IntegrationTests.VariousTypesToolsExtensionsJsonSerializerContext Default { get; } = new global::CSharpToJsonSchema.IntegrationTests.VariousTypesToolsExtensionsJsonSerializerContext(new global::System.Text.Json.JsonSerializerOptions(s_defaultOptions)); - - /// - /// The source-generated options associated with this context. - /// - protected override global::System.Text.Json.JsonSerializerOptions? GeneratedSerializerOptions { get; } = s_defaultOptions; - - /// - public VariousTypesToolsExtensionsJsonSerializerContext() : base(null) - { - } - - /// - public VariousTypesToolsExtensionsJsonSerializerContext(global::System.Text.Json.JsonSerializerOptions options) : base(options) - { - } - - private static bool TryGetTypeInfoForRuntimeCustomConverter(global::System.Text.Json.JsonSerializerOptions options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo) - { - global::System.Text.Json.Serialization.JsonConverter? converter = GetRuntimeConverterForType(typeof(TJsonMetadataType), options); - if (converter != null) - { - jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateValueInfo(options, converter); - return true; - } - - jsonTypeInfo = null; - return false; - } - - private static global::System.Text.Json.Serialization.JsonConverter? GetRuntimeConverterForType(global::System.Type type, global::System.Text.Json.JsonSerializerOptions options) - { - for (int i = 0; i < options.Converters.Count; i++) - { - global::System.Text.Json.Serialization.JsonConverter? converter = options.Converters[i]; - if (converter?.CanConvert(type) == true) - { - return ExpandConverter(type, converter, options, validateCanConvert: false); - } - } - - return null; - } - - private static global::System.Text.Json.Serialization.JsonConverter ExpandConverter(global::System.Type type, global::System.Text.Json.Serialization.JsonConverter converter, global::System.Text.Json.JsonSerializerOptions options, bool validateCanConvert = true) - { - if (validateCanConvert && !converter.CanConvert(type)) - { - throw new global::System.InvalidOperationException(string.Format("The converter '{0}' is not compatible with the type '{1}'.", converter.GetType(), type)); - } - - if (converter is global::System.Text.Json.Serialization.JsonConverterFactory factory) - { - converter = factory.CreateConverter(type, options); - if (converter is null || converter is global::System.Text.Json.Serialization.JsonConverterFactory) - { - throw new global::System.InvalidOperationException(string.Format("The converter '{0}' cannot return null or a JsonConverterFactory instance.", factory.GetType())); - } - } - - return converter; - } - } -} diff --git a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes_Diagnostics.verified.txt b/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes_Diagnostics.verified.txt deleted file mode 100644 index ad47dbb..0000000 --- a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes_Diagnostics.verified.txt +++ /dev/null @@ -1 +0,0 @@ -[] \ No newline at end of file diff --git a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.Calls.generated.verified.cs b/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.Calls.generated.verified.cs deleted file mode 100644 index b8f0f13..0000000 --- a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.Calls.generated.verified.cs +++ /dev/null @@ -1,195 +0,0 @@ -//HintName: IWeatherTools.Calls.generated.cs -#nullable enable - -namespace CSharpToJsonSchema.IntegrationTests -{ - public class GetCurrentWeatherArgs - { - - [global::System.ComponentModel.Description("The city and state, e.g. San Francisco, CA")] - public string? Location { get; set; } = string.Empty; - [global::System.ComponentModel.Description("")] - public CSharpToJsonSchema.IntegrationTests.Unit Unit { get; set; } - } - - public class GetCurrentWeatherAsyncArgs - { - - [global::System.ComponentModel.Description("The city and state, e.g. San Francisco, CA")] - public string? Location { get; set; } = string.Empty; - [global::System.ComponentModel.Description("")] - public CSharpToJsonSchema.IntegrationTests.Unit Unit { get; set; } - } - - public static partial class WeatherToolsExtensions - { - public static global::System.Collections.Generic.IReadOnlyDictionary>> AsCalls(this IWeatherTools service) - { - return new global::System.Collections.Generic.Dictionary>> - { - ["GetCurrentWeather"] = (json, _) => - { - return global::System.Threading.Tasks.Task.FromResult(service.CallGetCurrentWeather(json)); - }, - - ["GetCurrentWeatherAsync"] = async (json, cancellationToken) => - { - return await service.CallGetCurrentWeatherAsync(json, cancellationToken); - }, - - }; - } - - #pragma warning disable IL2026, IL3050 - public static GetCurrentWeatherArgs AsGetCurrentWeatherArgs( - this IWeatherTools functions, - string json) - { - #if NET6_0_OR_GREATER - if(global::System.Text.Json.JsonSerializer.IsReflectionEnabledByDefault) - { - - return global::System.Text.Json.JsonSerializer.Deserialize(json, new global::System.Text.Json.JsonSerializerOptions - { - PropertyNamingPolicy = global::System.Text.Json.JsonNamingPolicy.CamelCase, - Converters = {{ new global::System.Text.Json.Serialization.JsonStringEnumConverter(global::System.Text.Json.JsonNamingPolicy.CamelCase) }} - }) ?? - throw new global::System.InvalidOperationException("Could not deserialize JSON."); - - } - else - { - return global::System.Text.Json.JsonSerializer.Deserialize(json, global::CSharpToJsonSchema.IntegrationTests.WeatherToolsExtensionsJsonSerializerContext.Default.GetCurrentWeatherArgs) ?? - throw new global::System.InvalidOperationException("Could not deserialize JSON."); - } - #else - return - global::System.Text.Json.JsonSerializer.Deserialize(json, new global::System.Text.Json.JsonSerializerOptions - { - PropertyNamingPolicy = global::System.Text.Json.JsonNamingPolicy.CamelCase, - Converters = {{ new global::System.Text.Json.Serialization.JsonStringEnumConverter(global::System.Text.Json.JsonNamingPolicy.CamelCase) }} - }) ?? - throw new global::System.InvalidOperationException("Could not deserialize JSON."); - #endif - } - #pragma warning restore IL2026, IL3050 - - #pragma warning disable IL2026, IL3050 - public static GetCurrentWeatherAsyncArgs AsGetCurrentWeatherAsyncArgs( - this IWeatherTools functions, - string json) - { - #if NET6_0_OR_GREATER - if(global::System.Text.Json.JsonSerializer.IsReflectionEnabledByDefault) - { - - return global::System.Text.Json.JsonSerializer.Deserialize(json, new global::System.Text.Json.JsonSerializerOptions - { - PropertyNamingPolicy = global::System.Text.Json.JsonNamingPolicy.CamelCase, - Converters = {{ new global::System.Text.Json.Serialization.JsonStringEnumConverter(global::System.Text.Json.JsonNamingPolicy.CamelCase) }} - }) ?? - throw new global::System.InvalidOperationException("Could not deserialize JSON."); - - } - else - { - return global::System.Text.Json.JsonSerializer.Deserialize(json, global::CSharpToJsonSchema.IntegrationTests.WeatherToolsExtensionsJsonSerializerContext.Default.GetCurrentWeatherAsyncArgs) ?? - throw new global::System.InvalidOperationException("Could not deserialize JSON."); - } - #else - return - global::System.Text.Json.JsonSerializer.Deserialize(json, new global::System.Text.Json.JsonSerializerOptions - { - PropertyNamingPolicy = global::System.Text.Json.JsonNamingPolicy.CamelCase, - Converters = {{ new global::System.Text.Json.Serialization.JsonStringEnumConverter(global::System.Text.Json.JsonNamingPolicy.CamelCase) }} - }) ?? - throw new global::System.InvalidOperationException("Could not deserialize JSON."); - #endif - } - #pragma warning restore IL2026, IL3050 - - #pragma warning disable IL2026, IL3050 - public static string CallGetCurrentWeather(this IWeatherTools functions, string json) - { - var args = functions.AsGetCurrentWeatherArgs(json); - var jsonResult = functions.GetCurrentWeather(args.Location, args.Unit); - - #if NET6_0_OR_GREATER - if(global::System.Text.Json.JsonSerializer.IsReflectionEnabledByDefault) - { - - return global::System.Text.Json.JsonSerializer.Serialize(jsonResult, new global::System.Text.Json.JsonSerializerOptions - { - PropertyNamingPolicy = global::System.Text.Json.JsonNamingPolicy.CamelCase, - Converters = { new global::System.Text.Json.Serialization.JsonStringEnumConverter(global::System.Text.Json.JsonNamingPolicy.CamelCase) }, - }); - - } - else - { - return global::System.Text.Json.JsonSerializer.Serialize(jsonResult, global::CSharpToJsonSchema.IntegrationTests.WeatherToolsExtensionsJsonSerializerContext.Default.GetTypeInfo(jsonResult.GetType())); - } - #else - return global::System.Text.Json.JsonSerializer.Serialize(jsonResult, new global::System.Text.Json.JsonSerializerOptions - { - PropertyNamingPolicy = global::System.Text.Json.JsonNamingPolicy.CamelCase, - Converters = { new global::System.Text.Json.Serialization.JsonStringEnumConverter(global::System.Text.Json.JsonNamingPolicy.CamelCase) }, - }); - #endif - } - #pragma warning restore IL2026, IL3050 - - - #pragma warning disable IL2026, IL3050 - public static async global::System.Threading.Tasks.Task CallGetCurrentWeatherAsync( - this IWeatherTools functions, - string json, - global::System.Threading.CancellationToken cancellationToken = default) - { - var args = functions.AsGetCurrentWeatherAsyncArgs(json); - var jsonResult = await functions.GetCurrentWeatherAsync(args.Location, args.Unit, cancellationToken); - - #if NET6_0_OR_GREATER - if(global::System.Text.Json.JsonSerializer.IsReflectionEnabledByDefault) - { - - return global::System.Text.Json.JsonSerializer.Serialize(jsonResult, new global::System.Text.Json.JsonSerializerOptions - { - PropertyNamingPolicy = global::System.Text.Json.JsonNamingPolicy.CamelCase, - Converters = { new global::System.Text.Json.Serialization.JsonStringEnumConverter(global::System.Text.Json.JsonNamingPolicy.CamelCase) }, - }); - } - else - { - return global::System.Text.Json.JsonSerializer.Serialize(jsonResult, global::CSharpToJsonSchema.IntegrationTests.WeatherToolsExtensionsJsonSerializerContext.Default.GetTypeInfo(jsonResult.GetType())); - } - #else - return global::System.Text.Json.JsonSerializer.Serialize(jsonResult, new global::System.Text.Json.JsonSerializerOptions - { - PropertyNamingPolicy = global::System.Text.Json.JsonNamingPolicy.CamelCase, - Converters = { new global::System.Text.Json.Serialization.JsonStringEnumConverter(global::System.Text.Json.JsonNamingPolicy.CamelCase) }, - }); - #endif - - } - #pragma warning restore IL2026, IL3050 - - - - public static async global::System.Threading.Tasks.Task CallAsync( - this IWeatherTools service, - string functionName, - string argumentsAsJson, - global::System.Threading.CancellationToken cancellationToken = default) - { - var calls = service.AsCalls(); - var func = calls[functionName]; - - return await func(argumentsAsJson, cancellationToken); - } - } - - public partial class WeatherToolsExtensionsJsonSerializerContext: global::System.Text.Json.Serialization.JsonSerializerContext - { - } -} \ No newline at end of file diff --git a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.Double.g.verified.cs b/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.Double.g.verified.cs deleted file mode 100644 index 2347275..0000000 --- a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.Double.g.verified.cs +++ /dev/null @@ -1,37 +0,0 @@ -//HintName: IWeatherTools.Double.g.cs -// - -#nullable enable annotations -#nullable disable warnings - -// Suppress warnings about [Obsolete] member usage in generated code. -#pragma warning disable CS0612, CS0618 - -namespace CSharpToJsonSchema.IntegrationTests -{ - public partial class WeatherToolsExtensionsJsonSerializerContext - { - private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo? _Double; - - /// - /// Defines the source generated JSON serialization contract metadata for a given type. - /// - #nullable disable annotations // Marking the property type as nullable-oblivious. - public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo Double - #nullable enable annotations - { - get => _Double ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo)Options.GetTypeInfo(typeof(double)); - } - - private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo Create_Double(global::System.Text.Json.JsonSerializerOptions options) - { - if (!TryGetTypeInfoForRuntimeCustomConverter(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo)) - { - jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateValueInfo(options, global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.DoubleConverter); - } - - jsonTypeInfo.OriginatingResolver = this; - return jsonTypeInfo; - } - } -} diff --git a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.GetCurrentWeatherArgs.g.verified.cs b/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.GetCurrentWeatherArgs.g.verified.cs deleted file mode 100644 index ddadc1f..0000000 --- a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.GetCurrentWeatherArgs.g.verified.cs +++ /dev/null @@ -1,118 +0,0 @@ -//HintName: IWeatherTools.GetCurrentWeatherArgs.g.cs -// - -#nullable enable annotations -#nullable disable warnings - -// Suppress warnings about [Obsolete] member usage in generated code. -#pragma warning disable CS0612, CS0618 - -namespace CSharpToJsonSchema.IntegrationTests -{ - public partial class WeatherToolsExtensionsJsonSerializerContext - { - private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo? _GetCurrentWeatherArgs; - - /// - /// Defines the source generated JSON serialization contract metadata for a given type. - /// - #nullable disable annotations // Marking the property type as nullable-oblivious. - public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo GetCurrentWeatherArgs - #nullable enable annotations - { - get => _GetCurrentWeatherArgs ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo)Options.GetTypeInfo(typeof(global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeatherArgs)); - } - - private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo Create_GetCurrentWeatherArgs(global::System.Text.Json.JsonSerializerOptions options) - { - if (!TryGetTypeInfoForRuntimeCustomConverter(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo)) - { - var objectInfo = new global::System.Text.Json.Serialization.Metadata.JsonObjectInfoValues - { - ObjectCreator = () => new global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeatherArgs(), - ObjectWithParameterizedConstructorCreator = null, - PropertyMetadataInitializer = _ => GetCurrentWeatherArgsPropInit(options), - ConstructorParameterMetadataInitializer = null, - ConstructorAttributeProviderFactory = static () => typeof(global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeatherArgs).GetConstructor(InstanceMemberBindingFlags, binder: null, global::System.Array.Empty(), modifiers: null), - SerializeHandler = GetCurrentWeatherArgsSerializeHandler, - }; - - jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateObjectInfo(options, objectInfo); - jsonTypeInfo.NumberHandling = null; - } - - jsonTypeInfo.OriginatingResolver = this; - return jsonTypeInfo; - } - - private static global::System.Text.Json.Serialization.Metadata.JsonPropertyInfo[] GetCurrentWeatherArgsPropInit(global::System.Text.Json.JsonSerializerOptions options) - { - var properties = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfo[2]; - - var info0 = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfoValues - { - IsProperty = true, - IsPublic = true, - IsVirtual = false, - DeclaringType = typeof(global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeatherArgs), - Converter = null, - Getter = static obj => ((global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeatherArgs)obj).Location, - Setter = static (obj, value) => ((global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeatherArgs)obj).Location = value!, - IgnoreCondition = null, - HasJsonInclude = false, - IsExtensionData = false, - NumberHandling = null, - PropertyName = "Location", - JsonPropertyName = null, - AttributeProviderFactory = static () => typeof(global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeatherArgs).GetProperty("Location", InstanceMemberBindingFlags, null, typeof(string), global::System.Array.Empty(), null), - }; - - properties[0] = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreatePropertyInfo(options, info0); - - var info1 = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfoValues - { - IsProperty = true, - IsPublic = true, - IsVirtual = false, - DeclaringType = typeof(global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeatherArgs), - Converter = null, - Getter = static obj => ((global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeatherArgs)obj).Unit, - Setter = static (obj, value) => ((global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeatherArgs)obj).Unit = value!, - IgnoreCondition = null, - HasJsonInclude = false, - IsExtensionData = false, - NumberHandling = null, - PropertyName = "Unit", - JsonPropertyName = null, - AttributeProviderFactory = static () => typeof(global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeatherArgs).GetProperty("Unit", InstanceMemberBindingFlags, null, typeof(global::CSharpToJsonSchema.IntegrationTests.Unit), global::System.Array.Empty(), null), - }; - - properties[1] = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreatePropertyInfo(options, info1); - - return properties; - } - - // Intentionally not a static method because we create a delegate to it. Invoking delegates to instance - // methods is almost as fast as virtual calls. Static methods need to go through a shuffle thunk. - private void GetCurrentWeatherArgsSerializeHandler(global::System.Text.Json.Utf8JsonWriter writer, global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeatherArgs? value) - { - if (value is null) - { - writer.WriteNullValue(); - return; - } - - writer.WriteStartObject(); - - string __value_Location = ((global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeatherArgs)value).Location; - if (__value_Location is not null) - { - writer.WriteString(PropName_location, __value_Location); - } - writer.WritePropertyName(PropName_unit); - global::System.Text.Json.JsonSerializer.Serialize(writer, ((global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeatherArgs)value).Unit, Unit); - - writer.WriteEndObject(); - } - } -} diff --git a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.GetCurrentWeatherAsyncArgs.g.verified.cs b/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.GetCurrentWeatherAsyncArgs.g.verified.cs deleted file mode 100644 index 0ed9822..0000000 --- a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.GetCurrentWeatherAsyncArgs.g.verified.cs +++ /dev/null @@ -1,118 +0,0 @@ -//HintName: IWeatherTools.GetCurrentWeatherAsyncArgs.g.cs -// - -#nullable enable annotations -#nullable disable warnings - -// Suppress warnings about [Obsolete] member usage in generated code. -#pragma warning disable CS0612, CS0618 - -namespace CSharpToJsonSchema.IntegrationTests -{ - public partial class WeatherToolsExtensionsJsonSerializerContext - { - private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo? _GetCurrentWeatherAsyncArgs; - - /// - /// Defines the source generated JSON serialization contract metadata for a given type. - /// - #nullable disable annotations // Marking the property type as nullable-oblivious. - public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo GetCurrentWeatherAsyncArgs - #nullable enable annotations - { - get => _GetCurrentWeatherAsyncArgs ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo)Options.GetTypeInfo(typeof(global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeatherAsyncArgs)); - } - - private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo Create_GetCurrentWeatherAsyncArgs(global::System.Text.Json.JsonSerializerOptions options) - { - if (!TryGetTypeInfoForRuntimeCustomConverter(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo)) - { - var objectInfo = new global::System.Text.Json.Serialization.Metadata.JsonObjectInfoValues - { - ObjectCreator = () => new global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeatherAsyncArgs(), - ObjectWithParameterizedConstructorCreator = null, - PropertyMetadataInitializer = _ => GetCurrentWeatherAsyncArgsPropInit(options), - ConstructorParameterMetadataInitializer = null, - ConstructorAttributeProviderFactory = static () => typeof(global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeatherAsyncArgs).GetConstructor(InstanceMemberBindingFlags, binder: null, global::System.Array.Empty(), modifiers: null), - SerializeHandler = GetCurrentWeatherAsyncArgsSerializeHandler, - }; - - jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateObjectInfo(options, objectInfo); - jsonTypeInfo.NumberHandling = null; - } - - jsonTypeInfo.OriginatingResolver = this; - return jsonTypeInfo; - } - - private static global::System.Text.Json.Serialization.Metadata.JsonPropertyInfo[] GetCurrentWeatherAsyncArgsPropInit(global::System.Text.Json.JsonSerializerOptions options) - { - var properties = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfo[2]; - - var info0 = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfoValues - { - IsProperty = true, - IsPublic = true, - IsVirtual = false, - DeclaringType = typeof(global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeatherAsyncArgs), - Converter = null, - Getter = static obj => ((global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeatherAsyncArgs)obj).Location, - Setter = static (obj, value) => ((global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeatherAsyncArgs)obj).Location = value!, - IgnoreCondition = null, - HasJsonInclude = false, - IsExtensionData = false, - NumberHandling = null, - PropertyName = "Location", - JsonPropertyName = null, - AttributeProviderFactory = static () => typeof(global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeatherAsyncArgs).GetProperty("Location", InstanceMemberBindingFlags, null, typeof(string), global::System.Array.Empty(), null), - }; - - properties[0] = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreatePropertyInfo(options, info0); - - var info1 = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfoValues - { - IsProperty = true, - IsPublic = true, - IsVirtual = false, - DeclaringType = typeof(global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeatherAsyncArgs), - Converter = null, - Getter = static obj => ((global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeatherAsyncArgs)obj).Unit, - Setter = static (obj, value) => ((global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeatherAsyncArgs)obj).Unit = value!, - IgnoreCondition = null, - HasJsonInclude = false, - IsExtensionData = false, - NumberHandling = null, - PropertyName = "Unit", - JsonPropertyName = null, - AttributeProviderFactory = static () => typeof(global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeatherAsyncArgs).GetProperty("Unit", InstanceMemberBindingFlags, null, typeof(global::CSharpToJsonSchema.IntegrationTests.Unit), global::System.Array.Empty(), null), - }; - - properties[1] = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreatePropertyInfo(options, info1); - - return properties; - } - - // Intentionally not a static method because we create a delegate to it. Invoking delegates to instance - // methods is almost as fast as virtual calls. Static methods need to go through a shuffle thunk. - private void GetCurrentWeatherAsyncArgsSerializeHandler(global::System.Text.Json.Utf8JsonWriter writer, global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeatherAsyncArgs? value) - { - if (value is null) - { - writer.WriteNullValue(); - return; - } - - writer.WriteStartObject(); - - string __value_Location = ((global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeatherAsyncArgs)value).Location; - if (__value_Location is not null) - { - writer.WriteString(PropName_location, __value_Location); - } - writer.WritePropertyName(PropName_unit); - global::System.Text.Json.JsonSerializer.Serialize(writer, ((global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeatherAsyncArgs)value).Unit, Unit); - - writer.WriteEndObject(); - } - } -} diff --git a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.GetJsonTypeInfo.g.verified.cs b/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.GetJsonTypeInfo.g.verified.cs deleted file mode 100644 index 6e04e4e..0000000 --- a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.GetJsonTypeInfo.g.verified.cs +++ /dev/null @@ -1,50 +0,0 @@ -//HintName: IWeatherTools.GetJsonTypeInfo.g.cs -// - -#nullable enable annotations -#nullable disable warnings - -// Suppress warnings about [Obsolete] member usage in generated code. -#pragma warning disable CS0612, CS0618 - -namespace CSharpToJsonSchema.IntegrationTests -{ - public partial class WeatherToolsExtensionsJsonSerializerContext : global::System.Text.Json.Serialization.Metadata.IJsonTypeInfoResolver - { - /// - public override global::System.Text.Json.Serialization.Metadata.JsonTypeInfo? GetTypeInfo(global::System.Type type) - { - Options.TryGetTypeInfo(type, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo? typeInfo); - return typeInfo; - } - - global::System.Text.Json.Serialization.Metadata.JsonTypeInfo? global::System.Text.Json.Serialization.Metadata.IJsonTypeInfoResolver.GetTypeInfo(global::System.Type type, global::System.Text.Json.JsonSerializerOptions options) - { - if (type == typeof(double)) - { - return Create_Double(options); - } - if (type == typeof(global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeatherArgs)) - { - return Create_GetCurrentWeatherArgs(options); - } - if (type == typeof(global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeatherAsyncArgs)) - { - return Create_GetCurrentWeatherAsyncArgs(options); - } - if (type == typeof(global::CSharpToJsonSchema.IntegrationTests.Unit)) - { - return Create_Unit(options); - } - if (type == typeof(global::CSharpToJsonSchema.IntegrationTests.Weather)) - { - return Create_Weather(options); - } - if (type == typeof(string)) - { - return Create_String(options); - } - return null; - } - } -} diff --git a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.PropertyNames.g.verified.cs b/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.PropertyNames.g.verified.cs deleted file mode 100644 index f05a09c..0000000 --- a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.PropertyNames.g.verified.cs +++ /dev/null @@ -1,19 +0,0 @@ -//HintName: IWeatherTools.PropertyNames.g.cs -// - -#nullable enable annotations -#nullable disable warnings - -// Suppress warnings about [Obsolete] member usage in generated code. -#pragma warning disable CS0612, CS0618 - -namespace CSharpToJsonSchema.IntegrationTests -{ - public partial class WeatherToolsExtensionsJsonSerializerContext - { - private static readonly global::System.Text.Json.JsonEncodedText PropName_location = global::System.Text.Json.JsonEncodedText.Encode("location"); - private static readonly global::System.Text.Json.JsonEncodedText PropName_unit = global::System.Text.Json.JsonEncodedText.Encode("unit"); - private static readonly global::System.Text.Json.JsonEncodedText PropName_temperature = global::System.Text.Json.JsonEncodedText.Encode("temperature"); - private static readonly global::System.Text.Json.JsonEncodedText PropName_description = global::System.Text.Json.JsonEncodedText.Encode("description"); - } -} diff --git a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.String.g.verified.cs b/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.String.g.verified.cs deleted file mode 100644 index 56f2b3d..0000000 --- a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.String.g.verified.cs +++ /dev/null @@ -1,37 +0,0 @@ -//HintName: IWeatherTools.String.g.cs -// - -#nullable enable annotations -#nullable disable warnings - -// Suppress warnings about [Obsolete] member usage in generated code. -#pragma warning disable CS0612, CS0618 - -namespace CSharpToJsonSchema.IntegrationTests -{ - public partial class WeatherToolsExtensionsJsonSerializerContext - { - private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo? _String; - - /// - /// Defines the source generated JSON serialization contract metadata for a given type. - /// - #nullable disable annotations // Marking the property type as nullable-oblivious. - public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo String - #nullable enable annotations - { - get => _String ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo)Options.GetTypeInfo(typeof(string)); - } - - private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo Create_String(global::System.Text.Json.JsonSerializerOptions options) - { - if (!TryGetTypeInfoForRuntimeCustomConverter(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo)) - { - jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateValueInfo(options, global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.StringConverter); - } - - jsonTypeInfo.OriginatingResolver = this; - return jsonTypeInfo; - } - } -} diff --git a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.Tools.generated.verified.cs b/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.Tools.generated.verified.cs deleted file mode 100644 index dd40e67..0000000 --- a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.Tools.generated.verified.cs +++ /dev/null @@ -1,31 +0,0 @@ -//HintName: IWeatherTools.Tools.generated.cs - -#nullable enable - -namespace CSharpToJsonSchema.IntegrationTests -{ - public static partial class WeatherToolsExtensions - { - public static global::System.Collections.Generic.IList AsTools(this IWeatherTools functions) - { - return new global::System.Collections.Generic.List - { - new global::CSharpToJsonSchema.Tool - { - Name = "GetCurrentWeather", - Description = "Get the current weather in a given location", - Strict = false, - Parameters = global::CSharpToJsonSchema.SchemaBuilder.ConvertToSchema(global::CSharpToJsonSchema.IntegrationTests.WeatherToolsExtensionsJsonSerializerContext.Default.GetCurrentWeatherArgs,"{\"location\":\"The city and state, e.g. San Francisco, CA\", \"unit\":\"\", \"mainFunction_Desc\":\"Get the current weather in a given location\"}"), - }, - - new global::CSharpToJsonSchema.Tool - { - Name = "GetCurrentWeatherAsync", - Description = "Get the current weather in a given location", - Strict = false, - Parameters = global::CSharpToJsonSchema.SchemaBuilder.ConvertToSchema(global::CSharpToJsonSchema.IntegrationTests.WeatherToolsExtensionsJsonSerializerContext.Default.GetCurrentWeatherAsyncArgs,"{\"location\":\"The city and state, e.g. San Francisco, CA\", \"unit\":\"\", \"mainFunction_Desc\":\"Get the current weather in a given location\"}"), - }, - }; - } - } -} \ No newline at end of file diff --git a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.Unit.g.verified.cs b/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.Unit.g.verified.cs deleted file mode 100644 index 7850732..0000000 --- a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.Unit.g.verified.cs +++ /dev/null @@ -1,38 +0,0 @@ -//HintName: IWeatherTools.Unit.g.cs -// - -#nullable enable annotations -#nullable disable warnings - -// Suppress warnings about [Obsolete] member usage in generated code. -#pragma warning disable CS0612, CS0618 - -namespace CSharpToJsonSchema.IntegrationTests -{ - public partial class WeatherToolsExtensionsJsonSerializerContext - { - private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo? _Unit; - - /// - /// Defines the source generated JSON serialization contract metadata for a given type. - /// - #nullable disable annotations // Marking the property type as nullable-oblivious. - public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo Unit - #nullable enable annotations - { - get => _Unit ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo)Options.GetTypeInfo(typeof(global::CSharpToJsonSchema.IntegrationTests.Unit)); - } - - private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo Create_Unit(global::System.Text.Json.JsonSerializerOptions options) - { - if (!TryGetTypeInfoForRuntimeCustomConverter(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo)) - { - global::System.Text.Json.Serialization.JsonConverter converter = ExpandConverter(typeof(global::CSharpToJsonSchema.IntegrationTests.Unit), new global::System.Text.Json.Serialization.JsonStringEnumConverter(), options); - jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateValueInfo (options, converter); - } - - jsonTypeInfo.OriginatingResolver = this; - return jsonTypeInfo; - } - } -} diff --git a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.Weather.g.verified.cs b/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.Weather.g.verified.cs deleted file mode 100644 index 830d339..0000000 --- a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.Weather.g.verified.cs +++ /dev/null @@ -1,164 +0,0 @@ -//HintName: IWeatherTools.Weather.g.cs -// - -#nullable enable annotations -#nullable disable warnings - -// Suppress warnings about [Obsolete] member usage in generated code. -#pragma warning disable CS0612, CS0618 - -namespace CSharpToJsonSchema.IntegrationTests -{ - public partial class WeatherToolsExtensionsJsonSerializerContext - { - private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo? _Weather; - - /// - /// Defines the source generated JSON serialization contract metadata for a given type. - /// - #nullable disable annotations // Marking the property type as nullable-oblivious. - public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo Weather - #nullable enable annotations - { - get => _Weather ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo)Options.GetTypeInfo(typeof(global::CSharpToJsonSchema.IntegrationTests.Weather)); - } - - private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo Create_Weather(global::System.Text.Json.JsonSerializerOptions options) - { - if (!TryGetTypeInfoForRuntimeCustomConverter(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo)) - { - var objectInfo = new global::System.Text.Json.Serialization.Metadata.JsonObjectInfoValues - { - ObjectCreator = () => new global::CSharpToJsonSchema.IntegrationTests.Weather(), - ObjectWithParameterizedConstructorCreator = null, - PropertyMetadataInitializer = _ => WeatherPropInit(options), - ConstructorParameterMetadataInitializer = null, - ConstructorAttributeProviderFactory = static () => typeof(global::CSharpToJsonSchema.IntegrationTests.Weather).GetConstructor(InstanceMemberBindingFlags, binder: null, global::System.Array.Empty(), modifiers: null), - SerializeHandler = WeatherSerializeHandler, - }; - - jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateObjectInfo(options, objectInfo); - jsonTypeInfo.NumberHandling = null; - } - - jsonTypeInfo.OriginatingResolver = this; - return jsonTypeInfo; - } - - private static global::System.Text.Json.Serialization.Metadata.JsonPropertyInfo[] WeatherPropInit(global::System.Text.Json.JsonSerializerOptions options) - { - var properties = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfo[4]; - - var info0 = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfoValues - { - IsProperty = true, - IsPublic = true, - IsVirtual = false, - DeclaringType = typeof(global::CSharpToJsonSchema.IntegrationTests.Weather), - Converter = null, - Getter = static obj => ((global::CSharpToJsonSchema.IntegrationTests.Weather)obj).Location, - Setter = static (obj, value) => ((global::CSharpToJsonSchema.IntegrationTests.Weather)obj).Location = value!, - IgnoreCondition = null, - HasJsonInclude = false, - IsExtensionData = false, - NumberHandling = null, - PropertyName = "Location", - JsonPropertyName = null, - AttributeProviderFactory = static () => typeof(global::CSharpToJsonSchema.IntegrationTests.Weather).GetProperty("Location", InstanceMemberBindingFlags, null, typeof(string), global::System.Array.Empty(), null), - }; - - properties[0] = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreatePropertyInfo(options, info0); - - var info1 = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfoValues - { - IsProperty = true, - IsPublic = true, - IsVirtual = false, - DeclaringType = typeof(global::CSharpToJsonSchema.IntegrationTests.Weather), - Converter = null, - Getter = static obj => ((global::CSharpToJsonSchema.IntegrationTests.Weather)obj).Temperature, - Setter = static (obj, value) => ((global::CSharpToJsonSchema.IntegrationTests.Weather)obj).Temperature = value!, - IgnoreCondition = null, - HasJsonInclude = false, - IsExtensionData = false, - NumberHandling = null, - PropertyName = "Temperature", - JsonPropertyName = null, - AttributeProviderFactory = static () => typeof(global::CSharpToJsonSchema.IntegrationTests.Weather).GetProperty("Temperature", InstanceMemberBindingFlags, null, typeof(double), global::System.Array.Empty(), null), - }; - - properties[1] = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreatePropertyInfo(options, info1); - - var info2 = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfoValues - { - IsProperty = true, - IsPublic = true, - IsVirtual = false, - DeclaringType = typeof(global::CSharpToJsonSchema.IntegrationTests.Weather), - Converter = null, - Getter = static obj => ((global::CSharpToJsonSchema.IntegrationTests.Weather)obj).Unit, - Setter = static (obj, value) => ((global::CSharpToJsonSchema.IntegrationTests.Weather)obj).Unit = value!, - IgnoreCondition = null, - HasJsonInclude = false, - IsExtensionData = false, - NumberHandling = null, - PropertyName = "Unit", - JsonPropertyName = null, - AttributeProviderFactory = static () => typeof(global::CSharpToJsonSchema.IntegrationTests.Weather).GetProperty("Unit", InstanceMemberBindingFlags, null, typeof(global::CSharpToJsonSchema.IntegrationTests.Unit), global::System.Array.Empty(), null), - }; - - properties[2] = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreatePropertyInfo(options, info2); - - var info3 = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfoValues - { - IsProperty = true, - IsPublic = true, - IsVirtual = false, - DeclaringType = typeof(global::CSharpToJsonSchema.IntegrationTests.Weather), - Converter = null, - Getter = static obj => ((global::CSharpToJsonSchema.IntegrationTests.Weather)obj).Description, - Setter = static (obj, value) => ((global::CSharpToJsonSchema.IntegrationTests.Weather)obj).Description = value!, - IgnoreCondition = null, - HasJsonInclude = false, - IsExtensionData = false, - NumberHandling = null, - PropertyName = "Description", - JsonPropertyName = null, - AttributeProviderFactory = static () => typeof(global::CSharpToJsonSchema.IntegrationTests.Weather).GetProperty("Description", InstanceMemberBindingFlags, null, typeof(string), global::System.Array.Empty(), null), - }; - - properties[3] = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreatePropertyInfo(options, info3); - - return properties; - } - - // Intentionally not a static method because we create a delegate to it. Invoking delegates to instance - // methods is almost as fast as virtual calls. Static methods need to go through a shuffle thunk. - private void WeatherSerializeHandler(global::System.Text.Json.Utf8JsonWriter writer, global::CSharpToJsonSchema.IntegrationTests.Weather? value) - { - if (value is null) - { - writer.WriteNullValue(); - return; - } - - writer.WriteStartObject(); - - string __value_Location = ((global::CSharpToJsonSchema.IntegrationTests.Weather)value).Location; - if (__value_Location is not null) - { - writer.WriteString(PropName_location, __value_Location); - } - writer.WriteNumber(PropName_temperature, ((global::CSharpToJsonSchema.IntegrationTests.Weather)value).Temperature); - writer.WritePropertyName(PropName_unit); - global::System.Text.Json.JsonSerializer.Serialize(writer, ((global::CSharpToJsonSchema.IntegrationTests.Weather)value).Unit, Unit); - string __value_Description = ((global::CSharpToJsonSchema.IntegrationTests.Weather)value).Description; - if (__value_Description is not null) - { - writer.WriteString(PropName_description, __value_Description); - } - - writer.WriteEndObject(); - } - } -} diff --git a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.g.verified.cs b/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.g.verified.cs deleted file mode 100644 index e0160a5..0000000 --- a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.g.verified.cs +++ /dev/null @@ -1,111 +0,0 @@ -//HintName: IWeatherTools.g.cs -// - -#nullable enable annotations -#nullable disable warnings - -// Suppress warnings about [Obsolete] member usage in generated code. -#pragma warning disable CS0612, CS0618 - -namespace CSharpToJsonSchema.IntegrationTests -{ - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("CSharpToJsonSchema.Generators", "3.0.0.0")] - public partial class WeatherToolsExtensionsJsonSerializerContext - { - private readonly static global::System.Text.Json.JsonSerializerOptions s_defaultOptions = new(global::System.Text.Json.JsonSerializerDefaults.Web) - { - AllowOutOfOrderMetadataProperties = true, - AllowTrailingCommas = false, - DefaultBufferSize = 1024, - DefaultIgnoreCondition = global::System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull, - RespectNullableAnnotations = true, - RespectRequiredConstructorParameters = false, - IgnoreReadOnlyFields = false, - IgnoreReadOnlyProperties = false, - IncludeFields = false, - MaxDepth = 64, - NewLine = "\n", - NumberHandling = global::System.Text.Json.Serialization.JsonNumberHandling.Strict, - PreferredObjectCreationHandling = global::System.Text.Json.Serialization.JsonObjectCreationHandling.Replace, - PropertyNameCaseInsensitive = true, - PropertyNamingPolicy = global::System.Text.Json.JsonNamingPolicy.CamelCase, - ReadCommentHandling = global::System.Text.Json.JsonCommentHandling.Disallow, - UnknownTypeHandling = global::System.Text.Json.Serialization.JsonUnknownTypeHandling.JsonElement, - UnmappedMemberHandling = global::System.Text.Json.Serialization.JsonUnmappedMemberHandling.Skip, - WriteIndented = false, - IndentCharacter = ' ', - IndentSize = 2, - }; - - private const global::System.Reflection.BindingFlags InstanceMemberBindingFlags = - global::System.Reflection.BindingFlags.Instance | - global::System.Reflection.BindingFlags.Public | - global::System.Reflection.BindingFlags.NonPublic; - - /// - /// The default associated with a default instance. - /// - public static global::CSharpToJsonSchema.IntegrationTests.WeatherToolsExtensionsJsonSerializerContext Default { get; } = new global::CSharpToJsonSchema.IntegrationTests.WeatherToolsExtensionsJsonSerializerContext(new global::System.Text.Json.JsonSerializerOptions(s_defaultOptions)); - - /// - /// The source-generated options associated with this context. - /// - protected override global::System.Text.Json.JsonSerializerOptions? GeneratedSerializerOptions { get; } = s_defaultOptions; - - /// - public WeatherToolsExtensionsJsonSerializerContext() : base(null) - { - } - - /// - public WeatherToolsExtensionsJsonSerializerContext(global::System.Text.Json.JsonSerializerOptions options) : base(options) - { - } - - private static bool TryGetTypeInfoForRuntimeCustomConverter(global::System.Text.Json.JsonSerializerOptions options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo) - { - global::System.Text.Json.Serialization.JsonConverter? converter = GetRuntimeConverterForType(typeof(TJsonMetadataType), options); - if (converter != null) - { - jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateValueInfo(options, converter); - return true; - } - - jsonTypeInfo = null; - return false; - } - - private static global::System.Text.Json.Serialization.JsonConverter? GetRuntimeConverterForType(global::System.Type type, global::System.Text.Json.JsonSerializerOptions options) - { - for (int i = 0; i < options.Converters.Count; i++) - { - global::System.Text.Json.Serialization.JsonConverter? converter = options.Converters[i]; - if (converter?.CanConvert(type) == true) - { - return ExpandConverter(type, converter, options, validateCanConvert: false); - } - } - - return null; - } - - private static global::System.Text.Json.Serialization.JsonConverter ExpandConverter(global::System.Type type, global::System.Text.Json.Serialization.JsonConverter converter, global::System.Text.Json.JsonSerializerOptions options, bool validateCanConvert = true) - { - if (validateCanConvert && !converter.CanConvert(type)) - { - throw new global::System.InvalidOperationException(string.Format("The converter '{0}' is not compatible with the type '{1}'.", converter.GetType(), type)); - } - - if (converter is global::System.Text.Json.Serialization.JsonConverterFactory factory) - { - converter = factory.CreateConverter(type, options); - if (converter is null || converter is global::System.Text.Json.Serialization.JsonConverterFactory) - { - throw new global::System.InvalidOperationException(string.Format("The converter '{0}' cannot return null or a JsonConverterFactory instance.", factory.GetType())); - } - } - - return converter; - } - } -} diff --git a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.Calls.generated.verified.cs b/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.Calls.generated.verified.cs deleted file mode 100644 index 80ef1b8..0000000 --- a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.Calls.generated.verified.cs +++ /dev/null @@ -1,195 +0,0 @@ -//HintName: IWeatherStrictTools.Calls.generated.cs -#nullable enable - -namespace CSharpToJsonSchema.IntegrationTests -{ - public class GetCurrentWeather2Args - { - - [global::System.ComponentModel.Description("The city and state, e.g. San Francisco, CA")] - public string? Location { get; set; } = string.Empty; - [global::System.ComponentModel.Description("")] - public CSharpToJsonSchema.IntegrationTests.Unit2 Unit { get; set; } - } - - public class GetCurrentWeatherAsync2Args - { - - [global::System.ComponentModel.Description("The city and state, e.g. San Francisco, CA")] - public string? Location { get; set; } = string.Empty; - [global::System.ComponentModel.Description("")] - public CSharpToJsonSchema.IntegrationTests.Unit2 Unit { get; set; } - } - - public static partial class WeatherStrictToolsExtensions - { - public static global::System.Collections.Generic.IReadOnlyDictionary>> AsCalls(this IWeatherStrictTools service) - { - return new global::System.Collections.Generic.Dictionary>> - { - ["GetCurrentWeather2"] = (json, _) => - { - return global::System.Threading.Tasks.Task.FromResult(service.CallGetCurrentWeather2(json)); - }, - - ["GetCurrentWeatherAsync2"] = async (json, cancellationToken) => - { - return await service.CallGetCurrentWeatherAsync2(json, cancellationToken); - }, - - }; - } - - #pragma warning disable IL2026, IL3050 - public static GetCurrentWeather2Args AsGetCurrentWeather2Args( - this IWeatherStrictTools functions, - string json) - { - #if NET6_0_OR_GREATER - if(global::System.Text.Json.JsonSerializer.IsReflectionEnabledByDefault) - { - - return global::System.Text.Json.JsonSerializer.Deserialize(json, new global::System.Text.Json.JsonSerializerOptions - { - PropertyNamingPolicy = global::System.Text.Json.JsonNamingPolicy.CamelCase, - Converters = {{ new global::System.Text.Json.Serialization.JsonStringEnumConverter(global::System.Text.Json.JsonNamingPolicy.CamelCase) }} - }) ?? - throw new global::System.InvalidOperationException("Could not deserialize JSON."); - - } - else - { - return global::System.Text.Json.JsonSerializer.Deserialize(json, global::CSharpToJsonSchema.IntegrationTests.WeatherStrictToolsExtensionsJsonSerializerContext.Default.GetCurrentWeather2Args) ?? - throw new global::System.InvalidOperationException("Could not deserialize JSON."); - } - #else - return - global::System.Text.Json.JsonSerializer.Deserialize(json, new global::System.Text.Json.JsonSerializerOptions - { - PropertyNamingPolicy = global::System.Text.Json.JsonNamingPolicy.CamelCase, - Converters = {{ new global::System.Text.Json.Serialization.JsonStringEnumConverter(global::System.Text.Json.JsonNamingPolicy.CamelCase) }} - }) ?? - throw new global::System.InvalidOperationException("Could not deserialize JSON."); - #endif - } - #pragma warning restore IL2026, IL3050 - - #pragma warning disable IL2026, IL3050 - public static GetCurrentWeatherAsync2Args AsGetCurrentWeatherAsync2Args( - this IWeatherStrictTools functions, - string json) - { - #if NET6_0_OR_GREATER - if(global::System.Text.Json.JsonSerializer.IsReflectionEnabledByDefault) - { - - return global::System.Text.Json.JsonSerializer.Deserialize(json, new global::System.Text.Json.JsonSerializerOptions - { - PropertyNamingPolicy = global::System.Text.Json.JsonNamingPolicy.CamelCase, - Converters = {{ new global::System.Text.Json.Serialization.JsonStringEnumConverter(global::System.Text.Json.JsonNamingPolicy.CamelCase) }} - }) ?? - throw new global::System.InvalidOperationException("Could not deserialize JSON."); - - } - else - { - return global::System.Text.Json.JsonSerializer.Deserialize(json, global::CSharpToJsonSchema.IntegrationTests.WeatherStrictToolsExtensionsJsonSerializerContext.Default.GetCurrentWeatherAsync2Args) ?? - throw new global::System.InvalidOperationException("Could not deserialize JSON."); - } - #else - return - global::System.Text.Json.JsonSerializer.Deserialize(json, new global::System.Text.Json.JsonSerializerOptions - { - PropertyNamingPolicy = global::System.Text.Json.JsonNamingPolicy.CamelCase, - Converters = {{ new global::System.Text.Json.Serialization.JsonStringEnumConverter(global::System.Text.Json.JsonNamingPolicy.CamelCase) }} - }) ?? - throw new global::System.InvalidOperationException("Could not deserialize JSON."); - #endif - } - #pragma warning restore IL2026, IL3050 - - #pragma warning disable IL2026, IL3050 - public static string CallGetCurrentWeather2(this IWeatherStrictTools functions, string json) - { - var args = functions.AsGetCurrentWeather2Args(json); - var jsonResult = functions.GetCurrentWeather2(args.Location, args.Unit); - - #if NET6_0_OR_GREATER - if(global::System.Text.Json.JsonSerializer.IsReflectionEnabledByDefault) - { - - return global::System.Text.Json.JsonSerializer.Serialize(jsonResult, new global::System.Text.Json.JsonSerializerOptions - { - PropertyNamingPolicy = global::System.Text.Json.JsonNamingPolicy.CamelCase, - Converters = { new global::System.Text.Json.Serialization.JsonStringEnumConverter(global::System.Text.Json.JsonNamingPolicy.CamelCase) }, - }); - - } - else - { - return global::System.Text.Json.JsonSerializer.Serialize(jsonResult, global::CSharpToJsonSchema.IntegrationTests.WeatherStrictToolsExtensionsJsonSerializerContext.Default.GetTypeInfo(jsonResult.GetType())); - } - #else - return global::System.Text.Json.JsonSerializer.Serialize(jsonResult, new global::System.Text.Json.JsonSerializerOptions - { - PropertyNamingPolicy = global::System.Text.Json.JsonNamingPolicy.CamelCase, - Converters = { new global::System.Text.Json.Serialization.JsonStringEnumConverter(global::System.Text.Json.JsonNamingPolicy.CamelCase) }, - }); - #endif - } - #pragma warning restore IL2026, IL3050 - - - #pragma warning disable IL2026, IL3050 - public static async global::System.Threading.Tasks.Task CallGetCurrentWeatherAsync2( - this IWeatherStrictTools functions, - string json, - global::System.Threading.CancellationToken cancellationToken = default) - { - var args = functions.AsGetCurrentWeatherAsync2Args(json); - var jsonResult = await functions.GetCurrentWeatherAsync2(args.Location, args.Unit, cancellationToken); - - #if NET6_0_OR_GREATER - if(global::System.Text.Json.JsonSerializer.IsReflectionEnabledByDefault) - { - - return global::System.Text.Json.JsonSerializer.Serialize(jsonResult, new global::System.Text.Json.JsonSerializerOptions - { - PropertyNamingPolicy = global::System.Text.Json.JsonNamingPolicy.CamelCase, - Converters = { new global::System.Text.Json.Serialization.JsonStringEnumConverter(global::System.Text.Json.JsonNamingPolicy.CamelCase) }, - }); - } - else - { - return global::System.Text.Json.JsonSerializer.Serialize(jsonResult, global::CSharpToJsonSchema.IntegrationTests.WeatherStrictToolsExtensionsJsonSerializerContext.Default.GetTypeInfo(jsonResult.GetType())); - } - #else - return global::System.Text.Json.JsonSerializer.Serialize(jsonResult, new global::System.Text.Json.JsonSerializerOptions - { - PropertyNamingPolicy = global::System.Text.Json.JsonNamingPolicy.CamelCase, - Converters = { new global::System.Text.Json.Serialization.JsonStringEnumConverter(global::System.Text.Json.JsonNamingPolicy.CamelCase) }, - }); - #endif - - } - #pragma warning restore IL2026, IL3050 - - - - public static async global::System.Threading.Tasks.Task CallAsync( - this IWeatherStrictTools service, - string functionName, - string argumentsAsJson, - global::System.Threading.CancellationToken cancellationToken = default) - { - var calls = service.AsCalls(); - var func = calls[functionName]; - - return await func(argumentsAsJson, cancellationToken); - } - } - - public partial class WeatherStrictToolsExtensionsJsonSerializerContext: global::System.Text.Json.Serialization.JsonSerializerContext - { - } -} \ No newline at end of file diff --git a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.Double.g.verified.cs b/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.Double.g.verified.cs deleted file mode 100644 index 452fe78..0000000 --- a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.Double.g.verified.cs +++ /dev/null @@ -1,37 +0,0 @@ -//HintName: IWeatherStrictTools.Double.g.cs -// - -#nullable enable annotations -#nullable disable warnings - -// Suppress warnings about [Obsolete] member usage in generated code. -#pragma warning disable CS0612, CS0618 - -namespace CSharpToJsonSchema.IntegrationTests -{ - public partial class WeatherStrictToolsExtensionsJsonSerializerContext - { - private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo? _Double; - - /// - /// Defines the source generated JSON serialization contract metadata for a given type. - /// - #nullable disable annotations // Marking the property type as nullable-oblivious. - public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo Double - #nullable enable annotations - { - get => _Double ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo)Options.GetTypeInfo(typeof(double)); - } - - private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo Create_Double(global::System.Text.Json.JsonSerializerOptions options) - { - if (!TryGetTypeInfoForRuntimeCustomConverter(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo)) - { - jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateValueInfo(options, global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.DoubleConverter); - } - - jsonTypeInfo.OriginatingResolver = this; - return jsonTypeInfo; - } - } -} diff --git a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.GetCurrentWeather2Args.g.verified.cs b/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.GetCurrentWeather2Args.g.verified.cs deleted file mode 100644 index 2d4e52f..0000000 --- a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.GetCurrentWeather2Args.g.verified.cs +++ /dev/null @@ -1,118 +0,0 @@ -//HintName: IWeatherStrictTools.GetCurrentWeather2Args.g.cs -// - -#nullable enable annotations -#nullable disable warnings - -// Suppress warnings about [Obsolete] member usage in generated code. -#pragma warning disable CS0612, CS0618 - -namespace CSharpToJsonSchema.IntegrationTests -{ - public partial class WeatherStrictToolsExtensionsJsonSerializerContext - { - private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo? _GetCurrentWeather2Args; - - /// - /// Defines the source generated JSON serialization contract metadata for a given type. - /// - #nullable disable annotations // Marking the property type as nullable-oblivious. - public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo GetCurrentWeather2Args - #nullable enable annotations - { - get => _GetCurrentWeather2Args ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo)Options.GetTypeInfo(typeof(global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeather2Args)); - } - - private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo Create_GetCurrentWeather2Args(global::System.Text.Json.JsonSerializerOptions options) - { - if (!TryGetTypeInfoForRuntimeCustomConverter(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo)) - { - var objectInfo = new global::System.Text.Json.Serialization.Metadata.JsonObjectInfoValues - { - ObjectCreator = () => new global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeather2Args(), - ObjectWithParameterizedConstructorCreator = null, - PropertyMetadataInitializer = _ => GetCurrentWeather2ArgsPropInit(options), - ConstructorParameterMetadataInitializer = null, - ConstructorAttributeProviderFactory = static () => typeof(global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeather2Args).GetConstructor(InstanceMemberBindingFlags, binder: null, global::System.Array.Empty(), modifiers: null), - SerializeHandler = GetCurrentWeather2ArgsSerializeHandler, - }; - - jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateObjectInfo(options, objectInfo); - jsonTypeInfo.NumberHandling = null; - } - - jsonTypeInfo.OriginatingResolver = this; - return jsonTypeInfo; - } - - private static global::System.Text.Json.Serialization.Metadata.JsonPropertyInfo[] GetCurrentWeather2ArgsPropInit(global::System.Text.Json.JsonSerializerOptions options) - { - var properties = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfo[2]; - - var info0 = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfoValues - { - IsProperty = true, - IsPublic = true, - IsVirtual = false, - DeclaringType = typeof(global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeather2Args), - Converter = null, - Getter = static obj => ((global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeather2Args)obj).Location, - Setter = static (obj, value) => ((global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeather2Args)obj).Location = value!, - IgnoreCondition = null, - HasJsonInclude = false, - IsExtensionData = false, - NumberHandling = null, - PropertyName = "Location", - JsonPropertyName = null, - AttributeProviderFactory = static () => typeof(global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeather2Args).GetProperty("Location", InstanceMemberBindingFlags, null, typeof(string), global::System.Array.Empty(), null), - }; - - properties[0] = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreatePropertyInfo(options, info0); - - var info1 = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfoValues - { - IsProperty = true, - IsPublic = true, - IsVirtual = false, - DeclaringType = typeof(global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeather2Args), - Converter = null, - Getter = static obj => ((global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeather2Args)obj).Unit, - Setter = static (obj, value) => ((global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeather2Args)obj).Unit = value!, - IgnoreCondition = null, - HasJsonInclude = false, - IsExtensionData = false, - NumberHandling = null, - PropertyName = "Unit", - JsonPropertyName = null, - AttributeProviderFactory = static () => typeof(global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeather2Args).GetProperty("Unit", InstanceMemberBindingFlags, null, typeof(global::CSharpToJsonSchema.IntegrationTests.Unit2), global::System.Array.Empty(), null), - }; - - properties[1] = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreatePropertyInfo(options, info1); - - return properties; - } - - // Intentionally not a static method because we create a delegate to it. Invoking delegates to instance - // methods is almost as fast as virtual calls. Static methods need to go through a shuffle thunk. - private void GetCurrentWeather2ArgsSerializeHandler(global::System.Text.Json.Utf8JsonWriter writer, global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeather2Args? value) - { - if (value is null) - { - writer.WriteNullValue(); - return; - } - - writer.WriteStartObject(); - - string __value_Location = ((global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeather2Args)value).Location; - if (__value_Location is not null) - { - writer.WriteString(PropName_location, __value_Location); - } - writer.WritePropertyName(PropName_unit); - global::System.Text.Json.JsonSerializer.Serialize(writer, ((global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeather2Args)value).Unit, Unit2); - - writer.WriteEndObject(); - } - } -} diff --git a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.GetCurrentWeatherAsync2Args.g.verified.cs b/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.GetCurrentWeatherAsync2Args.g.verified.cs deleted file mode 100644 index 715c33e..0000000 --- a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.GetCurrentWeatherAsync2Args.g.verified.cs +++ /dev/null @@ -1,118 +0,0 @@ -//HintName: IWeatherStrictTools.GetCurrentWeatherAsync2Args.g.cs -// - -#nullable enable annotations -#nullable disable warnings - -// Suppress warnings about [Obsolete] member usage in generated code. -#pragma warning disable CS0612, CS0618 - -namespace CSharpToJsonSchema.IntegrationTests -{ - public partial class WeatherStrictToolsExtensionsJsonSerializerContext - { - private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo? _GetCurrentWeatherAsync2Args; - - /// - /// Defines the source generated JSON serialization contract metadata for a given type. - /// - #nullable disable annotations // Marking the property type as nullable-oblivious. - public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo GetCurrentWeatherAsync2Args - #nullable enable annotations - { - get => _GetCurrentWeatherAsync2Args ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo)Options.GetTypeInfo(typeof(global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeatherAsync2Args)); - } - - private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo Create_GetCurrentWeatherAsync2Args(global::System.Text.Json.JsonSerializerOptions options) - { - if (!TryGetTypeInfoForRuntimeCustomConverter(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo)) - { - var objectInfo = new global::System.Text.Json.Serialization.Metadata.JsonObjectInfoValues - { - ObjectCreator = () => new global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeatherAsync2Args(), - ObjectWithParameterizedConstructorCreator = null, - PropertyMetadataInitializer = _ => GetCurrentWeatherAsync2ArgsPropInit(options), - ConstructorParameterMetadataInitializer = null, - ConstructorAttributeProviderFactory = static () => typeof(global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeatherAsync2Args).GetConstructor(InstanceMemberBindingFlags, binder: null, global::System.Array.Empty(), modifiers: null), - SerializeHandler = GetCurrentWeatherAsync2ArgsSerializeHandler, - }; - - jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateObjectInfo(options, objectInfo); - jsonTypeInfo.NumberHandling = null; - } - - jsonTypeInfo.OriginatingResolver = this; - return jsonTypeInfo; - } - - private static global::System.Text.Json.Serialization.Metadata.JsonPropertyInfo[] GetCurrentWeatherAsync2ArgsPropInit(global::System.Text.Json.JsonSerializerOptions options) - { - var properties = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfo[2]; - - var info0 = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfoValues - { - IsProperty = true, - IsPublic = true, - IsVirtual = false, - DeclaringType = typeof(global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeatherAsync2Args), - Converter = null, - Getter = static obj => ((global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeatherAsync2Args)obj).Location, - Setter = static (obj, value) => ((global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeatherAsync2Args)obj).Location = value!, - IgnoreCondition = null, - HasJsonInclude = false, - IsExtensionData = false, - NumberHandling = null, - PropertyName = "Location", - JsonPropertyName = null, - AttributeProviderFactory = static () => typeof(global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeatherAsync2Args).GetProperty("Location", InstanceMemberBindingFlags, null, typeof(string), global::System.Array.Empty(), null), - }; - - properties[0] = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreatePropertyInfo(options, info0); - - var info1 = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfoValues - { - IsProperty = true, - IsPublic = true, - IsVirtual = false, - DeclaringType = typeof(global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeatherAsync2Args), - Converter = null, - Getter = static obj => ((global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeatherAsync2Args)obj).Unit, - Setter = static (obj, value) => ((global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeatherAsync2Args)obj).Unit = value!, - IgnoreCondition = null, - HasJsonInclude = false, - IsExtensionData = false, - NumberHandling = null, - PropertyName = "Unit", - JsonPropertyName = null, - AttributeProviderFactory = static () => typeof(global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeatherAsync2Args).GetProperty("Unit", InstanceMemberBindingFlags, null, typeof(global::CSharpToJsonSchema.IntegrationTests.Unit2), global::System.Array.Empty(), null), - }; - - properties[1] = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreatePropertyInfo(options, info1); - - return properties; - } - - // Intentionally not a static method because we create a delegate to it. Invoking delegates to instance - // methods is almost as fast as virtual calls. Static methods need to go through a shuffle thunk. - private void GetCurrentWeatherAsync2ArgsSerializeHandler(global::System.Text.Json.Utf8JsonWriter writer, global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeatherAsync2Args? value) - { - if (value is null) - { - writer.WriteNullValue(); - return; - } - - writer.WriteStartObject(); - - string __value_Location = ((global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeatherAsync2Args)value).Location; - if (__value_Location is not null) - { - writer.WriteString(PropName_location, __value_Location); - } - writer.WritePropertyName(PropName_unit); - global::System.Text.Json.JsonSerializer.Serialize(writer, ((global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeatherAsync2Args)value).Unit, Unit2); - - writer.WriteEndObject(); - } - } -} diff --git a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.GetJsonTypeInfo.g.verified.cs b/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.GetJsonTypeInfo.g.verified.cs deleted file mode 100644 index 1b7617b..0000000 --- a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.GetJsonTypeInfo.g.verified.cs +++ /dev/null @@ -1,50 +0,0 @@ -//HintName: IWeatherStrictTools.GetJsonTypeInfo.g.cs -// - -#nullable enable annotations -#nullable disable warnings - -// Suppress warnings about [Obsolete] member usage in generated code. -#pragma warning disable CS0612, CS0618 - -namespace CSharpToJsonSchema.IntegrationTests -{ - public partial class WeatherStrictToolsExtensionsJsonSerializerContext : global::System.Text.Json.Serialization.Metadata.IJsonTypeInfoResolver - { - /// - public override global::System.Text.Json.Serialization.Metadata.JsonTypeInfo? GetTypeInfo(global::System.Type type) - { - Options.TryGetTypeInfo(type, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo? typeInfo); - return typeInfo; - } - - global::System.Text.Json.Serialization.Metadata.JsonTypeInfo? global::System.Text.Json.Serialization.Metadata.IJsonTypeInfoResolver.GetTypeInfo(global::System.Type type, global::System.Text.Json.JsonSerializerOptions options) - { - if (type == typeof(double)) - { - return Create_Double(options); - } - if (type == typeof(global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeather2Args)) - { - return Create_GetCurrentWeather2Args(options); - } - if (type == typeof(global::CSharpToJsonSchema.IntegrationTests.GetCurrentWeatherAsync2Args)) - { - return Create_GetCurrentWeatherAsync2Args(options); - } - if (type == typeof(global::CSharpToJsonSchema.IntegrationTests.Unit2)) - { - return Create_Unit2(options); - } - if (type == typeof(global::CSharpToJsonSchema.IntegrationTests.Weather2)) - { - return Create_Weather2(options); - } - if (type == typeof(string)) - { - return Create_String(options); - } - return null; - } - } -} diff --git a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.PropertyNames.g.verified.cs b/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.PropertyNames.g.verified.cs deleted file mode 100644 index a8edc96..0000000 --- a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.PropertyNames.g.verified.cs +++ /dev/null @@ -1,19 +0,0 @@ -//HintName: IWeatherStrictTools.PropertyNames.g.cs -// - -#nullable enable annotations -#nullable disable warnings - -// Suppress warnings about [Obsolete] member usage in generated code. -#pragma warning disable CS0612, CS0618 - -namespace CSharpToJsonSchema.IntegrationTests -{ - public partial class WeatherStrictToolsExtensionsJsonSerializerContext - { - private static readonly global::System.Text.Json.JsonEncodedText PropName_location = global::System.Text.Json.JsonEncodedText.Encode("location"); - private static readonly global::System.Text.Json.JsonEncodedText PropName_unit = global::System.Text.Json.JsonEncodedText.Encode("unit"); - private static readonly global::System.Text.Json.JsonEncodedText PropName_temperature = global::System.Text.Json.JsonEncodedText.Encode("temperature"); - private static readonly global::System.Text.Json.JsonEncodedText PropName_description = global::System.Text.Json.JsonEncodedText.Encode("description"); - } -} diff --git a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.String.g.verified.cs b/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.String.g.verified.cs deleted file mode 100644 index 004080e..0000000 --- a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.String.g.verified.cs +++ /dev/null @@ -1,37 +0,0 @@ -//HintName: IWeatherStrictTools.String.g.cs -// - -#nullable enable annotations -#nullable disable warnings - -// Suppress warnings about [Obsolete] member usage in generated code. -#pragma warning disable CS0612, CS0618 - -namespace CSharpToJsonSchema.IntegrationTests -{ - public partial class WeatherStrictToolsExtensionsJsonSerializerContext - { - private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo? _String; - - /// - /// Defines the source generated JSON serialization contract metadata for a given type. - /// - #nullable disable annotations // Marking the property type as nullable-oblivious. - public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo String - #nullable enable annotations - { - get => _String ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo)Options.GetTypeInfo(typeof(string)); - } - - private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo Create_String(global::System.Text.Json.JsonSerializerOptions options) - { - if (!TryGetTypeInfoForRuntimeCustomConverter(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo)) - { - jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateValueInfo(options, global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.StringConverter); - } - - jsonTypeInfo.OriginatingResolver = this; - return jsonTypeInfo; - } - } -} diff --git a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.Tools.generated.verified.cs b/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.Tools.generated.verified.cs deleted file mode 100644 index d1aa605..0000000 --- a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.Tools.generated.verified.cs +++ /dev/null @@ -1,31 +0,0 @@ -//HintName: IWeatherStrictTools.Tools.generated.cs - -#nullable enable - -namespace CSharpToJsonSchema.IntegrationTests -{ - public static partial class WeatherStrictToolsExtensions - { - public static global::System.Collections.Generic.IList AsTools(this IWeatherStrictTools functions) - { - return new global::System.Collections.Generic.List - { - new global::CSharpToJsonSchema.Tool - { - Name = "GetCurrentWeather2", - Description = "Get the current weather in a given location", - Strict = true, - Parameters = global::CSharpToJsonSchema.SchemaBuilder.ConvertToSchema(global::CSharpToJsonSchema.IntegrationTests.WeatherStrictToolsExtensionsJsonSerializerContext.Default.GetCurrentWeather2Args,"{\"location\":\"The city and state, e.g. San Francisco, CA\", \"unit\":\"\", \"mainFunction_Desc\":\"Get the current weather in a given location\"}"), - }, - - new global::CSharpToJsonSchema.Tool - { - Name = "GetCurrentWeatherAsync2", - Description = "Get the current weather in a given location", - Strict = true, - Parameters = global::CSharpToJsonSchema.SchemaBuilder.ConvertToSchema(global::CSharpToJsonSchema.IntegrationTests.WeatherStrictToolsExtensionsJsonSerializerContext.Default.GetCurrentWeatherAsync2Args,"{\"location\":\"The city and state, e.g. San Francisco, CA\", \"unit\":\"\", \"mainFunction_Desc\":\"Get the current weather in a given location\"}"), - }, - }; - } - } -} \ No newline at end of file diff --git a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.Unit2.g.verified.cs b/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.Unit2.g.verified.cs deleted file mode 100644 index c3526ac..0000000 --- a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.Unit2.g.verified.cs +++ /dev/null @@ -1,38 +0,0 @@ -//HintName: IWeatherStrictTools.Unit2.g.cs -// - -#nullable enable annotations -#nullable disable warnings - -// Suppress warnings about [Obsolete] member usage in generated code. -#pragma warning disable CS0612, CS0618 - -namespace CSharpToJsonSchema.IntegrationTests -{ - public partial class WeatherStrictToolsExtensionsJsonSerializerContext - { - private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo? _Unit2; - - /// - /// Defines the source generated JSON serialization contract metadata for a given type. - /// - #nullable disable annotations // Marking the property type as nullable-oblivious. - public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo Unit2 - #nullable enable annotations - { - get => _Unit2 ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo)Options.GetTypeInfo(typeof(global::CSharpToJsonSchema.IntegrationTests.Unit2)); - } - - private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo Create_Unit2(global::System.Text.Json.JsonSerializerOptions options) - { - if (!TryGetTypeInfoForRuntimeCustomConverter(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo)) - { - global::System.Text.Json.Serialization.JsonConverter converter = ExpandConverter(typeof(global::CSharpToJsonSchema.IntegrationTests.Unit2), new global::System.Text.Json.Serialization.JsonStringEnumConverter(), options); - jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateValueInfo (options, converter); - } - - jsonTypeInfo.OriginatingResolver = this; - return jsonTypeInfo; - } - } -} diff --git a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.Weather2.g.verified.cs b/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.Weather2.g.verified.cs deleted file mode 100644 index 56c793b..0000000 --- a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.Weather2.g.verified.cs +++ /dev/null @@ -1,164 +0,0 @@ -//HintName: IWeatherStrictTools.Weather2.g.cs -// - -#nullable enable annotations -#nullable disable warnings - -// Suppress warnings about [Obsolete] member usage in generated code. -#pragma warning disable CS0612, CS0618 - -namespace CSharpToJsonSchema.IntegrationTests -{ - public partial class WeatherStrictToolsExtensionsJsonSerializerContext - { - private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo? _Weather2; - - /// - /// Defines the source generated JSON serialization contract metadata for a given type. - /// - #nullable disable annotations // Marking the property type as nullable-oblivious. - public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo Weather2 - #nullable enable annotations - { - get => _Weather2 ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo)Options.GetTypeInfo(typeof(global::CSharpToJsonSchema.IntegrationTests.Weather2)); - } - - private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo Create_Weather2(global::System.Text.Json.JsonSerializerOptions options) - { - if (!TryGetTypeInfoForRuntimeCustomConverter(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo)) - { - var objectInfo = new global::System.Text.Json.Serialization.Metadata.JsonObjectInfoValues - { - ObjectCreator = () => new global::CSharpToJsonSchema.IntegrationTests.Weather2(), - ObjectWithParameterizedConstructorCreator = null, - PropertyMetadataInitializer = _ => Weather2PropInit(options), - ConstructorParameterMetadataInitializer = null, - ConstructorAttributeProviderFactory = static () => typeof(global::CSharpToJsonSchema.IntegrationTests.Weather2).GetConstructor(InstanceMemberBindingFlags, binder: null, global::System.Array.Empty(), modifiers: null), - SerializeHandler = Weather2SerializeHandler, - }; - - jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateObjectInfo(options, objectInfo); - jsonTypeInfo.NumberHandling = null; - } - - jsonTypeInfo.OriginatingResolver = this; - return jsonTypeInfo; - } - - private static global::System.Text.Json.Serialization.Metadata.JsonPropertyInfo[] Weather2PropInit(global::System.Text.Json.JsonSerializerOptions options) - { - var properties = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfo[4]; - - var info0 = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfoValues - { - IsProperty = true, - IsPublic = true, - IsVirtual = false, - DeclaringType = typeof(global::CSharpToJsonSchema.IntegrationTests.Weather2), - Converter = null, - Getter = static obj => ((global::CSharpToJsonSchema.IntegrationTests.Weather2)obj).Location, - Setter = static (obj, value) => ((global::CSharpToJsonSchema.IntegrationTests.Weather2)obj).Location = value!, - IgnoreCondition = null, - HasJsonInclude = false, - IsExtensionData = false, - NumberHandling = null, - PropertyName = "Location", - JsonPropertyName = null, - AttributeProviderFactory = static () => typeof(global::CSharpToJsonSchema.IntegrationTests.Weather2).GetProperty("Location", InstanceMemberBindingFlags, null, typeof(string), global::System.Array.Empty(), null), - }; - - properties[0] = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreatePropertyInfo(options, info0); - - var info1 = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfoValues - { - IsProperty = true, - IsPublic = true, - IsVirtual = false, - DeclaringType = typeof(global::CSharpToJsonSchema.IntegrationTests.Weather2), - Converter = null, - Getter = static obj => ((global::CSharpToJsonSchema.IntegrationTests.Weather2)obj).Temperature, - Setter = static (obj, value) => ((global::CSharpToJsonSchema.IntegrationTests.Weather2)obj).Temperature = value!, - IgnoreCondition = null, - HasJsonInclude = false, - IsExtensionData = false, - NumberHandling = null, - PropertyName = "Temperature", - JsonPropertyName = null, - AttributeProviderFactory = static () => typeof(global::CSharpToJsonSchema.IntegrationTests.Weather2).GetProperty("Temperature", InstanceMemberBindingFlags, null, typeof(double), global::System.Array.Empty(), null), - }; - - properties[1] = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreatePropertyInfo(options, info1); - - var info2 = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfoValues - { - IsProperty = true, - IsPublic = true, - IsVirtual = false, - DeclaringType = typeof(global::CSharpToJsonSchema.IntegrationTests.Weather2), - Converter = null, - Getter = static obj => ((global::CSharpToJsonSchema.IntegrationTests.Weather2)obj).Unit, - Setter = static (obj, value) => ((global::CSharpToJsonSchema.IntegrationTests.Weather2)obj).Unit = value!, - IgnoreCondition = null, - HasJsonInclude = false, - IsExtensionData = false, - NumberHandling = null, - PropertyName = "Unit", - JsonPropertyName = null, - AttributeProviderFactory = static () => typeof(global::CSharpToJsonSchema.IntegrationTests.Weather2).GetProperty("Unit", InstanceMemberBindingFlags, null, typeof(global::CSharpToJsonSchema.IntegrationTests.Unit2), global::System.Array.Empty(), null), - }; - - properties[2] = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreatePropertyInfo(options, info2); - - var info3 = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfoValues - { - IsProperty = true, - IsPublic = true, - IsVirtual = false, - DeclaringType = typeof(global::CSharpToJsonSchema.IntegrationTests.Weather2), - Converter = null, - Getter = static obj => ((global::CSharpToJsonSchema.IntegrationTests.Weather2)obj).Description, - Setter = static (obj, value) => ((global::CSharpToJsonSchema.IntegrationTests.Weather2)obj).Description = value!, - IgnoreCondition = null, - HasJsonInclude = false, - IsExtensionData = false, - NumberHandling = null, - PropertyName = "Description", - JsonPropertyName = null, - AttributeProviderFactory = static () => typeof(global::CSharpToJsonSchema.IntegrationTests.Weather2).GetProperty("Description", InstanceMemberBindingFlags, null, typeof(string), global::System.Array.Empty(), null), - }; - - properties[3] = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreatePropertyInfo(options, info3); - - return properties; - } - - // Intentionally not a static method because we create a delegate to it. Invoking delegates to instance - // methods is almost as fast as virtual calls. Static methods need to go through a shuffle thunk. - private void Weather2SerializeHandler(global::System.Text.Json.Utf8JsonWriter writer, global::CSharpToJsonSchema.IntegrationTests.Weather2? value) - { - if (value is null) - { - writer.WriteNullValue(); - return; - } - - writer.WriteStartObject(); - - string __value_Location = ((global::CSharpToJsonSchema.IntegrationTests.Weather2)value).Location; - if (__value_Location is not null) - { - writer.WriteString(PropName_location, __value_Location); - } - writer.WriteNumber(PropName_temperature, ((global::CSharpToJsonSchema.IntegrationTests.Weather2)value).Temperature); - writer.WritePropertyName(PropName_unit); - global::System.Text.Json.JsonSerializer.Serialize(writer, ((global::CSharpToJsonSchema.IntegrationTests.Weather2)value).Unit, Unit2); - string __value_Description = ((global::CSharpToJsonSchema.IntegrationTests.Weather2)value).Description; - if (__value_Description is not null) - { - writer.WriteString(PropName_description, __value_Description); - } - - writer.WriteEndObject(); - } - } -} diff --git a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.g.verified.cs b/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.g.received.cs similarity index 99% rename from src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.g.verified.cs rename to src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.g.received.cs index 5869fdd..e949778 100644 --- a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.g.verified.cs +++ b/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.g.received.cs @@ -9,7 +9,7 @@ namespace CSharpToJsonSchema.IntegrationTests { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("CSharpToJsonSchema.Generators", "3.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("CSharpToJsonSchema.Generators", "0.0.0.0")] public partial class WeatherStrictToolsExtensionsJsonSerializerContext { private readonly static global::System.Text.Json.JsonSerializerOptions s_defaultOptions = new(global::System.Text.Json.JsonSerializerDefaults.Web) diff --git a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict_Diagnostics.verified.txt b/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict_Diagnostics.verified.txt deleted file mode 100644 index ad47dbb..0000000 --- a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict_Diagnostics.verified.txt +++ /dev/null @@ -1 +0,0 @@ -[] \ No newline at end of file diff --git a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather_Diagnostics.verified.txt b/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather_Diagnostics.verified.txt deleted file mode 100644 index ad47dbb..0000000 --- a/src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather_Diagnostics.verified.txt +++ /dev/null @@ -1 +0,0 @@ -[] \ No newline at end of file