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.

5
  • Looks like this question rather belongs to the swagger homepage / forum / bugtracker. Commented Aug 27, 2015 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? Commented Aug 28, 2015 at 2:31
  • @fehguy can you please point us to some frameworks that will create $ref schemas. Commented Aug 28, 2015 at 3: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. Commented Aug 31, 2015 at 2:47
  • Check this URL, it's not marked as solved, but I think it's fine: link Commented Dec 22, 2016 at 15:47

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.