Skip to content

Commit

Permalink
Fix DefaultRoutes validator when open-api feature is not enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
spencewenski committed May 19, 2024
1 parent e3a2795 commit bd44d0e
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions src/config/service/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,27 @@ impl Default for DefaultRoutes {
}
}

fn validate_default_routes(default_routes: &DefaultRoutes) -> Result<(), ValidationError> {
let default_enable = default_routes.default_enable;
let api_schema_enabled = default_routes.api_schema.enable.unwrap_or(default_enable);
let scalar_enabled = default_routes.scalar.enable.unwrap_or(default_enable);
let redoc_enabled = default_routes.redoc.enable.unwrap_or(default_enable);

if scalar_enabled && !api_schema_enabled {
return Err(ValidationError::new(
"The Open API schema route must be enabled in order to use the Scalar docs route.",
));
}
if redoc_enabled && !api_schema_enabled {
return Err(ValidationError::new(
"The Open API schema route must be enabled in order to use the Redoc docs route.",
));
fn validate_default_routes(
// This parameter isn't used for some feature flag combinations
#[allow(unused)] default_routes: &DefaultRoutes,
) -> Result<(), ValidationError> {
#[cfg(feature = "open-api")]
{
let default_enable = default_routes.default_enable;
let api_schema_enabled = default_routes.api_schema.enable.unwrap_or(default_enable);
let scalar_enabled = default_routes.scalar.enable.unwrap_or(default_enable);
let redoc_enabled = default_routes.redoc.enable.unwrap_or(default_enable);

if scalar_enabled && !api_schema_enabled {
return Err(ValidationError::new(
"The Open API schema route must be enabled in order to use the Scalar docs route.",
));
}
if redoc_enabled && !api_schema_enabled {
return Err(ValidationError::new(
"The Open API schema route must be enabled in order to use the Redoc docs route.",
));
}
}

Ok(())
Expand Down

0 comments on commit bd44d0e

Please sign in to comment.