From cb0488cfb4549f317d7ed2ce409d2e015258dd72 Mon Sep 17 00:00:00 2001 From: Sameen Karim Date: Sun, 25 Aug 2024 13:11:15 -0500 Subject: [PATCH] update json schema for recursive property defs --- package-lock.json | 4 ++-- package.json | 2 +- schema.json | 53 +++++++++++++++++++++++++++----------------- src/yamlGenerator.js | 14 +++++++----- 4 files changed, 45 insertions(+), 28 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0790171..18440f1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@flisk/analyze-tracking", - "version": "0.1.3", + "version": "0.2.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@flisk/analyze-tracking", - "version": "0.1.3", + "version": "0.2.0", "license": "MIT", "dependencies": { "@typescript-eslint/parser": "^8.1.0", diff --git a/package.json b/package.json index 66bbac4..eab3cd1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@flisk/analyze-tracking", - "version": "0.1.3", + "version": "0.2.0", "description": "Analyzes tracking code in a project and generates data schemas", "main": "src/index.js", "bin": { diff --git a/schema.json b/schema.json index 25b8460..d895f19 100644 --- a/schema.json +++ b/schema.json @@ -83,25 +83,7 @@ "type": "object", "patternProperties": { "^[a-zA-Z0-9_-]+$": { - "type": "object", - "properties": { - "type": { - "type": "string", - "description": "Data type of the property (e.g., string, number, any)" - }, - "required": { - "type": "boolean", - "description": "Whether this property is required" - }, - "description": { - "type": "string", - "description": "Description of the property" - } - }, - "required": [ - "type" - ], - "additionalProperties": false + "$ref": "#/definitions/property" } } } @@ -119,5 +101,36 @@ "version", "source", "events" - ] + ], + "definitions": { + "property": { + "type": "object", + "properties": { + "type": { + "type": "string", + "description": "Data type of the property (e.g., string, number, any)" + }, + "required": { + "type": "boolean", + "description": "Whether this property is required" + }, + "description": { + "type": "string", + "description": "Description of the property" + }, + "properties": { + "type": "object", + "patternProperties": { + "^[a-zA-Z0-9_-]+$": { + "$ref": "#/definitions/property" + } + } + } + }, + "required": [ + "type" + ], + "additionalProperties": false + } + } } diff --git a/src/yamlGenerator.js b/src/yamlGenerator.js index b02f84b..87c1a92 100644 --- a/src/yamlGenerator.js +++ b/src/yamlGenerator.js @@ -1,17 +1,21 @@ const fs = require('fs'); const yaml = require('js-yaml'); -const version = 1 +const VERSION = 1 +const SCHEMA_URL = "https://raw.githubusercontent.com/fliskdata/analyze-tracking/main/schema.json"; function generateYamlSchema(events, repository, outputPath) { const schema = { - version, + version: VERSION, source: repository, events, }; - - const yamlOutput = yaml.dump(schema, { noRefs: true }); - fs.writeFileSync(outputPath, yamlOutput, 'utf8'); + const options = { + noRefs: true, + }; + const yamlOutput = yaml.dump(schema, options); + const yamlFile = `# yaml-language-server: $schema=${SCHEMA_URL}\n${yamlOutput}`; + fs.writeFileSync(outputPath, yamlFile, 'utf8'); console.log(`Tracking schema YAML file generated: ${outputPath}`); }