• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

geo-engine / geoengine / 13988686027

21 Mar 2025 09:30AM UTC coverage: 90.016%. First build
13988686027

Pull #1013

github

web-flow
Merge c56dbfaff into 89b08c00f
Pull Request #1013: Update-utoipa

1088 of 1303 new or added lines in 47 files covered. (83.5%)

126708 of 140762 relevant lines covered (90.02%)

57181.41 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.96
/services/src/cli/openapi.rs
1
#![allow(clippy::print_stderr, clippy::print_stdout)] // okay in CLI
2

3
use crate::api::apidoc::ApiDoc;
4
use clap::Parser;
5
use geoengine_operators::util::spawn_blocking;
6
use utoipa::OpenApi;
7

8
/// Checks if the Geo Engine server is alive
9
#[derive(Debug, Parser)]
10
pub struct OpenAPIGenerate;
11

12
/// Outputs OpenAPI JSON to `STDOUT`
13
pub async fn output_openapi_json(_params: OpenAPIGenerate) -> Result<(), anyhow::Error> {
3✔
14
    spawn_blocking(_output_openapi_json).await?
3✔
15
}
3✔
16

17
fn _output_openapi_json() -> Result<(), anyhow::Error> {
3✔
18
    let mut spec = ApiDoc::openapi();
3✔
19

3✔
20
    // make server a wildcard
3✔
21
    spec.servers = Some(vec![
3✔
22
        utoipa::openapi::ServerBuilder::new()
3✔
23
            .url("{server}/api")
3✔
24
            .parameter(
3✔
25
                "server",
3✔
26
                utoipa::openapi::ServerVariableBuilder::new()
3✔
27
                    .default_value("https://geoengine.io")
3✔
28
                    .build(),
3✔
29
            )
3✔
30
            .build(),
3✔
31
    ]);
3✔
32

33
    println!("{}", serde_json::to_string_pretty(&spec)?);
3✔
34

35
    Ok(())
3✔
36
}
3✔
37

38
#[cfg(test)]
39
mod tests {
40
    use super::*;
41
    use assert_cmd::cargo::CommandCargoExt;
42
    use std::{
43
        path::{Path, PathBuf},
44
        process::{Command, Stdio},
45
    };
46

47
    #[test]
48
    fn it_generates_json() {
1✔
49
        let cli_result = Command::cargo_bin("geoengine-cli")
1✔
50
            .unwrap()
1✔
51
            .arg("openapi")
1✔
52
            .current_dir(workspace_dir())
1✔
53
            .stdout(Stdio::piped())
1✔
54
            .output()
1✔
55
            .unwrap();
1✔
56

1✔
57
        assert!(
1✔
58
            cli_result.status.success(),
1✔
NEW
59
            "failed to run CLI: {cli_result:?}",
×
60
        );
61

62
        let _openapi_spec: serde_json::Value = serde_json::from_slice(&cli_result.stdout).unwrap();
1✔
63
    }
1✔
64

65
    fn workspace_dir() -> PathBuf {
1✔
66
        let output = Command::new(env!("CARGO"))
1✔
67
            .arg("locate-project")
1✔
68
            .arg("--workspace")
1✔
69
            .arg("--message-format=plain")
1✔
70
            .output()
1✔
71
            .unwrap()
1✔
72
            .stdout;
1✔
73
        let cargo_path = Path::new(std::str::from_utf8(&output).unwrap().trim());
1✔
74
        cargo_path.parent().unwrap().to_path_buf()
1✔
75
    }
1✔
76

77
    #[tokio::test]
78
    async fn it_runs_successfully() {
1✔
79
        output_openapi_json(OpenAPIGenerate).await.unwrap();
1✔
80
    }
1✔
81
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc