@asyncapi/specs
Advanced tools
Comparing version 6.0.0-next-major-spec.4 to 6.0.0-next-major-spec.5
@@ -19,5 +19,3 @@ { | ||
"type": "string", | ||
"enum": [ | ||
"3.0.0" | ||
], | ||
"const": "3.0.0", | ||
"description": "The AsyncAPI specification version of this document." | ||
@@ -24,0 +22,0 @@ }, |
@@ -20,3 +20,32 @@ { | ||
"schemaFormat": { | ||
"type": "string" | ||
"anyOf": [ | ||
{ | ||
"type": "string" | ||
}, | ||
{ | ||
"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" | ||
] | ||
}, | ||
{ | ||
"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", | ||
"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", | ||
"application/raml+yaml;version=1.0" | ||
] | ||
} | ||
] | ||
}, | ||
@@ -29,2 +58,3 @@ "schema": {} | ||
"not": { | ||
"description": "If no schemaFormat has been defined, default to schema or reference", | ||
"required": [ | ||
@@ -52,2 +82,3 @@ "schemaFormat" | ||
"if": { | ||
"description": "If schemaFormat has been defined check if it's one of the AsyncAPI Schema Object formats", | ||
"required": [ | ||
@@ -54,0 +85,0 @@ "schemaFormat" |
{ | ||
"name": "@asyncapi/specs", | ||
"version": "6.0.0-next-major-spec.4", | ||
"version": "6.0.0-next-major-spec.5", | ||
"description": "AsyncAPI schema versions", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -0,1 +1,2 @@ | ||
const path = require('path'); | ||
/** | ||
@@ -26,2 +27,59 @@ * This script adds a new version of the spec with examples, by copying the latest one as baseline. | ||
/** | ||
* 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 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); | ||
// 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 because we want a clean slate | ||
mustSupportedSchemaFormats = mustSupportedSchemaFormats.filter((format) => !format.includes('application/vnd.aai.asyncapi')); | ||
} | ||
//Add new schema formats | ||
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)); | ||
} | ||
/** | ||
* 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) { | ||
@@ -42,8 +100,14 @@ const newVersionDir = `./definitions/${newVersion}`; | ||
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" {} +`); | ||
// 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}`) | ||
@@ -50,0 +114,0 @@ } |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16077960
170532
9