diff --git a/gatsby-node.js b/gatsby-node.js index 345d51f1..0b460e52 100755 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -202,9 +202,7 @@ const createTypeDocPage = async (createPage, name, downloadUrl) => { // https://github.com/swagger-api/swagger-js const fetchSwaggerSpec = async (component) => { try { - const client = await Swagger( - `https://${component}.mainnet.oceanprotocol.com/spec` - ) + const client = await Swagger(`http://localhost:5000/spec`) return client.spec // The resolved spec // client.originalSpec // In case you need it diff --git a/src/templates/Swagger/Paths.jsx b/src/templates/Swagger/Paths.jsx index f1675478..0f1d311e 100644 --- a/src/templates/Swagger/Paths.jsx +++ b/src/templates/Swagger/Paths.jsx @@ -4,8 +4,9 @@ import slugify from 'slugify' import { cleanPathKey } from './utils' import styles from './Paths.module.scss' import stylesDoc from '../Doc.module.scss' -import ReactJson from 'react-json-view' - +const ResponseExample = React.lazy(() => + import("./ResponseExample") +) const ParameterExample = ({ properties }) => ( // // HEADS UP! @@ -35,10 +36,10 @@ const ParameterExample = ({ properties }) => ( )} {(properties[key].type === 'integer' || properties[key].type === 'number') && ( - - {`${properties[key].example}`} - - )} + + {`${properties[key].example}`} + + )} {(properties[key].type === 'array' || properties[key].type === 'object') && JSON.stringify(properties[key].example, null, 2)} @@ -89,63 +90,31 @@ Parameters.propTypes = { parameters: PropTypes.array.isRequired } -const Responses = ({ responses }) => ( - <> +const Responses = ({ responses }) => { + const isSSR = typeof window === "undefined" + + return (<>

Responses

{Object.keys(responses).map((key) => (
{key} {responses[key].description}
- + <> + {!isSSR && ( + }> + + + )} +
))} - -) + ) +} Responses.propTypes = { responses: PropTypes.object.isRequired } -const ResponseExample = ({ examples }) => { - if (!examples) return null - const jsonExample = examples['application/json'] - const plainText = examples['text/plain'] - - if (jsonExample) { - return ( -
- Example -
- - {typeof jsonExample === 'boolean' ? ( - {JSON.stringify(jsonExample)} - ) : ( - - )} - -
- ) - } else if (plainText) { - return ( -
- Example - {plainText} -
- ) - } - - return null -} - -ResponseExample.propTypes = { - examples: PropTypes.object -} - const Method = ({ keyName, value }) => { const { summary, description, parameters, responses } = value console.log('---', summary, responses) diff --git a/src/templates/Swagger/ResponseExample.jsx b/src/templates/Swagger/ResponseExample.jsx new file mode 100644 index 00000000..974b1452 --- /dev/null +++ b/src/templates/Swagger/ResponseExample.jsx @@ -0,0 +1,48 @@ +import React from "react" +import PropTypes from "prop-types" +import ReactJson from 'react-json-view' + + +const ResponseExample = ({ examples }) => { + + if (!examples) return null + const jsonExample = examples['application/json'] + const plainText = examples['text/plain'] + + if (typeof document !== `undefined`) { + if (jsonExample) { + return ( +
+ Example +
+ + {typeof jsonExample === 'boolean' ? ( + {JSON.stringify(jsonExample)} + ) : ( + + )} + +
+ ) + } else if (plainText) { + return ( +
+ Example + {plainText} +
+ ) + } + } + return null +} + +ResponseExample.propTypes = { + examples: PropTypes.object +} + +export default ResponseExample \ No newline at end of file