Skip to content

Commit

Permalink
Add stability extensions for openapi (#2716)
Browse files Browse the repository at this point in the history
* add stability to extensions

* add new version of wasm lib

* refresh generated output

* explicitely do nothing for unhandled stabilities

* refresh wasm lib
  • Loading branch information
Anaethelion authored Jul 16, 2024
1 parent 5c3ba9f commit a409359
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 22 deletions.
16 changes: 13 additions & 3 deletions compiler-rs/clients_schema_to_openapi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use std::io::{BufWriter, Write};
use std::path::Path;
use indexmap::IndexMap;

use clients_schema::{Availabilities, Endpoint, IndexedModel};
use clients_schema::{Availabilities, Endpoint, IndexedModel, Stability};
use openapiv3::{Components, OpenAPI};
use tracing::warn;

Expand Down Expand Up @@ -149,15 +149,25 @@ fn info(model: &IndexedModel) -> openapiv3::Info {
}
}

pub fn availability_as_extension(availabilities: &Option<Availabilities>) -> IndexMap<String, serde_json::Value> {
pub fn availability_as_extensions(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;
}
if let Some(stability) = &availability.stability {
match stability {
Stability::Beta => {
result.insert("x-beta".to_string(), serde_json::Value::Bool(true));
}
Stability::Experimental => {
result.insert("x-technical-preview".to_string(), serde_json::Value::Bool(true));
}
_ => {}
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler-rs/clients_schema_to_openapi/src/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ pub fn add_endpoint(
deprecated: endpoint.deprecation.is_some(),
security: None,
servers: vec![],
extensions: crate::availability_as_extension(&endpoint.availability),
extensions: crate::availability_as_extensions(&endpoint.availability),
};


Expand Down
2 changes: 1 addition & 1 deletion compiler-rs/clients_schema_to_openapi/src/schemas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ 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);
data.extensions = crate::availability_as_extensions(&prop.availability);
// TODO: prop.aliases as extensions
// TODO: prop.server_default as extension
// TODO: prop.doc_id as extension (new representation of since and stability)
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 a409359

Please sign in to comment.