Hello Sebastian,
I try to use NSwag to generating API client. But if I use code base on what Squidex do for its own client generator I end up with something like
public partial class TestDto
{
public TestNameProperty Test { get; set; }
}
public partial class TestNameProperty
{
public string En { get; set; }
public string CsCZ { get; set; }
}
Even if NSwag at least base on what I found should support dictionary. Problem is, that Squidex do not generate swagger file “correctly”.
What i got in swagger file generated by squidex.
...
"TestDto": {
"test": {
"description": "test",
"nullable": true,
"$ref": "#/components/schemas/TestNameProperty"
},
..
..
"TestNameProperty": {
"type": "object",
"properties": {
"en": {
"type": "string",
"description": "English",
"nullable": true
},
"cs-CZ": {
"type": "string",
"description": "Czech (Czechia)",
"nullable": true
}
..
}...
I think, based on the docs here https://swagger.io/docs/specification/data-models/dictionaries/ it should use additionalProperties.
Testing example which I try with NSwag studio
{
"openapi": "3.0.0",
"info": {
"title": "Squidex API for test",
"version": "5.5.0.0",
"x-logo": {
"url": "https://test.local/images/logo-white.png",
"backgroundColor": "#3f83df"
}
},
"servers": [
{
"url": "https://test.local/api"
}
],
"paths": {
"/content/test/items/": {
"get": {
"responses": {
"200": {
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"test-dictionary": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"test-compose-object": {
"type": "object",
"additionalProperties": {
"type": "object",
"properties": {
"code": {
"type": "integer"
},
"text": {
"type": "string"
}
...
And output:
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "10.3.9.0 (Newtonsoft.Json v12.0.0.0)")]
public partial class Response
{
[Newtonsoft.Json.JsonProperty("test-dictionary", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public System.Collections.Generic.IDictionary<string, string> TestDictionary { get; set; }
[Newtonsoft.Json.JsonProperty("test-compose-object", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public System.Collections.Generic.IDictionary<string, Anonymous> TestComposeObject { get; set; }
..
}
I open it here because this change also mostly likely introduces BC. And also, I am not sure if it is any reason to current behavior. But I think this could be useful.