Code Monkey home page Code Monkey logo

playground's Introduction

Eclipse Thingweb logo with Playground

Playground

The place where you can create and play with WoT Thing Descriptions. Try it online at https://playground.thingweb.io/

Default CI & CD Pipeline CodeQL Discord npm Netlify Status

Installation

There are different ways to use Playground:

  • Install all packages and their dependencies via npm install in the root directory. This script calls lerna bootstrap.
  • You can install the different packages from npm (see below) or in their respective directories.

Structure

The structure of all Playground packages is shown here: packageStructure

All packages (except CLI and Web) are designed to be used as an imported package in a Node.js project or as a web bundle in a Web application. This allows them to be used in the Web package as part of a Web UI or inside the CLI.

  • The core package provides a function to check whether a Thing Description (TD) is valid according to the W3C WoT Thing Description standard. It uses the official JSON Schema plus additional scripts for aspects that cannot be checked with a JSON Schema alone. Used together with the assertions package, it allows to check whether all of the features of the TD standard are present in a single TD or a group of TDs representing an implementation.

Both packages are used by the Web and CLI packages to provide their functionalities, plus IO functionalities through a UI.

Packages

The packages in this repository are available under (packages folder) or on NPM under @thing-description-playground/packageName.

Reusable packages:

  • core: The core package provides a function to check whether a Thing Description (TD) is valid according to the W3C WoT Thing Description standard. It uses the official JSON Schema plus additional scripts for aspects that cannot be checked with a JSON Schema alone. It generates a JSON report of the validation results. NPM.
  • assertions: The assertions package allows to check whether all of the features of the TD standard are present in a single TD or a group of TDs representing an implementation. It needs to be used together with the core package since some features are detected by the core package. NPM.
  • defaults: The defaults package can be used to add or remove explicitly stated default values in a TD. It has no dependency to other playground packages. NPM.
  • td_to_openAPI: The Open API package allows to create an Open API instance from a Thing Description which has HTTP in the forms. It has no dependency to other playground packages.NPM.
  • td_to_asyncAPI: The Async API package allows to create an Async API instance from a Thing Description which has MQTT in the forms. It only depends on the defaults package to add defaults to a TD before generating the Async API instance. NPM.
  • json-spell-checker: The JSON Spell Checker package allows to find spelling mistakes (e.g. action instead of actions) in a JSON document according to its JSON Schema. Such JSON documents could be TDs, Open API specs etc. NPM.

End Product Packages:

  • cli: The CLI package wraps the above packages in a way they can be used from the command line. Additionally, it allows the functionalities of the other packages to be executed on a set of TDs. NPM.
  • web: The Web package wraps the above packages in a way they can be used from a browser interface. You can host/adapt your own browser version of the playground. It is online at https://playground.thingweb.io/NPM.

Examples

Examples are included in the core and in the examples folder at the root of the project.

Browser-based Thing Description Validation

  • Online: It is hosted here

    • Simply paste a TD in the text field and click validate
    • Safari browser has unexpected behavior with JSON-LD documents
    • If you lose your internet connection when validating JSON-LD validation will fail since it tries to access the documents under @context (can be turned off)
  • Offline/OnPremise: by hosting the web yourself. Therefore, please deliver the "index.html" file with a web-server.

Batch Testing

Please have a look at the cli package for batch testing of Thing Descriptions.

Script-based Assertion Tester

Please have a look at the cli package for script-based assertion testing, or at the assertions package, if you're planning to integrate the assertion testing as a dependency in your own NPM modules.

Script-based Thing Description Validation

Please have a look at the cli package for script-based TD validation, or at the core package, if you're planning to integrate the TD validation as a dependency in your own NPM modules.

License

All packages are licensed under the Eclipse Public License v. 2.0. You find a copy of the License here.

Publish a new version

  1. Run lerna bootstrap to install dependencies among the packages, even if a package has never been published before. Make sure you have not increased the dependency versions yet, e.g., you have a new package newExample and the oldExample depends on it. The newExample is on version 0.0.0 (since you want to publish it as 1.0.0) then in the oldExample package.json the dependency has to be on the same version (or lower) so "dependencies" { newExample: "^0.0.0"}}. Otherwise lerna will not accept linking the local newExample.
  2. If lerna bootstrap was successful you can now bump dependency versions (if required), e.g., you could now do "dependencies" { newExample: "^1.0.0"}} in the oldExample package.json.
  3. Run lerna publish to publish all the new package versions. Lerna will then ask for every changed package whether it received a patch, minor or major update. In our example, you should now select major for the newExample so that it will be published as 1.0.0 version. You should log in to npm via npm login before doing this.

Adapting Licenses

One can use the VS Code plugin at https://marketplace.visualstudio.com/items?itemName=angelo-breuer.license-header-manager to updating the copyright fields on top of each file.

playground's People

Contributors

adriankast avatar danielpeintner avatar dependabot[bot] avatar edbingo avatar egekorkan avatar eileenoo avatar fadysalama avatar fatadel avatar hasanheroglu avatar jkrhb avatar mmccool avatar ms-monika avatar relu91 avatar sergiocasceb avatar teckwan avatar vcharpenay avatar yagizyalcintas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

playground's Issues

False negative for multiLang

The following TD shows the error of multiLangConsistency even though all titles and descriptions have de language.

{
   "@context":[
      "https://www.w3.org/2019/wot/td/v1",
      {
         "cov":"http://www.example.org/coap-binding#"
      },
      {
         "saref":"https://w3id.org/saref#"
      }
   ],
   "securityDefinitions":{
      "basic_schema":{
         "scheme":"basic",
         "descriptions":{

         },
         "description":"Basic sec schema",
         "in":"query",
         "name":"querykey"
      }
   },
   "security":[
      "basic_schema"
   ],
   "@type":[
      "saref:LightSwitch"
   ],
   "titles":{
      "de":"Deutscher Titel"
   },
   "title":"English title",
   "descriptions":{
      "de":"Deutsche Beschreibung"
   },
   "description":"English description",
   "properties":{
      "echo":{
         "observable":false,
         "forms":[
            {
               "op":[
                  "readproperty"
               ],
               "href":"/echo",
               "contentType":"application/json"
            }
         ]
      }
   }
}

Merging of two exact assertion id

It can happen that two JSON Schemas for two assertions can have the same also field. For example, td-vocab-security--Thing and td-vocab-security--Form have both td-arrays_security in the also array. The results will have thus twice td-arrays_security. This needs to be handled

td-json-open assertion exists multiple times

Due to the multiple usage of td-json-open and child assertions of it (td-json-open_xyz) in both automatic and manual assertions it is not merged correctly, which results in 337 assertions if a single TD is assertion tested. If multiple TDs are under test, the result merge probably also merges the duplicates and 335 assertions are reported.

Offline validation appears to be broken

I tried to use the offline version for validation both in Safari and Chrome.
The page loads, the "clear log" button works,
however the validate button does not perform any action.

Change README

The section 'Script based Thing Description Validation' inside the README should be adjusted, because the path "./WebContent/Examples/Bundang/Valid/MyLampThing.jsonld" doesn't exist.

manual assertions only added?

Hi there! This is more of a question than an issue.
I'm wondering what the idea behind the manual.csv assertions is.
I was looking in the code. It appears to just append them to the results array. I find this a bit odd, the status column is null than.

Actions with a bug is validated correctly

The following TD was validated correctly, however, the actions definition is not correct:

{
    "@context": [
        "https://w3c.github.io/wot/w3c-wot-td-context.jsonld",
        "https://w3c.github.io/wot/w3c-wot-common-context.jsonld",
        {
            "iot": "http://iotschema.org/",
            "http": "http://www.w3.org/2011/http#"
        }
    ],
    "base": "http://159.203.213.90:1880",
    "id": "urn:uuid:c3068abb-7781-4ab4-9c0b-012408e9e758",
    "@type": [
        "Thing",
        "iot:MotionControl"
    ],
    "name": "Motion Sensor",
    "properties": {"MotionState": {
        "writable": false,
        "observable": true,
        "@type": [
            "Property",
            "iot:MotionDetected"
        ],
        "type": "array",
        "items": [{
            "type": "object",
            "properties": {
                "n": {
                    "type": "string",
                    "const": "5700"
                },
                "vb": {
                    "@type": ["iot:stateData"],
                    "type": "boolean"
                }
            }
        }],
        "forms": [
            {
                "href": "/3300/2",
                "mediaType": "application/json",
                "rel": "readProperty",
                "http:methodName": "GET"
            },
            {
                "href": "/3300/2",
                "mediaType": "application/json",
                "rel": "writeProperty",
                "http:methodName": "POST"
            },
            {
                "href": "mqtt://0m2m.net:1883/plugfest/subscriptions/Motion",
                "mediaType": "application/json",
                "rel": "observeProperty",
                "mqtt:commandCode": 8
            }
        ]
    }},
    "actions": {
        "connect": {"@type": ["mqtt:connect"]},
        "forms": [{
            "href": "mqtt://0m2m.net:1883",
            "mqtt:commandCode": 1
        }]
    }
}```

Cannot clear the console

After many validations, the console gets really full. There needs to be a button to clear console and a way to see the history of validations.

Dealing with prefixed JSON-LD Files

My assumption is that prefixed JSON-LD examples like the following should be valid.

{
  "@context": {
    "wot":"http://w3c.github.io/wot/w3c-wot-td-context.jsonld#",
    "td": "http://www.w3c.org/wot/td#",
    "xsd": "http://www.w3.org/2001/XMLSchema#",
    "sch": "http://schema.org"
  },
  "@type": "td:Thing",
  "wot:name":"echonet",
  "wot:interactions": [
       {
       "@type": "wot:Property",
       "wot:name": "operationStatus",
       "wot:valueType": { "@type": "xsd:boolean" },
       "wot:writable": true
      }
  ]
}

see https://github.com/w3c/wot/blob/master/proposals/td-lifecycle/Echonet_def0.jsonld

It seems the tool expects
"wot:name":"echonet"
to be
"name":"echonet"

et cetera...

TD missing namespace but still passes the validations on JSON-LD and TD/OWL

Following TD from Fujitsu does not define the namespace {"iot": "http://iotschema.org/"} for iot:Temperature, iot:Humidity, etc, but it passes all validations in http://plugfest.thingweb.io/playground/

{
"@context": ["https://w3c.github.io/wot/w3c-wot-td-context.jsonld"],
"@type": "Thing",
"name": "Fujitsu-WiFiAgent240AC4114764",
"id": "urn:dev:wot:com:fujitsu:wifiagent",
"base" : "http://192.168.1.21/Things/Property/",
"properties": {
"Temperature": {
"@type": "iot:Temperature",
"type": "object",
"properties": {
"temperature":{"type":"number"},
"rssi":{"type":"number"}
},
"writable": false,
"observable": false,
"forms": [{
"href" : "temperature",
"mediaType": "application/json"
}]
},
"Humidity": {
"@type": "iot:Humidity",
"type": "object",
"properties": {
"humidity":{"type":"number"},
"rssi":{"type":"number"}
},
"writable": false,
"observable": false,
"forms": [{
"href" : "humidity",
"mediaType": "application/json"
}]
},
"AirPressure": {
"@type": "iot:AirPressure",
"type": "object",
"properties": {
"airPressure":{"type":"number"},
"rssi":{"type":"number"}
},
"writable": false,
"observable": false,
"forms": [{
"href" : "airPressure",
"mediaType": "application/json"
}]
},
"Dust": {
"@type": "iot:Dust",
"type": "object",
"properties": {
"dust":{"type":"number"},
"rssi":{"type":"number"}
},
"writable": false,
"observable": false,
"forms": [{
"href" : "dust",
"mediaType": "application/json"
}]
},
"AllSensorData": {
"@type":"iot:AllSensor",
"type": "object",
"properties": {
"temperature":{"type":"number"},
"humidity":{"type":"number"},
"airPressure":{"type":"number"},
"dust":{"type":"number"},
"rssi":{"type":"number"}
},
"writable": false,
"observable": false,
"forms": [{
"href" : "allSensorData",
"mediaType": "application/json"
}]
}
},
"actions":{},
"events":{}
}

Console text is not wrapped

Since the error messages can be long sometimes, the text containing the error message should be wrapped in the console to match the width of the console

Wrong assertions

td-vocab-title--DataSchema.json and td-vocab-description--DataSchema.json are wrong, they don't cover the possibility of having title or description as a property name

Submit TD as gist feature

On the playground should be a button "submit as gist", which allows submitting the TD being edited to the Thingweb Github account. Unless other advise I would implement:

  • GOOD: an node.js script listening on a port which accepts Description+Name as input, does the request to the GitHub API, responses with Status and the gist ID.
    + The private API Token can be kept secret
    - The script needs to be hosted by an node.js environment on the playground/another server
  • Alternative: The request is made directly in the playground web script. This would allow extraction of the API key, which can be used to create/update/delete all Gists of the account.
    In both cases the API Token will be inserted by a CD process and not visible in the repository.

JSON Schema validation error without mandatory security vocabulary term with default

JSON Schema validation error occurs at securityDefinitions, when mandatory vocabularies defined at https://w3c.github.io/wot-thing-description/#sec-security-vocabulary-definition is omitted, even if the default value is defined at https://w3c.github.io/wot-thing-description/#json-serializiation-section.

For example, following fails:

  "securityDefinitions": {"bearer_sc": {
    "scheme": "bearer",
    "format": "jwt",
    "alg": "ES256",
    "authorization": "https://w3c.p-wot.com:8443/auth"
  }},
  "security": ["bearer_sc"],

with error message:

> data.securityDefinitions['bearer_sc'].scheme should be equal to one of the allowed values, data.securityDefinitions['bearer_sc'].scheme should be equal to one of the allowed values, data.securityDefinitions['bearer_sc'].scheme should be equal to one of the allowed values, data.securityDefinitions['bearer_sc'].scheme should be equal to one of the allowed values, data.securityDefinitions['bearer_sc'] should have required property 'in', data.securityDefinitions['bearer_sc'].scheme should be equal to one of the allowed values, data.securityDefinitions['bearer_sc'].scheme should be equal to one of the allowed values, data.securityDefinitions['bearer_sc'].scheme should be equal to one of the allowed values, data.securityDefinitions['bearer_sc'].scheme should be equal to one of the allowed values, data.securityDefinitions['bearer_sc'].scheme should be equal to one of the allowed values, data.securityDefinitions['bearer_sc'] should match exactly one schema in oneOf

while following passes:

  "securityDefinitions": {"bearer_sc": {
    "scheme": "bearer",
    "in": "header", 
    "format": "jwt",
    "alg": "ES256",
    "authorization": "https://w3c.p-wot.com:8443/auth"
  }},
  "security": ["bearer_sc"],

Editor window is pretty small on displays with high resolution

As the title states the editor window is pretty small for displays with high resolution with a pretty large unused white bar at the lower display part (see screenshots). Would it be possible to make the editor window variable in size or adapt the editor size to the display resolution? Maybe it would also be a possibility to adapt the layout to a column layout with the TD on the left and the options and validation output on the right side. These screenshot were taken with a display resolution of 1440x2560 (first) and 3840 ร— 2160 Pixel (second).
image
image

Open API generation

It should be possible to automatically generate an OpenAPI description of a Thing by using the Thing Description as input.
This description can be used to visualize an API view of a Thing and extend tool support by importing it e.g. to postman.

Functionalities should be added stepwise:

  • url + method based path generation
  • names transfer (title, description, ...)
  • generate example payloads
  • add tests in postman

Is developed under: https://github.com/adriankast/thingweb-playground/tree/openAPI

New Assertions after Princeton Testfest

Placeholder for new assertions to test

  • @context and @type in data schema and security
  • td-data-schema-object
  • When the value of readOnly member is true in an instance of PropertyAffordance, the value(s) in the op term member of the forms MUST NOT contain writeproperty. Similarly, when the value of writeOnly member is true in an instance of PropertyAffordance, the value(s) in the op term member of the forms MUST NOT contain readproperty.
  • td-ns assertions: these are about checking whether the different keys in a context object are unique and whether the context links are refereancable

@context checking too restrictive/false

Hi,

some examples that fail

Example 1

"@context": {
		"iot": "http://iotschema.org/"
}

Message: data['@context'] should be array, data['@context'] should be string, data['@context'] should be equal to one of the allowed values, data['@context'] should match exactly one schema in oneOf

Example 2

"@context": [{"iot": "http://example.org/iot"}]

Failure Message: > data['@context'][0] should be string, data['@context'][0] should be equal to one of the allowed values, data['@context'] should contain a valid item, data['@context'] should be string, data['@context'] should be equal to one of the allowed values, data['@context'] should match exactly one schema in oneOf

The assumption seems to be that it is always in the following way

"@context": ["http://www.w3.org/ns/td",
                {"iot": "http://example.org/iot"}]

Even the order seems to count... for example changing the order gives an error for

"@context": [{"iot": "http://example.org/iot"}, "http://www.w3.org/ns/td"]

"http://www.w3.org/ns/td" needs to come first to be valid.. i don't think these restrictions are necessary

Typo checks

I fed in a Thing Description with a typo in the description keyword (which was desciption), and it was validated to Ok. Is that an intended behaviour?

Validation of href vs base

@egekorkan So far, no validation is be done for a relative provided href and base URI. Also the correct "/" has to be checked.
E.g., "base":"http://test-example.net" and "href":""test" is not correct since there is a "/" missing at the begin of href or end of the base uri

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.