Skip to content

Commit 6bf0830

Browse files
committed
implement review from @davepacheco
1 parent f988df9 commit 6bf0830

File tree

5 files changed

+23
-18
lines changed

5 files changed

+23
-18
lines changed

dropshot/src/extractor/body.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +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
3332
/// `BodyType` from an HTTP request body. `BodyType` may be any struct of yours
34-
/// that implements [serde::Deserialize] and [schemars::JsonSchema], where
35-
/// primitives and enums have to be wrapped in an outer struct and enums need
36-
/// to be flattened using the `#[serde(flatten)]` attribute. See this module's
37-
/// documentation formore information.
33+
/// that implements [serde::Deserialize] and [schemars::JsonSchema].
34+
/// See this module's documentation for more information.
3835
#[derive(Debug)]
3936
pub struct TypedBody<BodyType: JsonSchema + DeserializeOwned + Send + Sync> {
4037
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: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ use std::fmt::Debug;
1919
/// `Path<PathType>` is an extractor used to deserialize an instance of
2020
/// `PathType` from an HTTP request's path parameters. `PathType` may be any
2121
/// struct of yours that implements [serde::Deserialize] and
22-
/// [schemars::JsonSchema], where primitives and enums have to be wrapped in an
23-
/// outer struct and enums need to be flattened using the `#[serde(flatten)]`
24-
/// attribute. See this module's documentation formore information.
22+
/// [schemars::JsonSchema].
23+
/// See the top-level crate documentation for more information.
2524
#[derive(Debug)]
2625
pub struct Path<PathType: JsonSchema + Send + Sync> {
2726
inner: PathType,

dropshot/src/extractor/query.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@ use std::fmt::Debug;
1919
/// `Query<QueryType>` is an extractor used to deserialize an instance of
2020
/// `QueryType` from an HTTP request's query string. `QueryType` may be any
2121
/// struct of yours that implements [serde::Deserialize] and
22-
/// [schemars::JsonSchema], where primitives and enums have to be wrapped in
23-
/// an outer struct and enums need to be flattened using the
24-
/// `#[serde(flatten)]` attribute. See this module's documentation for more
25-
/// information.
22+
/// [schemars::JsonSchema].
23+
/// See the top-level crate documentation for more information.
2624
#[derive(Debug)]
2725
pub struct Query<QueryType: DeserializeOwned + JsonSchema + Send + Sync> {
2826
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 qquery 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)