Skip to content

[Backport 8.5] Fix code-gen for IndexTemplate #7178

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 1 commit into from
Jan 23, 2023
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 @@ -26,7 +26,7 @@ public sealed class Name : IEquatable<Name>, IUrlParameter

string IUrlParameter.GetString(ITransportConfiguration? settings) => Value;

public override string ToString() => DebugDisplay;
public override string ToString() => Value;

public static implicit operator Name(string name) => name.IsNullOrEmpty() ? null : new Name(name);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public SimulateIndexTemplateRequest(Elastic.Clients.Elasticsearch.Name name) : b

[JsonInclude]
[JsonPropertyName("composed_of")]
public ICollection<Elastic.Clients.Elasticsearch.Name>? ComposedOf { get; set; }
public ICollection<string>? ComposedOf { get; set; }

[JsonInclude]
[JsonPropertyName("template")]
Expand Down Expand Up @@ -116,7 +116,7 @@ public SimulateIndexTemplateRequestDescriptor<TDocument> Name(Elastic.Clients.El

private bool? AllowAutoCreateValue { get; set; }

private ICollection<Elastic.Clients.Elasticsearch.Name>? ComposedOfValue { get; set; }
private ICollection<string>? ComposedOfValue { get; set; }

private Elastic.Clients.Elasticsearch.IndexManagement.DataStreamVisibility? DataStreamValue { get; set; }

Expand Down Expand Up @@ -166,7 +166,7 @@ public SimulateIndexTemplateRequestDescriptor<TDocument> AllowAutoCreate(bool? a
return Self;
}

public SimulateIndexTemplateRequestDescriptor<TDocument> ComposedOf(ICollection<Elastic.Clients.Elasticsearch.Name>? composedOf)
public SimulateIndexTemplateRequestDescriptor<TDocument> ComposedOf(ICollection<string>? composedOf)
{
ComposedOfValue = composedOf;
return Self;
Expand Down Expand Up @@ -321,7 +321,7 @@ public SimulateIndexTemplateRequestDescriptor Name(Elastic.Clients.Elasticsearch

private bool? AllowAutoCreateValue { get; set; }

private ICollection<Elastic.Clients.Elasticsearch.Name>? ComposedOfValue { get; set; }
private ICollection<string>? ComposedOfValue { get; set; }

private Elastic.Clients.Elasticsearch.IndexManagement.DataStreamVisibility? DataStreamValue { get; set; }

Expand Down Expand Up @@ -371,7 +371,7 @@ public SimulateIndexTemplateRequestDescriptor AllowAutoCreate(bool? allowAutoCre
return Self;
}

public SimulateIndexTemplateRequestDescriptor ComposedOf(ICollection<Elastic.Clients.Elasticsearch.Name>? composedOf)
public SimulateIndexTemplateRequestDescriptor ComposedOf(ICollection<string>? composedOf)
{
ComposedOfValue = composedOf;
return Self;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ public sealed partial class IndexTemplate

[JsonInclude]
[JsonPropertyName("composed_of")]
public IReadOnlyCollection<Elastic.Clients.Elasticsearch.Name> ComposedOf { get; init; }
public IReadOnlyCollection<string> ComposedOf { get; init; }

[JsonInclude]
[JsonPropertyName("data_stream")]
public Elastic.Clients.Elasticsearch.IndexManagement.IndexTemplateDataStreamConfiguration? DataStream { get; init; }

[JsonInclude]
[JsonPropertyName("index_patterns")]
public Elastic.Clients.Elasticsearch.Names IndexPatterns { get; init; }
public IReadOnlyCollection<string> IndexPatterns { get; init; }

[JsonInclude]
[JsonPropertyName("priority")]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.

using System.Linq;
using Elastic.Clients.Elasticsearch.IndexManagement;
using Tests.Serialization;

namespace Tests.IndexManagement.TemplateManagement;

public class GetTemplateResponseSerializationTests : SerializerTestBase
{
private const string ResponseJson = @"{
""index_templates"": [
{
""name"": ""template_1"",
""index_template"": {
""index_patterns"": [
""te*""
],
""template"": {
""settings"": {
""index"": {
""number_of_shards"": ""2""
}
}
},
""composed_of"": [],
""priority"": 1
}
}
]
}";

[U]
public void GetIndexTemplateResponse_DeserializesCorrectly_WhenIndexPatternsAreIncluded()
{
var response = DeserializeJsonString<GetIndexTemplateResponse>(ResponseJson);

response.IndexTemplates.Should().HaveCount(1);

var template = response.IndexTemplates.First();

template.Name.Should().Be("template_1");
template.IndexTemplate.IndexPatterns.Should().HaveCount(1);

template.IndexTemplate.IndexPatterns.First().Should().Be("te*");
}
}