Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/python-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ jobs:

- uses: ./.github/actions/setup-python

- name: Install pnpm workspace dependencies
run: pnpm install --no-frozen-lockfile

- name: Build http-client-generator-core dependency
run: pnpm -r --filter "@typespec/http-client-generator-core..." build

- name: Build and pack http-client-python from PR
run: |
cd core/packages/http-client-python
Expand Down
57 changes: 57 additions & 0 deletions packages/http-client-generator-core/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# @typespec/http-client-generator-core

Protocol-agnostic core library for TypeSpec client SDK generation.

## Overview

This package provides the foundational types, interfaces, and infrastructure for generating client SDKs from TypeSpec definitions. It is designed to be **cloud-provider agnostic** — containing no Azure-specific concepts.

Azure-specific functionality (LRO, ARM, Azure Core utilities) is provided by `@azure-tools/typespec-client-generator-core`, which extends this package.

## Architecture

```
@typespec/http-client-generator-core (this package)
├── Core type graph (SdkType, SdkModelType, SdkEnumType, etc.)
├── Client/operation interfaces (SdkClient, SdkClientType, SdkServiceMethod)
├── HTTP operation mapping (SdkHttpOperation, SdkHttpParameter)
├── Paging support (SdkPagingServiceMethod, SdkPagingServiceMetadata)
├── Decorator infrastructure (@clientName, @client, @access, @usage, etc.)
├── Context management (TCGCContext, SdkContext)
└── Example types (SdkHttpOperationExample, SdkExampleValue)

@azure-tools/typespec-client-generator-core (Azure extension)
├── LRO support (SdkLroServiceMethod, SdkLroPagingServiceMethod, SdkLroServiceMetadata)
├── ARM detection and subscription ID handling
├── Azure Core utilities (getUnionAsEnum, isPreviewVersion)
├── Azure-specific defaults and configurations
└── Re-exports everything from core for backward compatibility
```

## Key Design Decisions

### Extensible Method Types

The `SdkServiceMethod` union in core includes only `basic` and `paging` variants:

```typescript
type SdkCoreServiceMethod<T> = SdkBasicServiceMethod<T> | SdkPagingServiceMethod<T>;
```

The Azure extension adds LRO variants:

```typescript
type SdkServiceMethod<T> = SdkCoreServiceMethod<T> | SdkLroServiceMethod<T> | SdkLroPagingServiceMethod<T>;
```

### No Azure Dependencies

This package has **zero** dependencies on:
- `@azure-tools/typespec-azure-core`
- `@azure-tools/typespec-azure-resource-manager`
- Any Azure-specific TypeSpec libraries

### TSP Namespace

Core decorators use `TypeSpec.ClientGenerator.Core` namespace.
Azure-specific decorators remain in `Azure.ClientGenerator.Core` namespace.
284 changes: 284 additions & 0 deletions packages/http-client-generator-core/docs/python-emitter-migration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,284 @@
# Python Emitter Migration Example

This document shows how the Python emitter (`@typespec/http-client-python`) would
update its imports after the TCGC split.

## Summary

| Import Source | What it provides |
|---|---|
| `@typespec/http-client-generator-core` | All core types, context, utilities |
| `@azure-tools/typespec-client-generator-core` | LRO types + Azure-specific helpers (re-exports core) |

Most files switch entirely to the core package. Only files dealing with LRO or
Azure-specific helpers need the Azure extension.

---

## emitter.ts

```typescript
// BEFORE
import { createSdkContext } from "@azure-tools/typespec-client-generator-core";

// AFTER — createSdkContext is a core function
import { createSdkContext } from "@typespec/http-client-generator-core";
```

---

## lib.ts

```typescript
// BEFORE
import {
SdkContext,
SdkType,
UnbrandedSdkEmitterOptions,
} from "@azure-tools/typespec-client-generator-core";

// AFTER — all core types
import {
SdkContext,
SdkType,
UnbrandedSdkEmitterOptions,
} from "@typespec/http-client-generator-core";
```

---

## types.ts

```typescript
// BEFORE
import {
isHttpMetadata,
SdkArrayType,
SdkBuiltInType,
SdkConstantType,
SdkCredentialType,
SdkDateTimeType,
SdkDictionaryType,
SdkDurationType,
SdkEndpointType,
SdkEnumType,
SdkEnumValueType,
SdkModelPropertyType,
SdkModelType,
SdkType,
SdkUnionType,
UsageFlags,
} from "@azure-tools/typespec-client-generator-core";

// AFTER — all core types and utilities
import {
isHttpMetadata,
SdkArrayType,
SdkBuiltInType,
SdkConstantType,
SdkCredentialType,
SdkDateTimeType,
SdkDictionaryType,
SdkDurationType,
SdkEndpointType,
SdkEnumType,
SdkEnumValueType,
SdkModelPropertyType,
SdkModelType,
SdkType,
SdkUnionType,
UsageFlags,
} from "@typespec/http-client-generator-core";
```

---

## utils.ts

```typescript
// BEFORE
import {
InitializedByFlags,
SdkCredentialParameter,
SdkEndpointParameter,
SdkHeaderParameter,
SdkHttpParameter,
SdkMethod,
SdkMethodParameter,
SdkModelPropertyType,
SdkQueryParameter,
SdkServiceMethod,
SdkServiceOperation,
SdkServiceResponseHeader,
SdkType,
} from "@azure-tools/typespec-client-generator-core";

// AFTER — all core types
import {
InitializedByFlags,
SdkCredentialParameter,
SdkEndpointParameter,
SdkHeaderParameter,
SdkHttpParameter,
SdkMethod,
SdkMethodParameter,
SdkModelPropertyType,
SdkQueryParameter,
SdkServiceMethod,
SdkServiceOperation,
SdkServiceResponseHeader,
SdkType,
} from "@typespec/http-client-generator-core";
```

---

## http.ts

```typescript
// BEFORE
import {
getHttpOperationParameter,
SdkBasicServiceMethod,
SdkBodyParameter,
SdkClientType,
SdkHeaderParameter,
SdkHttpErrorResponse,
SdkHttpOperation,
SdkHttpOperationExample,
SdkHttpResponse,
SdkLroPagingServiceMethod,
SdkLroServiceMethod,
SdkMethodParameter,
SdkModelPropertyType,
SdkPagingServiceMethod,
SdkPathParameter,
SdkQueryParameter,
SdkServiceMethod,
SdkServiceResponseHeader,
SdkType,
UsageFlags,
} from "@azure-tools/typespec-client-generator-core";

// AFTER — split between core and azure extension
import {
getHttpOperationParameter,
SdkBasicServiceMethod,
SdkBodyParameter,
SdkClientType,
SdkHeaderParameter,
SdkHttpErrorResponse,
SdkHttpOperation,
SdkHttpOperationExample,
SdkHttpResponse,
SdkMethodParameter,
SdkModelPropertyType,
SdkPagingServiceMethod,
SdkPathParameter,
SdkQueryParameter,
SdkServiceResponseHeader,
SdkType,
UsageFlags,
} from "@typespec/http-client-generator-core";
// LRO types come from the Azure extension
import {
SdkLroPagingServiceMethod,
SdkLroServiceMethod,
} from "@azure-tools/typespec-client-generator-core";
// NOTE: SdkServiceMethod is re-exported from azure extension with LRO variants included
import type { SdkServiceMethod } from "@azure-tools/typespec-client-generator-core";
```

---

## code-model.ts

```typescript
// BEFORE
import {
SdkBasicServiceMethod,
SdkClientType,
SdkCredentialParameter,
SdkCredentialType,
SdkEndpointParameter,
SdkEndpointType,
SdkLroPagingServiceMethod,
SdkLroServiceMethod,
SdkMethodParameter,
SdkPagingServiceMethod,
SdkServiceMethod,
SdkServiceOperation,
SdkUnionType,
UsageFlags,
getCrossLanguagePackageId,
isAzureCoreModel,
} from "@azure-tools/typespec-client-generator-core";

// AFTER — core types from core, Azure-specific from extension
import {
SdkBasicServiceMethod,
SdkClientType,
SdkCredentialParameter,
SdkCredentialType,
SdkEndpointParameter,
SdkEndpointType,
SdkMethodParameter,
SdkPagingServiceMethod,
SdkServiceOperation,
SdkUnionType,
UsageFlags,
getCrossLanguagePackageId,
} from "@typespec/http-client-generator-core";
// Azure-specific: LRO types + Azure model detection
import {
SdkLroPagingServiceMethod,
SdkLroServiceMethod,
SdkServiceMethod,
isAzureCoreModel,
} from "@azure-tools/typespec-client-generator-core";
```

---

## package.json changes

```jsonc
{
// BEFORE
"peerDependencies": {
"@azure-tools/typespec-client-generator-core": ">=0.67.0 <1.0.0"
},
"devDependencies": {
"@azure-tools/typespec-client-generator-core": "~0.67.0"
}

// AFTER
"peerDependencies": {
"@typespec/http-client-generator-core": "workspace:^",
// Still needed for LRO + isAzureCoreModel (optional peer for non-Azure usage)
"@azure-tools/typespec-client-generator-core": ">=0.68.0 <1.0.0"
},
"devDependencies": {
"@typespec/http-client-generator-core": "workspace:^",
"@azure-tools/typespec-client-generator-core": "~0.68.0"
}
}
```

---

## Key Observations

1. **4 out of 6 files** can switch entirely to `@typespec/http-client-generator-core`
(emitter.ts, lib.ts, types.ts, utils.ts)

2. **2 files** need split imports (http.ts, code-model.ts) because they use:
- `SdkLroServiceMethod` / `SdkLroPagingServiceMethod` — Azure LRO extension
- `isAzureCoreModel` — Azure-specific helper
- `SdkServiceMethod` (the full union including LRO) — Azure extension re-export

3. **Future state**: If/when the Python emitter drops Azure support from its core and
moves Azure handling to a separate plugin, it could depend only on the core package.

4. **Backward compat**: The Azure package re-exports everything from core, so existing
code continues to work without changes. Migration is opt-in and incremental.
Loading
Loading