{
	"$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" }
				}
			}
		}
	},
	"allOf": [
		{
			"if": { "properties": { "layout": { "const": "separate" } } },
			"then": {
				"required": ["operations"],
				"properties": { "operations": { "items": { "required": ["slug"] } } }
			}
		}
	]
}
