From 5928134f9a9b43a1f302446b81fa32f714e00574 Mon Sep 17 00:00:00 2001 From: "jonas-lt@live.dk" Date: Thu, 16 Mar 2023 16:37:09 +0100 Subject: [PATCH 1/7] add recommended and must supported schema formats --- definitions/3.0.0/messageObject.json | 50 +++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/definitions/3.0.0/messageObject.json b/definitions/3.0.0/messageObject.json index e62f0d66..c87bacd4 100644 --- a/definitions/3.0.0/messageObject.json +++ b/definitions/3.0.0/messageObject.json @@ -8,7 +8,55 @@ }, "properties": { "schemaFormat": { - "type": "string" + "anyOf": [ + { + "type": "string" + }, + { + "description": "All MUST schema formats tooling should support", + "enum": [ + "application/vnd.aai.asyncapi;version=2.0.0", + "application/vnd.aai.asyncapi+json;version=2.0.0", + "application/vnd.aai.asyncapi+yaml;version=2.0.0", + "application/vnd.aai.asyncapi;version=2.1.0", + "application/vnd.aai.asyncapi+json;version=2.1.0", + "application/vnd.aai.asyncapi+yaml;version=2.1.0", + "application/vnd.aai.asyncapi;version=2.2.0", + "application/vnd.aai.asyncapi+json;version=2.2.0", + "application/vnd.aai.asyncapi+yaml;version=2.2.0", + "application/vnd.aai.asyncapi;version=2.3.0", + "application/vnd.aai.asyncapi+json;version=2.3.0", + "application/vnd.aai.asyncapi+yaml;version=2.3.0", + "application/vnd.aai.asyncapi;version=2.4.0", + "application/vnd.aai.asyncapi+json;version=2.4.0", + "application/vnd.aai.asyncapi+yaml;version=2.4.0", + "application/vnd.aai.asyncapi;version=2.5.0", + "application/vnd.aai.asyncapi+json;version=2.5.0", + "application/vnd.aai.asyncapi+yaml;version=2.5.0", + "application/vnd.aai.asyncapi;version=2.6.0", + "application/vnd.aai.asyncapi+json;version=2.6.0", + "application/vnd.aai.asyncapi+yaml;version=2.6.0", + "application/vnd.aai.asyncapi;version=3.0.0", + "application/vnd.aai.asyncapi+json;version=3.0.0", + "application/vnd.aai.asyncapi+yaml;version=3.0.0", + + "application/schema+json;version=draft-07", + "application/schema+yaml;version=draft-07" + ] + }, + { + "description": "All RECOMMENDED schema formats tooling should support", + "enum": [ + "application/vnd.oai.openapi;version=3.0.0", + "application/vnd.oai.openapi+json;version=3.0.0", + "application/vnd.oai.openapi+yaml;version=3.0.0", + + "application/vnd.apache.avro;version=1.9.0", + "application/vnd.apache.avro+json;version=1.9.0", + "application/vnd.apache.avro+yaml;version=1.9.0" + ] + } + ] }, "contentType": { "type": "string" From 26a3f295f86da661745589e677262b59ab03368d Mon Sep 17 00:00:00 2001 From: "jonas-lt@live.dk" Date: Thu, 16 Mar 2023 16:37:33 +0100 Subject: [PATCH 2/7] add raml --- definitions/3.0.0/messageObject.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/definitions/3.0.0/messageObject.json b/definitions/3.0.0/messageObject.json index c87bacd4..b42512c0 100644 --- a/definitions/3.0.0/messageObject.json +++ b/definitions/3.0.0/messageObject.json @@ -53,7 +53,9 @@ "application/vnd.apache.avro;version=1.9.0", "application/vnd.apache.avro+json;version=1.9.0", - "application/vnd.apache.avro+yaml;version=1.9.0" + "application/vnd.apache.avro+yaml;version=1.9.0", + + "application/raml+yaml;version=1.0" ] } ] From c9ba501de53a0d66a8d3ce17da164047a757d036 Mon Sep 17 00:00:00 2001 From: "jonas-lt@live.dk" Date: Thu, 29 Jun 2023 15:33:47 +0200 Subject: [PATCH 3/7] remove old versions --- definitions/3.0.0/messageObject.json | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/definitions/3.0.0/messageObject.json b/definitions/3.0.0/messageObject.json index b42512c0..db29f3d6 100644 --- a/definitions/3.0.0/messageObject.json +++ b/definitions/3.0.0/messageObject.json @@ -15,27 +15,6 @@ { "description": "All MUST schema formats tooling should support", "enum": [ - "application/vnd.aai.asyncapi;version=2.0.0", - "application/vnd.aai.asyncapi+json;version=2.0.0", - "application/vnd.aai.asyncapi+yaml;version=2.0.0", - "application/vnd.aai.asyncapi;version=2.1.0", - "application/vnd.aai.asyncapi+json;version=2.1.0", - "application/vnd.aai.asyncapi+yaml;version=2.1.0", - "application/vnd.aai.asyncapi;version=2.2.0", - "application/vnd.aai.asyncapi+json;version=2.2.0", - "application/vnd.aai.asyncapi+yaml;version=2.2.0", - "application/vnd.aai.asyncapi;version=2.3.0", - "application/vnd.aai.asyncapi+json;version=2.3.0", - "application/vnd.aai.asyncapi+yaml;version=2.3.0", - "application/vnd.aai.asyncapi;version=2.4.0", - "application/vnd.aai.asyncapi+json;version=2.4.0", - "application/vnd.aai.asyncapi+yaml;version=2.4.0", - "application/vnd.aai.asyncapi;version=2.5.0", - "application/vnd.aai.asyncapi+json;version=2.5.0", - "application/vnd.aai.asyncapi+yaml;version=2.5.0", - "application/vnd.aai.asyncapi;version=2.6.0", - "application/vnd.aai.asyncapi+json;version=2.6.0", - "application/vnd.aai.asyncapi+yaml;version=2.6.0", "application/vnd.aai.asyncapi;version=3.0.0", "application/vnd.aai.asyncapi+json;version=3.0.0", "application/vnd.aai.asyncapi+yaml;version=3.0.0", From 192651b6bc9ce80c75eef2f3204c3b31490947e9 Mon Sep 17 00:00:00 2001 From: "jonas-lt@live.dk" Date: Thu, 29 Jun 2023 16:16:46 +0200 Subject: [PATCH 4/7] fix add new version --- definitions/3.0.0/asyncapi.json | 4 +-- scripts/add-new-version.js | 51 +++++++++++++++++++++++++++++++-- 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/definitions/3.0.0/asyncapi.json b/definitions/3.0.0/asyncapi.json index 0157a6dd..18a6c39d 100644 --- a/definitions/3.0.0/asyncapi.json +++ b/definitions/3.0.0/asyncapi.json @@ -16,9 +16,7 @@ "properties": { "asyncapi": { "type": "string", - "enum": [ - "3.0.0" - ], + "const": "3.0.0", "description": "The AsyncAPI specification version of this document." }, "id": { diff --git a/scripts/add-new-version.js b/scripts/add-new-version.js index 8d2f2f49..5860a46c 100644 --- a/scripts/add-new-version.js +++ b/scripts/add-new-version.js @@ -1,3 +1,4 @@ +const path = require('path'); /** * This script adds a new version of the spec, by copying the latest one as baseline. */ @@ -23,6 +24,47 @@ function execute(command) { }); } +/** + * Add the new AsyncAPI schema object as values to schemaFormat + * + * If a major version change, replaces all old AsyncAPI schemaFormat values with fresh ones + * if minor or fix, it add new ones + */ +function addNewSchemaVersion(newVersion, newVersionDir, latestVersion) { + const objFile = path.resolve(newVersionDir, 'messageObject.json'); + const obj = require(objFile); + let enums = [] = obj?.properties?.schemaFormat?.anyOf[1]?.enum; + const isMajorVersionChange = newVersion.charAt(0) !== latestVersion.charAt(0); + + //Add new version to schemaFormat + if(enums) { + if(isMajorVersionChange) { + //Remove all old AsyncAPI schema formats + enums = enums.filter((format) => !format.includes('application/vnd.aai.asyncapi')); + } + //Add new schema formats + enums.push(`application/vnd.aai.asyncapi;version=${newVersion}`); + enums.push(`application/vnd.aai.asyncapi+json;version=${newVersion}`); + enums.push(`application/vnd.aai.asyncapi+yaml;version=${newVersion}`); + obj.properties.schemaFormat.anyOf[1].enum = enums; + } else { + throw new Error("Could not find object to add schemaFormat values to"); + } + + fs.writeFileSync(objFile, JSON.stringify(obj, null, 2)); +} + +/** + * Adapt the root title and .asyncapi property + */ +function adaptRootObject(newVersion, newVersionDir) { + const objFile = path.resolve(newVersionDir, 'asyncapi.json'); + const obj = require(objFile); + obj.title = `AsyncAPI ${newVersion} schema.`; + obj.properties.asyncapi.const = newVersion; + fs.writeFileSync(objFile, JSON.stringify(obj, null, 2)); +} + async function addNewVersion(newVersion) { const newVersionDir = `./definitions/${newVersion}`; @@ -36,8 +78,13 @@ async function addNewVersion(newVersion) { const latestVersion = (await execute('ls -d ./definitions/* | sort -V -r | head -1 | xargs -n 1 basename')).trim(); await execute(`cp -R ./definitions/${latestVersion} ${newVersionDir}`); - // Replace old version numbers with new - await execute(`find ${newVersionDir} -name '*.json' -exec sed -i '' \"s+${latestVersion}+${newVersion}+g\" {} +`); + // Replace $ref and $id paths such as `/3.0.0/` with new version (http://asyncapi.com/definitions/3.0.0/specificationExtension.json) + await execute(`find ${newVersionDir} -name '*.json' -exec sed -i '' \"s+\/${latestVersion}\/+\/${newVersion}\/+g\" {} +`); + // Replace .asyncapi version from old to new version + // Replace old version in title with new version + adaptRootObject(newVersion, newVersionDir); + // Add new schemaFormat version entries + addNewSchemaVersion(newVersion, newVersionDir, latestVersion); console.log(`New version added to ${newVersionDir}`) } From 1b874cff5ba6ebca9117deb68e01284d8dfe22c4 Mon Sep 17 00:00:00 2001 From: Jonas Lagoni Date: Tue, 25 Jul 2023 10:43:09 +0200 Subject: [PATCH 5/7] Update definitions/3.0.0/messageObject.json MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Fran Méndez --- definitions/3.0.0/messageObject.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/definitions/3.0.0/messageObject.json b/definitions/3.0.0/messageObject.json index db29f3d6..05dd6488 100644 --- a/definitions/3.0.0/messageObject.json +++ b/definitions/3.0.0/messageObject.json @@ -13,7 +13,7 @@ "type": "string" }, { - "description": "All MUST schema formats tooling should support", + "description": "All the schema formats tooling MUST support", "enum": [ "application/vnd.aai.asyncapi;version=3.0.0", "application/vnd.aai.asyncapi+json;version=3.0.0", From e728723eb5be2760fe7d7854cca7db5162e10510 Mon Sep 17 00:00:00 2001 From: Jonas Lagoni Date: Tue, 25 Jul 2023 10:43:20 +0200 Subject: [PATCH 6/7] Update definitions/3.0.0/messageObject.json MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Fran Méndez --- definitions/3.0.0/messageObject.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/definitions/3.0.0/messageObject.json b/definitions/3.0.0/messageObject.json index 05dd6488..619f3cb3 100644 --- a/definitions/3.0.0/messageObject.json +++ b/definitions/3.0.0/messageObject.json @@ -24,7 +24,7 @@ ] }, { - "description": "All RECOMMENDED schema formats tooling should support", + "description": "All the schema formats tools are RECOMMENDED to support", "enum": [ "application/vnd.oai.openapi;version=3.0.0", "application/vnd.oai.openapi+json;version=3.0.0", From 951bfd701988312459f100be1101303362fe5b39 Mon Sep 17 00:00:00 2001 From: "jonas-lt@live.dk" Date: Tue, 25 Jul 2023 11:28:10 +0200 Subject: [PATCH 7/7] fix script for creating new versions --- definitions/3.0.0/multiFormatSchema.json | 10 +++-- scripts/add-new-version.js | 52 +++++++++++++++--------- 2 files changed, 38 insertions(+), 24 deletions(-) diff --git a/definitions/3.0.0/multiFormatSchema.json b/definitions/3.0.0/multiFormatSchema.json index 2bafc34e..fa993a10 100644 --- a/definitions/3.0.0/multiFormatSchema.json +++ b/definitions/3.0.0/multiFormatSchema.json @@ -24,12 +24,12 @@ { "description": "All the schema formats tooling MUST support", "enum": [ + "application/schema+json;version=draft-07", + "application/schema+yaml;version=draft-07", + "application/vnd.aai.asyncapi;version=3.0.0", "application/vnd.aai.asyncapi+json;version=3.0.0", - "application/vnd.aai.asyncapi+yaml;version=3.0.0", - - "application/schema+json;version=draft-07", - "application/schema+yaml;version=draft-07" + "application/vnd.aai.asyncapi+yaml;version=3.0.0" ] }, { @@ -54,6 +54,7 @@ { "if": { "not": { + "description": "If no schemaFormat has been defined, default to schema or reference", "required": [ "schemaFormat" ] @@ -76,6 +77,7 @@ }, { "if": { + "description": "If schemaFormat has been defined check if it's one of the AsyncAPI Schema Object formats", "required": [ "schemaFormat" ], diff --git a/scripts/add-new-version.js b/scripts/add-new-version.js index 8ded26c3..6cdeaf8f 100644 --- a/scripts/add-new-version.js +++ b/scripts/add-new-version.js @@ -31,26 +31,42 @@ function execute(command) { * if minor or fix, it add new ones */ function addNewSchemaVersion(newVersion, newVersionDir, latestVersion) { - const objFile = path.resolve(newVersionDir, 'messageObject.json'); - const obj = require(objFile); - let enums = [] = obj?.properties?.schemaFormat?.anyOf[1]?.enum; + const newSchemaFormats = [ + `application/vnd.aai.asyncapi;version=${newVersion}`, + `application/vnd.aai.asyncapi+json;version=${newVersion}`, + `application/vnd.aai.asyncapi+yaml;version=${newVersion}` + ]; + //Did the major version (first char) change from last to new version? const isMajorVersionChange = newVersion.charAt(0) !== latestVersion.charAt(0); + const objFile = path.resolve(newVersionDir, 'multiFormatSchema.json'); + const obj = require(objFile); - //Add new version to schemaFormat - if(enums) { + // Adapt all the MUST supported schema formats + let mustSupportedSchemaFormats = [] = obj?.else?.properties?.schemaFormat?.anyOf[1]?.enum; + + //Add new version to the list of available schemaFormat values + if(mustSupportedSchemaFormats) { if(isMajorVersionChange) { - //Remove all old AsyncAPI schema formats - enums = enums.filter((format) => !format.includes('application/vnd.aai.asyncapi')); + //Remove all old AsyncAPI schema formats because we want a clean slate + mustSupportedSchemaFormats = mustSupportedSchemaFormats.filter((format) => !format.includes('application/vnd.aai.asyncapi')); } //Add new schema formats - enums.push(`application/vnd.aai.asyncapi;version=${newVersion}`); - enums.push(`application/vnd.aai.asyncapi+json;version=${newVersion}`); - enums.push(`application/vnd.aai.asyncapi+yaml;version=${newVersion}`); - obj.properties.schemaFormat.anyOf[1].enum = enums; + mustSupportedSchemaFormats.push(...newSchemaFormats); + obj.else.properties.schemaFormat.anyOf[1].enum = mustSupportedSchemaFormats; } else { throw new Error("Could not find object to add schemaFormat values to"); } + //Make sure new versions apply the right schema + let enumsForValidatingSchema = [] = obj?.else?.allOf[1]?.if?.properties?.schemaFormat?.enum; + if(enumsForValidatingSchema) { + //Add new schema formats + enumsForValidatingSchema.push(...newSchemaFormats); + obj.else.allOf[1].if.properties.schemaFormat.enum = enumsForValidatingSchema; + } else { + throw new Error("Could not find location for schemaFormats that applies the AsyncAPI Schema object to the schema property"); + } + fs.writeFileSync(objFile, JSON.stringify(obj, null, 2)); } @@ -79,22 +95,18 @@ async function addNewVersion(newVersion) { const latestVersion = (await execute('ls -d ./definitions/* | sort -V -r | head -1 | xargs -n 1 basename')).trim(); await execute(`cp -R ./definitions/${latestVersion} ${newVersionDir}`); -<<<<<<< HEAD + const latestExampleVersion = (await execute('ls -d ./examples/* | sort -V -r | head -1 | xargs -n 1 basename')).trim(); + await execute(`cp -R ./examples/${latestExampleVersion} ${newExampleVersionDir}`); + // Replace $ref and $id paths such as `/3.0.0/` with new version (http://asyncapi.com/definitions/3.0.0/specificationExtension.json) await execute(`find ${newVersionDir} -name '*.json' -exec sed -i '' \"s+\/${latestVersion}\/+\/${newVersion}\/+g\" {} +`); + // Replace .asyncapi version from old to new version // Replace old version in title with new version adaptRootObject(newVersion, newVersionDir); + // Add new schemaFormat version entries addNewSchemaVersion(newVersion, newVersionDir, latestVersion); -======= - const latestExampleVersion = (await execute('ls -d ./examples/* | sort -V -r | head -1 | xargs -n 1 basename')).trim(); - await execute(`cp -R ./definitions/${latestVersion} ${newVersionDir}`); - await execute(`cp -R ./examples/${latestExampleVersion} ${newExampleVersionDir}`); - - // Replace old version numbers with new - await execute(`find ${newVersionDir} -name '*.json' -exec sed -i '' "s+${latestVersion}+${newVersion}+g" {} +`); ->>>>>>> next-major-spec console.log(`New version added to ${newVersionDir}`) }