Skip to content

Commit d59cffd

Browse files
fix: weird feTs behavior with our schema
Signed-off-by: Henry <mail@henrygressmann.de>
1 parent 0577e2c commit d59cffd

5 files changed

Lines changed: 35 additions & 5 deletions

File tree

‎.github/workflows/container.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
with:
2626
persist-credentials: false
2727
- name: Setup Docker Buildx
28-
uses: docker/setup-buildx-action@bb05f3f5519dd87d3ba754cc423b652a5edd6d2c # v4.2.0
28+
uses: docker/setup-buildx-action@37fe631027851001ddb9b187196cc803df7f5f0e # v4.3.0
2929
- name: Extract Semver
3030
id: semver
3131
env:

‎.github/workflows/release.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ jobs:
7171
with:
7272
name: web-dist
7373
path: ./web/dist
74-
- uses: actions-rust-lang/setup-rust-toolchain@46268bd060767258de96ed93c1251119784f2ab6 # v1.16.1
74+
- uses: actions-rust-lang/setup-rust-toolchain@166cdcfd11aee3cb47222f9ddb555ce30ddb9659 # v1.17.0
7575
with:
7676
cache: false
7777
- uses: taiki-e/upload-rust-binary-action@f0d45ae91ee7b8ee928de7a9d04d893a08bcbec6 # v1.30.2

‎.github/workflows/test.yaml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ jobs:
2626
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
2727
with:
2828
persist-credentials: false
29-
- uses: actions-rust-lang/setup-rust-toolchain@46268bd060767258de96ed93c1251119784f2ab6 # v1.16.1
29+
- uses: actions-rust-lang/setup-rust-toolchain@166cdcfd11aee3cb47222f9ddb555ce30ddb9659 # v1.17.0
3030
with:
3131
components: clippy, rustfmt
32-
- uses: Swatinem/rust-cache@c19371144df3bb44fab255c43d04cbc2ab54d1c4 # v2.9.1
32+
- uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2
3333
- run: mkdir ./web/dist
3434
- name: Run tests
3535
run: cargo test --all --all-features

‎src/web/mod.rs‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,32 @@ pub struct RouterState {
4141
pub events: Sender<Event>,
4242
}
4343

44+
// feTS treats directly resolved component references as circular and falls back to less precise types.
45+
#[derive(Clone)]
46+
struct WrapSchemaRefs;
47+
48+
impl schemars::transform::Transform for WrapSchemaRefs {
49+
fn transform(&mut self, schema: &mut schemars::Schema) {
50+
let already_wrapped = schema.as_object().is_some_and(|object| {
51+
object.len() == 1
52+
&& object.get("anyOf").and_then(serde_json::Value::as_array).is_some_and(|any_of| {
53+
any_of.len() == 1
54+
&& any_of[0]
55+
.as_object()
56+
.is_some_and(|reference| reference.len() == 1 && reference.contains_key("$ref"))
57+
})
58+
});
59+
if already_wrapped {
60+
return;
61+
}
62+
63+
schemars::transform::transform_subschemas(self, schema);
64+
if let Some(reference) = schema.remove("$ref") {
65+
schema.insert("anyOf".to_string(), serde_json::json!([{ "$ref": reference }]));
66+
}
67+
}
68+
}
69+
4470
impl Deref for RouterState {
4571
type Target = Arc<Liwan>;
4672

@@ -50,6 +76,10 @@ impl Deref for RouterState {
5076
}
5177

5278
pub fn router(app: Arc<Liwan>, events: Sender<Event>) -> Result<(axum::Router<()>, openapi::OpenApi)> {
79+
aide::generate::in_context(|ctx| {
80+
ctx.schema = ctx.schema.settings().clone().with_transform(WrapSchemaRefs).into_generator();
81+
});
82+
5383
let mut api = openapi::OpenApi {
5484
info: openapi::Info { title: "Liwan API".to_string(), ..Default::default() },
5585
..openapi::OpenApi::default()

‎web/src/api/dashboard.ts‎

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)