Skip to content

Propagating availability information in fields in openapi output #4427

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
10 changes: 10 additions & 0 deletions compiler-rs/clients_schema/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// specific language governing permissions and limitations
// under the License.

use std::fmt;
use std::fmt::{Debug, Display, Formatter};

use anyhow::anyhow;
Expand Down Expand Up @@ -255,6 +256,15 @@ pub enum Flavor {
Serverless,
}

impl Display for Flavor {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
match self {
Flavor::Stack => write!(f, "stack"),
Flavor::Serverless => write!(f, "serverless"),
}
}
}

/// The availability of an item in a API flavor
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
Expand Down
21 changes: 17 additions & 4 deletions compiler-rs/clients_schema_to_openapi/src/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,24 @@
// specific language governing permissions and limitations
// under the License.

use std::string::String;
use std::collections::HashMap;
use std::fmt::Write;

use anyhow::{anyhow, bail};
use clients_schema::Property;
use clients_schema::{Availability, Property};
use indexmap::IndexMap;
use indexmap::indexmap;
use icu_segmenter::SentenceSegmenter;
use openapiv3::{
MediaType, Parameter, ParameterData, ParameterSchemaOrContent, PathItem, PathStyle, Paths, QueryStyle, ReferenceOr,
RequestBody, Response, Responses, StatusCode, Example
};
use serde_json::{Map, Value};
use serde_json::Value::{Object, String as JsonString};
use clients_schema::Flavor::Stack;
use clients_schema::SchemaExample;

use crate::components::TypesAndComponents;
use crate::components::{TypesAndComponents};

/// Add an endpoint to the OpenAPI schema. This will result in the addition of a number of elements to the
/// openapi schema's `paths` and `components` sections.
Expand Down Expand Up @@ -60,6 +63,16 @@ pub fn add_endpoint(
let request = tac.model.get_request(endpoint.request.as_ref().unwrap())?;

fn parameter_data(prop: &Property, in_path: bool, tac: &mut TypesAndComponents) -> anyhow::Result<ParameterData> {
let mut extensions: IndexMap<String,Value> = Default::default();
if let Some(temp_avail) = prop.availability.clone() {
let avail = temp_avail.get(&tac.config.flavor.clone().unwrap_or(Stack));
if avail.is_some() {
if let Some(since) = &avail.unwrap().since {
let stable_since = "Added in ".to_string() + since;
extensions.insert("x-state".to_string(),JsonString(stable_since));
}
}
}
Ok(ParameterData {
name: prop.name.clone(),
description: tac.property_description(prop)?,
Expand All @@ -69,7 +82,7 @@ pub fn add_endpoint(
example: None,
examples: Default::default(),
explode: None, // Defaults to simple, i.e. comma-separated values for arrays
extensions: Default::default(),
extensions
})
}

Expand Down
Binary file modified compiler-rs/compiler-wasm-lib/pkg/compiler_wasm_lib_bg.wasm
Binary file not shown.
33 changes: 33 additions & 0 deletions output/openapi/elasticsearch-openapi.json

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

Loading