Skip to content

Openapi: adding privileges #4434

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

Merged
merged 7 commits into from
Jun 9, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion compiler-rs/Cargo.lock

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

2 changes: 1 addition & 1 deletion compiler-rs/clients_schema/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ pub struct Availability {
pub visibility: Option<Visibility>,
}

/// The availability of an
/// The availability of an endpoint, field or parameter
pub type Availabilities = IndexMap<Flavor, Availability>;

pub trait AvailabilityFilter: Fn(&Option<Availabilities>) -> bool {}
Expand Down
2 changes: 1 addition & 1 deletion compiler-rs/clients_schema_to_openapi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ clients_schema = {path="../clients_schema"}
argh = { workspace = true }
derive_more = { version = "2", features = ["from_str"] }
serde_json = { workspace = true }
serde_ignored = { workspace = true }
itertools = { workspace = true }
icu_segmenter = { workspace = true }
openapiv3 = { workspace = true }
anyhow = { workspace = true }
Expand Down
32 changes: 30 additions & 2 deletions compiler-rs/clients_schema_to_openapi/src/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ use std::collections::HashMap;
use std::fmt::Write;

use anyhow::{anyhow, bail};
use clients_schema::{Property};
use clients_schema::{Privileges, Property};
use indexmap::IndexMap;
use indexmap::indexmap;
use icu_segmenter::SentenceSegmenter;
use itertools::Itertools;
use openapiv3::{
MediaType, Parameter, ParameterData, ParameterSchemaOrContent, PathItem, PathStyle, Paths, QueryStyle, ReferenceOr,
RequestBody, Response, Responses, StatusCode, Example
Expand Down Expand Up @@ -253,6 +254,13 @@ pub fn add_endpoint(
parameters.append(&mut query_params.clone());

let sum_desc = split_summary_desc(&endpoint.description);

let privilege_desc = add_privileges(&endpoint.privileges);

let full_desc = match (sum_desc.description, privilege_desc) {
(Some(a), Some(b)) => Some(a+ &b),
(opt_a, opt_b) => opt_a.or(opt_b)
};

// add the x-state extension for availability
let mut extensions = crate::availability_as_extensions(&endpoint.availability, &tac.config.flavor);
Expand Down Expand Up @@ -300,7 +308,7 @@ pub fn add_endpoint(
vec![namespace.to_string()]
},
summary: sum_desc.summary,
description: sum_desc.description,
description: full_desc,
external_docs: tac.convert_external_docs(endpoint),
// external_docs: None, // Need values that differ from client purposes
operation_id: None, // set in clone_operation below with operation_counter
Expand Down Expand Up @@ -444,6 +452,26 @@ fn split_summary_desc(desc: &str) -> SplitDesc{
}
}

fn add_privileges(privileges: &Option<Privileges>) -> Option<String>{
if let Some(privs) = privileges {
let mut result = "\n ##Required authorization\n".to_string();
if !privs.index.is_empty() {
result += "* Index privileges: ";
result += &privs.index.iter()
.map(|a| format!("`{a}`"))
.join(",");
}
if !privs.cluster.is_empty() {
result += "* Cluster privileges: ";
result += &privs.cluster.iter()
.map(|a| format!("`{a}`"))
.join(",");
}
return Some(result)
}
None
}

#[derive(PartialEq,Debug)]
struct SplitDesc {
summary: Option<String>,
Expand Down
Binary file modified compiler-rs/compiler-wasm-lib/pkg/compiler_wasm_lib_bg.wasm
Binary file not shown.
1,180 changes: 619 additions & 561 deletions output/openapi/elasticsearch-openapi.json

Large diffs are not rendered by default.

564 changes: 297 additions & 267 deletions output/openapi/elasticsearch-serverless-openapi.json

Large diffs are not rendered by default.