autorest.typescript icon indicating copy to clipboard operation
autorest.typescript copied to clipboard

Add Azure Alternate Type spector case and fix numeric type generation bug

Open Copilot opened this issue 4 months ago • 2 comments

Adds spector test case for Azure Client Generator Core alternate-type spec. During implementation, discovered and fixed bugs in the TypeSpec-TS emitter that caused issues when generating code for array types.

Bug Fixes

modelUtils.ts:

  1. Added numeric scalar type support: TypeSpec's numeric scalar type was not mapped, causing numeric[] to generate invalid array type instead of number[].
// Added case for numeric type
case "numeric":
  return applyIntrinsicDecorators(program, type, {
    type: "number"
  });
  1. Fixed null check for array schema items: Added null checks before accessing .includes() method when schema.items.type is undefined.
// Before
} else if (schema.items.type.includes("|")) {

// After  
} else if (schema.items.type && schema.items.type.includes("|")) {

Test Case Implementation

  • cadl-ranch-list.js: Added azure/client-generator-core/alternate-type to both azureRlcTsps and azureModularTsps
  • tspconfig.yaml: Created configuration files for RLC (with is-modular-library: false) and Modular test directories
  • Test specs: Implemented azureAlternateType.spec.ts for both RLC and Modular with 4 test cases:
    • getModel / putModel: Tests Feature model with geometry, properties, and optional id
    • getProperty / putProperty: Tests ModelWithFeatureProperty wrapper

All 4 RLC integration tests pass successfully.

  • Fixes Azure/autorest.typescript#3556
Original prompt

This section details on the original issue you should resolve

<issue_title>Add spector case for Azure Alternate Type</issue_title> <issue_description>typespec from https://github.com/Azure/typespec-azure/tree/main/packages/azure-http-specs/specs/azure/client-generator-core/alternate-type

  1. run rush update && rush build
  2. run rushx copy:typespec under folder packages/typespec.
  3. Add item into azureRlcTsps and azureModularTsps in file cadl-ranch-list.js. item:
  {
    outputPath: "azure/client-generator-core/alternate-type",
    inputPath: "azure/client-generator-core/alternate-type"
  }
  1. create tspconfig.yaml to azureIntegration/generated/azure/client-generator-core/alternate-type and azureModularIntegration/generated/azure/client-generator-core/alternate-type, the file configuration should refer to the cases in the same directory respectively.
  2. create azureAlternateType.spec.ts for azureIntegration and azureModularIntegration, then complete the case file according to the temp/specs/azure/client-generator-core/alternate-type/mockapi.ts
  3. Verify that all Integration case tests pass. If there are any issues, please fix them.</issue_description>

Comments on the Issue (you are @copilot in this section)

  • Fixes Azure/autorest.typescript#3556

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot avatar Oct 27 '25 07:10 Copilot

@copilot Based on the issue description, re-implement it.

v-jiaodi avatar Nov 25 '25 03:11 v-jiaodi

@copilot Based on the issue description, re-implement it.

Re-implemented the solution with the following fixes in commit dbd2ebb:

  1. Fixed tspconfig.yaml for RLC to include is-modular-library: false option (was generating modular client instead of RLC)
  2. Added support for numeric scalar type in modelUtils.ts - TypeSpec's numeric[] was generating invalid array type instead of number[]
  3. Added null check for schema.items.type in getSchemaForArrayModel to prevent crashes
  4. Fixed test file to use "Feature" as const for literal type compatibility

All 4 RLC integration tests now pass (getModel, putModel, getProperty, putProperty).

Copilot avatar Nov 25 '25 04:11 Copilot