Skip to content

Commit 4a1bce5

Browse files
authored
[docs] update extractor docs: fix a typo, increase verbosity (#1388)
1 parent dbf45eb commit 4a1bce5

File tree

5 files changed

+28
-16
lines changed

5 files changed

+28
-16
lines changed

dropshot/src/extractor/body.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,10 @@ use std::fmt::Debug;
2828

2929
// TypedBody: body extractor for formats that can be deserialized to a specific
3030
// type. Only JSON is currently supported.
31-
3231
/// `TypedBody<BodyType>` is an extractor used to deserialize an instance of
33-
/// `BodyType` from an HTTP request body. `BodyType` is any structure of yours
34-
/// that implements `serde::Deserialize`. See this module's documentation for
35-
/// more information.
32+
/// `BodyType` from an HTTP request body. `BodyType` may be any struct of yours
33+
/// that implements [serde::Deserialize] and [schemars::JsonSchema].
34+
/// See this module's documentation for more information.
3635
#[derive(Debug)]
3736
pub struct TypedBody<BodyType: JsonSchema + DeserializeOwned + Send + Sync> {
3837
inner: BodyType,

dropshot/src/extractor/header.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ use super::{metadata::get_metadata, ExtractorMetadata, SharedExtractor};
1919
/// `Header<HeaderType>` is an extractor used to deserialize an instance of
2020
/// `HeaderType` from an HTTP request's header values. `HeaderType` may be any
2121
/// structure that implements [serde::Deserialize] and [schemars::JsonSchema].
22-
/// While headers are accessible through [RequestInfo::headers], using this
23-
/// extractor in an entrypoint causes header inputs to be documented in
24-
/// OpenAPI output. See the crate documentation for more information.
22+
/// While headers are always accessible through [RequestInfo::headers] even
23+
/// without this extractor, using this extractor causes header inputs to be
24+
/// documented in OpenAPI output.
25+
/// See the top-level crate documentation for more information.
2526
///
2627
/// Note that (unlike the [`Query`] and [`Path`] extractors) headers are case-
2728
/// insensitive. You may rename fields with mixed casing (e.g. by using

dropshot/src/extractor/path.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ use serde::de::DeserializeOwned;
1717
use std::fmt::Debug;
1818

1919
/// `Path<PathType>` is an extractor used to deserialize an instance of
20-
/// `PathType` from an HTTP request's path parameters. `PathType` is any
21-
/// structure of yours that implements [serde::Deserialize] and
22-
/// [schemars::JsonSchema]. See the crate documentation for more information.
20+
/// `PathType` from an HTTP request's path parameters. `PathType` may be any
21+
/// struct of yours that implements [serde::Deserialize] and
22+
/// [schemars::JsonSchema].
23+
/// See the top-level crate documentation for more information.
2324
#[derive(Debug)]
2425
pub struct Path<PathType: JsonSchema + Send + Sync> {
2526
inner: PathType,

dropshot/src/extractor/query.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ use serde::de::DeserializeOwned;
1717
use std::fmt::Debug;
1818

1919
/// `Query<QueryType>` is an extractor used to deserialize an instance of
20-
/// `QueryType` from an HTTP request's query string. `QueryType` is any
21-
/// structure of yours that implements [serde::Deserialize] and
22-
/// [schemars::JsonSchema]. See the crate documentation for more information.
20+
/// `QueryType` from an HTTP request's query string. `QueryType` may be any
21+
/// struct of yours that implements [serde::Deserialize] and
22+
/// [schemars::JsonSchema].
23+
/// See the top-level crate documentation for more information.
2324
#[derive(Debug)]
2425
pub struct Query<QueryType: DeserializeOwned + JsonSchema + Send + Sync> {
2526
inner: QueryType,

dropshot/src/lib.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,13 +323,14 @@
323323
//!
324324
//! * [`Query`]`<Q>` extracts parameters from a query string, deserializing them
325325
//! into an instance of type `Q`. `Q` must implement `serde::Deserialize` and
326-
//! `schemars::JsonSchema`.
326+
//! `schemars::JsonSchema`. See below for additional restrictions.
327327
//! * [`Path`]`<P>` extracts parameters from HTTP path, deserializing them into
328328
//! an instance of type `P`. `P` must implement `serde::Deserialize` and
329-
//! `schemars::JsonSchema`.
329+
//! `schemars::JsonSchema`. See below for additional restrictions.
330330
//! * [`Header`]`<H>` extracts parameters from HTTP headers, deserializing
331331
//! them into an instance of type `H`. `H` must implement
332-
//! `serde::Deserialize` and `schemars::JsonSchema`.
332+
//! `serde::Deserialize` and `schemars::JsonSchema`. See below for additional
333+
//! restrictions.
333334
//! * [`TypedBody`]`<J>` extracts content from the request body by parsing the
334335
//! body as JSON (or form/url-encoded) and deserializing it into an instance
335336
//! of type `J`. `J` must implement `serde::Deserialize` and `schemars::JsonSchema`.
@@ -340,6 +341,15 @@
340341
//! hope is that this would generally not be needed. It can be useful to
341342
//! implement functionality not provided by Dropshot.
342343
//!
344+
//! Generally, the type parameter for the `Query`, `Header`, and `Path` extractors
345+
//! should be Rust structs. The struct's field _names_ correspond to the keys in
346+
//! the thing being extracted (i.e., they correspond to query parameter names
347+
//! for `Query`, header names for `Header`, and path component names for `Path`).
348+
//! The struct's field _values_ should generally be Rust primitives, strings,
349+
//! or enums containing no data.
350+
//! There is no facility for automatically parsing the values _again_ (e.g.,
351+
//! as JSON), which means nested values or enums with data cannot be supported.
352+
//!
343353
//! `Query` and `Path` impl `SharedExtractor`. `TypedBody`, `UntypedBody`,
344354
//! `StreamingBody`, and `RawRequest` impl `ExclusiveExtractor`. Your function
345355
//! may accept 0-5 extractors, but only one can be `ExclusiveExtractor`, and it

0 commit comments

Comments
 (0)