Turn a swagger endpoint schema into an equivalent one to validate our
    request.

    As an example, this would take this swagger schema:
        {
            "paramType": "query",
            "name": "query",
            "description": "Location to query",
            "type": "string",
            "required": true
        }
    To this jsonschema:
        {
            "type": "object",
            "additionalProperties": "False",
            "properties:": {
                "description": "Location to query",
                "type": "string",
                "required": true
            }
        }
    Which we can then validate against a JSON object we construct from the
    pyramid request.

def build_param_schema(schema, param_type):
    """Turn a swagger endpoint schema into an equivalent one to validate our
    request.

    As an example, this would take this swagger schema:
        {
            "paramType": "query",
            "name": "query",
            "description": "Location to query",
            "type": "string",
            "required": true
        }
    To this jsonschema:
        {
            "type": "object",
            "additionalProperties": "False",
            "properties:": {
                "description": "Location to query",
                "type": "string",
                "required": true
            }
        }
    Which we can then validate against a JSON object we construct from the
    pyramid request.
    """
    properties = filter_params_by_type(schema, param_type)
    if not properties:
        return

    # Generate a jsonschema that describes the set of all query parameters. We
    # can then validate this against dict(request.params).
    return {
        'type': 'object',
        'properties': dict((p['name'], p) for p in properties),
        # Allow extra headers. Most HTTP requests will have headers which
        # are outside the scope of the spec (like `Host`, or `User-Agent`)
        'additionalProperties': param_type == 'header',
    }