Skip to content

Commit 33e10dd

Browse files
Add namespace option to emitter (Azure#49466)
* Add namespace option to emitter * more detail * Add model-namespace
1 parent 384ca34 commit 33e10dd

File tree

4 files changed

+45
-4
lines changed

4 files changed

+45
-4
lines changed

eng/packages/http-client-csharp/emitter/src/emitter.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import { EmitContext } from "@typespec/compiler";
55

66
import {
77
$onEmit as $onMTGEmit,
8-
CSharpEmitterOptions
98
} from "@typespec/http-client-csharp";
9+
import { AzureEmitterOptions } from "./options.js";
1010

11-
export async function $onEmit(context: EmitContext<CSharpEmitterOptions>) {
11+
export async function $onEmit(context: EmitContext<AzureEmitterOptions>) {
1212
context.options["generator-name"] ??= "AzureClientGenerator";
1313
context.options["emitter-extension-path"] ??= import.meta.url;
1414
context.options["license"] ??= { name: "MIT License", company: "Microsoft Corporation" };
1515
await $onMTGEmit(context);
16-
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License. See License.txt in the project root for license information.
33

4-
export * from "./emitter.js";
4+
export { $onEmit } from "./emitter.js";
5+
export { AzureEmitterOptions, AzureEmitterOptionsSchema } from "./options.js";
6+
export { $lib } from "./lib/lib.js";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { createTypeSpecLibrary } from "@typespec/compiler";
2+
import {
3+
$lib as httpClientCSharpLib,
4+
} from "@typespec/http-client-csharp";
5+
import { AzureEmitterOptionsSchema } from "../options.js";
6+
7+
export const $lib = createTypeSpecLibrary({
8+
name: "@azure-typespec/http-client-csharp",
9+
diagnostics: httpClientCSharpLib.diagnostics,
10+
emitter: {
11+
options: AzureEmitterOptionsSchema,
12+
},
13+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See License.txt in the project root for license information.
3+
4+
import { JSONSchemaType } from "@typespec/compiler";
5+
import { CSharpEmitterOptions, CSharpEmitterOptionsSchema } from "@typespec/http-client-csharp";
6+
7+
export interface AzureEmitterOptions extends CSharpEmitterOptions {
8+
namespace?: string;
9+
"model-namespace"?: boolean;
10+
}
11+
12+
export const AzureEmitterOptionsSchema: JSONSchemaType<AzureEmitterOptions> = {
13+
type: "object",
14+
properties: {
15+
...CSharpEmitterOptionsSchema.properties,
16+
namespace: {
17+
type: "string",
18+
description: "The C# namespace to use for the generated code. This will override the TypeSpec namespaces.",
19+
},
20+
"model-namespace": {
21+
type: "boolean",
22+
description: "Whether to put models under a separate 'Models' sub-namespace. This only applies if the 'namespace' option is set. " +
23+
" The default value is 'true' when the 'namespace' option is set. Otherwise, each model will be in the corresponding namespace defined in the TypeSpec.",
24+
},
25+
},
26+
};

0 commit comments

Comments
 (0)