diff --git a/compiler-rs/clients_schema/src/lib.rs b/compiler-rs/clients_schema/src/lib.rs index def9228cfe..2ee7d84948 100644 --- a/compiler-rs/clients_schema/src/lib.rs +++ b/compiler-rs/clients_schema/src/lib.rs @@ -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; @@ -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")] diff --git a/compiler-rs/clients_schema_to_openapi/src/paths.rs b/compiler-rs/clients_schema_to_openapi/src/paths.rs index 22cf4f7a4d..c4f0432758 100644 --- a/compiler-rs/clients_schema_to_openapi/src/paths.rs +++ b/compiler-rs/clients_schema_to_openapi/src/paths.rs @@ -15,11 +15,12 @@ // 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; @@ -27,9 +28,11 @@ 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. @@ -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 { + let mut extensions: IndexMap = 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)?, @@ -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 }) } diff --git a/compiler-rs/compiler-wasm-lib/pkg/compiler_wasm_lib_bg.wasm b/compiler-rs/compiler-wasm-lib/pkg/compiler_wasm_lib_bg.wasm index 898e7ef0dd..549017542e 100644 Binary files a/compiler-rs/compiler-wasm-lib/pkg/compiler_wasm_lib_bg.wasm and b/compiler-rs/compiler-wasm-lib/pkg/compiler_wasm_lib_bg.wasm differ diff --git a/output/openapi/elasticsearch-openapi.json b/output/openapi/elasticsearch-openapi.json index 168720dcd3..96a1a8cbf0 100644 --- a/output/openapi/elasticsearch-openapi.json +++ b/output/openapi/elasticsearch-openapi.json @@ -12921,6 +12921,7 @@ "schema": { "$ref": "#/components/schemas/indices.get.Features" }, + "x-state": "Added in 8.1.0", "style": "form" } ], @@ -16760,6 +16761,7 @@ "schema": { "type": "boolean" }, + "x-state": "Added in 8.11.0", "style": "form" } ], @@ -23119,6 +23121,7 @@ "schema": { "type": "boolean" }, + "x-state": "Added in 8.0.0", "style": "form" }, { @@ -23129,6 +23132,7 @@ "schema": { "type": "boolean" }, + "x-state": "Added in 8.8.0", "style": "form" } ], @@ -26194,6 +26198,7 @@ "schema": { "type": "string" }, + "x-state": "Added in 8.8.0", "style": "form" }, { @@ -33333,6 +33338,7 @@ "schema": { "type": "boolean" }, + "x-state": "Added in 8.5.0", "style": "form" }, { @@ -33343,6 +33349,7 @@ "schema": { "type": "boolean" }, + "x-state": "Added in 8.10.0", "style": "form" }, { @@ -33353,6 +33360,7 @@ "schema": { "type": "boolean" }, + "x-state": "Added in 8.14.0", "style": "form" } ], @@ -38028,6 +38036,7 @@ "schema": { "type": "string" }, + "x-state": "Added in 7.14.0", "style": "form" }, { @@ -38038,6 +38047,7 @@ "schema": { "type": "string" }, + "x-state": "Added in 7.16.0", "style": "form" }, { @@ -38058,6 +38068,7 @@ "schema": { "type": "boolean" }, + "x-state": "Added in 7.13.0", "style": "form" }, { @@ -38068,6 +38079,7 @@ "schema": { "type": "boolean" }, + "x-state": "Added in 8.3.0", "style": "form" }, { @@ -38098,6 +38110,7 @@ "schema": { "$ref": "#/components/schemas/_types.SortOrder" }, + "x-state": "Added in 7.14.0", "style": "form" }, { @@ -38108,6 +38121,7 @@ "schema": { "type": "number" }, + "x-state": "Added in 7.15.0", "style": "form" }, { @@ -38118,6 +38132,7 @@ "schema": { "type": "number" }, + "x-state": "Added in 7.14.0", "style": "form" }, { @@ -38128,6 +38143,7 @@ "schema": { "$ref": "#/components/schemas/_types.Name" }, + "x-state": "Added in 7.16.0", "style": "form" }, { @@ -38138,6 +38154,7 @@ "schema": { "$ref": "#/components/schemas/snapshot._types.SnapshotSort" }, + "x-state": "Added in 7.14.0", "style": "form" }, { @@ -39664,6 +39681,7 @@ "schema": { "type": "boolean" }, + "x-state": "Added in 9.1.0", "style": "form" } ], @@ -39846,6 +39864,7 @@ "schema": { "type": "boolean" }, + "x-state": "Added in 9.1.0", "style": "form" } ], @@ -39932,6 +39951,7 @@ "schema": { "type": "boolean" }, + "x-state": "Added in 9.1.0", "style": "form" } ], @@ -107195,6 +107215,7 @@ "schema": { "type": "boolean" }, + "x-state": "Added in 8.11.0", "style": "form" }, "cluster.get_component_template-local": { @@ -108138,6 +108159,7 @@ "schema": { "type": "string" }, + "x-state": "Added in 8.2.0", "style": "form" }, "field_caps-types": { @@ -108151,6 +108173,7 @@ "type": "string" } }, + "x-state": "Added in 8.2.0", "style": "form" }, "field_caps-include_empty_fields": { @@ -108161,6 +108184,7 @@ "schema": { "type": "boolean" }, + "x-state": "Added in 8.13.0", "style": "form" }, "fleet.msearch-index": { @@ -109541,6 +109565,7 @@ "schema": { "type": "boolean" }, + "x-state": "Added in 8.11.0", "style": "form" }, "indices.get_data_stream-master_timeout": { @@ -109674,6 +109699,7 @@ "schema": { "type": "boolean" }, + "x-state": "Added in 8.11.0", "style": "form" }, "indices.get_mapping-index": { @@ -110625,6 +110651,7 @@ "schema": { "type": "boolean" }, + "x-state": "Added in 8.11.0", "style": "form" }, "indices.split-index": { @@ -113705,6 +113732,7 @@ "schema": { "type": "boolean" }, + "x-state": "Added in 8.14.0", "style": "form" }, "search_mvt-index": { @@ -114042,6 +114070,7 @@ "schema": { "type": "boolean" }, + "x-state": "Added in 7.0.0", "style": "form" }, "search_template-typed_keys": { @@ -114389,6 +114418,7 @@ "schema": { "type": "boolean" }, + "x-state": "Added in 8.5.0", "style": "form" }, "security.has_privileges-user": { @@ -114483,6 +114513,7 @@ "schema": { "type": "boolean" }, + "x-state": "Added in 8.5.0", "style": "form" }, "security.query_api_keys-with_profile_uid": { @@ -114493,6 +114524,7 @@ "schema": { "type": "boolean" }, + "x-state": "Added in 8.14.0", "style": "form" }, "security.query_api_keys-typed_keys": { @@ -114503,6 +114535,7 @@ "schema": { "type": "boolean" }, + "x-state": "Added in 8.14.0", "style": "form" }, "security.query_user-with_profile_uid": {