import copy


def _convert_jsonschema_to_list_of_parameters(obj, in_="query"):
    """
    Swagger is only _based_ on JSONSchema. Query string and header parameters
    are represented as list, not as an object. This converts a JSONSchema
    object (as return by the converters) to a list of parameters suitable for
    swagger.

    :param dict obj:
    :param str in_: 'query' or 'header'
    :rtype: list[dict]
    """
    parameters = []

    assert obj["type"] == "object"

    required = obj.get("required", [])

    for name, prop in sorted(obj["properties"].items(), key=lambda i: i[0]):
        parameter = copy.deepcopy(prop)
        parameter["required"] = name in required
        parameter["in"] = in_
        parameter["name"] = name
        parameters.append(parameter)

    return parameters