Skip to content

Commit

Permalink
Add version as an OpenAPI extension, cleanup obsolete properties and …
Browse files Browse the repository at this point in the history
…versions 0.0.0 (#2655)

Co-authored-by: Laurent Saint-Félix <[email protected]>
  • Loading branch information
swallez and Anaethelion authored Jul 11, 2024
1 parent f169111 commit da6edd4
Show file tree
Hide file tree
Showing 110 changed files with 1,829 additions and 1,113 deletions.
43 changes: 3 additions & 40 deletions compiler-rs/clients_schema/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ pub trait Documented {
fn doc_url(&self) -> Option<&str>;
fn doc_id(&self) -> Option<&str>;
fn description(&self) -> Option<&str>;
fn since(&self) -> Option<&str>;
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)]
Expand Down Expand Up @@ -252,9 +251,9 @@ pub enum Flavor {
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Availability {
since: Option<String>,
stability: Option<Stability>,
visibility: Option<Visibility>,
pub since: Option<String>,
pub stability: Option<Stability>,
pub visibility: Option<Visibility>,
}

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

#[serde(skip_serializing_if = "Option::is_none")]
pub since: Option<String>,

#[serde(skip_serializing_if = "Option::is_none")]
pub server_default: Option<ServerDefault>,

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

#[serde(skip_serializing_if = "Option::is_none")]
pub stability: Option<Stability>,

/// If specified takes precedence over `name` when generating code. `name` is always the value
/// to be sent over the wire
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -357,10 +350,6 @@ impl Documented for Property {
fn description(&self) -> Option<&str> {
self.description.as_deref()
}

fn since(&self) -> Option<&str> {
self.since.as_deref()
}
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down Expand Up @@ -536,10 +525,6 @@ impl Documented for BaseType {
fn description(&self) -> Option<&str> {
self.description.as_deref()
}

fn since(&self) -> Option<&str> {
None
}
}

trait WithBaseType {
Expand All @@ -558,10 +543,6 @@ impl<T: WithBaseType> Documented for T {
fn description(&self) -> Option<&str> {
self.base().description()
}

fn since(&self) -> Option<&str> {
self.base().since()
}
}

/// An interface type
Expand Down Expand Up @@ -843,20 +824,6 @@ pub struct Endpoint {

pub urls: Vec<UrlTemplate>,

/// The version when this endpoint reached its current stability level.
/// Missing data means "forever", i.e. before any of the target client versions produced from this spec.
#[serde(skip_serializing_if = "Option::is_none")]
pub since: Option<String>,

#[serde(skip_serializing_if = "Option::is_none")]
pub stability: Option<Stability>,

#[serde(skip_serializing_if = "Option::is_none")]
pub visibility: Option<Visibility>,

#[serde(skip_serializing_if = "Option::is_none")]
pub feature_flag: Option<String>,

#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub request_media_type: Vec<String>,

Expand All @@ -879,10 +846,6 @@ impl Documented for Endpoint {
fn description(&self) -> Option<&str> {
Some(self.description.as_str())
}

fn since(&self) -> Option<&str> {
self.since.as_deref()
}
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down
17 changes: 17 additions & 0 deletions compiler-rs/clients_schema_to_openapi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ mod utils;
use std::collections::HashSet;
use std::io::{BufWriter, Write};
use std::path::Path;
use indexmap::IndexMap;

use clients_schema::{Availabilities, Endpoint, IndexedModel};
use openapiv3::{Components, OpenAPI};
Expand Down Expand Up @@ -147,3 +148,19 @@ fn info(model: &IndexedModel) -> openapiv3::Info {
extensions: Default::default(),
}
}

pub fn availability_as_extension(availabilities: &Option<Availabilities>) -> IndexMap<String, serde_json::Value> {
let mut result = IndexMap::new();

if let Some(avails) = availabilities {
// We may have several availabilities, but since generally exists only on stateful (stack)
for (_, availability) in avails {
if let Some(since) = &availability.since {
result.insert("x-available-since".to_string(), serde_json::Value::String(since.clone()));
break;
}
}
}

result
}
3 changes: 2 additions & 1 deletion compiler-rs/clients_schema_to_openapi/src/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,10 @@ pub fn add_endpoint(
deprecated: endpoint.deprecation.is_some(),
security: None,
servers: vec![],
extensions: Default::default(), // FIXME: translate availability?
extensions: crate::availability_as_extension(&endpoint.availability),
};


let mut operation_path = url_template.path.clone();

// Disabled -- OpenAPI path templates do not contain the query string
Expand Down
3 changes: 1 addition & 2 deletions compiler-rs/clients_schema_to_openapi/src/schemas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,12 +472,11 @@ impl<'a> TypesAndComponents<'a> {
data.external_docs = self.convert_external_docs(prop);
data.deprecated = prop.deprecation.is_some();
data.description = prop.description.clone();
data.extensions = crate::availability_as_extension(&prop.availability);
// TODO: prop.aliases as extensions
// TODO: prop.server_default as extension
// TODO: prop.availability as extension
// TODO: prop.doc_id as extension (new representation of since and stability)
// TODO: prop.es_quirk as extension?
// TODO: prop.codegen_name as extension?
// TODO: prop.deprecation as extension
}
}
7 changes: 0 additions & 7 deletions compiler-rs/clients_schema_to_openapi/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,6 @@ pub trait IntoSchema {
schema
}

fn into_schema_with_data_fn(self, f: fn(&mut SchemaData) -> ()) -> Schema
where Self: Sized {
let mut schema = self.into_schema();
f(&mut schema.schema_data);
schema
}

fn into_schema(self) -> Schema;
}

Expand Down
Binary file modified compiler-rs/compiler-wasm-lib/pkg/compiler_wasm_lib_bg.wasm
Binary file not shown.
Loading

0 comments on commit da6edd4

Please sign in to comment.