Skip to content

Fix/7.x/interface searchresponse #3888

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

Merged
merged 3 commits into from
Jun 27, 2019
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
14 changes: 12 additions & 2 deletions src/CodeGeneration/ApiGenerator/Domain/Code/CsharpNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ public string ResponseName
else if (ApiName.EndsWith("Exists")) return $"ExistsResponse";

var generatedName = $"{ApiName}Response";
return CodeConfiguration.ResponseLookup.TryGetValue(generatedName, out var lookup) ? lookup.Item1 : generatedName;
var name = CodeConfiguration.ResponseLookup.TryGetValue(generatedName, out var lookup) ? lookup.Item1 : generatedName;
return name;
}
}
public string RequestInterfaceName => $"I{RequestName}";
Expand Down Expand Up @@ -159,7 +160,16 @@ public static List<string> SplitGeneric(string generic) => (generic ?? string.Em

public string GenericOrNonGenericDescriptorName => GenericDescriptorName ?? DescriptorName;
public string GenericOrNonGenericInterfaceName => GenericInterfaceName ?? RequestInterfaceName;
public string GenericOrNonGenericResponseName => GenericResponseName ?? ResponseName;
public string GenericOrNonGenericResponseName
{
get
{
var full = GenericResponseName ?? ResponseName;
if (full.StartsWith("SearchResponse<"))
full = "I" + full;
return full;
}
}

/// <summary> If matching Request.cs only defined generic interface make the client method only accept said interface </summary>
public string GenericOrNonGenericInterfacePreference => CodeConfiguration.GenericOnlyInterfaces.Contains(RequestInterfaceName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,15 @@ public InitializerMethod(CsharpNames names, string link, string summary) : base(

public string DispatchMethod => IsCatMethod ? "DoCat" : "DoRequest";

/// <summary>
/// Dispatch needs a class instance so if the response is an interface transform it to the concrete implementation
/// when calling into DoRequest
/// </summary>
private string DispatchResponseName => InterfaceResponse ? ResponseName.Substring(1, ResponseName.Length - 1) : ResponseName;

public string DispatchGenerics => IsCatMethod
? $"<{ArgumentType},{CsharpNames.ParametersName},{CsharpNames.RequestName.Replace("Request", "Record")}>"
: $"<{ArgumentType},{ResponseName}>";
: $"<{ArgumentType},{DispatchResponseName}>";

public string DispatchParameters => IsCatMethod
? "request"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
namespace ApiGenerator.Domain.Code.HighLevel.Methods
namespace ApiGenerator.Domain.Code.HighLevel.Methods
{
public abstract class MethodSyntaxBase
{
protected MethodSyntaxBase(CsharpNames names, string link, string summary) =>
protected MethodSyntaxBase(CsharpNames names, string link, string summary) =>
(CsharpNames, DocumentationLink, XmlDocSummary) = (names, link, summary);

public string DocumentationLink { get; }

public string XmlDocSummary { get; }

protected CsharpNames CsharpNames { get; }


public bool InterfaceResponse => ResponseName.StartsWith("ISearchResponse<");

public string ResponseName => CsharpNames.GenericOrNonGenericResponseName;

public string DocumentationCref => CsharpNames.GenericOrNonGenericInterfacePreference;

public abstract string MethodGenerics { get; }

public abstract string GenericWhereClause { get; }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
FluentSyntaxBase syntax = Model.Syntax;

var method = !Model.Async ? syntax.MethodName : string.Format("{0}Async", syntax.MethodName);
var asyncKeyword = Model.Syntax.InterfaceResponse && Model.Async ? "async " : String.Empty;
var awaitKeyWord = Model.Syntax.InterfaceResponse && Model.Async ? "await ": string.Empty;
var configureAwait = Model.Syntax.InterfaceResponse && Model.Async ? ".ConfigureAwait(false)" : String.Empty;

var requestMethodGenerics = syntax.RequestMethodGenerics;
var descriptor = syntax.DescriptorName;
Expand All @@ -18,5 +21,5 @@
var cancellationToken = !Model.Async ? string.Empty : ", ct";
}
@{ await IncludeAsync("HighLevel/Client/MethodXmlDocs.cshtml", syntax); }
public @{ await IncludeAsync("HighLevel/Client/FluentSyntax/FluentMethodHeader.cshtml", Model);} @Raw("=>")
@(method)@(Raw(requestMethodGenerics))(selector.InvokeOrDefault(new @(Raw(descriptor))(@Raw(selectorArgs))@(@selectorChained))@cancellationToken);
public @(asyncKeyword)@{ await IncludeAsync("HighLevel/Client/FluentSyntax/FluentMethodHeader.cshtml", Model);} @Raw("=>")
@(awaitKeyWord)@(method)@(Raw(requestMethodGenerics))(selector.InvokeOrDefault(new @(Raw(descriptor))(@Raw(selectorArgs))@(@selectorChained))@cancellationToken)@Raw(configureAwait);
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@
var dispatchMethod = !Model.Async ? syntax.DispatchMethod : string.Format("{0}Async", syntax.DispatchMethod);
var dispatchGenerics = syntax.DispatchGenerics;
var dispatchParameters = syntax.DispatchParameters;
var asyncKeyword = Model.Syntax.InterfaceResponse && Model.Async ? "async " : String.Empty;
var awaitKeyWord = Model.Syntax.InterfaceResponse && Model.Async ? "await ": string.Empty;
var configureAwait = Model.Syntax.InterfaceResponse && Model.Async ? ".ConfigureAwait(false)" : String.Empty;
if (Model.Async)
{
dispatchParameters += ", ct";
}
}
@{ await IncludeAsync("HighLevel/Client/MethodXmlDocs.cshtml", syntax); }
public @{ await IncludeAsync("HighLevel/Client/InitializerSyntax/InitializerMethodHeader.cshtml", Model); } @Raw("=>")
@(dispatchMethod)@(Raw(dispatchGenerics))(@Raw(dispatchParameters));
public @Raw(asyncKeyword)@{ await IncludeAsync("HighLevel/Client/InitializerSyntax/InitializerMethodHeader.cshtml", Model); } @Raw("=>")
@(awaitKeyWord)@(dispatchMethod)@(Raw(dispatchGenerics))(@Raw(dispatchParameters))@Raw(configureAwait);


6 changes: 3 additions & 3 deletions src/Nest/Descriptors.Graph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ public GraphExploreDescriptor<TDocument> Index<TOther>()
///<summary>A shortcut into calling Index(Indices.All)</summary>
public GraphExploreDescriptor<TDocument> AllIndices() => Index(Indices.All);
// Request parameters
///<summary>
///<summary>
/// A document is routed to a particular shard in an index using the following formula
/// <para> shard_num = hash(_routing) % num_primary_shards</para>
/// <para>Elasticsearch will use the document id if not provided. </para>
/// <para>For requests that are constructed from/for a document NEST will automatically infer the routing key
/// if that document has a <see cref = "Nest.JoinField"/> or a routing mapping on for its type exists on <see cref = "Nest.ConnectionSettings"/></para>
///</summary>
/// if that document has a <see cref = "Nest.JoinField"/> or a routing mapping on for its type exists on <see cref = "Nest.ConnectionSettings"/></para>
///</summary>
public GraphExploreDescriptor<TDocument> Routing(Routing routing) => Qs("routing", routing);
///<summary>Explicit operation timeout</summary>
public GraphExploreDescriptor<TDocument> Timeout(Time timeout) => Qs("timeout", timeout);
Expand Down
Loading