@ioka-technologies/asyncapi-rust-client-template 0.0.27 → 0.0.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2414,6 +2414,119 @@ ${doc}#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
2414
2414
  pub enum ${schema.rustName} {
2415
2415
  ${variants},
2416
2416
  }
2417
+ `;
2418
+ } else if (schema.schema.type && !schema.schema.properties) {
2419
+ // Handle primitive types and arrays without properties
2420
+ // Don't use jsonSchemaToRustType here as it might return the type name itself
2421
+ let primitiveType = 'serde_json::Value';
2422
+ switch (schema.schema.type) {
2423
+ case 'string':
2424
+ if (schema.schema.format === 'date-time') primitiveType = 'chrono::DateTime<chrono::Utc>';else if (schema.schema.format === 'uuid') primitiveType = 'uuid::Uuid';else primitiveType = 'String';
2425
+ break;
2426
+ case 'integer':
2427
+ switch (schema.schema.format) {
2428
+ case 'int32':
2429
+ primitiveType = 'i32';
2430
+ break;
2431
+ case 'int64':
2432
+ primitiveType = 'i64';
2433
+ break;
2434
+ case 'uint32':
2435
+ primitiveType = 'u32';
2436
+ break;
2437
+ case 'uint64':
2438
+ primitiveType = 'u64';
2439
+ break;
2440
+ default:
2441
+ primitiveType = 'i32';
2442
+ break;
2443
+ }
2444
+ break;
2445
+ case 'number':
2446
+ primitiveType = 'f64';
2447
+ break;
2448
+ case 'boolean':
2449
+ primitiveType = 'bool';
2450
+ break;
2451
+ case 'array':
2452
+ if (schema.schema.items) {
2453
+ // Handle array items
2454
+ let itemType = 'serde_json::Value';
2455
+ if (schema.schema.items.type === 'integer') {
2456
+ switch (schema.schema.items.format) {
2457
+ case 'int32':
2458
+ itemType = 'i32';
2459
+ break;
2460
+ case 'int64':
2461
+ itemType = 'i64';
2462
+ break;
2463
+ case 'uint32':
2464
+ itemType = 'u32';
2465
+ break;
2466
+ case 'uint64':
2467
+ itemType = 'u64';
2468
+ break;
2469
+ case 'uint8':
2470
+ itemType = 'u8';
2471
+ break;
2472
+ case 'int8':
2473
+ itemType = 'i8';
2474
+ break;
2475
+ case 'uint16':
2476
+ itemType = 'u16';
2477
+ break;
2478
+ case 'int16':
2479
+ itemType = 'i16';
2480
+ break;
2481
+ default:
2482
+ itemType = 'i32';
2483
+ break;
2484
+ }
2485
+ } else if (schema.schema.items.type === 'string') {
2486
+ if (schema.schema.items.format === 'date-time') itemType = 'chrono::DateTime<chrono::Utc>';else if (schema.schema.items.format === 'uuid') itemType = 'uuid::Uuid';else itemType = 'String';
2487
+ } else if (schema.schema.items.type === 'number') {
2488
+ itemType = 'f64';
2489
+ } else if (schema.schema.items.type === 'boolean') {
2490
+ itemType = 'bool';
2491
+ }
2492
+ primitiveType = `Vec<${itemType}>`;
2493
+ } else {
2494
+ primitiveType = 'Vec<serde_json::Value>';
2495
+ }
2496
+ break;
2497
+ }
2498
+
2499
+ // Generate a newtype wrapper for primitive types and arrays
2500
+ result += `
2501
+ ${doc}#[derive(Debug, Clone, Serialize, Deserialize)]
2502
+ pub struct ${schema.rustName}(pub ${primitiveType});
2503
+
2504
+ impl From<${primitiveType}> for ${schema.rustName} {
2505
+ fn from(value: ${primitiveType}) -> Self {
2506
+ Self(value)
2507
+ }
2508
+ }
2509
+
2510
+ impl From<${schema.rustName}> for ${primitiveType} {
2511
+ fn from(value: ${schema.rustName}) -> Self {
2512
+ value.0
2513
+ }
2514
+ }
2515
+
2516
+ impl std::fmt::Display for ${schema.rustName} {
2517
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
2518
+ ${(() => {
2519
+ // Generate appropriate Display implementation based on the primitive type
2520
+ if (primitiveType.startsWith('Vec<u8>')) {
2521
+ return `self.0.iter().try_for_each(|byte| write!(f, "{:02x}", byte))`;
2522
+ } else if (primitiveType.startsWith('Vec<')) {
2523
+ return 'write!(f, "{:?}", self.0)';
2524
+ } else {
2525
+ return 'write!(f, "{}", self.0)';
2526
+ }
2527
+ })()}
2528
+ }
2529
+ }
2417
2530
  `;
2418
2531
  } else {
2419
2532
  // Generate struct definition
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ioka-technologies/asyncapi-rust-client-template",
3
- "version": "0.0.27",
3
+ "version": "0.0.28",
4
4
  "description": "AsyncAPI template for generating Rust NATS clients",
5
5
  "main": "template/index.js",
6
6
  "keywords": [