code: def validate_spec(spec):
      
      try:
          import prance
      except ImportError as error:  # re-raise with a more verbose message
          exc_class = type(error)
          raise exc_class(
              "validate_spec requires prance to be installed. "
              "You can install all validation requirements using:\n"
              "    pip install 'apispec[validation]'"
          )
      parser_kwargs = {}
      if spec.openapi_version.version[0] == 3:
          parser_kwargs["backend"] = "openapi-spec-validator"
      try:
          prance.BaseParser(spec_string=json.dumps(spec.to_dict()), **parser_kwargs)
      except prance.ValidationError as err:
          raise exceptions.OpenAPIError(*err.args)
      else:
          return True
docs: Validate the output of an :class:`APISpec` object against the
      OpenAPI specification.
  
      Note: Requires installing apispec with the ``[validation]`` extras.
      ::
  
          pip install 'apispec[validation]'
  
      :raise: apispec.exceptions.OpenAPIError if validation fails.