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

Resolve recursive language definations causing incorrect x-ms-pageable methods #1303

Merged
merged 4 commits into from
Jun 9, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
62 changes: 5 additions & 57 deletions src/AutoRest.CSharp/Common/Input/CodeModelPartials.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ internal partial class Paging
}

/// <summary>language metadata specific to schema instances</summary>
internal partial class Language : IDictionary<string, object>
internal partial class Language
{
/// <summary>namespace of the implementation of this item</summary>
[YamlMember(Alias = "namespace")]
Expand All @@ -198,63 +198,11 @@ internal partial class Language : IDictionary<string, object>
[YamlMember(Alias = "paging")]
public Paging? Paging { get; set; }

[YamlIgnore]
public IDictionary<string, object> AdditionalProperties = new Dictionary<string, object>();
[YamlMember(Alias = "header")]
public string? Header { get; set; }

private readonly Dictionary<string, object> _dictionary = new Dictionary<string, object>();
private static readonly Dictionary<string, PropertyInfo> DeserializableProperties = typeof(Language).GetDeserializableProperties();

// Workaround for mapping properties from the dictionary entries
private void AddAndMap(string key, object value)
{
_dictionary.Add(key, value);

if (DeserializableProperties.ContainsKey(key))
{
var propInfo = DeserializableProperties[key];
propInfo.SetValue(this, propInfo.DeserializeDictionary(value));
return;
}

AdditionalProperties.Add(key, value);
}

public IEnumerator<KeyValuePair<string, object>> GetEnumerator() => _dictionary.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();

public void Add(KeyValuePair<string, object> item) => AddAndMap(item.Key, item.Value);
public void Clear() => _dictionary.Clear();
public bool Contains(KeyValuePair<string, object> item) => _dictionary.ContainsKey(item.Key);
public void CopyTo(KeyValuePair<string, object>[] array, int arrayIndex)
{
foreach (var item in _dictionary)
{
array[arrayIndex++] = item;
}
}
public bool Remove(KeyValuePair<string, object> item) => _dictionary.Remove(item.Key);

public int Count => _dictionary.Count;
public bool IsReadOnly => false;
public void Add(string key, object value) => AddAndMap(key, value);
public bool ContainsKey(string key) => _dictionary.ContainsKey(key);
public bool Remove(string key) => _dictionary.Remove(key);

public bool TryGetValue(string key, out object value)
{
var result = _dictionary.TryGetValue(key, out var outValue);
value = outValue ?? String.Empty;
return result;
}

public object this[string key]
{
get => _dictionary[key];
set => AddAndMap(key, value);
}

public ICollection<string> Keys => _dictionary.Keys;
public ICollection<object> Values => _dictionary.Values;
[YamlMember(Alias = "summary")]
public string? Summary { get; set; }
}

internal partial class NoAuthSecurity : SecurityScheme
Expand Down
4 changes: 4 additions & 0 deletions src/AutoRest.CSharp/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,10 @@
"commandName": "Project",
"commandLineArgs": "--standalone $(SolutionDir)\\test\\TestProjects\\OperationGroupMappings\\Generated"
},
"PageNextLink": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this project add something new on top of the existing test-server paging swagger?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those were in autorest.testserver and this felt possibly specific to C#'s handle of x-ms-pagable. I have no strong feeling here, I can push them up if you think that's preferable.

"commandName": "Project",
"commandLineArgs": "--standalone $(SolutionDir)\\test\\TestProjects\\PageNextLink\\Generated"
},
"paging": {
"commandName": "Project",
"commandLineArgs": "--standalone $(SolutionDir)\\test\\TestServerProjects\\paging\\Generated"
Expand Down
33 changes: 33 additions & 0 deletions test/AutoRest.TestServer.Tests/page-next-link.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.Collections.Generic;
using System.Reflection;
using System.Threading.Tasks;
using AutoRest.TestServer.Tests.Infrastructure;
using Azure;
using NUnit.Framework;
using PageNextLink;

namespace AutoRest.TestServer.Tests
{
public class PageNextLinkTests : TestServerTestBase
{
[Test]
public void RestClientDroppedMethods()
{
var client = typeof(PageNextLink.PagingRestClient);
Assert.IsNull(client.GetMethod ("CreateNextFragmentNextPageRequest", BindingFlags.Instance | BindingFlags.NonPublic), "CreateNextFragmentNextPageRequest should not be generated");
Assert.IsNull(client.GetMethod ("NextFragmentNextPageAsync", BindingFlags.Instance | BindingFlags.NonPublic), "NextFragmentNextPageAsync should not be generated");
Assert.IsNull(client.GetMethod ("NextFragmentNextPage", BindingFlags.Instance | BindingFlags.NonPublic), "NextFragmentNextPage should not be generated");
}

[Test]
public void ClientDroppedMethods()
{
var client = typeof(PageNextLink.PagingClient);
Assert.IsNull(client.GetMethod ("NextFragmentAsync", BindingFlags.Instance | BindingFlags.NonPublic), "NextFragmentAsync should not be generated");
Assert.IsNull(client.GetMethod ("NextFragment", BindingFlags.Instance | BindingFlags.NonPublic), "NextFragment should not be generated");
}
}
}

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