Add test swagger for x-ms-client-name (#385)
This commit is contained in:
Родитель
72725c100a
Коммит
5e759a0c07
|
@ -1,5 +1,5 @@
|
|||
#Requires -Version 6.0
|
||||
param($name, [switch]$noDebug, [switch]$reset, [switch]$noBuild, [switch]$fast)
|
||||
param($name, [switch]$noDebug, [switch]$reset, [switch]$noBuild, [switch]$fast, [switch]$updateLaunchSettings)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
|
@ -18,7 +18,7 @@ function Invoke-AutoRest($baseOutput, $title, $autoRestArguments)
|
|||
$outputPath = Join-Path $baseOutput $title
|
||||
$command = "dotnet run --project $script:autorestPluginProject --no-build -- --plugin=cs-modeler --title=$title --namespace=$namespace --standalone --input-file=$codeModel --output-path=$outputPath"
|
||||
}
|
||||
|
||||
|
||||
Write-Host "> $command"
|
||||
cmd /c "$command 2>&1"
|
||||
|
||||
|
@ -32,13 +32,15 @@ function Invoke-AutoRest($baseOutput, $title, $autoRestArguments)
|
|||
$repoRoot = Resolve-Path (Join-Path $PSScriptRoot '..')
|
||||
$debugFlags = if (-not $noDebug) { '--debug', '--verbose' }
|
||||
|
||||
$swaggerDefinitions = @{};
|
||||
|
||||
# Test server test configuration
|
||||
$testServerDirectory = Join-Path $repoRoot 'test' 'TestServerProjects'
|
||||
$autorestPluginProject = Resolve-Path (Join-Path $repoRoot 'src' 'AutoRest.CSharp.V3')
|
||||
$launchSettings = Join-Path $autorestPluginProject 'Properties' 'launchSettings.json'
|
||||
$configurationPath = Join-Path $testServerDirectory 'readme.tests.md'
|
||||
$testServerSwaggerPath = Join-Path $repoRoot 'node_modules' '@microsoft.azure' 'autorest.testserver' 'swagger'
|
||||
$testNames = if ($name) { $name } else
|
||||
{
|
||||
$testNames =
|
||||
'additionalProperties',
|
||||
#'azure-composite-swagger',
|
||||
#'azure-parameter-grouping',
|
||||
|
@ -88,7 +90,66 @@ $testNames = if ($name) { $name } else
|
|||
'validation',
|
||||
'xml-service',
|
||||
#'xms-error-responses',
|
||||
'url-multi-collectionFormat'
|
||||
'url-multi-collectionFormat';
|
||||
|
||||
foreach ($testName in $testNames)
|
||||
{
|
||||
$inputFile = Join-Path $testServerSwaggerPath "$testName.json"
|
||||
$swaggerDefinitions[$testName] = @{
|
||||
'title'=$testName;
|
||||
'output'=$testServerDirectory;
|
||||
'arguments'="--require=$configurationPath --input-file=$inputFile"
|
||||
}
|
||||
}
|
||||
|
||||
# Local test swaggers
|
||||
$testSwaggerPath = Join-Path $repoRoot 'test' 'swaggers'
|
||||
|
||||
foreach ($file in Get-ChildItem $testSwaggerPath)
|
||||
{
|
||||
$testName = [System.IO.Path]::GetFileNameWithoutExtension($file.Name)
|
||||
$inputFile = Join-Path $testSwaggerPath "$testName.json"
|
||||
$swaggerDefinitions[$testName] = @{
|
||||
'title'=$testName;
|
||||
'output'=$testServerDirectory;
|
||||
'arguments'="--require=$configurationPath --input-file=$inputFile"
|
||||
}
|
||||
}
|
||||
# Sample configuration
|
||||
$projectNames = 'AppConfiguration', 'CognitiveServices.TextAnalytics'
|
||||
|
||||
foreach ($projectName in $projectNames)
|
||||
{
|
||||
$projectDirectory = Join-Path $repoRoot 'samples' $projectName
|
||||
$configurationPath = Join-Path $projectDirectory 'readme.md'
|
||||
|
||||
$swaggerDefinitions[$projectName] = @{
|
||||
'title'=$projectName;
|
||||
'output'=$projectDirectory;
|
||||
'arguments'="--require=$configurationPath"
|
||||
}
|
||||
}
|
||||
|
||||
if ($updateLaunchSettings)
|
||||
{
|
||||
$settings = @{
|
||||
'profiles' = @{}
|
||||
};
|
||||
|
||||
foreach ($key in $swaggerDefinitions.Keys)
|
||||
{
|
||||
$definition = $swaggerDefinitions[$key];
|
||||
$outputPath = (Join-Path $definition.output $key).Replace($repoRoot, "`$(SolutionDir)")
|
||||
$codeModel = Join-Path $outputPath 'CodeModel.yaml'
|
||||
$namespace = $definition.title.Replace('-', '_')
|
||||
|
||||
$settings.profiles[$key] = @{
|
||||
'commandName'='Project';
|
||||
'commandLineArgs'="--standalone --input-codemodel=$codeModel --plugin=cs-modeler --output-path=$outputPath --namespace=$namespace"
|
||||
}
|
||||
}
|
||||
|
||||
$settings | ConvertTo-Json | Out-File $launchSettings
|
||||
}
|
||||
|
||||
if ($reset -or $env:TF_BUILD)
|
||||
|
@ -101,19 +162,11 @@ if (!$noBuild)
|
|||
dotnet build $autorestPluginProject
|
||||
}
|
||||
|
||||
foreach ($testName in $testNames)
|
||||
$keys = if (![string]::IsNullOrWhiteSpace($name)) { $name } else { $swaggerDefinitions.Keys }
|
||||
|
||||
foreach ($key in $keys)
|
||||
{
|
||||
$inputFile = Join-Path $testServerSwaggerPath "$testName.json"
|
||||
Invoke-AutoRest $testServerDirectory $testName "--require=$configurationPath --input-file=$inputFile"
|
||||
$definition = $swaggerDefinitions[$key];
|
||||
Invoke-AutoRest $definition.output $definition.title $definition.arguments
|
||||
}
|
||||
|
||||
# Sample configuration
|
||||
$sampleDirectory = Join-Path $repoRoot 'samples'
|
||||
$projectNames = 'AppConfiguration', 'CognitiveServices.TextAnalytics'
|
||||
|
||||
foreach ($projectName in $projectNames)
|
||||
{
|
||||
$projectDirectory = Join-Path $sampleDirectory $projectName
|
||||
$configurationPath = Join-Path $projectDirectory 'readme.md'
|
||||
Invoke-AutoRest $projectDirectory $projectName "--require=$configurationPath"
|
||||
}
|
|
@ -57,7 +57,7 @@ namespace AutoRest.CSharp.V3.CodeGen
|
|||
}
|
||||
|
||||
|
||||
using (writer.Class(null, "partial", schema.CSharpName(), implements: string.Join(", ", implementsTypes)))
|
||||
using (writer.Class(null, "partial", schema.Name, implements: string.Join(", ", implementsTypes)))
|
||||
{
|
||||
if (schema.Discriminator != null)
|
||||
{
|
||||
|
@ -169,7 +169,7 @@ namespace AutoRest.CSharp.V3.CodeGen
|
|||
using (writer.Namespace(cs.Namespace))
|
||||
{
|
||||
var implementType = new CSharpType(typeof(IEquatable<>), cs);
|
||||
using (writer.Struct(null, "readonly partial", schema.CSharpName(), writer.Type(implementType)))
|
||||
using (writer.Struct(null, "readonly partial", schema.Name, writer.Type(implementType)))
|
||||
{
|
||||
var stringText = writer.Type(typeof(string));
|
||||
var nullableStringText = writer.Type(typeof(string), true);
|
||||
|
@ -178,7 +178,7 @@ namespace AutoRest.CSharp.V3.CodeGen
|
|||
writer.LineRaw($"private readonly {writer.Pair(nullableStringText, "_value")};");
|
||||
writer.Line();
|
||||
|
||||
using (writer.Method("public", null, schema.CSharpName(), writer.Pair(stringText, "value")))
|
||||
using (writer.Method("public", null, schema.Name, writer.Pair(stringText, "value")))
|
||||
{
|
||||
writer.LineRaw($"_value = value ?? throw new {writer.Type(typeof(ArgumentNullException))}(nameof(value));");
|
||||
}
|
||||
|
|
|
@ -147,7 +147,7 @@ namespace AutoRest.CSharp.V3.CodeGen
|
|||
var cs = _typeFactory.CreateType(schema);
|
||||
using (writer.Namespace(cs.Namespace))
|
||||
{
|
||||
using (writer.Class("internal", "static", $"{schema.CSharpName()}Extensions"))
|
||||
using (writer.Class("internal", "static", $"{schema.Name}Extensions"))
|
||||
{
|
||||
var stringText = writer.Type(typeof(string));
|
||||
var csTypeText = writer.Type(cs);
|
||||
|
@ -169,7 +169,7 @@ namespace AutoRest.CSharp.V3.CodeGen
|
|||
.Append("}")
|
||||
.Prepend("{")
|
||||
.Prepend("value switch"));
|
||||
writer.MethodExpression("public static", csTypeText, $"To{schema.CSharpName()}", new[] { writer.Pair($"this {stringText}", "value") }, toChoiceType);
|
||||
writer.MethodExpression("public static", csTypeText, $"To{schema.Name}", new[] { writer.Pair($"this {stringText}", "value") }, toChoiceType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,100 @@
|
|||
{
|
||||
"profiles": {
|
||||
"AutoRest.CSharp.V3": {
|
||||
"commandName": "Executable",
|
||||
"executablePath": "$(APPDATA)\\npm\\npx.cmd",
|
||||
"commandLineArgs": "npx autorest-beta $(SolutionDir)\\test\\AutoRest.TestServer.Tests\\readme.md --output-folder=$(SolutionDir)\\test\\AutoRest.TestServer.Tests\\body-string --input-file=$(SolutionDir)\\node_modules\\@autorest\\test-server\\__files\\swagger\\body-string.json --title=body-string --namespace=body_string --cs-modeler.attach",
|
||||
"nativeDebugging": true
|
||||
"body-integer": {
|
||||
"commandName": "Project",
|
||||
"commandLineArgs": "--standalone --input-codemodel=$(SolutionDir)\\test\\TestServerProjects\\body-integer\\CodeModel.yaml --plugin=cs-modeler --output-path=$(SolutionDir)\\test\\TestServerProjects\\body-integer --namespace=body_integer"
|
||||
},
|
||||
"Standalone": {
|
||||
"commandName": "Project",
|
||||
"commandLineArgs": "--standalone --input-codemodel=$(SolutionDir)\\test\\TestServerProjects\\xml-service\\CodeModel.yaml --plugin=cs-modeler --output-path=$(SolutionDir)/test/TestServerProjects/xml-service/ --namespace=xml_service"
|
||||
"body-dictionary": {
|
||||
"commandName": "Project",
|
||||
"commandLineArgs": "--standalone --input-codemodel=$(SolutionDir)\\test\\TestServerProjects\\body-dictionary\\CodeModel.yaml --plugin=cs-modeler --output-path=$(SolutionDir)\\test\\TestServerProjects\\body-dictionary --namespace=body_dictionary"
|
||||
},
|
||||
"AppConfiguration": {
|
||||
"commandName": "Project",
|
||||
"commandLineArgs": "--standalone --input-codemodel=$(SolutionDir)\\samples\\AppConfiguration\\AppConfiguration\\CodeModel.yaml --plugin=cs-modeler --output-path=$(SolutionDir)\\samples\\AppConfiguration\\AppConfiguration --namespace=AppConfiguration"
|
||||
},
|
||||
"header": {
|
||||
"commandName": "Project",
|
||||
"commandLineArgs": "--standalone --input-codemodel=$(SolutionDir)\\test\\TestServerProjects\\header\\CodeModel.yaml --plugin=cs-modeler --output-path=$(SolutionDir)\\test\\TestServerProjects\\header --namespace=header"
|
||||
},
|
||||
"custom-baseUrl": {
|
||||
"commandName": "Project",
|
||||
"commandLineArgs": "--standalone --input-codemodel=$(SolutionDir)\\test\\TestServerProjects\\custom-baseUrl\\CodeModel.yaml --plugin=cs-modeler --output-path=$(SolutionDir)\\test\\TestServerProjects\\custom-baseUrl --namespace=custom_baseUrl"
|
||||
},
|
||||
"additionalProperties": {
|
||||
"commandName": "Project",
|
||||
"commandLineArgs": "--standalone --input-codemodel=$(SolutionDir)\\test\\TestServerProjects\\additionalProperties\\CodeModel.yaml --plugin=cs-modeler --output-path=$(SolutionDir)\\test\\TestServerProjects\\additionalProperties --namespace=additionalProperties"
|
||||
},
|
||||
"body-boolean": {
|
||||
"commandName": "Project",
|
||||
"commandLineArgs": "--standalone --input-codemodel=$(SolutionDir)\\test\\TestServerProjects\\body-boolean\\CodeModel.yaml --plugin=cs-modeler --output-path=$(SolutionDir)\\test\\TestServerProjects\\body-boolean --namespace=body_boolean"
|
||||
},
|
||||
"extension-client-name": {
|
||||
"commandName": "Project",
|
||||
"commandLineArgs": "--standalone --input-codemodel=$(SolutionDir)\\test\\TestServerProjects\\extension-client-name\\CodeModel.yaml --plugin=cs-modeler --output-path=$(SolutionDir)\\test\\TestServerProjects\\extension-client-name --namespace=extension_client_name"
|
||||
},
|
||||
"body-string": {
|
||||
"commandName": "Project",
|
||||
"commandLineArgs": "--standalone --input-codemodel=$(SolutionDir)\\test\\TestServerProjects\\body-string\\CodeModel.yaml --plugin=cs-modeler --output-path=$(SolutionDir)\\test\\TestServerProjects\\body-string --namespace=body_string"
|
||||
},
|
||||
"body-complex": {
|
||||
"commandName": "Project",
|
||||
"commandLineArgs": "--standalone --input-codemodel=$(SolutionDir)\\test\\TestServerProjects\\body-complex\\CodeModel.yaml --plugin=cs-modeler --output-path=$(SolutionDir)\\test\\TestServerProjects\\body-complex --namespace=body_complex"
|
||||
},
|
||||
"body-file": {
|
||||
"commandName": "Project",
|
||||
"commandLineArgs": "--standalone --input-codemodel=$(SolutionDir)\\test\\TestServerProjects\\body-file\\CodeModel.yaml --plugin=cs-modeler --output-path=$(SolutionDir)\\test\\TestServerProjects\\body-file --namespace=body_file"
|
||||
},
|
||||
"body-number": {
|
||||
"commandName": "Project",
|
||||
"commandLineArgs": "--standalone --input-codemodel=$(SolutionDir)\\test\\TestServerProjects\\body-number\\CodeModel.yaml --plugin=cs-modeler --output-path=$(SolutionDir)\\test\\TestServerProjects\\body-number --namespace=body_number"
|
||||
},
|
||||
"url": {
|
||||
"commandName": "Project",
|
||||
"commandLineArgs": "--standalone --input-codemodel=$(SolutionDir)\\test\\TestServerProjects\\url\\CodeModel.yaml --plugin=cs-modeler --output-path=$(SolutionDir)\\test\\TestServerProjects\\url --namespace=url"
|
||||
},
|
||||
"body-duration": {
|
||||
"commandName": "Project",
|
||||
"commandLineArgs": "--standalone --input-codemodel=$(SolutionDir)\\test\\TestServerProjects\\body-duration\\CodeModel.yaml --plugin=cs-modeler --output-path=$(SolutionDir)\\test\\TestServerProjects\\body-duration --namespace=body_duration"
|
||||
},
|
||||
"body-byte": {
|
||||
"commandName": "Project",
|
||||
"commandLineArgs": "--standalone --input-codemodel=$(SolutionDir)\\test\\TestServerProjects\\body-byte\\CodeModel.yaml --plugin=cs-modeler --output-path=$(SolutionDir)\\test\\TestServerProjects\\body-byte --namespace=body_byte"
|
||||
},
|
||||
"body-datetime-rfc1123": {
|
||||
"commandName": "Project",
|
||||
"commandLineArgs": "--standalone --input-codemodel=$(SolutionDir)\\test\\TestServerProjects\\body-datetime-rfc1123\\CodeModel.yaml --plugin=cs-modeler --output-path=$(SolutionDir)\\test\\TestServerProjects\\body-datetime-rfc1123 --namespace=body_datetime_rfc1123"
|
||||
},
|
||||
"CognitiveServices.TextAnalytics": {
|
||||
"commandName": "Project",
|
||||
"commandLineArgs": "--standalone --input-codemodel=$(SolutionDir)\\samples\\CognitiveServices.TextAnalytics\\CognitiveServices.TextAnalytics\\CodeModel.yaml --plugin=cs-modeler --output-path=$(SolutionDir)\\samples\\CognitiveServices.TextAnalytics\\CognitiveServices.TextAnalytics --namespace=CognitiveServices.TextAnalytics"
|
||||
},
|
||||
"validation": {
|
||||
"commandName": "Project",
|
||||
"commandLineArgs": "--standalone --input-codemodel=$(SolutionDir)\\test\\TestServerProjects\\validation\\CodeModel.yaml --plugin=cs-modeler --output-path=$(SolutionDir)\\test\\TestServerProjects\\validation --namespace=validation"
|
||||
},
|
||||
"extensible-enums-swagger": {
|
||||
"commandName": "Project",
|
||||
"commandLineArgs": "--standalone --input-codemodel=$(SolutionDir)\\test\\TestServerProjects\\extensible-enums-swagger\\CodeModel.yaml --plugin=cs-modeler --output-path=$(SolutionDir)\\test\\TestServerProjects\\extensible-enums-swagger --namespace=extensible_enums_swagger"
|
||||
},
|
||||
"body-date": {
|
||||
"commandName": "Project",
|
||||
"commandLineArgs": "--standalone --input-codemodel=$(SolutionDir)\\test\\TestServerProjects\\body-date\\CodeModel.yaml --plugin=cs-modeler --output-path=$(SolutionDir)\\test\\TestServerProjects\\body-date --namespace=body_date"
|
||||
},
|
||||
"url-multi-collectionFormat": {
|
||||
"commandName": "Project",
|
||||
"commandLineArgs": "--standalone --input-codemodel=$(SolutionDir)\\test\\TestServerProjects\\url-multi-collectionFormat\\CodeModel.yaml --plugin=cs-modeler --output-path=$(SolutionDir)\\test\\TestServerProjects\\url-multi-collectionFormat --namespace=url_multi_collectionFormat"
|
||||
},
|
||||
"custom-baseUrl-more-options": {
|
||||
"commandName": "Project",
|
||||
"commandLineArgs": "--standalone --input-codemodel=$(SolutionDir)\\test\\TestServerProjects\\custom-baseUrl-more-options\\CodeModel.yaml --plugin=cs-modeler --output-path=$(SolutionDir)\\test\\TestServerProjects\\custom-baseUrl-more-options --namespace=custom_baseUrl_more_options"
|
||||
},
|
||||
"body-array": {
|
||||
"commandName": "Project",
|
||||
"commandLineArgs": "--standalone --input-codemodel=$(SolutionDir)\\test\\TestServerProjects\\body-array\\CodeModel.yaml --plugin=cs-modeler --output-path=$(SolutionDir)\\test\\TestServerProjects\\body-array --namespace=body_array"
|
||||
},
|
||||
"body-datetime": {
|
||||
"commandName": "Project",
|
||||
"commandLineArgs": "--standalone --input-codemodel=$(SolutionDir)\\test\\TestServerProjects\\body-datetime\\CodeModel.yaml --plugin=cs-modeler --output-path=$(SolutionDir)\\test\\TestServerProjects\\body-datetime --namespace=body_datetime"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ namespace AutoRest.CSharp.V3.Utilities
|
|||
public static string? PrependUnderscoreIfNumbers(this string? text) => Regex.IsMatch(text ?? String.Empty, @"^\d") ? $"_{text}" : text;
|
||||
|
||||
[return: NotNullIfNotNull("name")]
|
||||
public static string? ToCleanName(this string? name) => name?.ToPascalCase().RemoveNonWordCharacters().PrependUnderscoreIfNumbers();
|
||||
public static string ToCleanName(this string name) => name.ToPascalCase().RemoveNonWordCharacters().PrependUnderscoreIfNumbers();
|
||||
[return: NotNullIfNotNull("name")]
|
||||
public static string? ToVariableName(this string? name) => name?.ToCamelCase().RemoveNonWordCharacters().PrependUnderscoreIfNumbers();
|
||||
|
||||
|
|
|
@ -16,12 +16,10 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Infrastructure\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="../swaggers/*.json" LinkBase="swaggers" />
|
||||
<Compile Include="../../src/assets/**/*.cs" />
|
||||
<Compile Include="../TestServerProjects/**/*.cs" LinkBase="TestServerProjects" />
|
||||
<None Include="../TestServerProjects/**/*.yaml" LinkBase="TestServerProjects" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
using extension_client_name;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace AutoRest.TestServer.Tests
|
||||
{
|
||||
public class ExtensionsClientNameTest
|
||||
{
|
||||
[Test]
|
||||
public void ParametersAreRenamed()
|
||||
{
|
||||
var method = TypeAsserts.HasPublicInstanceMethod(typeof(AllOperations), "OriginalOperationAsync");
|
||||
// TODO: Add more tests here
|
||||
TypeAsserts.HasParameter(method, "renamedBodyParameter");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace AutoRest.TestServer.Tests
|
||||
{
|
||||
public static class TypeAsserts
|
||||
{
|
||||
public static MethodInfo HasPublicInstanceMethod(Type type, string name)
|
||||
{
|
||||
var methodInfo = type.GetMethod(name, BindingFlags.Instance | BindingFlags.Public);
|
||||
Assert.NotNull(methodInfo);
|
||||
return methodInfo;
|
||||
}
|
||||
|
||||
public static ParameterInfo HasParameter(MethodInfo method, string name)
|
||||
{
|
||||
var parameterInfo = method.GetParameters().FirstOrDefault(p=>p.Name == name);
|
||||
Assert.NotNull(parameterInfo);
|
||||
return parameterInfo;
|
||||
}
|
||||
}
|
||||
}
|
50
test/TestServerProjects/extension-client-name/Generated/Models/OriginalSchema.Serialization.cs
сгенерированный
Normal file
50
test/TestServerProjects/extension-client-name/Generated/Models/OriginalSchema.Serialization.cs
сгенерированный
Normal file
|
@ -0,0 +1,50 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json;
|
||||
using Azure.Core;
|
||||
|
||||
namespace extension_client_name.Models.V100
|
||||
{
|
||||
public partial class OriginalSchema : IUtf8JsonSerializable
|
||||
{
|
||||
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
|
||||
{
|
||||
writer.WriteStartObject();
|
||||
if (OriginalProperty != null)
|
||||
{
|
||||
writer.WritePropertyName("originalProperty");
|
||||
writer.WriteStartObject();
|
||||
foreach (var item in OriginalProperty)
|
||||
{
|
||||
writer.WritePropertyName(item.Key);
|
||||
writer.WriteStringValue(item.Value);
|
||||
}
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
internal static OriginalSchema DeserializeOriginalSchema(JsonElement element)
|
||||
{
|
||||
OriginalSchema result = new OriginalSchema();
|
||||
foreach (var property in element.EnumerateObject())
|
||||
{
|
||||
if (property.NameEquals("originalProperty"))
|
||||
{
|
||||
if (property.Value.ValueKind == JsonValueKind.Null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
result.OriginalProperty = new Dictionary<string, string>();
|
||||
foreach (var property0 in property.Value.EnumerateObject())
|
||||
{
|
||||
result.OriginalProperty.Add(property0.Name, property0.Value.GetString());
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
12
test/TestServerProjects/extension-client-name/Generated/Models/OriginalSchema.cs
сгенерированный
Normal file
12
test/TestServerProjects/extension-client-name/Generated/Models/OriginalSchema.cs
сгенерированный
Normal file
|
@ -0,0 +1,12 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace extension_client_name.Models.V100
|
||||
{
|
||||
public partial class OriginalSchema
|
||||
{
|
||||
public IDictionary<string, string>? OriginalProperty { get; set; }
|
||||
}
|
||||
}
|
81
test/TestServerProjects/extension-client-name/Generated/Operations/AllOperations.cs
сгенерированный
Normal file
81
test/TestServerProjects/extension-client-name/Generated/Operations/AllOperations.cs
сгенерированный
Normal file
|
@ -0,0 +1,81 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
using System;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Azure.Core;
|
||||
using Azure.Core.Pipeline;
|
||||
using extension_client_name.Models.V100;
|
||||
|
||||
namespace extension_client_name
|
||||
{
|
||||
internal partial class AllOperations
|
||||
{
|
||||
private string host;
|
||||
private ClientDiagnostics clientDiagnostics;
|
||||
private HttpPipeline pipeline;
|
||||
public AllOperations(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string host = "http://localhost:3000")
|
||||
{
|
||||
if (host == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(host));
|
||||
}
|
||||
|
||||
this.host = host;
|
||||
this.clientDiagnostics = clientDiagnostics;
|
||||
this.pipeline = pipeline;
|
||||
}
|
||||
public async ValueTask<ResponseWithHeaders<OriginalSchema, OriginalOperationHeaders>> OriginalOperationAsync(string originalPathParameter, string originalQueryParameter, OriginalSchema renamedBodyParameter, CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (originalPathParameter == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(originalPathParameter));
|
||||
}
|
||||
if (originalQueryParameter == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(originalQueryParameter));
|
||||
}
|
||||
if (renamedBodyParameter == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(renamedBodyParameter));
|
||||
}
|
||||
|
||||
using var scope = clientDiagnostics.CreateScope("extension_client_name.OriginalOperation");
|
||||
scope.Start();
|
||||
try
|
||||
{
|
||||
using var message = pipeline.CreateMessage();
|
||||
var request = message.Request;
|
||||
request.Method = RequestMethod.Patch;
|
||||
request.Uri.Reset(new Uri($"{host}"));
|
||||
request.Uri.AppendPath("/originalOperation/", false);
|
||||
request.Uri.AppendPath(originalPathParameter, true);
|
||||
request.Headers.Add("Content-Type", "application/json");
|
||||
request.Uri.AppendQuery("originalQueryParameter", originalQueryParameter, true);
|
||||
using var content = new Utf8JsonRequestContent();
|
||||
content.JsonWriter.WriteObjectValue(renamedBodyParameter);
|
||||
request.Content = content;
|
||||
await pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
|
||||
switch (message.Response.Status)
|
||||
{
|
||||
case 200:
|
||||
{
|
||||
using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false);
|
||||
var value = OriginalSchema.DeserializeOriginalSchema(document.RootElement);
|
||||
var headers = new OriginalOperationHeaders(message.Response);
|
||||
return ResponseWithHeaders.FromValue(value, headers, message.Response);
|
||||
}
|
||||
default:
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
scope.Failed(e);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
18
test/TestServerProjects/extension-client-name/Generated/Operations/OriginalOperationHeaders.cs
сгенерированный
Normal file
18
test/TestServerProjects/extension-client-name/Generated/Operations/OriginalOperationHeaders.cs
сгенерированный
Normal file
|
@ -0,0 +1,18 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
using Azure;
|
||||
using Azure.Core;
|
||||
|
||||
namespace extension_client_name
|
||||
{
|
||||
internal class OriginalOperationHeaders
|
||||
{
|
||||
private readonly Azure.Response _response;
|
||||
public OriginalOperationHeaders(Azure.Response response)
|
||||
{
|
||||
_response = response;
|
||||
}
|
||||
public string? OriginalHeader => _response.Headers.TryGetValue("originalHeader", out string? value) ? value : null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<Nullable>annotations</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Azure.Core" Version="1.0.0" />
|
||||
<PackageReference Include="System.Text.Json" Version="4.6.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
@ -0,0 +1,82 @@
|
|||
{
|
||||
"swagger": "2.0",
|
||||
"info": {
|
||||
"title": "AutoRest Parameter Flattening",
|
||||
"description": "Resource Flattening for AutoRest",
|
||||
"version": "1.0.0"
|
||||
},
|
||||
"host": "localhost:3000",
|
||||
"schemes": [
|
||||
"http"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"paths": {
|
||||
"/originalOperation/{originalPathParameter}": {
|
||||
"patch": {
|
||||
"operationId": "originalOperation",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "originalPathParameter",
|
||||
"in": "path",
|
||||
"required": true,
|
||||
"type": "string",
|
||||
"x-ms-client-name": "RenamedPathParameter"
|
||||
},
|
||||
{
|
||||
"name": "originalQueryParameter",
|
||||
"x-ms-client-name": "RenamedQueryParameter",
|
||||
"in": "query",
|
||||
"required": true,
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"name": "originalBodyParameter",
|
||||
"x-ms-client-name": "RenamedBodyParameter",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/OriginalSchema"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/OriginalSchema"
|
||||
},
|
||||
"headers": {
|
||||
"originalHeader": {
|
||||
"x-ms-client-name": "RenamedHeader",
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
"OriginalSchema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"originalProperty": {
|
||||
"type": "object",
|
||||
"title": "A set of tags.",
|
||||
"description": "A description about the set of tags.",
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"tags"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче