Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ module.exports = {
// bump this back up to 80% when we have more tests
coverageThreshold: {
global: {
branches: 28.15,
branches: 28.3,
functions: 22.72,
lines: 32.91,
statements: 32.77,
lines: 33.74,
statements: 33.6,
},
},

Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"build": "tsc --project tsconfig.build.json && cp src/theme/OpenRPCDocMethod.css dist/theme/OpenRPCDocMethod.css",
"build:clean": "rimraf dist && yarn build",
"build:watch": "yarn build && tsc --project tsconfig.build.json --watch",
"link:setup": "rm -rf ./node_modules/@docusaurus/theme-common",
"lint": "yarn lint:eslint && yarn lint:misc --check && yarn lint:dependencies && yarn lint:changelog",
"lint:changelog": "auto-changelog validate",
"lint:dependencies": "depcheck",
Expand Down Expand Up @@ -111,5 +112,9 @@
"@metamask/open-rpc-docs-react>@stoplight/mosaic>@fortawesome/fontawesome-svg-core": false,
"@metamask/open-rpc-docs-react>@stoplight/mosaic>@fortawesome/fontawesome-svg-core>@fortawesome/fontawesome-common-types": false
}
},
"resolutions": {
"@metamask/open-rpc-docs-react": "portal:/Users/shanejonas/code/metamask/openrpc-docs-react",
"joi": "17.6.0"
}
}
2 changes: 1 addition & 1 deletion src/content-docs-enhanced-open-rpc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ async function docsPluginEnhanced(
const path = join(options.path, options.openrpc.path);

const openrpcPluginInstance: any = openrpcPlugin(context, {
...options.openrpc,
id: options.id,
path,
openrpcDocument: options.openrpc.openrpcDocument,
});
if (openrpcPluginInstance === undefined) {
throw new Error('openrpcPluginInstance is undefined');
Expand Down
25 changes: 23 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-template-curly-in-string */
/* eslint-disable no-restricted-globals */
/**
* See https://v2.docusaurus.io/docs/lifecycle-apis if you need more help!
Expand All @@ -14,8 +15,6 @@ import path, { join } from 'path';

// import {compile} from '@mdx-js/mdx'

// import openRPCToMarkdown from './openrpc-to-mdx';

/**
* Put your plugin's options in here.
*
Expand All @@ -28,6 +27,7 @@ export type DocusaurusOpenRPCOptions = {
// either a file path, or uri to a document.
openrpcDocument: string;
path: string;
requestTemplate?: string | Record<string, string>;
};

/**
Expand Down Expand Up @@ -64,6 +64,25 @@ export default function docusaurusOpenRpc(
const aliasedSource = (source: string) =>
`${posixPath(path.resolve(pluginDataDirRoot, options.id, source))}`;

console.log('OPTIONS=', typeof options.requestTemplate);
let reqTemplate: any = {
js: 'await window.fetch(\n "${serverUrl}",\n {\n method: "POST",\n headers: {\n "Content-Type": "application/json"\n },\n body: JSON.stringify(${jsonRpcRequest})\n }\n).then((res) => res.json());',
curl: "curl -X POST -H 'Content-Type: application/json' --data ${jsonRpcRequest} ${serverUrl}",
python:
'import requests\n\nrequests.request(\n "POST",\n "${serverUrl}",\n headers={\n "Content-Type": "application/json"\n },\n data=${jsonRpcRequest}\n)',
};

if (typeof options.requestTemplate === 'string') {
reqTemplate = {
js: options.requestTemplate,
};
} else if (typeof options.requestTemplate === 'object') {
reqTemplate = {
...reqTemplate,
...options.requestTemplate,
};
}

return {
// change this to something unique, or caches may conflict!
name: 'docusaurus-openrpc',
Expand Down Expand Up @@ -92,10 +111,12 @@ export default function docusaurusOpenRpc(

async contentLoaded({ content, actions }) {
const { openrpcDocument, loadedVersions } = content;
console.log('reqTemplate', reqTemplate);
const propsFilePath = await actions.createData(
'props.json',
JSON.stringify({
path: options.path,
requestTemplate: reqTemplate,
openrpcDocument,
}),
);
Expand Down
5 changes: 3 additions & 2 deletions src/theme/OpenRPCDocMethod.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
Sidebar,
} from "@docusaurus/plugin-content-docs/src/sidebars/types";
import Layout from '@theme/Layout';
const {useDocRouteMetadata} = require('@docusaurus/theme-common/internal');
import {ExamplePairingObject, MethodObject, ContentDescriptorObject} from '@open-rpc/meta-schema';
import { InteractiveMethod, Method} from '@metamask/open-rpc-docs-react';
import { join } from 'path';
Expand Down Expand Up @@ -105,6 +104,8 @@ export default function OpenRPCDocMethod(props: any) {
method.examples = method.examples || getExamplesFromMethod(method);
const [selectedExamplePairing, setSelectedExamplePairing] = React.useState<ExamplePairingObject | undefined>(method.examples[0]);

// requestTemplate

return (
<Layout>
<div style={{ display: "flex", width: "100%", flex: "1 0", }} className="docusaurus-openrpc">
Expand Down Expand Up @@ -142,7 +143,7 @@ export default function OpenRPCDocMethod(props: any) {
</div>

<div id="interactive-box" className="col col--5 interactive-right-sidebar table-of-contents__left-border thin-scrollbar">
{method && <InteractiveMethod method={method} components={{CodeBlock}} selectedExamplePairing={selectedExamplePairing as ExamplePairingObject}/>}
{method && <InteractiveMethod openrpcDocument={props.propsFile.openrpcDocument} method={method} components={{CodeBlock}} selectedExamplePairing={selectedExamplePairing as ExamplePairingObject} requestTemplate={props.propsFile.requestTemplate}/>}
</div>
</div>
</div>
Expand Down
29 changes: 18 additions & 11 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3115,9 +3115,9 @@ __metadata:
languageName: node
linkType: hard

"@metamask/open-rpc-docs-react@npm:^0.1.2":
version: 0.1.2
resolution: "@metamask/open-rpc-docs-react@npm:0.1.2"
"@metamask/open-rpc-docs-react@portal:/Users/shanejonas/code/metamask/openrpc-docs-react::locator=%40metamask%2Fdocusaurus-openrpc%40workspace%3A.":
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yarn link'd

version: 0.0.0-use.local
resolution: "@metamask/open-rpc-docs-react@portal:/Users/shanejonas/code/metamask/openrpc-docs-react::locator=%40metamask%2Fdocusaurus-openrpc%40workspace%3A."
dependencies:
"@json-schema-tools/traverse": ^1.10.1
"@open-rpc/examples": ^1.6.1
Expand All @@ -3130,15 +3130,15 @@ __metadata:
"@stoplight/mosaic-code-viewer": ^1.32
hash-color-material: ^1.1.3
lodash: ^4.17.15
openapi-url-resolver: ^1.0.8
qs: ^6.11.1
react-markdown: ^8.0.7
react-syntax-highlighter: ^15.4.3
peerDependencies:
react: ^17.0.2
react-dom: ^17.0.2
checksum: 2f9f0e1c8ed4292a9c7402273c02a84db78740966b64aec3cd325b8c279924b98dc8e63685e8fb37d4a05e0a0e491515f93af8b649e66106c3c2d9e529b2c740
languageName: node
linkType: hard
linkType: soft

"@nodelib/fs.scandir@npm:2.1.5":
version: 2.1.5
Expand Down Expand Up @@ -3580,7 +3580,7 @@ __metadata:
languageName: node
linkType: hard

"@sideway/formula@npm:^3.0.1":
"@sideway/formula@npm:^3.0.0":
version: 3.0.1
resolution: "@sideway/formula@npm:3.0.1"
checksum: e4beeebc9dbe2ff4ef0def15cec0165e00d1612e3d7cea0bc9ce5175c3263fc2c818b679bd558957f49400ee7be9d4e5ac90487e1625b4932e15c4aa7919c57a
Expand Down Expand Up @@ -10953,16 +10953,16 @@ __metadata:
languageName: node
linkType: hard

"joi@npm:^17.6.0":
version: 17.11.0
resolution: "joi@npm:17.11.0"
"joi@npm:17.6.0":
version: 17.6.0
resolution: "joi@npm:17.6.0"
dependencies:
"@hapi/hoek": ^9.0.0
"@hapi/topo": ^5.0.0
"@sideway/address": ^4.1.3
"@sideway/formula": ^3.0.1
"@sideway/formula": ^3.0.0
"@sideway/pinpoint": ^2.0.0
checksum: 3a4e9ecba345cdafe585e7ed8270a44b39718e11dff3749aa27e0001a63d578b75100c062be28e6f48f960b594864034e7a13833f33fbd7ad56d5ce6b617f9bf
checksum: eaf62f6c02f2edb1042f1ab04fc23a5918a2cb8f54bec84c6e1033624d8a462c10ae9518af55a3ba84f1793960450d58094eda308e7ef93c17edd4e3c8ef31d5
languageName: node
linkType: hard

Expand Down Expand Up @@ -12828,6 +12828,13 @@ __metadata:
languageName: node
linkType: hard

"openapi-url-resolver@npm:^1.0.8":
version: 1.0.8
resolution: "openapi-url-resolver@npm:1.0.8"
checksum: 26ab7a6103f44b5c9435540e4dcd18e8103453ab597f05e38be897bf89953b817841416cf3e219fb4b4add14174550e07a20fbb7cb30cc972948fd210360944a
languageName: node
linkType: hard

"opener@npm:^1.5.2":
version: 1.5.2
resolution: "opener@npm:1.5.2"
Expand Down