-
Notifications
You must be signed in to change notification settings - Fork 278
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
$status var in responses #6225
$status var in responses #6225
Conversation
✅ Docs Preview ReadyNo new or changed pages found. |
CI performance tests
|
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 good, though it needs a rebase and I have a couple inline comments below.
if let Some(status) = status { | ||
map.insert("$status".to_string(), Value::Number(status.into())); | ||
} |
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 it make sense to default $status
to Value::Number(200.into())
in this map? That way we'd be guaranteed it's always defined, and JSONSelection strings that mention $status
can still function even if there's no HTTP response involved.
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.
that's interesting, but i think it's better to have an apply_to
error if you try to use $status
in a body
selection, headers, or URLs. that's certainly a mistake, and it'd be weird to let customers emit 200
s in strange places.
we should probably also validate which variables are available in the different selections. i'll make a ticket for that.
71ea9ed
to
9bd73b3
Compare
@@ -771,7 +771,7 @@ mod helpers { | |||
// (externally-provided) variables like $this, $args, and | |||
// $config. The $ and @ variables, by contrast, are always bound | |||
// to something within the input data. | |||
KnownVariable::Dollar | KnownVariable::AtSign => { | |||
KnownVariable::Dollar | KnownVariable::AtSign | KnownVariable::Status => { |
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.
The fact that KnownVariable::Status
maps to None
here points to something missing here. We're reusing the Variable
and VariableType
definitions from the URL template code, which doesn't seem right, and doesn't capture a key distinction, which is request vs response variables - status only makes sense in a response context. We've already had bugs here, where $context
was passed in where it wasn't supported. I'd like to see some better type definitions around variables which clarify where they can be used and prevent mistakes where a variable is passed in somewhere it isn't supported at the code level, and also enable validations at the user level that they are only referencing variables where they are supported. This doesn't necessarily need to be solved in this PR, but it does come up here as it's really unclear without additional context why this one variable maps to None
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.
yeah that's a good point. i'll make a ticket
Checklist
Complete the checklist (and note appropriate exceptions) before the PR is marked ready-for-review.
Exceptions
Note any exceptions here
Notes
Footnotes
It may be appropriate to bring upcoming changes to the attention of other (impacted) groups. Please endeavour to do this before seeking PR approval. The mechanism for doing this will vary considerably, so use your judgement as to how and when to do this. ↩
Configuration is an important part of many changes. Where applicable please try to document configuration examples. ↩
Tick whichever testing boxes are applicable. If you are adding Manual Tests, please document the manual testing (extensively) in the Exceptions. ↩