-
Notifications
You must be signed in to change notification settings - Fork 321
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
905 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
#!/usr/bin/env node | ||
|
||
/* | ||
1.The script will check breaking changes as mentioned below and throw out errors to fail the build if needed | ||
-when an existing schema file got removed (rename a file will be breaking change in this case). | ||
-when an field got removed from the schema | ||
-when a field's data type got changed | ||
-when the value of $ref is changed | ||
-when a $ref got removed from allOf | ||
2.The script will only generate warning messages for cases below. | ||
-when the meta:extends does not match allOf | ||
*/ | ||
|
||
const fs = require('fs'); | ||
const glob = require("glob"); | ||
const shell = require('shelljs'); | ||
const diff = require('deep-diff'); | ||
const masterCopyLoc = "../tempmaster/"; | ||
const masterSchemaFolder = masterCopyLoc + "schemas"; | ||
const masterExtensionFolder = masterCopyLoc + "extensions"; | ||
|
||
shell.rm("-rf", masterCopyLoc); //start | ||
if (shell.exec('git clone https://github.com/adobe/xdm.git ' + masterCopyLoc).code !== 0) { | ||
shell.echo('Error: Git clone master branch failed'); | ||
shell.exit(1); | ||
} | ||
|
||
var jsonDataTypes = ["string", "number", "integer", "array", "object", "boolean"]; | ||
var schemaFiles = glob.sync(masterSchemaFolder + "/**/*.schema.json"); | ||
schemaFiles = schemaFiles.concat(glob.sync(masterExtensionFolder + "/**/*.schema.json")); | ||
|
||
checkBreakingChanges(schemaFiles); | ||
shell.rm("-rf", masterCopyLoc); //done | ||
|
||
function checkBreakingChanges(files) { | ||
files.forEach(function (file) { | ||
var err; | ||
console.log('Check breaking changes -->' + file); | ||
var originalSchema = JSON.parse(fs.readFileSync(file).toString()); | ||
var workingFile = file.replace("tempmaster/", ""); | ||
|
||
try { //check if schema file got removed | ||
var newSchema = JSON.parse(fs.readFileSync(workingFile).toString()); | ||
} catch (err) { | ||
if (err.code = "ENOENT" && err.message.indexOf("ENOENT: no such file or directory") != -1) | ||
createError("Breaking changes found!!! --> " + workingFile.replace("../", "") + " can not be removed"); | ||
else | ||
createError(err) //raise other validation errors | ||
} | ||
|
||
var allOfCheck = isAllOfBroken(originalSchema["allOf"], newSchema["allOf"]); //check deleted allOfs | ||
if (originalSchema["allOf"] && allOfCheck.isBroken) { | ||
createError('Breaking changes found!!! {"$ref": "' + allOfCheck["$ref"] + '"} inside "allOf" can not be removed.'); | ||
} | ||
|
||
if (newSchema["meta:extends"] && Array.isArray(newSchema["meta:extends"]) && isMetaExtendsBroken(newSchema["meta:extends"], newSchema["allOf"])) { //check meta:extends against allOf | ||
console.log('Warning: Incompatible "meta:extends" vs "allOf" found!!! The schemas inside "meta:extends" did not match those in "allOf".') | ||
} | ||
|
||
var differences = diff(originalSchema, newSchema); | ||
var brokenProperty = {}; | ||
if (differences && isPropertyRemoved(differences, brokenProperty)) { //check removed properties | ||
createError('Breaking changes found!!! Property "' + brokenProperty.name + '" can not be removed.'); | ||
} | ||
|
||
if (differences && isFieldTypeChanged(differences, brokenProperty)) { //check changed data types | ||
createError('Breaking changes found!!! Data type of property "' + brokenProperty.name + '" can not be changed.'); | ||
} | ||
|
||
}); | ||
} | ||
|
||
function isAllOfBroken(origAllOf, newAllOf) { | ||
var isBroken; | ||
for (var i in origAllOf) { | ||
isBroken = true; | ||
for (var j in newAllOf) { | ||
if (JSON.stringify(origAllOf[i]) == JSON.stringify(newAllOf[j])) isBroken = false; | ||
} | ||
if (isBroken) | ||
return { | ||
"isBroken": true, | ||
"$ref": origAllOf[i]["$ref"] | ||
} | ||
} | ||
|
||
return { | ||
"isBroken": false | ||
} | ||
} | ||
|
||
function isMetaExtendsBroken(metaExtends, newAllOf) { | ||
var allOfSchemas = []; | ||
for (var i in newAllOf) { | ||
if (newAllOf[i]["$ref"] && newAllOf[i]["$ref"].indexOf("#/definitions/") != 0 && newAllOf[i]["$ref"].indexOf("http") == 0) | ||
allOfSchemas.push(newAllOf[i]["$ref"]) | ||
} | ||
|
||
if (diff(metaExtends.sort(), allOfSchemas.sort())) { | ||
//console.log(diff(metaExtends.sort(), allOfSchemas.sort())) | ||
return true | ||
} else | ||
return false | ||
|
||
} | ||
|
||
function isPropertyRemoved(differences, brokenProperty) { | ||
for (var i in differences) { | ||
if (differences[i].kind == "D") { | ||
if (differences[i].path.indexOf("properties") != -1) { | ||
brokenProperty.name = differences[i].path.join("/").replace("../", ""); | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
function isFieldTypeChanged(differences, brokenProperty) { | ||
for (var i in differences) { | ||
if (differences[i].kind == "E") { | ||
if ((differences[i].path[differences[i].path.length - 1] == '$ref' && differences[i].path.indexOf("allOf") == -1) || | ||
(differences[i].path[differences[i].path.length - 1] == 'type' && jsonDataTypes.indexOf(differences[i].lhs.toLowerCase() != -1))) { | ||
brokenProperty.name = differences[i].path.join("/").replace("../", ""); | ||
return true; | ||
} | ||
|
||
} | ||
} | ||
return false; | ||
|
||
} | ||
|
||
|
||
function createError(err) { | ||
shell.rm("-rf", masterCopyLoc); | ||
throw (err); | ||
} |
103 changes: 103 additions & 0 deletions
103
extensions/adobe/experience/aam-experienceevent.example.1.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
{ | ||
"@id": "https://data.adobe.io/experienceid-123456", | ||
"xdm:dataSource": { | ||
"@id": "https://data.adobe.io/datasources/datasource-123", | ||
"xdm:code": "DataSourceIntegrationCode-123" | ||
}, | ||
"xdm:timestamp": "2017-09-26T15:52:25+00:00", | ||
"xdm:identityMap": { | ||
"https://data.adobe.io/entities/namespace/4": [ | ||
{ | ||
"xdm:id": "92312748749128" | ||
} | ||
], | ||
"https://data.adobe.io/entities/namespace/10": [ | ||
{ | ||
"xdm:id": "2394509340-30453470347" | ||
} | ||
], | ||
"https://data.adobe.io/entities/namespace/9": [ | ||
{ | ||
"xdm:id": "1233ce17-20e0-4a2c-8198-2a77fd60cf4d" | ||
} | ||
] | ||
}, | ||
"xdm:environment": { | ||
"xdm:type": "browser", | ||
"xdm:browserDetails": { | ||
"xdm:name": "Chrome", | ||
"xdm:version": "63.0.3239", | ||
"xdm:acceptLanguage": "en", | ||
"xdm:cookiesEnabled": true, | ||
"xdm:javaScriptEnabled": true, | ||
"xdm:javaScriptVersion": "1.8.5", | ||
"xdm:javaEnabled": true, | ||
"xdm:javaVersion": "Java SE 8", | ||
"xdm:viewportHeight": 900, | ||
"xdm:viewportWidth": 1680 | ||
}, | ||
"xdm:operatingSystem": "MAC OS", | ||
"xdm:operatingSystemVersion": "10.13", | ||
"xdm:connectionType": "cable" | ||
}, | ||
"xdm:placeContext": { | ||
"xdm:localTime": "2017-09-26T15:52:25+13:00", | ||
"xdm:geo": { | ||
"@id": "https://data.adobe.io/entities/geo/tokyo", | ||
"xdm:countryCode": "JP", | ||
"xdm:stateProvince": "JP-13", | ||
"xdm:city": "Tōkyō", | ||
"xdm:postalCode": "141-0032", | ||
"schema:latitude": 35.6185, | ||
"schema:longitude": 139.73237 | ||
} | ||
}, | ||
"xdm:profileStitch": [ | ||
{ | ||
"xdm:profileStitchID": { | ||
"@id": "https://data.adobe.io/entities/profileStitchIdentity/1", | ||
"xdm:namespace": { | ||
"xdm:code": "AAM" | ||
} | ||
}, | ||
"xdm:version": "1.0", | ||
"xdm:identityMap": { | ||
"ECID": [ | ||
{ | ||
"xdm:id": "https://data.adobe.io/entities/identity/92312748749128" | ||
}, | ||
{ | ||
"xdm:id": "https://data.adobe.io/entities/identity/62312748749321" | ||
}, | ||
{ | ||
"xdm:id": "https://data.adobe.io/entities/identity/49312748749132" | ||
} | ||
] | ||
} | ||
} | ||
], | ||
"xdm:segmentMemberships": [ | ||
{ | ||
"xdm:segmentID": { | ||
"@id": "https://data.adobe.io/entities/identity/92312748749128", | ||
"xdm:namespace": { | ||
"xdm:code": "AAM" | ||
} | ||
}, | ||
"xdm:profileStitchID": { | ||
"@id": "https://data.adobe.io/entities/profileStitchIdentity/1", | ||
"xdm:namespace": { | ||
"xdm:code": "AAM" | ||
}, | ||
"xdm:lastQualificationTime": "2017-09-26T15:52:25+00:00", | ||
"xdm:version": "1.0", | ||
"xdm:validUntil": "2017-12-26T15:52:25+00:00", | ||
"xdm:status": "realized" | ||
} | ||
} | ||
], | ||
"xdm:signals": { | ||
"pageTagCloud": ["analytics", "bigdata"], | ||
"pagelinkshovered": ["http://abcxyzabcxyz.com", "http://abcxyzabcxyz1.com"] | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
extensions/adobe/experience/aam-experienceevent.schema.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{ | ||
"meta:license": [ | ||
"Copyright 2018 Adobe Systems Incorporated. All rights reserved.", | ||
"This work is licensed under a Creative Commons Attribution 4.0 International (CC BY 4.0) license", | ||
"you may not use this file except in compliance with the License. You may obtain a copy", | ||
"of the License at https://creativecommons.org/licenses/by/4.0/" | ||
], | ||
"$id": "https://ns.adobe.com/experience/aam-experienceevent", | ||
"$schema": "http://json-schema.org/draft-06/schema#", | ||
"title": "Adobe Audience Manager Template Mixin", | ||
"type": "object", | ||
"description": "Adobe Audience Manager Mixin for use with Schemas for Solution data ingestion. Includes the core/standard ExperienceEvent as well as the other required Core mixins.", | ||
"meta:extensible": true, | ||
"meta:abstract": true, | ||
"meta:intendedToExtend": ["https://ns.adobe.com/xdm/context/experienceevent"], | ||
"meta:extends": [ | ||
"https://ns.adobe.com/xdm/context/experienceevent-segmentmembership", | ||
"https://ns.adobe.com/xdm/context/experienceevent-environment-details", | ||
"https://ns.adobe.com/xdm/context/experienceevent-profile-stitch", | ||
"https://ns.adobe.com/experience/audiencemanager/experienceevent-all" | ||
], | ||
"definitions": { | ||
"aam-experienceevent": { | ||
"properties": {} | ||
} | ||
}, | ||
"allOf": [ | ||
{ | ||
"$ref": "https://ns.adobe.com/xdm/context/experienceevent-segmentmembership" | ||
}, | ||
{ | ||
"$ref": "https://ns.adobe.com/xdm/context/experienceevent-environment-details" | ||
}, | ||
{ | ||
"$ref": "https://ns.adobe.com/xdm/context/experienceevent-profile-stitch" | ||
}, | ||
{ | ||
"$ref": "https://ns.adobe.com/experience/audiencemanager/experienceevent-all" | ||
}, | ||
{ | ||
"$ref": "#/definitions/aam-experienceevent" | ||
} | ||
], | ||
"meta:status": "experimental" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.