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

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.
@@ -1395,7 +1395,7 @@ function generateTypeScriptConfig(options = {}) {
1395
1395
  declaration: true,
1396
1396
  declarationMap: true,
1397
1397
  sourceMap: true,
1398
- moduleResolution: 'node',
1398
+ moduleResolution: 'bundler',
1399
1399
  allowSyntheticDefaultImports: true,
1400
1400
  experimentalDecorators: true,
1401
1401
  emitDecoratorMetadata: true,
@@ -3302,7 +3302,7 @@ function generateTypeScriptModels(asyncapi, options = {}) {
3302
3302
  }
3303
3303
 
3304
3304
  // Helper function to convert JSON schema to TypeScript type
3305
- function jsonSchemaToTypeScriptType(schema, fieldName = '') {
3305
+ function jsonSchemaToTypeScriptType(schema, fieldName = '', isComponentSchemaDefinition = false) {
3306
3306
  if (!schema) return 'any';
3307
3307
 
3308
3308
  // Handle $ref - resolve from schema registry
@@ -3314,7 +3314,8 @@ function generateTypeScriptModels(asyncapi, options = {}) {
3314
3314
  }
3315
3315
 
3316
3316
  // Handle resolved $ref - check for x-parser-schema-id which indicates original schema name
3317
- if (schema['x-parser-schema-id'] && typeof schema['x-parser-schema-id'] === 'string') {
3317
+ // But skip this if we're defining the component schema itself (to avoid circular references)
3318
+ if (!isComponentSchemaDefinition && schema['x-parser-schema-id'] && typeof schema['x-parser-schema-id'] === 'string') {
3318
3319
  const schemaId = schema['x-parser-schema-id'];
3319
3320
  // Check if this matches a known component schema
3320
3321
  if (schemaRegistry.has(schemaId)) {
@@ -3403,6 +3404,11 @@ function generateTypeScriptModels(asyncapi, options = {}) {
3403
3404
  // Generate union type for enum
3404
3405
  const enumValues = schema.schema.enum.map(val => `'${val}'`).join(' | ');
3405
3406
  content += `${doc}export type ${schema.typeName} = ${enumValues};\n\n`;
3407
+ } else if (schema.schema.type && !schema.schema.properties) {
3408
+ // For primitive types (integer, number, string, boolean, array) without properties,
3409
+ // generate a type alias instead of an interface
3410
+ const tsType = jsonSchemaToTypeScriptType(schema.schema, schema.name, true);
3411
+ content += `${doc}export type ${schema.typeName} = ${tsType};\n\n`;
3406
3412
  } else {
3407
3413
  // Generate interface for object schema
3408
3414
  content += `${doc}export interface ${schema.typeName} {\n`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ioka-technologies/asyncapi-rust-client-template",
3
- "version": "0.0.28",
3
+ "version": "0.0.30",
4
4
  "description": "AsyncAPI template for generating Rust NATS clients",
5
5
  "main": "template/index.js",
6
6
  "keywords": [