From 5a197fd65d7ca1b37b7cb23333c933b56de9d803 Mon Sep 17 00:00:00 2001 From: mashizora <30516315+mashizora@users.noreply.github.com> Date: Tue, 27 Aug 2024 11:31:05 +0800 Subject: [PATCH] feat(target_typescript): add support for additionalProperties --- crates/target_typescript/output/geojson/index.ts | 7 +++++++ crates/target_typescript/src/lib.rs | 9 ++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/crates/target_typescript/output/geojson/index.ts b/crates/target_typescript/output/geojson/index.ts index e43cd0de..0557c8ef 100644 --- a/crates/target_typescript/output/geojson/index.ts +++ b/crates/target_typescript/output/geojson/index.ts @@ -172,6 +172,7 @@ export interface GeojsonObjectGeometryCollection { type: "GeometryCollection"; geometries: GeojsonObject[]; bbox?: BoundingBox; + [x: string]: unknown; } /** @@ -182,6 +183,7 @@ export interface GeojsonObjectLineString { type: "LineString"; coordinates: Position[]; bbox?: BoundingBox; + [x: string]: unknown; } /** @@ -192,6 +194,7 @@ export interface GeojsonObjectMultiLineString { type: "MultiLineString"; coordinates: Position[]; bbox?: BoundingBox; + [x: string]: unknown; } /** @@ -202,6 +205,7 @@ export interface GeojsonObjectMultiPoint { type: "MultiPoint"; coordinates: Position[]; bbox?: BoundingBox; + [x: string]: unknown; } /** @@ -212,6 +216,7 @@ export interface GeojsonObjectMultiPolygon { type: "MultiPolygon"; coordinates: LinearRing[]; bbox?: BoundingBox; + [x: string]: unknown; } /** @@ -221,6 +226,7 @@ export interface GeojsonObjectPoint { type: "Point"; coordinates: Position; bbox?: BoundingBox; + [x: string]: unknown; } /** @@ -231,6 +237,7 @@ export interface GeojsonObjectPolygon { type: "Polygon"; coordinates: LinearRing[]; bbox?: BoundingBox; + [x: string]: unknown; } /** diff --git a/crates/target_typescript/src/lib.rs b/crates/target_typescript/src/lib.rs index a6465579..451284dd 100644 --- a/crates/target_typescript/src/lib.rs +++ b/crates/target_typescript/src/lib.rs @@ -161,7 +161,7 @@ impl jtd_codegen::target::Target for Target { target::Item::Struct { metadata, name, - has_additional: _, + has_additional, fields, } => { if let Some(s) = metadata.get("typescriptType").and_then(|v| v.as_str()) { @@ -195,6 +195,9 @@ impl jtd_codegen::target::Target for Target { )?; } } + if has_additional { + writeln!(out, " [x: string]: unknown;")?; + } writeln!(out, "}}")?; None @@ -231,6 +234,7 @@ impl jtd_codegen::target::Target for Target { name, tag_json_name, tag_value, + has_additional, fields, .. } => { @@ -266,6 +270,9 @@ impl jtd_codegen::target::Target for Target { )?; } } + if has_additional { + writeln!(out, " [x: string]: unknown;")?; + } writeln!(out, "}}")?; None