-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from hasanheroglu/26-move-json-spell-checker
26 move json spell checker
- Loading branch information
Showing
12 changed files
with
12,756 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
name: JSON Spell Checker CI Pipeline | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
paths: | ||
- "node/json-spell-checker/**" | ||
pull_request: | ||
branches: [main] | ||
paths: | ||
- "node/json-spell-checker/**" | ||
workflow_dispatch: | ||
|
||
defaults: | ||
run: | ||
working-directory: node/json-spell-checker | ||
|
||
jobs: | ||
setup-and-test: | ||
name: Tests (${{ matrix.os }}, Node ${{ matrix.node-version }}) | ||
runs-on: ${{ matrix.os }} | ||
|
||
strategy: | ||
matrix: | ||
os: [ubuntu-latest] | ||
node-version: [18.x, 20.x] | ||
|
||
timeout-minutes: 30 | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Use Node.js ${{ matrix.os }} ${{ matrix.node-version }} | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
cache: "npm" | ||
|
||
- name: Install Dependencies | ||
run: npm ci | ||
|
||
- name: Test | ||
timeout-minutes: 10 | ||
run: npm run test:coverage | ||
|
||
- name: Upload to codecov.io | ||
uses: codecov/codecov-action@v4 | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} | ||
file: coverage/lcov.info | ||
verbose: true |
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,64 @@ | ||
# Eclipse Thingweb - JSON Spell Checker | ||
|
||
This package provides spell-checking support for JSON files when a JSON Schema is given. | ||
|
||
Limitations: | ||
|
||
- There is limited nested spell-checking. Some of the $ref definitions can be nested infinitely. Therefore, spell-checking stops when recursive nesting is first detected. | ||
- This tool is mainly developed for Thing Descriptions. Even though it can be used for all JSON Schemas, it may not cover all schema rules. For example 'if, else, then' rule of Open API schema is not supported yet, but this functionality could be added in the future. | ||
|
||
## License | ||
|
||
Licensed under the MIT license, see [License](../../LICENSE.md). | ||
|
||
## Script-based Spell Checking | ||
|
||
JSON spell checker is a Node.js based tool. | ||
|
||
You can use the functionality of this package by: | ||
|
||
- Install the package with npm `npm install @thing-description-playground/json-spell-checker` (or clone the repo and install the package with `npm install`) | ||
- Node.js or Browser | ||
|
||
- Node.js: Require the package and use the validation function | ||
|
||
```javascript | ||
const jsonSpellChecker = require("@thing-description-playground/json-spell-checker"); | ||
``` | ||
|
||
- Browser: Import the `JsonSpellChecker` as a global by adding a script tag to your HTML. | ||
|
||
```html | ||
<script src="./node_modules/@thing-description-playground/json-spell-checker/dist/web-bundle.min.js"></script> | ||
``` | ||
|
||
- First, configure your spell checker using (similarityThreshold should be between 0 and 1 and try to set maxLengthDifference low if you need quick typo evaluation): | ||
|
||
```javascript | ||
jsonSpellChecker.configure(yourSchema, similarityThreshold, maxLengthDifference); | ||
``` | ||
|
||
- Or just set schema and use default values for similarityThreshold (0.85) and maxLengthDifference (2) | ||
|
||
```javascript | ||
jsonSpellChecker.configure(yourSchema); | ||
``` | ||
|
||
- Then call checkTypos function with your stringified JSON file to find typos | ||
|
||
```javascript | ||
jsonSpellChecker.checkTypos(stringifiedJsonFile); | ||
``` | ||
|
||
### Structure | ||
|
||
The [index.js](./src/index.js) file contains the main validation functionality and exports the module's functionalities. | ||
|
||
## Examples | ||
|
||
- There are also examples provided in the [examples-scripts folder](./examples/scripts/) to demonstrate the usage of this package. | ||
|
||
## Test Usage | ||
|
||
Test Examples are located under the examples directory. | ||
When preparing TD examples, you must fill in the 'typoCount' field corresponding to the number of typos in the TD. |
48 changes: 48 additions & 0 deletions
48
node/json-spell-checker/examples/json/open-api-example.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,48 @@ | ||
{ | ||
"ope2napi": "3.1.0", | ||
"info": { | ||
"ti2tle": "Webhook Example", | ||
"versiomn": "1.0.0" | ||
}, | ||
"webhoks": { | ||
"newPet": { | ||
"post": { | ||
"requestBody": { | ||
"description": "Information about a new pet in the system", | ||
"content": { | ||
"application/json": { | ||
"schema": { | ||
"$ref": "#/components/schemas/Pet" | ||
} | ||
} | ||
} | ||
}, | ||
"responses": { | ||
"200": { | ||
"description": "Return a 200 status to indicate that the data was received successfully" | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"components": { | ||
"shemas": { | ||
"Pet": { | ||
"required": ["id", "name"], | ||
"properties": { | ||
"id": { | ||
"type": "integer", | ||
"format": "int64" | ||
}, | ||
"name": { | ||
"type": "string" | ||
}, | ||
"tag": { | ||
"type": "string" | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"typoCount": 5 | ||
} |
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,83 @@ | ||
{ | ||
"id2": "urn:formOpArrayWithDefaults", | ||
"@co3ntext": "https://www.w3.org/2022/wot/td/v1.1", | ||
"titlve": "MyLampThing", | ||
"descbription": "Valid TD demonstrating how to use multiple forms with different op", | ||
"securnityDefinitions": { | ||
"basic_sc": { | ||
"scheme": "basic", | ||
"in": "header" | ||
} | ||
}, | ||
"securimty": ["basic_sc"], | ||
"properties": { | ||
"brightness": { | ||
"ddescription": "The current brightness setting", | ||
"tyfpe": "integer", | ||
"mingimum": -64, | ||
"maximum": 64, | ||
"observable": true, | ||
"readOnly": false, | ||
"writeOnly": false, | ||
"forms": [ | ||
{ | ||
"hresf": "http://example.org:9191/api/brightness", | ||
"op": ["readproperty"], | ||
"contentType": "application/json" | ||
}, | ||
{ | ||
"href": "http://example.org:9191/api/brightness", | ||
"op": ["writeproperty"], | ||
"htv:methodName": "POST", | ||
"contentType": "application/json" | ||
}, | ||
{ | ||
"href": "http://example.org:9191/api/brightness/observe", | ||
"op": ["observeproperty"], | ||
"htv:methodName": "GET", | ||
"subprotocol": "websub", | ||
"contentType": "application/json" | ||
}, | ||
{ | ||
"href": "http://example.org:9191/api/brightness/unobserve", | ||
"op": ["unobserveproperty"], | ||
"htv:methodName": "GET", | ||
"subprotocol": "websub", | ||
"contentType": "application/json" | ||
} | ||
] | ||
} | ||
}, | ||
"actions": { | ||
"toggle": { | ||
"safe": false, | ||
"idempotent": false, | ||
"forms": [ | ||
{ | ||
"href": "https://mylamp.example.com/toggle", | ||
"op": ["invokeaction"], | ||
"contentType": "application/json" | ||
} | ||
] | ||
} | ||
}, | ||
"events": { | ||
"overheating": { | ||
"data": { | ||
"type": "string", | ||
"readOnsly": true, | ||
"writeOnly": false, | ||
"observable": false | ||
}, | ||
"forms": [ | ||
{ | ||
"href": "https://mylamp.example.com/oh", | ||
"subprotocol": "longpoll", | ||
"op": ["subscribeevent"], | ||
"contentType": "application/json" | ||
} | ||
] | ||
} | ||
}, | ||
"typoCount": 15 | ||
} |
Oops, something went wrong.