Skip to content

Add spector test for alternate-type with emitter fixes for external types#861

Merged
antkmsft merged 7 commits intomainfrom
copilot/add-spector-test-for-azure
Feb 24, 2026
Merged

Add spector test for alternate-type with emitter fixes for external types#861
antkmsft merged 7 commits intomainfrom
copilot/add-spector-test-for-azure

Conversation

Copy link
Contributor

Copilot AI commented Feb 17, 2026

Adds spector test for azure/client-generator-core/alternate-type demonstrating external type replacement with geojson::Feature.

Changes

  • Emitter: Handle non-discriminated unions in external types

    • Skip non-discriminated unions in adaptTypes() instead of failing
    • Return placeholder type in getType() when encountering unsupported unions
    • Prevents failures when external types contain complex property types that won't be emitted
  • Emitter: Add numeric type support

    • Map TypeSpec numeric base type to f64
  • Test infrastructure

    • Local client.tsp with Rust alternateType decorator mapping Feature → geojson::Feature
    • Tests validate external type usage in operations and model properties
    • Workspace integration with geojson dependency

Example

Generated code uses external type from geojson crate:

use geojson::Feature;

pub async fn get_model(&self) -> Result<Response<Feature>> { ... }

#[derive(Clone, Deserialize, Serialize)]
pub struct ModelWithFeatureProperty {
    pub feature: Option<Feature>,
    pub additional_property: Option<String>,
}
Original prompt

This section details on the original issue you should resolve

<issue_title>Add spector test for azure-http-specs\azure\client-generator-core\alternate-type</issue_title>
<issue_description>Do not modify the generated rust source code (in src/generated), only modify the emitter code (in /packages/typespec-rust/src/) if necessary.</issue_description>

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


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 3 commits February 17, 2026 16:22
Co-authored-by: antkmsft <41349689+antkmsft@users.noreply.github.com>
Co-authored-by: antkmsft <41349689+antkmsft@users.noreply.github.com>
Co-authored-by: antkmsft <41349689+antkmsft@users.noreply.github.com>
Copilot AI changed the title [WIP] Add spector test for azure-http-specs Add spector test for alternate-type with emitter fixes for external types Feb 17, 2026
Copilot AI requested a review from antkmsft February 17, 2026 16:35
@antkmsft antkmsft marked this pull request as ready for review February 18, 2026 22:00
Copilot AI review requested due to automatic review settings February 18, 2026 22:00
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds spector test coverage for the azure/client-generator-core/alternate-type spec, demonstrating external type replacement using the geojson::Feature crate. To support this, the emitter was enhanced to gracefully handle non-discriminated unions that appear in external types (which will be replaced and thus won't be emitted) and to support the TypeSpec numeric base type by mapping it to Rust's f64.

Changes:

  • Enhanced emitter to skip non-discriminated unions in adaptTypes() instead of failing, since external types containing these unions will be replaced
  • Added support for TypeSpec's numeric type by mapping it to f64 in Rust code generation
  • Added comprehensive spector test suite for alternate-type feature with TypeSpec definitions, Cargo workspace integration, generated code, and integration tests

Reviewed changes

Copilot reviewed 8 out of 17 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/typespec-rust/src/tcgcadapter/adapter.ts Emitter enhancements: skip non-discriminated unions in adaptTypes() and getType(); map numeric type to f64
packages/typespec-rust/test/spector/azure/client-generator-core/alternate-type/main.tsp TypeSpec definitions for Feature, Geometry, and test operations demonstrating external type usage
packages/typespec-rust/test/spector/azure/client-generator-core/alternate-type/client.tsp Rust-specific alternateType decorator mapping Feature to geojson::Feature
packages/typespec-rust/test/spector/azure/client-generator-core/alternate-type/Cargo.toml Package configuration with geojson dependency
packages/typespec-rust/test/Cargo.toml Workspace member addition and geojson dependency declaration
packages/typespec-rust/test/Cargo.lock Dependency lock file updates for geojson and transitive dependencies
packages/typespec-rust/test/spector/azure/client-generator-core/alternate-type/src/lib.rs Library entry point
packages/typespec-rust/test/spector/azure/client-generator-core/alternate-type/src/generated/* Generated client and model code using external geojson::Feature type
packages/typespec-rust/test/spector/azure/client-generator-core/alternate-type/tests/external_type_client.rs Integration tests validating external type usage in operations and model properties
packages/typespec-rust/.scripts/tspcompile.js Build script integration for the new test suite

@antkmsft antkmsft requested a review from RickWinter February 20, 2026 00:32
@antkmsft antkmsft merged commit 98ee74f into main Feb 24, 2026
5 checks passed
@antkmsft antkmsft deleted the copilot/add-spector-test-for-azure branch February 24, 2026 00:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add spector test for azure-http-specs\azure\client-generator-core\alternate-type\

6 participants