-
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
Conversation
Hi, @friej715, thanks for this! It looks like exports.onCreateWebpackConfig = ({ stage, actions, loaders, getConfig }) => {
........stuff that is already there....
if (stage === 'build-html') {
setWebpackConfig({
module: {
rules: [
{
test: /swagger-ui/,
use: loaders.null(),
},
],
},
})
}
} |
@friej715 this looks great! I imagine that it could replace part (or all) of this page https://covidtracking.com/api is that different than what others were thinking? |
(I just learned about draft PRs today, so I'm changing this to that!) I think I've fixed the issues in Every time I try to build, I get: The only thing that comes to mind is that |
…d to fix SSR issues
@friej715 OK so I did some search and testing, it seems Swagger UI doesn't play well with SSR and it's more an issue on their side than Gatsby. See gatsbyjs/gatsby#11081 (comment) Basically, the workaround is to avoid rendering it in SSR, then render it - client-only - using Which actually seems like a good idea on the performance side of things: rendering anything related to Swagger UI in SSR would make the bundle (probably much) heavier and I'm not sure that's relevant for the sandbox API docs (while it might still make sense to do so for the production API, thus making it quite difficult to replace the /api page with a Swagger UI like @muamichali suggested) I quickly tried the mentioned solution and it works. If this seems like a reasonable workaround, check out friej715#1 And also I removed the null loader workaround as it's not needed anymore with this approach. EDIT: if we go down this road, it would be a good idea to load Swagger UI dist CSS only on the client too |
Thank you so much @superbiche, that PR looks promising! Almost clapped with glee when I think the only change I'd make (if my git understanding is right) is just to switch the branch your PR is against, so that it's merging into my fork's |
@friej715 will switch the target branch, just chatted with Kai a few minutes ago about me lost regarding where to PR what 😅 |
Fix/swaggerui ssr
Great, thank you @superbiche! Looks like some tests are still failing--I think maybe because we just updated a bunch of testing stuff within the last 24-48h. I can take a look later tonight. |
@friej715 OK let me know if you need further help, I'll be working on another PR for the next couple hrs |
This is a preview version of the site. Built with commit 608408f https://deploy-preview-517--upbeat-lovelace-3e9fff.netlify.app |
Post go-live:
|
Quickly popping on to say--I think the code here is largely good to go, but I'd love to have @webmasterkai and/or @kissane (or anyone on their respective API/content teams) check over the descriptions etc. and make sure everything is described accurately. You can see the preview here. |
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.
This looks excellent! Just one question 😄.
gatsby-browser.js
Outdated
@@ -1,5 +1,9 @@ | |||
const SwaggerUI = require('swagger-ui') |
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:
- Uses
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." - Loads swagger UI in the
SwaggerSandbox
component.
Maybe this is a silly question, but will this replace the current API page? If so, we should definitely include the preamble that's on there now and make sure this PR includes all of the endpoints listed there (counties, tracker URLs, etc.) |
@schwartzadev Not sure about whether this is in addition to or replacing the other API docs--we've talked about it some but I don't think there's been one definitive answer. As for the second--makes sense! I wrote these docs like two weeks ago, which is basically forever in covid19 tracking time 🤣 I'll get on that later tonight when I'm done with work. |
My thought is that this should replace the API page, but that can happen slowly - we do this merge and I can update the API page in Contentful and point it at this one for now. Long term, I think the API page should be a snippet from Contentful, plus a swagger component. |
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.
This is such amazing work @friej715! I'm so happy to get this change in today.
I think this PR could use some eyes (and maybe in the end we won't need it), but I wanted to put it out there and get some comments sooner rather than later!
I took a pass at writing up a spec for the v1 API, and made a little sandbox page (based on
swagger-ui-react
) that lays out the different schema/endpoints, and lets folks try executing queries.I think ultimately we would want to tie the API and the docs closer together, so there's not two sources of truth (this is just pulling from a json file that I wrote in Swagger)--but this might be a handy in-between til then.