Creates a /metadata route that returns service metadata.  Also creates
    a /v{api_version}/metadata route, and those routes with ".json"
    appended.  If route is specified, prepends it (or each component) to the
    front of the route.

    Parameters
    ----------
    app : :class:`flask.Flask` instance
        Flask application for the microservice you're adding metadata to.

    route : `None`, `str`, or list of `str`, optional
        The 'route' parameter must be None, a string, or a list of strings.
        If supplied, each string will be prepended to the metadata route.

    Returns
    -------
        Nothing, but decorates app with `/metadata`
        and `/v{app_version}/metadata` routes.

def add_metadata_route(app, route):
    """
    Creates a /metadata route that returns service metadata.  Also creates
    a /v{api_version}/metadata route, and those routes with ".json"
    appended.  If route is specified, prepends it (or each component) to the
    front of the route.

    Parameters
    ----------
    app : :class:`flask.Flask` instance
        Flask application for the microservice you're adding metadata to.

    route : `None`, `str`, or list of `str`, optional
        The 'route' parameter must be None, a string, or a list of strings.
        If supplied, each string will be prepended to the metadata route.

    Returns
    -------
        Nothing, but decorates app with `/metadata`
        and `/v{app_version}/metadata` routes.

    """
    errstr = add_metadata_route.__doc__
    if route is None:
        route = [""]
    if isinstance(route, str):
        route = [route]
    if not isinstance(route, list):
        raise TypeError(errstr)
    if not all(isinstance(item, str) for item in route):
        raise TypeError(errstr)
    api_version = app.config["API_VERSION"]

    for rcomp in route:
        # Make canonical
        rcomp = "/" + rcomp.strip("/")
        if rcomp == "/":
            rcomp = ""
        for rbase in ["/metadata", "/v" + api_version + "/metadata"]:
            for rext in ["", ".json"]:
                rte = rcomp + rbase + rext
                with app.app_context():
                    app.add_url_rule(rte, '_return_metadata', _return_metadata)