Skip to content
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

Add the operation ID to the RequestContext #1087

Merged
merged 3 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,18 @@ https://github.com/oxidecomputer/dropshot/compare/v0.10.1\...HEAD[Full list of c
=== Breaking Changes

* For `ApiEndpoint::register`, the `Err` variant now returns a structured `ApiDescriptionRegisterError` rather than a string.
* https://github.com/oxidecomputer/dropshot/pull/1087[#1087] The
`RequestContext` type now contains the `operation_id`, the name of the endpoint
handler. This is the name of the Rust handler function, if one uses the
`dropshot::endpoint` macro, and the value of the `operationId` field in the
generated OpenAPI spec.
* `TagConfig` field names have changed, for consistency with tag configuration in API traits. The `Deserialize` implementation will still work with the old field names, but the `Serialize` implementation will always produce the new field names.
** `endpoint_tag_policy` is now called `policy`.
** `tag_definitions` is now called `tags`.

=== Other notable changes


== 0.10.1 (released 2024-05-15)

https://github.com/oxidecomputer/dropshot/compare/v0.10.0\...v0.10.1[Full list of commits]
Expand Down
3 changes: 2 additions & 1 deletion dropshot/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ pub struct RequestContext<Context: ServerContext> {
pub request_id: String,
/// logger for this specific request
pub log: Logger,

/// The operation ID for the endpoint handler method
pub operation_id: String,
/// basic request information (method, URI, etc.)
pub request: RequestInfo,
}
Expand Down
2 changes: 2 additions & 0 deletions dropshot/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ impl MapValue for VariableValue {
#[derive(Debug)]
pub struct RouterLookupResult<Context: ServerContext> {
pub handler: Arc<dyn RouteHandler<Context>>,
pub operation_id: String,
pub variables: VariableSet,
pub body_content_type: ApiEndpointBodyContentType,
}
Expand Down Expand Up @@ -482,6 +483,7 @@ impl<Context: ServerContext> HttpRouter<Context> {
.get(&methodname)
.map(|handler| RouterLookupResult {
handler: Arc::clone(&handler.handler),
operation_id: handler.operation_id.clone(),
variables,
body_content_type: handler.body_content_type.clone(),
})
Expand Down
1 change: 1 addition & 0 deletions dropshot/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,7 @@ async fn http_request_handle<C: ServerContext>(
request: RequestInfo::new(&request, remote_addr),
path_variables: lookup_result.variables,
body_content_type: lookup_result.body_content_type,
operation_id: lookup_result.operation_id,
request_id: request_id.to_string(),
log: request_log,
};
Expand Down
1 change: 1 addition & 0 deletions dropshot/src/websocket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ mod tests {
request: RequestInfo::new(&request, remote_addr),
path_variables: Default::default(),
body_content_type: Default::default(),
operation_id: "".to_string(),
request_id: "".to_string(),
log: log.clone(),
};
Expand Down