Skip to content

Commit 3afd3c2

Browse files
committed
Fix api url lookups (#4714)
* Exclude lookups for ignored high level APIs This commit fixes a bug in the ApiUrlsLookup generator to use the endpoint filename when comparing against the list of high level APIs to ignore. * Do not remove Index from SimulateIndexTemplate method name This commit fixes a bug in the CSharp method name generation where Index is removed from the name of the SimulateIndexTemplate method in the Indices namespace. Removing this causes a collision with SimulateTemplate (cherry picked from commit d36aabb)
1 parent e821cf2 commit 3afd3c2

File tree

3 files changed

+12
-35
lines changed

3 files changed

+12
-35
lines changed

src/ApiGenerator/Domain/Code/CsharpNames.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,29 @@ public CsharpNames(string name, string endpointMethodName, string endpointNamesp
1818
else ApiName = endpointMethodName.ToPascalCase();
1919

2020
//if the api name starts with the namespace do not repeat it in the method name
21-
string Replace(string original, string ns, string find, string replace)
21+
string Replace(string original, string ns, string find, string replace, string[] exceptions)
2222
{
2323
if (ns != null && Namespace != ns) return original;
24+
if (exceptions.Contains(original)) return original;
2425

2526
var replaced = original.Replace(find, replace);
2627
if (string.IsNullOrEmpty(replaced)) return original;
2728

2829
return replaced;
2930
}
3031

31-
MethodName = Replace(ApiName, null, Namespace, "");
32+
MethodName = Replace(ApiName, null, Namespace, "", new string[0]);
3233

33-
var namespaceRenames = new Dictionary<string, (string find, string replace)>
34+
var namespaceRenames = new Dictionary<string, (string find, string replace, string[] exceptions)>
3435
{
35-
{ "Watcher", (find: "Watch", replace: "") },
36-
{ "Indices", (find: "Index", replace: "") },
37-
{ "CrossClusterReplication", (find: "Ccr", replace: "") },
38-
{ "IndexLifecycleManagement", (find: "Ilm", replace: "") },
39-
{ "SnapshotLifecycleManagement", (find: "Slm", replace: "") },
36+
{ "Watcher", (find: "Watch", replace: "", exceptions: new string[0]) },
37+
{ "Indices", (find: "Index", replace: "", exceptions: new string[] { "SimulateIndexTemplate" }) },
38+
{ "CrossClusterReplication", (find: "Ccr", replace: "", exceptions: new string[0]) },
39+
{ "IndexLifecycleManagement", (find: "Ilm", replace: "", exceptions: new string[0]) },
40+
{ "SnapshotLifecycleManagement", (find: "Slm", replace: "", exceptions: new string[0]) },
4041
};
41-
foreach (var (ns, (find, replace)) in namespaceRenames)
42-
MethodName = Replace(MethodName, ns, find, replace);
42+
foreach (var (ns, (find, replace, exceptions)) in namespaceRenames)
43+
MethodName = Replace(MethodName, ns, find, replace, exceptions);
4344
}
4445

4546
/// <summary> Pascal cased version of the namespace from the specification </summary>

src/ApiGenerator/Views/HighLevel/Requests/ApiUrlsLookup.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace Nest
1919
{
2020
@foreach (var endpoint in m.Endpoints.Values)
2121
{
22-
if (CodeConfiguration.IgnoredApisHighLevel.Contains(endpoint.Name))
22+
if (CodeConfiguration.IgnoredApisHighLevel.Contains(endpoint.FileName))
2323
{
2424
continue;
2525
}

src/Nest/_Generated/ApiUrlsLookup.generated.cs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ internal static class ApiUrlsLookups
2121
internal static ApiUrls AsyncSearchDelete = new ApiUrls(new[]{"_async_search/{id}"});
2222
internal static ApiUrls AsyncSearchGet = new ApiUrls(new[]{"_async_search/{id}"});
2323
internal static ApiUrls AsyncSearchSubmit = new ApiUrls(new[]{"_async_search", "{index}/_async_search"});
24-
internal static ApiUrls AutoscalingGetDecision = new ApiUrls(new[]{"_autoscaling/decision"});
2524
internal static ApiUrls NoNamespaceBulk = new ApiUrls(new[]{"_bulk", "{index}/_bulk"});
2625
internal static ApiUrls CatAliases = new ApiUrls(new[]{"_cat/aliases", "_cat/aliases/{name}"});
2726
internal static ApiUrls CatAllocation = new ApiUrls(new[]{"_cat/allocation", "_cat/allocation/{node_id}"});
@@ -63,12 +62,9 @@ internal static class ApiUrlsLookups
6362
internal static ApiUrls CrossClusterReplicationUnfollowIndex = new ApiUrls(new[]{"{index}/_ccr/unfollow"});
6463
internal static ApiUrls NoNamespaceClearScroll = new ApiUrls(new[]{"_search/scroll"});
6564
internal static ApiUrls ClusterAllocationExplain = new ApiUrls(new[]{"_cluster/allocation/explain"});
66-
internal static ApiUrls ClusterDeleteComponentTemplate = new ApiUrls(new[]{"_component_template/{name}"});
67-
internal static ApiUrls ClusterGetComponentTemplate = new ApiUrls(new[]{"_component_template", "_component_template/{name}"});
6865
internal static ApiUrls ClusterGetSettings = new ApiUrls(new[]{"_cluster/settings"});
6966
internal static ApiUrls ClusterHealth = new ApiUrls(new[]{"_cluster/health", "_cluster/health/{index}"});
7067
internal static ApiUrls ClusterPendingTasks = new ApiUrls(new[]{"_cluster/pending_tasks"});
71-
internal static ApiUrls ClusterPutComponentTemplate = new ApiUrls(new[]{"_component_template/{name}"});
7268
internal static ApiUrls ClusterPutSettings = new ApiUrls(new[]{"_cluster/settings"});
7369
internal static ApiUrls ClusterRemoteInfo = new ApiUrls(new[]{"_remote/info"});
7470
internal static ApiUrls ClusterReroute = new ApiUrls(new[]{"_cluster/reroute"});
@@ -85,15 +81,12 @@ internal static class ApiUrlsLookups
8581
internal static ApiUrls EnrichGetPolicy = new ApiUrls(new[]{"_enrich/policy/{name}", "_enrich/policy/"});
8682
internal static ApiUrls EnrichPutPolicy = new ApiUrls(new[]{"_enrich/policy/{name}"});
8783
internal static ApiUrls EnrichStats = new ApiUrls(new[]{"_enrich/_stats"});
88-
internal static ApiUrls EqlSearch = new ApiUrls(new[]{"{index}/_eql/search"});
8984
internal static ApiUrls NoNamespaceDocumentExists = new ApiUrls(new[]{"{index}/_doc/{id}"});
9085
internal static ApiUrls NoNamespaceSourceExists = new ApiUrls(new[]{"{index}/_source/{id}"});
9186
internal static ApiUrls NoNamespaceExplain = new ApiUrls(new[]{"{index}/_explain/{id}"});
9287
internal static ApiUrls NoNamespaceFieldCapabilities = new ApiUrls(new[]{"_field_caps", "{index}/_field_caps"});
9388
internal static ApiUrls NoNamespaceGet = new ApiUrls(new[]{"{index}/_doc/{id}"});
9489
internal static ApiUrls NoNamespaceGetScript = new ApiUrls(new[]{"_scripts/{id}"});
95-
internal static ApiUrls NoNamespaceGetScriptContext = new ApiUrls(new[]{"_script_context"});
96-
internal static ApiUrls NoNamespaceGetScriptLanguages = new ApiUrls(new[]{"_script_language"});
9790
internal static ApiUrls NoNamespaceSource = new ApiUrls(new[]{"{index}/_source/{id}"});
9891
internal static ApiUrls GraphExplore = new ApiUrls(new[]{"{index}/_graph/explore"});
9992
internal static ApiUrls IndexLifecycleManagementDeleteLifecycle = new ApiUrls(new[]{"_ilm/policy/{policy_id}"});
@@ -112,10 +105,8 @@ internal static class ApiUrlsLookups
112105
internal static ApiUrls IndicesClone = new ApiUrls(new[]{"{index}/_clone/{target}"});
113106
internal static ApiUrls IndicesClose = new ApiUrls(new[]{"{index}/_close"});
114107
internal static ApiUrls IndicesCreate = new ApiUrls(new[]{"{index}"});
115-
internal static ApiUrls IndicesCreateDataStream = new ApiUrls(new[]{"_data_stream/{name}"});
116108
internal static ApiUrls IndicesDelete = new ApiUrls(new[]{"{index}"});
117109
internal static ApiUrls IndicesDeleteAlias = new ApiUrls(new[]{"{index}/_alias/{name}"});
118-
internal static ApiUrls IndicesDeleteDataStream = new ApiUrls(new[]{"_data_stream/{name}"});
119110
internal static ApiUrls IndicesDeleteTemplate = new ApiUrls(new[]{"_template/{name}"});
120111
internal static ApiUrls IndicesExists = new ApiUrls(new[]{"{index}"});
121112
internal static ApiUrls IndicesAliasExists = new ApiUrls(new[]{"_alias/{name}", "{index}/_alias/{name}"});
@@ -127,7 +118,6 @@ internal static class ApiUrlsLookups
127118
internal static ApiUrls IndicesFreeze = new ApiUrls(new[]{"{index}/_freeze"});
128119
internal static ApiUrls IndicesGet = new ApiUrls(new[]{"{index}"});
129120
internal static ApiUrls IndicesGetAlias = new ApiUrls(new[]{"_alias", "_alias/{name}", "{index}/_alias/{name}", "{index}/_alias"});
130-
internal static ApiUrls IndicesGetDataStreams = new ApiUrls(new[]{"_data_streams", "_data_streams/{name}"});
131121
internal static ApiUrls IndicesGetFieldMapping = new ApiUrls(new[]{"_mapping/field/{fields}", "{index}/_mapping/field/{fields}"});
132122
internal static ApiUrls IndicesGetMapping = new ApiUrls(new[]{"_mapping", "{index}/_mapping"});
133123
internal static ApiUrls IndicesGetSettings = new ApiUrls(new[]{"_settings", "{index}/_settings", "{index}/_settings/{name}", "_settings/{name}"});
@@ -168,26 +158,19 @@ internal static class ApiUrlsLookups
168158
internal static ApiUrls MachineLearningDeleteCalendar = new ApiUrls(new[]{"_ml/calendars/{calendar_id}"});
169159
internal static ApiUrls MachineLearningDeleteCalendarEvent = new ApiUrls(new[]{"_ml/calendars/{calendar_id}/events/{event_id}"});
170160
internal static ApiUrls MachineLearningDeleteCalendarJob = new ApiUrls(new[]{"_ml/calendars/{calendar_id}/jobs/{job_id}"});
171-
internal static ApiUrls MachineLearningDeleteDataFrameAnalytics = new ApiUrls(new[]{"_ml/data_frame/analytics/{id}"});
172161
internal static ApiUrls MachineLearningDeleteDatafeed = new ApiUrls(new[]{"_ml/datafeeds/{datafeed_id}"});
173162
internal static ApiUrls MachineLearningDeleteExpiredData = new ApiUrls(new[]{"_ml/_delete_expired_data"});
174163
internal static ApiUrls MachineLearningDeleteFilter = new ApiUrls(new[]{"_ml/filters/{filter_id}"});
175164
internal static ApiUrls MachineLearningDeleteForecast = new ApiUrls(new[]{"_ml/anomaly_detectors/{job_id}/_forecast/{forecast_id}"});
176165
internal static ApiUrls MachineLearningDeleteJob = new ApiUrls(new[]{"_ml/anomaly_detectors/{job_id}"});
177166
internal static ApiUrls MachineLearningDeleteModelSnapshot = new ApiUrls(new[]{"_ml/anomaly_detectors/{job_id}/model_snapshots/{snapshot_id}"});
178-
internal static ApiUrls MachineLearningDeleteTrainedModel = new ApiUrls(new[]{"_ml/inference/{model_id}"});
179167
internal static ApiUrls MachineLearningEstimateModelMemory = new ApiUrls(new[]{"_ml/anomaly_detectors/_estimate_model_memory"});
180-
internal static ApiUrls MachineLearningEvaluateDataFrame = new ApiUrls(new[]{"_ml/data_frame/_evaluate"});
181-
internal static ApiUrls MachineLearningExplainDataFrameAnalytics = new ApiUrls(new[]{"_ml/data_frame/analytics/_explain", "_ml/data_frame/analytics/{id}/_explain"});
182-
internal static ApiUrls MachineLearningFindFileStructure = new ApiUrls(new[]{"_ml/find_file_structure"});
183168
internal static ApiUrls MachineLearningFlushJob = new ApiUrls(new[]{"_ml/anomaly_detectors/{job_id}/_flush"});
184169
internal static ApiUrls MachineLearningForecastJob = new ApiUrls(new[]{"_ml/anomaly_detectors/{job_id}/_forecast"});
185170
internal static ApiUrls MachineLearningGetBuckets = new ApiUrls(new[]{"_ml/anomaly_detectors/{job_id}/results/buckets/{timestamp}", "_ml/anomaly_detectors/{job_id}/results/buckets"});
186171
internal static ApiUrls MachineLearningGetCalendarEvents = new ApiUrls(new[]{"_ml/calendars/{calendar_id}/events"});
187172
internal static ApiUrls MachineLearningGetCalendars = new ApiUrls(new[]{"_ml/calendars", "_ml/calendars/{calendar_id}"});
188173
internal static ApiUrls MachineLearningGetCategories = new ApiUrls(new[]{"_ml/anomaly_detectors/{job_id}/results/categories/{category_id}", "_ml/anomaly_detectors/{job_id}/results/categories/"});
189-
internal static ApiUrls MachineLearningGetDataFrameAnalytics = new ApiUrls(new[]{"_ml/data_frame/analytics/{id}", "_ml/data_frame/analytics"});
190-
internal static ApiUrls MachineLearningGetDataFrameAnalyticsStats = new ApiUrls(new[]{"_ml/data_frame/analytics/_stats", "_ml/data_frame/analytics/{id}/_stats"});
191174
internal static ApiUrls MachineLearningGetDatafeedStats = new ApiUrls(new[]{"_ml/datafeeds/{datafeed_id}/_stats", "_ml/datafeeds/_stats"});
192175
internal static ApiUrls MachineLearningGetDatafeeds = new ApiUrls(new[]{"_ml/datafeeds/{datafeed_id}", "_ml/datafeeds"});
193176
internal static ApiUrls MachineLearningGetFilters = new ApiUrls(new[]{"_ml/filters", "_ml/filters/{filter_id}"});
@@ -197,25 +180,19 @@ internal static class ApiUrlsLookups
197180
internal static ApiUrls MachineLearningGetModelSnapshots = new ApiUrls(new[]{"_ml/anomaly_detectors/{job_id}/model_snapshots/{snapshot_id}", "_ml/anomaly_detectors/{job_id}/model_snapshots"});
198181
internal static ApiUrls MachineLearningGetOverallBuckets = new ApiUrls(new[]{"_ml/anomaly_detectors/{job_id}/results/overall_buckets"});
199182
internal static ApiUrls MachineLearningGetAnomalyRecords = new ApiUrls(new[]{"_ml/anomaly_detectors/{job_id}/results/records"});
200-
internal static ApiUrls MachineLearningGetTrainedModels = new ApiUrls(new[]{"_ml/inference/{model_id}", "_ml/inference"});
201-
internal static ApiUrls MachineLearningGetTrainedModelsStats = new ApiUrls(new[]{"_ml/inference/{model_id}/_stats", "_ml/inference/_stats"});
202183
internal static ApiUrls MachineLearningInfo = new ApiUrls(new[]{"_ml/info"});
203184
internal static ApiUrls MachineLearningOpenJob = new ApiUrls(new[]{"_ml/anomaly_detectors/{job_id}/_open"});
204185
internal static ApiUrls MachineLearningPostCalendarEvents = new ApiUrls(new[]{"_ml/calendars/{calendar_id}/events"});
205186
internal static ApiUrls MachineLearningPostJobData = new ApiUrls(new[]{"_ml/anomaly_detectors/{job_id}/_data"});
206187
internal static ApiUrls MachineLearningPreviewDatafeed = new ApiUrls(new[]{"_ml/datafeeds/{datafeed_id}/_preview"});
207188
internal static ApiUrls MachineLearningPutCalendar = new ApiUrls(new[]{"_ml/calendars/{calendar_id}"});
208189
internal static ApiUrls MachineLearningPutCalendarJob = new ApiUrls(new[]{"_ml/calendars/{calendar_id}/jobs/{job_id}"});
209-
internal static ApiUrls MachineLearningPutDataFrameAnalytics = new ApiUrls(new[]{"_ml/data_frame/analytics/{id}"});
210190
internal static ApiUrls MachineLearningPutDatafeed = new ApiUrls(new[]{"_ml/datafeeds/{datafeed_id}"});
211191
internal static ApiUrls MachineLearningPutFilter = new ApiUrls(new[]{"_ml/filters/{filter_id}"});
212192
internal static ApiUrls MachineLearningPutJob = new ApiUrls(new[]{"_ml/anomaly_detectors/{job_id}"});
213-
internal static ApiUrls MachineLearningPutTrainedModel = new ApiUrls(new[]{"_ml/inference/{model_id}"});
214193
internal static ApiUrls MachineLearningRevertModelSnapshot = new ApiUrls(new[]{"_ml/anomaly_detectors/{job_id}/model_snapshots/{snapshot_id}/_revert"});
215194
internal static ApiUrls MachineLearningSetUpgradeMode = new ApiUrls(new[]{"_ml/set_upgrade_mode"});
216-
internal static ApiUrls MachineLearningStartDataFrameAnalytics = new ApiUrls(new[]{"_ml/data_frame/analytics/{id}/_start"});
217195
internal static ApiUrls MachineLearningStartDatafeed = new ApiUrls(new[]{"_ml/datafeeds/{datafeed_id}/_start"});
218-
internal static ApiUrls MachineLearningStopDataFrameAnalytics = new ApiUrls(new[]{"_ml/data_frame/analytics/{id}/_stop"});
219196
internal static ApiUrls MachineLearningStopDatafeed = new ApiUrls(new[]{"_ml/datafeeds/{datafeed_id}/_stop"});
220197
internal static ApiUrls MachineLearningUpdateDatafeed = new ApiUrls(new[]{"_ml/datafeeds/{datafeed_id}/_update"});
221198
internal static ApiUrls MachineLearningUpdateFilter = new ApiUrls(new[]{"_ml/filters/{filter_id}/_update"});
@@ -233,7 +210,6 @@ internal static class ApiUrlsLookups
233210
internal static ApiUrls NodesUsage = new ApiUrls(new[]{"_nodes/usage", "_nodes/{node_id}/usage", "_nodes/usage/{metric}", "_nodes/{node_id}/usage/{metric}"});
234211
internal static ApiUrls NoNamespacePing = new ApiUrls(new[]{""});
235212
internal static ApiUrls NoNamespacePutScript = new ApiUrls(new[]{"_scripts/{id}", "_scripts/{id}/{context}"});
236-
internal static ApiUrls NoNamespaceRankEval = new ApiUrls(new[]{"_rank_eval", "{index}/_rank_eval"});
237213
internal static ApiUrls NoNamespaceReindexOnServer = new ApiUrls(new[]{"_reindex"});
238214
internal static ApiUrls NoNamespaceReindexRethrottle = new ApiUrls(new[]{"_reindex/{task_id}/_rethrottle"});
239215
internal static ApiUrls NoNamespaceRenderSearchTemplate = new ApiUrls(new[]{"_render/template", "_render/template/{id}"});

0 commit comments

Comments
 (0)