Skip to content

Commit

Permalink
Fix serverless filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
swallez committed Oct 4, 2023
1 parent cac5cdd commit 3f9daef
Show file tree
Hide file tree
Showing 3 changed files with 28,920 additions and 47,068 deletions.
26 changes: 18 additions & 8 deletions openapi-converter/clients_schema/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,15 +198,15 @@ pub enum LiteralValueValue {

//--------------------------------------------------------------------------------------------

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum Stability {
Stable,
Beta,
Experimental,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum Visibility {
Public,
Expand Down Expand Up @@ -254,12 +254,22 @@ impl Flavor {
}
}

pub fn is_serverless(a: &Option<Availabilities>) -> bool {
Flavor::Serverless.available(a)
}

pub fn is_stack(a: &Option<Availabilities>) -> bool {
Flavor::Stack.available(a)
/// Gets the visibility for a given set of availabilities. If the result is `None`,
/// this flavor isn't available.
pub fn visibility(&self, availabilities: &Option<Availabilities>) -> Option<Visibility> {
if let Some(ref availabilities) = availabilities {
// Some availabilities defined
if let Some(ref availability) = availabilities.get(self) {
// This one exists. Public by default
availability.visibility.clone().or(Some(Visibility::Public))
} else {
// Not available
None
}
} else {
// No restriction: available and public
Some(Visibility::Public)
}
}
}

Expand Down
16 changes: 12 additions & 4 deletions openapi-converter/clients_schema_to_openapi/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use tracing::Level;
use tracing_subscriber::fmt::format::FmtSpan;
use tracing_subscriber::FmtSubscriber;
use std::path::{Path, PathBuf};
use clients_schema::Availabilities;
use clients_schema::{Availabilities, Visibility};

fn main() -> anyhow::Result<()> {

Expand Down Expand Up @@ -77,9 +77,17 @@ impl Cli {
if let Some(flavor) = self.flavor {
if flavor != SchemaFlavor::All {
let filter: fn(&Option<Availabilities>) -> bool = match flavor {
SchemaFlavor::All => |_| true,
SchemaFlavor::Stack => |a| clients_schema::Flavor::is_stack(a),
SchemaFlavor::Serverless => |a| clients_schema::Flavor::is_serverless(a),
SchemaFlavor::All => |_| {
true
},
SchemaFlavor::Stack => |a| {
// Generate public and private items for Stack
clients_schema::Flavor::Stack.available(a)
},
SchemaFlavor::Serverless => |a| {
// Generate only public items for Serverless
clients_schema::Flavor::Serverless.visibility(a) == Some(Visibility::Public)
},
};

model = clients_schema::transform::filter_availability(model, filter)?;
Expand Down
Loading

0 comments on commit 3f9daef

Please sign in to comment.