Skip to content

Commit

Permalink
update json schema for recursive property defs
Browse files Browse the repository at this point in the history
  • Loading branch information
skarim committed Aug 25, 2024
1 parent 00e4398 commit cb0488c
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 28 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
53 changes: 33 additions & 20 deletions schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
Expand All @@ -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
}
}
}
14 changes: 9 additions & 5 deletions src/yamlGenerator.js
Original file line number Diff line number Diff line change
@@ -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}`);
}

Expand Down

0 comments on commit cb0488c

Please sign in to comment.