{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://cdn.posit.co/publisher/schemas/posit-publishing-schema-v3.json",
  "type": "object",
  "description": "Posit Publishing Configuration",
  "$defs": {
    "config_connect": {
      "description": "Extensions to the base schema for Posit Connect deployments.",
      "properties": {
        "has_parameters": {
          "type": "boolean",
          "description": "True if this is a report that accepts parameters.",
          "default": false
        },
        "python": {
          "type": "object",
          "additionalProperties": false,
          "description": "Python language and dependencies.",
          "properties": {
            "version": {},
            "package_file": {
              "type": "string",
              "description": "File containing package dependencies. When set to the default 'requirements.txt' and the file does not exist, requirements will be generated from pylock.toml, uv.lock, or pyproject.toml if available.",
              "default": "requirements.txt",
              "examples": ["requirements.txt"]
            },
            "package_manager": {
              "type": "string",
              "default": "pip",
              "description": "Package manager that will install the dependencies. If package-manager is none, dependencies are assumed to be pre-installed on the server. The default is 'pip'.",
              "examples": ["pip", "conda", "pipenv", "poetry", "none"]
            },
            "requires_python": {
              "type": "string",
              "default": "",
              "description": "Python interpreter version, in PEP 440 format, required to run the content. If not specified it will be detected from the one in use.",
              "examples": [">3.8", "<3.9", "==3.5"]
            }
          }
        },
        "r": {
          "type": "object",
          "additionalProperties": false,
          "description": "R language and dependencies.",
          "properties": {
            "version": {},
            "package_file": {
              "type": "string",
              "default": "renv.lock",
              "description": "File containing package dependencies. The file must exist and be listed under 'files'.",
              "examples": ["renv.lock"]
            },
            "package_manager": {
              "type": "string",
              "default": "renv",
              "description": "Package manager that will install the dependencies. If package-manager is none, dependencies will be assumed to be pre-installed on the server.",
              "examples": ["renv", "none"]
            },
            "requires_r": {
              "type": "string",
              "default": "",
              "description": "R interpreter version, required to run the content. If not specified it will be detected from the one in use.",
              "examples": [">3.8", "<4.3", ">=3.5.0"]
            },
            "packages_from_library": {
              "type": "boolean",
              "default": false,
              "description": "When true, generate manifest packages from the local renv library (legacy behavior). When false (default), read packages from renv.lock."
            }
          }
        },
        "jupyter": {
          "type": "object",
          "additionalProperties": false,
          "description": "Additional rendering options for Jupyter Notebooks.",
          "properties": {
            "hide_all_input": {
              "type": "boolean",
              "description": "Hide all input cells when rendering output."
            },
            "hide_tagged_input": {
              "type": "boolean",
              "description": "Hide input code cells with the 'hide_input' tag when rendering output."
            }
          }
        },
        "quarto": {
          "type": "object",
          "additionalProperties": false,
          "description": "Quarto version required to run the content.",
          "required": ["version"],
          "properties": {
            "version": {
              "type": "string",
              "description": "Quarto version. The server must have a similar Quarto version in order to run the content.",
              "examples": ["1.4"]
            },
            "engines": {
              "type": "array",
              "description": "List of Quarto engines required for this content.",
              "items": {
                "type": "string",
                "enum": ["knitr", "jupyter", "markdown"],
                "examples": ["knitr", "jupyter", "markdown"]
              }
            }
          }
        },
        "connect": {
          "type": "object",
          "additionalProperties": false,
          "description": "Setting specific to Posit Connect deployments.",
          "properties": {
            "runtime": {},
            "kubernetes": {
              "type": "object",
              "additionalProperties": false,
              "description": "Settings used with Posit Connect's off-host execution feature, where content is run in Kubernetes.",
              "properties": {
                "amd_gpu_limit": {
                  "type": "integer",
                  "minimum": 0,
                  "description": "The number of AMD GPUs that will be allocated by Kubernetes to run this content.",
                  "examples": [0]
                },
                "cpu_limit": {
                  "type": "number",
                  "minimum": 0,
                  "description": "The maximum amount of compute power this content will be allowed to consume when executing or rendering, expressed in CPU Units, where 1.0 unit is equivalent to 1 physical or virtual core. Fractional values are allowed. If the process tries to use more CPU than allowed, it will be throttled.",
                  "examples": [1]
                },
                "cpu_request": {
                  "type": "number",
                  "minimum": 0,
                  "description": "The minimum amount of compute power this content needs when executing virtual core. Fractional values are allowed.",
                  "examples": [0.5]
                },
                "default_image_name": {
                  "type": "string",
                  "pattern": "^[^\t\n\b\f\r ]*$",
                  "description": "Name of the target container image.",
                  "examples": ["posit/connect-runtime-python3.11-r4.3"]
                },
                "memory_limit": {
                  "type": "integer",
                  "minimum": 0,
                  "description": "The maximum amount of RAM this content will be allowed to consume when executing or rendering, expressed in bytes. If the process tries to use more memory than allowed, it will be terminated",
                  "examples": [100000000]
                },
                "memory_request": {
                  "type": "integer",
                  "minimum": 0,
                  "description": "The minimum amount of RAM this content needs when executing or rendering, expressed in bytes.",
                  "examples": [20000000]
                },
                "nvidia_gpu_limit": {
                  "type": "integer",
                  "minimum": 0,
                  "description": "The number of NVIDIA GPUs that will be allocated by Kubernetes to run this content.",
                  "examples": [0]
                },
                "service_account_name": {
                  "type": "string",
                  "pattern": "^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$",
                  "description": "The name of the Kubernetes service account that is used to run this content. It must adhere to Kubernetes service account naming rules. You must be an administrator to set this value.",
                  "examples": ["posit-connect-content"]
                },
                "default_r_environment_management": {
                  "type": "boolean",
                  "description": "Enables or disables R environment management. When false, Posit Connect will not install R packages and instead assume that all required packages are present in the container image.",
                  "examples": [true]
                },
                "default_py_environment_management": {
                  "type": "boolean",
                  "description": "Enables or disables Python environment management. When false, Posit Connect will not install Python packages and instead assume that all required packages are present in the container image.",
                  "examples": [true]
                }
              }
            },
            "access": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "run_as": {
                  "type": "string",
                  "description": "The system username under which the content should be run. Must be an existing user in the allowed group. You must be an administrator to set this value.",
                  "examples": ["rstudio-connect"]
                },
                "run_as_current_user": {
                  "type": "boolean",
                  "default": false,
                  "description": "For application content types, run a separate process under the user account of each visiting user under that user's server account. Requires PAM authentication on the Posit Connect server. You must be an administrator to set this value."
                }
              }
            }
          }
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "type": {
                "enum": ["quarto-shiny", "quarto", "quarto-static"]
              }
            },
            "required": ["type"]
          },
          "then": {
            "required": ["quarto"]
          }
        }
      ]
    },
    "config_connect_cloud": {
      "description": "Extensions to the base schema for Posit Connect Cloud deployments.",
      "properties": {
        "product_type": {
          "type": "string",
          "description": "Product type indicating this is a Posit Connect Cloud configuration.",
          "enum": ["connect_cloud"]
        },
        "python": {
          "type": "object",
          "additionalProperties": false,
          "description": "Python language and dependencies.",
          "properties": {
            "version": {}
          }
        },
        "r": {
          "type": "object",
          "additionalProperties": false,
          "description": "R language and dependencies.",
          "properties": {
            "version": {}
          }
        },
        "connect_cloud": {
          "type": "object",
          "additionalProperties": false,
          "description": "Setting specific to Posit Connect Cloud deployments.",
          "properties": {
            "python": {
              "type": "object",
              "additionalProperties": false,
              "description": "Python language and dependencies.",
              "properties": {
                "version": {}
              }
            },
            "r": {
              "type": "object",
              "additionalProperties": false,
              "description": "R language and dependencies.",
              "properties": {
                "version": {}
              }
            },
            "vanity_name": {
              "type": "string",
              "pattern": "^[a-z0-9]([-a-z0-9]*[a-z0-9])$",
              "description": "The custom component of the vanity URL. If your account name is 'my-account' and this value is 'vanity', the vanity URL will be https://my-account-vanity.share.connect.posit.cloud.",
              "examples": ["sales-report"]
            },
            "access_control": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "public_access": {
                  "type": "boolean",
                  "description": "Whether or not the content is publicly accessible."
                },
                "organization_access": {
                  "type": "string",
                  "enum": ["disabled", "viewer", "editor"],
                  "default": "disabled",
                  "description": "The default level of access for account members within an organizational account."
                }
              }
            }
          }
        },
        "connect": {
          "additionalProperties": false,
          "properties": {
            "runtime": {}
          }
        }
      }
    }
  },
  "unevaluatedProperties": false,
  "properties": {
    "product_type": {
      "type": "string",
      "description": "The server type that this content will be deployed to.",
      "enum": ["connect", "snowflake", "connect_cloud"],
      "default": "connect"
    },
    "comments": {
      "type": "array",
      "items": {
        "type": ["string"]
      },
      "description": "Comments are allowed at the top of the configuration file, with a leading '#' character."
    },
    "$schema": {
      "type": "string",
      "format": "url",
      "description": "URL of the json-schema definition for this file. Must be 'https://cdn.posit.co/publisher/schemas/posit-publishing-schema-v3.json'.",
      "examples": [
        "https://cdn.posit.co/publisher/schemas/posit-publishing-schema-v3.json"
      ]
    },
    "type": {
      "type": "string",
      "description": "Indicates the type of content being deployed. Valid values are: html, jupyter-notebook, jupyter-voila, nodejs, python-bokeh, python-dash, python-fastapi, python-flask, python-gradio, python-panel, python-shiny, python-streamlit, quarto-shiny, quarto-static, r-plumber, r-shiny, rmd-shiny, rmd",
      "enum": [
        "html",
        "jupyter-notebook",
        "jupyter-voila",
        "nodejs",
        "python-bokeh",
        "python-dash",
        "python-fastapi",
        "python-flask",
        "python-gradio",
        "python-panel",
        "python-shiny",
        "python-streamlit",
        "quarto-shiny",
        "quarto",
        "quarto-static",
        "r-plumber",
        "r-shiny",
        "rmd-shiny",
        "rmd",
        "unknown"
      ],
      "examples": ["quarto-static"]
    },
    "entrypoint": {
      "type": "string",
      "description": "Name of the primary file containing the content. For Python flask, dash, fastapi, and python-shiny projects, this specifies the object within the file in module:object format. See the documentation at https://docs.posit.co/connect/user/publishing-cli-apps/#publishing-rsconnect-python-entrypoint.",
      "examples": ["app.py", "report.qmd"]
    },
    "source": {
      "type": "string",
      "description": "Name of the primary file that acts as the source for content that can be rendered on demand. Only useful when deploying static content which has been rendered from Quarto, Rmarkdown or Jupyter Notebooks",
      "examples": ["report.qmd", "_quarto.yml"]
    },
    "title": {
      "type": "string",
      "pattern": "^[^\t\n\f\r]{3,1000}$|",
      "description": "Title for this content. If specified, it must be a single line containing between 3 and 1000 characters.",
      "examples": ["Quarterly Sales Report"]
    },
    "description": {
      "type": "string",
      "pattern": "^[^\t\f\r]*$",
      "description": "Description for this content. It may span multiple lines and be up to 4000 characters.",
      "examples": ["This is the quarterly sales report, broken down by region."]
    },
    "validate": {
      "type": "boolean",
      "description": "Access the content after deploying, to validate that it is live. Defaults to true.",
      "default": true
    },
    "files": {
      "type": "array",
      "items": {
        "type": ["string"]
      },
      "description": "Project-relative paths of the files to be included in the deployment. Wildcards are accepted, using .gitignore syntax.",
      "examples": ["app.py", "model/*.csv", "!model/excludeme.csv"]
    },
    "python": {
      "$comment": "Note: this object is extended by the other config definitions. Extensions should use additionalProperties: false to prevent unexpected properties.",
      "type": "object",
      "description": "Python language and dependencies.",
      "properties": {
        "version": {
          "type": "string",
          "description": "Python version. The server must have a matching Python major/minor version in order to run the content.",
          "examples": ["3.11.3", "3.11"]
        }
      }
    },
    "r": {
      "$comment": "Note: this object is extended by the other config definitions. Extensions should use additionalProperties: false to prevent unexpected properties.",
      "type": "object",
      "description": "R language and dependencies.",
      "properties": {
        "version": {
          "type": "string",
          "description": "R version. The server will use the nearest R version to run the content.",
          "examples": ["4.3.1"]
        }
      }
    },
    "environment": {
      "type": "object",
      "additionalProperties": {
        "type": ["string"]
      },
      "description": "Environment variable/value map. All values must be strings. Secrets such as API keys or tokens should not be stored here.",
      "examples": [
        {
          "API_URL": "https://example.com/api"
        }
      ]
    },
    "secrets": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "description": "Names of secrets required by the application. Injected as environment variables.",
      "examples": ["API_KEY", "DATABASE_PASSWORD"]
    },
    "integration_requests": {
      "type": "array",
      "description": "Integration requests associated with this configuration",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "guid": {
            "type": "string",
            "description": "Unique identifier for the integration request"
          },
          "name": {
            "type": "string",
            "description": "Name of the integration request"
          },
          "description": {
            "type": "string",
            "description": "Description of the integration request"
          },
          "auth_type": {
            "type": "string",
            "description": "Authentication type for the integration request"
          },
          "type": {
            "type": "string",
            "description": "Integration type"
          },
          "config": {
            "type": "object",
            "additionalProperties": true,
            "description": "Configuration for the integration request"
          }
        }
      }
    },
    "connect": {
      "type": "object",
      "description": "Settings for Posit Connect applications.",
      "properties": {
        "runtime": {
          "type": "object",
          "additionalProperties": false,
          "description": "Runtime settings for application content types.",
          "properties": {
            "connection_timeout": {
              "type": "integer",
              "minimum": 0,
              "maximum": 2592000,
              "description": "Maximum number of seconds allowed without data sent or received across a client connection. A value of `0` means connections will never time-out (not recommended).",
              "examples": [5]
            },
            "read_timeout": {
              "type": "integer",
              "minimum": 0,
              "maximum": 2592000,
              "description": "Maximum number of seconds allowed without data received from a client connection. A value of `0` means a lack of client (browser) interaction never causes the connection to close.",
              "examples": [30]
            },
            "init_timeout": {
              "type": "integer",
              "minimum": 0,
              "maximum": 2592000,
              "description": "The maximum number of seconds allowed for an interactive application to start. Posit Connect must be able to connect to a newly launched application before this threshold has elapsed.",
              "examples": [60]
            },
            "idle_timeout": {
              "type": "integer",
              "minimum": 0,
              "maximum": 2592000,
              "description": "The maximum number of seconds a worker process for an interactive application to remain alive after it goes idle (no active connections).",
              "examples": [120]
            },
            "max_processes": {
              "type": "integer",
              "minimum": 1,
              "description": "Specifies the total number of concurrent processes allowed for a single interactive application.",
              "examples": [5]
            },
            "min_processes": {
              "type": "integer",
              "minimum": 0,
              "description": "Specifies the minimum number of concurrent processes allowed for a single interactive application.",
              "examples": [1]
            },
            "max_conns_per_process": {
              "type": "integer",
              "minimum": 1,
              "description": "Specifies the maximum number of client connections allowed to an individual process. Incoming connections which will exceed this limit are routed to a new process or rejected.",
              "examples": [50]
            },
            "load_factor": {
              "type": "number",
              "minimum": 0,
              "maximum": 1,
              "description": "Controls how aggressively new processes are spawned. The valid range is between 0.0 and 1.0.",
              "examples": [0.5]
            }
          }
        }
      }
    }
  },
  "required": ["$schema", "type", "entrypoint"],
  "allOf": [
    {
      "if": {
        "properties": {
          "type": {
            "enum": [
              "jupyter-notebook",
              "jupyter-voila",
              "python-bokeh",
              "python-dash",
              "python-fastapi",
              "python-flask",
              "python-gradio",
              "python-panel",
              "python-shiny",
              "python-streamlit"
            ]
          }
        },
        "required": ["type"]
      },
      "then": {
        "required": ["python"]
      }
    },
    {
      "if": {
        "properties": {
          "type": {
            "enum": ["r-plumber", "r-shiny", "rmd-shiny", "rmd"]
          }
        },
        "required": ["type"]
      },
      "then": {
        "required": ["r"]
      }
    },
    {
      "if": {
        "anyOf": [
          {
            "$comment": "Default to connect if product_type is not specified.",
            "properties": {
              "product_type": false
            }
          },
          {
            "required": ["product_type"],
            "properties": {
              "product_type": {
                "const": "connect"
              }
            }
          }
        ]
      },
      "then": {
        "$ref": "#/$defs/config_connect"
      }
    },
    {
      "if": {
        "required": ["product_type"],
        "properties": {
          "product_type": {
            "const": "connect_cloud"
          }
        }
      },
      "then": {
        "$ref": "#/$defs/config_connect_cloud"
      }
    }
  ]
}
