Iv changed to property1, property2

I recently upgraded to new version of squidex. I used to have “iv” field under every node but now it as “property1”, “property2” which is braking almost every thing. How can I resolved this? I need to old way of doing serialization.

OLD :
“name”: {
“iv”: “aaA”
},

Now I see below…

“name”: {

  • “property1”: “string”,
  • “property2”: “string”
    },

How it actually works has not changed, but the OpenAPI spec.

The properties do not contain the actual languages or iv anymore and are just a object / hashmap / dictionary.

Thanks. Is there plan to fix OpenAPI spec ?

It is not a bug.

Problem

The problem is the following.

When you declare a type in OpenAPI like this:

  data: {
    field {
      iv: string
    }
  }
}

You get a lot of types. I just use typescript as an example here:

type DataType = { field: FieldType };

type FieldType = { iv: string };

So for iv properties this kind of works. But when for localized fields you have an issue.

  1. When you add a new language you have to run the code generator again.
  2. In general you just a have a lot of types.

Solution

Therefore the decision was made to keep the field dynamic and generate something like this.

type DataType = { field: Object<string, string> };

For typescript it makes almost no difference, because the syntax to access an value is just the same.

For C# and types language, usually a dictionary is created:

class DataType {
   public Dictionary<string, string> Field { get; set; } 
}

So you can access the field like this.

myContent.Data.Field["iv"];

It still sucks

I am not sure whether I would go the decision with iv again. it is very complicated but now I have to live with it. To make it a little bit easier there is the X-Flatten header: https://docs.squidex.io/02-documentation/concepts/localization#how-to-use-the-api. So you define via header the language you need and all properties are flatten.

Basically this would generate types like this:

type DataType = { field: string; };

Unfortunanetaly it is not possible to communicate this in a nice way with OpenAPI.

Therefore a second documentation is created for the flat representation, e.g.

ok, I managed to get it working. Now I am facing another issue. Since I decorated the class objects with InvariantConverter so response which goes out from my webApi has “iv” nested in each and every node. Is there a way to resolve this? Basically I need to tell MVC WebAPI somehow not use the InvariantConverter when sending back response.

    [JsonConverter(typeof(InvariantConverter))]
    public bool IsActive { get; set; }

Response goes like this… I don’t like it. It should be just “IsActive” : true.

"IsActive ": {
“iv”: true
}

You need to write a custom converter for that.

Or you just use the X-Flatten header: https://docs.squidex.io/02-documentation/concepts/localization#how-to-use-the-api

Great. Thanks. X-Flatten = true works perfectly for response. Do we have something similar for Request as well? I don’t want my user of API to send “iv” properties. I want user to send request like below and desterilize automatically as iv when we send request to Squidex API.

"IsActive ": true

No, but you can use the InvariantWriterConverter for that. It accepts flatten objects as response and writes nested objects.

Do you mean InvariantConverter (as below)? Below requires request to be sent with “iv”. I am not able to locate InvariantWriterConverter. Can you point me to right place or give an example. Thanks for quick reply.

[JsonConverter(typeof(InvariantConverter))]
public bool IsActive { get; set; }

It is also part of the SDK: https://github.com/Squidex/squidex-samples/blob/master/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/InvariantWriteConverter.cs

Thanks found it. I was looking for InvariantWriterConverter. its name is InvariantWriteConverter. Small typo. Thanks.

1 Like

My mistake, sorry for that.