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 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
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
18 changes: 18 additions & 0 deletions test/AutoRest.TestServer.Tests/paging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using AutoRest.TestServer.Tests.Infrastructure;
using Azure;
Expand Down Expand Up @@ -846,5 +847,22 @@ public void PagingModelsAreHidden()
{
Assert.IsFalse(typeof(ProductResult).IsPublic);
}

[Test]
public void RestClientDroppedMethods()
{
var client = typeof(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(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.

8 changes: 4 additions & 4 deletions test/TestServerProjects/paging/Generated/PagingClient.cs

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

Loading