From d0b69801f67311108b28129adf54368fd1ee87de Mon Sep 17 00:00:00 2001 From: Sotatek-TanHoang Date: Mon, 9 Sep 2024 18:45:12 +0700 Subject: [PATCH] fix: document display params remove unwanted params: id, jsonrpc, method keep the params unfolded --- web3rpc/refactor-code-example.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/web3rpc/refactor-code-example.js b/web3rpc/refactor-code-example.js index 098d7677bbbe..87575e929603 100644 --- a/web3rpc/refactor-code-example.js +++ b/web3rpc/refactor-code-example.js @@ -18,6 +18,7 @@ const refactorOpenAPI = async ( path ) => { let fileContents = fs.readFileSync(path, 'utf8') let apiLine = ''; let apiIndex; + const lines = fileContents.split("\n"); lines.forEach((line, index) => { if (line.startsWith("api: ")) { @@ -34,11 +35,25 @@ const refactorOpenAPI = async ( path ) => { const compressedOpenAPI = await deflateOpenAPI( JSON.stringify(decompressedOpenAPI) ); + lines[apiIndex] = `api: ${compressedOpenAPI}`; - const newFileContents = lines.join("\n"); + + let newFileContents = lines.join('\n'); + + // remove unwanted params from request and response + newFileContents=removeSchemaItem('id',newFileContents) + newFileContents=removeSchemaItem('method',newFileContents) + newFileContents=removeSchemaItem('jsonrpc',newFileContents) + + // change
{ + return str.replace(new RegExp(`<\\s*SchemaItem\\b[^>]*\\bname\\s*=\\s*{"${name}"}[^>]*>\\s*`,'g'),'') +} const flateOpenAPI = ( compressedData ) => { return new Promise((resolve, reject) => { zlib.inflate(Buffer.from(compressedData, 'base64'), (err, decompressedData) => {