subeeshcbabu-zz / swagmock

Mock data generator for swagger api
MIT License
173 stars 38 forks source link

Respect allOf when generating mocked responses. #49

Open sammarks opened 6 years ago

sammarks commented 6 years ago

In my usage of this library, I'll run into something similar to the following schema:

{
    "type": "object",
    "required": ["name", "photoUrls"],
    "allOf": [
        {
            "type": "object",
            "properties": {
                "test-one": {
                    "type": "integer",
                    "format": "int64"
                }
            }
        },
        {
            "type": "object",
            "properties": {
                "test-two": {
                    "type": "integer",
                    "format": "int64",
                    "example": 20
                }
            }
        }
    ],
    "properties": {
        "id": {
            "type": "integer",
            "format": "int64"
        },
        "category": {
            "$ref": "#/definitions/Category"
        },
        "name": {
            "type": "string",
            "example": "doggie"
        },
        "photoUrls": {
            "type": "array",
            "xml": {
                "name": "photoUrl",
                "wrapped": true
            },
            "items": {
                "type": "string"
            }
        },
        "tags": {
            "type": "array",
            "minItems": 2,
            "maxItems": 5,
            "xml": {
                "name": "tag",
                "wrapped": true
            },
            "items": {
                "$ref": "#/definitions/Tag"
            }
        },
        "status": {
            "type": "string",
            "description": "pet status in the store",
            "enum": ["available", "pending", "sold"]
        }
    },
    "xml": {
        "name": "Pet"
    }
}

Currently, the library doesn't generate values for test-one or test-two since they're hidden inside the allOf clause of the schema. This PR updates the response mocker to respect the allOf clause and generate values for it as well.

enmand commented 5 years ago

Any change on getting this merged in, and a new NPM release up? 🙏