-
Notifications
You must be signed in to change notification settings - Fork 189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(docs): API sandbox #517
Merged
Merged
Changes from 14 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
8fddb1b
first tiny pass at swagger page
friej715 86a4c76
fix(docs): removing comments
friej715 3a04c6e
moving locally, tweaking style
friej715 33d093e
fix(docs) adding SSR fix
friej715 899da81
fix(sandbox): minor tweak to gatsby-node.js, but build not solved yet
friej715 e187875
fix(apisandbox): replace swagger-ui-react with a swagger-ui workaroun…
superbiche cad4dcc
Merge pull request #1 from superbiche/fix/swaggerui-ssr
friej715 1cb8b03
fix(docs): merge conflict for api sandbox
friej715 bdda11e
fix(docs): quick fix, hopefully, for test
friej715 3a0900a
fix(docs): lint
friej715 e82e708
fix(docs): making sandbox look nicer on smaller screens, brand colors
friej715 26216fe
Merge branch 'master' into jane/api-sandbox
friej715 63dee0f
fix(docs): fixing table borders
friej715 be5175c
Merge branch 'master' into jane/api-sandbox
friej715 8f9140d
Merge branch 'master' into jane/api-sandbox
schwartzadev efae555
chore: Make swagger load in component only
kevee 47b690d
Merge branch 'master' into jane/api-sandbox
friej715 11bf472
fix(docs): updating for current endpoints
friej715 608408f
Merge branch 'master' into jane/api-sandbox
kevee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
const SwaggerUI = require('swagger-ui') | ||
|
||
exports.onClientEntry = () => { | ||
window.addEventListener('load', () => { | ||
document.body.className = document.body.className.replace(/\bno-js\b/, '') | ||
}) | ||
} | ||
|
||
window.SwaggerUI = SwaggerUI |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/__tests__/components/common/__snapshots__/swagger-sandbox.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Components : Common: Swagger sandbox renders correctly 1`] = ` | ||
<div | ||
id="swaggerWrapper" | ||
/> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React from 'react' | ||
import renderer from 'react-test-renderer' | ||
import SwaggerUI from 'swagger-ui' | ||
import SwaggerSandbox from '../../../components/common/swagger-sandbox' | ||
|
||
beforeEach(() => { | ||
window.SwaggerUI = SwaggerUI | ||
}) | ||
|
||
describe('Components : Common: Swagger sandbox', () => { | ||
it('renders correctly', () => { | ||
const tree = renderer.create(<SwaggerSandbox />).toJSON() | ||
expect(tree).toMatchSnapshot() | ||
}) | ||
}) | ||
|
||
afterEach(() => { | ||
delete window.SwaggerUI | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React from 'react' | ||
import 'swagger-ui/dist/swagger-ui.css' | ||
import './swagger-sandbox.scss' | ||
|
||
class SwaggerSandbox extends React.Component { | ||
componentDidMount() { | ||
window.SwaggerUI({ | ||
domNode: this.swaggerWrapper, | ||
url: '/api-docs/COVID-tracking-endpoints-1.0-docs.json', | ||
defaultModelExpandDepth: 10, | ||
docExpansion: 'list', | ||
}) | ||
} | ||
|
||
render() { | ||
return ( | ||
<div | ||
ref={ref => { | ||
this.swaggerWrapper = ref | ||
}} | ||
id="swaggerWrapper" | ||
/> | ||
) | ||
} | ||
} | ||
|
||
export default SwaggerSandbox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
@import '../../scss/colors.module.scss'; | ||
@import '../../scss/breakpoints.module.scss'; | ||
|
||
#swaggerWrapper { | ||
.swagger-ui { | ||
pre.microlight { | ||
line-height: 1rem; | ||
} | ||
|
||
.wrapper { | ||
padding: 0px; | ||
} | ||
|
||
.download-contents { | ||
font-size: 0.7rem; | ||
line-height: 1.2rem; | ||
} | ||
|
||
.model { | ||
border:0px; | ||
|
||
td, tr { | ||
border-top: none; | ||
border-bottom: none; | ||
padding-top:20px; | ||
padding-bottom:20px; | ||
} | ||
|
||
tbody tr { | ||
border-top:1px solid rgb(200, 200, 200); | ||
} | ||
} | ||
|
||
table, th, td { | ||
border-color: rgb(175, 175, 175); | ||
border-left: none; | ||
border-right: none; | ||
} | ||
|
||
td { | ||
font-size: 0.8rem; | ||
} | ||
|
||
tr { | ||
line-height: 1.5rem; | ||
} | ||
|
||
ul { | ||
margin: auto; | ||
} | ||
|
||
.url { | ||
display: none; | ||
} | ||
|
||
.scheme-container { | ||
box-shadow: none; | ||
padding-top: 0px; | ||
margin-top: 0px; | ||
} | ||
|
||
select.content-type { | ||
border-color: $color-plum-600; | ||
} | ||
|
||
.opblock-title span:after, | ||
.opblock-summary-method { | ||
background-color: $color-plum-600; | ||
} | ||
|
||
.btn.execute { | ||
background-color: $color-plum-600; | ||
border-color: $color-plum-600; | ||
} | ||
|
||
.btn.execute:active, | ||
.btn.execute:hover { | ||
background-color: $color-plum-700; | ||
} | ||
|
||
.response-control-media-type__accept-message, | ||
.model .prop-type { | ||
color: $color-plum-600; | ||
} | ||
|
||
.opblock-summary, | ||
.opblock-get { | ||
background-color: $color-plum-200; | ||
border-color: $color-plum-300; | ||
border-radius: 2px; | ||
} | ||
|
||
@media (max-width: $viewport-ms) { | ||
.responses-table, | ||
.model { | ||
table-layout: fixed; | ||
} | ||
.col_header.response-col_description { | ||
width: 55%; | ||
} | ||
|
||
.model td { | ||
display: block; | ||
padding: 0px; | ||
max-width: 100%; | ||
} | ||
|
||
.model td:nth-child(2) { | ||
margin-bottom: 30px; | ||
border-bottom: 0px; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import React from 'react' | ||
import { graphql } from 'gatsby' | ||
import SwaggerSandbox from '../../components/common/swagger-sandbox' | ||
import Layout from '../../components/layout' | ||
|
||
export default ({ data }) => ( | ||
<Layout | ||
title="API Sandbox" | ||
navigation={data.allContentfulNavigationGroup.edges[0].node.pages} | ||
> | ||
Below, you can explore each of our endpoints, try out API requests, and | ||
learn about our schema. | ||
<SwaggerSandbox /> | ||
</Layout> | ||
) | ||
|
||
export const query = graphql` | ||
query { | ||
allContentfulNavigationGroup(filter: { slug: { eq: "data" } }) { | ||
edges { | ||
node { | ||
pages { | ||
... on ContentfulPage { | ||
title | ||
link: slug | ||
} | ||
... on ContentfulNavigationLink { | ||
title | ||
link: url | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean that Swagger runs on every page? If do, is there a way to only load it on the pages we'll need it for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure, I think @superbiche might know?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, I missed that. I'm going to do a test and propose a change to just load swagger on that one page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK I just pushed a commit that:
onCreateWebpackConfig
to say "Gatsby, when you're building the site with SSR, and therefore there is nowindow
object, just chill and don't bother about Swagger."SwaggerSandbox
component.