Skip to content

Commit

Permalink
Merge branch 'master' into ag-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
devilkiller-ag authored Dec 17, 2023
2 parents 9211632 + 287ed28 commit 89ffe66
Show file tree
Hide file tree
Showing 8 changed files with 1,536 additions and 3,406 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/bump.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ jobs:
github_token: ${{ secrets.GH_TOKEN }}
committer_username: asyncapi-bot
committer_email: [email protected]
repos_to_ignore: html-template # this is temporary until react component releases 1.0, then it can be removed
repos_to_ignore: spec,bindings
2 changes: 1 addition & 1 deletion .github/workflows/if-nodejs-pr-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,4 @@ jobs:
run: npm run lint --if-present
- if: steps.packagejson.outputs.exists == 'true'
name: Run release assets generation to make sure PR does not break it
run: npm run generate:assets --if-present
run: npm run generate:assets --if-present
5 changes: 4 additions & 1 deletion bindings/kafka/0.4.0/message.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@
},
"properties": {
"key": {
"oneOf": [
"anyOf": [
{
"$ref": "http://asyncapi.com/definitions/3.0.0/Reference.json"
},
{
"$ref": "http://asyncapi.com/definitions/3.0.0/schema.json"
},
{
"$ref": "http://asyncapi.com/definitions/3.0.0/avroSchema_v1.json"
}
],
"description": "The message key."
Expand Down
4,823 changes: 1,426 additions & 3,397 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
{
"name": "@asyncapi/specs",
"version": "6.1.0",
"version": "6.2.0",
"description": "AsyncAPI schema versions",
"main": "index.js",
"types": "index.d.ts",
"scripts": {
"test": "npm run build && nyc mocha",
"test": "npm run build && nyc mocha && npm run validate:schemas",
"build": "npm run bundle",
"generate:assets": "npm run build",
"prepublishOnly": "npm run build",
"bundle": "cd tools/bundler && npm i && npm run bundle",
"startNewVersion": "newVersion=$npm_config_new_version node scripts/add-new-version.js",
"lint": "echo 'No linter integrated yet'",
"bump:version": "npm --no-git-tag-version --allow-same-version version $VERSION"
"bump:version": "npm --no-git-tag-version --allow-same-version version $VERSION",
"validate:schemas": "node scripts/validate-schemas.js"
},
"repository": {
"type": "git",
Expand All @@ -37,7 +38,8 @@
},
"homepage": "https://github.com/asyncapi/spec-json-schemas#readme",
"devDependencies": {
"ajv": "^8.11.2",
"ajv": "^8.12.0",
"ajv-draft-04": "^1.0.0",
"mocha": "^10.0.0",
"nyc": "^15.1.0"
},
Expand Down
5 changes: 4 additions & 1 deletion schemas/3.0.0-without-$id.json
Original file line number Diff line number Diff line change
Expand Up @@ -3958,12 +3958,15 @@
},
"properties": {
"key": {
"oneOf": [
"anyOf": [
{
"$ref": "#/definitions/Reference"
},
{
"$ref": "#/definitions/schema"
},
{
"$ref": "#/definitions/avroSchema_v1"
}
],
"description": "The message key."
Expand Down
5 changes: 4 additions & 1 deletion schemas/3.0.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -4015,12 +4015,15 @@
},
"properties": {
"key": {
"oneOf": [
"anyOf": [
{
"$ref": "http://asyncapi.com/definitions/3.0.0/Reference.json"
},
{
"$ref": "http://asyncapi.com/definitions/3.0.0/schema.json"
},
{
"$ref": "http://asyncapi.com/definitions/3.0.0/avroSchema_v1.json"
}
],
"description": "The message key."
Expand Down
90 changes: 90 additions & 0 deletions scripts/validate-schemas.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
const fs = require('fs');
const path = require('path');

const AjvDraft04 = require('ajv-draft-04');
const ajvDraft04 = new AjvDraft04();

const Ajv = require('ajv');
const ajv = new Ajv();

function validation (excludedFiles){

// Specify the path to the 'schemas' directory
const directoryPath = './schemas';

try{

const files = fs.readdirSync(directoryPath);

// Filter files
const filteredFiles = files.filter(file => !excludedFiles.includes(file) && path.extname(file).toLowerCase() === '.json');


// Collect errors in an array
const validationErrors = [];

// Iterate through the filtered files
filteredFiles.forEach(file => {
// Construct the full path to the JSON schema file
const filePath = path.join(directoryPath, file);


try {
// Read and parse the JSON schema
const fileContent = fs.readFileSync(filePath, 'utf8');
const obj = JSON.parse(fileContent);

let validate;
if (obj.$schema === 'http://json-schema.org/draft-04/schema') {
// Validate the schema
validate = ajvDraft04.validateSchema(obj);
if(validate){
console.log(`\n${file}: JSON Schema is valid!`);
}
} else {
// Validate the schema
validate = ajv.validateSchema(obj);
if(validate){
console.log(`\n${file}: JSON Schema is valid!`);
}
}

// Check if the schema is not valid and collect errors
if (!validate) {
validationErrors.push({
file,
errors: obj.$schema === 'http://json-schema.org/draft-04/schema'
? ajvDraft04.errors
: ajv.errors
});
}
} catch (error) {
validationErrors.push({
file,
errors: [{ message: `\nError reading or parsing JSON Schema: ${error.message}` }]
});
}
});

// Print errors after processing all files
validationErrors.forEach(({ file, errors }) => {
console.error(`\n${file}: JSON Schema is not valid:`, errors);
});

// Exit with an error code if there are validation errors
if (validationErrors.length > 0) {
process.exit(1);
}

} catch (error) {
console.error('\nError during validation:', error.message);
process.exit(1);
}
}


const excludedFiles=['2.0.0-rc1.json', '2.0.0-rc1-without-$id.json']; // added temporarily to avoid validation failure due to these two files. The schemas version are incorrect in these and needs to be fixed.

validation(excludedFiles);

console.log('\nValidation completed successfully.');

0 comments on commit 89ffe66

Please sign in to comment.