Skip to content

Commit

Permalink
Allow deserializing path params from JSON
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Farr <[email protected]>
  • Loading branch information
Xtansia committed Nov 13, 2024
1 parent 9beeb7b commit f37df1e
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ public CreateIndexRequest build() {

protected static void setupCreateIndexRequestDeserializer(ObjectDeserializer<CreateIndexRequest.Builder> op) {
op.add(Builder::aliases, JsonpDeserializer.stringMapDeserializer(Alias._DESERIALIZER), "aliases");
op.add(Builder::index, JsonpDeserializer.stringDeserializer(), "index");
op.add(Builder::mappings, TypeMapping._DESERIALIZER, "mappings");
op.add(Builder::settings, IndexSettings._DESERIALIZER, "settings");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,7 @@ protected static void setupPutIndexTemplateRequestDeserializer(ObjectDeserialize
op.add(Builder::dataStream, IndexTemplateDataStreamConfiguration._DESERIALIZER, "data_stream");
op.add(Builder::indexPatterns, JsonpDeserializer.arrayDeserializer(JsonpDeserializer.stringDeserializer()), "index_patterns");
op.add(Builder::meta, JsonpDeserializer.stringMapDeserializer(JsonData._DESERIALIZER), "_meta");
op.add(Builder::name, JsonpDeserializer.stringDeserializer(), "name");
op.add(Builder::priority, JsonpDeserializer.integerDeserializer(), "priority");
op.add(Builder::template, IndexTemplateMapping._DESERIALIZER, "template");
op.add(Builder::version, JsonpDeserializer.longDeserializer(), "version");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,7 @@ protected static void setupSimulateIndexTemplateRequestDeserializer(ObjectDeseri
op.add(Builder::dataStream, IndexTemplateDataStreamConfiguration._DESERIALIZER, "data_stream");
op.add(Builder::indexPatterns, JsonpDeserializer.arrayDeserializer(JsonpDeserializer.stringDeserializer()), "index_patterns");
op.add(Builder::meta, JsonpDeserializer.stringMapDeserializer(JsonData._DESERIALIZER), "_meta");
op.add(Builder::name, JsonpDeserializer.stringDeserializer(), "name");
op.add(Builder::priority, JsonpDeserializer.integerDeserializer(), "priority");
op.add(Builder::template, IndexTemplateMapping._DESERIALIZER, "template");
op.add(Builder::version, JsonpDeserializer.longDeserializer(), "version");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,9 @@ public CloneSnapshotRequest build() {

protected static void setupCloneSnapshotRequestDeserializer(ObjectDeserializer<CloneSnapshotRequest.Builder> op) {
op.add(Builder::indices, JsonpDeserializer.stringDeserializer(), "indices");
op.add(Builder::repository, JsonpDeserializer.stringDeserializer(), "repository");
op.add(Builder::snapshot, JsonpDeserializer.stringDeserializer(), "snapshot");
op.add(Builder::targetSnapshot, JsonpDeserializer.stringDeserializer(), "target_snapshot");
}

// ---------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,18 @@ public void setShortcutProperty(String shortcutProperty) {
this.shortcutProperty = shortcutProperty;
}

public Collection<Field> getFieldsToSerialize() {
return getBodyFields();
}

public boolean hasFieldsToSerialize() {
return !bodyFields.isEmpty() || additionalPropertiesField != null;
}

public Collection<Field> getFieldsToDeserialize() {
return getBodyFields();
}

public Collection<ReferencingDiscriminatedUnion> getReferencingDiscriminatedUnions() {
return getIncomingReference(ReferenceKind.UnionVariant).stream()
.map(s -> (TaggedUnionShape) s)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ public boolean canBeSingleton() {
return !hasRequestBody() && !hasQueryParams() && hasSinglePath() && !getFirstPath().hasParams();
}

@Override
public Collection<Field> getFieldsToDeserialize() {
var fields = new TreeMap<>(bodyFields);
fields.putAll(pathParams);
return fields.values();
}

public boolean hasRequestBody() {
return !getBodyFields().isEmpty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
{{#extendsOtherShape}}
setup{{extendsType.name}}Deserializer(op{{#extendsType.typeParams}}, {{>Type/deserializer}}{{/extendsType.typeParams}});
{{/extendsOtherShape}}
{{#bodyFields}}
{{#fieldsToDeserialize}}
op.add({{#extendedByOtherShape}}Abstract{{/extendedByOtherShape}}Builder::{{name}}, {{#type}}{{>Type/deserializer}}{{/type}}, {{#quoted}}{{wireName}}{{/quoted}}{{#aliases}}, {{#quoted}}{{.}}{{/quoted}}{{/aliases}});
{{/bodyFields}}
{{/fieldsToDeserialize}}
{{#additionalPropertiesField}}
op.setUnknownFieldHandler((builder, name, parser, mapper) -> {
if (builder.{{name}} == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
{{#additionalPropertiesField}}
{{#type.directSerializer}}this.{{name}}{{/type.directSerializer}}
{{/additionalPropertiesField}}
{{#bodyFields}}
{{#fieldsToSerialize}}
{{^required}}
if ({{#type.isDefined}}this.{{name}}{{/type.isDefined}}) {
{{/required}}
Expand All @@ -32,5 +32,5 @@
{{^-last}}

{{/-last}}
{{/bodyFields}}
{{/fieldsToSerialize}}
}

0 comments on commit f37df1e

Please sign in to comment.