Skip to content

Commit

Permalink
we are inadvertently generating OpenAPI documents with wildcard path …
Browse files Browse the repository at this point in the history
…parameters (#197)
  • Loading branch information
ahl authored Nov 29, 2021
1 parent 59c01bf commit 123d0e5
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@

https://github.com/oxidecomputer/dropshot/compare/v0.6.0\...HEAD[Full list of commits]

=== Breaking Changes

* https://github.com/oxidecomputer/dropshot/pull/197[#197] Endpoints using wildcard path params (i.e. those using the `/foo/{bar:.*}` syntax) previously could be included in OpenAPI output albeit in a form that was invalid. Specifying a wildcard path **without** also specifying `unpublished = true` is now a **compile-time error**.

== 0.6.0 (released 2021-11-18)

https://github.com/oxidecomputer/dropshot/compare/v0.5.1\...v0.6.0[Full list of commits]
Expand Down
30 changes: 30 additions & 0 deletions dropshot/tests/fail/bad_endpoint14.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2021 Oxide Computer Company

#![allow(unused_imports)]

use dropshot::endpoint;
use dropshot::HttpError;
use dropshot::HttpResponseOk;
use dropshot::Path;
use dropshot::RequestContext;
use schemars::JsonSchema;
use serde::Deserialize;
use std::sync::Arc;

#[derive(JsonSchema, Deserialize)]
struct PathParams {
stuff: Vec<String>,
}

#[endpoint {
method = GET,
path = "/assets/{stuff:.*}",
}]
async fn must_be_unpublished(
_: Arc<RequestContext<()>>,
_: Path<PathParams>,
) -> Result<HttpResponseOk<String>, HttpError> {
panic!()
}

fn main() {}
6 changes: 6 additions & 0 deletions dropshot/tests/fail/bad_endpoint14.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
error: paths that contain a wildcard match must include 'unpublished = true'
--> tests/fail/bad_endpoint14.rs:20:5
|
20 | / method = GET,
21 | | path = "/assets/{stuff:.*}",
| |________________________________^
10 changes: 8 additions & 2 deletions dropshot_endpoint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
*/
#![allow(clippy::style)]

extern crate proc_macro;

use proc_macro2::TokenStream;
use quote::format_ident;
use quote::quote;
Expand Down Expand Up @@ -397,6 +395,14 @@ fn do_endpoint(
errors.insert(0, Error::new_spanned(&ast.sig, USAGE));
}

if path.contains(":.*}") && metadata.unpublished != Some(true) {
errors.push(Error::new_spanned(
&attr,
"paths that contain a wildcard match must include 'unpublished = \
true'",
));
}

Ok((stream, errors))
}

Expand Down

0 comments on commit 123d0e5

Please sign in to comment.