Skip to content

Commit d19a414

Browse files
authored
[tcgc] add license config support (#2353)
resolve: #2273
1 parent f8969db commit d19a414

File tree

10 files changed

+467
-17
lines changed

10 files changed

+467
-17
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
changeKind: feature
3+
packages:
4+
- "@azure-tools/typespec-client-generator-core"
5+
---
6+
7+
Add `licenseInfo` property of `LicenseInfo` type to `SdkPackage`, which is used to indicate the license for the package and could be configured by `license.name`, `license.company`, `license.link`, `license.header` and `license.description` in `tspconfig.yaml`.

packages/typespec-client-generator-core/README.md

+23-5
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,24 @@ options:
3535
3636
## Emitter options
3737
38+
### `emitter-name`
39+
40+
**Type:** `string`
41+
42+
Set `emitter-name` to output TCGC code models for specific language's emitter. This flag only work for taking TCGC as an emitter.
43+
3844
### `generate-protocol-methods`
3945

4046
**Type:** `boolean`
4147

48+
When set to `true`, the emitter will generate low-level protocol methods for each service operation if `@protocolAPI` is not set for an operation. Default value is `true`.
49+
4250
### `generate-convenience-methods`
4351

4452
**Type:** `boolean`
4553

54+
When set to `true`, the emitter will generate low-level protocol methods for each service operation if `@convenientAPI` is not set for an operation. Default value is `true`.
55+
4656
### `package-name`
4757

4858
**Type:** `string`
@@ -51,21 +61,29 @@ options:
5161

5262
**Type:** `boolean`
5363

54-
### `api-version`
64+
### `examples-dir`
5565

5666
**Type:** `string`
5767

58-
### `examples-dir`
68+
Specifies the directory where the emitter will look for example files. If the flag isn’t set, the emitter defaults to using an `examples` directory located at the project root.
69+
70+
### `namespace`
5971

6072
**Type:** `string`
6173

62-
### `emitter-name`
74+
Specifies the namespace you want to override for namespaces set in the spec. With this config, all namespace for the spec types will default to it.
75+
76+
### `api-version`
6377

6478
**Type:** `string`
6579

66-
### `namespace`
80+
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`.
6781

68-
**Type:** `string`
82+
### `license`
83+
84+
**Type:** `object`
85+
86+
License information for the generated client code.
6987

7088
## Usage
7189

packages/typespec-client-generator-core/design-docs/flags.md

+24
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,27 @@ Specifies the namespace you want to override for namespaces set in the spec. Wit
1919
## 5. `api-version`
2020

2121
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`.
22+
23+
## 6. `license`
24+
25+
License information for the generated client code.
26+
27+
### `name`
28+
29+
License name. The config is required. Predefined license are: MIT License, Apache License 2.0, BSD 3-Clause License, MPL 2.0, GPL-3.0, LGPL-3.0. For other license, you need to configure all the other license config manually.
30+
31+
### `company`
32+
33+
License company name. It will be used in copyright sentences.
34+
35+
### `link`
36+
37+
License link.
38+
39+
### `header`
40+
41+
License header. It will be used in the header comment of generated client code.
42+
43+
### `description`
44+
45+
License description. The full license text.

packages/typespec-client-generator-core/src/context.ts

+1
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ export async function createSdkContext<
127127
examplesDir: context.options["examples-dir"],
128128
namespaceFlag: context.options["namespace"],
129129
apiVersion: options?.versioning?.strategy === "ignore" ? "all" : context.options["api-version"],
130+
license: context.options["license"],
130131
decoratorsAllowList: [...defaultDecoratorsAllowList, ...(options?.additionalDecorators ?? [])],
131132
previewStringRegex: options?.versioning?.previewStringRegex || tcgcContext.previewStringRegex,
132133
disableUsageAccessPropagationToBase: options?.disableUsageAccessPropagationToBase ?? false,

packages/typespec-client-generator-core/src/interfaces.ts

+24-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ export interface TCGCContext {
4646
examplesDir?: string;
4747
namespaceFlag?: string;
4848
apiVersion?: string;
49+
license?: {
50+
name: string;
51+
company?: string;
52+
header?: string;
53+
link?: string;
54+
description?: string;
55+
};
4956

5057
decoratorsAllowList?: string[];
5158
previewStringRegex: RegExp;
@@ -79,6 +86,7 @@ export interface SdkContext<
7986
}
8087

8188
export interface SdkEmitterOptions {
89+
"emitter-name"?: string;
8290
"generate-protocol-methods"?: boolean;
8391
"generate-convenience-methods"?: boolean;
8492
/**
@@ -88,8 +96,14 @@ export interface SdkEmitterOptions {
8896
"flatten-union-as-enum"?: boolean;
8997
"api-version"?: string;
9098
"examples-dir"?: string;
91-
"emitter-name"?: string;
9299
namespace?: string;
100+
license?: {
101+
name: string;
102+
company?: string;
103+
link?: string;
104+
header?: string;
105+
description?: string;
106+
};
93107
}
94108

95109
// Types for TCGC customization decorators
@@ -965,6 +979,15 @@ export interface SdkPackage<TServiceOperation extends SdkServiceOperation> {
965979
unions: (SdkUnionType | SdkNullableType)[];
966980
crossLanguagePackageId: string;
967981
namespaces: SdkNamespace<TServiceOperation>[];
982+
licenseInfo?: LicenseInfo;
983+
}
984+
985+
export interface LicenseInfo {
986+
name: string;
987+
company: string;
988+
link: string;
989+
header: string;
990+
description: string;
968991
}
969992

970993
export interface SdkNamespace<TServiceOperation extends SdkServiceOperation> {

packages/typespec-client-generator-core/src/lib.ts

+75-6
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,86 @@ const EmitterOptionsSchema: JSONSchemaType<SdkEmitterOptions> = {
55
type: "object",
66
additionalProperties: true,
77
properties: {
8-
"generate-protocol-methods": { type: "boolean", nullable: true },
9-
"generate-convenience-methods": { type: "boolean", nullable: true },
8+
"emitter-name": {
9+
type: "string",
10+
nullable: true,
11+
description:
12+
"Set `emitter-name` to output TCGC code models for specific language's emitter. This flag only work for taking TCGC as an emitter.",
13+
},
14+
"generate-protocol-methods": {
15+
type: "boolean",
16+
nullable: true,
17+
description:
18+
"When set to `true`, the emitter will generate low-level protocol methods for each service operation if `@protocolAPI` is not set for an operation. Default value is `true`.",
19+
},
20+
"generate-convenience-methods": {
21+
type: "boolean",
22+
nullable: true,
23+
description:
24+
"When set to `true`, the emitter will generate low-level protocol methods for each service operation if `@convenientAPI` is not set for an operation. Default value is `true`.",
25+
},
1026
/**
1127
* @deprecated Use the `package-name` option on your language emitter instead, if it exists.
1228
*/
1329
"package-name": { type: "string", nullable: true },
30+
/**
31+
* @deprecated Use `flattenUnionAsEnum` in `CreateSdkContextOptions` instead.
32+
*/
1433
"flatten-union-as-enum": { type: "boolean", nullable: true },
15-
"api-version": { type: "string", nullable: true },
16-
"examples-dir": { type: "string", nullable: true },
17-
"emitter-name": { type: "string", nullable: true },
18-
namespace: { type: "string", nullable: true },
34+
"examples-dir": {
35+
type: "string",
36+
nullable: true,
37+
description:
38+
"Specifies the directory where the emitter will look for example files. If the flag isn’t set, the emitter defaults to using an `examples` directory located at the project root.",
39+
},
40+
namespace: {
41+
type: "string",
42+
nullable: true,
43+
description:
44+
"Specifies the namespace you want to override for namespaces set in the spec. With this config, all namespace for the spec types will default to it.",
45+
},
46+
"api-version": {
47+
type: "string",
48+
nullable: true,
49+
description:
50+
"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`.",
51+
},
52+
license: {
53+
type: "object",
54+
additionalProperties: false,
55+
nullable: true,
56+
required: ["name"],
57+
properties: {
58+
name: {
59+
type: "string",
60+
nullable: false,
61+
description:
62+
"License name. The config is required. Predefined license are: MIT License, Apache License 2.0, BSD 3-Clause License, MPL 2.0, GPL-3.0, LGPL-3.0. For other license, you need to configure all the other license config manually.",
63+
},
64+
company: {
65+
type: "string",
66+
nullable: true,
67+
description: "License company name. It will be used in copyright sentences.",
68+
},
69+
link: {
70+
type: "string",
71+
nullable: true,
72+
description: "License link.",
73+
},
74+
header: {
75+
type: "string",
76+
nullable: true,
77+
description:
78+
"License header. It will be used in the header comment of generated client code.",
79+
},
80+
description: {
81+
type: "string",
82+
nullable: true,
83+
description: "License description. The full license text.",
84+
},
85+
},
86+
description: "License information for the generated client code.",
87+
},
1988
},
2089
};
2190

0 commit comments

Comments
 (0)