This repository has been archived by the owner on Nov 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Conversation
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
Talked offline with @domharrington and I think I can clean this up a bit by wrapping the |
In fixing this mess I'm ending up rewriting most of this branch so I'm closing this out and will open up a new draft when that's close. |
11 tasks
# for free
to subscribe to this conversation on GitHub.
Already have an account?
#.
Labels
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.
🧰 What's being changed?
Doc
component so OAS definitions are dereferenced before the operation loads.ResponseExample
andResponseTabs
components are no longer async as they're now supplied a fully dereferenced OAS.ResponseExample
component for APIs from our manual editor. Previously we were upgrading their responses into a shape that we could handle within therender
method, causing that work to happen anytime the component changed. Since this work should be static it's now happening within the constructor of theResponse
component.🧪 Testing
The following areas need some attention:
$ref
can still be loaded handled within the form.🐳 Notes
Why do this?
A couple reasons!
$ref
lookups.json-schema-ref-parser
has some options to ignore circular schemas and leave the$ref
intact within the OAS so this allows us to quickly detect a ciruclar schema so we can ignore it without having to write our own recursive traversal mapping logic.$ref
lookups, we end up doing a lot of the same work multiple times depending on how often a$ref
is used within an OAS. By dereferencing the OAS up front we now no longer have$ref
components anywhere within the spec and don't need to fetch schemas on demand.Why dereference here?
Instead of doing this dereference work within the explorer and creating these async components, why not send the explorer a fully dereferenced OAS instead? Good question! The problem with doing that is right now for our legacy Swagger definitions we're storing them in the DB with circular-json in order for us to be stringify circular schemas. We currently do not do this for OAS definitions.
It's currently an open question whether we still need to do this, or if we could stringify a dereferenced (while ignoring circular schemas as we do in
oas
, see this code), but until we solve that this is the way to go.Testing issues
The testing changes here are extremely shitty and I am not happy with them at all. I tried moving these
Doc
component tests over to using @testing-library/react but with the current HTML that the explorer has makes it extremely difficult to create tests off roles without addingdata-testid
literally everywhere.Another thing is that the OAS dereferencing error states are really difficult to test because React error boundaries don't support catching exceptions thrown from
componentDidMount
so we have to hack it into catching exceptions by throwing them within asetState
call (facebook/react#11334 (comment)). Problem with this is that this method only makes the errors able to get caught in the error boundary when running in a browser, Enzyme just throws it. There's got to be a better way to handle these.But yeah, those error boundary tests are being skipped right now. 😔