* Update to autorest

* More

* Noreset

* Again

* Fixes and comments

* More fixes

* Launch settings
This commit is contained in:
Pavel Krymets 2019-12-09 17:21:07 -08:00 коммит произвёл GitHub
Родитель 808f6fc147
Коммит 4839e20154
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
33 изменённых файлов: 375 добавлений и 207 удалений

Просмотреть файл

@ -1,4 +1,4 @@
param($name, [switch]$noDebug)
param($name, [switch]$noDebug, [switch]$NoReset)
$ErrorActionPreference = 'Stop'
function Invoke-Block([scriptblock]$cmd) {
@ -38,6 +38,11 @@ $configurationPath = Join-Path $testServerDirectory 'readme.tests.md'
$testServerSwaggerPath = Join-Path $repoRoot 'node_modules' '@microsoft.azure' 'autorest.testserver' 'swagger'
$testNames = if ($name) { $name } else { 'url', 'body-string', 'body-complex', 'custom-baseUrl', 'custom-baseUrl-more-options', 'header' }
if (!$NoReset)
{
Invoke-AutoRest "--reset" $repoRoot
}
foreach ($testName in $testNames)
{
$inputFile = Join-Path $testServerSwaggerPath "$testName.json"

5
package-lock.json сгенерированный
Просмотреть файл

@ -4,9 +4,8 @@
"lockfileVersion": 1,
"dependencies": {
"@autorest/autorest": {
"version": "3.0.6122",
"resolved": "https://registry.npmjs.org/@autorest/autorest/-/autorest-3.0.6122.tgz",
"integrity": "sha512-A7eapUdRG/HRDAV6rVFHD/CyK4sAshaQjaAJBZJk9jBFxjUGSPMk1PjCFpP50pvZs5iL/EktBW1/ncFaw4SiTA==",
"version": "https://github.com/Azure/autorest/releases/download/autorest-3.0.6146/autorest-autorest-3.0.6146.tgz",
"integrity": "sha512-K+2u+CyT6EKb9loGqHE5forJTqVH9042ivJQcLzKaH9CrJWkF5jF2LYBHu8ffszyHv6vLQuHSUNgM6Km2kdkbQ==",
"dev": true
},
"@autorest/test-server": {

Просмотреть файл

@ -8,7 +8,7 @@
"debug": "dotnet ./artifacts/bin/AutoRest.CSharp.V3/Debug/netcoreapp3.0/AutoRest.CSharp.V3.dll --server --launch-debugger"
},
"devDependencies": {
"@autorest/autorest": "^3.0.6122",
"@autorest/autorest": "https://github.com/Azure/autorest/releases/download/autorest-3.0.6146/autorest-autorest-3.0.6146.tgz",
"@autorest/test-server": "3.0.27",
"@microsoft.azure/autorest.testserver": "^2.7.1"
},

Просмотреть файл

@ -4,8 +4,8 @@
## Configuration
```yaml
use-extension:
"@autorest/modelerfour": "4.1.60"
"@autorest/modelerfour": "4.2.84"
version: 3.0.6162
pipeline:
cs-modeler:
input: modelerfour/identity

Просмотреть файл

@ -8,7 +8,7 @@ namespace AutoRest.CSharp.V3.ClientModels
{
internal struct ClientConstant
{
public ClientConstant(object? value, FrameworkTypeReference type)
public ClientConstant(object? value, ClientTypeReference type)
{
Debug.Assert(value == null || value.GetType().Namespace?.StartsWith("System") == true);
Value = value;
@ -23,13 +23,20 @@ namespace AutoRest.CSharp.V3.ClientModels
return;
}
if (value.GetType() != type.Type)
var expectedType = type switch
{
BinaryTypeReference _ => typeof(byte[]),
FrameworkTypeReference frameworkType => frameworkType.Type,
_ => throw new InvalidOperationException("Unexpected type kind")
};
if (value.GetType() != expectedType)
{
throw new InvalidOperationException("Constant type mismatch");
}
}
public object? Value { get; }
public FrameworkTypeReference Type { get; }
public ClientTypeReference Type { get; }
}
}

Просмотреть файл

@ -5,15 +5,17 @@ namespace AutoRest.CSharp.V3.ClientModels
{
internal class QueryParameter
{
public QueryParameter(string name, ConstantOrParameter value, bool escape)
public QueryParameter(string name, ConstantOrParameter value, bool escape, SerializationFormat serializationFormat)
{
Name = name;
Value = value;
Escape = escape;
SerializationFormat = serializationFormat;
}
public string Name { get; }
public ConstantOrParameter Value { get; }
public SerializationFormat SerializationFormat { get; }
public bool Escape { get; }
}
}

Просмотреть файл

@ -137,6 +137,60 @@ namespace AutoRest.CSharp.V3.CodeGen
}
}
private void WriteConstant(ClientConstant constant)
{
if (constant.Value == null)
{
Literal(null);
return;
}
switch (constant.Type)
{
case FrameworkTypeReference frameworkType when frameworkType.Type == typeof(DateTime):
var dateTimeValue = (DateTime)constant.Value;
dateTimeValue = dateTimeValue.ToUniversalTime();
Append("new ");
Append(Type(typeof(DateTime)));
Append("(");
Literal(dateTimeValue.Year);
Append(", ");
Literal(dateTimeValue.Month);
Append(", ");
Literal(dateTimeValue.Day);
Append(", ");
Literal(dateTimeValue.Hour);
Append(", ");
Literal(dateTimeValue.Minute);
Append(", ");
Literal(dateTimeValue.Second);
Append(", ");
Literal(dateTimeValue.Millisecond);
Append(", ");
Append(Type(typeof(DateTimeKind)));
Append(".");
Append(nameof(DateTimeKind.Utc));
Append(")");
break;
case FrameworkTypeReference _:
Literal(constant.Value);
break;
case BinaryTypeReference _:
var value = (byte[])constant.Value;
Append("new byte[] {");
foreach (byte b in value)
{
Literal(b);
Append(", ");
}
Append("}");
break;
default:
throw new InvalidOperationException("Unknown constant type");
}
}
private void WritePathSegment(PathSegment segment)
{
var value = segment.Value;
@ -144,7 +198,7 @@ namespace AutoRest.CSharp.V3.CodeGen
if (value.IsConstant)
{
Append("request.Uri.AppendPath(");
Literal(value.Constant.Value);
WriteConstant(value.Constant);
WriteSerializationFormat(segment.Format);
Append(", ");
Literal(segment.Escape);
@ -167,7 +221,7 @@ namespace AutoRest.CSharp.V3.CodeGen
Append("request.Headers.Add(");
Literal(header.Name);
Append(", ");
Literal(header.Value.Constant.Value);
WriteConstant(header.Value.Constant);
Line(");");
return;
}
@ -216,7 +270,8 @@ namespace AutoRest.CSharp.V3.CodeGen
Append("request.Uri.AppendQuery(");
Literal(queryParameter.Name);
Append(", ");
Literal(value.Constant.Value);
WriteConstant(value.Constant);
WriteSerializationFormat(queryParameter.SerializationFormat);
Append(", ");
Literal(queryParameter.Escape);
Line(");");
@ -235,6 +290,7 @@ namespace AutoRest.CSharp.V3.CodeGen
{
Append(".Value");
}
WriteSerializationFormat(queryParameter.SerializationFormat);
Append(", ");
Literal(queryParameter.Escape);
Line(");");

Просмотреть файл

@ -1500,8 +1500,11 @@ namespace AutoRest.CSharp.V3.Pipeline.Generated
[System.Runtime.Serialization.EnumMember(Value = @"spaceDelimited")]
SpaceDelimited = 8,
[System.Runtime.Serialization.EnumMember(Value = @"tabDelimited")]
TabDelimited = 9,
[System.Runtime.Serialization.EnumMember(Value = @"xml")]
Xml = 9,
Xml = 10,
}
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "10.0.23.0 (Newtonsoft.Json v9.0.0.0)")]

Просмотреть файл

@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -86,11 +87,13 @@ namespace AutoRest.CSharp.V3.Plugins
string defaultName = requestParameter.Language.Default.Name;
string serializedName = requestParameter.Language.Default.SerializedName ?? defaultName;
ConstantOrParameter? constantOrParameter;
Schema valueSchema = requestParameter.Schema;
switch (requestParameter.Schema)
{
case ConstantSchema constant:
constantOrParameter = ParseClientConstant(constant.Value.Value, (FrameworkTypeReference)CreateType(constant.ValueType, true));
constantOrParameter = ParseClientConstant(constant.Value.Value, CreateType(constant.ValueType, true));
valueSchema = constant.ValueType;
break;
case BinarySchema _:
// skip
@ -116,16 +119,17 @@ namespace AutoRest.CSharp.V3.Plugins
if (requestParameter.Protocol.Http is HttpParameter httpParameter)
{
SerializationFormat serializationFormat = GetSerializationFormat(valueSchema);
switch (httpParameter.In)
{
case ParameterLocation.Header:
headers.Add(new RequestHeader(serializedName, constantOrParameter.Value, GetSerializationFormat(requestParameter.Schema)));
headers.Add(new RequestHeader(serializedName, constantOrParameter.Value, serializationFormat));
break;
case ParameterLocation.Query:
query.Add(new QueryParameter(serializedName, constantOrParameter.Value, true));
query.Add(new QueryParameter(serializedName, constantOrParameter.Value, true, serializationFormat));
break;
case ParameterLocation.Path:
pathParameters.Add(serializedName, new PathSegment(constantOrParameter.Value, true, GetSerializationFormat(requestParameter.Schema)));
pathParameters.Add(serializedName, new PathSegment(constantOrParameter.Value, true, serializationFormat));
break;
case ParameterLocation.Body:
body = constantOrParameter;
@ -178,8 +182,8 @@ namespace AutoRest.CSharp.V3.Plugins
{
UnixTimeSchema _ => SerializationFormat.DateTimeUnix,
DateTimeSchema dateTimeSchema when dateTimeSchema.Format == DateTimeSchemaFormat.DateTime => SerializationFormat.DateTimeISO8601,
DateSchema _ => SerializationFormat.Date,
DateTimeSchema dateTimeSchema when dateTimeSchema.Format == DateTimeSchemaFormat.DateTimeRfc1123 => SerializationFormat.DateTimeRFC1123,
DateSchema _ => SerializationFormat.Date,
_ => SerializationFormat.Default,
};
}
@ -276,9 +280,18 @@ namespace AutoRest.CSharp.V3.Plugins
_ => new SchemaTypeReference(schema, isNullable)
};
private static ClientConstant ParseClientConstant(object? value, FrameworkTypeReference type)
private static ClientConstant ParseClientConstant(object? value, ClientTypeReference type)
{
return new ClientConstant(Convert.ChangeType(value, type.Type), type);
var normalizedValue = type switch
{
BinaryTypeReference _ when value is string base64String => Convert.FromBase64String(base64String),
FrameworkTypeReference frameworkType when
frameworkType.Type == typeof(DateTime) &&
value is string dateTimeString => DateTime.Parse(dateTimeString, styles: DateTimeStyles.AssumeUniversal),
FrameworkTypeReference frameworkType => Convert.ChangeType(value, frameworkType.Type),
_ => null
};
return new ClientConstant(normalizedValue, type);
}
//TODO: Refactor as this is written quite... ugly.

Просмотреть файл

@ -19,14 +19,13 @@ namespace AutoRest.CodeModel
private static void Main()
{
using var webClient = new WebClient();
webClient.DownloadFile(@"https://raw.githubusercontent.com/Azure/perks/master/codemodel/.resources/all-in-one/json/code-model.json", "../../../../../src/AutoRest.CodeModel/code-model.json");
webClient.DownloadFile(@"https://raw.githubusercontent.com/Azure/perks/master/codemodel/.resources/all-in-one/json/code-model.json", "code-model.json");
var schemaJsonLines = File.ReadAllLines("../../../../../src/AutoRest.CodeModel/code-model.json");
var schemaJson = String.Join(Environment.NewLine, schemaJsonLines)
var schemaJson = File.ReadAllText("code-model.json")
// Fixes + and - enum values that cannot be generated into C# enum names
.Replace("\"+\"", "\"plus\"").Replace("\"-\"", "\"minus\"")
// Makes Choices only have string values
.Replace($" \"type\": [{Environment.NewLine} \"string\",{Environment.NewLine} \"number\",{Environment.NewLine} \"boolean\"{Environment.NewLine} ]{Environment.NewLine}", $" \"type\": \"string\"{Environment.NewLine}");
.Replace(" \"type\": [\n \"string\",\n \"number\",\n \"boolean\"\n ]\n", $" \"type\": \"string\"\n");
var schema = JsonSchema.FromJsonAsync(schemaJson).GetAwaiter().GetResult();
var settings = new CSharpGeneratorSettings
{
@ -67,7 +66,7 @@ namespace AutoRest.CodeModel
})
.SkipLast(1)
.Prepend(lines.First()));
File.WriteAllText($"../../../../../src/{Path}/CodeModel.cs", fileWithNullable);
File.WriteAllText($"../../src/{Path}/CodeModel.cs", fileWithNullable);
}
}
}

Просмотреть файл

@ -0,0 +1,8 @@
{
"profiles": {
"AutoRest.CodeModel": {
"commandName": "Project",
"workingDirectory": "$(ProjectDir)"
}
}
}

Просмотреть файл

@ -2024,6 +2024,7 @@
"pipeDelimited",
"simple",
"spaceDelimited",
"tabDelimited",
"xml"
],
"type": "string"

Просмотреть файл

@ -62,6 +62,11 @@ namespace Azure.Core
builder.AppendQuery(name, value.ToString(TypeFormatters.DefaultNumberFormat), escape);
}
public static void AppendQuery(this RequestUriBuilder builder, string name, DateTime value, string format, bool escape = true)
{
builder.AppendQuery(name, TypeFormatters.ToString(value, format), escape);
}
public static void AppendQuery(this RequestUriBuilder builder, string name, double value, bool escape = true)
{
builder.AppendQuery(name, value.ToString(TypeFormatters.DefaultNumberFormat), escape);

Просмотреть файл

@ -985,5 +985,15 @@ namespace AutoRest.TestServer.Tests
var value = new ReadonlyObj();
return await ReadonlypropertyOperations.PutValidAsync(ClientDiagnostics, pipeline, value, host);
});
[Test]
public void EnumGeneratedAsExtensibleWithCorrectName()
{
// Name directive
Assert.AreEqual("CMYKColors", typeof(CMYKColors).Name);
// modelAsString
Assert.True(typeof(CMYKColors).IsValueType);
Assert.False(typeof(CMYKColors).IsEnum);
}
}
}

Просмотреть файл

@ -13,22 +13,56 @@ namespace AutoRest.TestServer.Tests
public UrlPathItemsTests(TestServerVersion version) : base(version, "pathitem") { }
[Test]
[Ignore("globalStringQuery not generated")]
[IgnoreOnTestServer(TestServerVersion.V2, "No recording")]
public Task UrlPathItemGetAll() => TestStatus(async (host, pipeline) =>
await PathItemsOperations.GetAllWithValuesAsync(ClientDiagnostics, pipeline, pathItemStringPath: "pathItemStringPath", pathItemStringQuery: "pathItemStringQuery", localStringPath: "localStringPath", localStringQuery: "localStringQuery", host));
await PathItemsOperations.GetAllWithValuesAsync(ClientDiagnostics,
pipeline,
pathItemStringPath: "pathItemStringPath",
pathItemStringQuery: "pathItemStringQuery",
globalStringPath: "globalStringPath",
globalStringQuery: "globalStringQuery",
localStringPath: "localStringPath",
localStringQuery: "localStringQuery",
host: host));
[Test]
[Ignore("globalStringQuery not generated")]
public Task UrlPathItemGetPathItemAndLocalNull() => TestStatus(async (host, pipeline) =>
await PathItemsOperations.GetLocalPathItemQueryNullAsync(ClientDiagnostics, pipeline, pathItemStringPath: "pathItemStringPath", pathItemStringQuery: "pathItemStringQuery", localStringPath: "localStringPath", localStringQuery: null, host));
await PathItemsOperations.GetLocalPathItemQueryNullAsync(
ClientDiagnostics,
pipeline,
pathItemStringPath: "pathItemStringPath",
pathItemStringQuery: null,
globalStringPath: "globalStringPath",
globalStringQuery: "globalStringQuery",
localStringPath: "localStringPath",
localStringQuery: null,
host));
[Test]
[IgnoreOnTestServer(TestServerVersion.V2, "No recording")]
public Task UrlPathItemGetGlobalNull() => TestStatus(async (host, pipeline) =>
await PathItemsOperations.GetGlobalQueryNullAsync(ClientDiagnostics, pipeline, pathItemStringPath: "pathItemStringPath", pathItemStringQuery: "pathItemStringQuery", localStringPath: "localStringPath", localStringQuery: "localStringQuery", host));
await PathItemsOperations.GetGlobalQueryNullAsync(
ClientDiagnostics,
pipeline,
pathItemStringPath: "pathItemStringPath",
pathItemStringQuery: "pathItemStringQuery",
globalStringPath: "globalStringPath",
globalStringQuery: null,
localStringPath: "localStringPath",
localStringQuery: "localStringQuery",
host));
[Test]
public Task UrlPathItemGetGlobalAndLocalNull() => TestStatus(async (host, pipeline) =>
await PathItemsOperations.GetGlobalAndLocalQueryNullAsync(ClientDiagnostics, pipeline, pathItemStringPath: "pathItemStringPath", pathItemStringQuery: "pathItemStringQuery", localStringPath: "localStringPath", localStringQuery: null, host));
await PathItemsOperations.GetGlobalAndLocalQueryNullAsync(
ClientDiagnostics,
pipeline,
pathItemStringPath: "pathItemStringPath",
pathItemStringQuery: "pathItemStringQuery",
globalStringPath: "globalStringPath",
globalStringQuery: null,
localStringPath: "localStringPath",
localStringQuery: null,
host));
}
}

Просмотреть файл

@ -77,6 +77,7 @@ namespace AutoRest.TestServer.Tests
public Task UrlQueriesStringNull() => TestStatus(async (host, pipeline) => await QueriesOperations.StringNullAsync(ClientDiagnostics, pipeline, null, host: host));
[Test]
[Ignore("Not implemented https://github.com/Azure/autorest.csharp/issues/325")]
public Task UrlQueriesEnumValid() => TestStatus(async (host, pipeline) => await QueriesOperations.EnumValidAsync(ClientDiagnostics, pipeline, UriColor.GreenColor, host: host));
[Test]

Просмотреть файл

@ -20,6 +20,7 @@ namespace AutoRest.TestServer.Tests
public Task UrlPathsStringEmpty() => TestStatus(async (host, pipeline) => await PathsOperations.StringEmptyAsync(ClientDiagnostics, pipeline, host));
[Test]
[Ignore("Not implemented https://github.com/Azure/autorest.csharp/issues/325")]
public Task UrlPathsEnumValid() => TestStatus(async (host, pipeline) => await PathsOperations.EnumValidAsync(ClientDiagnostics, pipeline, UriColor.GreenColor, host));
[Test]
@ -105,6 +106,14 @@ namespace AutoRest.TestServer.Tests
[Test]
public Task UrlPathsDoublePositive() => TestStatus(async (host, pipeline) => await PathsOperations.DoubleDecimalPositiveAsync(ClientDiagnostics, pipeline, host));
[Test]
public void EnumGeneratedNonExtesibleWithoutModelAsString()
{
// modelAsString
Assert.True(typeof(UriColor).IsEnum);
}
public override IEnumerable<string> AdditionalKnownScenarios { get; } = new string[] {"UrlPathsBoolFalse",
"UrlPathsBoolTrue",
"UrlPathsIntPositive",

Просмотреть файл

@ -23,7 +23,7 @@ namespace body_complex.Models.V20160229
if (Color != null)
{
writer.WritePropertyName("color");
writer.WriteStringValue(Color.Value.ToSerialString());
writer.WriteStringValue(Color.ToString());
}
writer.WriteEndObject();
}
@ -44,7 +44,7 @@ namespace body_complex.Models.V20160229
}
if (property.NameEquals("color"))
{
result.Color = property.Value.GetString().ToCMYKColors();
result.Color = new CMYKColors(property.Value.GetString());
continue;
}
}

Просмотреть файл

@ -1,28 +0,0 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
namespace body_complex.Models.V20160229
{
internal static class CMYKColorsExtensions
{
public static string ToSerialString(this CMYKColors value) => value switch
{
CMYKColors.Cyan => "cyan",
CMYKColors.Magenta => "Magenta",
CMYKColors.YELLOW => "YELLOW",
CMYKColors.BlacK => "blacK",
_ => throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown CMYKColors value.")
};
public static CMYKColors ToCMYKColors(this string value) => value switch
{
"cyan" => CMYKColors.Cyan,
"Magenta" => CMYKColors.Magenta,
"YELLOW" => CMYKColors.YELLOW,
"blacK" => CMYKColors.BlacK,
_ => throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown CMYKColors value.")
};
}
}

Просмотреть файл

@ -1,13 +1,39 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.ComponentModel;
namespace body_complex.Models.V20160229
{
public enum CMYKColors
public readonly partial struct CMYKColors : IEquatable<CMYKColors>
{
Cyan,
Magenta,
YELLOW,
BlacK
private readonly string? _value;
public CMYKColors(string value)
{
_value = value ?? throw new ArgumentNullException(nameof(value));
}
private const string CyanValue = "cyan";
private const string MagentaValue = "Magenta";
private const string YELLOWValue = "YELLOW";
private const string BlacKValue = "blacK";
public static CMYKColors Cyan { get; } = new CMYKColors(CyanValue);
public static CMYKColors Magenta { get; } = new CMYKColors(MagentaValue);
public static CMYKColors YELLOW { get; } = new CMYKColors(YELLOWValue);
public static CMYKColors BlacK { get; } = new CMYKColors(BlacKValue);
public static bool operator ==(CMYKColors left, CMYKColors right) => left.Equals(right);
public static bool operator !=(CMYKColors left, CMYKColors right) => !left.Equals(right);
public static implicit operator CMYKColors(string value) => new CMYKColors(value);
[EditorBrowsable(EditorBrowsableState.Never)]
public override bool Equals(object? obj) => obj is CMYKColors other && Equals(other);
public bool Equals(CMYKColors other) => string.Equals(_value, other._value, StringComparison.Ordinal);
[EditorBrowsable(EditorBrowsableState.Never)]
public override int GetHashCode() => _value?.GetHashCode() ?? 0;
public override string? ToString() => _value;
}
}

Просмотреть файл

@ -1,26 +0,0 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
namespace body_complex.Models.V20160229
{
internal static class GoblinSharkColorExtensions
{
public static string ToSerialString(this GoblinSharkColor value) => value switch
{
GoblinSharkColor.Pink => "pink",
GoblinSharkColor.Gray => "gray",
GoblinSharkColor.Brown => "brown",
_ => throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown GoblinSharkColor value.")
};
public static GoblinSharkColor ToGoblinSharkColor(this string value) => value switch
{
"pink" => GoblinSharkColor.Pink,
"gray" => GoblinSharkColor.Gray,
"brown" => GoblinSharkColor.Brown,
_ => throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown GoblinSharkColor value.")
};
}
}

Просмотреть файл

@ -1,12 +1,37 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.ComponentModel;
namespace body_complex.Models.V20160229
{
public enum GoblinSharkColor
public readonly partial struct GoblinSharkColor : IEquatable<GoblinSharkColor>
{
Pink,
Gray,
Brown
private readonly string? _value;
public GoblinSharkColor(string value)
{
_value = value ?? throw new ArgumentNullException(nameof(value));
}
private const string PinkValue = "pink";
private const string GrayValue = "gray";
private const string BrownValue = "brown";
public static GoblinSharkColor Pink { get; } = new GoblinSharkColor(PinkValue);
public static GoblinSharkColor Gray { get; } = new GoblinSharkColor(GrayValue);
public static GoblinSharkColor Brown { get; } = new GoblinSharkColor(BrownValue);
public static bool operator ==(GoblinSharkColor left, GoblinSharkColor right) => left.Equals(right);
public static bool operator !=(GoblinSharkColor left, GoblinSharkColor right) => !left.Equals(right);
public static implicit operator GoblinSharkColor(string value) => new GoblinSharkColor(value);
[EditorBrowsable(EditorBrowsableState.Never)]
public override bool Equals(object? obj) => obj is GoblinSharkColor other && Equals(other);
public bool Equals(GoblinSharkColor other) => string.Equals(_value, other._value, StringComparison.Ordinal);
[EditorBrowsable(EditorBrowsableState.Never)]
public override int GetHashCode() => _value?.GetHashCode() ?? 0;
public override string? ToString() => _value;
}
}

Просмотреть файл

@ -18,7 +18,7 @@ namespace body_complex.Models.V20160229
if (Color != null)
{
writer.WritePropertyName("color");
writer.WriteStringValue(Color.Value.ToSerialString());
writer.WriteStringValue(Color.ToString());
}
writer.WriteEndObject();
}
@ -34,7 +34,7 @@ namespace body_complex.Models.V20160229
}
if (property.NameEquals("color"))
{
result.Color = property.Value.GetString().ToGoblinSharkColor();
result.Color = new GoblinSharkColor(property.Value.GetString());
continue;
}
}

Просмотреть файл

@ -0,0 +1,26 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
namespace body_string.Models.V100
{
internal static class ColorsExtensions
{
public static string ToSerialString(this Colors value) => value switch
{
Colors.RedColor => "red color",
Colors.GreenColor => "green-color",
Colors.BlueColor => "blue_color",
_ => throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown Colors value.")
};
public static Colors ToColors(this string value) => value switch
{
"red color" => Colors.RedColor,
"green-color" => Colors.GreenColor,
"blue_color" => Colors.BlueColor,
_ => throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown Colors value.")
};
}
}

Просмотреть файл

@ -1,37 +1,12 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.ComponentModel;
namespace body_string.Models.V100
{
public readonly partial struct Colors : IEquatable<Colors>
public enum Colors
{
private readonly string? _value;
public Colors(string value)
{
_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);
[EditorBrowsable(EditorBrowsableState.Never)]
public override bool Equals(object? obj) => obj is Colors other && Equals(other);
public bool Equals(Colors other) => string.Equals(_value, other._value, StringComparison.Ordinal);
[EditorBrowsable(EditorBrowsableState.Never)]
public override int GetHashCode() => _value?.GetHashCode() ?? 0;
public override string? ToString() => _value;
RedColor,
GreenColor,
BlueColor
}
}

Просмотреть файл

@ -30,7 +30,7 @@ namespace body_string
switch (response.Status)
{
case 200:
return Response.FromValue(new Colors(document.RootElement.GetString()), response);
return Response.FromValue(document.RootElement.GetString().ToColors(), response);
default:
throw new Exception();
}
@ -54,7 +54,7 @@ namespace body_string
request.Headers.Add("Content-Type", "application/json");
var buffer = new ArrayBufferWriter<byte>();
await using var writer = new Utf8JsonWriter(buffer);
writer.WriteStringValue(stringBody.ToString());
writer.WriteStringValue(stringBody.ToSerialString());
writer.Flush();
request.Content = RequestContent.Create(buffer.WrittenMemory);
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
@ -83,7 +83,7 @@ namespace body_string
switch (response.Status)
{
case 200:
return Response.FromValue(new Colors(document.RootElement.GetString()), response);
return Response.FromValue(document.RootElement.GetString().ToColors(), response);
default:
throw new Exception();
}
@ -107,7 +107,7 @@ namespace body_string
request.Headers.Add("Content-Type", "application/json");
var buffer = new ArrayBufferWriter<byte>();
await using var writer = new Utf8JsonWriter(buffer);
writer.WriteStringValue(enumStringBody.ToString());
writer.WriteStringValue(enumStringBody.ToSerialString());
writer.Flush();
request.Content = RequestContent.Create(buffer.WrittenMemory);
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);

Просмотреть файл

@ -0,0 +1,26 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
namespace header.Models.V100
{
internal static class GreyscaleColorsExtensions
{
public static string ToSerialString(this GreyscaleColors value) => value switch
{
GreyscaleColors.White => "White",
GreyscaleColors.Black => "black",
GreyscaleColors.GREY => "GREY",
_ => throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown GreyscaleColors value.")
};
public static GreyscaleColors ToGreyscaleColors(this string value) => value switch
{
"White" => GreyscaleColors.White,
"black" => GreyscaleColors.Black,
"GREY" => GreyscaleColors.GREY,
_ => throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown GreyscaleColors value.")
};
}
}

Просмотреть файл

@ -1,37 +1,12 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.ComponentModel;
namespace header.Models.V100
{
public readonly partial struct GreyscaleColors : IEquatable<GreyscaleColors>
public enum GreyscaleColors
{
private readonly string? _value;
public GreyscaleColors(string value)
{
_value = value ?? throw new ArgumentNullException(nameof(value));
}
private const string WhiteValue = "White";
private const string BlackValue = "black";
private const string GREYValue = "GREY";
public static GreyscaleColors White { get; } = new GreyscaleColors(WhiteValue);
public static GreyscaleColors Black { get; } = new GreyscaleColors(BlackValue);
public static GreyscaleColors GREY { get; } = new GreyscaleColors(GREYValue);
public static bool operator ==(GreyscaleColors left, GreyscaleColors right) => left.Equals(right);
public static bool operator !=(GreyscaleColors left, GreyscaleColors right) => !left.Equals(right);
public static implicit operator GreyscaleColors(string value) => new GreyscaleColors(value);
[EditorBrowsable(EditorBrowsableState.Never)]
public override bool Equals(object? obj) => obj is GreyscaleColors other && Equals(other);
public bool Equals(GreyscaleColors other) => string.Equals(_value, other._value, StringComparison.Ordinal);
[EditorBrowsable(EditorBrowsableState.Never)]
public override int GetHashCode() => _value?.GetHashCode() ?? 0;
public override string? ToString() => _value;
White,
Black,
GREY
}
}

Просмотреть файл

@ -0,0 +1,26 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
namespace url.Models.V100
{
internal static class UriColorExtensions
{
public static string ToSerialString(this UriColor value) => value switch
{
UriColor.RedColor => "red color",
UriColor.GreenColor => "green color",
UriColor.BlueColor => "blue color",
_ => throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown UriColor value.")
};
public static UriColor ToUriColor(this string value) => value switch
{
"red color" => UriColor.RedColor,
"green color" => UriColor.GreenColor,
"blue color" => UriColor.BlueColor,
_ => throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown UriColor value.")
};
}
}

Просмотреть файл

@ -1,37 +1,12 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.ComponentModel;
namespace url.Models.V100
{
public readonly partial struct UriColor : IEquatable<UriColor>
public enum UriColor
{
private readonly string? _value;
public UriColor(string value)
{
_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 UriColor RedColor { get; } = new UriColor(RedColorValue);
public static UriColor GreenColor { get; } = new UriColor(GreenColorValue);
public static UriColor BlueColor { get; } = new UriColor(BlueColorValue);
public static bool operator ==(UriColor left, UriColor right) => left.Equals(right);
public static bool operator !=(UriColor left, UriColor right) => !left.Equals(right);
public static implicit operator UriColor(string value) => new UriColor(value);
[EditorBrowsable(EditorBrowsableState.Never)]
public override bool Equals(object? obj) => obj is UriColor other && Equals(other);
public bool Equals(UriColor other) => string.Equals(_value, other._value, StringComparison.Ordinal);
[EditorBrowsable(EditorBrowsableState.Never)]
public override int GetHashCode() => _value?.GetHashCode() ?? 0;
public override string? ToString() => _value;
RedColor,
GreenColor,
BlueColor
}
}

Просмотреть файл

@ -12,7 +12,7 @@ namespace url
{
internal static class PathItemsOperations
{
public static async ValueTask<Response> GetAllWithValuesAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string pathItemStringPath, string? pathItemStringQuery, string localStringPath, string? localStringQuery, string host = "http://localhost:3000", CancellationToken cancellationToken = default)
public static async ValueTask<Response> GetAllWithValuesAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string pathItemStringPath, string? pathItemStringQuery, string globalStringPath, string? globalStringQuery, string localStringPath, string? localStringQuery, string host = "http://localhost:3000", CancellationToken cancellationToken = default)
{
using var scope = clientDiagnostics.CreateScope("url.GetAllWithValues");
scope.Start();
@ -22,7 +22,7 @@ namespace url
request.Method = RequestMethod.Get;
request.Uri.Reset(new Uri($"{host}"));
request.Uri.AppendPath("/pathitem/nullable/globalStringPath/", false);
request.Uri.AppendPath("globalStringPath", false);
request.Uri.AppendPath(globalStringPath, true);
request.Uri.AppendPath("/pathItemStringPath/", false);
request.Uri.AppendPath(pathItemStringPath, true);
request.Uri.AppendPath("/localStringPath/", false);
@ -32,6 +32,10 @@ namespace url
{
request.Uri.AppendQuery("pathItemStringQuery", pathItemStringQuery, true);
}
if (globalStringQuery != null)
{
request.Uri.AppendQuery("globalStringQuery", globalStringQuery, true);
}
if (localStringQuery != null)
{
request.Uri.AppendQuery("localStringQuery", localStringQuery, true);
@ -46,7 +50,7 @@ namespace url
throw;
}
}
public static async ValueTask<Response> GetGlobalQueryNullAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string pathItemStringPath, string? pathItemStringQuery, string localStringPath, string? localStringQuery, string host = "http://localhost:3000", CancellationToken cancellationToken = default)
public static async ValueTask<Response> GetGlobalQueryNullAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string pathItemStringPath, string? pathItemStringQuery, string globalStringPath, string? globalStringQuery, string localStringPath, string? localStringQuery, string host = "http://localhost:3000", CancellationToken cancellationToken = default)
{
using var scope = clientDiagnostics.CreateScope("url.GetGlobalQueryNull");
scope.Start();
@ -56,7 +60,7 @@ namespace url
request.Method = RequestMethod.Get;
request.Uri.Reset(new Uri($"{host}"));
request.Uri.AppendPath("/pathitem/nullable/globalStringPath/", false);
request.Uri.AppendPath("globalStringPath", false);
request.Uri.AppendPath(globalStringPath, true);
request.Uri.AppendPath("/pathItemStringPath/", false);
request.Uri.AppendPath(pathItemStringPath, true);
request.Uri.AppendPath("/localStringPath/", false);
@ -66,6 +70,10 @@ namespace url
{
request.Uri.AppendQuery("pathItemStringQuery", pathItemStringQuery, true);
}
if (globalStringQuery != null)
{
request.Uri.AppendQuery("globalStringQuery", globalStringQuery, true);
}
if (localStringQuery != null)
{
request.Uri.AppendQuery("localStringQuery", localStringQuery, true);
@ -80,7 +88,7 @@ namespace url
throw;
}
}
public static async ValueTask<Response> GetGlobalAndLocalQueryNullAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string pathItemStringPath, string? pathItemStringQuery, string localStringPath, string? localStringQuery, string host = "http://localhost:3000", CancellationToken cancellationToken = default)
public static async ValueTask<Response> GetGlobalAndLocalQueryNullAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string pathItemStringPath, string? pathItemStringQuery, string globalStringPath, string? globalStringQuery, string localStringPath, string? localStringQuery, string host = "http://localhost:3000", CancellationToken cancellationToken = default)
{
using var scope = clientDiagnostics.CreateScope("url.GetGlobalAndLocalQueryNull");
scope.Start();
@ -90,7 +98,7 @@ namespace url
request.Method = RequestMethod.Get;
request.Uri.Reset(new Uri($"{host}"));
request.Uri.AppendPath("/pathitem/nullable/globalStringPath/", false);
request.Uri.AppendPath("globalStringPath", false);
request.Uri.AppendPath(globalStringPath, true);
request.Uri.AppendPath("/pathItemStringPath/", false);
request.Uri.AppendPath(pathItemStringPath, true);
request.Uri.AppendPath("/localStringPath/", false);
@ -100,6 +108,10 @@ namespace url
{
request.Uri.AppendQuery("pathItemStringQuery", pathItemStringQuery, true);
}
if (globalStringQuery != null)
{
request.Uri.AppendQuery("globalStringQuery", globalStringQuery, true);
}
if (localStringQuery != null)
{
request.Uri.AppendQuery("localStringQuery", localStringQuery, true);
@ -114,7 +126,7 @@ namespace url
throw;
}
}
public static async ValueTask<Response> GetLocalPathItemQueryNullAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string pathItemStringPath, string? pathItemStringQuery, string localStringPath, string? localStringQuery, string host = "http://localhost:3000", CancellationToken cancellationToken = default)
public static async ValueTask<Response> GetLocalPathItemQueryNullAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string pathItemStringPath, string? pathItemStringQuery, string globalStringPath, string? globalStringQuery, string localStringPath, string? localStringQuery, string host = "http://localhost:3000", CancellationToken cancellationToken = default)
{
using var scope = clientDiagnostics.CreateScope("url.GetLocalPathItemQueryNull");
scope.Start();
@ -124,7 +136,7 @@ namespace url
request.Method = RequestMethod.Get;
request.Uri.Reset(new Uri($"{host}"));
request.Uri.AppendPath("/pathitem/nullable/globalStringPath/", false);
request.Uri.AppendPath("globalStringPath", false);
request.Uri.AppendPath(globalStringPath, true);
request.Uri.AppendPath("/pathItemStringPath/", false);
request.Uri.AppendPath(pathItemStringPath, true);
request.Uri.AppendPath("/localStringPath/", false);
@ -134,6 +146,10 @@ namespace url
{
request.Uri.AppendQuery("pathItemStringQuery", pathItemStringQuery, true);
}
if (globalStringQuery != null)
{
request.Uri.AppendQuery("globalStringQuery", globalStringQuery, true);
}
if (localStringQuery != null)
{
request.Uri.AppendQuery("localStringQuery", localStringQuery, true);

Просмотреть файл

@ -381,7 +381,7 @@ namespace url
request.Method = RequestMethod.Get;
request.Uri.Reset(new Uri($"{host}"));
request.Uri.AppendPath("/paths/byte/empty/", false);
request.Uri.AppendPath("", true);
request.Uri.AppendPath(new byte[] { }, true);
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
return response;
@ -423,7 +423,7 @@ namespace url
request.Method = RequestMethod.Get;
request.Uri.Reset(new Uri($"{host}"));
request.Uri.AppendPath("/paths/date/2012-01-01/", false);
request.Uri.AppendPath("2012-01-01", true);
request.Uri.AppendPath(new DateTime(2012, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc), "D", true);
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
return response;
@ -465,7 +465,7 @@ namespace url
request.Method = RequestMethod.Get;
request.Uri.Reset(new Uri($"{host}"));
request.Uri.AppendPath("/paths/datetime/2012-01-01T01%3A01%3A01Z/", false);
request.Uri.AppendPath("2012-01-01T01:01:01Z", true);
request.Uri.AppendPath(new DateTime(2012, 1, 1, 1, 1, 1, 0, DateTimeKind.Utc), "S", true);
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
return response;

Просмотреть файл

@ -513,7 +513,7 @@ namespace url
request.Method = RequestMethod.Get;
request.Uri.Reset(new Uri($"{host}"));
request.Uri.AppendPath("/queries/byte/empty", false);
request.Uri.AppendQuery("byteQuery", "", true);
request.Uri.AppendQuery("byteQuery", new byte[] { }, true);
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
return response;
@ -558,7 +558,7 @@ namespace url
request.Method = RequestMethod.Get;
request.Uri.Reset(new Uri($"{host}"));
request.Uri.AppendPath("/queries/date/2012-01-01", false);
request.Uri.AppendQuery("dateQuery", "2012-01-01", true);
request.Uri.AppendQuery("dateQuery", new DateTime(2012, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc), "D", true);
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
return response;
@ -581,7 +581,7 @@ namespace url
request.Uri.AppendPath("/queries/date/null", false);
if (dateQuery != null)
{
request.Uri.AppendQuery("dateQuery", dateQuery.Value, true);
request.Uri.AppendQuery("dateQuery", dateQuery.Value, "D", true);
}
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
@ -603,7 +603,7 @@ namespace url
request.Method = RequestMethod.Get;
request.Uri.Reset(new Uri($"{host}"));
request.Uri.AppendPath("/queries/datetime/2012-01-01T01%3A01%3A01Z", false);
request.Uri.AppendQuery("dateTimeQuery", "2012-01-01T01:01:01Z", true);
request.Uri.AppendQuery("dateTimeQuery", new DateTime(2012, 1, 1, 1, 1, 1, 0, DateTimeKind.Utc), "S", true);
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
return response;
@ -626,7 +626,7 @@ namespace url
request.Uri.AppendPath("/queries/datetime/null", false);
if (dateTimeQuery != null)
{
request.Uri.AppendQuery("dateTimeQuery", dateTimeQuery.Value, true);
request.Uri.AppendQuery("dateTimeQuery", dateTimeQuery.Value, "S", true);
}
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();