Skip to content

Commit 702d569

Browse files
committed
Revert outputting examples as objects
1 parent fb97a46 commit 702d569

File tree

9 files changed

+1009
-16092
lines changed

9 files changed

+1009
-16092
lines changed

compiler-rs/Cargo.lock

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compiler-rs/clients_schema_to_openapi/src/paths.rs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ pub fn add_endpoint(
3939
out: &mut Paths,
4040
) -> anyhow::Result<()> {
4141
if endpoint.request.is_none() {
42-
tracing::warn!("Endpoint {} is missing a request -- ignored", &endpoint.name);
42+
// tracing::warn!("Endpoint {} is missing a request -- ignored", &endpoint.name);
4343
return Ok(());
4444
}
4545

4646
if endpoint.response.is_none() {
47-
tracing::warn!("Endpoint {} is missing a response -- ignored", &endpoint.name);
47+
// tracing::warn!("Endpoint {} is missing a response -- ignored", &endpoint.name);
4848
return Ok(());
4949
}
5050

@@ -126,14 +126,22 @@ pub fn add_endpoint(
126126
for (name, schema_example) in schema_examples {
127127
let example = match &schema_example.value {
128128
None => None,
129-
Some(text) => {
130-
match serde_json::from_str::<serde_json::Value>(&text) {
131-
Ok(json) => Some(json),
132-
// Cannot parse json: assume it's text (e.g. cat requests)
133-
// FIXME: should be validated by looking at the media-type
134-
Err(_) => Some(serde_json::Value::String(text.clone()))
135-
}
136-
}
129+
// Examples should be objects - https://spec.openapis.org/oas/v3.1.1.html#example-object
130+
// Disabled for now, as some examples use multi-line json as in the Kibana console.
131+
Some(text) => Some(serde_json::Value::String(text.clone())),
132+
// Some(text) => {
133+
// match serde_json::from_str::<serde_json::Value>(&text) {
134+
// Ok(json) => {
135+
// Some(json)
136+
// }
137+
// // Cannot parse json: assume it's text (e.g. cat requests)
138+
// // but should be validated by looking at the media-type
139+
// Err(err) => {
140+
// tracing::warn!("Cannot parse example: {}\n{}", err, text);
141+
// Some(serde_json::Value::String(text.clone()))
142+
// }
143+
// }
144+
// }
137145
};
138146

139147
let openapi_example = Example {

compiler-rs/compiler-wasm-lib/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ serde_json = { workspace = true }
1919
anyhow = { workspace = true }
2020

2121
console_error_panic_hook = { workspace = true, optional = true }
22+
tracing-wasm = "0.2.1"
2223

2324
[dev-dependencies]
2425
wasm-bindgen-test = { workspace = true }

compiler-rs/compiler-wasm-lib/pkg/compiler_wasm_lib.js

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,68 @@ module.exports.convert_schema_to_openapi = function(json, flavor) {
149149
}
150150
};
151151

152+
function handleError(f, args) {
153+
try {
154+
return f.apply(this, args);
155+
} catch (e) {
156+
wasm.__wbindgen_exn_store(addHeapObject(e));
157+
}
158+
}
159+
152160
module.exports.__wbindgen_string_new = function(arg0, arg1) {
153161
const ret = getStringFromWasm0(arg0, arg1);
154162
return addHeapObject(ret);
155163
};
156164

165+
module.exports.__wbg_log_c9486ca5d8e2cbe8 = function(arg0, arg1) {
166+
let deferred0_0;
167+
let deferred0_1;
168+
try {
169+
deferred0_0 = arg0;
170+
deferred0_1 = arg1;
171+
console.log(getStringFromWasm0(arg0, arg1));
172+
} finally {
173+
wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
174+
}
175+
};
176+
177+
module.exports.__wbg_log_aba5996d9bde071f = function(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7) {
178+
let deferred0_0;
179+
let deferred0_1;
180+
try {
181+
deferred0_0 = arg0;
182+
deferred0_1 = arg1;
183+
console.log(getStringFromWasm0(arg0, arg1), getStringFromWasm0(arg2, arg3), getStringFromWasm0(arg4, arg5), getStringFromWasm0(arg6, arg7));
184+
} finally {
185+
wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
186+
}
187+
};
188+
189+
module.exports.__wbg_mark_40e050a77cc39fea = function(arg0, arg1) {
190+
performance.mark(getStringFromWasm0(arg0, arg1));
191+
};
192+
193+
module.exports.__wbindgen_object_drop_ref = function(arg0) {
194+
takeObject(arg0);
195+
};
196+
197+
module.exports.__wbg_measure_aa7a73f17813f708 = function() { return handleError(function (arg0, arg1, arg2, arg3) {
198+
let deferred0_0;
199+
let deferred0_1;
200+
let deferred1_0;
201+
let deferred1_1;
202+
try {
203+
deferred0_0 = arg0;
204+
deferred0_1 = arg1;
205+
deferred1_0 = arg2;
206+
deferred1_1 = arg3;
207+
performance.measure(getStringFromWasm0(arg0, arg1), getStringFromWasm0(arg2, arg3));
208+
} finally {
209+
wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
210+
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
211+
}
212+
}, arguments) };
213+
157214
module.exports.__wbg_new_abda76e883ba8a5f = function() {
158215
const ret = new Error();
159216
return addHeapObject(ret);
@@ -179,10 +236,6 @@ module.exports.__wbg_error_f851667af71bcfc6 = function(arg0, arg1) {
179236
}
180237
};
181238

182-
module.exports.__wbindgen_object_drop_ref = function(arg0) {
183-
takeObject(arg0);
184-
};
185-
186239
const path = require('path').join(__dirname, 'compiler_wasm_lib_bg.wasm');
187240
const bytes = require('fs').readFileSync(path);
188241

16.8 KB
Binary file not shown.

compiler-rs/compiler-wasm-lib/pkg/compiler_wasm_lib_bg.wasm.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ export function __wbindgen_add_to_stack_pointer(a: number): number;
66
export function __wbindgen_malloc(a: number, b: number): number;
77
export function __wbindgen_realloc(a: number, b: number, c: number, d: number): number;
88
export function __wbindgen_free(a: number, b: number, c: number): void;
9+
export function __wbindgen_exn_store(a: number): void;

compiler-rs/compiler-wasm-lib/src/lib.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use clients_schema::transform::ExpandConfig;
2222

2323
#[wasm_bindgen]
2424
pub fn convert_schema_to_openapi(json: &str, flavor: &str) -> Result<String, String> {
25-
set_panic_hook();
25+
setup_hooks();
2626
convert0(json, flavor).map_err(|err| err.to_string())
2727
}
2828

@@ -50,7 +50,7 @@ fn convert0(json: &str, flavor: &str) -> anyhow::Result<String> {
5050
Ok(result)
5151
}
5252

53-
pub fn set_panic_hook() {
53+
pub fn setup_hooks() {
5454
// When the `console_error_panic_hook` feature is enabled, we can call the
5555
// `set_panic_hook` function at least once during initialization, and then
5656
// we will get better error messages if our code ever panics.
@@ -59,4 +59,10 @@ pub fn set_panic_hook() {
5959
// https://github.com/rustwasm/console_error_panic_hook#readme
6060
#[cfg(feature = "console_error_panic_hook")]
6161
console_error_panic_hook::set_once();
62+
63+
use std::sync::Once;
64+
static SET_TRACING: Once = Once::new();
65+
SET_TRACING.call_once(|| {
66+
tracing_wasm::set_as_global_default();
67+
});
6268
}

0 commit comments

Comments
 (0)