Skip to content

Commit

Permalink
fixed openapi translation, regenerate
Browse files Browse the repository at this point in the history
  • Loading branch information
l-trotta authored and flobernd committed Jun 13, 2024
1 parent 93ea8c6 commit 13edad5
Show file tree
Hide file tree
Showing 8 changed files with 431 additions and 544 deletions.
9 changes: 9 additions & 0 deletions compiler-rs/clients_schema/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ pub enum ServerDefault {
pub enum Variants {
ExternalTag(ExternalTag),
InternalTag(InternalTag),
Untagged(Untagged),
Container(Container),
}

Expand All @@ -404,6 +405,13 @@ pub struct InternalTag {
pub default_tag: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Untagged {
#[serde(default)]
pub non_exhaustive: bool,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Container {
Expand Down Expand Up @@ -799,6 +807,7 @@ impl TypeAlias {
pub enum TypeAliasVariants {
ExternalTag(ExternalTag),
InternalTag(InternalTag),
Untagged(Untagged),
}

//------------------------------------------------------------------------------------------------------------
Expand Down
6 changes: 5 additions & 1 deletion compiler-rs/clients_schema_to_openapi/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// under the License.

use std::path::{Path, PathBuf};
use anyhow::bail;

use clap::{Parser, ValueEnum};
use clients_schema::{Availabilities, Visibility};
Expand Down Expand Up @@ -71,7 +72,10 @@ impl Cli {
std::fs::read_to_string(self.schema)?
};

let mut model: clients_schema::IndexedModel = serde_json::from_str(&json)?;
let mut model: clients_schema::IndexedModel = match serde_json::from_str(&json) {
Ok(indexed_model) => indexed_model,
Err(e) => bail!("cannot parse schema json: {}", e)
};

if let Some(flavor) = self.flavor {
if flavor != SchemaFlavor::All {
Expand Down
2 changes: 2 additions & 0 deletions compiler-rs/clients_schema_to_openapi/src/schemas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,8 @@ impl<'a> TypesAndComponents<'a> {
extensions: Default::default(),
});
}
Some(TypeAliasVariants::Untagged(_tag)) => {
}
};

Ok(schema)
Expand Down
Binary file modified compiler-rs/compiler-wasm-lib/pkg/compiler_wasm_lib_bg.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion compiler-rs/openapi_to_clients_schema/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ fn generate_schema_kind_one_of(
let mut variants: Option<TypeAliasVariants> = None;

// TODO: do we want to allow untagged unions (those that are disambiguated by inspecting property names)?

if let Some(discriminator) = discriminator {
variants = Some(TypeAliasVariants::InternalTag(InternalTag {
default_tag: None,
Expand Down
104 changes: 78 additions & 26 deletions output/openapi/elasticsearch-serverless-openapi.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 13edad5

Please sign in to comment.