4

We are using Swagger 2.0 for our documentation. We are Pro-grammatically creating swagger 2.0 spec straight out our data design documents.

Our Model is very complex and nested. I would like to understand can we define nested array objects defined inline.

for e.g :

{
    "definitions": {
        "user": {
            "type": "object",
            "required": ["name"],
            "properties": {
                "name": {
                    "type": "string"
                },
                "address": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "properties": {
                            "type": {
                                "type": "string",
                                "enum": ["home",
                                "office"]
                            },
                            "line1": {
                                "type": "string"
                            }
                        },
                        "Person": {
                            "type": "object",
                            "properties": {
                                "name": {
                                    "type": "string"
                                }
                            }
                        }
                    }
                }
            }
        }
    }
} 

We have many cases where we encounter this in our model and defining a #ref is not an option that we want to consider at this time. We need this to handled inline.

As per the following post : https://github.com/swagger-api/swagger-editor/issues/603#evenenter code heret-391465196 looks like its not supported to handle nested array objects defined inline.

Since lot of big enterprise's have a very complex data model we would like to have this this feature to be supported in swagger 2.0 spec.

Is there any thought on this feature to be added.

  • Looks like this question rather belongs to the swagger homepage / forum / bugtracker. – m02ph3u5 Aug 27 '15 at 18:43
  • Many frameworks will create `$ref` schemas for you automatically. Can you share more of why that's not possible from a modeling point of view? – fehguy Aug 28 '15 at 02:31
  • @fehguy can you please point us to some frameworks that will create $ref schemas. – Darshan Shivashankar Aug 28 '15 at 03:11
  • Well, the swagger-supported `swagger-jaxrs` will do this. If you have a property which is a complex type, the `$ref` will automatically be created. – fehguy Aug 31 '15 at 02:47
  • Check this URL, it's not marked as solved, but I think it's fine: [link](http://stackoverflow.com/questions/19585581/how-to-describe-a-model-in-swagger-for-an-array-with-simple-objects) – Elbassel Dec 22 '16 at 15:47

1 Answers1

3

You document is just invalid and this is not about nested arrays: the property Person is not allowed in a Swagger 2.0 schema inside items.

The only allowed properties in a schema are: $ref, format, title, description, default, multipleOf, maximum, exclusiveMaximum, minimum, exclusiveMinimum, maxLength, minLength, pattern, maxItems, minItems, uniqueItems, maxProperties, minProperties, required, enum, additionalProperties, type, items, allOf, properties, discriminator, readOnly, xml, externalDocs, example.

dolmen
  • 8,126
  • 5
  • 40
  • 42