Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AutoRest version update #11621

Merged
merged 9 commits into from
Apr 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ input-file:
require: https://github.com/Azure/azure-rest-api-specs/blob/49fc16354df7211f8392c56884a3437138317d1f/specification/azsadmin/resource-manager/storage/readme.md
```

3. Run `dotnet msbuild /t:GenerateCode` in src directory of the project (e.g. `net\sdk\storage\Azure.Management.Storage\src`). This would run Autorest and generate the code. (NOTE: this step requires Node 13).
3. Run `dotnet msbuild /t:GenerateCode` in src directory of the project (e.g. `net\sdk\storage\Azure.Management.Storage\src`). This would run AutoRest and generate the code. (NOTE: this step requires Node 13).
4. For management plan libraries add `azure-arm: true` setting to `autorest.md` client constructors and options would be auto-generated. For data-plane libraries follow the next two steps.
4. Add a `*ClientOptions` type that inherits from `ClientOptions` and has a service version enum:

Expand Down
18 changes: 9 additions & 9 deletions eng/CodeGeneration.targets
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
<Project>

<PropertyGroup>
<_AutoRestVersion>https://github.com/Azure/autorest/releases/download/autorest-3.0.6221/autorest-3.0.6221.tgz</_AutoRestVersion>
<_AutoRestCoreVersion>3.0.6280</_AutoRestCoreVersion>
<_AutoRestCSharpVersion>https://github.com/Azure/autorest.csharp/releases/download/3.0.0-dev.20200415.7/autorest-csharp-v3-3.0.0-dev.20200415.7.tgz</_AutoRestCSharpVersion>
<_AutoRestVersion>https://github.com/Azure/autorest/releases/download/autorest-3.0.6222/autorest-3.0.6222.tgz</_AutoRestVersion>
<_AutoRestCoreVersion>3.0.6282</_AutoRestCoreVersion>
<_AutoRestCSharpVersion>https://github.com/Azure/autorest.csharp/releases/download/3.0.0-dev.20200427.3/autorest-csharp-v3-3.0.0-dev.20200427.3.tgz</_AutoRestCSharpVersion>
<_SupportsCodeGeneration Condition="'$(IsClientLibrary)' == 'true'">true</_SupportsCodeGeneration>
<_DefaultInputName Condition="Exists('$(MSBuildProjectDirectory)/autorest.md')">$(MSBuildProjectDirectory)/autorest.md</_DefaultInputName>
<AutorestInput Condition="'$(AutorestInput)' == ''">$(_DefaultInputName)</AutorestInput>
<AutoRestInput Condition="'$(AutoRestInput)' == ''">$(_DefaultInputName)</AutoRestInput>
<!--
Allows passing additional AutoRest command line arguments, for example to run in interactive mode
use the following command line (remove the space between minus minus): dotnet msbuild /t:GenerateCode /p:AutorestAdditionalParameters="- -interactive"
use the following command line (remove the space between minus minus): dotnet msbuild /t:GenerateCode /p:AutoRestAdditionalParameters="- -interactive"
-->
<AutorestAdditionalParameters></AutorestAdditionalParameters>
<AutoRestAdditionalParameters></AutoRestAdditionalParameters>
<_SharedCodeDirectory>$(MSBuildThisFileDirectory)../sdk/core/Azure.Core/src/Shared/</_SharedCodeDirectory>
<_AutoRestSharedCodeDirectory>$(_SharedCodeDirectory)Autorest/</_AutoRestSharedCodeDirectory>
<_AutoRestSharedCodeDirectory>$(_SharedCodeDirectory)AutoRest/</_AutoRestSharedCodeDirectory>

<_GenerateCode Condition="'$(_SupportsCodeGeneration)' == 'true' AND '$(AutorestInput)' != ''">true</_GenerateCode>
<_GenerateCode Condition="'$(_SupportsCodeGeneration)' == 'true' AND '$(AutoRestInput)' != ''">true</_GenerateCode>
<UsesJsonSerialization Condition="'$(UsesJsonSerialization)' == ''">true</UsesJsonSerialization>
</PropertyGroup>

<Target Name="GenerateCode" Condition="'$(_GenerateCode)' == 'true'" >
<RemoveDir Directories="$(MSBuildProjectDirectory)/Generated"/>
<Exec Command="npx autorest@$(_AutoRestVersion) --version=$(_AutoRestCoreVersion) $(AutorestInput) $(AutorestAdditionalParameters) --use=$(_AutoRestCSharpVersion) --output-folder=$(MSBuildProjectDirectory) --title=$(RootNamespace) --namespace=$(RootNamespace) --shared-source-folder=$(_SharedCodeDirectory) --verbose" />
<Exec Command="npx autorest@$(_AutoRestVersion) --version=$(_AutoRestCoreVersion) $(AutoRestInput) $(AutoRestAdditionalParameters) --use=$(_AutoRestCSharpVersion) --output-folder=$(MSBuildProjectDirectory) --title=$(RootNamespace) --namespace=$(RootNamespace) --shared-source-folder=$(_SharedCodeDirectory) --verbose" />
</Target>

<ItemGroup Condition="'$(_GenerateCode)' == 'true'">
Expand Down
153 changes: 153 additions & 0 deletions sdk/core/Azure.Core/src/Shared/AutoRest/RawRequestUriBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

#nullable enable

using System;
using System.Globalization;

namespace Azure.Core
{
internal class RawRequestUriBuilder: RequestUriBuilder
{
private const string SchemeSeparator = "://";
private const char HostSeparator = '/';
private const char PortSeparator = ':';
private static readonly char[] HostOrPort = { HostSeparator, PortSeparator };
private const char QueryBeginSeparator = '?';
private const char QueryContinueSeparator = '&';
private const char QueryValueSeparator = '=';

private RawWritingPosition _position = RawWritingPosition.Scheme;

private static (string Name, string Value) GetQueryParts(string queryUnparsed)
{
int separatorIndex = queryUnparsed.IndexOf(QueryValueSeparator);
if (separatorIndex == -1)
{
return (queryUnparsed, string.Empty);
}
return (queryUnparsed.Substring(0, separatorIndex), queryUnparsed.Substring(separatorIndex + 1));
}

public void AppendRaw(string value, bool escape)
{
while (!string.IsNullOrWhiteSpace(value))
{
if (_position == RawWritingPosition.Scheme)
{
int separator = value.IndexOf(SchemeSeparator, StringComparison.InvariantCultureIgnoreCase);
if (separator == -1)
{
Scheme += value;
value = string.Empty;
}
else
{
Scheme += value.Substring(0, separator);
// TODO: Find a better way to map schemes to default ports
Port = string.Equals(Scheme, "https", StringComparison.OrdinalIgnoreCase) ? 443 : 80;
value = value.Substring(separator + SchemeSeparator.Length);
_position = RawWritingPosition.Host;
}
}
else if (_position == RawWritingPosition.Host)
{
int separator = value.IndexOfAny(HostOrPort);
if (separator == -1)
{
if (string.IsNullOrEmpty(Path))
{
Host += value;
value = string.Empty;
}
else
{
// All Host information must be written before Path information
// If Path already has information, we transition to writing Path
_position = RawWritingPosition.Path;
}
}
else
{
Host += value.Substring(0, separator);
_position = value[separator] == HostSeparator ? RawWritingPosition.Path : RawWritingPosition.Port;
value = value.Substring(separator + 1);
}
}
else if (_position == RawWritingPosition.Port)
{
int separator = value.IndexOf(HostSeparator);
if (separator == -1)
{
Port = int.Parse(value, CultureInfo.InvariantCulture);
value = string.Empty;
}
else
{
Port = int.Parse(value.Substring(0, separator), CultureInfo.InvariantCulture);
value = value.Substring(separator + 1);
}
// Port cannot be split (like Host), so always transition to Path when Port is parsed
_position = RawWritingPosition.Path;
}
else if (_position == RawWritingPosition.Path)
{
int separator = value.IndexOf(QueryBeginSeparator);
if (separator == -1)
{
AppendPath(value, escape);
value = string.Empty;
}
else
{
AppendPath(value.Substring(0, separator), escape);
value = value.Substring(separator + 1);
_position = RawWritingPosition.Query;
}
}
else if (_position == RawWritingPosition.Query)
{
int separator = value.IndexOf(QueryContinueSeparator);
if (separator == 0)
{
value = value.Substring(1);
}
else if (separator == -1)
{
(string queryName, string queryValue) = GetQueryParts(value);
AppendQuery(queryName, queryValue, escape);
value = string.Empty;
}
else
{
(string queryName, string queryValue) = GetQueryParts(value.Substring(0, separator));
AppendQuery(queryName, queryValue, escape);
value = value.Substring(separator + 1);
}
}
}
}

private enum RawWritingPosition
{
Scheme,
Host,
Port,
Path,
Query
}

public void AppendRawNextLink(string nextLink, bool escape)
{
// If it is an absolute link, we use the nextLink as the entire url
if (nextLink.StartsWith(Uri.UriSchemeHttp, StringComparison.InvariantCultureIgnoreCase))
{
Reset(new Uri(nextLink));
return;
}

AppendPath(nextLink, escape);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#nullable enable

using System;
using System.Collections.Generic;
using System.Globalization;

namespace Azure.Core
Expand Down Expand Up @@ -49,5 +50,10 @@ public static void Add(this RequestHeaders headers, string name, byte[] value)
{
headers.Add(name, Convert.ToBase64String(value));
}

public static void AddDelimited<T>(this RequestHeaders headers, string name, IEnumerable<T> value, string delimiter)
{
headers.Add(name, string.Join(delimiter, value));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ public static void AppendQuery(this RequestUriBuilder builder, string name, byte
builder.AppendQuery(name, Convert.ToBase64String(value), escape);
}

public static void AppendQuery(this RequestUriBuilder builder, string name, Guid value, bool escape = true)
{
builder.AppendQuery(name, value.ToString(), escape);
}

public static void AppendQueryDelimited<T>(this RequestUriBuilder builder, string name, IEnumerable<T> value, string delimiter, bool escape = true)
{
builder.AppendQuery(name, string.Join(delimiter, value), escape);
Expand Down
91 changes: 0 additions & 91 deletions sdk/core/Azure.Core/src/Shared/Autorest/RawRequestUriBuilder.cs

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading