-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.js
More file actions
103 lines (92 loc) · 2.46 KB
/
build.js
File metadata and controls
103 lines (92 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import fs from "fs";
import merger from "json-schema-merge-allof";
import { dereferenceDocument } from "@open-rpc/schema-utils-js";
console.log("Loading files...\n");
let methods = [];
let methodsBase = "src/tolar/";
let methodFiles = fs.readdirSync(methodsBase);
methodFiles.forEach(file => {
console.log(file);
let raw = fs.readFileSync(methodsBase + file);
let parsed = JSON.parse(raw);
methods = [
...methods,
...parsed,
];
});
let schemas = {};
let schemasBase = "src/schemas/"
let schemaFiles = fs.readdirSync(schemasBase);
schemaFiles.forEach(file => {
console.log(file);
let raw = fs.readFileSync(schemasBase + file);
let parsed = JSON.parse(raw);
schemas = {
...schemas,
...parsed,
};
});
const doc = {
openrpc: "1.2.6",
info: {
title: "Tolar JSON-RPC Specification",
description: "A specification of the standard interface for Tolar clients.",
license: {
name: "Unknown",
url: "https://unknown"
},
version: "1.3.0"
},
servers: [
{
name: "Mainnet",
summary: "[network_id: 1]",
url: "https://jsongw.mainnet.tolar.io/jsonrpc"
},
{
name: "Testnet",
summary: "[network_id: 2]",
url: "https://jsongw.testnet.tolar.io/jsonrpc"
},
{
name: "Stagenet",
summary: "[network_id: 3]",
url: "https://jsongw.stagenet.tolar.io/jsonrpc",
},
{
name: "EuChain",
summary: "[network_id: 5]",
url: "https://jsongw.euchain.org/jsonrpc"
},
],
methods: methods,
components: {
schemas: schemas
}
}
fs.writeFileSync('refs-openrpc.json', JSON.stringify(doc, null, '\t'));
let spec = await dereferenceDocument(doc);
spec.components = {};
function recursiveMerge(schema) {
schema = merger(schema);
if("items" in schema && "oneOf" in schema.items) {
schema.items.oneOf = recursiveMerge(schema.items.oneOf);
}
if("oneOf" in schema) {
for(var k=0; k < schema.oneOf.length; k++) {
schema.oneOf[k] = recursiveMerge(schema.oneOf[k]);
}
}
return schema;
}
// Merge instances of `allOf` in methods.
for (var i=0; i < spec.methods.length; i++) {
for (var j=0; j < spec.methods[i].params.length; j++) {
spec.methods[i].params[j].schema = recursiveMerge(spec.methods[i].params[j].schema);
}
spec.methods[i].result.schema = recursiveMerge(spec.methods[i].result.schema);
}
let data = JSON.stringify(spec, null, '\t');
fs.writeFileSync('openrpc.json', data);
console.log();
console.log("Build successful.");