0
votes

In a class which is driven from IDocumentFilter

I can go through the swagger document and add new properties underneath

SwaggerDocument provides me a definition out of it.

Then I create a new property and assign an array as a Schema such as;

swagDoc.properties["JsonData"].properties.Add("Parent", new Schema() { type = "array" });

It allows the document to have an array property underneath the JsonData document

Then I want to open up a loop to bind child properties under Parent schema such as;

for (int i = 1; i < 10; i++) 
{
    swagDoc.properties["JsonData"].properties["Parent"].properties.Add(
        "Child"+i.ToString(), 
        new Schema() { type = "string" }); 
}      

I am expecting a Json object in the Swagger request input just as;

{
    "JsonData": { 
        "request_rejected_date": "string", 
        "report_delivered_date": "string", 
        "report_cancelled_date": "string", 
        "Parent": [ { 
            "child1": "string", 
            "child2": "string", 
            "child3": "string", 
            "child4": "string", 
            "child5": "string", 
            "child6": "string", 
            "child7": "string",
            "child8": "string", 
            "child9": "string" 
        } ] 
    } 
}

I do not have a defined class to bind, I do generate the model dynamically in Swagger

However, the above code does not produce anything like that - How can I achieve this?

Thank you

1

1 Answers

0
votes

After playing with the object, here is the approach that works out, apparently (:

swagDoc.properties["JsonData"].properties["Parent"].items = new Schema() { properties = new Dictionary<string, Schema>() };

 var schemaChild = new Schema() { description = "Child1", type = "string" };

swagDoc.properties["JsonData"].properties["Parent"].items.properties.Add("child1", schemaChild);