code: def pydantic_v2_components_schema(
      pydantic_model: type[pydantic.BaseModel],
  ):
      json_schema = jschema.model_json_schema(
          pydantic_model, ref_template=REF_PREFIX + "{model}"
      )
      defs = json_schema.pop("$defs", None)
      components: dict[str, Schema] = {
          pydantic_model.__name__: Schema(**json_schema)
      }
      if defs is not None:
          # NOTE: This is a nested models, hence we will update the definitions
          components.update({k: Schema(**v) for k, v in defs.items()})
      return components
  
file_path: BentoML/src/bentoml/_internal/service/openapi/utils.py
imports: from __future__ import annotations
  import typing
  from functools import lru_cache
  from typing import TYPE_CHECKING
  from bentoml.exceptions import InternalServerError
  from bentoml.exceptions import InvalidArgument
  from bentoml.exceptions import NotFound
  from ...utils import LazyLoader
  from ...utils.pkg import pkg_version_info
  from .specification import Schema
label_desc: Use image node_id 2 for calling a global function with example usage: pydantic_v2_components_schema(pydantic_model) and returns: components