{
	"$schema": "https://json-schema.org/draft/2020-12/schema",
	"$id": "https://neon.com/functions/registry/schemas/template.schema.json",
	"title": "Neon Function Registry template",
	"type": "object",
	"required": ["id", "title", "description", "layout"],
	"additionalProperties": false,
	"properties": {
		"$schema": { "type": "string" },
		"id": { "type": "string", "pattern": "^[a-z0-9][a-z0-9-]*$" },
		"provider": { "type": "string" },
		"title": { "type": "string", "minLength": 1 },
		"description": { "type": "string", "minLength": 1 },
		"categories": {
			"type": "array",
			"minItems": 1,
			"maxItems": 16,
			"uniqueItems": true,
			"items": {
				"type": "string",
				"minLength": 1,
				"maxLength": 64,
				"pattern": "^[a-z0-9][a-z0-9-]*$"
			},
			"description": "Display-only topical labels, e.g. ai and bots. The source label (first-party, partner, or community) goes in the index entry, not here."
		},
		"layout": {
			"enum": ["router", "separate"],
			"description": "router generates one function that dispatches on URL path; separate deploys each operation as its own function."
		},
		"dependencies": {
			"type": "array",
			"items": {
				"type": "string",
				"pattern": "^(?:@[a-z0-9][a-z0-9._-]*/)?[a-z0-9][a-z0-9._-]*@\\d+\\.\\d+\\.\\d+(?:-[0-9A-Za-z.-]+)?(?:\\+[0-9A-Za-z.-]+)?$",
				"description": "An exact name@version pin."
			}
		},
		"environment": {
			"type": "array",
			"items": {
				"type": "object",
				"required": ["name", "description"],
				"additionalProperties": false,
				"properties": {
					"name": { "type": "string", "pattern": "^[A-Z_][A-Z0-9_]*$" },
					"description": { "type": "string" },
					"required": {
						"description": "Written as the variable's required in neon.ts. true (the default) fails neon deploy and neon dev while it is unset; false lets both run without it; \"default-branch\" requires it only when deploying the project's default branch.",
						"oneOf": [{ "type": "boolean" }, { "const": "default-branch" }]
					}
				}
			}
		},
		"operations": {
			"type": "array",
			"minItems": 1,
			"maxItems": 40,
			"items": {
				"type": "object",
				"required": ["id", "title", "description", "source", "recommended"],
				"additionalProperties": false,
				"properties": {
					"id": { "type": "string", "pattern": "^[a-z0-9][a-z0-9-]*$" },
					"title": { "type": "string", "minLength": 1 },
					"description": { "type": "string", "minLength": 1 },
					"source": {
						"type": "string",
						"maxLength": 255,
						"description": "Module path relative to this template.json."
					},
					"route": {
						"type": "string",
						"pattern": "^\\/[A-Za-z0-9\\-._~/]*$",
						"description": "Router layout: the URL path. Defaults to /<id>."
					},
					"slug": {
						"type": "string",
						"pattern": "^[a-z0-9]{1,20}$",
						"description": "Separate layout: the Neon function slug."
					},
					"recommended": { "type": "boolean" }
				}
			}
		},
		"features": {
			"type": "array",
			"minItems": 1,
			"maxItems": 16,
			"description": "Neon products the template uses, shown as \"Built with\" on its neon.com page in this order, so list the most important first. Leave out Functions: every template is one. Write each feature as its id; function-triggers can instead be an object that lists the trigger types the template sets up. List each feature once.",
			"items": {
				"oneOf": [
					{ "$ref": "#/$defs/featureId" },
					{
						"type": "object",
						"required": ["id", "types"],
						"additionalProperties": false,
						"properties": {
							"id": { "const": "function-triggers" },
							"types": {
								"type": "array",
								"minItems": 1,
								"uniqueItems": true,
								"items": { "$ref": "#/$defs/triggerType" },
								"description": "Trigger types the template sets up. Values match the Neon API's trigger `type`."
							}
						}
					}
				]
			}
		}
	},
	"$defs": {
		"featureId": {
			"enum": [
				"postgres",
				"lakebase-search",
				"auth",
				"data-api",
				"realtime",
				"object-storage",
				"ai-gateway",
				"function-triggers"
			],
			"description": "postgres: Lakebase Postgres. lakebase-search: Lakebase Search. auth: Managed Better Auth. data-api: Data API. realtime: Realtime. object-storage: Object Storage. ai-gateway: AI Gateway. function-triggers: Function Triggers."
		},
		"triggerType": {
			"enum": ["schedule", "storage_object_created"],
			"description": "schedule: a cron schedule. storage_object_created: an object upload to an Object Storage bucket."
		}
	},
	"allOf": [
		{
			"if": { "properties": { "layout": { "const": "separate" } } },
			"then": {
				"required": ["operations"],
				"properties": { "operations": { "items": { "required": ["slug"] } } }
			}
		}
	]
}
