Skip to content

Commit

Permalink
Update API spec, fix some spec-related java client issues (#348) (#349)
Browse files Browse the repository at this point in the history
  • Loading branch information
swallez authored Jul 13, 2022
1 parent 57729da commit 9edea36
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class MappingCharFilter extends CharFilterBase implements CharFilterDefin
private MappingCharFilter(Builder builder) {
super(builder);

this.mappings = ApiTypeHelper.unmodifiableRequired(builder.mappings, this, "mappings");
this.mappings = ApiTypeHelper.unmodifiable(builder.mappings);
this.mappingsPath = builder.mappingsPath;

}
Expand All @@ -75,7 +75,7 @@ public CharFilterDefinition.Kind _charFilterDefinitionKind() {
}

/**
* Required - API name: {@code mappings}
* API name: {@code mappings}
*/
public final List<String> mappings() {
return this.mappings;
Expand Down Expand Up @@ -120,13 +120,14 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
public static class Builder extends CharFilterBase.AbstractBuilder<Builder>
implements
ObjectBuilder<MappingCharFilter> {
@Nullable
private List<String> mappings;

@Nullable
private String mappingsPath;

/**
* Required - API name: {@code mappings}
* API name: {@code mappings}
* <p>
* Adds all elements of <code>list</code> to <code>mappings</code>.
*/
Expand All @@ -136,7 +137,7 @@ public final Builder mappings(List<String> list) {
}

/**
* Required - API name: {@code mappings}
* API name: {@code mappings}
* <p>
* Adds one or more values to <code>mappings</code>.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import co.elastic.clients.util.ApiTypeHelper;
import co.elastic.clients.util.ObjectBuilder;
import jakarta.json.stream.JsonGenerator;
import java.util.List;
import java.util.Objects;
import java.util.function.Function;
import javax.annotation.Nullable;
Expand All @@ -45,14 +46,14 @@
*/
@JsonpDeserializable
public class PhraseSuggest extends SuggestBase implements SuggestionVariant {
private final PhraseSuggestOption options;
private final List<PhraseSuggestOption> options;

// ---------------------------------------------------------------------------------------------

private PhraseSuggest(Builder builder) {
super(builder);

this.options = ApiTypeHelper.requireNonNull(builder.options, this, "options");
this.options = ApiTypeHelper.unmodifiableRequired(builder.options, this, "options");

}

Expand All @@ -71,15 +72,23 @@ public Suggestion.Kind _suggestionKind() {
/**
* Required - API name: {@code options}
*/
public final PhraseSuggestOption options() {
public final List<PhraseSuggestOption> options() {
return this.options;
}

protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {

super.serializeInternal(generator, mapper);
generator.writeKey("options");
this.options.serialize(generator, mapper);
if (ApiTypeHelper.isDefined(this.options)) {
generator.writeKey("options");
generator.writeStartArray();
for (PhraseSuggestOption item0 : this.options) {
item0.serialize(generator, mapper);

}
generator.writeEnd();

}

}

Expand All @@ -90,21 +99,35 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
*/

public static class Builder extends SuggestBase.AbstractBuilder<Builder> implements ObjectBuilder<PhraseSuggest> {
private PhraseSuggestOption options;
private List<PhraseSuggestOption> options;

/**
* Required - API name: {@code options}
* <p>
* Adds all elements of <code>list</code> to <code>options</code>.
*/
public final Builder options(List<PhraseSuggestOption> list) {
this.options = _listAddAll(this.options, list);
return this;
}

/**
* Required - API name: {@code options}
* <p>
* Adds one or more values to <code>options</code>.
*/
public final Builder options(PhraseSuggestOption value) {
this.options = value;
public final Builder options(PhraseSuggestOption value, PhraseSuggestOption... values) {
this.options = _listAdd(this.options, value, values);
return this;
}

/**
* Required - API name: {@code options}
* <p>
* Adds a value to <code>options</code> using a builder lambda.
*/
public final Builder options(Function<PhraseSuggestOption.Builder, ObjectBuilder<PhraseSuggestOption>> fn) {
return this.options(fn.apply(new PhraseSuggestOption.Builder()).build());
return options(fn.apply(new PhraseSuggestOption.Builder()).build());
}

@Override
Expand Down Expand Up @@ -135,7 +158,7 @@ public PhraseSuggest build() {

protected static void setupPhraseSuggestDeserializer(ObjectDeserializer<PhraseSuggest.Builder> op) {
SuggestBase.setupSuggestBaseDeserializer(op);
op.add(Builder::options, PhraseSuggestOption._DESERIALIZER, "options");
op.add(Builder::options, JsonpDeserializer.arrayDeserializer(PhraseSuggestOption._DESERIALIZER), "options");

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import co.elastic.clients.util.ApiTypeHelper;
import co.elastic.clients.util.ObjectBuilder;
import jakarta.json.stream.JsonGenerator;
import java.util.List;
import java.util.Objects;
import java.util.function.Function;
import javax.annotation.Nullable;
Expand All @@ -45,14 +46,14 @@
*/
@JsonpDeserializable
public class TermSuggest extends SuggestBase implements SuggestionVariant {
private final TermSuggestOption options;
private final List<TermSuggestOption> options;

// ---------------------------------------------------------------------------------------------

private TermSuggest(Builder builder) {
super(builder);

this.options = ApiTypeHelper.requireNonNull(builder.options, this, "options");
this.options = ApiTypeHelper.unmodifiableRequired(builder.options, this, "options");

}

Expand All @@ -71,15 +72,23 @@ public Suggestion.Kind _suggestionKind() {
/**
* Required - API name: {@code options}
*/
public final TermSuggestOption options() {
public final List<TermSuggestOption> options() {
return this.options;
}

protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {

super.serializeInternal(generator, mapper);
generator.writeKey("options");
this.options.serialize(generator, mapper);
if (ApiTypeHelper.isDefined(this.options)) {
generator.writeKey("options");
generator.writeStartArray();
for (TermSuggestOption item0 : this.options) {
item0.serialize(generator, mapper);

}
generator.writeEnd();

}

}

Expand All @@ -90,21 +99,35 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
*/

public static class Builder extends SuggestBase.AbstractBuilder<Builder> implements ObjectBuilder<TermSuggest> {
private TermSuggestOption options;
private List<TermSuggestOption> options;

/**
* Required - API name: {@code options}
* <p>
* Adds all elements of <code>list</code> to <code>options</code>.
*/
public final Builder options(List<TermSuggestOption> list) {
this.options = _listAddAll(this.options, list);
return this;
}

/**
* Required - API name: {@code options}
* <p>
* Adds one or more values to <code>options</code>.
*/
public final Builder options(TermSuggestOption value) {
this.options = value;
public final Builder options(TermSuggestOption value, TermSuggestOption... values) {
this.options = _listAdd(this.options, value, values);
return this;
}

/**
* Required - API name: {@code options}
* <p>
* Adds a value to <code>options</code> using a builder lambda.
*/
public final Builder options(Function<TermSuggestOption.Builder, ObjectBuilder<TermSuggestOption>> fn) {
return this.options(fn.apply(new TermSuggestOption.Builder()).build());
return options(fn.apply(new TermSuggestOption.Builder()).build());
}

@Override
Expand Down Expand Up @@ -135,7 +158,7 @@ public TermSuggest build() {

protected static void setupTermSuggestDeserializer(ObjectDeserializer<TermSuggest.Builder> op) {
SuggestBase.setupSuggestBaseDeserializer(op);
op.add(Builder::options, TermSuggestOption._DESERIALIZER, "options");
op.add(Builder::options, JsonpDeserializer.arrayDeserializer(TermSuggestOption._DESERIALIZER), "options");

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,17 @@
'_global.search._types.AggregationProfileDelegateDebugFilter': '_global/search/_types/profile.ts#L68-L72',
'_global.search._types.BoundaryScanner': '_global/search/_types/highlighting.ts#L26-L30',
'_global.search._types.Collector': '_global/search/_types/profile.ts#L83-L88',
'_global.search._types.CompletionContext': '_global/search/_types/suggester.ts#L150-L157',
'_global.search._types.CompletionSuggest': '_global/search/_types/suggester.ts#L48-L53',
'_global.search._types.CompletionSuggestOption': '_global/search/_types/suggester.ts#L71-L82',
'_global.search._types.CompletionSuggester': '_global/search/_types/suggester.ts#L125-L131',
'_global.search._types.Context': '_global/search/_types/suggester.ts#L143-L148',
'_global.search._types.DirectGenerator': '_global/search/_types/suggester.ts#L161-L173',
'_global.search._types.CompletionContext': '_global/search/_types/suggester.ts#L152-L159',
'_global.search._types.CompletionSuggest': '_global/search/_types/suggester.ts#L48-L55',
'_global.search._types.CompletionSuggestOption': '_global/search/_types/suggester.ts#L73-L84',
'_global.search._types.CompletionSuggester': '_global/search/_types/suggester.ts#L127-L133',
'_global.search._types.Context': '_global/search/_types/suggester.ts#L145-L150',
'_global.search._types.DirectGenerator': '_global/search/_types/suggester.ts#L163-L175',
'_global.search._types.FetchProfile': '_global/search/_types/profile.ts#L136-L143',
'_global.search._types.FetchProfileBreakdown': '_global/search/_types/profile.ts#L145-L152',
'_global.search._types.FetchProfileDebug': '_global/search/_types/profile.ts#L154-L157',
'_global.search._types.FieldCollapse': '_global/search/_types/FieldCollapse.ts#L24-L29',
'_global.search._types.FieldSuggester': '_global/search/_types/suggester.ts#L101-L115',
'_global.search._types.FieldSuggester': '_global/search/_types/suggester.ts#L103-L117',
'_global.search._types.Highlight': '_global/search/_types/highlighting.ts#L56-L59',
'_global.search._types.HighlightBase': '_global/search/_types/highlighting.ts#L32-L54',
'_global.search._types.HighlightField': '_global/search/_types/highlighting.ts#L87-L90',
Expand All @@ -156,15 +156,15 @@
'_global.search._types.HitsMetadata': '_global/search/_types/hits.ts#L62-L68',
'_global.search._types.InnerHits': '_global/search/_types/hits.ts#L102-L120',
'_global.search._types.InnerHitsResult': '_global/search/_types/hits.ts#L80-L82',
'_global.search._types.LaplaceSmoothingModel': '_global/search/_types/suggester.ts#L207-L209',
'_global.search._types.LinearInterpolationSmoothingModel': '_global/search/_types/suggester.ts#L211-L215',
'_global.search._types.LaplaceSmoothingModel': '_global/search/_types/suggester.ts#L209-L211',
'_global.search._types.LinearInterpolationSmoothingModel': '_global/search/_types/suggester.ts#L213-L217',
'_global.search._types.NestedIdentity': '_global/search/_types/hits.ts#L84-L88',
'_global.search._types.PhraseSuggest': '_global/search/_types/suggester.ts#L55-L60',
'_global.search._types.PhraseSuggestCollate': '_global/search/_types/suggester.ts#L175-L179',
'_global.search._types.PhraseSuggestCollateQuery': '_global/search/_types/suggester.ts#L181-L184',
'_global.search._types.PhraseSuggestHighlight': '_global/search/_types/suggester.ts#L202-L205',
'_global.search._types.PhraseSuggestOption': '_global/search/_types/suggester.ts#L84-L88',
'_global.search._types.PhraseSuggester': '_global/search/_types/suggester.ts#L186-L200',
'_global.search._types.PhraseSuggest': '_global/search/_types/suggester.ts#L57-L62',
'_global.search._types.PhraseSuggestCollate': '_global/search/_types/suggester.ts#L177-L181',
'_global.search._types.PhraseSuggestCollateQuery': '_global/search/_types/suggester.ts#L183-L186',
'_global.search._types.PhraseSuggestHighlight': '_global/search/_types/suggester.ts#L204-L207',
'_global.search._types.PhraseSuggestOption': '_global/search/_types/suggester.ts#L86-L90',
'_global.search._types.PhraseSuggester': '_global/search/_types/suggester.ts#L188-L202',
'_global.search._types.PointInTimeReference': '_global/search/_types/PointInTimeReference.ts#L23-L26',
'_global.search._types.Profile': '_global/search/_types/profile.ts#L90-L92',
'_global.search._types.QueryBreakdown': '_global/search/_types/profile.ts#L94-L113',
Expand All @@ -174,21 +174,21 @@
'_global.search._types.ScoreMode': '_global/search/_types/rescoring.ts#L36-L42',
'_global.search._types.SearchProfile': '_global/search/_types/profile.ts#L123-L127',
'_global.search._types.ShardProfile': '_global/search/_types/profile.ts#L129-L134',
'_global.search._types.SmoothingModelContainer': '_global/search/_types/suggester.ts#L219-L226',
'_global.search._types.SmoothingModelContainer': '_global/search/_types/suggester.ts#L221-L228',
'_global.search._types.SourceConfig': '_global/search/_types/SourceFilter.ts#L33-L37',
'_global.search._types.SourceConfigParam': '_global/search/_types/SourceFilter.ts#L39-L45',
'_global.search._types.SourceFilter': '_global/search/_types/SourceFilter.ts#L23-L31',
'_global.search._types.StringDistance': '_global/search/_types/suggester.ts#L234-L240',
'_global.search._types.StupidBackoffSmoothingModel': '_global/search/_types/suggester.ts#L228-L230',
'_global.search._types.StringDistance': '_global/search/_types/suggester.ts#L236-L242',
'_global.search._types.StupidBackoffSmoothingModel': '_global/search/_types/suggester.ts#L230-L232',
'_global.search._types.Suggest': '_global/search/_types/suggester.ts#L34-L40',
'_global.search._types.SuggestBase': '_global/search/_types/suggester.ts#L42-L46',
'_global.search._types.SuggestFuzziness': '_global/search/_types/suggester.ts#L133-L139',
'_global.search._types.SuggestSort': '_global/search/_types/suggester.ts#L242-L245',
'_global.search._types.Suggester': '_global/search/_types/suggester.ts#L96-L99',
'_global.search._types.SuggesterBase': '_global/search/_types/suggester.ts#L117-L121',
'_global.search._types.TermSuggest': '_global/search/_types/suggester.ts#L62-L67',
'_global.search._types.TermSuggestOption': '_global/search/_types/suggester.ts#L90-L94',
'_global.search._types.TermSuggester': '_global/search/_types/suggester.ts#L247-L260',
'_global.search._types.SuggestFuzziness': '_global/search/_types/suggester.ts#L135-L141',
'_global.search._types.SuggestSort': '_global/search/_types/suggester.ts#L244-L247',
'_global.search._types.Suggester': '_global/search/_types/suggester.ts#L98-L101',
'_global.search._types.SuggesterBase': '_global/search/_types/suggester.ts#L119-L123',
'_global.search._types.TermSuggest': '_global/search/_types/suggester.ts#L64-L69',
'_global.search._types.TermSuggestOption': '_global/search/_types/suggester.ts#L92-L96',
'_global.search._types.TermSuggester': '_global/search/_types/suggester.ts#L249-L262',
'_global.search._types.TotalHits': '_global/search/_types/hits.ts#L90-L93',
'_global.search._types.TotalHitsRelation': '_global/search/_types/hits.ts#L95-L100',
'_global.search._types.TrackHits': '_global/search/_types/hits.ts#L122-L130',
Expand Down Expand Up @@ -2509,10 +2509,10 @@
if (hash.length > 1) {
hash = hash.substring(1);
}
window.location = "https://github.com/elastic/elasticsearch-specification/tree/135ae054e304239743b5777ad8d41cb2c9091d35/specification/" + (paths[hash] || "");
window.location = "https://github.com/elastic/elasticsearch-specification/tree/1ac08ee3f920b0193b0983146af077cbd4cadc1e/specification/" + (paths[hash] || "");
</script>
</head>
<body>
Please see the <a href="https://github.com/elastic/elasticsearch-specification/tree/135ae054e304239743b5777ad8d41cb2c9091d35/specification/">Elasticsearch API specification</a>.
Please see the <a href="https://github.com/elastic/elasticsearch-specification/tree/1ac08ee3f920b0193b0983146af077cbd4cadc1e/specification/">Elasticsearch API specification</a>.
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,16 @@
import co.elastic.clients.elasticsearch.core.SearchResponse;
import co.elastic.clients.elasticsearch.indices.GetFieldMappingRequest;
import co.elastic.clients.elasticsearch.indices.GetFieldMappingResponse;
import co.elastic.clients.elasticsearch.indices.IndexSettings;
import co.elastic.clients.elasticsearch.model.ModelTestCase;
import co.elastic.clients.json.JsonData;
import co.elastic.clients.json.JsonpDeserializer;
import jakarta.json.stream.JsonParser;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import java.io.InputStream;
import java.io.StringReader;

/**
* Test issues related to the API specifications.
Expand All @@ -42,6 +45,28 @@
*/
public class SpecIssuesTest extends ModelTestCase {

@Test
public void i0328_charFilter() throws Exception {
// Both mappings and mappings_path are optional
String json =
"{\n" +
" \"analysis\": { \n" +
" \"char_filter\": {\n" +
" \"multi_char_filter\": {\n" +
" \"type\": \"mapping\",\n" +
// " \"mappings\": [\n" +
// " \"xyz => xyz\"\n" +
// " ],\n" +
" \"mappings_path\": \"analysis/multi-char-replacement.txt\"\n" +
" }\n" +
" }\n" +
" }\n" +
"}";

IndexSettings.of(b -> b.withJson(new StringReader(json)));
}

@Disabled("Not fixed yet")
@Test
public void i066_multiFieldMapping() throws Exception {
ElasticsearchClient client = ElasticsearchTestServer.global().client();
Expand Down

0 comments on commit 9edea36

Please sign in to comment.