1
0
mirror of https://github.com/oceanprotocol/docs.git synced 2024-11-26 19:49:26 +01:00

use pet store as example, output data from the depths of swagger json files

This commit is contained in:
Matthias Kretschmann 2018-11-28 13:20:03 +01:00
parent ae7e16a932
commit a2252e10a5
Signed by: m
GPG Key ID: 606EEEF3C479A91F
6 changed files with 76 additions and 29 deletions

View File

@ -11,6 +11,10 @@
url: /api/aquarius/ url: /api/aquarius/
- name: brizo - name: brizo
links:
- name: API reference
url: /api/brizo/
- name: pleuston - name: pleuston
- group: Libraries - group: Libraries

View File

@ -17,3 +17,8 @@
items: items:
- title: API reference - title: API reference
link: /api/brizo/ link: /api/brizo/
- group: pet store
items:
- title: API reference
link: /api/petstore/

View File

@ -155,16 +155,16 @@ exports.createPages = ({ graphql, actions }) => {
'./src/templates/ApiSwagger.jsx' './src/templates/ApiSwagger.jsx'
) )
const brizoSlug = '/api/brizo/' const petStoreSlug = '/api/petstore/'
try { try {
const spec = await getSpec() const spec = await getSpec()
createPage({ createPage({
path: brizoSlug, path: petStoreSlug,
component: apiSwaggerTemplate, component: apiSwaggerTemplate,
context: { context: {
slug: brizoSlug, slug: petStoreSlug,
api: spec api: spec
} }
}) })
@ -172,29 +172,29 @@ exports.createPages = ({ graphql, actions }) => {
console.log(error) console.log(error)
} }
// const aquariusSpecs = require('./data/aquarius.json') const aquariusSpecs = require('./data/aquarius.json')
// const aquariusSlug = '/api/aquarius/' const aquariusSlug = '/api/aquarius/'
// createPage({ createPage({
// path: aquariusSlug, path: aquariusSlug,
// component: apiSwaggerTemplate, component: apiSwaggerTemplate,
// context: { context: {
// slug: aquariusSlug, slug: aquariusSlug,
// api: aquariusSpecs api: aquariusSpecs
// } }
// }) })
// const brizoSpecs = require('./data/brizo.json') const brizoSpecs = require('./data/brizo.json')
// const brizoSlug = '/api/brizo/' const brizoSlug = '/api/brizo/'
// createPage({ createPage({
// path: brizoSlug, path: brizoSlug,
// component: apiSwaggerTemplate, component: apiSwaggerTemplate,
// context: { context: {
// slug: brizoSlug, slug: brizoSlug,
// api: brizoSpecs api: brizoSpecs
// } }
// }) })
resolve() resolve()
}) })

View File

@ -38,7 +38,6 @@
&:last-child { &:last-child {
flex-basis: 100%; flex-basis: 100%;
text-align: center; text-align: center;
opacity: .75;
} }
} }

View File

@ -272,6 +272,10 @@ samp {
font-size: $font-size-small !important; font-size: $font-size-small !important;
border-radius: $border-radius !important; border-radius: $border-radius !important;
text-shadow: none !important; text-shadow: none !important;
h1 &, h2 &, h3 &, h4 &, h5 & {
font-size: inherit !important;
}
} }
:not(pre) > code { :not(pre) > code {

View File

@ -11,6 +11,17 @@ import SEO from '../components/Seo'
import stylesDoc from './Doc.module.scss' import stylesDoc from './Doc.module.scss'
// import styles from './ApiSwagger.module.scss' // import styles from './ApiSwagger.module.scss'
const toc = api => {
const items = Object.keys(api.paths).map(
key =>
`<li key=${key}>
<a href="#${key.replace(/\//gi, '-')}"><code>${key}</code></a>
</li>`
)
return `<ul>${items}</ul>`
}
export default class ApiSwaggerTemplate extends Component { export default class ApiSwaggerTemplate extends Component {
static propTypes = { static propTypes = {
data: PropTypes.object.isRequired, data: PropTypes.object.isRequired,
@ -55,6 +66,10 @@ export default class ApiSwaggerTemplate extends Component {
location={location} location={location}
sidebar={'api'} sidebar={'api'}
collapsed collapsed
toc
tableOfContents={toc(api)
.split(',')
.join('')}
/> />
</aside> </aside>
<article className={stylesDoc.main}> <article className={stylesDoc.main}>
@ -65,11 +80,31 @@ export default class ApiSwaggerTemplate extends Component {
{version} {version}
{Object.keys(api.paths).map(key => ( {Object.entries(api.paths).map(
<> ([key, value]) => (
<h2 key={key}>{key}</h2> <>
</> <h2
))} key={key}
id={key.replace(/\//gi, '-')}
>
<code>{key}</code>
</h2>
{Object.entries(value).map(
([key, value]) => (
<>
<h4 key={key}>
<code>{key}</code>
</h4>
<p>
{value['summary']}
</p>
</>
)
)}
</>
)
)}
</article> </article>
</main> </main>
</Content> </Content>