Skip to content
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

[bug]: search fails to deserialize in csharp client after merging #3869 #3934

Closed
1 task
Kalmar99 opened this issue Oct 9, 2024 · 2 comments · Fixed by #3939
Closed
1 task

[bug]: search fails to deserialize in csharp client after merging #3869 #3934

Kalmar99 opened this issue Oct 9, 2024 · 2 comments · Fixed by #3939
Labels
bug Something isn't working

Comments

@Kalmar99
Copy link
Contributor

Kalmar99 commented Oct 9, 2024

Description

in #3869 we added a new field to the RenderingContent model, however it contained some typos in the syntax causing the banners to not be treated like a list.

Response from api:

"widgets": {
   "banners": [
    {
     "image": {
      "urls": [
       {
        "url": "https://komplett.no/marketingmedia/155541/k_wo_q324_macbookstudents_stripe.jpg"
       }
      ],
      "title": "text"
     },
     "link": {
      "url": "https://www.komplett.no/kampanje/40375/test"
     }
    }
   ]
  }

However the model that is genered in the csharp client looks like this:

//
// Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT.
//
using System;
using System.Text;
using System.Linq;
using System.Text.Json.Serialization;
using System.Collections.Generic;
using Algolia.Search.Serializer;
using System.Text.Json;

namespace Algolia.Search.Models.Search;

/// <summary>
/// widgets returned from any rules that are applied to the current search.
/// </summary>
public partial class Widgets
{
  /// <summary>
  /// Initializes a new instance of the Widgets class.
  /// </summary>
  public Widgets()
  {
  }

  /// <summary>
  /// Gets or Sets Banners
  /// </summary>
  [JsonPropertyName("banners")]
  public Banners Banners { get; set; } // this is where the issue is, this should be a list of type banner

  /// <summary>
  /// Returns the string presentation of the object
  /// </summary>
  /// <returns>String presentation of the object</returns>
  public override string ToString()
  {
    StringBuilder sb = new StringBuilder();
    sb.Append("class Widgets {\n");
    sb.Append("  Banners: ").Append(Banners).Append("\n");
    sb.Append("}\n");
    return sb.ToString();
  }

  /// <summary>
  /// Returns the JSON string presentation of the object
  /// </summary>
  /// <returns>JSON string presentation of the object</returns>
  public virtual string ToJson()
  {
    return JsonSerializer.Serialize(this, JsonConfig.Options);
  }

  /// <summary>
  /// Returns true if objects are equal
  /// </summary>
  /// <param name="obj">Object to be compared</param>
  /// <returns>Boolean</returns>
  public override bool Equals(object obj)
  {
    if (obj is not Widgets input)
    {
      return false;
    }

    return
        (Banners == input.Banners || (Banners != null && Banners.Equals(input.Banners)));
  }

  /// <summary>
  /// Gets the hash code
  /// </summary>
  /// <returns>Hash code</returns>
  public override int GetHashCode()
  {
    unchecked // Overflow is fine, just wrap
    {
      int hashCode = 41;
      if (Banners != null)
      {
        hashCode = (hashCode * 59) + Banners.GetHashCode();
      }
      return hashCode;
    }
  }

}

Its the same case for the urls in the BannerImage.cs, it should be a list of strings.

Language

CSharp

Client

Search

Steps to reproduce

  1. Go to the merchandising studio and create a rule that should return a banner for a given query
  2. Execute the query you specified in step 1 through the .NET client
  3. The client will fail to deserialize the json response from the api

Relevant log output

Algolia.Search.Exceptions.AlgoliaException: Error while deserializing response of type Algolia.Search.Models.Search.SearchResponses`1[Komplett.Integrations.SearchEngine.AlgoliaIndexedProductDto]
       ---> System.IO.InvalidDataException: The JSON string cannot be deserialized into any schema defined.                                                                                             
         at Algolia.Search.Models.Search.SearchResultJsonConverter`1.Read(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options)                                                    
         at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value, Boolean& isPopulatedValue)
         at System.Text.Json.Serialization.JsonCollectionConverter`2.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, TCollection& value)
         at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value, Boolean& isPopulatedValue)
         at System.Text.Json.Serialization.Metadata.JsonPropertyInfo`1.ReadJsonAndSetMember(Object obj, ReadStack& state, Utf8JsonReader& reader)
         at System.Text.Json.Serialization.Converters.ObjectDefaultConverter`1.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
         at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value, Boolean& isPopulatedValue)
         at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
         at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.DeserializeAsObject(Utf8JsonReader& reader, ReadStack& state)
         at System.Text.Json.JsonSerializer.ReadFromSpanAsObject(ReadOnlySpan`1 utf8Json, JsonTypeInfo jsonTypeInfo, Nullable`1 actualByteCount)
         at System.Text.Json.JsonSerializer.ReadFromSpanAsObject(ReadOnlySpan`1 json, JsonTypeInfo jsonTypeInfo)
         at System.Text.Json.JsonSerializer.Deserialize(String json, Type returnType, JsonSerializerOptions options)
         at Algolia.Search.Serializer.DefaultJsonSerializer.Deserialize(Stream response, Type type)
         --- End of inner exception stack trace ---
         at Algolia.Search.Serializer.DefaultJsonSerializer.Deserialize(Stream response, Type type)
         at Algolia.Search.Serializer.DefaultJsonSerializer.Deserialize[T](Stream response)
         at Algolia.Search.Transport.HttpTransport.ExecuteRequestAsync[TResult,TData](HttpMethod method, String uri, InternalRequestOptions requestOptions, CancellationToken ct)
         at Algolia.Search.Transport.HttpTransport.ExecuteRequestAsync[TResult](HttpMethod method, String uri, InternalRequestOptions requestOptions, CancellationToken ct)
         at Algolia.Search.Clients.SearchClient.SearchAsync[T](SearchMethodParams searchMethodParams, RequestOptions options, CancellationToken cancellationToken)

Self-service

  • I'd be willing to fix this bug myself.
@Kalmar99 Kalmar99 added the bug Something isn't working label Oct 9, 2024
@Kalmar99
Copy link
Contributor Author

Kalmar99 commented Oct 9, 2024

@millotp this is related to the changes introduced in #3869, i have not been able to set up this repo on my local machine so i cant run this and actually confirm that it works but i think its as simple as altering the syntax slightly on the bannerImageUrl like this:

bannerImageUrl:
description: url for a search banner image.
type: array
items:
type: string
additionalProperties: false

and also update the banners syntax:
banners:
description: banners defined in the merchandising studio for the given search.
type: array
items:
$ref: '#/banner'
additionalProperties: false

but you would have to build the project to confirm that its the only issue

@millotp
Copy link
Collaborator

millotp commented Oct 9, 2024

Hey, the specs in #3939 should match the example you gave in the description :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants