Skip to content

Commit

Permalink
Merge pull request #54 from starkware-libs/liors/fix-validation
Browse files Browse the repository at this point in the history
fix validation script
  • Loading branch information
lior-stark authored Sep 7, 2022
2 parents 438df17 + 8437a27 commit 01832d3
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 32 deletions.
17 changes: 10 additions & 7 deletions api/starknet_trace_api_openrpc.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"summary": "The hash of the transaction to trace",
"required": true,
"schema": {
"$ref": "starknet_api_openrpc.json#/components/schemas/TXN_HASH"
"$ref": "./api/starknet_api_openrpc.json#/components/schemas/TXN_HASH"
}
}
],
Expand Down Expand Up @@ -103,6 +103,9 @@
}
}
},
"NESTED_CALL": {
"$ref": "#/components/schemas/FUNCTION_INVOCATION"
},
"FUNCTION_INVOCATION": {
"allOf": [
{
Expand Down Expand Up @@ -140,7 +143,7 @@
"description": "The calls made by this invocation",
"type": "array",
"items": {
"$ref": "#/components/schemas/FUNCTION_INVOCATION"
"$ref": "#/components/schemas/NESTED_CALL"
}
},
"events": {
Expand Down Expand Up @@ -179,19 +182,19 @@
]
},
"FELT": {
"$ref": "starknet_api_openrpc.json#/components/schemas/FELT"
"$ref": "./api/starknet_api_openrpc.json#/components/schemas/FELT"
},
"FUNCTION_CALL": {
"$ref": "starknet_api_openrpc.json#/components/schemas/FUNCTION_CALL"
"$ref": "./api/starknet_api_openrpc.json#/components/schemas/FUNCTION_CALL"
},
"EVENT": {
"$ref": "starknet_api_openrpc.json#/components/schemas/EVENT_CONTENT"
"$ref": "./api/starknet_api_openrpc.json#/components/schemas/EVENT_CONTENT"
},
"MSG_TO_L1": {
"$ref": "starknet_api_openrpc.json#/components/schemas/MSG_TO_L1"
"$ref": "./api/starknet_api_openrpc.json#/components/schemas/MSG_TO_L1"
},
"BLOCK_HASH": {
"$ref": "starknet_api_openrpc.json#/components/schemas/BLOCK_HASH"
"$ref": "./api/starknet_api_openrpc.json#/components/schemas/BLOCK_HASH"
}
},
"errors": {
Expand Down
16 changes: 8 additions & 8 deletions api/starknet_write_api.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,33 +109,33 @@
"contentDescriptors": {},
"schemas": {
"CONTRACT_CLASS": {
"$ref": "starknet_api_openrpc.json#/components/schemas/CONTRACT_CLASS"
"$ref": "./api/starknet_api_openrpc.json#/components/schemas/CONTRACT_CLASS"
},
"NUM_AS_HEX": {
"title": "An integer number in hex format (0x...)",
"type": "string",
"pattern": "^0x[a-fA-F0-9]+$"
},
"SIGNATURE": {
"$ref": "starknet_api_openrpc.json#/components/schemas/SIGNATURE"
"$ref": "./api/starknet_api_openrpc.json#/components/schemas/SIGNATURE"
},
"FELT": {
"$ref": "starknet_api_openrpc.json#/components/schemas/FELT"
"$ref": "./api/starknet_api_openrpc.json#/components/schemas/FELT"
},
"TXN_HASH": {
"$ref": "starknet_api_openrpc.json#/components/schemas/TXN_HASH"
"$ref": "./api/starknet_api_openrpc.json#/components/schemas/TXN_HASH"
},
"BROADCASTED_INVOKE_TXN": {
"$ref": "starknet_api_openrpc.json#/components/schemas/BROADCASTED_INVOKE_TXN"
"$ref": "./api/starknet_api_openrpc.json#/components/schemas/BROADCASTED_INVOKE_TXN"
},
"BROADCASTED_DECLARE_TXN": {
"$ref": "starknet_api_openrpc.json#/components/schemas/BROADCASTED_DECLARE_TXN"
"$ref": "./api/starknet_api_openrpc.json#/components/schemas/BROADCASTED_DECLARE_TXN"
},
"BROADCASTED_DEPLOY_TXN": {
"$ref": "starknet_api_openrpc.json#/components/schemas/BROADCASTED_DEPLOY_TXN"
"$ref": "./api/starknet_api_openrpc.json#/components/schemas/BROADCASTED_DEPLOY_TXN"
},
"FUNCTION_CALL": {
"$ref": "starknet_api_openrpc.json#/components/schemas/FUNCTION_CALL"
"$ref": "./api/starknet_api_openrpc.json#/components/schemas/FUNCTION_CALL"
}
},
"errors": {
Expand Down
37 changes: 20 additions & 17 deletions validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ async function runValidation(filename) {
let docToParseWithExternalRefs = await fetchExternalRefsFor(docToParse);
let dereffedDoc = await derefAll(docToParseWithExternalRefs);

let doc = await parseOpenRPCDocument(dereffedDoc, { dereference: false });
let doc = await parseOpenRPCDocument(dereffedDoc, { dereference: true });

const errors = validateOpenRPCDocument(doc);
if (errors === true) {
Expand Down Expand Up @@ -58,20 +58,23 @@ function fixRefs(dereffer) {
* @returns The document, with the references resolved.
*/
async function derefAll(doc) {
let dereffer = fixRefs(new Dereferencer.default(
doc,
{
//TOOD: look generically for all recursive definitions and put them in the cache.
refCache: {
"#/components/schemas/FUNCTION_INVOCATION": doc.components.schemas["FUNCTION_INVOCATION"]
},
rootSchema: doc
})
);

let dereffedDoc = await dereffer.resolve();

return dereffedDoc;

let allSchemas = doc.components.schemas;
let refCacheWithRecursiveRef = {
"#/components/schemas/NESTED_CALL": allSchemas["NESTED_CALL"]
}
let dereferencerOptions = {
refCache: refCacheWithRecursiveRef,
rootSchema: doc
}
//resolve all schemas, and remember them
await Promise.all(Object.keys(allSchemas).map(async k => {
let s = allSchemas[k]
let dereffer = fixRefs(new Dereferencer.default(s, dereferencerOptions));
allSchemas[k] = await dereffer.resolve();
return allSchemas[k];
}))
return doc;
}


Expand Down Expand Up @@ -139,11 +142,11 @@ const filenameFromExternalRef = ref => ref.split("#")[0];
//TODO: this assumes the script is run in a specific directory relative to the files.
/**
* Given a relative path, retrieve the full path to the relative API.
* Note this assumes some structure on the project.
* Note this assumes the references in the file are relative to the current working directory.
* @param {String} relative The relative path
* @returns The full filesystem path
*/
const fullPathForRefFile = relative => `${process.cwd()}/api/${relative}` //should canonize this
const fullPathForRefFile = relative => `${process.cwd()}/${relative}` //should canonize this

let args = process.argv.slice(2);

Expand Down

0 comments on commit 01832d3

Please sign in to comment.