Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(rust): revamp the OpenAPI specification #1564

Merged
merged 7 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/ci-rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ jobs:
openssl-3
pam-devel
python-langtable-data
python3-openapi_spec_validator
timezone
xkeyboard-config

Expand All @@ -101,6 +102,11 @@ jobs:
- name: Run the tests
run: cargo tarpaulin --out xml -- --nocapture

- name: Generate and validate the OpenAPI specification
run: |
cargo xtask openapi
openapi-spec-validator out/openapi/*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great that it is validated 👍 , but does it also find missing piece?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, if it is mentioned and not defined, it is found here (most of the problems were like that). About completely forgotten stuff, we might need to try something different (but I do not know what).


# send the code coverage for the Rust part to the coveralls.io
- name: Coveralls GitHub Action
uses: coverallsapp/github-action@v2
Expand Down
3 changes: 3 additions & 0 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions rust/agama-lib/src/network/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ use std::default::Default;
use std::net::IpAddr;

/// Network settings for installation
#[derive(Debug, Default, Serialize, Deserialize)]
#[derive(Debug, Default, Serialize, Deserialize, utoipa::ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct NetworkSettings {
/// Connections to use in the installation
pub connections: Vec<NetworkConnection>,
}

#[derive(Clone, Debug, Default, Serialize, Deserialize)]
#[derive(Clone, Debug, Default, Serialize, Deserialize, utoipa::ToSchema)]
pub struct MatchSettings {
#[serde(skip_serializing_if = "Vec::is_empty", default)]
pub driver: Vec<String>,
Expand All @@ -56,7 +56,7 @@ impl MatchSettings {
}

/// Wireless configuration
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
#[derive(Clone, Debug, Default, Serialize, Deserialize, utoipa::ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct WirelessSettings {
/// Password of the wireless network
Expand Down Expand Up @@ -94,7 +94,7 @@ pub struct WirelessSettings {
pub pmf: i32,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, Serialize, Deserialize, utoipa::ToSchema)]
pub struct BondSettings {
pub mode: String,
#[serde(skip_serializing_if = "Option::is_none")]
Expand All @@ -114,7 +114,7 @@ impl Default for BondSettings {
}

/// IEEE 802.1x (EAP) settings
#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, Serialize, Deserialize, utoipa::ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct IEEE8021XSettings {
/// List of EAP methods used
Expand Down
8 changes: 4 additions & 4 deletions rust/agama-lib/src/network/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub struct Device {
pub state: DeviceState,
}

#[derive(Debug, Default, PartialEq, Clone, Serialize, Deserialize)]
#[derive(Debug, Default, PartialEq, Clone, Serialize, Deserialize, utoipa::ToSchema)]
pub struct SSID(pub Vec<u8>);

impl SSID {
Expand Down Expand Up @@ -80,7 +80,7 @@ pub enum DeviceType {

// For now this mirrors NetworkManager, because it was less mental work than coming up with
// what exactly Agama needs. Expected to be adapted.
#[derive(Debug, Default, Clone, Copy, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Default, Clone, Copy, PartialEq, Serialize, Deserialize, utoipa::ToSchema)]
#[serde(rename_all = "camelCase")]
pub enum DeviceState {
#[default]
Expand Down Expand Up @@ -145,7 +145,7 @@ impl fmt::Display for DeviceState {
}
}

#[derive(Debug, Default, Clone, Copy, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Default, Clone, Copy, PartialEq, Serialize, Deserialize, utoipa::ToSchema)]
#[serde(rename_all = "camelCase")]
pub enum Status {
#[default]
Expand Down Expand Up @@ -183,7 +183,7 @@ impl TryFrom<&str> for Status {
}

/// Bond mode
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone, Copy)]
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone, Copy, utoipa::ToSchema)]
pub enum BondMode {
#[serde(rename = "balance-rr")]
RoundRobin = 0,
Expand Down
2 changes: 1 addition & 1 deletion rust/agama-lib/src/software/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub struct Pattern {
}

/// Represents the reason why a pattern is selected.
#[derive(Clone, Copy, Debug, PartialEq, Serialize_repr)]
#[derive(Clone, Copy, Debug, PartialEq, Serialize_repr, utoipa::ToSchema)]
#[repr(u8)]
pub enum SelectedBy {
/// The pattern was selected by the user.
Expand Down
1 change: 1 addition & 0 deletions rust/agama-locale-data/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ flate2 = "1.0.34"
chrono-tz = "0.8.6"
regex = "1"
thiserror = "1.0.64"
utoipa = "4.2.3"
6 changes: 4 additions & 2 deletions rust/agama-locale-data/src/locale.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use std::sync::OnceLock;
use std::{fmt::Display, str::FromStr};
use thiserror::Error;

#[derive(Clone, Debug, PartialEq, Serialize)]
#[derive(Clone, Debug, PartialEq, Serialize, utoipa::ToSchema)]
pub struct LocaleId {
// ISO-639
pub language: String,
Expand Down Expand Up @@ -100,9 +100,11 @@ static KEYMAP_ID_REGEX: OnceLock<Regex> = OnceLock::new();
/// let id_with_dashes: KeymapId = "es-ast".parse().unwrap();
/// assert_eq!(id, id_with_dashes);
/// ```
#[derive(Clone, Debug, PartialEq, Serialize)]
#[derive(Clone, Debug, PartialEq, Serialize, utoipa::ToSchema)]
pub struct KeymapId {
/// Keyboard layout (e.g., "es" in "es(ast)")
pub layout: String,
/// Keyboard variante (e.g., "ast" in "es(ast)")
pub variant: Option<String>,
}

Expand Down
2 changes: 1 addition & 1 deletion rust/agama-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ tracing-journald = "0.3.0"
tracing = "0.1.40"
clap = { version = "4.5.19", features = ["derive", "wrap_help"] }
tower = { version = "0.4.13", features = ["util"] }
utoipa = { version = "4.2.3", features = ["axum_extras"] }
utoipa = { version = "4.2.0", features = ["axum_extras", "uuid"] }
config = "0.14.0"
rand = "0.8.5"
axum-extra = { version = "0.9.4", features = ["cookie", "typed-header"] }
Expand Down
10 changes: 0 additions & 10 deletions rust/agama-server/src/agama-web-server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ use openssl::ssl::{Ssl, SslAcceptor, SslMethod};
use tokio::sync::broadcast::channel;
use tokio_openssl::SslStream;
use tower::Service;
use utoipa::OpenApi;

const DEFAULT_WEB_UI_DIR: &str = "/usr/share/agama/web_ui";
const TOKEN_FILE: &str = "/run/agama/token";
Expand All @@ -58,8 +57,6 @@ enum Commands {
/// This command starts the server in the given ports. The secondary port, if enabled, uses SSL.
/// If no certificate is specified, agama-web-server generates a self-signed one.
Serve(ServeArgs),
/// Generates the API documentation in OpenAPI format.
Openapi,
}

/// Manage Agama's HTTP/JSON API.
Expand Down Expand Up @@ -379,16 +376,9 @@ async fn serve_command(args: ServeArgs) -> anyhow::Result<()> {
Ok(())
}

/// Display the API documentation in OpenAPI format.
fn openapi_command() -> anyhow::Result<()> {
println!("{}", web::ApiDoc::openapi().to_pretty_json().unwrap());
Ok(())
}

async fn run_command(cli: Cli) -> anyhow::Result<()> {
match cli.command {
Commands::Serve(options) => serve_command(options).await,
Commands::Openapi => openapi_command(),
}
}

Expand Down
Loading