Hi Team,

        Could you please help How a Array of Json with different type to be 
mapped in Swagger schema model.
All my below usecases relates to "items' property of array schema object. 
Ideally JSON schema supports Array of Schema. But Swagger not supporting 
this. 
Could you help us in understanding why is it so and help to resolve my two 
cases.

Below is my json for which i need to write schema which adhere to swagger 
schema:

{
    "Address": [
        {
            "DoorNo": "122-A",
            "Street": "Dalal Street",
            "Town": "DA",
            "Country": "CA",
            "IsBillingAddress": "Y"
        },
        {
            "DoorNo": "57/56",
            "Street": "Lake View Street",
            "Town": "DA",
            "Country": "CA",
            "IsShippingAddress": "N"
        }
    ]
}

Both elements at position 1 and 2 different though it looks more or less 
same. In this case, when I tried to write schema as below.

{
    "definitions": {
        "Address": {
            "type": "array",
            "items": {
                "type": "object",
                "properties": {
                    "DoorNo": {
                        "type": "string"
                    },
                    "Street": {
                        "type": "string"
                    },
                    "Town": {
                        "type": "string"
                    },
                    "Country": {
                        "type": "string"
                    },
                    "IsBillingAddress": {
                        "type": "string"
                    }
                }
            }
        }
    }
}
I mentioned schema for first. How to mention for second element.

But I want to mention it contains two schema. 

second usecase : 

To write schems for the json below

{
    "OrderNumber":"IJKG8709230",
    "Components":[
        {
            "Name":"Voice",
            "Phone":7868794
        },
        {
            "Name":"Data",
            "IP":"87.22.11.222",
            "DataPlan":"500GB/300GB"
        }
    ]
}

Always first element is of type 'Voice' and second element is of type 
"Data". If Voice JSON is empty, then i used to get empty json like 
{
    "OrderNumber":"IJKG8709230",
    "Components":[
        {
        },
        {
            "Name":"Data",
            "IP":"87.22.11.222",
            "DataPlan":"500GB/300GB"
        }
    ]
}

I end up writing schema like this. 
{
    "definitions": {
        "Order": {
            "type": "object",
            "properties": {
                "OrderNumber": {
                    "type": "string"
                },
                "Components": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "properties":{
                            "Name":{
                                "type": "string"
                            },
                            "PhoneNumber":{
                                "type":"number"
                            }
                        }
                    }
                }
            }
        }
    }
}





-- 
You received this message because you are subscribed to the Google Groups 
"Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to