Skip to content

[Feature] Support client level header/path apiVersion #3304

@v-jiaodi

Description

@v-jiaodi

Summary

The TypeSpec TypeScript generator for Azure Modular SDK incorrectly generates code that imports version from Node.js os module instead of using the client's API version string, causing TypeScript compilation errors.

Spector case link: https://github.com/Azure/typespec-azure/tree/main/packages/azure-http-specs/specs/azure/client-generator-core/api-version

Bug Details

  • Component: TypeSpec TypeScript Generator (Modular SDK)
  • Error Type: Incorrect import generation
  • Affected Files: *Context.ts files in generated Modular SDK clients
  • TypeScript Error: Type '() => string' is not comparable to type 'string'

Generated Code Issue

The generator produces incorrect code like this:

// ❌ INCORRECT - Generated by TypeSpec generator
import { version } from "os";  // This imports Node.js os.version() function
import { logger } from "../logger.js";
import { Client, ClientOptions, getClient } from "@azure-rest/core-client";

export function createHeader(options: HeaderClientOptionalParams = {}): HeaderContext {
  // ... other code ...
  clientContext.pipeline.addPolicy({
    name: "ClientApiVersionPolicy",
    sendRequest: (req, next) => {
      // ... 
      req.url = `${req.url}api-version=${version}`;  // ❌ version is a function, not string
      // ...
    },
  });
  return { ...clientContext, version } as HeaderContext;  // ❌ Type error here
}

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions