Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,26 @@ export function createModelForService(

const apiVersions: Set<string> | undefined = new Set<string>();
let defaultApiVersion: string | undefined = undefined;
const versions = getVersions(program, service.type)[1]?.getVersions();
let versions = getVersions(program, service.type)[1]
?.getVersions()
.map((v) => v.value);
const targetApiVersion = sdkContext.emitContext.options["api-version"];
if (
versions !== undefined &&
targetApiVersion !== undefined &&
targetApiVersion !== "all" &&
targetApiVersion !== "latest"
) {
const targetApiVersionIndex = versions.findIndex(
(v) => v === targetApiVersion
);
versions = versions.slice(0, targetApiVersionIndex + 1);
}
if (versions && versions.length > 0) {
for (const ver of versions) {
apiVersions.add(ver.value);
apiVersions.add(ver);
}
defaultApiVersion = versions[versions.length - 1].value;
defaultApiVersion = versions[versions.length - 1];
}
const defaultApiVersionConstant: InputConstant | undefined =
defaultApiVersion
Expand Down
8 changes: 8 additions & 0 deletions test/AutoRest.TestServerLowLevel.Tests/dpg-latest-version.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Collections.Generic;
using Resource = TypeSpec.Versioning.Latest.Models.Resource;
using System.Threading;
using System.Reflection;

namespace AutoRest.TestServer.Tests
{
Expand Down Expand Up @@ -42,6 +43,13 @@ public void LatestVersion()
m.ReturnType.GenericTypeArguments[0] == typeof(Resource)).FirstOrDefault();
var createLongRunningOperationParameters = createLongRunningOperation.GetParameters().Select(p => (p.Name, p.ParameterType)).ToArray();
Assert.AreEqual(new (string, Type)[] { ("waitUntil", typeof(WaitUntil)), ("name", typeof(string)), ("resource", typeof(Resource)), ("cancellationToken", typeof(CancellationToken)) }, createLongRunningOperationParameters);

// All 3 versions are defined
var enumType = typeof(LatestClientOptions.ServiceVersion);
Assert.AreEqual(new string[] { "V2022_06_01_Preview", "V2022_09_01", "V2022_12_01_Preview" }, enumType.GetEnumNames());
var optionsType = typeof(LatestClientOptions);
var field = optionsType.GetField("LatestVersion", BindingFlags.NonPublic | BindingFlags.Static);
Assert.AreEqual(LatestClientOptions.ServiceVersion.V2022_12_01_Preview, field.GetValue(null));
}
}
}
8 changes: 8 additions & 0 deletions test/AutoRest.TestServerLowLevel.Tests/dpg-oldest-version.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Collections.Generic;
using Resource = TypeSpec.Versioning.Oldest.Models.Resource;
using System.Threading;
using System.Reflection;

namespace AutoRest.TestServer.Tests
{
Expand Down Expand Up @@ -42,6 +43,13 @@ public void OldestVersion()
m.ReturnType.GenericTypeArguments[0] == typeof(Resource)).FirstOrDefault();
var getResourcesOperationParameters = getResourcesOperation.GetParameters().Select(p => (p.Name, p.ParameterType)).ToArray();
Assert.AreEqual(new (string, Type)[] { ("select", typeof(IEnumerable<string>)), ("expand", typeof(string)), ("cancellationToken", typeof(CancellationToken)) },getResourcesOperationParameters);

// Only 1 version is defined
var enumType = typeof(OldestClientOptions.ServiceVersion);
Assert.AreEqual(new string[] { "V2022_06_01_Preview" }, enumType.GetEnumNames());
var optionsType = typeof(OldestClientOptions);
var field = optionsType.GetField("LatestVersion", BindingFlags.NonPublic | BindingFlags.Static);
Assert.AreEqual(OldestClientOptions.ServiceVersion.V2022_06_01_Preview, field.GetValue(null));
}
}
}
10 changes: 9 additions & 1 deletion test/AutoRest.TestServerLowLevel.Tests/dpg-specific-version.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Collections.Generic;
using Resource = TypeSpec.Versioning.Specific.Models.Resource;
using System.Threading;
using System.Reflection;

namespace AutoRest.TestServer.Tests
{
Expand Down Expand Up @@ -41,7 +42,14 @@ public void SpecificVersion()
m.Name == "GetResources" && m.ReturnType.Name.StartsWith("Pageable") && m.ReturnType.GenericTypeArguments.Length == 1 &&
m.ReturnType.GenericTypeArguments[0] == typeof(Resource)).FirstOrDefault();
var getResourcesOperationParameters = getResourcesOperation.GetParameters().Select(p => (p.Name, p.ParameterType)).ToArray();
Assert.AreEqual(new (string, Type)[] { ("select", typeof(IEnumerable<string>)), ("expand", typeof(string)), ("cancellationToken", typeof(CancellationToken)) },getResourcesOperationParameters);
Assert.AreEqual(new (string, Type)[] { ("select", typeof(IEnumerable<string>)), ("expand", typeof(string)), ("cancellationToken", typeof(CancellationToken)) }, getResourcesOperationParameters);

// 2 versions are defined
var enumType = typeof(SpecificClientOptions.ServiceVersion);
Assert.AreEqual(new string[] { "V2022_06_01_Preview", "V2022_09_01" }, enumType.GetEnumNames());
var optionsType = typeof(SpecificClientOptions);
var field = optionsType.GetField("LatestVersion", BindingFlags.NonPublic | BindingFlags.Static);
Assert.AreEqual(SpecificClientOptions.ServiceVersion.V2022_09_01, field.GetValue(null));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
This sample shows how to call CreateAsync.
<code><![CDATA[
Uri endpoint = new Uri("<https://my-service.azure.com>");
VersioningOp client = new OldestClient(endpoint).GetVersioningOpClient(apiVersion: "2022-12-01-preview");
VersioningOp client = new OldestClient(endpoint).GetVersioningOpClient(apiVersion: "2022-06-01-preview");

Models.Resource resource = new Models.Resource("<type>");
Response<Models.Resource> response = await client.CreateAsync("<name>", resource);
]]></code>
This sample shows how to call CreateAsync with all parameters.
<code><![CDATA[
Uri endpoint = new Uri("<https://my-service.azure.com>");
VersioningOp client = new OldestClient(endpoint).GetVersioningOpClient(apiVersion: "2022-12-01-preview");
VersioningOp client = new OldestClient(endpoint).GetVersioningOpClient(apiVersion: "2022-06-01-preview");

Models.Resource resource = new Models.Resource("<type>");
Response<Models.Resource> response = await client.CreateAsync("<name>", resource);
Expand All @@ -25,15 +25,15 @@ Response<Models.Resource> response = await client.CreateAsync("<name>", resource
This sample shows how to call Create.
<code><![CDATA[
Uri endpoint = new Uri("<https://my-service.azure.com>");
VersioningOp client = new OldestClient(endpoint).GetVersioningOpClient(apiVersion: "2022-12-01-preview");
VersioningOp client = new OldestClient(endpoint).GetVersioningOpClient(apiVersion: "2022-06-01-preview");

Models.Resource resource = new Models.Resource("<type>");
Response<Models.Resource> response = client.Create("<name>", resource);
]]></code>
This sample shows how to call Create with all parameters.
<code><![CDATA[
Uri endpoint = new Uri("<https://my-service.azure.com>");
VersioningOp client = new OldestClient(endpoint).GetVersioningOpClient(apiVersion: "2022-12-01-preview");
VersioningOp client = new OldestClient(endpoint).GetVersioningOpClient(apiVersion: "2022-06-01-preview");

Models.Resource resource = new Models.Resource("<type>");
Response<Models.Resource> response = client.Create("<name>", resource);
Expand All @@ -44,7 +44,7 @@ Response<Models.Resource> response = client.Create("<name>", resource);
This sample shows how to call CreateAsync and parse the result.
<code><![CDATA[
Uri endpoint = new Uri("<https://my-service.azure.com>");
VersioningOp client = new OldestClient(endpoint).GetVersioningOpClient(apiVersion: "2022-12-01-preview");
VersioningOp client = new OldestClient(endpoint).GetVersioningOpClient(apiVersion: "2022-06-01-preview");

using RequestContent content = RequestContent.Create(new
{
Expand All @@ -60,7 +60,7 @@ Console.WriteLine(result.GetProperty("type").ToString());
This sample shows how to call CreateAsync with all parameters and request content and parse the result.
<code><![CDATA[
Uri endpoint = new Uri("<https://my-service.azure.com>");
VersioningOp client = new OldestClient(endpoint).GetVersioningOpClient(apiVersion: "2022-12-01-preview");
VersioningOp client = new OldestClient(endpoint).GetVersioningOpClient(apiVersion: "2022-06-01-preview");

using RequestContent content = RequestContent.Create(new
{
Expand All @@ -79,7 +79,7 @@ Console.WriteLine(result.GetProperty("type").ToString());
This sample shows how to call Create and parse the result.
<code><![CDATA[
Uri endpoint = new Uri("<https://my-service.azure.com>");
VersioningOp client = new OldestClient(endpoint).GetVersioningOpClient(apiVersion: "2022-12-01-preview");
VersioningOp client = new OldestClient(endpoint).GetVersioningOpClient(apiVersion: "2022-06-01-preview");

using RequestContent content = RequestContent.Create(new
{
Expand All @@ -95,7 +95,7 @@ Console.WriteLine(result.GetProperty("type").ToString());
This sample shows how to call Create with all parameters and request content and parse the result.
<code><![CDATA[
Uri endpoint = new Uri("<https://my-service.azure.com>");
VersioningOp client = new OldestClient(endpoint).GetVersioningOpClient(apiVersion: "2022-12-01-preview");
VersioningOp client = new OldestClient(endpoint).GetVersioningOpClient(apiVersion: "2022-06-01-preview");

using RequestContent content = RequestContent.Create(new
{
Expand All @@ -114,7 +114,7 @@ Console.WriteLine(result.GetProperty("type").ToString());
This sample shows how to call GetResourcesAsync.
<code><![CDATA[
Uri endpoint = new Uri("<https://my-service.azure.com>");
VersioningOp client = new OldestClient(endpoint).GetVersioningOpClient(apiVersion: "2022-12-01-preview");
VersioningOp client = new OldestClient(endpoint).GetVersioningOpClient(apiVersion: "2022-06-01-preview");

await foreach (Models.Resource item in client.GetResourcesAsync())
{
Expand All @@ -123,7 +123,7 @@ await foreach (Models.Resource item in client.GetResourcesAsync())
This sample shows how to call GetResourcesAsync with all parameters.
<code><![CDATA[
Uri endpoint = new Uri("<https://my-service.azure.com>");
VersioningOp client = new OldestClient(endpoint).GetVersioningOpClient(apiVersion: "2022-12-01-preview");
VersioningOp client = new OldestClient(endpoint).GetVersioningOpClient(apiVersion: "2022-06-01-preview");

await foreach (Models.Resource item in client.GetResourcesAsync(select: new string[] { "<select>" }, expand: "<expand>"))
{
Expand All @@ -135,7 +135,7 @@ await foreach (Models.Resource item in client.GetResourcesAsync(select: new stri
This sample shows how to call GetResources.
<code><![CDATA[
Uri endpoint = new Uri("<https://my-service.azure.com>");
VersioningOp client = new OldestClient(endpoint).GetVersioningOpClient(apiVersion: "2022-12-01-preview");
VersioningOp client = new OldestClient(endpoint).GetVersioningOpClient(apiVersion: "2022-06-01-preview");

foreach (Models.Resource item in client.GetResources())
{
Expand All @@ -144,7 +144,7 @@ foreach (Models.Resource item in client.GetResources())
This sample shows how to call GetResources with all parameters.
<code><![CDATA[
Uri endpoint = new Uri("<https://my-service.azure.com>");
VersioningOp client = new OldestClient(endpoint).GetVersioningOpClient(apiVersion: "2022-12-01-preview");
VersioningOp client = new OldestClient(endpoint).GetVersioningOpClient(apiVersion: "2022-06-01-preview");

foreach (Models.Resource item in client.GetResources(select: new string[] { "<select>" }, expand: "<expand>"))
{
Expand All @@ -156,7 +156,7 @@ foreach (Models.Resource item in client.GetResources(select: new string[] { "<se
This sample shows how to call GetResourcesAsync and parse the result.
<code><![CDATA[
Uri endpoint = new Uri("<https://my-service.azure.com>");
VersioningOp client = new OldestClient(endpoint).GetVersioningOpClient(apiVersion: "2022-12-01-preview");
VersioningOp client = new OldestClient(endpoint).GetVersioningOpClient(apiVersion: "2022-06-01-preview");

await foreach (BinaryData item in client.GetResourcesAsync(null, null, null))
{
Expand All @@ -169,7 +169,7 @@ await foreach (BinaryData item in client.GetResourcesAsync(null, null, null))
This sample shows how to call GetResourcesAsync with all parameters and parse the result.
<code><![CDATA[
Uri endpoint = new Uri("<https://my-service.azure.com>");
VersioningOp client = new OldestClient(endpoint).GetVersioningOpClient(apiVersion: "2022-12-01-preview");
VersioningOp client = new OldestClient(endpoint).GetVersioningOpClient(apiVersion: "2022-06-01-preview");

await foreach (BinaryData item in client.GetResourcesAsync(new string[] { "<select>" }, "<expand>", null))
{
Expand All @@ -185,7 +185,7 @@ await foreach (BinaryData item in client.GetResourcesAsync(new string[] { "<sele
This sample shows how to call GetResources and parse the result.
<code><![CDATA[
Uri endpoint = new Uri("<https://my-service.azure.com>");
VersioningOp client = new OldestClient(endpoint).GetVersioningOpClient(apiVersion: "2022-12-01-preview");
VersioningOp client = new OldestClient(endpoint).GetVersioningOpClient(apiVersion: "2022-06-01-preview");

foreach (BinaryData item in client.GetResources(null, null, null))
{
Expand All @@ -198,7 +198,7 @@ foreach (BinaryData item in client.GetResources(null, null, null))
This sample shows how to call GetResources with all parameters and parse the result.
<code><![CDATA[
Uri endpoint = new Uri("<https://my-service.azure.com>");
VersioningOp client = new OldestClient(endpoint).GetVersioningOpClient(apiVersion: "2022-12-01-preview");
VersioningOp client = new OldestClient(endpoint).GetVersioningOpClient(apiVersion: "2022-06-01-preview");

foreach (BinaryData item in client.GetResources(new string[] { "<select>" }, "<expand>", null))
{
Expand All @@ -214,15 +214,15 @@ foreach (BinaryData item in client.GetResources(new string[] { "<select>" }, "<e
This sample shows how to call ExportAsync.
<code><![CDATA[
Uri endpoint = new Uri("<https://my-service.azure.com>");
VersioningOp client = new OldestClient(endpoint).GetVersioningOpClient(apiVersion: "2022-12-01-preview");
VersioningOp client = new OldestClient(endpoint).GetVersioningOpClient(apiVersion: "2022-06-01-preview");

Operation<ExportedResource> operation = await client.ExportAsync(WaitUntil.Completed, "<name>");
ExportedResource responseData = operation.Value;
]]></code>
This sample shows how to call ExportAsync with all parameters.
<code><![CDATA[
Uri endpoint = new Uri("<https://my-service.azure.com>");
VersioningOp client = new OldestClient(endpoint).GetVersioningOpClient(apiVersion: "2022-12-01-preview");
VersioningOp client = new OldestClient(endpoint).GetVersioningOpClient(apiVersion: "2022-06-01-preview");

Operation<ExportedResource> operation = await client.ExportAsync(WaitUntil.Completed, "<name>", projectFileVersion: "<projectFileVersion>", removedQueryParam: "<removedQueryParam>");
ExportedResource responseData = operation.Value;
Expand All @@ -233,15 +233,15 @@ ExportedResource responseData = operation.Value;
This sample shows how to call Export.
<code><![CDATA[
Uri endpoint = new Uri("<https://my-service.azure.com>");
VersioningOp client = new OldestClient(endpoint).GetVersioningOpClient(apiVersion: "2022-12-01-preview");
VersioningOp client = new OldestClient(endpoint).GetVersioningOpClient(apiVersion: "2022-06-01-preview");

Operation<ExportedResource> operation = client.Export(WaitUntil.Completed, "<name>");
ExportedResource responseData = operation.Value;
]]></code>
This sample shows how to call Export with all parameters.
<code><![CDATA[
Uri endpoint = new Uri("<https://my-service.azure.com>");
VersioningOp client = new OldestClient(endpoint).GetVersioningOpClient(apiVersion: "2022-12-01-preview");
VersioningOp client = new OldestClient(endpoint).GetVersioningOpClient(apiVersion: "2022-06-01-preview");

Operation<ExportedResource> operation = client.Export(WaitUntil.Completed, "<name>", projectFileVersion: "<projectFileVersion>", removedQueryParam: "<removedQueryParam>");
ExportedResource responseData = operation.Value;
Expand All @@ -252,7 +252,7 @@ ExportedResource responseData = operation.Value;
This sample shows how to call ExportAsync and parse the result.
<code><![CDATA[
Uri endpoint = new Uri("<https://my-service.azure.com>");
VersioningOp client = new OldestClient(endpoint).GetVersioningOpClient(apiVersion: "2022-12-01-preview");
VersioningOp client = new OldestClient(endpoint).GetVersioningOpClient(apiVersion: "2022-06-01-preview");

Operation<BinaryData> operation = await client.ExportAsync(WaitUntil.Completed, "<name>", null, null, null);
BinaryData responseData = operation.Value;
Expand All @@ -265,7 +265,7 @@ Console.WriteLine(result.GetProperty("name").ToString());
This sample shows how to call ExportAsync with all parameters and parse the result.
<code><![CDATA[
Uri endpoint = new Uri("<https://my-service.azure.com>");
VersioningOp client = new OldestClient(endpoint).GetVersioningOpClient(apiVersion: "2022-12-01-preview");
VersioningOp client = new OldestClient(endpoint).GetVersioningOpClient(apiVersion: "2022-06-01-preview");

Operation<BinaryData> operation = await client.ExportAsync(WaitUntil.Completed, "<name>", "<projectFileVersion>", "<removedQueryParam>", null);
BinaryData responseData = operation.Value;
Expand All @@ -281,7 +281,7 @@ Console.WriteLine(result.GetProperty("name").ToString());
This sample shows how to call Export and parse the result.
<code><![CDATA[
Uri endpoint = new Uri("<https://my-service.azure.com>");
VersioningOp client = new OldestClient(endpoint).GetVersioningOpClient(apiVersion: "2022-12-01-preview");
VersioningOp client = new OldestClient(endpoint).GetVersioningOpClient(apiVersion: "2022-06-01-preview");

Operation<BinaryData> operation = client.Export(WaitUntil.Completed, "<name>", null, null, null);
BinaryData responseData = operation.Value;
Expand All @@ -294,7 +294,7 @@ Console.WriteLine(result.GetProperty("name").ToString());
This sample shows how to call Export with all parameters and parse the result.
<code><![CDATA[
Uri endpoint = new Uri("<https://my-service.azure.com>");
VersioningOp client = new OldestClient(endpoint).GetVersioningOpClient(apiVersion: "2022-12-01-preview");
VersioningOp client = new OldestClient(endpoint).GetVersioningOpClient(apiVersion: "2022-06-01-preview");

Operation<BinaryData> operation = client.Export(WaitUntil.Completed, "<name>", "<projectFileVersion>", "<removedQueryParam>", null);
BinaryData responseData = operation.Value;
Expand Down

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