[DECLINED] Squidex.ClientLibrary: Autogenerated classes from Squidex Backend

I’d love to have an export button for all the created schemas. Upon clicking the export button, a ZIP file contaning all the schema representations as C# classes would be downloaded. This would make the sync of schemas in Squidex to the C# wrapper classes so much easier.

Ideally, the namespace that gets inserted into the generated files should be definable in a text field.

This is called Swagger :wink: … you can already create classes for C#.

e.g. this is how the classes for management functions like schema and apps management are created: https://github.com/Squidex/squidex-samples/blob/master/csharp/Squidex.ClientLibrary/CodeGeneration/Program.cs

The problem with content is that due to localization the generated classes look a little bit ugly.

Hi Sebastian,

thanks for the link! We found some time to look at Squidex again and try to evaluate it further :wink:
We managed to create the classes (by cloning the sample project, adjusting the json path to the Swagger Json from the cloud version in the project, and generating the classes. This works fine so far:

In case anyone else is looking for usage information on autogenerated classes, this might be helpful. Currently, there’s no documentation for it:

var squidexClientManger = new SquidexClientManager(
	serviceUrl: "XXXX",
	applicationName: "XXX",
	clientId: "XXX",
	clientSecret: "XXX");

var homeClient = new HomeClient(squidexClientManger.CreateHttpClient());

var foo = homeClient.GetHomeContentAsync(new Guid("XXX-XXX-X-X-d7436382f155"));

Yes, you are right. The autogenerated code is a little bit ugly since it introduces an intermediate wrapper class which is present the swagger defintion. In our case this was the result:

    public partial class HomeDto 
    {
        [Newtonsoft.Json.JsonProperty("service-block", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
        public HomeServiceBlockProperty ServiceBlock { get; set; }
</pre>

<pre>
public partial class HomeServiceBlockProperty 
{
	[Newtonsoft.Json.JsonProperty("iv", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
	public System.Collections.Generic.ICollection<Iv> Iv { get; set; }

With IV being

[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "10.1.4.0 (Newtonsoft.Json v9.0.0.0)")]
    public partial class Iv 
    {
        [Newtonsoft.Json.JsonProperty("headline", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
        public string Headline { get; set; }
    
        [Newtonsoft.Json.JsonProperty("sub-headline", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
        public string SubHeadline { get; set; }
		
		// ...

What I hoped to get was HomeDto with a List<HomeServiceBlockProperty> where HomeServiceBlockProperty contains the fields from Iv.

Given that you are using NSwag to generate the classes, would you be able to provide a more “flattened” JSON representation that we can you for NSwag? =) So in addition to swagger/v1/swagger.json, there could be a swagger/v1/swagger_autogenerate.json which could produce the classes in the desired function. This should be a lot faster than writing code that generates the classes as plain text.

I would like to do it, but so far I have not found a solution for that.

There is a header X-Flatten that can be used to create a flattened version of the content but OpenAPI does not provide a way for different payloads based on parameters.