fix(oas): user data + server variable quirks #848
Merged
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.
🧰 Changes
This PR fixes two interwoven issues related to construction of server variable data.
Issue 1: User Data Payload Retrieval
If a user data payload has a
keys
array, ouroas.defaultVariables()
function will look in there but fail to properly retrieve any data from the top level of that payload.For example, take the following the server variables definition:
And say the user payload looks like this:
Because of a quirk in our
getUserVariable
helper, the presence of thatkeys
array in the user data prevents us from using that top-level data at all. The resulting URL ishttps://demo.example.com:443/v2
when it should behttps://owlbert.example.com:8000/v2
.This was a one-liner fix in 6e89c47 and I also added some test coverage in 366ffed 😌
Issue 2: Server Variable Data Precedence in
oas.url()
Quick background
Once I figured out the solution to issue 1 above, I noticed the following bug — when you're logged in and you have user data populating your server variables, editing the server variables won't update the code sample:
CleanShot.2024-03-21.at.18.38.31-trimmed.mp4
Isolating the issue
After going down a crazy rabbit hole, I discovered the root issue was with how we use
oas.url()
to construct the URL in the auto-generated code snippet in our reference section.For starters, we call
oas-to-snippet
to generate the snippet, which then invokesoas-to-har
:oas/packages/oas-to-snippet/src/index.ts
Line 81 in 77ba97d
Once we're in
oas-to-har
, we invokeoas.url()
to construct the resulting URL:oas/packages/oas-to-har/src/index.ts
Line 277 in 77ba97d
The issue itself
There are essentially three sources for these variable values that we need to deal with (in order of lowest to highest precedence):
The problem is we were prioritizing 2 over 3. This PR reworks some logic related to
oas.url()
to fix that, see 9fbea61 😮💨🧬 QA & Testing
For all of this, the new test cases provide a great visualization of the changes and expected behaviors. That and all the existing test coverage passes, so hopefully we should be in good shape!