Skip to content

Commit 1396311

Browse files
authored
fix: clippy (#9)
1 parent 0a00d42 commit 1396311

File tree

5 files changed

+27
-16
lines changed

5 files changed

+27
-16
lines changed

.github/workflows/example.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ on:
99
env:
1010
RUST_TOOLCHAIN: stable
1111
TOOLCHAIN_PROFILE: minimal
12-
CARGO_MANIFEST_DIR: ./example
1312

1413
jobs:
1514
rustfmt:
@@ -51,7 +50,7 @@ jobs:
5150
uses: actions-rs/cargo@v1
5251
with:
5352
command: clippy
54-
args: --all-features -- -D warnings -W clippy::pedantic -W clippy::nursery -W rust-2018-idioms
53+
args: --all-features -- -D warnings -W clippy::pedantic -W clippy::nursery -W rust-2018-idioms -A clippy::result_large_err
5554

5655
test:
5756
name: Run Tests

src/config.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ use serde::{Deserialize, Serialize};
55

66
static OPENAPI_CONFIG: OnceLock<Option<OpenAPIConfig>> = OnceLock::new();
77

8+
/// # Errors
9+
///
10+
/// Will return `Err` if initializers: openapi: is not set in config/*.yaml
811
pub fn set_openapi_config(ctx: &AppContext) -> Result<Option<&OpenAPIConfig>, Error> {
912
let json = ctx
1013
.config

src/lib.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,16 @@ pub mod utils;
2323
type RouterList = Option<Vec<OpenApiRouter<AppContext>>>;
2424
type InitialSpec = dyn Fn(&AppContext) -> OpenApi + Send + Sync + 'static;
2525

26-
/// Loco initializer for OpenAPI with custom initial spec setup
26+
/// Loco initializer for `OpenAPI` with custom initial spec setup
2727
#[derive(Default)]
2828
pub struct OpenapiInitializerWithSetup {
29-
/// Custom setup for the initial OpenAPI spec, if any
29+
/// Custom setup for the initial `OpenAPI` spec, if any
3030
initial_spec: Option<Box<InitialSpec>>,
31-
/// Routes to add to the OpenAPI spec
31+
/// Routes to add to the `OpenAPI` spec
3232
routes_setup: RouterList,
3333
}
3434

3535
impl OpenapiInitializerWithSetup {
36-
#[inline(always)]
3736
#[must_use]
3837
pub fn new<F>(initial_spec: F, routes_setup: RouterList) -> Self
3938
where
@@ -55,12 +54,12 @@ impl Initializer for OpenapiInitializerWithSetup {
5554
async fn after_routes(&self, mut router: AxumRouter, ctx: &AppContext) -> Result<AxumRouter> {
5655
set_openapi_config(ctx)?;
5756

58-
let mut api_router: OpenApiRouter<AppContext> =
59-
if let Some(ref custom_spec_fn) = self.initial_spec {
57+
let mut api_router: OpenApiRouter<AppContext> = self
58+
.initial_spec
59+
.as_ref()
60+
.map_or_else(OpenApiRouter::new, |custom_spec_fn| {
6061
OpenApiRouter::with_openapi(custom_spec_fn(ctx))
61-
} else {
62-
OpenApiRouter::new()
63-
};
62+
});
6463

6564
// Merge all manually collected routes
6665
if let Some(ref routes_setup) = self.routes_setup {
@@ -72,17 +71,15 @@ impl Initializer for OpenapiInitializerWithSetup {
7271
// Merge all automatically collected routes
7372
api_router = api_router.merge(get_merged_router());
7473

75-
// Collect the OpenAPI spec
74+
// Collect the `OpenAPI` spec
7675
let (_, open_api_spec) = api_router.split_for_parts();
7776
set_openapi_spec(open_api_spec);
7877

79-
let open_api_config = if let Some(open_api_config) = get_openapi_config() {
80-
open_api_config
81-
} else {
78+
let Some(open_api_config) = get_openapi_config() else {
8279
return Ok(router);
8380
};
8481

85-
// Serve the OpenAPI spec using the enabled OpenAPI visualizers
82+
// Serve the `OpenAPI` spec using the enabled `OpenAPI` visualizers
8683
#[cfg(feature = "redoc")]
8784
if let Some(OpenAPIType::Redoc {
8885
url,

src/openapi.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ pub fn add_route(route: OpenApiRouter<AppContext>) {
1616
}
1717

1818
// Get a merged router containing all collected routes
19+
#[must_use]
1920
pub fn get_merged_router() -> OpenApiRouter<AppContext> {
2021
let mut result = OpenApiRouter::new();
2122

src/utils.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,27 @@ pub fn set_openapi_spec(api: OpenApi) -> &'static OpenApi {
1111
OPENAPI_SPEC.get_or_init(|| api)
1212
}
1313

14+
/// # Panics
15+
///
16+
/// Will panic if `OpenAPI` spec fails to build
1417
pub fn get_openapi_spec() -> &'static OpenApi {
1518
OPENAPI_SPEC.get().unwrap()
1619
}
1720

1821
/// Axum handler that returns the `OpenAPI` spec as JSON
22+
///
23+
/// # Errors
24+
/// Currently this function doesn't return any error. this is for feature
25+
/// functionality
1926
pub async fn openapi_spec_json() -> Result<Response> {
2027
format::json(get_openapi_spec())
2128
}
2229

2330
/// Axum handler that returns the `OpenAPI` spec as YAML
31+
///
32+
/// # Errors
33+
/// Currently this function doesn't return any error. this is for feature
34+
/// functionality
2435
pub async fn openapi_spec_yaml() -> Result<Response> {
2536
format::yaml(&get_openapi_spec().to_yaml()?)
2637
}

0 commit comments

Comments
 (0)