Skip to content
Merged
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
17 changes: 8 additions & 9 deletions packages/http-client-csharp/emitter/src/options.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { CreateSdkContextOptions } from "@azure-tools/typespec-client-generator-core";
import {
CreateSdkContextOptions,
UnbrandedSdkEmitterOptions,
} from "@azure-tools/typespec-client-generator-core";
import { EmitContext, JSONSchemaType } from "@typespec/compiler";
import { _defaultGeneratorName } from "./constants.js";
import { DYNAMIC_MODEL_DECORATOR_PATTERN } from "./lib/decorators.js";
Expand All @@ -8,8 +11,10 @@ import { LoggerLevel } from "./lib/logger-level.js";
* The emitter options for the CSharp emitter.
* @beta
*/
type ApiVersionSelection = string | Record<string, string>;

export interface CSharpEmitterOptions {
"api-version"?: string;
"api-version"?: ApiVersionSelection;
"unreferenced-types-handling"?: "removeOrInternalize" | "internalize" | "keepAll";
"new-project"?: boolean;
"save-inputs"?: boolean;
Expand Down Expand Up @@ -41,13 +46,7 @@ export const CSharpEmitterOptionsSchema: JSONSchemaType<CSharpEmitterOptions> =
type: "object",
additionalProperties: false,
properties: {
"api-version": {
type: "string",
nullable: true,
description:
"For TypeSpec files using the [`@versioned`](https://typespec.io/docs/libraries/versioning/reference/decorators/#@TypeSpec.Versioning.versioned) decorator, " +
"set this option to the version that should be used to generate against.",
},
...UnbrandedSdkEmitterOptions["api-version"],
"generate-protocol-methods": {
type: "boolean",
nullable: true,
Expand Down
25 changes: 15 additions & 10 deletions packages/http-client-csharp/emitter/test/Unit/emitter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,21 @@ describe("$onEmit tests", () => {
}),
};
});
vi.mock("@azure-tools/typespec-client-generator-core", () => ({
createSdkContext: vi.fn().mockImplementation(async (...args) => {
return {
sdkPackage: {},
emitContext: args[0],
program: args[0].program,
diagnostics: [],
};
}),
}));
vi.mock("@azure-tools/typespec-client-generator-core", async (importOriginal) => {
const actual =
await importOriginal<typeof import("@azure-tools/typespec-client-generator-core")>();
return {
...actual,
createSdkContext: vi.fn().mockImplementation(async (...args) => {
return {
sdkPackage: {},
emitContext: args[0],
program: args[0].program,
diagnostics: [],
};
}),
};
});

vi.mock("../../src/lib/exec-utils.js", () => ({
execCSharpGenerator: vi.fn(),
Expand Down
13 changes: 12 additions & 1 deletion packages/http-client-csharp/emitter/test/Unit/options.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
vi.resetModules();

import { UnbrandedSdkEmitterOptions } from "@azure-tools/typespec-client-generator-core";
import { EmitContext, Program } from "@typespec/compiler";
import { ok, strictEqual } from "assert";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { createConfiguration } from "../../src/emitter.js";
import { CSharpEmitterOptions } from "../../src/options.js";
import { CSharpEmitterOptions, CSharpEmitterOptionsSchema } from "../../src/options.js";
import {
createCSharpSdkContext,
createEmitterContext,
Expand Down Expand Up @@ -187,4 +188,14 @@ describe("Configuration tests", async () => {

expect(config["plugins"]).toBeUndefined();
});

it("api-version schema accepts a string or namespace-to-version map", () => {
const schema = CSharpEmitterOptionsSchema.properties["api-version"];
const tcgcSchema = UnbrandedSdkEmitterOptions["api-version"]["api-version"] as {
oneOf?: unknown[];
};

expect(schema).toBe(tcgcSchema);
expect(tcgcSchema.oneOf).toBeDefined();
});
});
10 changes: 5 additions & 5 deletions packages/http-client-csharp/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/http-client-csharp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
],
"peerDependencies": {
"@azure-tools/typespec-azure-core": ">=0.69.0 <0.70.0 || ~0.70.0-0",
"@azure-tools/typespec-client-generator-core": ">=0.69.0 <0.70.0 || ~0.70.0-0",
"@azure-tools/typespec-client-generator-core": ">=0.69.1 <0.70.0 || ~0.70.0-0",
"@typespec/compiler": "^1.13.0",
"@typespec/http": "^1.13.0",
"@typespec/openapi": "^1.13.0",
Expand All @@ -71,7 +71,7 @@
"devDependencies": {
"@azure-tools/azure-http-specs": "0.1.0-alpha.42",
"@azure-tools/typespec-azure-core": "0.69.0",
"@azure-tools/typespec-client-generator-core": "0.69.0",
"@azure-tools/typespec-client-generator-core": "0.69.1",
"@microsoft/api-extractor": "^7.52.2",
"@types/node": "~22.12.0",
"@typespec/compiler": "1.13.0",
Expand Down
9 changes: 7 additions & 2 deletions packages/http-client-csharp/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,14 @@ See [Configuring output directory for more info](https://typespec.io/docs/handbo

### `api-version`

**Type:** `string`
**Type:** `string | object`

Use this flag if you would like to generate the sdk only for a specific version. Default value is the latest version. Also accepts values `latest` and `all`. For multi-service packages, provide a map from each service namespace's full name to its desired version; services not listed default to their latest version.

**Options:**

For TypeSpec files using the [`@versioned`](https://typespec.io/docs/libraries/versioning/reference/decorators/#@TypeSpec.Versioning.versioned) decorator, set this option to the version that should be used to generate against.
- `string`
- `object`

### `generate-protocol-methods`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,14 @@ See [Configuring output directory for more info](https://typespec.io/docs/handbo

### `api-version`

**Type:** `string`
**Type:** `string | object`

Use this flag if you would like to generate the sdk only for a specific version. Default value is the latest version. Also accepts values `latest` and `all`. For multi-service packages, provide a map from each service namespace's full name to its desired version; services not listed default to their latest version.

**Options:**

For TypeSpec files using the [`@versioned`](https://typespec.io/docs/libraries/versioning/reference/decorators/#@TypeSpec.Versioning.versioned) decorator, set this option to the version that should be used to generate against.
- `string`
- `object`

### `generate-protocol-methods`

Expand Down
Loading