Skip to content

Commit

Permalink
new schema structure (#65)
Browse files Browse the repository at this point in the history
* new schema structure
quicktypeUtils update
npm scripts update

* PR feedback

* cleanup

* typos

* fix type generation folder

* Fixed schema structures

* copy schemas to website

* package json update

* removed defunct file

* make sources optional

* cleanup

* Update schemas/bridging/raiseIntentResultResponse.schema.json

Co-authored-by: Kris West <kris@cosaic.io>

* cleanup

* regenerated types

* PR feedback

* Fixe meta for requests

* Apply suggestions from code review

* Regenerating bridging typescript

* Apply suggestions from code review

* adjust OptionalFeatures and IntentResult schemas

---------

Co-authored-by: Kris West <kris@cosaic.io>
  • Loading branch information
tpina and kriswest authored Apr 25, 2023
1 parent 6830c73 commit 37d2f53
Show file tree
Hide file tree
Showing 102 changed files with 4,230 additions and 117 deletions.
1 change: 1 addition & 0 deletions docs/api-bridging/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ Response messages will be differentiated from requests by the presence of a `met
* to the bridge before the timeout or because an error occurred.
* Should be the same length as the `errorSources` array and ordered the
* same. May be omitted if all sources responded. */

errorDetails?: string[]
}
}
Expand Down
3 changes: 3 additions & 0 deletions docs/api/ref/Metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,9 @@ interface ImplementationMetadata {
* `fdc3.getCurrentChannel` and `fdc3.leaveCurrentChannel` are implemented by
* the Desktop Agent.*/
"UserChannelMembershipAPIs": boolean;
/** Used to indicate whether the experimental Desktop Agent Bridging
* feature is implemented by the Desktop Agent.*/
DesktopAgentBridging: boolean;
};

/** The calling application instance's own metadata, according to the
Expand Down
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.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@
},
"scripts": {
"start": "tsdx watch",
"prebuild": "npm run typegen && npm run typegen-bridging",
"build": "tsdx build",
"test": "tsdx test --verbose",
"lint": "tsdx lint src/api test",
"preprepare": "npm run typegen && npm run typegen-bridging",
"prepare": "tsdx build",
"typegen": "node quicktypeUtil.js src/context/schemas src/context/ContextTypes.ts && tsdx lint src/context --fix"
"typegen": "node quicktypeUtil.js schemas/context src/context/ContextTypes.ts && tsdx lint src/context/ --fix",
"typegen-bridging": "node quicktypeUtil.js schemas/api schemas/bridging schemas/context/context.schema.json src/bridging/BridgingTypes.ts && tsdx lint src/bridging/ --fix"
},
"peerDependencies": {},
"husky": {
Expand Down
54 changes: 34 additions & 20 deletions quicktypeUtil.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,51 @@
/** Utility for preparing arguments to quicktype, which workaround a specific
* quicktype bug in command line argument handling (where a directory is used
/** Utility for preparing arguments to quicktype, which workaround a specific
* quicktype bug in command line argument handling (where a directory is used
* as input the source language argument is ignored which causes our schemas
* to be interpreted as JSON input, rather than JSONSchema).
* Bug issue:
* Bug issue:
* */

const path = require('path');
const fs = require('fs');
const exec = require('child_process').exec;

const args = process.argv;
const inputFolder = args[2]
const outputFile = args[3];
const args = process.argv.slice(2);
const outputFile = args.pop();
const inputs = args;

console.log("Input folder argument: " + inputFolder);
console.log("Output file argument: " + outputFile);
console.log('Inputs: ' + inputs.join(' | '));
console.log('Output file argument: ' + outputFile);

let srcs = "";
fs.readdirSync(inputFolder).forEach(file => {
srcs += `--src ${path.join(inputFolder, file)} `;
});
let sources = '';

let dirIndex = 0;

while (dirIndex < inputs.length) {
if (inputs[dirIndex].endsWith('.schema.json')) {
sources += `--src ${path.join(inputs[dirIndex])} `;
} else {
fs.readdirSync(inputs[dirIndex], { withFileTypes: true }).forEach(file => {
if (file.isDirectory()) {
inputs.push(path.join(inputs[dirIndex], file.name));
} else {
sources += `--src ${path.join(inputs[dirIndex], file.name)} `;
}
});
}
dirIndex++;
}

// Normalise path to local quicktype executable.
const quicktypeExec = ['.', 'node_modules', '.bin', 'quicktype'].join(path.sep);

const command = `${quicktypeExec} -s schema -o ${outputFile} ${srcs}`;
console.log("command to run: " + command);
const command = `${quicktypeExec} -s schema -o ${outputFile} ${sources}`;
console.log('command to run: ' + command);

exec(command, function(error, stdout, stderr) {
if (stdout) {
console.log(stdout);
}
if (stderr) {
console.log(stderr);
}
if (stdout) {
console.log(stdout);
}
if (stderr) {
console.log(stderr);
}
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://fdc3.finos.org/schemas/next/appIdentifier.schema.json",
"$id": "https://fdc3.finos.org/schemas/next/api/appIdentifier.schema.json",
"title": "AppIdentifier",
"description": "Identifies an application, or instance of an application, and is used to target FDC3 API calls at specific applications.",
"type": "object",
Expand All @@ -10,10 +10,13 @@
},
"instanceId": {
"type": "string"
},
"desktopAgent": {
"type": "string"
}
},
"required": [
"appId"
],
"additionalProperties": false
"unevaluatedProperties": false
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://fdc3.finos.org/schemas/next/appIntent.schema.json",
"$id": "https://fdc3.finos.org/schemas/next/api/appIntent.schema.json",
"title": "AppIntent",
"description": "Represents the binding of an intent to apps",
"type": "object",
"properties": {
"intent": {
"$ref": "https://fdc3.finos.org/schemas/next/intentMetadata.schema.json"
"$ref": "intentMetadata.schema.json"
},
"apps": {
"type": "array",
"items": {
"$ref": "https://fdc3.finos.org/schemas/next/appMetadata.schema.json"
"$ref": "appMetadata.schema.json"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://fdc3.finos.org/schemas/next/appMetadata.schema.json",
"$id": "https://fdc3.finos.org/schemas/next/api/appMetadata.schema.json",
"title": "AppMetadata",
"description": "Extends an AppIdentifier, describing an application or instance of an application.",
"type": "object",
"allOf": [
{
"$ref": "appIdentifier.schema.json"
}
],
"properties": {
"appId": {
"type": "string"
},
"instanceId": {
"type": "string"
},
"appId": true,
"instanceId": true,
"desktopAgent": true,
"name": {
"type": "string"
},
Expand All @@ -32,13 +34,13 @@
"icons": {
"type": "array",
"items": {
"$ref": "https://fdc3.finos.org/schemas/next/icon.schema.json"
"$ref": "icon.schema.json"
}
},
"screenshots": {
"type": "array",
"items": {
"$ref": "https://fdc3.finos.org/schemas/next/image.schema.json"
"$ref": "image.schema.json"
}
},
"resultType": {
Expand All @@ -48,8 +50,5 @@
]
}
},
"additionalProperties": false,
"required": [
"appId"
]
"additionalProperties": false
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://fdc3.finos.org/schemas/next/channel.schema.json",
"$id": "https://fdc3.finos.org/schemas/next/api/channel.schema.json",
"title": "Channel",
"description": "Represents a context channel that applications can join to share context data.",
"type": "object",
Expand All @@ -17,7 +17,7 @@
]
},
"displayMetadata": {
"$ref": "https://fdc3.finos.org/schemas/next/displayMetadata.schema.json"
"$ref": "displayMetadata.schema.json"
}
},
"required": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://fdc3.finos.org/schemas/next/contextMetadata.schema.json",
"$id": "https://fdc3.finos.org/schemas/next/api/contextMetadata.schema.json",
"title": "ContextMetadata",
"description": "Metadata relating to a context or intent & context received through the addContextListener and addIntentListener functions.",
"type": "object",
"properties": {
"source": {
"$ref": "https://fdc3.finos.org/schemas/next/appIdentifier.schema.json"
"$ref": "appIdentifier.schema.json"
}
},
"required": [
Expand Down
16 changes: 16 additions & 0 deletions schemas/api/desktopAgentIdentifier.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://fdc3.finos.org/schemas/next/api/desktopAgentIdentifier.schema.json",
"title": "DesktopAgentIdentifier",
"description": "Identifies a particular Desktop Agent. Used by Desktop Agent Bridging to indicate the source or destination of a message which was produced by or should be processed by the Desktop Agent itself rather than a specific application. Often added to messages by the Desktop Agent Bridge.",
"type": "object",
"properties": {
"desktopAgent": {
"type": "string"
}
},
"required": [
"desktopAgent"
],
"additionalProperties": false
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://fdc3.finos.org/schemas/next/displayMetadata.schema.json",
"$id": "https://fdc3.finos.org/schemas/next/api/displayMetadata.schema.json",
"title": "DisplayMetadata",
"description": "A desktop agent (typically for user channels) may want to provide additional information about how a channel can be represented in a UI. A common use case is for color linking.",
"type": "object",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://fdc3.finos.org/schemas/next/errors.schema.json",
"$id": "https://fdc3.finos.org/schemas/next/api/errors.schema.json",
"definitions": {
"OpenError": {
"type": "string",
Expand All @@ -9,7 +9,8 @@
"AppNotFound",
"ErrorOnLaunch",
"AppTimeout",
"ResolverUnavailable"
"ResolverUnavailable",
"DesktopAgentNotFound"
]
},
"ResolveError": {
Expand All @@ -22,7 +23,8 @@
"ResolverTimeout",
"TargetAppUnavailable",
"TargetInstanceUnavailable",
"IntentDeliveryFailed"
"IntentDeliveryFailed",
"DesktopAgentNotFound"
]
},
"ResultError": {
Expand All @@ -41,6 +43,15 @@
"AccessDenied",
"CreationFailed"
]
},
"BridgingError": {
"type": "string",
"description": "Contains constants representing the errors that can be encountered by Desktop Agents when exchanging bridging messages.",
"enum": [
"ResponseToBridgeTimedOut",
"AgentDisconnected",
"NotConnectedToBridge"
]
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://fdc3.finos.org/schemas/next/icon.schema.json",
"$id": "https://fdc3.finos.org/schemas/next/api/icon.schema.json",
"title": "Icon",
"description": "Metadata relating to a single icon image at a remote URL, used to represent an application in a user interface.",
"type": "object",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://fdc3.finos.org/schemas/next/image.schema.json",
"$id": "https://fdc3.finos.org/schemas/next/api/image.schema.json",
"title": "Image",
"description": "Metadata relating to a single image at a remote URL, used to represent screenshot images.",
"type": "object",
Expand Down
47 changes: 47 additions & 0 deletions schemas/api/implementationMetadata.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://fdc3.finos.org/schemas/next/api/implementationMetadata.schema.json",
"title": "ImplementationMetadata",
"description": "Metadata relating to the FDC3 DesktopAgent object and its provider",
"type": "object",
"properties": {
"fdc3Version": {
"type": "string"
},
"provider": {
"type": "string"
},
"providerVersion": {
"type": "string"
},
"optionalFeatures": {
"type": "object",
"properties": {
"OriginatingAppMetadata": {
"type": "boolean"
},
"UserChannelMembershipAPIs": {
"type": "boolean"
},
"DesktopAgentBridging": {
"type": "boolean"
}
},
"required": [
"OriginatingAppMetadata",
"UserChannelMembershipAPIs"
],
"additionalProperties": false
},
"appMetadata": {
"$ref": "appMetadata.schema.json"
}
},
"required": [
"fdc3Version",
"provider",
"optionalFeatures",
"appMetadata"
],
"additionalProperties": false
}
Loading

0 comments on commit 37d2f53

Please sign in to comment.