From 0ac97545de2b1668c7219e00152b56d37734e545 Mon Sep 17 00:00:00 2001 From: Ben Blank Date: Thu, 14 Dec 2023 05:33:42 +0000 Subject: [PATCH 1/3] Add JSON schema for Development Container Template Metadata --- schemas/devContainerTemplate.schema.json | 182 +++++++++++++++++++++++ 1 file changed, 182 insertions(+) create mode 100644 schemas/devContainerTemplate.schema.json diff --git a/schemas/devContainerTemplate.schema.json b/schemas/devContainerTemplate.schema.json new file mode 100644 index 00000000..59b4261d --- /dev/null +++ b/schemas/devContainerTemplate.schema.json @@ -0,0 +1,182 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "Development Container Template Metadata", + "description": "Development Container Template Metadata (devcontainer-template.json). See https://containers.dev/implementors/templates/ for more information.", + "definitions": { + "Template": { + "type": "object", + "additionalProperties": false, + "properties": { + "$schema": { + "description": "The JSON schema of the `devcontainer-template.json` file.", + "type": "string", + "format": "uri" + }, + "description": { + "description": "Description of the Template.", + "type": "string" + }, + "documentationURL": { + "description": "Url that points to the documentation of the Template.", + "type": "string", + "format": "uri" + }, + "id": { + "description": "ID of the Template. The id should be unique in the context of the repository/published package where the Template exists and must match the name of the directory where the devcontainer-template.json resides.", + "type": "string" + }, + "keywords": { + "description": "List of strings relevant to a user that would search for this Template.", + "type": "array", + "items": { + "type": "string" + } + }, + "licenseURL": { + "description": "Url that points to the license of the Template.", + "type": "string", + "format": "uri" + }, + "name": { + "description": "Name of the Template.", + "type": "string" + }, + "options": { + "description": "A map of options that the supporting tools should use to populate different configuration options for the Template.", + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/Option" + } + }, + "platforms": { + "description": "Languages and platforms supported by the Template.", + "type": "array", + "items": { + "type": "string" + } + }, + "publisher": { + "description": "Name of the publisher/maintainer of the Template.", + "type": "string" + }, + "version": { + "description": "The semantic version of the Template.", + "type": "string" + } + }, + "required": [ + "id", + "name", + "version" + ] + }, + "Option": { + "description": "An option that the supporting tools should use to populate different configuration options for the Template.", + "type": "object", + "properties": { + "default": { + "description": "Default value for the option.", + "type": [ + "boolean", + "string" + ] + }, + "description": { + "description": "Description for the option.", + "type": "string" + }, + "type": { + "description": "Type of the option. Valid types are currently: boolean, string", + "type": "string", + "enum": [ + "boolean", + "string" + ] + } + }, + "required": [ + "default", + "description", + "type" + ], + "oneOf": [ + { + "type": "object", + "additionalProperties": false, + "properties": { + "default": { + "type": "boolean" + }, + "description": true, + "type": { + "type": "string", + "const": "boolean" + } + }, + "required": [ + "default", + "type" + ] + }, + { + "type": "object", + "additionalProperties": false, + "properties": { + "default": { + "type": "string" + }, + "description": true, + "enum": true, + "proposals": true, + "type": { + "type": "string", + "const": "string" + } + }, + "required": [ + "default", + "type" + ], + "oneOf": [ + { + "type": "object", + "properties": { + "enum": { + "description": "A strict list of allowed string values. Free-form values are not allowed. Omit when using optionId.proposals.", + "type": "array", + "minItems": 1, + "items": { + "type": "string" + } + } + }, + "required": [ + "enum" + ] + }, + { + "type": "object", + "properties": { + "proposals": { + "description": "A list of suggested string values. Free-form values are allowed. Omit when using optionId.enum.", + "type": "array", + "items": { + "type": "string" + } + } + }, + "required": [ + "proposals" + ] + } + ] + } + ] + } + }, + "oneOf": [ + { + "$ref": "#/definitions/Template" + } + ] +} From 4e19083adfb49abe297b4d254cb69e41ab56878b Mon Sep 17 00:00:00 2001 From: Ben Blank Date: Thu, 21 Dec 2023 19:44:49 +0000 Subject: [PATCH 2/3] Allow optional "$schema" property in devcontainer-feature.json --- schemas/devContainerFeature.schema.json | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/schemas/devContainerFeature.schema.json b/schemas/devContainerFeature.schema.json index 6234f5d5..9eb2d304 100644 --- a/schemas/devContainerFeature.schema.json +++ b/schemas/devContainerFeature.schema.json @@ -6,6 +6,11 @@ "Feature": { "additionalProperties": false, "properties": { + "$schema": { + "description": "The JSON schema of the `devcontainer-feature.json` file.", + "type": "string", + "format": "uri" + }, "capAdd": { "description": "Passes docker capabilities to include when creating the dev container.", "examples": [ @@ -333,4 +338,4 @@ "$ref": "#/definitions/Feature" } ] -} \ No newline at end of file +} From b7c3ce45e9f383a046cd11dfc42f6649c2d7d1f0 Mon Sep 17 00:00:00 2001 From: Ben Blank Date: Tue, 16 Jan 2024 01:10:01 +0000 Subject: [PATCH 3/3] Update JSON schemas based on PR feedback. - The schema for features has been updated to use "oneOf" semantics instead of "anyOf" semantics for option types. (This should have no practical effect, but clarifies intent.) - For templates, the schema no longer requires a string option to have "proposals" when "enum" is absent. (This matches the behavior of the features schema.) --- schemas/devContainerFeature.schema.json | 2 +- schemas/devContainerTemplate.schema.json | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/schemas/devContainerFeature.schema.json b/schemas/devContainerFeature.schema.json index 9eb2d304..1e3db112 100644 --- a/schemas/devContainerFeature.schema.json +++ b/schemas/devContainerFeature.schema.json @@ -216,7 +216,7 @@ "type": "object" }, "FeatureOption": { - "anyOf": [ + "oneOf": [ { "description": "Option value is represented with a boolean value.", "additionalProperties": false, diff --git a/schemas/devContainerTemplate.schema.json b/schemas/devContainerTemplate.schema.json index 59b4261d..adb36dd6 100644 --- a/schemas/devContainerTemplate.schema.json +++ b/schemas/devContainerTemplate.schema.json @@ -164,10 +164,7 @@ "type": "string" } } - }, - "required": [ - "proposals" - ] + } } ] }