krakenjs / swaggerize-routes

Swagger document driven route builder.
Other
58 stars 57 forks source link

discriminator support #46

Open toboid opened 9 years ago

toboid commented 9 years ago

The swagger spec allows polymorphism using a discriminator field. I don't think swaggerize-routes has support for this at the moment, can you confirm this is the case?

For example, say I have an api parameter specified as:

    {
        "name": "params",
        "in": "body",
        "required": true,
        "schema": {
            "type": "object",
            "properties": {
                "things": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/BaseThing"
                    }
                }
            }
        }
    }

and definitions specified as:

    {
        "definitions": {
            "BaseThing": {
                "type": "object",
                "required": ["name", "type"],
                "discriminator": "type",
                "properties": {
                    "name": {
                        "type": "string",
                    },
                    "type": {
                        "type": "string",
                    }
                }
            },
            "ChildThing": {
                "type": "object",
                "required": ["extra"],
                "allOf": [
                    {
                        "$ref": "#/definitions/BaseThing"
                    },
                    {
                        "properties": {
                            "extra": {
                                "type": "string",
                            }
                        }
                    }
                ]
            }
        }
    }

Child thing is ignored and so it's fields are disallowed by validation

tlivings commented 9 years ago

Since this is once again an example of Swagger not using standard json-schema, default validation will not support it. This is one of the ongoing problems with Swagger in general.