Skip to content

[Backport 8.19] Openapi: adding privileges (#4434) #4521

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 1 commit into from
Jun 11, 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 @@ -8,7 +8,7 @@ publish = false
clients_schema = {path="../clients_schema"}

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 @@ -250,6 +251,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)
};

// Create the operation, it will be repeated if we have several methods
let operation = openapiv3::Operation {
Expand All @@ -259,7 +267,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 @@ -403,6 +411,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,171 changes: 615 additions & 556 deletions output/openapi/elasticsearch-openapi.json

Large diffs are not rendered by default.

548 changes: 289 additions & 259 deletions output/openapi/elasticsearch-serverless-openapi.json

Large diffs are not rendered by default.