Skip to content

Commit d35ab35

Browse files
authored
[tcgc] license doc (#2394)
resolve: #2272
1 parent 79026ff commit d35ab35

File tree

3 files changed

+129
-0
lines changed

3 files changed

+129
-0
lines changed

website/src/content/current-sidebar.ts

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ const sidebar: SidebarItem[] = [
7474
"libraries/typespec-client-generator-core",
7575
"Azure.ClientGenerator.Core",
7676
false,
77+
["libraries/typespec-client-generator-core/guideline"],
7778
),
7879
createLibraryReferenceStructure("libraries/azure-portal-core", "Azure.Portal", false),
7980
],
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
---
2+
title: License
3+
---
4+
5+
import { ClientTabs, ClientTabItem } from "@components/client-tabs";
6+
7+
This page explains how the license info is generated in the client code.
8+
9+
## Azure license
10+
11+
For Azure scenarios, client code will always use the MIT license and include the license info in the header of the generated code or in a separate file depending on the language.
12+
13+
For example, this is the license comment in the generated code of a Java client:
14+
15+
```java
16+
// Copyright (c) Microsoft Corporation. All rights reserved.
17+
// Licensed under the MIT License.
18+
```
19+
20+
This is the `LICENSE` file of a Python client library:
21+
22+
```text
23+
Copyright (c) Microsoft Corporation
24+
25+
Permission is hereby granted, free of charge, to any person obtaining a copy
26+
of this software and associated documentation files (the “Software”), to deal
27+
in the Software without restriction, including without limitation the rights
28+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
29+
copies of the Software, and to permit persons to whom the Software is
30+
furnished to do so, subject to the following conditions:
31+
32+
The above copyright notice and this permission notice shall be included in
33+
all copies or substantial portions of the Software.
34+
35+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
36+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
37+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
38+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
39+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
40+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
41+
THE SOFTWARE.
42+
```
43+
44+
## Unbranded license
45+
46+
For unbranded scenarios, client code will have no license info if there is no license configuration in `tspconfig.yaml`.
47+
Spec authors can set the license info with the `license` configuration in the `tspconfig.yaml`:
48+
49+
```yaml
50+
license:
51+
name: <License name. We have built-in "MIT License", "Apache License 2.0", "BSD 3-Clause License", "MPL 2.0", "GPL-3.0", and "LGPL-3.0". For other licenses, you need to set the link, header, and description manually.>
52+
company: <Company name used in copyright>
53+
link: <License link>
54+
header: <License header in the generated code>
55+
description: <License description in the separate license file>
56+
```
57+
58+
For example, if you configure the license like the following, you will get the same license info as Azure scenarios:
59+
60+
```yaml
61+
emit:
62+
- "@azure-tools/typespec-python"
63+
- "@azure-tools/typespec-java"
64+
options:
65+
"@azure-tools/typespec-python":
66+
license:
67+
name: "MIT License"
68+
company: "Microsoft Corporation"
69+
"@azure-tools/typespec-java":
70+
license:
71+
name: "MIT License"
72+
company: "Microsoft Corporation"
73+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
title: Guideline for client emitter
3+
---
4+
5+
This document will guide you on how to use the TypeSpec Client Generator Core (TCGC) in client emitters.
6+
TCGC is a library that introduces a client type graph and provides useful helper functions for client emitters to generate client code.
7+
Client emitters do not need to interact with the TypeSpec core API directly; they can use the client type graph to obtain enough information to generate client code.
8+
9+
## Basic concepts
10+
11+
TODO
12+
13+
## TCGC options
14+
15+
TODO
16+
17+
## Client type graph
18+
19+
### Package
20+
21+
[`SdkPackage`](../reference/js-api/interfaces/sdkpackage/) represents a client package. It contains all clients and types information in either a flattened structure or a namespace hierarchy. It also includes common information useful for client code generation.
22+
23+
### License Info
24+
25+
The `licenseInfo` property of the [`LicenseInfo`](../reference/js-api/interfaces/licenseinfo/) type in `SdkPackage` contains the license information to be used for client code license comments or license file generation.
26+
27+
Client emitters should use `licenseInfo.name` (license name), `licenseInfo.link` (link to the official license document), `licenseInfo.header` (license sentences for code header comments), and `licenseInfo.description` (license sentences for separate license file) directly when generating license information in configuration files, code files, or license files. If `licenseInfo` is `undefined`, no license information should be included in the client code generation. Client emitters do not need to handle how the license information is configured.
28+
29+
For Azure services, client emitters should hard-code the `license.name` configuration to `MIT License` when calling `createSdkContext`.
30+
31+
```typescript
32+
export async function $onEmit(context: EmitContext<SdkEmitterOptions>) {
33+
context.options.license = {
34+
name: "MIT License",
35+
};
36+
const sdkContext = await createSdkContext(context);
37+
// ...
38+
}
39+
```
40+
41+
### Client
42+
43+
TODO
44+
45+
### Method
46+
47+
TODO
48+
49+
### Operation
50+
51+
TODO
52+
53+
### Type
54+
55+
TODO

0 commit comments

Comments
 (0)