Skip to content

Commit

Permalink
fix(specs): highlight result map definition
Browse files Browse the repository at this point in the history
  • Loading branch information
shortcuts committed Dec 1, 2023
1 parent 64da244 commit c68e864
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,6 @@ public String toEnumVarName(String value, String datatype) {

/** Convert a Seq type to a valid class name. */
private String typeToName(String content) {
return content.trim().replace("<", "Of").replace(">", "");
return content.trim().replace("<", "Of").replace(">", "").replace(",", "").replace(" ", "");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public void processOpts() {

/** Convert a Seq type to a valid class name. */
private String typeToName(String content) {
return content.trim().replace("<", "Of").replace(">", "");
return content.trim().replace("<", "Of").replace(">", "").replace(", ", "").replace(".", "");
}

private void hostForKotlin() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void processOpts() {

/** Convert a Seq type to a valid class name. */
private String typeToName(String content) {
return content.trim().replace("[", "Of").replace("]", "");
return content.trim().replace("[", "Of").replace("]", "").replace(".", "").replace(", ", "");
}

@Override
Expand Down
44 changes: 28 additions & 16 deletions specs/search/common/schemas/Hit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ hit:
objectID:
$ref: '../../../common/parameters.yml#/objectID'
_highlightResult:
$ref: '#/highlightResultMap'
$ref: '#/highlightResult'
_snippetResult:
$ref: '#/snippetResultMap'
$ref: '#/snippetResult'
_rankingInfo:
$ref: '#/rankingInfo'
_distinctSeqID:
Expand All @@ -21,10 +21,25 @@ hit:
_distinctSeqID:
type: integer

highlightResultOptionMap:
type: object
description: Show highlighted section and words matched on a query.
additionalProperties:
$ref: '#/highlightResultOption'

highlightResultOptionOneOf:
oneOf:
- $ref: '#/highlightResultOption'
- $ref: '#/highlightResultOptionMap'

highlightResultOption:
type: object
description: Show highlighted section and words matched on a query.
additionalProperties: false
x-discriminator-fields:
- matchLevel
- value
- matchedWords
properties:
value:
$ref: '#/highlightedValue'
Expand All @@ -45,17 +60,10 @@ highlightResultOption:
- matchedWords

highlightResult:
oneOf:
- $ref: '#/highlightResultOption'
- type: array
items:
$ref: '#/highlightResultOption'

highlightResultMap:
type: object
description: Show highlighted section and words matched on a query.
additionalProperties:
$ref: '#/highlightResult'
$ref: '#/highlightResultOptionOneOf'

snippetResultOption:
type: object
Expand All @@ -70,18 +78,22 @@ snippetResultOption:
- value
- matchLevel

snippetResult:
snippetResultOptionMap:
type: object
description: Snippeted attributes show parts of the matched attributes. Only returned when attributesToSnippet is non-empty.
additionalProperties:
$ref: '#/snippetResultOption'

snippetResultOptionOneOf:
oneOf:
- $ref: '#/snippetResultOption'
- type: array
items:
$ref: '#/snippetResultOption'
- $ref: '#/snippetResultOptionMap'

snippetResultMap:
snippetResult:
type: object
description: Snippeted attributes show parts of the matched attributes. Only returned when attributesToSnippet is non-empty.
additionalProperties:
$ref: '#/snippetResult'
$ref: '#/snippetResultOptionOneOf'

rankingInfo:
type: object
Expand Down
4 changes: 2 additions & 2 deletions specs/search/paths/multiclusters/searchUserIds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ post:
type: object
properties:
userID:
$ref: '../../common/schemas/Hit.yml#/highlightResultMap'
$ref: '../../common/schemas/Hit.yml#/highlightResult'
clusterName:
$ref: '../../common/schemas/Hit.yml#/highlightResultMap'
$ref: '../../common/schemas/Hit.yml#/highlightResult'
required:
- userID
- clusterName
Expand Down
12 changes: 8 additions & 4 deletions templates/java/oneof_interface.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ public interface {{classname}} {
JsonNode tree = jp.readValueAsTree();
{{#composedSchemas.oneOf}}
// deserialize {{{datatypeWithEnum}}}
if (tree.{{#isModel}}isObject(){{#vendorExtensions.x-discriminator-fields}} && tree.has("{{{.}}}"){{/vendorExtensions.x-discriminator-fields}}{{/isModel}}{{#isEnumRef}}isTextual(){{/isEnumRef}}{{#isArray}}isArray(){{/isArray}}{{#isInteger}}isInt(){{/isInteger}}{{#isLong}}isLong(){{/isLong}}{{#isDouble}}isDouble(){{/isDouble}}{{#isBoolean}}isBoolean(){{/isBoolean}}{{#isString}}isTextual(){{/isString}}){

if (tree.{{#isMap}}isObject(){{/isMap}}{{#isModel}}isObject(){{#vendorExtensions.x-discriminator-fields}} && tree.has("{{{.}}}"){{/vendorExtensions.x-discriminator-fields}}{{/isModel}}{{#isEnumRef}}isTextual(){{/isEnumRef}}{{#isArray}}isArray(){{/isArray}}{{#isInteger}}isInt(){{/isInteger}}{{#isLong}}isLong(){{/isLong}}{{#isDouble}}isDouble(){{/isDouble}}{{#isBoolean}}isBoolean(){{/isBoolean}}{{#isString}}isTextual(){{/isString}}){
try(JsonParser parser = tree.traverse(jp.getCodec())) {
{{#isModel}}
return parser.readValueAs({{{datatypeWithEnum}}}.class);
Expand All @@ -94,10 +95,14 @@ public interface {{classname}} {
{{{datatypeWithEnum}}} value = parser.readValueAs(new TypeReference<{{{datatypeWithEnum}}}>(){});
return new {{classname}}.{{#lambda.type-to-name}}{{{datatypeWithEnum}}}{{/lambda.type-to-name}}Wrapper(value);
{{/isArray}}
{{^isModel}}{{^isEnumRef}}{{^isArray}}
{{^isModel}}{{^isEnumRef}}{{^isArray}}{{^isMap}}
{{{datatypeWithEnum}}} value = parser.readValueAs({{{datatypeWithEnum}}}.class);
return new {{classname}}.{{{datatypeWithEnum}}}Wrapper(value);
{{/isArray}}{{/isEnumRef}}{{/isModel}}
{{/isMap}}{{/isArray}}{{/isEnumRef}}{{/isModel}}
{{#isMap}}
{{{datatypeWithEnum}}} value = parser.readValueAs({{#lambda.type-to-name}}{{{datatypeWithEnum}}}{{/lambda.type-to-name}}.class);
return new {{classname}}.{{#lambda.type-to-name}}{{{datatypeWithEnum}}}{{/lambda.type-to-name}}Wrapper(value);
{{/isMap}}
} catch (Exception e) {
// deserialization failed, continue
LOGGER.finest("Failed to deserialize oneOf {{{datatypeWithEnum}}} (error: " + e.getMessage() + ") (type: {{{datatypeWithEnum}}})");
Expand All @@ -121,4 +126,3 @@ public interface {{classname}} {
}
}
}

5 changes: 4 additions & 1 deletion templates/kotlin/oneof_interface.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ internal class {{classname}}Serializer : JsonContentPolymorphicSerializer<{{clas
{{#isModel}}
element is JsonObject{{#vendorExtensions.x-discriminator-fields}} && element.containsKey("{{{.}}}"){{/vendorExtensions.x-discriminator-fields}} -> {{{datatypeWithEnum}}}.serializer()
{{/isModel}}
{{#isMap}}
element is JsonObject -> {{#lambda.type-to-name}}{{{datatypeWithEnum}}}{{/lambda.type-to-name}}Value.serializer()
{{/isMap}}
{{#isArray}}
element{{#items}}{{#isModel}}.isJsonArrayOfObjects{{/isModel}}{{#isPrimitiveType}}.isJsonArrayOfPrimitives{{/isPrimitiveType}}{{#isModel}}{{#isPrimitiveType}} is JsonArray{{/isPrimitiveType}}{{/isModel}}{{/items}} -> {{{classname}}}.{{#lambda.type-to-name}}{{{datatypeWithEnum}}}{{/lambda.type-to-name}}Value.serializer()
{{/isArray}}
Expand All @@ -94,4 +97,4 @@ internal class {{classname}}Serializer : JsonContentPolymorphicSerializer<{{clas
else -> throw AlgoliaClientException("Failed to deserialize json element: $element")
}
}
}
}
11 changes: 7 additions & 4 deletions templates/scala/oneof_trait.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ object {{classname}} {
{{#composedSchemas.oneOf}}
{{^isModel}}
{{^isEnumRef}}
case class {{#isArray}}{{#lambda.type-to-name}}{{{datatypeWithEnum}}}{{/lambda.type-to-name}}{{/isArray}}{{^isArray}}{{{datatypeWithEnum}}}Value{{/isArray}}(value: {{{datatypeWithEnum}}}) extends {{classname}}
case class {{#isMap}}{{#lambda.type-to-name}}{{{datatypeWithEnum}}}{{/lambda.type-to-name}}{{/isMap}}{{#isArray}}{{#lambda.type-to-name}}{{{datatypeWithEnum}}}{{/lambda.type-to-name}}{{/isArray}}{{^isMap}}{{^isArray}}{{{datatypeWithEnum}}}Value{{/isArray}}{{/isMap}}(value: {{{datatypeWithEnum}}}) extends {{classname}}
{{/isEnumRef}}
{{/isModel}}
{{/composedSchemas.oneOf}}
Expand All @@ -38,7 +38,7 @@ object {{classname}} {
{{^isModel}}
{{^isEnumRef}}
def apply(value: {{{datatypeWithEnum}}}){{#isArray}}(implicit ev: {{classname}}Evidence.{{#lambda.type-to-name}}{{{datatypeWithEnum}}}{{/lambda.type-to-name}}Evidence.type){{/isArray}}: {{classname}} = {
{{classname}}.{{#isArray}}{{#lambda.type-to-name}}{{{datatypeWithEnum}}}{{/lambda.type-to-name}}{{/isArray}}{{^isArray}}{{{datatypeWithEnum}}}Value{{/isArray}}(value)
{{classname}}.{{#isMap}}{{#lambda.type-to-name}}{{{datatypeWithEnum}}}{{/lambda.type-to-name}}{{/isMap}}{{#isArray}}{{#lambda.type-to-name}}{{{datatypeWithEnum}}}{{/lambda.type-to-name}}{{/isArray}}{{^isMap}}{{^isArray}}{{{datatypeWithEnum}}}Value{{/isArray}}{{/isMap}}(value)
}
{{/isEnumRef}}
{{/isModel}}
Expand All @@ -50,7 +50,7 @@ object {{classname}} {
{{^isModel}}
{{^isEnumRef}}
def apply(value: {{{datatypeWithEnum}}}): {{classname}} = {
{{classname}}.{{#isArray}}{{#lambda.type-to-name}}{{{datatypeWithEnum}}}{{/lambda.type-to-name}}{{/isArray}}{{^isArray}}{{{datatypeWithEnum}}}Value{{/isArray}}(value)
{{classname}}.{{#isMap}}{{#lambda.type-to-name}}{{{datatypeWithEnum}}}{{/lambda.type-to-name}}{{/isMap}}{{#isArray}}{{#lambda.type-to-name}}{{{datatypeWithEnum}}}{{/lambda.type-to-name}}{{/isArray}}{{^isMap}}{{^isArray}}{{{datatypeWithEnum}}}Value{{/isArray}}{{/isMap}}(value)
}
{{/isEnumRef}}
{{/isModel}}
Expand All @@ -67,6 +67,9 @@ object {{classname}}Serializer extends Serializer[{{classname}}] {
{{#isModel}}
case value: JObject {{#vendorExtensions.x-discriminator-fields}}{{#-first}}if{{/-first}}{{^-first}}&&{{/-first}} value.obj.contains("{{{.}}}"){{/vendorExtensions.x-discriminator-fields}} => Extraction.extract[{{{datatypeWithEnum}}}](value)
{{/isModel}}
{{#isMap}}
case value: JObject => Extraction.extract[{{{datatypeWithEnum}}}](value)
{{/isMap}}
{{#isEnumRef}}
case value: JString => Extraction.extract[{{{datatypeWithEnum}}}](value)
{{/isEnumRef}}
Expand Down Expand Up @@ -96,4 +99,4 @@ object {{classname}}Serializer extends Serializer[{{classname}}] {
override def serialize(implicit format: Formats): PartialFunction[Any, JValue] = {
case value => Extraction.decompose(value)(format - this)
}
}
}

0 comments on commit c68e864

Please sign in to comment.