-
Notifications
You must be signed in to change notification settings - Fork 63
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
4 changed files
with
285 additions
and
0 deletions.
There are no files selected for viewing
95 changes: 95 additions & 0 deletions
95
proposals/initial-connection/tooling/schema-new.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,95 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"type":"object", | ||
"definitions": { | ||
"singleSecurityDefinition":{ | ||
"type":"object", | ||
"properties": { | ||
"scheme":{ | ||
"type":"string" | ||
} | ||
} | ||
}, | ||
"singleConnectionDefinition": { | ||
"type": "object", | ||
"properties": { | ||
"base": { | ||
"type": "string" | ||
} | ||
} | ||
}, | ||
"singleFormDefinition": { | ||
"type": "object", | ||
"properties": { | ||
"contentType": { | ||
"type": "string" | ||
}, | ||
"connection":{ | ||
"$ref": "#/definitions/singleConnectionDefinition" | ||
} | ||
} | ||
}, | ||
"singleSchemaDefinition": { | ||
"type": "object" | ||
} | ||
}, | ||
"properties": { | ||
"security": { | ||
"oneOf": [ | ||
{ | ||
"$ref": "#/definitions/singleSecurityDefinition" | ||
}, | ||
{ | ||
"type": "string", | ||
"$comment": "Reference to a securityDefinitions object key" | ||
} | ||
] | ||
}, | ||
"form": { | ||
"oneOf": [ | ||
{ | ||
"$ref": "#/definitions/singleFormDefinition" | ||
}, | ||
{ | ||
"type": "string", | ||
"$comment": "Reference to a formDefinitions object key" | ||
} | ||
] | ||
}, | ||
"connection": { | ||
"oneOf": [ | ||
{ | ||
"$ref": "#/definitions/singleConnectionDefinition" | ||
}, | ||
{ | ||
"type": "string", | ||
"$comment": "Reference to a connectionDefinitions object key" | ||
} | ||
] | ||
}, | ||
"securityDefinitions": { | ||
"type": "object", | ||
"additionalProperties": { | ||
"$ref": "#/definitions/singleSecurityDefinition" | ||
} | ||
}, | ||
"connectionDefinitions": { | ||
"type": "object", | ||
"additionalProperties": { | ||
"$ref": "#/definitions/singleConnectionDefinition" | ||
} | ||
}, | ||
"formDefinitions": { | ||
"type": "object", | ||
"additionalProperties": { | ||
"$ref": "#/definitions/singleFormDefinition" | ||
} | ||
}, | ||
"schemaDefinitions": { | ||
"type": "object", | ||
"additionalProperties": { | ||
"$ref": "#/definitions/singleSchemaDefinition" | ||
} | ||
} | ||
} | ||
} |
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,16 @@ | ||
// Takes a TD with initial connection information and transforms it to a TD 1.1 | ||
|
||
const tdInput = {}; | ||
let tdOutput = {}; | ||
|
||
// Find if there is a default in the root level | ||
|
||
if (Object.hasOwn(tdInput,"form")){ | ||
const defaultForm = tdInput.form; | ||
|
||
} | ||
|
||
// Go into the forms and try to find each reference or inline | ||
|
||
// separating inline security to secDef -> create sec1 as object key | ||
// separating inline schema to schema definitions -> create schema1 as object key |
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,137 @@ | ||
// TDs are provided as js so that we can put comments | ||
// However, please do not remove JSON serialization so that they can be copy pasted easily | ||
|
||
const validTDs = [ | ||
// Inline (no definitions objects) | ||
// Separate Defaults | ||
{ | ||
"title": "test1", | ||
"connection":{ | ||
"base": "https://example.com" | ||
}, | ||
"form":{ | ||
"contentType":"application/json" | ||
}, | ||
"security":{ | ||
"scheme":"nosec" | ||
}, | ||
"properties": { | ||
"prop1": { | ||
"type":"string", | ||
"forms": [ | ||
{ | ||
"href": "/props/prop1" | ||
} | ||
] | ||
}, | ||
"prop2": { | ||
"type":"string", | ||
"forms": [ | ||
{ | ||
"href": "/props/prop2" | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
// All Defaults in a Form but still with connection | ||
{ | ||
"title": "test2", | ||
"form":{ | ||
"contentType":"application/json", | ||
"connection":{ | ||
"base": "https://example.com", | ||
"security":{ | ||
"scheme":"nosec" | ||
} | ||
} | ||
}, | ||
"properties": { | ||
"prop1": { | ||
"type":"string", | ||
"forms": [ | ||
{ | ||
"href": "/props/prop1" | ||
} | ||
] | ||
}, | ||
"prop2": { | ||
"type":"string", | ||
"forms": [ | ||
{ | ||
"href": "/props/prop2" | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
// All defaults in a form and flattened without connection | ||
{ | ||
"title": "test3", | ||
"form":{ | ||
"contentType":"application/json", | ||
"base": "https://example.com", | ||
"security":{ | ||
"scheme":"nosec" | ||
} | ||
}, | ||
"properties": { | ||
"prop1": { | ||
"type":"string", | ||
"forms": [ | ||
{ | ||
"href": "/props/prop1" | ||
} | ||
] | ||
}, | ||
"prop2": { | ||
"type":"string", | ||
"forms": [ | ||
{ | ||
"href": "/props/prop2" | ||
} | ||
] | ||
} | ||
} | ||
} | ||
] | ||
|
||
|
||
|
||
// TODO: Invalid TDs are not detected yet | ||
const invalidTDs = [ | ||
// Inline (no definitions objects) | ||
// Missing Connection | ||
{ | ||
"title": "test1", | ||
"form": { | ||
"contentType": 123 // FIXME: Put correct string value here | ||
}, | ||
"security": { | ||
"scheme": "nosec" | ||
}, | ||
"properties": { | ||
"prop1": { | ||
"type": "string", | ||
"forms": [ | ||
{ | ||
"href": "/props/prop1" | ||
} | ||
] | ||
}, | ||
"prop2": { | ||
"type": "string", | ||
"forms": [ | ||
{ | ||
"href": "/props/prop2" | ||
} | ||
] | ||
} | ||
} | ||
} | ||
]; | ||
|
||
module.exports = { | ||
validTDs, | ||
invalidTDs, | ||
}; |
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,37 @@ | ||
const fs = require("fs"); | ||
const assert = require("assert"); | ||
const { validTDs, invalidTDs } = require("./tds"); | ||
const Ajv = require("ajv"); | ||
|
||
const tdSchema = fs.readFileSync("schema-new.schema.json"); | ||
const ajv = new Ajv({ | ||
strict: false, | ||
addUsedSchema: false, | ||
formats: { | ||
// Do not validate the following formats. | ||
// In the future we could provide a custom checking function for these formats | ||
"uri-reference": true, | ||
"json-pointer": true, | ||
uri: true, | ||
"date-time": true, | ||
}, | ||
}); | ||
|
||
describe("Thing Description Confirmation", () => { | ||
|
||
for (const [id, td] of validTDs.entries()) { | ||
it(`should validate n° ${id}`, () => { | ||
const valid = ajv.validate(JSON.parse(tdSchema), td); | ||
assert.equal(valid, true, ajv.errorsText()); | ||
}); | ||
} | ||
}); | ||
|
||
describe("Thing Description Rejection", () => { | ||
for (const [id, td] of invalidTDs.entries()) { | ||
it(`should NOT validate n° ${id}`, () => { | ||
const valid = ajv.validate(JSON.parse(tdSchema), td); | ||
assert.equal(valid, false, ajv.errorsText()); | ||
}); | ||
} | ||
}); |