Skip to content

Commit da6edd4

Browse files
swallezAnaethelion
andauthored
Add version as an OpenAPI extension, cleanup obsolete properties and versions 0.0.0 (#2655)
Co-authored-by: Laurent Saint-Félix <laurent.saintfelix@elastic.co>
1 parent f169111 commit da6edd4

File tree

110 files changed

+1829
-1113
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+1829
-1113
lines changed

compiler-rs/clients_schema/src/lib.rs

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ pub trait Documented {
5050
fn doc_url(&self) -> Option<&str>;
5151
fn doc_id(&self) -> Option<&str>;
5252
fn description(&self) -> Option<&str>;
53-
fn since(&self) -> Option<&str>;
5453
}
5554

5655
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)]
@@ -252,9 +251,9 @@ pub enum Flavor {
252251
#[derive(Debug, Clone, Serialize, Deserialize)]
253252
#[serde(rename_all = "camelCase")]
254253
pub struct Availability {
255-
since: Option<String>,
256-
stability: Option<Stability>,
257-
visibility: Option<Visibility>,
254+
pub since: Option<String>,
255+
pub stability: Option<Stability>,
256+
pub visibility: Option<Visibility>,
258257
}
259258

260259
/// The availability of an
@@ -312,9 +311,6 @@ pub struct Property {
312311
#[serde(skip_serializing_if = "Option::is_none")]
313312
pub doc_id: Option<String>,
314313

315-
#[serde(skip_serializing_if = "Option::is_none")]
316-
pub since: Option<String>,
317-
318314
#[serde(skip_serializing_if = "Option::is_none")]
319315
pub server_default: Option<ServerDefault>,
320316

@@ -324,9 +320,6 @@ pub struct Property {
324320
#[serde(skip_serializing_if = "Option::is_none")]
325321
pub availability: Option<Availabilities>,
326322

327-
#[serde(skip_serializing_if = "Option::is_none")]
328-
pub stability: Option<Stability>,
329-
330323
/// If specified takes precedence over `name` when generating code. `name` is always the value
331324
/// to be sent over the wire
332325
#[serde(skip_serializing_if = "Option::is_none")]
@@ -357,10 +350,6 @@ impl Documented for Property {
357350
fn description(&self) -> Option<&str> {
358351
self.description.as_deref()
359352
}
360-
361-
fn since(&self) -> Option<&str> {
362-
self.since.as_deref()
363-
}
364353
}
365354

366355
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -536,10 +525,6 @@ impl Documented for BaseType {
536525
fn description(&self) -> Option<&str> {
537526
self.description.as_deref()
538527
}
539-
540-
fn since(&self) -> Option<&str> {
541-
None
542-
}
543528
}
544529

545530
trait WithBaseType {
@@ -558,10 +543,6 @@ impl<T: WithBaseType> Documented for T {
558543
fn description(&self) -> Option<&str> {
559544
self.base().description()
560545
}
561-
562-
fn since(&self) -> Option<&str> {
563-
self.base().since()
564-
}
565546
}
566547

567548
/// An interface type
@@ -843,20 +824,6 @@ pub struct Endpoint {
843824

844825
pub urls: Vec<UrlTemplate>,
845826

846-
/// The version when this endpoint reached its current stability level.
847-
/// Missing data means "forever", i.e. before any of the target client versions produced from this spec.
848-
#[serde(skip_serializing_if = "Option::is_none")]
849-
pub since: Option<String>,
850-
851-
#[serde(skip_serializing_if = "Option::is_none")]
852-
pub stability: Option<Stability>,
853-
854-
#[serde(skip_serializing_if = "Option::is_none")]
855-
pub visibility: Option<Visibility>,
856-
857-
#[serde(skip_serializing_if = "Option::is_none")]
858-
pub feature_flag: Option<String>,
859-
860827
#[serde(default, skip_serializing_if = "Vec::is_empty")]
861828
pub request_media_type: Vec<String>,
862829

@@ -879,10 +846,6 @@ impl Documented for Endpoint {
879846
fn description(&self) -> Option<&str> {
880847
Some(self.description.as_str())
881848
}
882-
883-
fn since(&self) -> Option<&str> {
884-
self.since.as_deref()
885-
}
886849
}
887850

888851
#[derive(Debug, Clone, Serialize, Deserialize)]

compiler-rs/clients_schema_to_openapi/src/lib.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ mod utils;
2323
use std::collections::HashSet;
2424
use std::io::{BufWriter, Write};
2525
use std::path::Path;
26+
use indexmap::IndexMap;
2627

2728
use clients_schema::{Availabilities, Endpoint, IndexedModel};
2829
use openapiv3::{Components, OpenAPI};
@@ -147,3 +148,19 @@ fn info(model: &IndexedModel) -> openapiv3::Info {
147148
extensions: Default::default(),
148149
}
149150
}
151+
152+
pub fn availability_as_extension(availabilities: &Option<Availabilities>) -> IndexMap<String, serde_json::Value> {
153+
let mut result = IndexMap::new();
154+
155+
if let Some(avails) = availabilities {
156+
// We may have several availabilities, but since generally exists only on stateful (stack)
157+
for (_, availability) in avails {
158+
if let Some(since) = &availability.since {
159+
result.insert("x-available-since".to_string(), serde_json::Value::String(since.clone()));
160+
break;
161+
}
162+
}
163+
}
164+
165+
result
166+
}

compiler-rs/clients_schema_to_openapi/src/paths.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,10 @@ pub fn add_endpoint(
211211
deprecated: endpoint.deprecation.is_some(),
212212
security: None,
213213
servers: vec![],
214-
extensions: Default::default(), // FIXME: translate availability?
214+
extensions: crate::availability_as_extension(&endpoint.availability),
215215
};
216216

217+
217218
let mut operation_path = url_template.path.clone();
218219

219220
// Disabled -- OpenAPI path templates do not contain the query string

compiler-rs/clients_schema_to_openapi/src/schemas.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,12 +472,11 @@ impl<'a> TypesAndComponents<'a> {
472472
data.external_docs = self.convert_external_docs(prop);
473473
data.deprecated = prop.deprecation.is_some();
474474
data.description = prop.description.clone();
475+
data.extensions = crate::availability_as_extension(&prop.availability);
475476
// TODO: prop.aliases as extensions
476477
// TODO: prop.server_default as extension
477-
// TODO: prop.availability as extension
478478
// TODO: prop.doc_id as extension (new representation of since and stability)
479479
// TODO: prop.es_quirk as extension?
480480
// TODO: prop.codegen_name as extension?
481-
// TODO: prop.deprecation as extension
482481
}
483482
}

compiler-rs/clients_schema_to_openapi/src/utils.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,6 @@ pub trait IntoSchema {
8686
schema
8787
}
8888

89-
fn into_schema_with_data_fn(self, f: fn(&mut SchemaData) -> ()) -> Schema
90-
where Self: Sized {
91-
let mut schema = self.into_schema();
92-
f(&mut schema.schema_data);
93-
schema
94-
}
95-
9689
fn into_schema(self) -> Schema;
9790
}
9891

Binary file not shown.

0 commit comments

Comments
 (0)