Skip to content

Commit

Permalink
fix(specs): userData type as 'any' (#2033)
Browse files Browse the repository at this point in the history
  • Loading branch information
aallam authored Sep 21, 2023
1 parent 7a006fd commit b7b6565
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 8 deletions.
1 change: 0 additions & 1 deletion specs/common/schemas/IndexSettings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,6 @@ hitsPerPage:
- Pagination

userData:
type: object
example: {'settingID': 'f2a7b51e3503acc6a39b3784ffb84300','pluginVersion': '1.6.0'}
description: Lets you store custom data in your indices.
default: {}
Expand Down
1 change: 0 additions & 1 deletion specs/search/paths/rules/common/schemas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ consequence:
required:
- objectID
userData:
type: object
description: Custom JSON object that will be appended to the userData array in the response. This object isn't interpreted by the API. It's limited to 1kB of minified JSON.
example: {'settingID': 'f2a7b51e3503acc6a39b3784ffb84300','pluginVersion': '1.6.0'}

Expand Down
5 changes: 4 additions & 1 deletion templates/dart/tests/param_value.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@
{{#isBoolean}}{{{value}}}{{/isBoolean}}
{{#isEnum}}{{{objectName}}}.fromJson("{{value}}"){{/isEnum}}
{{#isArray}}[{{#value}}{{> param_value}},{{/value}}]{{/isArray}}
{{#isFreeFormObject}}{{> param_map}}{{/isFreeFormObject}}
{{#isFreeFormObject}}
{{#isAnyType}}{ {{#value}}{{#entrySet}}'{{{key}}}' : '{{{value}}}',{{/entrySet}}}{{/value}}{{/isAnyType}}
{{^isAnyType}}{{> param_map}}{{/isAnyType}}
{{/isFreeFormObject}}
{{#isObject}}{{> param_object}}{{/isObject}}
3 changes: 1 addition & 2 deletions templates/java/tests/generateGenerics.mustache
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
{{#isArray}}{{#value.0}}<{{#oneOfModel}}{{parentClassName}}{{/oneOfModel}}{{^oneOfModel}}{{objectName}}{{/oneOfModel}}{{> generateGenerics}}>{{/value.0}}{{/isArray}}
{{#isFreeFormObject}}{{^isSimpleObject}}<String, {{#value.0}}{{#isAnyType}}Object{{/isAnyType}}{{^isAnyType}}{{#oneOfModel}}{{parentClassName}}{{/oneOfModel}}{{^oneOfModel}}{{objectName}}{{/oneOfModel}}{{> generateGenerics}}{{/isAnyType}}{{/value.0}}>{{/isSimpleObject}}{{/isFreeFormObject}}
{{#isArray}}{{#value.0}}<{{#oneOfModel}}{{parentClassName}}{{/oneOfModel}}{{^oneOfModel}}{{objectName}}{{/oneOfModel}}{{> generateGenerics}}>{{/value.0}}{{/isArray}}{{#isFreeFormObject}}{{^isSimpleObject}}<String, {{#value.0}}{{#isAnyType}}Object{{/isAnyType}}{{^isAnyType}}{{#oneOfModel}}{{parentClassName}}{{/oneOfModel}}{{^oneOfModel}}{{objectName}}{{/oneOfModel}}{{> generateGenerics}}{{/isAnyType}}{{/value.0}}>{{/isSimpleObject}}{{/isFreeFormObject}}
5 changes: 5 additions & 0 deletions templates/java/tests/generateParams.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,13 @@
}
{{/isObject}}
{{#isFreeFormObject}}
{{#isAnyType}}
Map {{{key}}}{{suffix}} = Map.of({{#value}}{{#entrySet}}"{{{key}}}", "{{{value}}}"{{^-last}},{{/-last}}{{/entrySet}}{{/value}});
{{/isAnyType}}
{{^isAnyType}}
Map{{> forceMapGenerics}} {{{key}}}{{suffix}} = new HashMap<>();
{
{{#value}}{{> generateParams}}{{parent}}{{parentSuffix}}.put("{{{key}}}", {{> maybeConvertOneOf}});{{/value}}
}
{{/isAnyType}}
{{/isFreeFormObject}}
2 changes: 1 addition & 1 deletion templates/kotlin/data_class.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public data class {{classname}}(

override fun deserialize(decoder: Decoder): {{nameInCamelCase}} {
val value = decoder.decodeSerializableValue({{{dataType}}}.serializer())
return {{nameInCamelCase}}.values().firstOrNull { it.value == value }
return {{nameInCamelCase}}.entries.firstOrNull { it.value == value }
?: {{nameInCamelCase}}.{{#allowableValues}}{{#enumVars}}{{#-last}}{{&name}}{{/-last}}{{/enumVars}}{{/allowableValues}}
}

Expand Down
2 changes: 1 addition & 1 deletion templates/kotlin/data_class_field_type.mustache
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{{#isFreeFormObject}}JsonObject{{/isFreeFormObject}}{{^isFreeFormObject}}{{{datatypeWithEnum}}}{{/isFreeFormObject}}
{{#isFreeFormObject}}JsonObject{{/isFreeFormObject}}{{#isAnyType}}JsonElement{{/isAnyType}}{{^isFreeFormObject}}{{^isAnyType}}{{{datatypeWithEnum}}}{{/isAnyType}}{{/isFreeFormObject}}
7 changes: 7 additions & 0 deletions templates/kotlin/tests/param_json_any.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
buildJsonObject {
{{#value}}
{{#entrySet}}
put("{{{key}}}", "{{{value}}}")
{{/entrySet}}
{{/value}}
}
2 changes: 1 addition & 1 deletion templates/kotlin/tests/param_value.mustache
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{{#isNull}}empty(),{{/isNull}}{{#isString}}{{#oneOfModel}}{{{parentClassName}}}.String("{{{value}}}"){{/oneOfModel}}{{^oneOfModel}}"{{{value}}}"{{/oneOfModel}},{{/isString}}{{#isInteger}}{{#oneOfModel}}{{{parentClassName}}}.Number({{{value}}}.toNumberType()){{/oneOfModel}}{{^oneOfModel}}{{{value}}}{{/oneOfModel}},{{/isInteger}}{{#isLong}}{{#oneOfModel}}{{{parentClassName}}}.Number({{{value}}}.toNumberType()){{/oneOfModel}}{{^oneOfModel}}{{{value}}}L{{/oneOfModel}},{{/isLong}}{{#isDouble}}{{#oneOfModel}}{{{parentClassName}}}.Number({{{value}}}){{/oneOfModel}}{{^oneOfModel}}{{{value}}}{{/oneOfModel}},{{/isDouble}}{{#isBoolean}}{{#oneOfModel}}{{{parentClassName}}}.Boolean({{{value}}}){{/oneOfModel}}{{^oneOfModel}}{{{value}}}{{/oneOfModel}},{{/isBoolean}}{{#isEnum}}{{{objectName}}}.values().first { it.value == "{{{value}}}" },{{/isEnum}}{{#isArray}}{{> param_list}},{{/isArray}}{{#isFreeFormObject}}{{#isSimpleObject}}{{> param_json_object}},{{/isSimpleObject}}{{^isSimpleObject}}{{> param_map}},{{/isSimpleObject}}{{/isFreeFormObject}}{{#isObject}}{{> param_object}},{{/isObject}}
{{#isNull}}empty(),{{/isNull}}{{#isString}}{{#oneOfModel}}{{{parentClassName}}}.String("{{{value}}}"){{/oneOfModel}}{{^oneOfModel}}"{{{value}}}"{{/oneOfModel}},{{/isString}}{{#isInteger}}{{#oneOfModel}}{{{parentClassName}}}.Number({{{value}}}.toNumberType()){{/oneOfModel}}{{^oneOfModel}}{{{value}}}{{/oneOfModel}},{{/isInteger}}{{#isLong}}{{#oneOfModel}}{{{parentClassName}}}.Number({{{value}}}.toNumberType()){{/oneOfModel}}{{^oneOfModel}}{{{value}}}L{{/oneOfModel}},{{/isLong}}{{#isDouble}}{{#oneOfModel}}{{{parentClassName}}}.Number({{{value}}}){{/oneOfModel}}{{^oneOfModel}}{{{value}}}{{/oneOfModel}},{{/isDouble}}{{#isBoolean}}{{#oneOfModel}}{{{parentClassName}}}.Boolean({{{value}}}){{/oneOfModel}}{{^oneOfModel}}{{{value}}}{{/oneOfModel}},{{/isBoolean}}{{#isEnum}}{{{objectName}}}.entries.first { it.value == "{{{value}}}" },{{/isEnum}}{{#isArray}}{{> param_list}},{{/isArray}}{{#isObject}}{{> param_object}},{{/isObject}}{{#isFreeFormObject}}{{#isSimpleObject}}{{> param_json_object}},{{/isSimpleObject}}{{^isSimpleObject}}{{#isAnyType}}{{> param_json_any}},{{/isAnyType}}{{^isAnyType}}{{> param_map}},{{/isAnyType}}{{/isSimpleObject}}{{/isFreeFormObject}}
5 changes: 5 additions & 0 deletions templates/php/tests/generateParams.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,10 @@
[{{#value}}{{> generateParams}}{{/value}}],
{{/isObject}}
{{#isFreeFormObject}}
{{#isAnyType}}
[{{#value}}{{#entrySet}}'{{{key}}}' => '{{{value}}}'{{^-last}},{{/-last}}{{/entrySet}}{{/value}}],
{{/isAnyType}}
{{^isAnyType}}
[{{#value}}{{> generateParams}}{{/value}}],
{{/isAnyType}}
{{/isFreeFormObject}}

0 comments on commit b7b6565

Please sign in to comment.