From 608001d13a337167433815e7889208b7c2b6a123 Mon Sep 17 00:00:00 2001 From: Elliot Winkler Date: Tue, 4 Jul 2023 14:25:43 -0700 Subject: [PATCH] Sort RPC methods in docs (#301) The methods that appear in the published docs are not sorted by method name. This may not matter when looking for a particular method (as you can use Ctrl-F/Cmd-F in your browser), but not so when using the list as a whole. In our case, we have a proxy to Ethereum in our project, and we want to ensure we have proper test coverage for all public Ethereum RPC methods. This is difficult when the official list of methods is unsorted because we have to double- and triple-check that we've accounted for all of them on our side. If the list were sorted then this task would be a lot easier. --- scripts/build.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/scripts/build.js b/scripts/build.js index f04f1cb2..335ca476 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -3,6 +3,18 @@ import yaml from "js-yaml"; import merger from "json-schema-merge-allof"; import { dereferenceDocument } from "@open-rpc/schema-utils-js"; +function sortByMethodName(methods) { + return methods.slice().sort((a, b) => { + if (a['name'] > b['name']) { + return 1; + } else if (a['name'] < b['name']) { + return -1; + } else { + return 0; + } + }) +} + console.log("Loading files...\n"); let methods = []; @@ -78,7 +90,7 @@ const doc = { }, version: "0.0.0" }, - methods: methods, + methods: sortByMethodName(methods), components: { schemas: schemas }