import json
import yaml


def prepare(*, spec_str: str, version: str) -> str:
    """
    Prepare a stored spec to be returned to the user.

    De-serializes using JSON, adds version and serializes using YAML.

    Args:
        spec_str: The spec as it is stored.
        version: The version of the spec.

    Returns:
        The spec in a user friendly form.

    """
    spec = json.loads(spec_str)
    info = {"version": version}
    if "info" in spec:
        info = {**info, **spec["info"]}
    components = spec["components"]
    return yaml.dump({"info": info}) + yaml.dump({"components": components})