Add the client model step and implement it for models and serializers (#265)
This commit is contained in:
Родитель
1ec432cc56
Коммит
1889cbd7d8
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"sdk":
|
||||
{
|
||||
"version": "3.0.100"
|
||||
}
|
||||
}
|
|
@ -3,7 +3,7 @@
|
|||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
<Nullable>annotations</Nullable>
|
||||
<Nullable>enable</Nullable>
|
||||
<RunAnalyzersDuringBuild>true</RunAnalyzersDuringBuild>
|
||||
<RunAnalyzersDuringLiveAnalysis>false</RunAnalyzersDuringLiveAnalysis>
|
||||
</PropertyGroup>
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
||||
namespace AutoRest.CSharp.V3.ClientModel
|
||||
{
|
||||
internal struct ClientConstant
|
||||
{
|
||||
public ClientConstant(object value, FrameworkTypeReference type)
|
||||
{
|
||||
Value = value;
|
||||
Type = type;
|
||||
}
|
||||
|
||||
public object Value { get; }
|
||||
public FrameworkTypeReference Type { get; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using AutoRest.CSharp.V3.Pipeline.Generated;
|
||||
|
||||
namespace AutoRest.CSharp.V3.ClientModel
|
||||
{
|
||||
internal class ClientEnum : ClientModel, ISchemaTypeProvider
|
||||
{
|
||||
public ClientEnum(Schema schema, string name, IEnumerable<ClientEnumValue> values)
|
||||
{
|
||||
Schema = schema;
|
||||
Name = name;
|
||||
Values = new List<ClientEnumValue>(values);
|
||||
}
|
||||
|
||||
public bool IsStringBased { get; set; }
|
||||
public Schema Schema { get; }
|
||||
public override string Name { get; }
|
||||
public IList<ClientEnumValue> Values { get; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
||||
namespace AutoRest.CSharp.V3.ClientModel
|
||||
{
|
||||
internal class ClientEnumValue
|
||||
{
|
||||
public ClientEnumValue(string name, ClientConstant value)
|
||||
{
|
||||
Name = name;
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public string Name { get; }
|
||||
public ClientConstant Value { get; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
||||
namespace AutoRest.CSharp.V3.ClientModel
|
||||
{
|
||||
internal abstract class ClientModel
|
||||
{
|
||||
public abstract string Name { get; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using AutoRest.CSharp.V3.Pipeline.Generated;
|
||||
|
||||
namespace AutoRest.CSharp.V3.ClientModel
|
||||
{
|
||||
internal class ClientObject : ClientModel, ISchemaTypeProvider
|
||||
{
|
||||
public ClientObject(Schema schema, string name, IEnumerable<ClientObjectProperty> properties, IEnumerable<ClientObjectConstant> constants)
|
||||
{
|
||||
Schema = schema;
|
||||
Name = name;
|
||||
Properties = new List<ClientObjectProperty>(properties);
|
||||
Constants = new List<ClientObjectConstant>(constants);
|
||||
}
|
||||
|
||||
public override string Name { get; }
|
||||
public Schema Schema { get; }
|
||||
|
||||
public IList<ClientObjectConstant> Constants { get; }
|
||||
public IList<ClientObjectProperty> Properties { get; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
||||
namespace AutoRest.CSharp.V3.ClientModel
|
||||
{
|
||||
internal class ClientObjectConstant
|
||||
{
|
||||
public ClientObjectConstant(string name, FrameworkTypeReference type, ClientConstant value)
|
||||
{
|
||||
Name = name;
|
||||
Type = type;
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public string Name { get; }
|
||||
public ClientTypeReference Type { get; }
|
||||
public ClientConstant Value { get; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
||||
namespace AutoRest.CSharp.V3.ClientModel
|
||||
{
|
||||
internal class ClientObjectProperty
|
||||
{
|
||||
public ClientObjectProperty(string name, ClientTypeReference type, bool isReadOnly, string serializedName)
|
||||
{
|
||||
Name = name;
|
||||
Type = type;
|
||||
IsReadOnly = isReadOnly;
|
||||
SerializedName = serializedName;
|
||||
}
|
||||
|
||||
public string Name { get; }
|
||||
public ClientTypeReference Type { get; }
|
||||
public bool IsReadOnly { get; }
|
||||
public string SerializedName { get; set; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
||||
namespace AutoRest.CSharp.V3.ClientModel
|
||||
{
|
||||
internal abstract class ClientTypeReference
|
||||
{
|
||||
public abstract bool IsNullable { get; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
||||
namespace AutoRest.CSharp.V3.ClientModel
|
||||
{
|
||||
internal class CollectionTypeReference : ClientTypeReference
|
||||
{
|
||||
public ClientTypeReference ItemType { get; }
|
||||
|
||||
public CollectionTypeReference(ClientTypeReference itemType)
|
||||
{
|
||||
ItemType = itemType;
|
||||
}
|
||||
|
||||
public override bool IsNullable => false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
||||
namespace AutoRest.CSharp.V3.ClientModel
|
||||
{
|
||||
internal class DictionaryTypeReference: ClientTypeReference
|
||||
{
|
||||
public ClientTypeReference KeyType { get; }
|
||||
public ClientTypeReference ValueType { get; }
|
||||
|
||||
public DictionaryTypeReference(ClientTypeReference keyType, ClientTypeReference valueType)
|
||||
{
|
||||
KeyType = keyType;
|
||||
ValueType = valueType;
|
||||
}
|
||||
|
||||
public override bool IsNullable => false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
|
||||
namespace AutoRest.CSharp.V3.ClientModel
|
||||
{
|
||||
internal class FrameworkTypeReference: ClientTypeReference
|
||||
{
|
||||
public Type Type { get; }
|
||||
public override bool IsNullable { get; }
|
||||
|
||||
public FrameworkTypeReference(Type type, bool isNullable = false)
|
||||
{
|
||||
Type = type;
|
||||
IsNullable = isNullable;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
||||
using AutoRest.CSharp.V3.Pipeline.Generated;
|
||||
|
||||
namespace AutoRest.CSharp.V3.ClientModel
|
||||
{
|
||||
internal interface ISchemaTypeProvider
|
||||
{
|
||||
string Name { get; }
|
||||
Schema Schema { get; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
||||
using AutoRest.CSharp.V3.Pipeline.Generated;
|
||||
|
||||
namespace AutoRest.CSharp.V3.ClientModel
|
||||
{
|
||||
internal class SchemaTypeReference: ClientTypeReference
|
||||
{
|
||||
public Schema Schema { get; }
|
||||
|
||||
public SchemaTypeReference(Schema schema, bool isNullable)
|
||||
{
|
||||
Schema = schema;
|
||||
IsNullable = isNullable;
|
||||
}
|
||||
|
||||
public override bool IsNullable { get; }
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
|
@ -118,33 +119,18 @@ namespace AutoRest.CSharp.V3.CodeGen
|
|||
//TODO: Handle multiple responses
|
||||
var schemaResponse = operation.Responses?.FirstOrDefault() as SchemaResponse;
|
||||
CSharpType returnType;
|
||||
CSharpType responseType = null;
|
||||
CSharpType? responseType = null;
|
||||
bool hasResponse = false;
|
||||
|
||||
if (schemaResponse != null)
|
||||
{
|
||||
hasResponse = true;
|
||||
responseType = _typeFactory.CreateType(schemaResponse?.Schema);
|
||||
returnType = new CSharpType
|
||||
{
|
||||
FrameworkType = typeof(ValueTask<>),
|
||||
SubType1 = new CSharpType
|
||||
{
|
||||
FrameworkType = typeof(Response<>),
|
||||
SubType1 = responseType
|
||||
}
|
||||
};
|
||||
responseType = _typeFactory.CreateType(schemaResponse.Schema);
|
||||
returnType = new CSharpType(typeof(ValueTask<>), new CSharpType(typeof(Response<>), responseType));
|
||||
}
|
||||
else
|
||||
{
|
||||
returnType = new CSharpType
|
||||
{
|
||||
FrameworkType = typeof(ValueTask<>),
|
||||
SubType1 = new CSharpType
|
||||
{
|
||||
FrameworkType = typeof(Response)
|
||||
}
|
||||
};
|
||||
returnType = new CSharpType(typeof(ValueTask<>), new CSharpType(typeof(Response)));
|
||||
}
|
||||
|
||||
var httpRequest = operation.Request.Protocol.Http as HttpRequest;
|
||||
|
@ -160,8 +146,9 @@ namespace AutoRest.CSharp.V3.CodeGen
|
|||
.OrderBy(p => (p.Parameter.IsNullable()) || (p.Parameter.ClientDefaultValue != null)).Select(p =>
|
||||
{
|
||||
var (parameter, _) = p;
|
||||
var pair = Pair(_typeFactory.CreateInputType(parameter.Schema) ?? _typeFactory.CreateType(parameter.Schema), parameter.CSharpName(), parameter?.IsNullable());
|
||||
var shouldBeDefaulted = (parameter?.IsNullable() ?? false) || (parameter!.ClientDefaultValue != null);
|
||||
Debug.Assert(parameter != null);
|
||||
var pair = Pair(_typeFactory.CreateInputType(parameter.Schema).WithNullable(parameter.IsNullable()), parameter.CSharpName());
|
||||
var shouldBeDefaulted = parameter.IsNullable() || parameter.ClientDefaultValue != null;
|
||||
//TODO: This will only work if the parameter is a string parameter
|
||||
return shouldBeDefaulted ? $"{pair} = {(parameter.ClientDefaultValue != null ? $"\"{parameter.ClientDefaultValue}\"" : "default")}" : pair;
|
||||
}))
|
||||
|
@ -218,14 +205,7 @@ namespace AutoRest.CSharp.V3.CodeGen
|
|||
var bodyParameter = parameters.Select(p => p.Parameter).FirstOrDefault(p => (p.Protocol.Http as HttpParameter)?.In == ParameterLocation.Body);
|
||||
if (bodyParameter != null)
|
||||
{
|
||||
var bufferWriter = new CSharpType
|
||||
{
|
||||
FrameworkType = typeof(ArrayBufferWriter<>),
|
||||
SubType1 = new CSharpType
|
||||
{
|
||||
FrameworkType = typeof(byte)
|
||||
}
|
||||
};
|
||||
var bufferWriter = new CSharpType(typeof(ArrayBufferWriter<>), new CSharpType(typeof(byte)));
|
||||
|
||||
Line($"var buffer = new {Type(bufferWriter)}();");
|
||||
Line($"await using var writer = new {Type(typeof(Utf8JsonWriter))}(buffer);");
|
||||
|
@ -255,7 +235,7 @@ namespace AutoRest.CSharp.V3.CodeGen
|
|||
{
|
||||
Line($"case {statusCode.GetEnumMemberValue()}:");
|
||||
}
|
||||
Line($"return {Type(typeof(Response))}.FromValue({schemaResponse.Schema.ToDeserializeCall(_typeFactory, "document.RootElement", Type(responseType), responseType?.Name ?? "[NO TYPE NAME]")}, response);");
|
||||
Line($"return {Type(typeof(Response))}.FromValue({schemaResponse.Schema.ToDeserializeCall(_typeFactory, "document.RootElement", Type(responseType!), responseType!.Name ?? "[NO TYPE NAME]")}, response);");
|
||||
Line("default:");
|
||||
//TODO: Handle actual exception responses
|
||||
Line($"throw new {Type(typeof(Exception))}();");
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using AutoRest.CSharp.V3.ClientModel;
|
||||
using AutoRest.CSharp.V3.Pipeline;
|
||||
using AutoRest.CSharp.V3.Pipeline.Generated;
|
||||
using AutoRest.CSharp.V3.Plugins;
|
||||
|
@ -20,29 +21,25 @@ namespace AutoRest.CSharp.V3.CodeGen
|
|||
_typeFactory = typeFactory;
|
||||
}
|
||||
|
||||
public bool WriteSchema(Schema schema) =>
|
||||
schema switch
|
||||
{
|
||||
ObjectSchema objectSchema => WriteObjectSchema(objectSchema),
|
||||
SealedChoiceSchema sealedChoiceSchema => WriteSealedChoiceSchema(sealedChoiceSchema),
|
||||
ChoiceSchema choiceSchema => WriteChoiceSchema(choiceSchema),
|
||||
_ => WriteDefaultSchema(schema)
|
||||
};
|
||||
|
||||
public bool WriteDefaultSchema(Schema schema)
|
||||
public void WriteSchema(ClientModel.ClientModel model)
|
||||
{
|
||||
Header();
|
||||
using var _ = UsingStatements();
|
||||
var cs = _typeFactory.CreateType(schema);
|
||||
using (Namespace(cs.Namespace))
|
||||
switch (model)
|
||||
{
|
||||
using (Class(null, "partial", schema.CSharpName())) { }
|
||||
case ClientObject objectSchema:
|
||||
WriteObjectSchema(objectSchema);
|
||||
break;
|
||||
case ClientEnum e when e.IsStringBased:
|
||||
WriteChoiceSchema(e);
|
||||
break;
|
||||
case ClientEnum e when !e.IsStringBased:
|
||||
WriteSealedChoiceSchema(e);
|
||||
break;
|
||||
default:
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//TODO: This is currently input schemas only. Does not handle output-style schemas.
|
||||
private bool WriteObjectSchema(ObjectSchema schema)
|
||||
private void WriteObjectSchema(ClientModel.ClientObject schema)
|
||||
{
|
||||
Header();
|
||||
using var _ = UsingStatements();
|
||||
|
@ -51,83 +48,60 @@ namespace AutoRest.CSharp.V3.CodeGen
|
|||
{
|
||||
using (Class(null, "partial", schema.CSharpName()))
|
||||
{
|
||||
var propertyInfos = (schema.Properties ?? Enumerable.Empty<Property>())
|
||||
.Select(p => (Property: p, PropertySchemaCs: p.Schema.Language.CSharp)).ToArray();
|
||||
foreach (var (property, _) in propertyInfos)
|
||||
foreach (var constant in schema.Constants)
|
||||
{
|
||||
if (property.Schema is ConstantSchema constantSchema)
|
||||
{
|
||||
//TODO: Determine if type can use 'const' field instead of 'static' property
|
||||
Line($"public static {Pair(_typeFactory.CreateType(constantSchema.ValueType), property.CSharpName())} {{ get; }} = {constantSchema.ToValueString()};");
|
||||
continue;
|
||||
}
|
||||
if ((property.Schema.IsLazy()) && !(property.Required ?? false) && !(property.Required ?? false))
|
||||
{
|
||||
LazyProperty("public", _typeFactory.CreateType(property.Schema), _typeFactory.CreateConcreteType(property.Schema), property.CSharpName(), property.IsNullable());
|
||||
continue;
|
||||
}
|
||||
AutoProperty("public", _typeFactory.CreateType(property.Schema), property.CSharpName(), property.IsNullable(), property.Required ?? false);
|
||||
//TODO: Determine if type can use 'const' field instead of 'static' property
|
||||
Line($"public static {Pair(_typeFactory.CreateType(constant.Type), constant.Name)} {{ get; }} = {constant.Value.ToValueString()};");
|
||||
}
|
||||
|
||||
var filteredPropertyInfos = propertyInfos.Where(p => !(p.Property.Schema is ConstantSchema)).ToArray();
|
||||
if (filteredPropertyInfos.Any(pi => pi.Property.Required ?? false))
|
||||
foreach (var property in schema.Properties)
|
||||
{
|
||||
Line();
|
||||
Line("#pragma warning disable CS8618 // Non-nullable field is uninitialized. Consider declaring as nullable.");
|
||||
using (Method("private", null, schema.CSharpName()))
|
||||
{
|
||||
}
|
||||
Line("#pragma warning restore CS8618 // Non-nullable field is uninitialized. Consider declaring as nullable.");
|
||||
var initializer = NeedsInitialization(property.Type) ? $" = new {Type(_typeFactory.CreateConcreteType(property.Type))}();" : null;
|
||||
|
||||
Line();
|
||||
var requiredProperties = filteredPropertyInfos.Where(pi => pi.Property.Required ?? false)
|
||||
.Select(pi => (Info: pi, VariableName: pi.Property.CSharpVariableName(), InputType: _typeFactory.CreateInputType(pi.Property.Schema))).ToArray();
|
||||
var parameters = requiredProperties.Select(rp => Pair(rp.InputType, rp.VariableName)).ToArray();
|
||||
using (Method("public", null, schema.CSharpName(), parameters))
|
||||
{
|
||||
foreach (var ((property, _), variableName, _) in requiredProperties)
|
||||
{
|
||||
if (property.Schema.IsLazy())
|
||||
{
|
||||
Line($"{property.CSharpName()} = new {Type(_typeFactory.CreateConcreteType(property.Schema))}({variableName});");
|
||||
continue;
|
||||
}
|
||||
Line($"{property.CSharpName()} = {variableName};");
|
||||
}
|
||||
}
|
||||
AutoProperty("public", _typeFactory.CreateType(property.Type), property.Name, property.IsReadOnly, initializer);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool WriteSealedChoiceSchema(SealedChoiceSchema schema)
|
||||
private bool NeedsInitialization(ClientTypeReference reference)
|
||||
{
|
||||
if (reference is CollectionTypeReference || reference is DictionaryTypeReference)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void WriteSealedChoiceSchema(ClientEnum schema)
|
||||
{
|
||||
Header();
|
||||
using var _ = UsingStatements();
|
||||
var cs = _typeFactory.CreateType(schema);
|
||||
using (Namespace(cs.Namespace))
|
||||
{
|
||||
using (Enum(null, null, schema.CSharpName()))
|
||||
using (Enum(null, null, cs.Name))
|
||||
{
|
||||
schema.Choices.Select(c => c).ForEachLast(ccs => EnumValue(ccs.CSharpName()), ccs => EnumValue(ccs.CSharpName(), false));
|
||||
schema.Values.Select(c => c).ForEachLast(ccs => EnumValue(ccs.Name), ccs => EnumValue(ccs.Name, false));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool WriteChoiceSchema(ChoiceSchema schema)
|
||||
private void WriteChoiceSchema(ClientEnum schema)
|
||||
{
|
||||
Header();
|
||||
using var _ = UsingStatements();
|
||||
var cs = _typeFactory.CreateType(schema);
|
||||
using (Namespace(cs.Namespace))
|
||||
{
|
||||
var implementType = new CSharpType {FrameworkType = typeof(IEquatable<>), SubType1 = cs};
|
||||
var implementType = new CSharpType(typeof(IEquatable<>), cs);
|
||||
using (Struct(null, "readonly partial", schema.CSharpName(), Type(implementType)))
|
||||
{
|
||||
var stringText = Type(typeof(string));
|
||||
var nullableStringText = Type(typeof(string), true);
|
||||
var csTypeText = Type(cs);
|
||||
|
||||
Line($"private readonly {Pair(nullableStringText, "_value")};");
|
||||
Line();
|
||||
|
||||
|
@ -137,7 +111,17 @@ namespace AutoRest.CSharp.V3.CodeGen
|
|||
}
|
||||
Line();
|
||||
|
||||
var csTypeText = Type(cs);
|
||||
foreach (var choice in schema.Values.Select(c => c))
|
||||
{
|
||||
Line($"private const {Pair(stringText, $"{choice.Name}Value")} = \"{choice.Value.Value}\";");
|
||||
}
|
||||
Line();
|
||||
|
||||
foreach (var choice in schema.Values)
|
||||
{
|
||||
Line($"public static {Pair(csTypeText, choice?.Name)} {{ get; }} = new {csTypeText}({choice?.Name}Value);");
|
||||
}
|
||||
|
||||
var boolText = Type(typeof(bool));
|
||||
var leftRightParams = new[] {Pair(csTypeText, "left"), Pair(csTypeText, "right")};
|
||||
MethodExpression("public static", boolText, "operator ==", leftRightParams, "left.Equals(right)");
|
||||
|
@ -156,7 +140,6 @@ namespace AutoRest.CSharp.V3.CodeGen
|
|||
MethodExpression("public override", nullableStringText, "ToString", null, "_value");
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
||||
using AutoRest.CSharp.V3.Pipeline.Generated;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using AutoRest.CSharp.V3.ClientModel;
|
||||
using AutoRest.CSharp.V3.Pipeline;
|
||||
using AutoRest.CSharp.V3.Plugins;
|
||||
using AutoRest.CSharp.V3.Utilities;
|
||||
|
||||
namespace AutoRest.CSharp.V3.CodeGen
|
||||
{
|
||||
|
@ -20,118 +19,101 @@ namespace AutoRest.CSharp.V3.CodeGen
|
|||
_typeFactory = typeFactory;
|
||||
}
|
||||
|
||||
public bool WriteSerialization(Schema schema) =>
|
||||
schema switch
|
||||
{
|
||||
ObjectSchema objectSchema => WriteObjectSerialization(objectSchema),
|
||||
SealedChoiceSchema sealedChoiceSchema => WriteSealedChoiceSerialization(sealedChoiceSchema),
|
||||
ChoiceSchema choiceSchema => WriteChoiceSerialization(choiceSchema),
|
||||
_ => WriteDefaultSerialization(schema)
|
||||
};
|
||||
|
||||
private bool WriteDefaultSerialization(Schema schema)
|
||||
public void WriteSerialization(ClientModel.ClientModel schema)
|
||||
{
|
||||
Header();
|
||||
using var _ = UsingStatements();
|
||||
var cs = _typeFactory.CreateType(schema);
|
||||
using (Namespace(cs?.Namespace))
|
||||
switch (schema)
|
||||
{
|
||||
using (Class(null, "partial", schema.CSharpName())) { }
|
||||
case ClientObject objectSchema:
|
||||
WriteObjectSerialization(objectSchema);
|
||||
break;
|
||||
case ClientEnum sealedChoiceSchema when !sealedChoiceSchema.IsStringBased:
|
||||
WriteSealedChoiceSerialization(sealedChoiceSchema);
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void WriteProperty(Schema schema, string name, string serializedName, bool isNullable)
|
||||
private void WriteProperty(ClientTypeReference type, string name, string serializedName)
|
||||
{
|
||||
if (schema is ArraySchema array)
|
||||
if (type is CollectionTypeReference array)
|
||||
{
|
||||
Line($"writer.WriteStartArray(\"{serializedName}\");");
|
||||
using (ForEach($"var item in {name}"))
|
||||
{
|
||||
Line(array.ElementType.ToSerializeCall(_typeFactory, "item", serializedName, isNullable, true) ?? $"// {array.ElementType.GetType().Name}: Not Implemented");
|
||||
this.ToSerializeCall(array.ItemType, _typeFactory, "item", serializedName, true);
|
||||
}
|
||||
Line("writer.WriteEndArray();");
|
||||
return;
|
||||
}
|
||||
if (schema is DictionarySchema dictionary)
|
||||
|
||||
if (type is DictionaryTypeReference dictionary)
|
||||
{
|
||||
Line($"writer.WriteStartObject(\"{serializedName}\");");
|
||||
using (ForEach($"var item in {name}"))
|
||||
{
|
||||
Line(dictionary.ElementType.ToSerializeCall(_typeFactory, "item.Value", "item.Key", isNullable, false, false) ?? $"// {dictionary.ElementType.GetType().Name}: Not Implemented");
|
||||
this.ToSerializeCall(dictionary.ValueType, _typeFactory, "item.Value", "item.Key", false, false);
|
||||
}
|
||||
Line("writer.WriteEndObject();");
|
||||
return;
|
||||
}
|
||||
|
||||
Line(schema.ToSerializeCall(_typeFactory, name, serializedName, isNullable) ?? $"// {schema.GetType().Name} {name}: Not Implemented");
|
||||
this.ToSerializeCall(type, _typeFactory, name, serializedName);
|
||||
}
|
||||
|
||||
private void ReadProperty(Schema schema, string name, string typeText, string typeName)
|
||||
private void ReadProperty(ClientTypeReference type, string name)
|
||||
{
|
||||
if (schema is ArraySchema array)
|
||||
if (type is CollectionTypeReference array)
|
||||
{
|
||||
using (ForEach("var item in property.Value.EnumerateArray()"))
|
||||
{
|
||||
var elementType = _typeFactory.CreateType(array.ElementType);
|
||||
var elementTypeName = elementType?.Name ?? "[NO TYPE NAME]";
|
||||
//TODO: Hack for property name/type name clashing
|
||||
var elementTypeText = elementType?.FullName ?? "[NO TYPE]";
|
||||
var createText = array.ElementType.ToDeserializeCall(_typeFactory, "item", elementTypeText, elementTypeName);
|
||||
Line(createText != null ? $"result.{name}.Add({createText});" : $"// {array.ElementType.GetType().Name}: Not Implemented");
|
||||
var elementType = _typeFactory.CreateType(array.ItemType);
|
||||
var elementTypeName = elementType.Name;
|
||||
var elementTypeText = Type(elementType);
|
||||
Append($"result.{name}.Add(");
|
||||
this.ToDeserializeCall(array.ItemType, _typeFactory, "item", elementTypeText, elementTypeName);
|
||||
Line(");");
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (schema is DictionarySchema dictionary)
|
||||
if (type is DictionaryTypeReference dictionary)
|
||||
{
|
||||
using (ForEach("var item in property.Value.EnumerateObject()"))
|
||||
{
|
||||
var elementType = _typeFactory.CreateType(dictionary.ElementType);
|
||||
var elementTypeName = elementType?.Name ?? "[NO TYPE NAME]";
|
||||
//TODO: Hack for property name/type name clashing
|
||||
var elementTypeText = elementType?.FullName ?? "[NO TYPE]";
|
||||
var createText = dictionary.ElementType.ToDeserializeCall(_typeFactory, "item.Value", elementTypeText, elementTypeName);
|
||||
Line(createText != null ? $"result.{name}.Add(item.Name, {createText});" : $"// {dictionary.ElementType.GetType().Name}: Not Implemented");
|
||||
var elementType = _typeFactory.CreateType(dictionary.ValueType);
|
||||
var elementTypeName = elementType.Name;
|
||||
var elementTypeText = Type(elementType);
|
||||
Append($"result.{name}.Add(item.Name, ");
|
||||
this.ToDeserializeCall(dictionary.ValueType, _typeFactory, "item.Value", elementTypeText, elementTypeName);
|
||||
Line(");");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
var callText = schema.ToDeserializeCall(_typeFactory, "property.Value", typeText, typeName);
|
||||
Line(callText != null ? $"result.{name} = {callText};" : $"// {schema.GetType().Name} {name}: Not Implemented");
|
||||
var t = Type(_typeFactory.CreateType(type));
|
||||
Append($"result.{name} = ");
|
||||
this.ToDeserializeCall(type, _typeFactory, "property.Value", t, t);
|
||||
Line(";");
|
||||
}
|
||||
|
||||
//TODO: This is currently input schemas only. Does not handle output-style schemas.
|
||||
private bool WriteObjectSerialization(ObjectSchema schema)
|
||||
private void WriteObjectSerialization(ClientObject model)
|
||||
{
|
||||
Header();
|
||||
using var _ = UsingStatements();
|
||||
var cs = _typeFactory.CreateType(schema);
|
||||
var cs = _typeFactory.CreateType(model);
|
||||
using (Namespace(cs.Namespace))
|
||||
{
|
||||
using (Class(null, "partial", schema.CSharpName()))
|
||||
using (Class(null, "partial", model.CSharpName()))
|
||||
{
|
||||
using (Method("internal", "void", "Serialize", Pair(typeof(Utf8JsonWriter), "writer"), Pair(typeof(bool), "includeName = true")))
|
||||
using (Method("internal", "void", "Serialize", Pair(typeof(Utf8JsonWriter), "writer")))
|
||||
{
|
||||
using (If("includeName"))
|
||||
{
|
||||
Line($"writer.WriteStartObject(\"{schema.Language.Default.Name}\");");
|
||||
}
|
||||
using (Else())
|
||||
{
|
||||
Line("writer.WriteStartObject();");
|
||||
}
|
||||
Line("writer.WriteStartObject();");
|
||||
|
||||
var propertyInfos = schema.Properties ?? Enumerable.Empty<Property>();
|
||||
var propertyInfos = model.Properties;
|
||||
foreach (var property in propertyInfos)
|
||||
{
|
||||
var hasField = property.Schema.IsLazy() && !(property.Required ?? false);
|
||||
var name = (hasField ? $"_{property.CSharpVariableName()}" : null) ?? property?.CSharpName() ?? "[NO NAME]";
|
||||
|
||||
var serializedName = property!.Language.Default.Name;
|
||||
var isNullable = property.IsNullable();
|
||||
using (isNullable ? If($"{name} != null") : new DisposeAction())
|
||||
using (property.Type.IsNullable ? If($"{property.Name} != null") : new DisposeAction())
|
||||
{
|
||||
WriteProperty(property.Schema, name, serializedName, isNullable);
|
||||
WriteProperty(property.Type, property.Name, property.SerializedName);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -144,20 +126,11 @@ namespace AutoRest.CSharp.V3.CodeGen
|
|||
Line($"var result = new {typeText}();");
|
||||
using (ForEach("var property in element.EnumerateObject()"))
|
||||
{
|
||||
var propertyInfos = (schema.Properties ?? Enumerable.Empty<Property>())
|
||||
// Do not deserialize constant properties
|
||||
.Where(p => !(p.Schema is ConstantSchema)).ToArray();
|
||||
foreach (var property in propertyInfos)
|
||||
foreach (var property in model.Properties)
|
||||
{
|
||||
var name = property.CSharpName();
|
||||
var serializedName = property.Language.Default.Name;
|
||||
using (If($"property.NameEquals(\"{serializedName}\")"))
|
||||
using (If($"property.NameEquals(\"{property.SerializedName}\")"))
|
||||
{
|
||||
var propertyType = _typeFactory.CreateType(property.Schema);
|
||||
var propertyTypeName = propertyType?.Name ?? "[NO TYPE NAME]";
|
||||
//TODO: Hack for property name/type name clashing
|
||||
//var propertyType = Type(property.Schema.Language.CSharp?.Type);
|
||||
ReadProperty(property.Schema, name, propertyType.FullName, propertyTypeName);
|
||||
ReadProperty(property.Type, property.Name);
|
||||
Line("continue;");
|
||||
}
|
||||
}
|
||||
|
@ -166,10 +139,9 @@ namespace AutoRest.CSharp.V3.CodeGen
|
|||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool WriteSealedChoiceSerialization(SealedChoiceSchema schema)
|
||||
private void WriteSealedChoiceSerialization(ClientEnum schema)
|
||||
{
|
||||
Header();
|
||||
using var _ = UsingStatements();
|
||||
|
@ -180,7 +152,7 @@ namespace AutoRest.CSharp.V3.CodeGen
|
|||
{
|
||||
var stringText = Type(typeof(string));
|
||||
var csTypeText = Type(cs);
|
||||
var nameMap = schema.Choices.Select(c => (Choice: $"{csTypeText}.{c.CSharpName()}", Serial: $"\"{c.Value}\"")).ToArray();
|
||||
var nameMap = schema.Values.Select(c => (Choice: $"{csTypeText}.{c.Name}", Serial: $"\"{c.Value.Value}\"")).ToArray();
|
||||
var exceptionEntry = $"_ => throw new {Type(typeof(ArgumentOutOfRangeException))}(nameof(value), value, \"Unknown {csTypeText} value.\")";
|
||||
|
||||
var toSerialString = String.Join(Environment.NewLine, nameMap
|
||||
|
@ -201,33 +173,6 @@ namespace AutoRest.CSharp.V3.CodeGen
|
|||
MethodExpression("public static", csTypeText, $"To{schema.CSharpName()}", new[] { Pair($"this {stringText}", "value") }, toChoiceType);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool WriteChoiceSerialization(ChoiceSchema schema)
|
||||
{
|
||||
Header();
|
||||
using var _ = UsingStatements();
|
||||
var cs = _typeFactory.CreateType(schema);
|
||||
using (Namespace(cs?.Namespace))
|
||||
{
|
||||
using (Struct(null, "readonly partial", schema.CSharpName()))
|
||||
{
|
||||
var stringText = Type(typeof(string));
|
||||
foreach (var choice in schema.Choices.Select(c => c))
|
||||
{
|
||||
Line($"private const {Pair(stringText, $"{choice.CSharpName()}Value")} = \"{choice.Value}\";");
|
||||
}
|
||||
Line();
|
||||
|
||||
var csTypeText = Type(cs);
|
||||
foreach (var choice in schema.Choices)
|
||||
{
|
||||
Line($"public static {Pair(csTypeText, choice?.CSharpName())} {{ get; }} = new {csTypeText}({choice?.CSharpName()}Value);");
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,9 +16,6 @@ namespace AutoRest.CSharp.V3.CodeGen
|
|||
private readonly List<string> _classFields = new List<string>();
|
||||
private CSharpNamespace? _currentNamespace;
|
||||
|
||||
//TODO: Make these into configuration values
|
||||
private readonly bool _useTypeShortNames = true;
|
||||
private readonly bool _useKeywords = true;
|
||||
private readonly string _definitionAccessDefault = "public";
|
||||
|
||||
public abstract void Line(string str = "");
|
||||
|
@ -128,15 +125,8 @@ namespace AutoRest.CSharp.V3.CodeGen
|
|||
public void EnumValue(string? value, bool includeComma = true) =>
|
||||
Line($"{value ?? "[NO VALUE]"}{(includeComma ? "," : String.Empty)}");
|
||||
|
||||
public void AutoProperty(string modifiers, CSharpType? type, string? name, bool? isNullable, bool isRequired = false) =>
|
||||
Line($"{modifiers} {Pair(type, name, isNullable)} {{ get; {(isRequired ? "private " : String.Empty)}set; }}");
|
||||
|
||||
public void LazyProperty(string modifiers, CSharpType? type, CSharpType? concreteType, string? name, bool? isNullable)
|
||||
{
|
||||
var variable = $"_{name.ToVariableName()}";
|
||||
_classFields.Add($"private {Pair(concreteType, variable, isNullable)};");
|
||||
Line($"{modifiers} {Pair(type, name)} => {Type(typeof(LazyInitializer))}.EnsureInitialized(ref {variable});");
|
||||
}
|
||||
public void AutoProperty(string modifiers, CSharpType type, string? name, bool isReadOnly = false, string? initializer = null) =>
|
||||
Line($"{modifiers} {Pair(type, name)} {{ get; {(isReadOnly ? String.Empty : "set; ")}}}{initializer}");
|
||||
|
||||
//TODO: Determine implementation for documentation
|
||||
//public void DocSummary(string summary)
|
||||
|
@ -175,25 +165,60 @@ namespace AutoRest.CSharp.V3.CodeGen
|
|||
});
|
||||
}
|
||||
|
||||
public string Type(CSharpType? type, bool? isNullable = false)
|
||||
public string Type(CSharpType type)
|
||||
{
|
||||
if (_useTypeShortNames)
|
||||
string name;
|
||||
|
||||
if (type.FrameworkType != null && GetKeywordMapping(type.FrameworkType) is string keyword)
|
||||
{
|
||||
//TODO: Does not recursively dig for types from subtypes
|
||||
_usingNamespaces.Add(type?.KeywordName != null ? null : type?.Namespace);
|
||||
_usingNamespaces.Add(type?.SubType1?.KeywordName != null ? null : type?.SubType1?.Namespace);
|
||||
_usingNamespaces.Add(type?.SubType2?.KeywordName != null ? null : type?.SubType2?.Namespace);
|
||||
name = keyword;
|
||||
}
|
||||
var typeText = _useTypeShortNames ? type?.GetComposedName(typesAsKeywords: _useKeywords) : type?.FullName;
|
||||
var nullMark = (isNullable ?? false) ? "?" : String.Empty;
|
||||
return (typeText != null ? typeText + nullMark : null) ?? "[NO TYPE]";
|
||||
else
|
||||
{
|
||||
name = type.Name;
|
||||
_usingNamespaces.Add(type.Namespace);
|
||||
}
|
||||
|
||||
if (type.Arguments.Any())
|
||||
{
|
||||
var subTypes = type.Arguments.Select(a => Type(a)).JoinIgnoreEmpty(", ");
|
||||
name += $"<{subTypes}>";
|
||||
}
|
||||
|
||||
if (type.IsNullable)
|
||||
{
|
||||
name += "?";
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
public string Type(Type? type, bool? isNullable = false) => Type(new CSharpType {FrameworkType = type}, isNullable);
|
||||
public string AttributeType(Type? type) => Type(type).Replace("Attribute", String.Empty);
|
||||
public string Type(Type type, bool isNullable = false) => Type(new CSharpType(type, isNullable));
|
||||
public string AttributeType(Type type) => Type(type).Replace("Attribute", String.Empty);
|
||||
|
||||
public static string Pair(string? typeText, string? name) => $"{typeText ?? "[NO TYPE]"} {name ?? "[NO NAME]"}";
|
||||
public string Pair(CSharpType? type, string? name, bool? isNullable = false) => $"{Type(type, isNullable)} {name ?? "[NO NAME]"}";
|
||||
public string Pair(Type? type, string? name, bool? isNullable = false) => $"{Type(type, isNullable)} {name ?? "[NO NAME]"}";
|
||||
public string Pair(CSharpType type, string? name) => $"{Type(type)} {name ?? "[NO NAME]"}";
|
||||
public string Pair(Type type, string? name, bool isNullable = false) => $"{Type(type, isNullable)} {name ?? "[NO NAME]"}";
|
||||
|
||||
private static string? GetKeywordMapping(Type? type) =>
|
||||
type switch
|
||||
{
|
||||
var t when t == typeof(bool) => "bool",
|
||||
var t when t == typeof(byte) => "byte",
|
||||
var t when t == typeof(sbyte) => "sbyte",
|
||||
var t when t == typeof(short) => "short",
|
||||
var t when t == typeof(ushort) => "ushort",
|
||||
var t when t == typeof(int) => "int",
|
||||
var t when t == typeof(uint) => "uint",
|
||||
var t when t == typeof(long) => "long",
|
||||
var t when t == typeof(ulong) => "ulong",
|
||||
var t when t == typeof(char) => "char",
|
||||
var t when t == typeof(double) => "double",
|
||||
var t when t == typeof(float) => "float",
|
||||
var t when t == typeof(object) => "object",
|
||||
var t when t == typeof(decimal) => "decimal",
|
||||
var t when t == typeof(string) => "string",
|
||||
_ => null
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ namespace AutoRest.CSharp.V3.JsonRpc.MessageModels
|
|||
return Task.FromResult((T)Convert.ChangeType(stringValue, typeof(T)));
|
||||
}
|
||||
|
||||
return Task.FromResult(default(T));
|
||||
return Task.FromResult(default(T)!);
|
||||
}
|
||||
|
||||
public Task<string[]> ListInputs(string? artifactType = null)
|
||||
|
|
|
@ -2,10 +2,9 @@
|
|||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using AutoRest.CSharp.V3.ClientModel;
|
||||
using AutoRest.CSharp.V3.CodeGen;
|
||||
using AutoRest.CSharp.V3.Pipeline.Generated;
|
||||
using AutoRest.CSharp.V3.Plugins;
|
||||
using Azure.Core;
|
||||
|
@ -14,72 +13,43 @@ namespace AutoRest.CSharp.V3.Pipeline
|
|||
{
|
||||
internal static class Extensions
|
||||
{
|
||||
public static readonly Type[] GeneratedTypes = Assembly.GetExecutingAssembly().GetTypes().Where(t => t.Namespace == typeof(CodeModel).Namespace).ToArray();
|
||||
|
||||
private static readonly PropertyInfo[] SchemaCollectionProperties = typeof(Schemas).GetProperties(BindingFlags.Public | BindingFlags.Instance)
|
||||
.Where(pi => pi.PropertyType.IsGenericType
|
||||
&& pi.PropertyType.IsInterface
|
||||
&& pi.PropertyType.GetGenericTypeDefinition() == typeof(ICollection<>)
|
||||
&& (pi.PropertyType.GenericTypeArguments.First().IsSubclassOf(typeof(Schema))
|
||||
|| pi.PropertyType.GenericTypeArguments.First() == typeof(Schema)))
|
||||
.ToArray();
|
||||
public static Schema[] GetAllSchemaNodes(this Schemas schemasNode) => SchemaCollectionProperties
|
||||
.Select(pi => pi.GetValue(schemasNode))
|
||||
.Where(c => c != null)
|
||||
.SelectMany(c => ((IEnumerable)c!).Cast<Schema>())
|
||||
.ToArray();
|
||||
|
||||
// Cache the CSharpType so they become references in the YAML.
|
||||
private static readonly Dictionary<Type, CSharpType> CSharpTypes = new Dictionary<Type, CSharpType>
|
||||
{
|
||||
{ typeof(bool), new CSharpType { FrameworkType = typeof(bool) } },
|
||||
{ typeof(char), new CSharpType { FrameworkType = typeof(char) } },
|
||||
{ typeof(int), new CSharpType { FrameworkType = typeof(int) } },
|
||||
{ typeof(double), new CSharpType { FrameworkType = typeof(double) } },
|
||||
{ typeof(string), new CSharpType { FrameworkType = typeof(string) } },
|
||||
{ typeof(byte[]), new CSharpType { FrameworkType = typeof(byte[]) } },
|
||||
{ typeof(DateTime), new CSharpType { FrameworkType = typeof(DateTime) } },
|
||||
{ typeof(TimeSpan), new CSharpType { FrameworkType = typeof(TimeSpan) } },
|
||||
{ typeof(Uri), new CSharpType { FrameworkType = typeof(Uri) } }
|
||||
};
|
||||
|
||||
public static CSharpType? ToFrameworkCSharpType(this AllSchemaTypes schemaType) => schemaType switch
|
||||
public static Type? ToFrameworkCSharpType(this AllSchemaTypes schemaType) => schemaType switch
|
||||
{
|
||||
AllSchemaTypes.Any => null,
|
||||
AllSchemaTypes.Array => null,
|
||||
AllSchemaTypes.Boolean => CSharpTypes[typeof(bool)],
|
||||
AllSchemaTypes.ByteArray => CSharpTypes[typeof(byte[])],
|
||||
AllSchemaTypes.Char => CSharpTypes[typeof(char)],
|
||||
AllSchemaTypes.Boolean => typeof(bool),
|
||||
AllSchemaTypes.ByteArray => typeof(byte[]),
|
||||
AllSchemaTypes.Char => typeof(char),
|
||||
AllSchemaTypes.Choice => null,
|
||||
AllSchemaTypes.Constant => null,
|
||||
AllSchemaTypes.Credential => null,
|
||||
AllSchemaTypes.Date => CSharpTypes[typeof(DateTime)],
|
||||
AllSchemaTypes.DateTime => CSharpTypes[typeof(DateTime)],
|
||||
AllSchemaTypes.Date => typeof(DateTime),
|
||||
AllSchemaTypes.DateTime => typeof(DateTime),
|
||||
AllSchemaTypes.Dictionary => null,
|
||||
AllSchemaTypes.Duration => CSharpTypes[typeof(TimeSpan)],
|
||||
AllSchemaTypes.Duration => typeof(TimeSpan),
|
||||
AllSchemaTypes.Flag => null,
|
||||
AllSchemaTypes.Integer => CSharpTypes[typeof(int)],
|
||||
AllSchemaTypes.Integer => typeof(int),
|
||||
AllSchemaTypes.Not => null,
|
||||
AllSchemaTypes.Number => CSharpTypes[typeof(double)],
|
||||
AllSchemaTypes.Number => typeof(double),
|
||||
AllSchemaTypes.Object => null,
|
||||
AllSchemaTypes.OdataQuery => CSharpTypes[typeof(string)],
|
||||
AllSchemaTypes.OdataQuery => typeof(string),
|
||||
AllSchemaTypes.Or => null,
|
||||
AllSchemaTypes.Group => null,
|
||||
AllSchemaTypes.SealedChoice => null,
|
||||
AllSchemaTypes.String => CSharpTypes[typeof(string)],
|
||||
AllSchemaTypes.Unixtime => CSharpTypes[typeof(DateTime)],
|
||||
AllSchemaTypes.Uri => CSharpTypes[typeof(Uri)],
|
||||
AllSchemaTypes.Uuid => CSharpTypes[typeof(string)],
|
||||
AllSchemaTypes.String => typeof(string),
|
||||
AllSchemaTypes.Unixtime => typeof(DateTime),
|
||||
AllSchemaTypes.Uri => typeof(Uri),
|
||||
AllSchemaTypes.Uuid => typeof(string),
|
||||
AllSchemaTypes.Xor => null,
|
||||
_ => null
|
||||
};
|
||||
|
||||
public static RequestMethod? ToCoreRequestMethod(this HttpMethod method) => method switch
|
||||
{
|
||||
HttpMethod.Delete => (RequestMethod?)RequestMethod.Delete,
|
||||
HttpMethod.Delete => RequestMethod.Delete,
|
||||
HttpMethod.Get => RequestMethod.Get,
|
||||
HttpMethod.Head => RequestMethod.Head,
|
||||
HttpMethod.Options => null,
|
||||
HttpMethod.Options => (RequestMethod?)null,
|
||||
HttpMethod.Patch => RequestMethod.Patch,
|
||||
HttpMethod.Post => RequestMethod.Post,
|
||||
HttpMethod.Put => RequestMethod.Put,
|
||||
|
@ -103,21 +73,12 @@ namespace AutoRest.CSharp.V3.Pipeline
|
|||
|
||||
private static readonly Dictionary<Type, Func<string, string?, bool, bool, bool, bool, string?>> SchemaSerializers = new Dictionary<Type, Func<string, string?, bool, bool, bool, bool, string?>>
|
||||
{
|
||||
{ typeof(ObjectSchema), (vn, sn, n, a, q, ipn) => $"{vn}{(n ? "?" : String.Empty)}.Serialize(writer, {(ipn ? "true" : "false")});" },
|
||||
{ typeof(ObjectSchema), (vn, sn, n, a, q, ipn) => $"{vn}{(n ? "?" : String.Empty)}.Serialize(writer);" },
|
||||
{ typeof(SealedChoiceSchema), (vn, sn, n, a, q, ipn) => a ? $"writer.WriteStringValue({vn}{(n ? "?" : String.Empty)}.ToSerialString());" : $"writer.WriteString({(q ? $"\"{sn}\"" : sn)}, {vn}{(n ? "?" : String.Empty)}.ToSerialString());" },
|
||||
{ typeof(ChoiceSchema), (vn, sn, n, a, q, ipn) => a ? $"writer.WriteStringValue({vn}{(n ? "?" : String.Empty)}.ToString());" : $"writer.WriteString({(q ? $"\"{sn}\"" : sn)}, {vn}{(n ? "?" : String.Empty)}.ToString());" },
|
||||
{ typeof(ByteArraySchema), (vn, sn, n, a, q, ipn) => a ? $"writer.WriteBase64StringValue({vn});" : $"writer.WriteBase64String({(q ? $"\"{sn}\"" : sn)}, {vn});" }
|
||||
};
|
||||
|
||||
public static string? ToSerializeCall(this Schema schema, TypeFactory typeFactory, string name, string serializedName, bool isNullable, bool asArray = false, bool quotedSerializedName = true, bool includePropertyName = true)
|
||||
{
|
||||
var schemaType = schema.GetType();
|
||||
var frameworkType = typeFactory.CreateType(schema)?.FrameworkType ?? typeof(void);
|
||||
return SchemaSerializers.ContainsKey(schemaType)
|
||||
? SchemaSerializers[schemaType](name, serializedName, isNullable, asArray, quotedSerializedName, includePropertyName)
|
||||
: (TypeSerializers.ContainsKey(frameworkType) ? TypeSerializers[frameworkType](name, serializedName, isNullable, asArray, quotedSerializedName, includePropertyName) : null);
|
||||
}
|
||||
|
||||
//TODO: Figure out the rest of these.
|
||||
private static readonly Dictionary<Type, Func<string, string?>> TypeDeserializers = new Dictionary<Type, Func<string, string?>>
|
||||
{
|
||||
|
@ -128,7 +89,7 @@ namespace AutoRest.CSharp.V3.Pipeline
|
|||
{ typeof(string), n => $"{n}.GetString()" },
|
||||
{ typeof(byte[]), n => null },
|
||||
{ typeof(DateTime), n => $"{n}.GetDateTime()" },
|
||||
{ typeof(TimeSpan), n => null },
|
||||
{ typeof(TimeSpan), n => $"TimeSpan.Parse({n}.GetString())" },
|
||||
{ typeof(Uri), n => null } //TODO: Figure out how to get the Uri type here, so we can do 'new Uri(GetString())'
|
||||
};
|
||||
|
||||
|
@ -140,6 +101,15 @@ namespace AutoRest.CSharp.V3.Pipeline
|
|||
{ typeof(ByteArraySchema), (n, tt, tn) => $"{n}.GetBytesFromBase64()" }
|
||||
};
|
||||
|
||||
public static string? ToSerializeCall(this Schema schema, TypeFactory typeFactory, string name, string serializedName, bool isNullable, bool asArray = false, bool quotedSerializedName = true, bool includePropertyName = true)
|
||||
{
|
||||
var schemaType = schema.GetType();
|
||||
var frameworkType = typeFactory.CreateType(schema)?.FrameworkType ?? typeof(void);
|
||||
return SchemaSerializers.ContainsKey(schemaType)
|
||||
? SchemaSerializers[schemaType](name, serializedName, isNullable, asArray, quotedSerializedName, includePropertyName)
|
||||
: (TypeSerializers.ContainsKey(frameworkType) ? TypeSerializers[frameworkType](name, serializedName, isNullable, asArray, quotedSerializedName, includePropertyName) : null);
|
||||
}
|
||||
|
||||
public static string? ToDeserializeCall(this Schema schema, TypeFactory typeFactory, string name, string typeText, string typeName)
|
||||
{
|
||||
var schemaType = schema.GetType();
|
||||
|
@ -149,10 +119,101 @@ namespace AutoRest.CSharp.V3.Pipeline
|
|||
: (TypeDeserializers.ContainsKey(frameworkType) ? TypeDeserializers[frameworkType](name) : null);
|
||||
}
|
||||
|
||||
public static void ToSerializeCall(this WriterBase writer, ClientTypeReference type, TypeFactory typeFactory, string name, string serializedName, bool asArray = false, bool quotedSerializedName = true, bool includePropertyName = true)
|
||||
{
|
||||
if (includePropertyName)
|
||||
{
|
||||
writer.Append("writer.WritePropertyName(");
|
||||
writer.Append("\"");
|
||||
writer.Append(serializedName);
|
||||
writer.Append("\"");
|
||||
writer.Append(");");
|
||||
writer.Line();
|
||||
}
|
||||
|
||||
if (type is SchemaTypeReference schemaTypeReference)
|
||||
{
|
||||
var implementationType = typeFactory.ResolveReference(schemaTypeReference);
|
||||
|
||||
if (implementationType is ClientObject)
|
||||
{
|
||||
writer.Append(name);
|
||||
if (type.IsNullable)
|
||||
{
|
||||
writer.Append("?");
|
||||
}
|
||||
writer.Append(".Serialize(writer);");
|
||||
return;
|
||||
}
|
||||
|
||||
writer.Append("writer.WriteStringValue(");
|
||||
switch (implementationType)
|
||||
{
|
||||
case ClientEnum e when e.IsStringBased:
|
||||
writer.Append(name);
|
||||
writer.Append(".ToString()");
|
||||
break;
|
||||
case ClientEnum e when !e.IsStringBased:
|
||||
writer.Append(name);
|
||||
if (type.IsNullable)
|
||||
{
|
||||
writer.Append(".Value");
|
||||
}
|
||||
writer.Append(".ToSerialString()");
|
||||
break;
|
||||
}
|
||||
writer.Append(");");
|
||||
writer.Line();
|
||||
}
|
||||
else
|
||||
{
|
||||
var frameworkType = typeFactory.CreateType(type)?.FrameworkType ?? typeof(void);
|
||||
writer.Line(TypeSerializers[frameworkType](name, serializedName, type.IsNullable, asArray, quotedSerializedName, false) ?? "writer.WriteNullValue();");
|
||||
}
|
||||
}
|
||||
|
||||
public static void ToDeserializeCall(this WriterBase writer, ClientTypeReference type, TypeFactory typeFactory, string name, string typeText, string typeName)
|
||||
{
|
||||
CSharpType cSharpType = typeFactory.CreateType(type).WithNullable(false);
|
||||
if (type is SchemaTypeReference schemaTypeReference)
|
||||
{
|
||||
var implementationType = typeFactory.ResolveReference(schemaTypeReference);
|
||||
|
||||
switch (implementationType)
|
||||
{
|
||||
case ClientObject _:
|
||||
writer.Append(writer.Type(cSharpType));
|
||||
writer.Append($".Deserialize({name})");
|
||||
return;
|
||||
case ClientEnum e when e.IsStringBased:
|
||||
writer.Append(writer.Type(cSharpType));
|
||||
writer.Append($".Parse({name})");
|
||||
return;
|
||||
case ClientEnum e when !e.IsStringBased:
|
||||
writer.Append($"{name}");
|
||||
writer.Append(".GetString().To");
|
||||
writer.Append(writer.Type(cSharpType));
|
||||
writer.Append($"()");
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var frameworkType = cSharpType?.FrameworkType ?? typeof(void);
|
||||
writer.Append(TypeDeserializers[frameworkType](name) ?? "null");
|
||||
}
|
||||
}
|
||||
|
||||
public static string ToValueString(this ConstantSchema schema)
|
||||
{
|
||||
var value = schema.Value.Value;
|
||||
return $"{((value is string || value == null) ? $"\"{value}\"" : value)}";
|
||||
}
|
||||
|
||||
public static string ToValueString(this ClientConstant schema)
|
||||
{
|
||||
var value = schema.Value;
|
||||
return $"{((value is string || value == null) ? $"\"{value}\"" : value)}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using AutoRest.CSharp.V3.Utilities;
|
||||
using YamlDotNet.Core;
|
||||
|
@ -15,116 +16,76 @@ using YamlDotNet.Serialization;
|
|||
// ReSharper disable once CheckNamespace
|
||||
namespace AutoRest.CSharp.V3.Pipeline.Generated
|
||||
{
|
||||
|
||||
internal partial class ObjectSchema
|
||||
{
|
||||
public ObjectSchema()
|
||||
{
|
||||
Properties = Array.Empty<Property>();
|
||||
}
|
||||
}
|
||||
|
||||
internal class CSharpNamespace
|
||||
{
|
||||
public CSharpNamespace(string? @base, string? category = null, string? apiVersion = null)
|
||||
{
|
||||
Base = @base;
|
||||
Category = category;
|
||||
ApiVersion = apiVersion;
|
||||
}
|
||||
|
||||
public string? Base { get; set; }
|
||||
|
||||
public string? Category { get; set; }
|
||||
|
||||
public string? ApiVersion { get; set; }
|
||||
|
||||
public string FullName => new[]{ Base, Category, ApiVersion }.JoinIgnoreEmpty(".");
|
||||
public string FullName => new[] { Base, Category, ApiVersion }.JoinIgnoreEmpty(".");
|
||||
}
|
||||
|
||||
|
||||
internal class CSharpType
|
||||
{
|
||||
private Type? CreateFrameworkType() => Namespace?.FullName != null && Name != null ? Type.GetType(FullName) : _frameworkType;
|
||||
|
||||
private CSharpNamespace? _namespace;
|
||||
|
||||
public CSharpNamespace? Namespace
|
||||
public CSharpType(Type type, params CSharpType[] arguments) : this(type, false, arguments)
|
||||
{
|
||||
get => _namespace;
|
||||
set
|
||||
{
|
||||
_namespace = value;
|
||||
_frameworkType = CreateFrameworkType();
|
||||
}
|
||||
}
|
||||
|
||||
private string? _name;
|
||||
|
||||
public string? Name
|
||||
public CSharpType(Type type, bool isNullable, params CSharpType[] arguments)
|
||||
{
|
||||
get => _name;
|
||||
set
|
||||
{
|
||||
_name = value;
|
||||
_frameworkType = CreateFrameworkType();
|
||||
}
|
||||
Namespace ??= new CSharpNamespace(type.Namespace);
|
||||
Name = type.IsGenericType ? type.Name.Substring(0, type.Name.IndexOf('`')) : type.Name;
|
||||
IsNullable = isNullable;
|
||||
Arguments = arguments;
|
||||
IsValueType = type.IsValueType;
|
||||
FrameworkType = type;
|
||||
}
|
||||
|
||||
public CSharpType? SubType1 { get; set; }
|
||||
|
||||
public CSharpType? SubType2 { get; set; }
|
||||
|
||||
public string GetComposedName(bool subTypesAsFullName = false, bool typesAsKeywords = true)
|
||||
public CSharpType(CSharpNamespace ns, string name, bool isValueType = false, bool isNullable = false)
|
||||
{
|
||||
var name = (typesAsKeywords ? KeywordName : null) ?? Name ?? String.Empty;
|
||||
if ((SubType1 != null || SubType2 != null) && Name != null)
|
||||
{
|
||||
var subTypes = (subTypesAsFullName
|
||||
? new[] {SubType1?.FullName, SubType2?.FullName}
|
||||
: new[] {SubType1?.GetComposedName(typesAsKeywords: typesAsKeywords), SubType2?.GetComposedName(typesAsKeywords: typesAsKeywords)})
|
||||
.JoinIgnoreEmpty(", ");
|
||||
return $"{name}<{subTypes}>";
|
||||
}
|
||||
return name;
|
||||
Name = name;
|
||||
IsValueType = isValueType;
|
||||
IsNullable = isNullable;
|
||||
Namespace = ns;
|
||||
}
|
||||
|
||||
public string FullName => new[] { Namespace?.FullName, GetComposedName(true, false) }.JoinIgnoreEmpty(".");
|
||||
public CSharpNamespace Namespace { get; }
|
||||
|
||||
private Type? _frameworkType;
|
||||
public Type? FrameworkType
|
||||
public string Name { get; }
|
||||
public bool IsValueType { get; }
|
||||
|
||||
public CSharpType[] Arguments { get; } = Array.Empty<CSharpType>();
|
||||
|
||||
public Type? FrameworkType { get; }
|
||||
|
||||
public bool IsNullable { get; }
|
||||
|
||||
public CSharpType WithNullable(bool isNullable)
|
||||
{
|
||||
get => _frameworkType;
|
||||
set
|
||||
{
|
||||
_frameworkType = value;
|
||||
if (_frameworkType == null) return;
|
||||
|
||||
_namespace ??= new CSharpNamespace();
|
||||
_namespace.Base = _frameworkType.Namespace;
|
||||
_namespace.Category = null;
|
||||
_namespace.ApiVersion = null;
|
||||
_name = _frameworkType.Name.Split('`')[0];
|
||||
SubType1 = _frameworkType.IsGenericType && _frameworkType.GenericTypeArguments.Length > 0 ? new CSharpType { FrameworkType = _frameworkType.GenericTypeArguments[0] } : null;
|
||||
SubType2 = _frameworkType.IsGenericType && _frameworkType.GenericTypeArguments.Length > 1 ? new CSharpType { FrameworkType = _frameworkType.GenericTypeArguments[1] } : null;
|
||||
}
|
||||
return FrameworkType != null ?
|
||||
new CSharpType(FrameworkType, isNullable, Arguments) :
|
||||
new CSharpType(Namespace, Name, IsValueType, isNullable);
|
||||
}
|
||||
|
||||
public string? KeywordName {
|
||||
get
|
||||
{
|
||||
var hasElementType = FrameworkType?.HasElementType ?? false;
|
||||
var frameworkType = hasElementType ? FrameworkType!.GetElementType() : FrameworkType;
|
||||
var squareBrackets = hasElementType ? "[]" : String.Empty;
|
||||
var keyword = GetKeywordMapping(frameworkType);
|
||||
return keyword != null ? $"{keyword}{squareBrackets}" : null;
|
||||
}
|
||||
}
|
||||
|
||||
//https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/built-in-types-table
|
||||
private static string? GetKeywordMapping(Type? type) =>
|
||||
type switch
|
||||
{
|
||||
var t when t == typeof(bool) => "bool",
|
||||
var t when t == typeof(byte) => "byte",
|
||||
var t when t == typeof(sbyte) => "sbyte",
|
||||
var t when t == typeof(short) => "short",
|
||||
var t when t == typeof(ushort) => "ushort",
|
||||
var t when t == typeof(int) => "int",
|
||||
var t when t == typeof(uint) => "uint",
|
||||
var t when t == typeof(long) => "long",
|
||||
var t when t == typeof(ulong) => "ulong",
|
||||
var t when t == typeof(char) => "char",
|
||||
var t when t == typeof(double) => "double",
|
||||
var t when t == typeof(float) => "float",
|
||||
var t when t == typeof(object) => "object",
|
||||
var t when t == typeof(decimal) => "decimal",
|
||||
var t when t == typeof(string) => "string",
|
||||
_ => null
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>language metadata specific to schema instances</summary>
|
||||
|
|
|
@ -11,12 +11,13 @@ using YamlDotNet.Core;
|
|||
using YamlDotNet.Core.Events;
|
||||
using YamlDotNet.Serialization;
|
||||
using YamlDotNet.Serialization.Utilities;
|
||||
using static AutoRest.CSharp.V3.Pipeline.Extensions;
|
||||
|
||||
namespace AutoRest.CSharp.V3.Pipeline
|
||||
{
|
||||
internal static class Serialization
|
||||
{
|
||||
public static readonly Type[] GeneratedTypes = Assembly.GetExecutingAssembly().GetTypes().Where(t => t.Namespace == typeof(CodeModel).Namespace).ToArray();
|
||||
|
||||
private static KeyValuePair<string, Type> CreateTagPair(this Type type) => new KeyValuePair<string, Type>($"!{type.Name}", type);
|
||||
private static readonly IEnumerable<KeyValuePair<string, Type>> TagMap = GeneratedTypes.Where(t => t.IsClass).Select(CreateTagPair);
|
||||
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using AutoRest.CSharp.V3.Pipeline;
|
||||
using AutoRest.CSharp.V3.ClientModel;
|
||||
using AutoRest.CSharp.V3.Pipeline.Generated;
|
||||
using AutoRest.CSharp.V3.Utilities;
|
||||
|
||||
|
@ -15,8 +12,6 @@ namespace AutoRest.CSharp.V3.Plugins
|
|||
public static bool IsNullable(this Parameter parameter) => !(parameter.Required ?? false);
|
||||
public static bool IsNullable(this Property parameter) => !(parameter.Required ?? false);
|
||||
|
||||
public static string CSharpVariableName(this Property property) => property.Language.Default.Name.ToVariableName();
|
||||
|
||||
public static string CSharpName(this Parameter parameter) => parameter.Schema is ConstantSchema ?
|
||||
parameter.Language.Default.Name.ToCleanName() :
|
||||
parameter.Language.Default.Name.ToVariableName();
|
||||
|
@ -35,6 +30,9 @@ namespace AutoRest.CSharp.V3.Plugins
|
|||
public static string CSharpName(this Schema operation) =>
|
||||
operation.Language.Default.Name.ToCleanName();
|
||||
|
||||
public static string CSharpName(this ISchemaTypeProvider operation) =>
|
||||
operation.Name.ToCleanName();
|
||||
|
||||
public static bool IsLazy(this Schema operation) => operation is ArraySchema || operation is DictionarySchema;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using AutoRest.CSharp.V3.ClientModel;
|
||||
using AutoRest.CSharp.V3.CodeGen;
|
||||
using AutoRest.CSharp.V3.JsonRpc.MessageModels;
|
||||
using AutoRest.CSharp.V3.Pipeline;
|
||||
|
@ -18,21 +20,27 @@ namespace AutoRest.CSharp.V3.Plugins
|
|||
var schemas = (codeModel.Schemas.Choices ?? Enumerable.Empty<ChoiceSchema>()).Cast<Schema>()
|
||||
.Concat(codeModel.Schemas.SealedChoices ?? Enumerable.Empty<SealedChoiceSchema>())
|
||||
.Concat(codeModel.Schemas.Objects ?? Enumerable.Empty<ObjectSchema>());
|
||||
foreach (var schema in schemas)
|
||||
{
|
||||
var name = schema.CSharpName() ?? "[NO NAME]";
|
||||
var writer = new SchemaWriter(new TypeFactory(configuration.Namespace));
|
||||
writer.WriteSchema(schema);
|
||||
await autoRest.WriteFile($"Generated/Models/{name}.cs", writer.ToFormattedCode(), "source-file-csharp");
|
||||
|
||||
var serializeWriter = new SerializationWriter(new TypeFactory(configuration.Namespace));
|
||||
serializeWriter.WriteSerialization(schema);
|
||||
var entities = schemas.Select(BuildEntity).ToArray();
|
||||
var typeProviders = entities.OfType<ISchemaTypeProvider>().ToArray();
|
||||
var typeFactory = new TypeFactory(configuration.Namespace, typeProviders);
|
||||
|
||||
foreach (var entity in entities)
|
||||
{
|
||||
var name = entity.Name;
|
||||
var writer = new SchemaWriter(typeFactory);
|
||||
writer.WriteSchema(entity);
|
||||
|
||||
var serializeWriter = new SerializationWriter(typeFactory);
|
||||
serializeWriter.WriteSerialization(entity);
|
||||
|
||||
await autoRest.WriteFile($"Generated/Models/{name}.cs", writer.ToFormattedCode(), "source-file-csharp");
|
||||
await autoRest.WriteFile($"Generated/Models/{name}.Serialization.cs", serializeWriter.ToFormattedCode(), "source-file-csharp");
|
||||
}
|
||||
|
||||
foreach (var operationGroup in codeModel.OperationGroups)
|
||||
{
|
||||
var writer = new OperationWriter(new TypeFactory(configuration.Namespace));
|
||||
var writer = new OperationWriter(typeFactory);
|
||||
writer.WriteOperationGroup(operationGroup);
|
||||
await autoRest.WriteFile($"Generated/Operations/{operationGroup.CSharpName()}.cs", writer.ToFormattedCode(), "source-file-csharp");
|
||||
}
|
||||
|
@ -42,5 +50,59 @@ namespace AutoRest.CSharp.V3.Plugins
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
private ClientModel.ClientModel BuildEntity(Schema schema)
|
||||
{
|
||||
switch (schema)
|
||||
{
|
||||
case SealedChoiceSchema sealedChoiceSchema:
|
||||
return new ClientEnum(sealedChoiceSchema,
|
||||
sealedChoiceSchema.CSharpName(),
|
||||
sealedChoiceSchema.Choices.Select(c => new ClientEnumValue(c.CSharpName(), new ClientConstant(c.Value, new FrameworkTypeReference(typeof(string))))))
|
||||
{
|
||||
IsStringBased = false
|
||||
};
|
||||
case ChoiceSchema choiceSchema:
|
||||
return new ClientEnum(choiceSchema,
|
||||
choiceSchema.CSharpName(),
|
||||
choiceSchema.Choices.Select(c => new ClientEnumValue(c.CSharpName(), new ClientConstant(c.Value, new FrameworkTypeReference(typeof(string))))))
|
||||
{
|
||||
IsStringBased = true
|
||||
};
|
||||
case ObjectSchema objectSchema:
|
||||
return new ClientModel.ClientObject(objectSchema, objectSchema.CSharpName(),
|
||||
objectSchema.Properties.Where(p => !(p.Schema is ConstantSchema)).Select(CreateProperty),
|
||||
objectSchema.Properties.Where(p=>p.Schema is ConstantSchema).Select(CreateConstant));
|
||||
}
|
||||
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private static ClientObjectConstant CreateConstant(Property property)
|
||||
{
|
||||
var constantSchema = (ConstantSchema)property.Schema;
|
||||
FrameworkTypeReference type = (FrameworkTypeReference)CreateType(constantSchema.ValueType, false);
|
||||
return new ClientObjectConstant(property.CSharpName(), type, new ClientConstant(constantSchema.Value.Value, type));
|
||||
}
|
||||
|
||||
private static ClientObjectProperty CreateProperty(Property property)
|
||||
{
|
||||
return new ClientObjectProperty(property.CSharpName(), CreateType(property.Schema, property.IsNullable()), property.Schema.IsLazy(), property.SerializedName);
|
||||
}
|
||||
|
||||
private static ClientTypeReference CreateType(Schema schema, bool isNullable)
|
||||
{
|
||||
switch (schema)
|
||||
{
|
||||
case ArraySchema array:
|
||||
return new CollectionTypeReference(CreateType(array.ElementType, false));
|
||||
case DictionarySchema dictionary:
|
||||
return new DictionaryTypeReference(new FrameworkTypeReference(typeof(string)), CreateType(dictionary.ElementType, isNullable));
|
||||
case Schema s when s.Type.ToFrameworkCSharpType() is Type type:
|
||||
return new FrameworkTypeReference(type, isNullable);
|
||||
default:
|
||||
return new SchemaTypeReference(schema, isNullable);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using AutoRest.CSharp.V3.ClientModel;
|
||||
using AutoRest.CSharp.V3.Pipeline;
|
||||
using AutoRest.CSharp.V3.Pipeline.Generated;
|
||||
using AutoRest.CSharp.V3.Utilities;
|
||||
|
@ -13,10 +14,17 @@ namespace AutoRest.CSharp.V3.Plugins
|
|||
internal class TypeFactory
|
||||
{
|
||||
private readonly string _namespace;
|
||||
private readonly ISchemaTypeProvider[] _schemaTypes;
|
||||
|
||||
public TypeFactory(string @namespace)
|
||||
public TypeFactory(string @namespace, ISchemaTypeProvider[] schemaTypes)
|
||||
{
|
||||
_namespace = @namespace;
|
||||
_schemaTypes = schemaTypes;
|
||||
}
|
||||
|
||||
public CSharpType CreateType(ISchemaTypeProvider clientTypeProvider)
|
||||
{
|
||||
return DefaultTypeInfo(clientTypeProvider.Schema);
|
||||
}
|
||||
|
||||
public CSharpType CreateType(Schema schema)
|
||||
|
@ -26,17 +34,7 @@ namespace AutoRest.CSharp.V3.Plugins
|
|||
return CreateTypeInfo(schema);
|
||||
}
|
||||
|
||||
public CSharpType? CreateConcreteType(Schema schema)
|
||||
{
|
||||
if (!(schema is ArraySchema || schema is DictionarySchema))
|
||||
{
|
||||
return CreateType(schema);
|
||||
}
|
||||
|
||||
return CreateTypeInfo(schema, true);
|
||||
}
|
||||
|
||||
public CSharpType? CreateInputType(Schema schema)
|
||||
public CSharpType CreateInputType(Schema schema)
|
||||
{
|
||||
if (!(schema is ArraySchema || schema is DictionarySchema))
|
||||
{
|
||||
|
@ -49,23 +47,16 @@ namespace AutoRest.CSharp.V3.Plugins
|
|||
public CSharpType CreateType(OperationGroup operationGroup)
|
||||
{
|
||||
var apiVersion = operationGroup.Operations.Where(o => o.ApiVersions != null).SelectMany(o => o.ApiVersions).FirstOrDefault()?.Version.RemoveNonWordCharacters();
|
||||
return new CSharpType
|
||||
{
|
||||
Name = operationGroup.CSharpName() ?? operationGroup.Language.Default.Name,
|
||||
Namespace = new CSharpNamespace
|
||||
{
|
||||
Base = _namespace.NullIfEmpty(),
|
||||
Category = "Operations",
|
||||
ApiVersion = apiVersion != null ? $"V{apiVersion}" : null
|
||||
}
|
||||
};
|
||||
return new CSharpType(
|
||||
new CSharpNamespace(_namespace.NullIfEmpty(), "Operations", apiVersion != null ? $"V{apiVersion}" : operationGroup.Language.Default.Namespace),
|
||||
operationGroup.CSharpName() ?? operationGroup.Language.Default.Name);
|
||||
}
|
||||
|
||||
// TODO: Clean this type selection mechanism up
|
||||
private CSharpType? CreateTypeInfo(Schema schema, bool useConcrete = false, bool useInput = false) =>
|
||||
private CSharpType CreateTypeInfo(Schema schema, bool useConcrete = false, bool useInput = false) =>
|
||||
schema switch
|
||||
{
|
||||
{ } s when s.Type.ToFrameworkCSharpType() is { } t => t,
|
||||
Schema s when s.Type.ToFrameworkCSharpType() is Type t => new CSharpType(t),
|
||||
ArraySchema arraySchema => ArrayTypeInfo(arraySchema, useConcrete, useInput),
|
||||
DictionarySchema dictionarySchema => DictionaryTypeInfo(dictionarySchema, useConcrete),
|
||||
ConstantSchema constantSchema => ConstantTypeInfo(constantSchema),
|
||||
|
@ -80,37 +71,66 @@ namespace AutoRest.CSharp.V3.Plugins
|
|||
private readonly Type IDictionaryType = typeof(IDictionary<string, object>);
|
||||
|
||||
private CSharpType ArrayTypeInfo(ArraySchema schema, bool useConcrete = false, bool useInput = false) =>
|
||||
new CSharpType
|
||||
{
|
||||
FrameworkType = useConcrete ? ListType : (useInput ? IEnumerableType : ICollectionType),
|
||||
SubType1 = CreateTypeInfo(schema.ElementType)
|
||||
};
|
||||
new CSharpType(useConcrete ? ListType : (useInput ? IEnumerableType : ICollectionType),
|
||||
CreateTypeInfo(schema.ElementType));
|
||||
|
||||
private CSharpType DictionaryTypeInfo(DictionarySchema schema,
|
||||
bool useConcrete = false) =>
|
||||
new CSharpType
|
||||
{
|
||||
// The generic type arguments are not used when assigning them via FrameworkType.
|
||||
FrameworkType = useConcrete ? DictionaryType : IDictionaryType,
|
||||
SubType1 = AllSchemaTypes.String.ToFrameworkCSharpType(),
|
||||
SubType2 = CreateTypeInfo(schema.ElementType)
|
||||
};
|
||||
new CSharpType(useConcrete ? DictionaryType : IDictionaryType, new CSharpType(typeof(string)), CreateTypeInfo(schema.ElementType));
|
||||
|
||||
private CSharpType ConstantTypeInfo(ConstantSchema schema) => CreateTypeInfo(schema.ValueType) ?? AllSchemaTypes.String.ToFrameworkCSharpType()!;
|
||||
private CSharpType ConstantTypeInfo(ConstantSchema schema) => CreateTypeInfo(schema.ValueType) ?? new CSharpType(typeof(string));
|
||||
|
||||
private CSharpType DefaultTypeInfo(Schema schema)
|
||||
{
|
||||
var apiVersion = schema.ApiVersions?.FirstOrDefault()?.Version.RemoveNonWordCharacters();
|
||||
return new CSharpType
|
||||
{
|
||||
Name = schema.CSharpName() ?? schema.Language.Default.Name,
|
||||
Namespace = new CSharpNamespace
|
||||
{
|
||||
Base = _namespace.NullIfEmpty(),
|
||||
Category = "Models",
|
||||
ApiVersion = apiVersion != null ? $"V{apiVersion}" : schema.Language.Default.Namespace
|
||||
}
|
||||
};
|
||||
return new CSharpType(
|
||||
new CSharpNamespace(_namespace.NullIfEmpty(), "Models", apiVersion != null ? $"V{apiVersion}" : schema.Language.Default.Namespace),
|
||||
schema.CSharpName() ?? schema.Language.Default.Name);
|
||||
}
|
||||
|
||||
public CSharpType CreateType(ClientTypeReference clientTypeProvider)
|
||||
{
|
||||
return CreateTypeInfo(clientTypeProvider);
|
||||
}
|
||||
|
||||
public CSharpType CreateConcreteType(ClientTypeReference clientTypeProvider)
|
||||
{
|
||||
return CreateTypeInfo(clientTypeProvider, useConcrete: true);
|
||||
}
|
||||
|
||||
public ISchemaTypeProvider ResolveReference(SchemaTypeReference reference)
|
||||
{
|
||||
return _schemaTypes.Single(s => s.Schema == reference.Schema);
|
||||
}
|
||||
|
||||
private CSharpType CreateTypeInfo(ClientTypeReference schema, bool useConcrete = false, bool useInput = false) =>
|
||||
schema switch
|
||||
{
|
||||
CollectionTypeReference arraySchema => ArrayTypeInfo(arraySchema, useConcrete, useInput),
|
||||
DictionaryTypeReference dictionarySchema => DictionaryTypeInfo(dictionarySchema, useConcrete),
|
||||
SchemaTypeReference schemaTypeReference => DefaultTypeInfo(schemaTypeReference),
|
||||
FrameworkTypeReference frameworkTypeReference => new CSharpType(frameworkTypeReference.Type, isNullable: frameworkTypeReference.IsNullable),
|
||||
_ => throw new NotImplementedException()
|
||||
};
|
||||
|
||||
private CSharpType ArrayTypeInfo(CollectionTypeReference schema, bool useConcrete = false, bool useInput = false) =>
|
||||
new CSharpType(useConcrete ? ListType : (useInput ? IEnumerableType : ICollectionType),
|
||||
CreateTypeInfo(schema.ItemType));
|
||||
|
||||
private CSharpType DictionaryTypeInfo(DictionaryTypeReference schema,
|
||||
bool useConcrete = false) =>
|
||||
new CSharpType(useConcrete ? DictionaryType : IDictionaryType, CreateTypeInfo(schema.KeyType), CreateTypeInfo(schema.ValueType));
|
||||
|
||||
private CSharpType DefaultTypeInfo(SchemaTypeReference schemaReference)
|
||||
{
|
||||
var type = ResolveReference(schemaReference);
|
||||
var schema = type.Schema;
|
||||
var apiVersion = schema.ApiVersions?.FirstOrDefault()?.Version.RemoveNonWordCharacters();
|
||||
return new CSharpType(
|
||||
new CSharpNamespace(_namespace.NullIfEmpty(), "Models", apiVersion != null ? $"V{apiVersion}" : schema.Language.Default.Namespace),
|
||||
type.Name,
|
||||
isNullable: schemaReference.IsNullable);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
},
|
||||
"Standalone": {
|
||||
"commandName": "Project",
|
||||
"commandLineArgs": "--standalone --input-codemodel=D:/github/azure/autorest.csharp/test/AutoRest.TestServer.Tests/body-string/CodeModel-body-string.yaml --plugin=cs-modeler --base-path=D:/github/azure/autorest.csharp/test/AutoRest.TestServer.Tests/body-string/ --namespace=body_string"
|
||||
"commandLineArgs": "--standalone --input-codemodel=d:\\github\\azure\\autorest.csharp\\test\\AutoRest.TestServer.Tests\\body-complex\\CodeModel-body-complex.yaml --plugin=cs-modeler --base-path=D:/github/azure/autorest.csharp/test/AutoRest.TestServer.Tests/body-complex/ --namespace=body_complex"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -17,14 +17,6 @@ namespace AutoRest.CSharp.V3.Utilities
|
|||
|
||||
public static string TextOrEmpty(this object? value, string text) => value != null ? text : String.Empty;
|
||||
|
||||
//https://stackoverflow.com/a/324812/294804
|
||||
//private static string ToStringLiteral(string input)
|
||||
//{
|
||||
// using var writer = new StringWriter();
|
||||
// using var provider = CodeDomProvider.CreateProvider("CSharp");
|
||||
// provider.GenerateCodeFromExpression(new CodePrimitiveExpression(input), writer, null);
|
||||
// return writer.ToString();
|
||||
//}
|
||||
|
||||
public static string? ToStringLiteral(this string? text) =>
|
||||
!String.IsNullOrEmpty(text)
|
||||
|
|
|
@ -7,25 +7,16 @@ namespace body_complex.Models.V20160229
|
|||
{
|
||||
public partial class ArrayWrapper
|
||||
{
|
||||
internal void Serialize(Utf8JsonWriter writer, bool includeName = true)
|
||||
internal void Serialize(Utf8JsonWriter writer)
|
||||
{
|
||||
if (includeName)
|
||||
writer.WriteStartObject();
|
||||
writer.WriteStartArray("array");
|
||||
foreach (var item in Array)
|
||||
{
|
||||
writer.WriteStartObject("array-wrapper");
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteStartObject();
|
||||
}
|
||||
if (_array != null)
|
||||
{
|
||||
writer.WriteStartArray("array");
|
||||
foreach (var item in _array)
|
||||
{
|
||||
writer.WriteStringValue(item);
|
||||
}
|
||||
writer.WriteEndArray();
|
||||
writer.WritePropertyName("array");
|
||||
writer.WriteStringValue(item);
|
||||
}
|
||||
writer.WriteEndArray();
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
internal static ArrayWrapper Deserialize(JsonElement element)
|
||||
|
|
|
@ -2,14 +2,11 @@
|
|||
// Licensed under the MIT License.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
|
||||
namespace body_complex.Models.V20160229
|
||||
{
|
||||
public partial class ArrayWrapper
|
||||
{
|
||||
private List<string>? _array;
|
||||
|
||||
public ICollection<string> Array => LazyInitializer.EnsureInitialized(ref _array);
|
||||
public ICollection<string> Array { get; } = new List<string>();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,27 +7,23 @@ namespace body_complex.Models.V20160229
|
|||
{
|
||||
public partial class Basic
|
||||
{
|
||||
internal void Serialize(Utf8JsonWriter writer, bool includeName = true)
|
||||
internal void Serialize(Utf8JsonWriter writer)
|
||||
{
|
||||
if (includeName)
|
||||
{
|
||||
writer.WriteStartObject("basic");
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteStartObject();
|
||||
}
|
||||
writer.WriteStartObject();
|
||||
if (Id != null)
|
||||
{
|
||||
writer.WriteNumber("id", Id.Value);
|
||||
writer.WritePropertyName("id");
|
||||
writer.WriteNumberValue(Id.Value);
|
||||
}
|
||||
if (Name != null)
|
||||
{
|
||||
writer.WriteString("name", Name);
|
||||
writer.WritePropertyName("name");
|
||||
writer.WriteStringValue(Name);
|
||||
}
|
||||
if (Color != null)
|
||||
{
|
||||
writer.WriteString("color", Color?.ToSerialString());
|
||||
writer.WritePropertyName("color");
|
||||
writer.WriteStringValue(Color.Value.ToSerialString());
|
||||
}
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
|
|
|
@ -7,23 +7,18 @@ namespace body_complex.Models.V20160229
|
|||
{
|
||||
public partial class BooleanWrapper
|
||||
{
|
||||
internal void Serialize(Utf8JsonWriter writer, bool includeName = true)
|
||||
internal void Serialize(Utf8JsonWriter writer)
|
||||
{
|
||||
if (includeName)
|
||||
{
|
||||
writer.WriteStartObject("boolean-wrapper");
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteStartObject();
|
||||
}
|
||||
writer.WriteStartObject();
|
||||
if (FieldTrue != null)
|
||||
{
|
||||
writer.WriteBoolean("field_true", FieldTrue.Value);
|
||||
writer.WritePropertyName("field_true");
|
||||
writer.WriteBooleanValue(FieldTrue.Value);
|
||||
}
|
||||
if (FieldFalse != null)
|
||||
{
|
||||
writer.WriteBoolean("field_false", FieldFalse.Value);
|
||||
writer.WritePropertyName("field_false");
|
||||
writer.WriteBooleanValue(FieldFalse.Value);
|
||||
}
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
|
|
|
@ -1,25 +1,20 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
using System;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace body_complex.Models.V20160229
|
||||
{
|
||||
public partial class ByteWrapper
|
||||
{
|
||||
internal void Serialize(Utf8JsonWriter writer, bool includeName = true)
|
||||
internal void Serialize(Utf8JsonWriter writer)
|
||||
{
|
||||
if (includeName)
|
||||
{
|
||||
writer.WriteStartObject("byte-wrapper");
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteStartObject();
|
||||
}
|
||||
writer.WriteStartObject();
|
||||
if (Field != null)
|
||||
{
|
||||
writer.WriteBase64String("field", Field);
|
||||
writer.WritePropertyName("field");
|
||||
writer.WriteNullValue();
|
||||
}
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
|
@ -30,7 +25,7 @@ namespace body_complex.Models.V20160229
|
|||
{
|
||||
if (property.NameEquals("field"))
|
||||
{
|
||||
result.Field = property.Value.GetBytesFromBase64();
|
||||
result.Field = null;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
using System;
|
||||
|
||||
namespace body_complex.Models.V20160229
|
||||
{
|
||||
public partial class ByteWrapper
|
||||
{
|
||||
public byte[]? Field { get; set; }
|
||||
public Byte[]? Field { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,29 +7,21 @@ namespace body_complex.Models.V20160229
|
|||
{
|
||||
public partial class Cat
|
||||
{
|
||||
internal void Serialize(Utf8JsonWriter writer, bool includeName = true)
|
||||
internal void Serialize(Utf8JsonWriter writer)
|
||||
{
|
||||
if (includeName)
|
||||
{
|
||||
writer.WriteStartObject("cat");
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteStartObject();
|
||||
}
|
||||
writer.WriteStartObject();
|
||||
if (Color != null)
|
||||
{
|
||||
writer.WriteString("color", Color);
|
||||
writer.WritePropertyName("color");
|
||||
writer.WriteStringValue(Color);
|
||||
}
|
||||
if (_hates != null)
|
||||
writer.WriteStartArray("hates");
|
||||
foreach (var item in Hates)
|
||||
{
|
||||
writer.WriteStartArray("hates");
|
||||
foreach (var item in _hates)
|
||||
{
|
||||
item?.Serialize(writer, true);
|
||||
}
|
||||
writer.WriteEndArray();
|
||||
writer.WritePropertyName("hates");
|
||||
item.Serialize(writer);
|
||||
}
|
||||
writer.WriteEndArray();
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
internal static Cat Deserialize(JsonElement element)
|
||||
|
@ -46,7 +38,7 @@ namespace body_complex.Models.V20160229
|
|||
{
|
||||
foreach (var item in property.Value.EnumerateArray())
|
||||
{
|
||||
result.Hates.Add(body_complex.Models.V20160229.Dog.Deserialize(item));
|
||||
result.Hates.Add(Dog.Deserialize(item));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -2,15 +2,12 @@
|
|||
// Licensed under the MIT License.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
|
||||
namespace body_complex.Models.V20160229
|
||||
{
|
||||
public partial class Cat
|
||||
{
|
||||
private List<Dog>? _hates;
|
||||
|
||||
public string? Color { get; set; }
|
||||
public ICollection<Dog> Hates => LazyInitializer.EnsureInitialized(ref _hates);
|
||||
public ICollection<Dog> Hates { get; } = new List<Dog>();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,16 +7,9 @@ namespace body_complex.Models.V20160229
|
|||
{
|
||||
public partial class Cookiecuttershark
|
||||
{
|
||||
internal void Serialize(Utf8JsonWriter writer, bool includeName = true)
|
||||
internal void Serialize(Utf8JsonWriter writer)
|
||||
{
|
||||
if (includeName)
|
||||
{
|
||||
writer.WriteStartObject("cookiecuttershark");
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteStartObject();
|
||||
}
|
||||
writer.WriteStartObject();
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
internal static Cookiecuttershark Deserialize(JsonElement element)
|
||||
|
|
|
@ -1,29 +1,25 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
using System;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace body_complex.Models.V20160229
|
||||
{
|
||||
public partial class DateWrapper
|
||||
{
|
||||
internal void Serialize(Utf8JsonWriter writer, bool includeName = true)
|
||||
internal void Serialize(Utf8JsonWriter writer)
|
||||
{
|
||||
if (includeName)
|
||||
{
|
||||
writer.WriteStartObject("date-wrapper");
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteStartObject();
|
||||
}
|
||||
writer.WriteStartObject();
|
||||
if (Field != null)
|
||||
{
|
||||
writer.WriteString("field", Field.ToString());
|
||||
writer.WritePropertyName("field");
|
||||
writer.WriteStringValue(Field.ToString());
|
||||
}
|
||||
if (Leap != null)
|
||||
{
|
||||
writer.WriteString("leap", Leap.ToString());
|
||||
writer.WritePropertyName("leap");
|
||||
writer.WriteStringValue(Leap.ToString());
|
||||
}
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
|
|
|
@ -1,29 +1,25 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
using System;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace body_complex.Models.V20160229
|
||||
{
|
||||
public partial class DatetimeWrapper
|
||||
{
|
||||
internal void Serialize(Utf8JsonWriter writer, bool includeName = true)
|
||||
internal void Serialize(Utf8JsonWriter writer)
|
||||
{
|
||||
if (includeName)
|
||||
{
|
||||
writer.WriteStartObject("datetime-wrapper");
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteStartObject();
|
||||
}
|
||||
writer.WriteStartObject();
|
||||
if (Field != null)
|
||||
{
|
||||
writer.WriteString("field", Field.ToString());
|
||||
writer.WritePropertyName("field");
|
||||
writer.WriteStringValue(Field.ToString());
|
||||
}
|
||||
if (Now != null)
|
||||
{
|
||||
writer.WriteString("now", Now.ToString());
|
||||
writer.WritePropertyName("now");
|
||||
writer.WriteStringValue(Now.ToString());
|
||||
}
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
|
|
|
@ -1,29 +1,25 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
using System;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace body_complex.Models.V20160229
|
||||
{
|
||||
public partial class Datetimerfc1123Wrapper
|
||||
{
|
||||
internal void Serialize(Utf8JsonWriter writer, bool includeName = true)
|
||||
internal void Serialize(Utf8JsonWriter writer)
|
||||
{
|
||||
if (includeName)
|
||||
{
|
||||
writer.WriteStartObject("datetimerfc1123-wrapper");
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteStartObject();
|
||||
}
|
||||
writer.WriteStartObject();
|
||||
if (Field != null)
|
||||
{
|
||||
writer.WriteString("field", Field.ToString());
|
||||
writer.WritePropertyName("field");
|
||||
writer.WriteStringValue(Field.ToString());
|
||||
}
|
||||
if (Now != null)
|
||||
{
|
||||
writer.WriteString("now", Now.ToString());
|
||||
writer.WritePropertyName("now");
|
||||
writer.WriteStringValue(Now.ToString());
|
||||
}
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
|
|
|
@ -7,26 +7,17 @@ namespace body_complex.Models.V20160229
|
|||
{
|
||||
public partial class DictionaryWrapper
|
||||
{
|
||||
internal void Serialize(Utf8JsonWriter writer, bool includeName = true)
|
||||
internal void Serialize(Utf8JsonWriter writer)
|
||||
{
|
||||
if (includeName)
|
||||
writer.WriteStartObject();
|
||||
writer.WriteStartObject("defaultProgram");
|
||||
foreach (var item in DefaultProgram)
|
||||
{
|
||||
writer.WriteStartObject("dictionary-wrapper");
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteStartObject();
|
||||
}
|
||||
if (_defaultProgram != null)
|
||||
{
|
||||
writer.WriteStartObject("defaultProgram");
|
||||
foreach (var item in _defaultProgram)
|
||||
{
|
||||
writer.WriteString(item.Key, item.Value);
|
||||
}
|
||||
writer.WriteEndObject();
|
||||
writer.WritePropertyName("item.Key");
|
||||
writer.WriteStringValue(item.Value);
|
||||
}
|
||||
writer.WriteEndObject();
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
internal static DictionaryWrapper Deserialize(JsonElement element)
|
||||
{
|
||||
|
|
|
@ -2,14 +2,11 @@
|
|||
// Licensed under the MIT License.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
|
||||
namespace body_complex.Models.V20160229
|
||||
{
|
||||
public partial class DictionaryWrapper
|
||||
{
|
||||
private Dictionary<string, string>? _defaultProgram;
|
||||
|
||||
public IDictionary<string, string> DefaultProgram => LazyInitializer.EnsureInitialized(ref _defaultProgram);
|
||||
public IDictionary<string, string?> DefaultProgram { get; } = new Dictionary<string, string?>();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,19 +7,13 @@ namespace body_complex.Models.V20160229
|
|||
{
|
||||
public partial class Dog
|
||||
{
|
||||
internal void Serialize(Utf8JsonWriter writer, bool includeName = true)
|
||||
internal void Serialize(Utf8JsonWriter writer)
|
||||
{
|
||||
if (includeName)
|
||||
{
|
||||
writer.WriteStartObject("dog");
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteStartObject();
|
||||
}
|
||||
writer.WriteStartObject();
|
||||
if (Food != null)
|
||||
{
|
||||
writer.WriteString("food", Food);
|
||||
writer.WritePropertyName("food");
|
||||
writer.WriteStringValue(Food);
|
||||
}
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
|
|
|
@ -7,20 +7,15 @@ namespace body_complex.Models.V20160229
|
|||
{
|
||||
public partial class DotFish
|
||||
{
|
||||
internal void Serialize(Utf8JsonWriter writer, bool includeName = true)
|
||||
internal void Serialize(Utf8JsonWriter writer)
|
||||
{
|
||||
if (includeName)
|
||||
{
|
||||
writer.WriteStartObject("DotFish");
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteStartObject();
|
||||
}
|
||||
writer.WriteString("fish.type", FishType);
|
||||
writer.WriteStartObject();
|
||||
writer.WritePropertyName("fish.type");
|
||||
writer.WriteStringValue(FishType);
|
||||
if (Species != null)
|
||||
{
|
||||
writer.WriteString("species", Species);
|
||||
writer.WritePropertyName("species");
|
||||
writer.WriteStringValue(Species);
|
||||
}
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
|
|
|
@ -5,18 +5,7 @@ namespace body_complex.Models.V20160229
|
|||
{
|
||||
public partial class DotFish
|
||||
{
|
||||
public string FishType { get; private set; }
|
||||
public string FishType { get; set; }
|
||||
public string? Species { get; set; }
|
||||
|
||||
#pragma warning disable CS8618 // Non-nullable field is uninitialized. Consider declaring as nullable.
|
||||
private DotFish()
|
||||
{
|
||||
}
|
||||
#pragma warning restore CS8618 // Non-nullable field is uninitialized. Consider declaring as nullable.
|
||||
|
||||
public DotFish(string fishtype)
|
||||
{
|
||||
FishType = fishtype;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,42 +7,33 @@ namespace body_complex.Models.V20160229
|
|||
{
|
||||
public partial class DotFishMarket
|
||||
{
|
||||
internal void Serialize(Utf8JsonWriter writer, bool includeName = true)
|
||||
internal void Serialize(Utf8JsonWriter writer)
|
||||
{
|
||||
if (includeName)
|
||||
{
|
||||
writer.WriteStartObject("DotFishMarket");
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteStartObject();
|
||||
}
|
||||
writer.WriteStartObject();
|
||||
if (SampleSalmon != null)
|
||||
{
|
||||
SampleSalmon?.Serialize(writer, true);
|
||||
writer.WritePropertyName("sampleSalmon");
|
||||
SampleSalmon?.Serialize(writer);
|
||||
}
|
||||
if (_salmons != null)
|
||||
writer.WriteStartArray("salmons");
|
||||
foreach (var item in Salmons)
|
||||
{
|
||||
writer.WriteStartArray("salmons");
|
||||
foreach (var item in _salmons)
|
||||
{
|
||||
item?.Serialize(writer, true);
|
||||
}
|
||||
writer.WriteEndArray();
|
||||
writer.WritePropertyName("salmons");
|
||||
item.Serialize(writer);
|
||||
}
|
||||
writer.WriteEndArray();
|
||||
if (SampleFish != null)
|
||||
{
|
||||
SampleFish?.Serialize(writer, true);
|
||||
writer.WritePropertyName("sampleFish");
|
||||
SampleFish?.Serialize(writer);
|
||||
}
|
||||
if (_fishes != null)
|
||||
writer.WriteStartArray("fishes");
|
||||
foreach (var item in Fishes)
|
||||
{
|
||||
writer.WriteStartArray("fishes");
|
||||
foreach (var item in _fishes)
|
||||
{
|
||||
item?.Serialize(writer, true);
|
||||
}
|
||||
writer.WriteEndArray();
|
||||
writer.WritePropertyName("fishes");
|
||||
item.Serialize(writer);
|
||||
}
|
||||
writer.WriteEndArray();
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
internal static DotFishMarket Deserialize(JsonElement element)
|
||||
|
@ -52,27 +43,27 @@ namespace body_complex.Models.V20160229
|
|||
{
|
||||
if (property.NameEquals("sampleSalmon"))
|
||||
{
|
||||
result.SampleSalmon = body_complex.Models.V20160229.DotSalmon.Deserialize(property.Value);
|
||||
result.SampleSalmon = DotSalmon.Deserialize(property.Value);
|
||||
continue;
|
||||
}
|
||||
if (property.NameEquals("salmons"))
|
||||
{
|
||||
foreach (var item in property.Value.EnumerateArray())
|
||||
{
|
||||
result.Salmons.Add(body_complex.Models.V20160229.DotSalmon.Deserialize(item));
|
||||
result.Salmons.Add(DotSalmon.Deserialize(item));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (property.NameEquals("sampleFish"))
|
||||
{
|
||||
result.SampleFish = body_complex.Models.V20160229.DotFish.Deserialize(property.Value);
|
||||
result.SampleFish = DotFish.Deserialize(property.Value);
|
||||
continue;
|
||||
}
|
||||
if (property.NameEquals("fishes"))
|
||||
{
|
||||
foreach (var item in property.Value.EnumerateArray())
|
||||
{
|
||||
result.Fishes.Add(body_complex.Models.V20160229.DotFish.Deserialize(item));
|
||||
result.Fishes.Add(DotFish.Deserialize(item));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -2,18 +2,14 @@
|
|||
// Licensed under the MIT License.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
|
||||
namespace body_complex.Models.V20160229
|
||||
{
|
||||
public partial class DotFishMarket
|
||||
{
|
||||
private List<DotSalmon>? _salmons;
|
||||
private List<DotFish>? _fishes;
|
||||
|
||||
public DotSalmon? SampleSalmon { get; set; }
|
||||
public ICollection<DotSalmon> Salmons => LazyInitializer.EnsureInitialized(ref _salmons);
|
||||
public ICollection<DotSalmon> Salmons { get; } = new List<DotSalmon>();
|
||||
public DotFish? SampleFish { get; set; }
|
||||
public ICollection<DotFish> Fishes => LazyInitializer.EnsureInitialized(ref _fishes);
|
||||
public ICollection<DotFish> Fishes { get; } = new List<DotFish>();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,23 +7,18 @@ namespace body_complex.Models.V20160229
|
|||
{
|
||||
public partial class DotSalmon
|
||||
{
|
||||
internal void Serialize(Utf8JsonWriter writer, bool includeName = true)
|
||||
internal void Serialize(Utf8JsonWriter writer)
|
||||
{
|
||||
if (includeName)
|
||||
{
|
||||
writer.WriteStartObject("DotSalmon");
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteStartObject();
|
||||
}
|
||||
writer.WriteStartObject();
|
||||
if (Location != null)
|
||||
{
|
||||
writer.WriteString("location", Location);
|
||||
writer.WritePropertyName("location");
|
||||
writer.WriteStringValue(Location);
|
||||
}
|
||||
if (Iswild != null)
|
||||
{
|
||||
writer.WriteBoolean("iswild", Iswild.Value);
|
||||
writer.WritePropertyName("iswild");
|
||||
writer.WriteBooleanValue(Iswild.Value);
|
||||
}
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
|
|
|
@ -7,23 +7,18 @@ namespace body_complex.Models.V20160229
|
|||
{
|
||||
public partial class DoubleWrapper
|
||||
{
|
||||
internal void Serialize(Utf8JsonWriter writer, bool includeName = true)
|
||||
internal void Serialize(Utf8JsonWriter writer)
|
||||
{
|
||||
if (includeName)
|
||||
{
|
||||
writer.WriteStartObject("double-wrapper");
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteStartObject();
|
||||
}
|
||||
writer.WriteStartObject();
|
||||
if (Field1 != null)
|
||||
{
|
||||
writer.WriteNumber("field1", Field1.Value);
|
||||
writer.WritePropertyName("field1");
|
||||
writer.WriteNumberValue(Field1.Value);
|
||||
}
|
||||
if (Field56ZerosAfterTheDotAndNegativeZeroBeforeDotAndThisIsALongFieldNameOnPurpose != null)
|
||||
{
|
||||
writer.WriteNumber("field_56_zeros_after_the_dot_and_negative_zero_before_dot_and_this_is_a_long_field_name_on_purpose", Field56ZerosAfterTheDotAndNegativeZeroBeforeDotAndThisIsALongFieldNameOnPurpose.Value);
|
||||
writer.WritePropertyName("field_56_zeros_after_the_dot_and_negative_zero_before_dot_and_this_is_a_long_field_name_on_purpose");
|
||||
writer.WriteNumberValue(Field56ZerosAfterTheDotAndNegativeZeroBeforeDotAndThisIsALongFieldNameOnPurpose.Value);
|
||||
}
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
|
|
|
@ -1,25 +1,20 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
using System;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace body_complex.Models.V20160229
|
||||
{
|
||||
public partial class DurationWrapper
|
||||
{
|
||||
internal void Serialize(Utf8JsonWriter writer, bool includeName = true)
|
||||
internal void Serialize(Utf8JsonWriter writer)
|
||||
{
|
||||
if (includeName)
|
||||
{
|
||||
writer.WriteStartObject("duration-wrapper");
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteStartObject();
|
||||
}
|
||||
writer.WriteStartObject();
|
||||
if (Field != null)
|
||||
{
|
||||
writer.WriteString("field", Field.ToString());
|
||||
writer.WritePropertyName("field");
|
||||
writer.WriteStringValue(Field.ToString());
|
||||
}
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
|
@ -30,7 +25,7 @@ namespace body_complex.Models.V20160229
|
|||
{
|
||||
if (property.NameEquals("field"))
|
||||
{
|
||||
// DurationSchema Field: Not Implemented
|
||||
result.Field = TimeSpan.Parse(property.Value.GetString());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,23 +7,18 @@ namespace body_complex.Models.V20160229
|
|||
{
|
||||
public partial class Error
|
||||
{
|
||||
internal void Serialize(Utf8JsonWriter writer, bool includeName = true)
|
||||
internal void Serialize(Utf8JsonWriter writer)
|
||||
{
|
||||
if (includeName)
|
||||
{
|
||||
writer.WriteStartObject("Error");
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteStartObject();
|
||||
}
|
||||
writer.WriteStartObject();
|
||||
if (Status != null)
|
||||
{
|
||||
writer.WriteNumber("status", Status.Value);
|
||||
writer.WritePropertyName("status");
|
||||
writer.WriteNumberValue(Status.Value);
|
||||
}
|
||||
if (Message != null)
|
||||
{
|
||||
writer.WriteString("message", Message);
|
||||
writer.WritePropertyName("message");
|
||||
writer.WriteStringValue(Message);
|
||||
}
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
|
|
|
@ -7,31 +7,25 @@ namespace body_complex.Models.V20160229
|
|||
{
|
||||
public partial class Fish
|
||||
{
|
||||
internal void Serialize(Utf8JsonWriter writer, bool includeName = true)
|
||||
internal void Serialize(Utf8JsonWriter writer)
|
||||
{
|
||||
if (includeName)
|
||||
{
|
||||
writer.WriteStartObject("Fish");
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteStartObject();
|
||||
}
|
||||
writer.WriteString("fishtype", Fishtype);
|
||||
writer.WriteStartObject();
|
||||
writer.WritePropertyName("fishtype");
|
||||
writer.WriteStringValue(Fishtype);
|
||||
if (Species != null)
|
||||
{
|
||||
writer.WriteString("species", Species);
|
||||
writer.WritePropertyName("species");
|
||||
writer.WriteStringValue(Species);
|
||||
}
|
||||
writer.WriteNumber("length", Length);
|
||||
if (_siblings != null)
|
||||
writer.WritePropertyName("length");
|
||||
writer.WriteNumberValue(Length);
|
||||
writer.WriteStartArray("siblings");
|
||||
foreach (var item in Siblings)
|
||||
{
|
||||
writer.WriteStartArray("siblings");
|
||||
foreach (var item in _siblings)
|
||||
{
|
||||
item?.Serialize(writer, true);
|
||||
}
|
||||
writer.WriteEndArray();
|
||||
writer.WritePropertyName("siblings");
|
||||
item.Serialize(writer);
|
||||
}
|
||||
writer.WriteEndArray();
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
internal static Fish Deserialize(JsonElement element)
|
||||
|
@ -58,7 +52,7 @@ namespace body_complex.Models.V20160229
|
|||
{
|
||||
foreach (var item in property.Value.EnumerateArray())
|
||||
{
|
||||
result.Siblings.Add(body_complex.Models.V20160229.Fish.Deserialize(item));
|
||||
result.Siblings.Add(Fish.Deserialize(item));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -2,29 +2,14 @@
|
|||
// Licensed under the MIT License.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
|
||||
namespace body_complex.Models.V20160229
|
||||
{
|
||||
public partial class Fish
|
||||
{
|
||||
private List<Fish>? _siblings;
|
||||
|
||||
public string Fishtype { get; private set; }
|
||||
public string Fishtype { get; set; }
|
||||
public string? Species { get; set; }
|
||||
public double Length { get; private set; }
|
||||
public ICollection<Fish> Siblings => LazyInitializer.EnsureInitialized(ref _siblings);
|
||||
|
||||
#pragma warning disable CS8618 // Non-nullable field is uninitialized. Consider declaring as nullable.
|
||||
private Fish()
|
||||
{
|
||||
}
|
||||
#pragma warning restore CS8618 // Non-nullable field is uninitialized. Consider declaring as nullable.
|
||||
|
||||
public Fish(string fishtype, double length)
|
||||
{
|
||||
Fishtype = fishtype;
|
||||
Length = length;
|
||||
}
|
||||
public double Length { get; set; }
|
||||
public ICollection<Fish> Siblings { get; } = new List<Fish>();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,23 +7,18 @@ namespace body_complex.Models.V20160229
|
|||
{
|
||||
public partial class FloatWrapper
|
||||
{
|
||||
internal void Serialize(Utf8JsonWriter writer, bool includeName = true)
|
||||
internal void Serialize(Utf8JsonWriter writer)
|
||||
{
|
||||
if (includeName)
|
||||
{
|
||||
writer.WriteStartObject("float-wrapper");
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteStartObject();
|
||||
}
|
||||
writer.WriteStartObject();
|
||||
if (Field1 != null)
|
||||
{
|
||||
writer.WriteNumber("field1", Field1.Value);
|
||||
writer.WritePropertyName("field1");
|
||||
writer.WriteNumberValue(Field1.Value);
|
||||
}
|
||||
if (Field2 != null)
|
||||
{
|
||||
writer.WriteNumber("field2", Field2.Value);
|
||||
writer.WritePropertyName("field2");
|
||||
writer.WriteNumberValue(Field2.Value);
|
||||
}
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
|
|
|
@ -7,23 +7,18 @@ namespace body_complex.Models.V20160229
|
|||
{
|
||||
public partial class Goblinshark
|
||||
{
|
||||
internal void Serialize(Utf8JsonWriter writer, bool includeName = true)
|
||||
internal void Serialize(Utf8JsonWriter writer)
|
||||
{
|
||||
if (includeName)
|
||||
{
|
||||
writer.WriteStartObject("goblinshark");
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteStartObject();
|
||||
}
|
||||
writer.WriteStartObject();
|
||||
if (Jawsize != null)
|
||||
{
|
||||
writer.WriteNumber("jawsize", Jawsize.Value);
|
||||
writer.WritePropertyName("jawsize");
|
||||
writer.WriteNumberValue(Jawsize.Value);
|
||||
}
|
||||
if (Color != null)
|
||||
{
|
||||
writer.WriteString("color", Color?.ToSerialString());
|
||||
writer.WritePropertyName("color");
|
||||
writer.WriteStringValue(Color.Value.ToSerialString());
|
||||
}
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
|
|
|
@ -7,23 +7,18 @@ namespace body_complex.Models.V20160229
|
|||
{
|
||||
public partial class IntWrapper
|
||||
{
|
||||
internal void Serialize(Utf8JsonWriter writer, bool includeName = true)
|
||||
internal void Serialize(Utf8JsonWriter writer)
|
||||
{
|
||||
if (includeName)
|
||||
{
|
||||
writer.WriteStartObject("int-wrapper");
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteStartObject();
|
||||
}
|
||||
writer.WriteStartObject();
|
||||
if (Field1 != null)
|
||||
{
|
||||
writer.WriteNumber("field1", Field1.Value);
|
||||
writer.WritePropertyName("field1");
|
||||
writer.WriteNumberValue(Field1.Value);
|
||||
}
|
||||
if (Field2 != null)
|
||||
{
|
||||
writer.WriteNumber("field2", Field2.Value);
|
||||
writer.WritePropertyName("field2");
|
||||
writer.WriteNumberValue(Field2.Value);
|
||||
}
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
|
|
|
@ -7,23 +7,18 @@ namespace body_complex.Models.V20160229
|
|||
{
|
||||
public partial class LongWrapper
|
||||
{
|
||||
internal void Serialize(Utf8JsonWriter writer, bool includeName = true)
|
||||
internal void Serialize(Utf8JsonWriter writer)
|
||||
{
|
||||
if (includeName)
|
||||
{
|
||||
writer.WriteStartObject("long-wrapper");
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteStartObject();
|
||||
}
|
||||
writer.WriteStartObject();
|
||||
if (Field1 != null)
|
||||
{
|
||||
writer.WriteNumber("field1", Field1.Value);
|
||||
writer.WritePropertyName("field1");
|
||||
writer.WriteNumberValue(Field1.Value);
|
||||
}
|
||||
if (Field2 != null)
|
||||
{
|
||||
writer.WriteNumber("field2", Field2.Value);
|
||||
writer.WritePropertyName("field2");
|
||||
writer.WriteNumberValue(Field2.Value);
|
||||
}
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
|
|
|
@ -7,19 +7,13 @@ namespace body_complex.Models.V20160229
|
|||
{
|
||||
public partial class MyBaseHelperType
|
||||
{
|
||||
internal void Serialize(Utf8JsonWriter writer, bool includeName = true)
|
||||
internal void Serialize(Utf8JsonWriter writer)
|
||||
{
|
||||
if (includeName)
|
||||
{
|
||||
writer.WriteStartObject("MyBaseHelperType");
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteStartObject();
|
||||
}
|
||||
writer.WriteStartObject();
|
||||
if (PropBH1 != null)
|
||||
{
|
||||
writer.WriteString("propBH1", PropBH1);
|
||||
writer.WritePropertyName("propBH1");
|
||||
writer.WriteStringValue(PropBH1);
|
||||
}
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
|
|
|
@ -7,24 +7,18 @@ namespace body_complex.Models.V20160229
|
|||
{
|
||||
public partial class MyBaseType
|
||||
{
|
||||
internal void Serialize(Utf8JsonWriter writer, bool includeName = true)
|
||||
internal void Serialize(Utf8JsonWriter writer)
|
||||
{
|
||||
if (includeName)
|
||||
{
|
||||
writer.WriteStartObject("MyBaseType");
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteStartObject();
|
||||
}
|
||||
writer.WriteString("kind", Kind);
|
||||
writer.WriteStartObject();
|
||||
if (PropB1 != null)
|
||||
{
|
||||
writer.WriteString("propB1", PropB1);
|
||||
writer.WritePropertyName("propB1");
|
||||
writer.WriteStringValue(PropB1);
|
||||
}
|
||||
if (Helper != null)
|
||||
{
|
||||
Helper?.Serialize(writer, true);
|
||||
writer.WritePropertyName("helper");
|
||||
Helper?.Serialize(writer);
|
||||
}
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
|
@ -40,7 +34,7 @@ namespace body_complex.Models.V20160229
|
|||
}
|
||||
if (property.NameEquals("helper"))
|
||||
{
|
||||
result.Helper = body_complex.Models.V20160229.MyBaseHelperType.Deserialize(property.Value);
|
||||
result.Helper = MyBaseHelperType.Deserialize(property.Value);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,19 +7,13 @@ namespace body_complex.Models.V20160229
|
|||
{
|
||||
public partial class MyDerivedType
|
||||
{
|
||||
internal void Serialize(Utf8JsonWriter writer, bool includeName = true)
|
||||
internal void Serialize(Utf8JsonWriter writer)
|
||||
{
|
||||
if (includeName)
|
||||
{
|
||||
writer.WriteStartObject("MyDerivedType");
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteStartObject();
|
||||
}
|
||||
writer.WriteStartObject();
|
||||
if (PropD1 != null)
|
||||
{
|
||||
writer.WriteString("propD1", PropD1);
|
||||
writer.WritePropertyName("propD1");
|
||||
writer.WriteStringValue(PropD1);
|
||||
}
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
|
|
|
@ -7,23 +7,18 @@ namespace body_complex.Models.V20160229
|
|||
{
|
||||
public partial class Pet
|
||||
{
|
||||
internal void Serialize(Utf8JsonWriter writer, bool includeName = true)
|
||||
internal void Serialize(Utf8JsonWriter writer)
|
||||
{
|
||||
if (includeName)
|
||||
{
|
||||
writer.WriteStartObject("pet");
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteStartObject();
|
||||
}
|
||||
writer.WriteStartObject();
|
||||
if (Id != null)
|
||||
{
|
||||
writer.WriteNumber("id", Id.Value);
|
||||
writer.WritePropertyName("id");
|
||||
writer.WriteNumberValue(Id.Value);
|
||||
}
|
||||
if (Name != null)
|
||||
{
|
||||
writer.WriteString("name", Name);
|
||||
writer.WritePropertyName("name");
|
||||
writer.WriteStringValue(Name);
|
||||
}
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
|
|
|
@ -7,23 +7,18 @@ namespace body_complex.Models.V20160229
|
|||
{
|
||||
public partial class ReadonlyObj
|
||||
{
|
||||
internal void Serialize(Utf8JsonWriter writer, bool includeName = true)
|
||||
internal void Serialize(Utf8JsonWriter writer)
|
||||
{
|
||||
if (includeName)
|
||||
{
|
||||
writer.WriteStartObject("readonly-obj");
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteStartObject();
|
||||
}
|
||||
writer.WriteStartObject();
|
||||
if (Id != null)
|
||||
{
|
||||
writer.WriteString("id", Id);
|
||||
writer.WritePropertyName("id");
|
||||
writer.WriteStringValue(Id);
|
||||
}
|
||||
if (Size != null)
|
||||
{
|
||||
writer.WriteNumber("size", Size.Value);
|
||||
writer.WritePropertyName("size");
|
||||
writer.WriteNumberValue(Size.Value);
|
||||
}
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
|
|
|
@ -7,23 +7,18 @@ namespace body_complex.Models.V20160229
|
|||
{
|
||||
public partial class Salmon
|
||||
{
|
||||
internal void Serialize(Utf8JsonWriter writer, bool includeName = true)
|
||||
internal void Serialize(Utf8JsonWriter writer)
|
||||
{
|
||||
if (includeName)
|
||||
{
|
||||
writer.WriteStartObject("salmon");
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteStartObject();
|
||||
}
|
||||
writer.WriteStartObject();
|
||||
if (Location != null)
|
||||
{
|
||||
writer.WriteString("location", Location);
|
||||
writer.WritePropertyName("location");
|
||||
writer.WriteStringValue(Location);
|
||||
}
|
||||
if (Iswild != null)
|
||||
{
|
||||
writer.WriteBoolean("iswild", Iswild.Value);
|
||||
writer.WritePropertyName("iswild");
|
||||
writer.WriteBooleanValue(Iswild.Value);
|
||||
}
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
|
|
|
@ -1,25 +1,20 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
using System;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace body_complex.Models.V20160229
|
||||
{
|
||||
public partial class Sawshark
|
||||
{
|
||||
internal void Serialize(Utf8JsonWriter writer, bool includeName = true)
|
||||
internal void Serialize(Utf8JsonWriter writer)
|
||||
{
|
||||
if (includeName)
|
||||
{
|
||||
writer.WriteStartObject("sawshark");
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteStartObject();
|
||||
}
|
||||
writer.WriteStartObject();
|
||||
if (Picture != null)
|
||||
{
|
||||
writer.WriteBase64String("picture", Picture);
|
||||
writer.WritePropertyName("picture");
|
||||
writer.WriteNullValue();
|
||||
}
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
|
@ -30,7 +25,7 @@ namespace body_complex.Models.V20160229
|
|||
{
|
||||
if (property.NameEquals("picture"))
|
||||
{
|
||||
result.Picture = property.Value.GetBytesFromBase64();
|
||||
result.Picture = null;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
using System;
|
||||
|
||||
namespace body_complex.Models.V20160229
|
||||
{
|
||||
public partial class Sawshark
|
||||
{
|
||||
public byte[]? Picture { get; set; }
|
||||
public Byte[]? Picture { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,27 +1,23 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
using System;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace body_complex.Models.V20160229
|
||||
{
|
||||
public partial class Shark
|
||||
{
|
||||
internal void Serialize(Utf8JsonWriter writer, bool includeName = true)
|
||||
internal void Serialize(Utf8JsonWriter writer)
|
||||
{
|
||||
if (includeName)
|
||||
{
|
||||
writer.WriteStartObject("shark");
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteStartObject();
|
||||
}
|
||||
writer.WriteStartObject();
|
||||
if (Age != null)
|
||||
{
|
||||
writer.WriteNumber("age", Age.Value);
|
||||
writer.WritePropertyName("age");
|
||||
writer.WriteNumberValue(Age.Value);
|
||||
}
|
||||
writer.WriteString("birthday", Birthday.ToString());
|
||||
writer.WritePropertyName("birthday");
|
||||
writer.WriteStringValue(Birthday.ToString());
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
internal static Shark Deserialize(JsonElement element)
|
||||
|
|
|
@ -8,17 +8,6 @@ namespace body_complex.Models.V20160229
|
|||
public partial class Shark
|
||||
{
|
||||
public int? Age { get; set; }
|
||||
public DateTime Birthday { get; private set; }
|
||||
|
||||
#pragma warning disable CS8618 // Non-nullable field is uninitialized. Consider declaring as nullable.
|
||||
private Shark()
|
||||
{
|
||||
}
|
||||
#pragma warning restore CS8618 // Non-nullable field is uninitialized. Consider declaring as nullable.
|
||||
|
||||
public Shark(DateTime birthday)
|
||||
{
|
||||
Birthday = birthday;
|
||||
}
|
||||
public DateTime Birthday { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,19 +7,13 @@ namespace body_complex.Models.V20160229
|
|||
{
|
||||
public partial class Siamese
|
||||
{
|
||||
internal void Serialize(Utf8JsonWriter writer, bool includeName = true)
|
||||
internal void Serialize(Utf8JsonWriter writer)
|
||||
{
|
||||
if (includeName)
|
||||
{
|
||||
writer.WriteStartObject("siamese");
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteStartObject();
|
||||
}
|
||||
writer.WriteStartObject();
|
||||
if (Breed != null)
|
||||
{
|
||||
writer.WriteString("breed", Breed);
|
||||
writer.WritePropertyName("breed");
|
||||
writer.WriteStringValue(Breed);
|
||||
}
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
|
|
|
@ -7,19 +7,13 @@ namespace body_complex.Models.V20160229
|
|||
{
|
||||
public partial class SmartSalmon
|
||||
{
|
||||
internal void Serialize(Utf8JsonWriter writer, bool includeName = true)
|
||||
internal void Serialize(Utf8JsonWriter writer)
|
||||
{
|
||||
if (includeName)
|
||||
{
|
||||
writer.WriteStartObject("smart_salmon");
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteStartObject();
|
||||
}
|
||||
writer.WriteStartObject();
|
||||
if (CollegeDegree != null)
|
||||
{
|
||||
writer.WriteString("college_degree", CollegeDegree);
|
||||
writer.WritePropertyName("college_degree");
|
||||
writer.WriteStringValue(CollegeDegree);
|
||||
}
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
|
|
|
@ -7,27 +7,23 @@ namespace body_complex.Models.V20160229
|
|||
{
|
||||
public partial class StringWrapper
|
||||
{
|
||||
internal void Serialize(Utf8JsonWriter writer, bool includeName = true)
|
||||
internal void Serialize(Utf8JsonWriter writer)
|
||||
{
|
||||
if (includeName)
|
||||
{
|
||||
writer.WriteStartObject("string-wrapper");
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteStartObject();
|
||||
}
|
||||
writer.WriteStartObject();
|
||||
if (Field != null)
|
||||
{
|
||||
writer.WriteString("field", Field);
|
||||
writer.WritePropertyName("field");
|
||||
writer.WriteStringValue(Field);
|
||||
}
|
||||
if (Empty != null)
|
||||
{
|
||||
writer.WriteString("empty", Empty);
|
||||
writer.WritePropertyName("empty");
|
||||
writer.WriteStringValue(Empty);
|
||||
}
|
||||
if (NullProperty != null)
|
||||
{
|
||||
writer.WriteString("null", NullProperty);
|
||||
writer.WritePropertyName("null");
|
||||
writer.WriteStringValue(NullProperty);
|
||||
}
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ namespace body_complex.Operations.V20160229
|
|||
request.Headers.SetValue("Content-Type", "application/json");
|
||||
var buffer = new ArrayBufferWriter<byte>();
|
||||
await using var writer = new Utf8JsonWriter(buffer);
|
||||
complexBody.Serialize(writer, false);
|
||||
complexBody.Serialize(writer);
|
||||
writer.Flush();
|
||||
request.Content = RequestContent.Create(buffer.WrittenMemory);
|
||||
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
|
||||
|
@ -106,7 +106,7 @@ namespace body_complex.Operations.V20160229
|
|||
request.Headers.SetValue("Content-Type", "application/json");
|
||||
var buffer = new ArrayBufferWriter<byte>();
|
||||
await using var writer = new Utf8JsonWriter(buffer);
|
||||
complexBody.Serialize(writer, false);
|
||||
complexBody.Serialize(writer);
|
||||
writer.Flush();
|
||||
request.Content = RequestContent.Create(buffer.WrittenMemory);
|
||||
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
|
||||
|
|
|
@ -54,7 +54,7 @@ namespace body_complex.Operations.V20160229
|
|||
request.Headers.SetValue("Content-Type", "application/json");
|
||||
var buffer = new ArrayBufferWriter<byte>();
|
||||
await using var writer = new Utf8JsonWriter(buffer);
|
||||
complexBody.Serialize(writer, false);
|
||||
complexBody.Serialize(writer);
|
||||
writer.Flush();
|
||||
request.Content = RequestContent.Create(buffer.WrittenMemory);
|
||||
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
|
||||
|
|
|
@ -53,7 +53,7 @@ namespace body_complex.Operations.V20160229
|
|||
request.Headers.SetValue("Content-Type", "application/json");
|
||||
var buffer = new ArrayBufferWriter<byte>();
|
||||
await using var writer = new Utf8JsonWriter(buffer);
|
||||
complexBody.Serialize(writer, false);
|
||||
complexBody.Serialize(writer);
|
||||
writer.Flush();
|
||||
request.Content = RequestContent.Create(buffer.WrittenMemory);
|
||||
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
|
||||
|
@ -106,7 +106,7 @@ namespace body_complex.Operations.V20160229
|
|||
request.Headers.SetValue("Content-Type", "application/json");
|
||||
var buffer = new ArrayBufferWriter<byte>();
|
||||
await using var writer = new Utf8JsonWriter(buffer);
|
||||
complexBody.Serialize(writer, false);
|
||||
complexBody.Serialize(writer);
|
||||
writer.Flush();
|
||||
request.Content = RequestContent.Create(buffer.WrittenMemory);
|
||||
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
|
||||
|
|
|
@ -53,7 +53,7 @@ namespace body_complex.Operations.V20160229
|
|||
request.Headers.SetValue("Content-Type", "application/json");
|
||||
var buffer = new ArrayBufferWriter<byte>();
|
||||
await using var writer = new Utf8JsonWriter(buffer);
|
||||
complexBody.Serialize(writer, false);
|
||||
complexBody.Serialize(writer);
|
||||
writer.Flush();
|
||||
request.Content = RequestContent.Create(buffer.WrittenMemory);
|
||||
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
|
||||
|
|
|
@ -53,7 +53,7 @@ namespace body_complex.Operations.V20160229
|
|||
request.Headers.SetValue("Content-Type", "application/json");
|
||||
var buffer = new ArrayBufferWriter<byte>();
|
||||
await using var writer = new Utf8JsonWriter(buffer);
|
||||
complexBody.Serialize(writer, false);
|
||||
complexBody.Serialize(writer);
|
||||
writer.Flush();
|
||||
request.Content = RequestContent.Create(buffer.WrittenMemory);
|
||||
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
|
||||
|
|
|
@ -53,7 +53,7 @@ namespace body_complex.Operations.V20160229
|
|||
request.Headers.SetValue("Content-Type", "application/json");
|
||||
var buffer = new ArrayBufferWriter<byte>();
|
||||
await using var writer = new Utf8JsonWriter(buffer);
|
||||
complexBody.Serialize(writer, false);
|
||||
complexBody.Serialize(writer);
|
||||
writer.Flush();
|
||||
request.Content = RequestContent.Create(buffer.WrittenMemory);
|
||||
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
|
||||
|
@ -187,7 +187,7 @@ namespace body_complex.Operations.V20160229
|
|||
request.Headers.SetValue("Content-Type", "application/json");
|
||||
var buffer = new ArrayBufferWriter<byte>();
|
||||
await using var writer = new Utf8JsonWriter(buffer);
|
||||
complexBody.Serialize(writer, false);
|
||||
complexBody.Serialize(writer);
|
||||
writer.Flush();
|
||||
request.Content = RequestContent.Create(buffer.WrittenMemory);
|
||||
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
|
||||
|
@ -213,7 +213,7 @@ namespace body_complex.Operations.V20160229
|
|||
request.Headers.SetValue("Content-Type", "application/json");
|
||||
var buffer = new ArrayBufferWriter<byte>();
|
||||
await using var writer = new Utf8JsonWriter(buffer);
|
||||
complexBody.Serialize(writer, false);
|
||||
complexBody.Serialize(writer);
|
||||
writer.Flush();
|
||||
request.Content = RequestContent.Create(buffer.WrittenMemory);
|
||||
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
|
||||
|
@ -246,7 +246,7 @@ namespace body_complex.Operations.V20160229
|
|||
request.Headers.SetValue("Content-Type", "application/json");
|
||||
var buffer = new ArrayBufferWriter<byte>();
|
||||
await using var writer = new Utf8JsonWriter(buffer);
|
||||
complexBody.Serialize(writer, false);
|
||||
complexBody.Serialize(writer);
|
||||
writer.Flush();
|
||||
request.Content = RequestContent.Create(buffer.WrittenMemory);
|
||||
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
|
||||
|
|
|
@ -53,7 +53,7 @@ namespace body_complex.Operations.V20160229
|
|||
request.Headers.SetValue("Content-Type", "application/json");
|
||||
var buffer = new ArrayBufferWriter<byte>();
|
||||
await using var writer = new Utf8JsonWriter(buffer);
|
||||
complexBody.Serialize(writer, false);
|
||||
complexBody.Serialize(writer);
|
||||
writer.Flush();
|
||||
request.Content = RequestContent.Create(buffer.WrittenMemory);
|
||||
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
|
||||
|
@ -106,7 +106,7 @@ namespace body_complex.Operations.V20160229
|
|||
request.Headers.SetValue("Content-Type", "application/json");
|
||||
var buffer = new ArrayBufferWriter<byte>();
|
||||
await using var writer = new Utf8JsonWriter(buffer);
|
||||
complexBody.Serialize(writer, false);
|
||||
complexBody.Serialize(writer);
|
||||
writer.Flush();
|
||||
request.Content = RequestContent.Create(buffer.WrittenMemory);
|
||||
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
|
||||
|
@ -159,7 +159,7 @@ namespace body_complex.Operations.V20160229
|
|||
request.Headers.SetValue("Content-Type", "application/json");
|
||||
var buffer = new ArrayBufferWriter<byte>();
|
||||
await using var writer = new Utf8JsonWriter(buffer);
|
||||
complexBody.Serialize(writer, false);
|
||||
complexBody.Serialize(writer);
|
||||
writer.Flush();
|
||||
request.Content = RequestContent.Create(buffer.WrittenMemory);
|
||||
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
|
||||
|
@ -212,7 +212,7 @@ namespace body_complex.Operations.V20160229
|
|||
request.Headers.SetValue("Content-Type", "application/json");
|
||||
var buffer = new ArrayBufferWriter<byte>();
|
||||
await using var writer = new Utf8JsonWriter(buffer);
|
||||
complexBody.Serialize(writer, false);
|
||||
complexBody.Serialize(writer);
|
||||
writer.Flush();
|
||||
request.Content = RequestContent.Create(buffer.WrittenMemory);
|
||||
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
|
||||
|
@ -265,7 +265,7 @@ namespace body_complex.Operations.V20160229
|
|||
request.Headers.SetValue("Content-Type", "application/json");
|
||||
var buffer = new ArrayBufferWriter<byte>();
|
||||
await using var writer = new Utf8JsonWriter(buffer);
|
||||
complexBody.Serialize(writer, false);
|
||||
complexBody.Serialize(writer);
|
||||
writer.Flush();
|
||||
request.Content = RequestContent.Create(buffer.WrittenMemory);
|
||||
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
|
||||
|
@ -318,7 +318,7 @@ namespace body_complex.Operations.V20160229
|
|||
request.Headers.SetValue("Content-Type", "application/json");
|
||||
var buffer = new ArrayBufferWriter<byte>();
|
||||
await using var writer = new Utf8JsonWriter(buffer);
|
||||
complexBody.Serialize(writer, false);
|
||||
complexBody.Serialize(writer);
|
||||
writer.Flush();
|
||||
request.Content = RequestContent.Create(buffer.WrittenMemory);
|
||||
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
|
||||
|
@ -371,7 +371,7 @@ namespace body_complex.Operations.V20160229
|
|||
request.Headers.SetValue("Content-Type", "application/json");
|
||||
var buffer = new ArrayBufferWriter<byte>();
|
||||
await using var writer = new Utf8JsonWriter(buffer);
|
||||
complexBody.Serialize(writer, false);
|
||||
complexBody.Serialize(writer);
|
||||
writer.Flush();
|
||||
request.Content = RequestContent.Create(buffer.WrittenMemory);
|
||||
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
|
||||
|
@ -424,7 +424,7 @@ namespace body_complex.Operations.V20160229
|
|||
request.Headers.SetValue("Content-Type", "application/json");
|
||||
var buffer = new ArrayBufferWriter<byte>();
|
||||
await using var writer = new Utf8JsonWriter(buffer);
|
||||
complexBody.Serialize(writer, false);
|
||||
complexBody.Serialize(writer);
|
||||
writer.Flush();
|
||||
request.Content = RequestContent.Create(buffer.WrittenMemory);
|
||||
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
|
||||
|
@ -477,7 +477,7 @@ namespace body_complex.Operations.V20160229
|
|||
request.Headers.SetValue("Content-Type", "application/json");
|
||||
var buffer = new ArrayBufferWriter<byte>();
|
||||
await using var writer = new Utf8JsonWriter(buffer);
|
||||
complexBody.Serialize(writer, false);
|
||||
complexBody.Serialize(writer);
|
||||
writer.Flush();
|
||||
request.Content = RequestContent.Create(buffer.WrittenMemory);
|
||||
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
|
||||
|
@ -530,7 +530,7 @@ namespace body_complex.Operations.V20160229
|
|||
request.Headers.SetValue("Content-Type", "application/json");
|
||||
var buffer = new ArrayBufferWriter<byte>();
|
||||
await using var writer = new Utf8JsonWriter(buffer);
|
||||
complexBody.Serialize(writer, false);
|
||||
complexBody.Serialize(writer);
|
||||
writer.Flush();
|
||||
request.Content = RequestContent.Create(buffer.WrittenMemory);
|
||||
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
|
||||
|
@ -583,7 +583,7 @@ namespace body_complex.Operations.V20160229
|
|||
request.Headers.SetValue("Content-Type", "application/json");
|
||||
var buffer = new ArrayBufferWriter<byte>();
|
||||
await using var writer = new Utf8JsonWriter(buffer);
|
||||
complexBody.Serialize(writer, false);
|
||||
complexBody.Serialize(writer);
|
||||
writer.Flush();
|
||||
request.Content = RequestContent.Create(buffer.WrittenMemory);
|
||||
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
|
||||
|
|
|
@ -53,7 +53,7 @@ namespace body_complex.Operations.V20160229
|
|||
request.Headers.SetValue("Content-Type", "application/json");
|
||||
var buffer = new ArrayBufferWriter<byte>();
|
||||
await using var writer = new Utf8JsonWriter(buffer);
|
||||
complexBody.Serialize(writer, false);
|
||||
complexBody.Serialize(writer);
|
||||
writer.Flush();
|
||||
request.Content = RequestContent.Create(buffer.WrittenMemory);
|
||||
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
namespace body_string.Models.V100
|
||||
{
|
||||
public readonly partial struct Colors
|
||||
{
|
||||
private const string RedColorValue = "red color";
|
||||
private const string GreenColorValue = "green-color";
|
||||
private const string BlueColorValue = "blue_color";
|
||||
|
||||
public static Colors RedColor { get; } = new Colors(RedColorValue);
|
||||
public static Colors GreenColor { get; } = new Colors(GreenColorValue);
|
||||
public static Colors BlueColor { get; } = new Colors(BlueColorValue);
|
||||
}
|
||||
}
|
|
@ -15,6 +15,13 @@ namespace body_string.Models.V100
|
|||
_value = value ?? throw new ArgumentNullException(nameof(value));
|
||||
}
|
||||
|
||||
private const string RedColorValue = "red color";
|
||||
private const string GreenColorValue = "green-color";
|
||||
private const string BlueColorValue = "blue_color";
|
||||
|
||||
public static Colors RedColor { get; } = new Colors(RedColorValue);
|
||||
public static Colors GreenColor { get; } = new Colors(GreenColorValue);
|
||||
public static Colors BlueColor { get; } = new Colors(BlueColorValue);
|
||||
public static bool operator ==(Colors left, Colors right) => left.Equals(right);
|
||||
public static bool operator !=(Colors left, Colors right) => !left.Equals(right);
|
||||
public static implicit operator Colors(string value) => new Colors(value);
|
||||
|
|
|
@ -7,23 +7,18 @@ namespace body_string.Models.V100
|
|||
{
|
||||
public partial class Error
|
||||
{
|
||||
internal void Serialize(Utf8JsonWriter writer, bool includeName = true)
|
||||
internal void Serialize(Utf8JsonWriter writer)
|
||||
{
|
||||
if (includeName)
|
||||
{
|
||||
writer.WriteStartObject("Error");
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteStartObject();
|
||||
}
|
||||
writer.WriteStartObject();
|
||||
if (Status != null)
|
||||
{
|
||||
writer.WriteNumber("status", Status.Value);
|
||||
writer.WritePropertyName("status");
|
||||
writer.WriteNumberValue(Status.Value);
|
||||
}
|
||||
if (Message != null)
|
||||
{
|
||||
writer.WriteString("message", Message);
|
||||
writer.WritePropertyName("message");
|
||||
writer.WriteStringValue(Message);
|
||||
}
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
|
|
|
@ -7,20 +7,13 @@ namespace body_string.Models.V100
|
|||
{
|
||||
public partial class RefColorConstant
|
||||
{
|
||||
internal void Serialize(Utf8JsonWriter writer, bool includeName = true)
|
||||
internal void Serialize(Utf8JsonWriter writer)
|
||||
{
|
||||
if (includeName)
|
||||
{
|
||||
writer.WriteStartObject("RefColorConstant");
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteStartObject();
|
||||
}
|
||||
writer.WriteString("ColorConstant", ColorConstant);
|
||||
writer.WriteStartObject();
|
||||
if (Field1 != null)
|
||||
{
|
||||
writer.WriteString("field1", Field1);
|
||||
writer.WritePropertyName("field1");
|
||||
writer.WriteStringValue(Field1);
|
||||
}
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
|
|
|
@ -159,7 +159,7 @@ namespace body_string.Operations.V100
|
|||
request.Headers.SetValue("Content-Type", "application/json");
|
||||
var buffer = new ArrayBufferWriter<byte>();
|
||||
await using var writer = new Utf8JsonWriter(buffer);
|
||||
enumStringBody.Serialize(writer, false);
|
||||
enumStringBody.Serialize(writer);
|
||||
writer.Flush();
|
||||
request.Content = RequestContent.Create(buffer.WrittenMemory);
|
||||
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
|
||||
|
|
|
@ -252,7 +252,7 @@ namespace body_string.Operations.V100
|
|||
}
|
||||
}
|
||||
|
||||
public static async ValueTask<Response<byte[]>> GetBase64EncodedAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default)
|
||||
public static async ValueTask<Response<Byte[]>> GetBase64EncodedAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default)
|
||||
{
|
||||
using var scope = clientDiagnostics.CreateScope("body_string.Operations.V100.GetBase64Encoded");
|
||||
scope.Start();
|
||||
|
@ -279,7 +279,7 @@ namespace body_string.Operations.V100
|
|||
}
|
||||
}
|
||||
|
||||
public static async ValueTask<Response<byte[]>> GetBase64UrlEncodedAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default)
|
||||
public static async ValueTask<Response<Byte[]>> GetBase64UrlEncodedAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default)
|
||||
{
|
||||
using var scope = clientDiagnostics.CreateScope("body_string.Operations.V100.GetBase64UrlEncoded");
|
||||
scope.Start();
|
||||
|
@ -306,7 +306,7 @@ namespace body_string.Operations.V100
|
|||
}
|
||||
}
|
||||
|
||||
public static async ValueTask<Response> PutBase64UrlEncodedAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, byte[] stringBody, string host = "http://localhost:3000", CancellationToken cancellationToken = default)
|
||||
public static async ValueTask<Response> PutBase64UrlEncodedAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Byte[] stringBody, string host = "http://localhost:3000", CancellationToken cancellationToken = default)
|
||||
{
|
||||
using var scope = clientDiagnostics.CreateScope("body_string.Operations.V100.PutBase64UrlEncoded");
|
||||
scope.Start();
|
||||
|
@ -332,7 +332,7 @@ namespace body_string.Operations.V100
|
|||
}
|
||||
}
|
||||
|
||||
public static async ValueTask<Response<byte[]>> GetNullBase64UrlEncodedAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default)
|
||||
public static async ValueTask<Response<Byte[]>> GetNullBase64UrlEncodedAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000", CancellationToken cancellationToken = default)
|
||||
{
|
||||
using var scope = clientDiagnostics.CreateScope("body_string.Operations.V100.GetNullBase64UrlEncoded");
|
||||
scope.Start();
|
||||
|
|
|
@ -7,23 +7,18 @@ namespace custom_baseUrl_more_options.Models.V100
|
|||
{
|
||||
public partial class Error
|
||||
{
|
||||
internal void Serialize(Utf8JsonWriter writer, bool includeName = true)
|
||||
internal void Serialize(Utf8JsonWriter writer)
|
||||
{
|
||||
if (includeName)
|
||||
{
|
||||
writer.WriteStartObject("Error");
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteStartObject();
|
||||
}
|
||||
writer.WriteStartObject();
|
||||
if (Status != null)
|
||||
{
|
||||
writer.WriteNumber("status", Status.Value);
|
||||
writer.WritePropertyName("status");
|
||||
writer.WriteNumberValue(Status.Value);
|
||||
}
|
||||
if (Message != null)
|
||||
{
|
||||
writer.WriteString("message", Message);
|
||||
writer.WritePropertyName("message");
|
||||
writer.WriteStringValue(Message);
|
||||
}
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
|
|
|
@ -7,23 +7,18 @@ namespace custom_baseUrl.Models.V100
|
|||
{
|
||||
public partial class Error
|
||||
{
|
||||
internal void Serialize(Utf8JsonWriter writer, bool includeName = true)
|
||||
internal void Serialize(Utf8JsonWriter writer)
|
||||
{
|
||||
if (includeName)
|
||||
{
|
||||
writer.WriteStartObject("Error");
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteStartObject();
|
||||
}
|
||||
writer.WriteStartObject();
|
||||
if (Status != null)
|
||||
{
|
||||
writer.WriteNumber("status", Status.Value);
|
||||
writer.WritePropertyName("status");
|
||||
writer.WriteNumberValue(Status.Value);
|
||||
}
|
||||
if (Message != null)
|
||||
{
|
||||
writer.WriteString("message", Message);
|
||||
writer.WritePropertyName("message");
|
||||
writer.WriteStringValue(Message);
|
||||
}
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче