cancel
Showing results for 
Search instead for 
Did you mean: 

How NOT to use Dictionary in generated C# class

New Contributor

How NOT to use Dictionary in generated C# class

When I choose csharp-dotnet2 to generate C# classes on https://editor.swagger.io/,
Dictionary is used as type in the resulting class (see example below). Is there a way to not use Dictionary?

I need C# classes that can be serialized as XML, and Dictionary simply breaks it.

Here is the use case: I will use XSLT to construct an XML document, then deserialize it
into a Swagger object. then I will invoke api (using json).

"attributes": {
"type": "object",
"additionalProperties": {
"type": "object",
"additionalProperties": false
},
"description": "Any attributes associated with the item.",
"nullable": true
}

[DataMember(Name="attributes", EmitDefaultValue=false)]
[JsonProperty(PropertyName = "attributes")]
public Dictionary<string, Object> Attributes { get; set; }

1 REPLY 1
New Contributor

Re: How NOT to use Dictionary in generated C# class

Also, enum appears to be broken. The generated class has no data member for an enum as below:

 

"Product.Api.Models.Enums.ProductStatus": {
"enum": [
"inactive",
"active"
],
"type": "string"
}

New Here?
Join us and watch the welcome video:
Announcements