Add Azure Alternate Type spector case and fix numeric type generation bug
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:
-
Added
numericscalar type support: TypeSpec'snumericscalar type was not mapped, causingnumeric[]to generate invalidarraytype instead ofnumber[].
// Added case for numeric type
case "numeric":
return applyIntrinsicDecorators(program, type, {
type: "number"
});
-
Fixed null check for array schema items: Added null checks before accessing
.includes()method whenschema.items.typeis 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-typeto bothazureRlcTspsandazureModularTsps -
tspconfig.yaml: Created configuration files for RLC (with
is-modular-library: false) and Modular test directories -
Test specs: Implemented
azureAlternateType.spec.tsfor 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
- run
rush update && rush build- run
rushx copy:typespecunder folderpackages/typespec.- 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" }
- create
tspconfig.yamltoazureIntegration/generated/azure/client-generator-core/alternate-typeandazureModularIntegration/generated/azure/client-generator-core/alternate-type, the file configuration should refer to the cases in the same directory respectively.- create
azureAlternateType.spec.tsfor azureIntegration and azureModularIntegration, then complete the case file according to thetemp/specs/azure/client-generator-core/alternate-type/mockapi.ts- 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 Based on the issue description, re-implement it.
@copilot Based on the issue description, re-implement it.
Re-implemented the solution with the following fixes in commit dbd2ebb:
- Fixed
tspconfig.yamlfor RLC to includeis-modular-library: falseoption (was generating modular client instead of RLC) - Added support for
numericscalar type inmodelUtils.ts- TypeSpec'snumeric[]was generating invalidarraytype instead ofnumber[] - Added null check for
schema.items.typeingetSchemaForArrayModelto prevent crashes - Fixed test file to use
"Feature" as constfor literal type compatibility
All 4 RLC integration tests now pass (getModel, putModel, getProperty, putProperty).