Skip to content
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

Add stability extensions for openapi #2716

Merged
merged 5 commits into from
Jul 16, 2024
Merged
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
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
Loading