Skip to content

Commit dc9b048

Browse files
committed
Handle number|string special cases
1 parent a7cf126 commit dc9b048

File tree

1 file changed

+11
-1
lines changed
  • compiler-rs/clients_schema_to_rest_api_spec/src

1 file changed

+11
-1
lines changed

compiler-rs/clients_schema_to_rest_api_spec/src/lib.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ fn convert_parameter(property: &Property, types: &IndexMap<TypeName, TypeDefinit
172172
let typ = get_type_name(&property.typ, types).to_string();
173173
let options = get_enum_options(&property.typ, types);
174174

175-
let default = property.server_default.as_ref().map(|default| match default {
175+
let mut default = property.server_default.as_ref().map(|default| match default {
176176
clients_schema::ServerDefault::String(s) => serde_json::Value::String(s.clone()),
177177
clients_schema::ServerDefault::Number(n) => serde_json::Value::from(*n as i64),
178178
clients_schema::ServerDefault::Boolean(b) => serde_json::Value::Bool(*b),
@@ -184,6 +184,14 @@ fn convert_parameter(property: &Property, types: &IndexMap<TypeName, TypeDefinit
184184
}
185185
});
186186

187+
if typ == "number|string" {
188+
// convert default to integer
189+
default = default.and_then(|def| match def {
190+
serde_json::Value::String(s) => s.parse::<i64>().ok().map(serde_json::Value::from),
191+
_ => Some(def),
192+
});
193+
}
194+
187195
let deprecated = property.deprecation.as_ref().map(|dep| Deprecation {
188196
version: dep.version.clone(),
189197
description: dep.description.clone(),
@@ -230,6 +238,8 @@ const BUILTIN_MAPPINGS: &[((&str, &str), &str)] = &[
230238
// hard cases
231239
(("_types", "WaitForActiveShards"), "string"),
232240
(("_global.search._types", "TrackHits"), "boolean|long"),
241+
(("_types", "Slices"), "number|string"),
242+
(("cluster.health", "WaitForNodes"), "string"),
233243
// sometimes list in rest-api-spec as comma-separate values are allowed
234244
// but the Elasticsearch specification always models it as a string.
235245
(("_global.search._types", "SourceConfigParam"), "list"),

0 commit comments

Comments
 (0)