*Remove use of anyOf and set Avj allowUnionTypes
*Compile schema to validateRpcRequest *Use errorsText to generate errors for validation
This commit is contained in:
parent
44af1cf765
commit
16e8eab836
|
@ -15,8 +15,8 @@ import stringify from "json-stable-stringify";
|
|||
import Ajv from "ajv";
|
||||
import RPCConnection from "./connection.js";
|
||||
|
||||
const ajv = new Ajv();
|
||||
ajv.addSchema(RPC_REQUEST_SCHEMA, "rpc_request");
|
||||
const ajv = new Ajv({ allowUnionTypes: true });
|
||||
const validateRpcRequest = ajv.compile(RPC_REQUEST_SCHEMA);
|
||||
|
||||
let server: RPCServer;
|
||||
|
||||
|
@ -193,9 +193,10 @@ export class RPCServer {
|
|||
}
|
||||
|
||||
private verifyRequest(request: RPCRequest) {
|
||||
let valid: any = ajv.getSchema("rpc_request")?.(request);
|
||||
let valid: boolean | Error | RPCMethod = validateRpcRequest(request);
|
||||
|
||||
if (!valid) {
|
||||
return new Error("Invalid request");
|
||||
return new Error(ajv.errorsText(validateRpcRequest.errors));
|
||||
}
|
||||
|
||||
valid = this.getMethodByRequest(request);
|
||||
|
|
|
@ -34,14 +34,7 @@ export const RPC_REQUEST_SCHEMA: JSONSchemaType<RPCRequest> = {
|
|||
type: "string",
|
||||
},
|
||||
data: {
|
||||
type: "string",
|
||||
anyOf: [
|
||||
{ type: "string" },
|
||||
{ type: "number" },
|
||||
{ type: "integer" },
|
||||
{ type: "object" },
|
||||
{ type: "array" },
|
||||
],
|
||||
type: ["number", "string", "boolean", "object", "array"],
|
||||
},
|
||||
bypassCache: {
|
||||
type: "boolean",
|
||||
|
|
Loading…
Reference in New Issue