@alagoni97/cli 0.72.1 → 0.72.2

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.
@@ -9,6 +9,15 @@ const X_PARAMETER_STYLE = 'x-parameter-style';
9
9
  const X_PARAMETER_EXPLODE = 'x-parameter-explode';
10
10
  const X_PARAMETER_ALLOW_RESERVED = 'x-parameter-allowReserved';
11
11
  const X_PARAMETER_COLLECTION_FORMAT = 'x-parameter-collectionFormat';
12
+ /**
13
+ * Map the raw OpenAPI parameter name to the constrained TypeScript property
14
+ * name rendered by Modelina, falling back to the raw name when the model does
15
+ * not expose the property.
16
+ */
17
+ function getConstrainedPropertyName({ model, parameterName }) {
18
+ const constrainedProperty = Object.values(model.properties).find((property) => property.unconstrainedPropertyName === parameterName);
19
+ return constrainedProperty?.propertyName ?? parameterName;
20
+ }
12
21
  // OpenAPI parameter processor
13
22
  function processOpenAPIParameters(openapiDocument) {
14
23
  const channelParameters = {};
@@ -134,11 +143,21 @@ function generateOpenAPIParameterMethods(model) {
134
143
  for (const [propName, propSchema] of Object.entries(properties)) {
135
144
  const paramConfig = processParameterSchema(propName, propSchema);
136
145
  if (paramConfig) {
146
+ const parameterConfig = {
147
+ name: paramConfig.name,
148
+ propertyName: getConstrainedPropertyName({
149
+ model,
150
+ parameterName: propName
151
+ }),
152
+ style: paramConfig.style,
153
+ explode: paramConfig.explode,
154
+ allowReserved: paramConfig.allowReserved
155
+ };
137
156
  if (paramConfig.location === 'path') {
138
- pathParams.push(paramConfig);
157
+ pathParams.push(parameterConfig);
139
158
  }
140
159
  else if (paramConfig.location === 'query') {
141
- queryParams.push(paramConfig);
160
+ queryParams.push(parameterConfig);
142
161
  }
143
162
  }
144
163
  }
@@ -292,11 +311,11 @@ getChannelWithParameters(basePath: string): string {
292
311
  * Generate serialization code for a single path parameter
293
312
  */
294
313
  function generatePathParameterSerialization(param) {
295
- const { name, style, explode, allowReserved } = param;
314
+ const { name, propertyName, style, explode, allowReserved } = param;
296
315
  const encoding = allowReserved ? '' : 'encodeURIComponent';
297
316
  return ` // Serialize path parameter: ${name} (style: ${style}, explode: ${explode})
298
- if (this.${name} !== undefined && this.${name} !== null) {
299
- const value = this.${name};
317
+ if (this.${propertyName} !== undefined && this.${propertyName} !== null) {
318
+ const value = this.${propertyName};
300
319
  ${generatePathSerializationLogic(name, style, explode, encoding)}
301
320
  }`;
302
321
  }
@@ -304,11 +323,11 @@ function generatePathParameterSerialization(param) {
304
323
  * Generate serialization code for a single query parameter
305
324
  */
306
325
  function generateQueryParameterSerialization(param) {
307
- const { name, style, explode, allowReserved } = param;
326
+ const { name, propertyName, style, explode, allowReserved } = param;
308
327
  const encoding = allowReserved ? '' : 'encodeURIComponent';
309
328
  return ` // Serialize query parameter: ${name} (style: ${style}, explode: ${explode})
310
- if (this.${name} !== undefined && this.${name} !== null) {
311
- const value = this.${name};
329
+ if (this.${propertyName} !== undefined && this.${propertyName} !== null) {
330
+ const value = this.${propertyName};
312
331
  ${generateQuerySerializationLogic(name, style, explode, encoding)}
313
332
  }`;
314
333
  }
@@ -486,7 +505,11 @@ function generateDeserializationMethods(pathParams, queryParams, model) {
486
505
  methods += generateUrlDeserializationMethod(queryParams, model);
487
506
  }
488
507
  // Generate static fromUrl method
489
- methods += generateFromUrlStaticMethod(pathParams, model);
508
+ methods += generateFromUrlStaticMethod({
509
+ pathParams,
510
+ hasQueryParams: queryParams.length > 0,
511
+ model
512
+ });
490
513
  return methods;
491
514
  }
492
515
  /**
@@ -523,7 +546,7 @@ ${paramDeserializations}
523
546
  /**
524
547
  * Generate static fromUrl method
525
548
  */
526
- function generateFromUrlStaticMethod(pathParams, model) {
549
+ function generateFromUrlStaticMethod({ pathParams, hasQueryParams, model }) {
527
550
  const properties = model.originalInput?.properties ?? {};
528
551
  const requiredParams = [];
529
552
  // Find required parameters to determine constructor defaults
@@ -537,11 +560,11 @@ function generateFromUrlStaticMethod(pathParams, model) {
537
560
  const pathParamExtraction = pathParams.length > 0 ? generatePathParameterExtraction(pathParams) : '';
538
561
  // Generate constructor arguments with path parameters first, then required non-path parameters
539
562
  const pathParamArgs = pathParams
540
- .map((param) => `${param.name}: pathParams.${param.name}`)
563
+ .map((param) => `${param.propertyName}: pathParams.${param.propertyName}`)
541
564
  .join(', ');
542
565
  const requiredNonPathParams = requiredParams.filter((param) => !pathParams.some((pathParam) => pathParam.name === param));
543
566
  const requiredParamArgs = requiredNonPathParams
544
- .map((param) => `${param}: default${(0, utils_1.pascalCase)(param)}`)
567
+ .map((param) => `${getConstrainedPropertyName({ model, parameterName: param })}: default${(0, utils_1.pascalCase)(param)}`)
545
568
  .join(', ');
546
569
  let constructorArgs = '';
547
570
  if (pathParamArgs && requiredParamArgs) {
@@ -565,6 +588,11 @@ function generateFromUrlStaticMethod(pathParams, model) {
565
588
  .map((param) => `, default${(0, utils_1.pascalCase)(param)}: ${getParameterType(properties[param])} = ${generateDefaultValue(properties[param], param)}`)
566
589
  .join('')
567
590
  : '';
591
+ // deserializeUrl only exists on the class when there are query parameters
592
+ const deserializeUrlCall = hasQueryParams
593
+ ? `
594
+ instance.deserializeUrl(url);`
595
+ : '';
568
596
  return `
569
597
 
570
598
  /**
@@ -576,8 +604,7 @@ ${paramDocs}
576
604
  */
577
605
  static fromUrl(url: string, basePath: string${functionParams}): ${model.type} {
578
606
  ${pathParamExtraction}
579
- const instance = new ${model.type}({ ${constructorArgs} });
580
- instance.deserializeUrl(url);
607
+ const instance = new ${model.type}({ ${constructorArgs} });${deserializeUrlCall}
581
608
  return instance;
582
609
  }`;
583
610
  }
@@ -598,7 +625,7 @@ function generateQueryParameterDeserialization(param, model) {
598
625
  const { name, style, explode } = param;
599
626
  const properties = model.originalInput?.properties ?? {};
600
627
  const propSchema = properties[name];
601
- const logicCode = generateQueryDeserializationLogic(name, style, explode, propSchema);
628
+ const logicCode = generateQueryDeserializationLogic({ param, propSchema });
602
629
  return ` // Deserialize query parameter: ${name} (style: ${style}, explode: ${explode})
603
630
  if (params.has('${name}')) {
604
631
  const value = params.get('${name}');
@@ -608,36 +635,60 @@ function generateQueryParameterDeserialization(param, model) {
608
635
  /**
609
636
  * Generate query parameter deserialization logic
610
637
  */
611
- function generateQueryDeserializationLogic(name, style, explode, propSchema) {
638
+ function generateQueryDeserializationLogic({ param, propSchema }) {
612
639
  const isArray = propSchema?.type === 'array' || propSchema?.items;
613
640
  const isBoolean = propSchema?.type === 'boolean';
614
641
  const isNumber = propSchema?.type === 'integer' || propSchema?.type === 'number';
615
642
  const paramType = getParameterType(propSchema);
616
- switch (style) {
643
+ switch (param.style) {
617
644
  case 'form':
618
- return generateFormStyleDeserializationLogic(name, explode, isArray, isBoolean, isNumber, paramType);
645
+ return generateFormStyleDeserializationLogic({
646
+ param,
647
+ isArray,
648
+ isBoolean,
649
+ isNumber,
650
+ paramType
651
+ });
619
652
  case 'spaceDelimited':
620
- return generateSpaceDelimitedDeserializationLogic(name, explode, isArray, isBoolean, isNumber, paramType);
653
+ return generateSpaceDelimitedDeserializationLogic({
654
+ param,
655
+ isArray,
656
+ isBoolean,
657
+ isNumber,
658
+ paramType
659
+ });
621
660
  case 'pipeDelimited':
622
- return generatePipeDelimitedDeserializationLogic(name, explode, isArray, isBoolean, isNumber, paramType);
661
+ return generatePipeDelimitedDeserializationLogic({
662
+ param,
663
+ isArray,
664
+ isBoolean,
665
+ isNumber,
666
+ paramType
667
+ });
623
668
  case 'deepObject':
624
- return generateDeepObjectDeserializationLogic(name, isBoolean, isNumber, paramType);
669
+ return generateDeepObjectDeserializationLogic({
670
+ param,
671
+ isBoolean,
672
+ isNumber,
673
+ paramType
674
+ });
625
675
  default:
626
- throw new Error(`Unsupported style: ${style}`);
676
+ throw new Error(`Unsupported style: ${param.style}`);
627
677
  }
628
678
  }
629
679
  /**
630
680
  * Generate deserialization logic for form style
631
681
  */
632
- function generateFormStyleDeserializationLogic(name, explode, isArray, isBoolean, isNumber, paramType) {
682
+ function generateFormStyleDeserializationLogic({ param, isArray, isBoolean, isNumber, paramType }) {
683
+ const { name, propertyName, explode } = param;
633
684
  if (isArray && !explode) {
634
685
  const typecast = paramType.includes('[]') ? ` as ${paramType}` : '';
635
686
  return `if (value === '') {
636
- this.${name} = [];
687
+ this.${propertyName} = [];
637
688
  } else if (value) {
638
689
  // Split by comma and decode
639
690
  const decodedValues = value.split(',').map(val => decodeURIComponent(val.trim()));
640
- this.${name} = decodedValues${typecast};
691
+ this.${propertyName} = decodedValues${typecast};
641
692
  }`;
642
693
  }
643
694
  else if (isArray && explode) {
@@ -645,13 +696,13 @@ function generateFormStyleDeserializationLogic(name, explode, isArray, isBoolean
645
696
  return `const allValues = params.getAll('${name}');
646
697
  if (allValues.length > 0) {
647
698
  const decodedValues = allValues.map(val => decodeURIComponent(val));
648
- this.${name} = decodedValues${typecast};
699
+ this.${propertyName} = decodedValues${typecast};
649
700
  }`;
650
701
  }
651
702
  else if (isBoolean) {
652
703
  return `if (value) {
653
704
  const decodedValue = decodeURIComponent(value);
654
- this.${name} = decodedValue.toLowerCase() === 'true';
705
+ this.${propertyName} = decodedValue.toLowerCase() === 'true';
655
706
  }`;
656
707
  }
657
708
  else if (isNumber) {
@@ -659,7 +710,7 @@ function generateFormStyleDeserializationLogic(name, explode, isArray, isBoolean
659
710
  const decodedValue = decodeURIComponent(value);
660
711
  const numValue = Number(decodedValue);
661
712
  if (!isNaN(numValue)) {
662
- this.${name} = numValue;
713
+ this.${propertyName} = numValue;
663
714
  }
664
715
  }`;
665
716
  }
@@ -668,45 +719,58 @@ function generateFormStyleDeserializationLogic(name, explode, isArray, isBoolean
668
719
  : '';
669
720
  return `if (value) {
670
721
  const decodedValue = decodeURIComponent(value);
671
- this.${name} = decodedValue${typecast};
722
+ this.${propertyName} = decodedValue${typecast};
672
723
  }`;
673
724
  }
674
725
  /**
675
726
  * Generate deserialization logic for space delimited style
676
727
  */
677
- function generateSpaceDelimitedDeserializationLogic(name, explode, isArray, isBoolean, isNumber, paramType) {
678
- if (isArray && !explode) {
728
+ function generateSpaceDelimitedDeserializationLogic({ param, isArray, isBoolean, isNumber, paramType }) {
729
+ if (isArray && !param.explode) {
679
730
  const typecast = paramType.includes('[]') ? ` as ${paramType}` : '';
680
731
  return `if (value === '') {
681
- this.${name} = [];
732
+ this.${param.propertyName} = [];
682
733
  } else if (value) {
683
734
  // Split by space and decode
684
735
  const decodedValues = value.split(' ').map(val => decodeURIComponent(val.trim()));
685
- this.${name} = decodedValues${typecast};
736
+ this.${param.propertyName} = decodedValues${typecast};
686
737
  }`;
687
738
  }
688
- return generateFormStyleDeserializationLogic(name, explode, isArray, isBoolean, isNumber, paramType);
739
+ return generateFormStyleDeserializationLogic({
740
+ param,
741
+ isArray,
742
+ isBoolean,
743
+ isNumber,
744
+ paramType
745
+ });
689
746
  }
690
747
  /**
691
748
  * Generate deserialization logic for pipe delimited style
692
749
  */
693
- function generatePipeDelimitedDeserializationLogic(name, explode, isArray, isBoolean, isNumber, paramType) {
694
- if (isArray && !explode) {
750
+ function generatePipeDelimitedDeserializationLogic({ param, isArray, isBoolean, isNumber, paramType }) {
751
+ if (isArray && !param.explode) {
695
752
  const typecast = paramType.includes('[]') ? ` as ${paramType}` : '';
696
753
  return `if (value === '') {
697
- this.${name} = [];
754
+ this.${param.propertyName} = [];
698
755
  } else if (value) {
699
756
  // Split by pipe and decode
700
757
  const decodedValues = value.split('|').map(val => decodeURIComponent(val.trim()));
701
- this.${name} = decodedValues${typecast};
758
+ this.${param.propertyName} = decodedValues${typecast};
702
759
  }`;
703
760
  }
704
- return generateFormStyleDeserializationLogic(name, explode, isArray, isBoolean, isNumber, paramType);
761
+ return generateFormStyleDeserializationLogic({
762
+ param,
763
+ isArray,
764
+ isBoolean,
765
+ isNumber,
766
+ paramType
767
+ });
705
768
  }
706
769
  /**
707
770
  * Generate deserialization logic for deep object style
708
771
  */
709
- function generateDeepObjectDeserializationLogic(name, isBoolean, isNumber, paramType) {
772
+ function generateDeepObjectDeserializationLogic({ param, paramType }) {
773
+ const { name, propertyName } = param;
710
774
  const nameLength = name.length + 1;
711
775
  const typecast = paramType !== 'any' && paramType !== 'any | undefined'
712
776
  ? ` as ${paramType.replace(' | undefined', '')}`
@@ -720,7 +784,7 @@ function generateDeepObjectDeserializationLogic(name, isBoolean, isNumber, param
720
784
  }
721
785
  }
722
786
  if (Object.keys(deepObjectParams).length > 0) {
723
- this.${name} = deepObjectParams${typecast};
787
+ this.${propertyName} = deepObjectParams${typecast};
724
788
  }`;
725
789
  }
726
790
  /**
@@ -787,7 +851,7 @@ function generateExtractPathParametersMethod(pathParams, model) {
787
851
  const paramType = getParameterType(propSchema);
788
852
  const typecast = paramType !== 'string' ? ` as ${paramType}` : '';
789
853
  return ` case '${param.name}':
790
- result.${param.name} = ${conversion}${typecast};
854
+ result.${param.propertyName} = ${conversion}${typecast};
791
855
  break;`;
792
856
  })
793
857
  .join('\n');
@@ -799,7 +863,7 @@ function generateExtractPathParametersMethod(pathParams, model) {
799
863
  * @param basePath The base path template (e.g., '/pet/findByStatus/{status}/{categoryId}')
800
864
  * @returns Object containing extracted path parameter values
801
865
  */
802
- private static extractPathParameters(url: string, basePath: string): { ${pathParams.map((p) => `${p.name}: ${getParameterType(properties[p.name])}`).join(', ')} } {
866
+ private static extractPathParameters(url: string, basePath: string): { ${pathParams.map((p) => `${p.propertyName}: ${getParameterType(properties[p.name])}`).join(', ')} } {
803
867
  // Remove query string from URL for path matching
804
868
  const urlPath = url.split('?')[0];
805
869
 
@@ -506,5 +506,5 @@
506
506
  ]
507
507
  }
508
508
  },
509
- "version": "0.72.1"
509
+ "version": "0.72.2"
510
510
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@alagoni97/cli",
3
3
  "description": "CLI to work with code generation in any environment",
4
- "version": "0.72.1",
4
+ "version": "0.72.2",
5
5
  "bin": {
6
6
  "codegen": "./bin/run.mjs"
7
7
  },