Skip to content

Commit 844a0b8

Browse files
committed
Added conversion script for JSON schmea to openapi3
1 parent fbfd106 commit 844a0b8

File tree

3 files changed

+78
-17
lines changed

3 files changed

+78
-17
lines changed

jsonschema/README.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## 1. Validate and clean up JSON-schema
2+
https://www.jsonschemavalidator.net/
3+
4+
## 2. Install requirements
5+
```
6+
npm install --save json-schema-to-openapi-schema
7+
```
8+
9+
## 3. Edit
10+
Edit convert.js on line 3 (filepath = to be towards the file path)
11+
12+
## 4. Run convert.js
13+
```
14+
node convert.js
15+
```

jsonschema/alienvault.json

+28-17
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,28 @@
1-
[{
1+
{
2+
"$schema": "http://json-schema.org/draft-04/schema",
3+
"additionalProperties": false,
4+
"required": ["count", "next", "results", "previous"],
5+
"properties": {
6+
"count": {"type": "integer"},
7+
"next": {"type": ["string", "null"]},
8+
"results": {
9+
"type": "array",
10+
"items": {
11+
"additionalProperties": false,
12+
"required": ["indicator", "title", "content", "type", "id", "description"],
13+
"properties": {
14+
"indicator": {"type": "string"},
15+
"title": {"type": ["string", "null"]},
16+
"content": {"type": ["string", "null"]},
17+
"type": {"type": "string"},
18+
"id": {"type": "integer"},
19+
"description": {"type": ["string", "null"]}
20+
}
21+
}
22+
},
23+
"previous": {"type": ["string", "null"]}
24+
},
25+
{
226
"count": 3,
327
"next": null,
428
"results": [
@@ -72,20 +96,6 @@
7296
"description": "New Description",
7397
"tags": {"add": ["addtag1", "addtag2"], "remove": ["remtag1"]}
7498
}
75-
,{
76-
'add': [
77-
{'indicator': '8.8.8.9', 'type': 'IPv4', 'role': 'command_and_control'},
78-
{'indicator': '8.8.8.10', 'type': 'IPv4'},
79-
],
80-
'edit': [
81-
{'id': 1 'type': 'hostname', 'indicator': 'www.amazon.com'},
82-
{'id': 2, 'indicator': '[email protected]'},
83-
{'id': 3, 'is_active': True, 'expiration': '2017-01-01', 'role': 'scanning_host'},
84-
],
85-
'remove': [
86-
{'id': 4},
87-
]
88-
}
8999
,{
90100
"$schema": "http://json-schema.org/draft-04/schema",
91101
"additionalProperties": false,
@@ -1712,5 +1722,6 @@
17121722
"unfollowed"
17131723
]
17141724
}
1715-
}}
1716-
]
1725+
}
1726+
}
1727+

jsonschema/convert.js

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const convert = require('json-schema-to-openapi-schema');
2+
const fs = require('fs')
3+
const filepath = "alienvault.json"
4+
5+
const schema = {
6+
'$schema': 'http://json-schema.org/draft-04/schema#',
7+
type: ['string', 'null'],
8+
format: 'date-time',
9+
};
10+
11+
try {
12+
const data = fs.readFileSync(filepath, 'utf8')
13+
console.log(data)
14+
console.log("\n=================================")
15+
console.log("Succesfully loaded data!")
16+
console.log("=================================\n")
17+
18+
const convertedSchema = convert(schema);
19+
const stringified = JSON.stringify(convertedSchema)
20+
21+
console.log("Done translating")
22+
const new_filename = "new_"+filepath
23+
fs.writeFile(new_filename, stringified, function (err) {
24+
if (err) return console.log(err);
25+
//console.log('Hello World > helloworld.txt');
26+
console.log("\n=================================")
27+
console.log("Wrote to file ", new_filename, "!!!!")
28+
console.log("=================================\n")
29+
})
30+
31+
} catch (err) {
32+
console.error("An error occured: ", err)
33+
}
34+
35+

0 commit comments

Comments
 (0)