Skip to content

Commit fe08fe8

Browse files
Use tspd in emitters (Azure#49477)
* Use tspd in emitters * mgmt * prettier * run prettier on package.json * fix * add emitter.md
1 parent 904565b commit fe08fe8

File tree

16 files changed

+1168
-41
lines changed

16 files changed

+1168
-41
lines changed
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
# @azure-typespec/http-client-csharp-mgmt
2+
3+
## Install
4+
5+
```bash
6+
npm install @azure-typespec/http-client-csharp-mgmt
7+
```
8+
9+
## Usage
10+
11+
1. Via the command line
12+
13+
```bash
14+
tsp compile . --emit=@azure-typespec/http-client-csharp-mgmt
15+
```
16+
17+
2. Via the config
18+
19+
```yaml
20+
emit:
21+
- '@azure-typespec/http-client-csharp-mgmt'
22+
```
23+
24+
The config can be extended with options as follows:
25+
26+
```yaml
27+
emit:
28+
- '@azure-typespec/http-client-csharp-mgmt'
29+
options:
30+
'@azure-typespec/http-client-csharp-mgmt':
31+
option: value
32+
```
33+
34+
## Emitter options
35+
36+
### `api-version`
37+
38+
**Type:** `string`
39+
40+
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.
41+
42+
### `generate-protocol-methods`
43+
44+
**Type:** `boolean`
45+
46+
### `generate-convenience-methods`
47+
48+
**Type:** `boolean`
49+
50+
### `unreferenced-types-handling`
51+
52+
**Type:** `"removeOrInternalize" | "internalize" | "keepAll"`
53+
54+
Defines the strategy on how to handle unreferenced types. The default value is `removeOrInternalize`.
55+
56+
### `new-project`
57+
58+
**Type:** `boolean`
59+
60+
Set to `true` to overwrite the csproj if it already exists. The default value is `false`.
61+
62+
### `clear-output-folder`
63+
64+
**Type:** `boolean`
65+
66+
Indicates if you want to clear the output folder before generating. The default value is `true`.
67+
68+
### `save-inputs`
69+
70+
**Type:** `boolean`
71+
72+
Set to `true` to save the `tspCodeModel.json` and `Configuration.json` files that are emitted and used as inputs to the generator. The default value is `false`.
73+
74+
### `package-name`
75+
76+
**Type:** `string`
77+
78+
Define the package name. If not specified, the first namespace defined in the TypeSpec is used as the package name.
79+
80+
### `debug`
81+
82+
**Type:** `boolean`
83+
84+
Set to `true` to automatically attempt to attach to a debugger when executing the C# generator. The default value is `false`.
85+
86+
### `logLevel`
87+
88+
**Type:** `"info" | "debug" | "verbose"`
89+
90+
Set the log level. The default value is `info`.
91+
92+
### `disable-xml-docs`
93+
94+
**Type:** `boolean`
95+
96+
Set to `true` to disable XML documentation generation. The default value is `false`.
97+
98+
### `generator-name`
99+
100+
**Type:** `string`
101+
102+
The name of the generator. By default this is set to `ScmCodeModelGenerator`. Generator authors can set this to the name of a generator that inherits from `ScmCodeModelGenerator`.
103+
104+
### `emitter-extension-path`
105+
106+
**Type:** `string`
107+
108+
Allows emitter authors to specify the path to a custom emitter package, allowing you to extend the emitter behavior. This should be set to `import.meta.url` if you are using a custom emitter.
109+
110+
### `update-code-model`
111+
112+
**Type:** `object`
113+
114+
Allows emitter authors to specify a custom function to modify the generated code model before emitting. This is useful for modifying the code model before it is passed to the generator.
115+
116+
### `license`
117+
118+
**Type:** `object`
119+
120+
License information for the generated client code.
121+
122+
### `sdk-context-options`
123+
124+
**Type:** `object`
125+
126+
The SDK context options that implement the `CreateSdkContextOptions` interface from the [`@azure-tools/typespec-client-generator-core`](https://www.npmjs.com/package/@azure-tools/typespec-client-generator-core) package to be used by the CSharp emitter.
127+
128+
### `namespace`
129+
130+
**Type:** `string`
131+
132+
The C# namespace to use for the generated code. This will override the TypeSpec namespaces.
133+
134+
### `model-namespace`
135+
136+
**Type:** `boolean`
137+
138+
Whether to put models under a separate 'Models' sub-namespace. This only applies if the 'namespace' option is set. The default value is 'true' when the 'namespace' option is set. Otherwise, each model will be in the corresponding namespace defined in the TypeSpec.
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
---
2+
title: 'Emitter usage'
3+
---
4+
5+
## Usage
6+
7+
1. Via the command line
8+
9+
```bash
10+
tsp compile . --emit=@azure-typespec/http-client-csharp-mgmt
11+
```
12+
13+
2. Via the config
14+
15+
```yaml
16+
emit:
17+
- '@azure-typespec/http-client-csharp-mgmt'
18+
```
19+
20+
The config can be extended with options as follows:
21+
22+
```yaml
23+
emit:
24+
- '@azure-typespec/http-client-csharp-mgmt'
25+
options:
26+
'@azure-typespec/http-client-csharp-mgmt':
27+
option: value
28+
```
29+
30+
## Emitter options
31+
32+
### `api-version`
33+
34+
**Type:** `string`
35+
36+
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.
37+
38+
### `generate-protocol-methods`
39+
40+
**Type:** `boolean`
41+
42+
### `generate-convenience-methods`
43+
44+
**Type:** `boolean`
45+
46+
### `unreferenced-types-handling`
47+
48+
**Type:** `"removeOrInternalize" | "internalize" | "keepAll"`
49+
50+
Defines the strategy on how to handle unreferenced types. The default value is `removeOrInternalize`.
51+
52+
### `new-project`
53+
54+
**Type:** `boolean`
55+
56+
Set to `true` to overwrite the csproj if it already exists. The default value is `false`.
57+
58+
### `clear-output-folder`
59+
60+
**Type:** `boolean`
61+
62+
Indicates if you want to clear the output folder before generating. The default value is `true`.
63+
64+
### `save-inputs`
65+
66+
**Type:** `boolean`
67+
68+
Set to `true` to save the `tspCodeModel.json` and `Configuration.json` files that are emitted and used as inputs to the generator. The default value is `false`.
69+
70+
### `package-name`
71+
72+
**Type:** `string`
73+
74+
Define the package name. If not specified, the first namespace defined in the TypeSpec is used as the package name.
75+
76+
### `debug`
77+
78+
**Type:** `boolean`
79+
80+
Set to `true` to automatically attempt to attach to a debugger when executing the C# generator. The default value is `false`.
81+
82+
### `logLevel`
83+
84+
**Type:** `"info" | "debug" | "verbose"`
85+
86+
Set the log level. The default value is `info`.
87+
88+
### `disable-xml-docs`
89+
90+
**Type:** `boolean`
91+
92+
Set to `true` to disable XML documentation generation. The default value is `false`.
93+
94+
### `generator-name`
95+
96+
**Type:** `string`
97+
98+
The name of the generator. By default this is set to `ScmCodeModelGenerator`. Generator authors can set this to the name of a generator that inherits from `ScmCodeModelGenerator`.
99+
100+
### `emitter-extension-path`
101+
102+
**Type:** `string`
103+
104+
Allows emitter authors to specify the path to a custom emitter package, allowing you to extend the emitter behavior. This should be set to `import.meta.url` if you are using a custom emitter.
105+
106+
### `update-code-model`
107+
108+
**Type:** `object`
109+
110+
Allows emitter authors to specify a custom function to modify the generated code model before emitting. This is useful for modifying the code model before it is passed to the generator.
111+
112+
### `license`
113+
114+
**Type:** `object`
115+
116+
License information for the generated client code.
117+
118+
### `sdk-context-options`
119+
120+
**Type:** `object`
121+
122+
The SDK context options that implement the `CreateSdkContextOptions` interface from the [`@azure-tools/typespec-client-generator-core`](https://www.npmjs.com/package/@azure-tools/typespec-client-generator-core) package to be used by the CSharp emitter.
123+
124+
### `namespace`
125+
126+
**Type:** `string`
127+
128+
The C# namespace to use for the generated code. This will override the TypeSpec namespaces.
129+
130+
### `model-namespace`
131+
132+
**Type:** `boolean`
133+
134+
Whether to put models under a separate 'Models' sub-namespace. This only applies if the 'namespace' option is set. The default value is 'true' when the 'namespace' option is set. Otherwise, each model will be in the corresponding namespace defined in the TypeSpec.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
title: Overview
3+
sidebar_position: 0
4+
toc_min_heading_level: 2
5+
toc_max_heading_level: 3
6+
---
7+
8+
import { Tabs, TabItem } from '@astrojs/starlight/components';
9+
10+
## Install
11+
12+
<Tabs>
13+
<TabItem label="In a spec" default>
14+
15+
```bash
16+
npm install @azure-typespec/http-client-csharp-mgmt
17+
```
18+
19+
</TabItem>
20+
<TabItem label="In a library" default>
21+
22+
```bash
23+
npm install --save-peer @azure-typespec/http-client-csharp-mgmt
24+
```
25+
26+
</TabItem>
27+
</Tabs>
28+
29+
## Emitter usage
30+
31+
[See documentation](./emitter.md)

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ import { DecoratorInfo } from "@azure-tools/typespec-client-generator-core";
66

77
import {
88
CodeModel,
9-
CSharpEmitterOptions,
109
InputClient,
1110
InputModelType,
1211
setSDKContextOptions
1312
} from "@typespec/http-client-csharp";
1413

15-
import { $onEmit as $onAzureEmit } from "@azure-typespec/http-client-csharp";
14+
import {
15+
$onEmit as $onAzureEmit,
16+
AzureEmitterOptions
17+
} from "@azure-typespec/http-client-csharp";
1618
import { azureSDKContextOptions } from "./sdk-context-options.js";
1719
import { calculateResourceTypeFromPath } from "./resource-type.js";
1820

@@ -23,7 +25,7 @@ const armResourceCreateOrUpdate =
2325
const singleton = "Azure.ResourceManager.@singleton";
2426
const resourceMetadata = "Azure.ClientGenerator.Core.@resourceSchema";
2527

26-
export async function $onEmit(context: EmitContext<CSharpEmitterOptions>) {
28+
export async function $onEmit(context: EmitContext<AzureEmitterOptions>) {
2729
context.options["generator-name"] ??= "ManagementClientGenerator";
2830
context.options["update-code-model"] = updateCodeModel;
2931
context.options["emitter-extension-path"] ??= import.meta.url;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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 { $lib } from "./lib/lib.js";
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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 { AzureEmitterOptionsSchema } from "@azure-typespec/http-client-csharp";
5+
import { createTypeSpecLibrary } from "@typespec/compiler";
6+
import { $lib as httpClientCSharpLib } from "@typespec/http-client-csharp";
7+
8+
export const $lib = createTypeSpecLibrary({
9+
name: "@azure-typespec/http-client-csharp-mgmt",
10+
diagnostics: httpClientCSharpLib.diagnostics,
11+
emitter: {
12+
options: AzureEmitterOptionsSchema
13+
}
14+
});

0 commit comments

Comments
 (0)