Common Behavior for Client Packages
This page documents the common behavior for a client package, including the service, namespace, license, and more.
Service
The service acts as the entry point for a client library. Currently, only one service per package is supported. The service is defined using the @service
decorator. If multiple services are defined, the first one will be used as the entry point.
Namespace
Clients, models, enums, and unions in TypeSpec include namespace information. Code generators for different languages use this information to organize the generated code.
Basic Example
@service(#{ title: "Pet Store" })namespace PetStore;
@route("/feed")op feed(food: Food): void;
model Food { name: string; quantity: int32;}
# TODO
// TODO
// TODO
// TODO
Customization
You can use the @clientNamespace
decorator to customize the namespace for specific clients, enums, models, or unions.
import "./main.tsp";import "@azure-tools/typespec-client-generator-core";
namespace Customization;
@@clientNamespace(PetStore.Food, "PetStore.Models");
# TODO
// TODO
// TODO
// TODO
License
License information is automatically generated in the client code header and the LICENSE
file, depending on the language’s emitter.
Azure License
For Azure scenarios, client code always uses the MIT license. The license information is included in the header of the generated code or in a separate file, depending on the language.
For example, here is the license comment in the generated code of a Java client:
// Copyright (c) Microsoft Corporation. All rights reserved.// Licensed under the MIT License.
And here is the LICENSE
file for a Python client library:
Copyright (c) Microsoft Corporation
Permission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the “Software”), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included inall copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS INTHE SOFTWARE.
Unbranded License
For unbranded scenarios, client code will not include license information unless it is configured in tspconfig.yaml
. Spec authors can define license information using the license
configuration in tspconfig.yaml
as shown below:
license: name: <License name. This is required. We support built-in licenses such as "MIT License", "Apache License 2.0", "BSD 3-Clause License", "MPL 2.0", "GPL-3.0", and "LGPL-3.0". For custom licenses, you must provide the name, company, link, header, and description manually.> company: <Company name. Optional. For built-in licenses, this affects the copyright statement.> link: <License link. Optional. Required for custom licenses.> header: <License header in the generated code. Optional. Required for custom licenses.> description: <License description in the separate license file. Optional. Required for custom licenses.>
Example: Built-in License
emit: - "@azure-tools/typespec-python" - "@azure-tools/typespec-java"options: "@azure-tools/typespec-python": license: name: "Apache License 2.0" company: "Microsoft Corporation" "@azure-tools/typespec-java": license: name: "Apache License 2.0" company: "Microsoft Corporation"
Generated license comment in Java client code:
// Copyright (c) Microsoft Corporation. All rights reserved.// Licensed under the Apache License, Version 2.0.
Generated LICENSE
file for Python client library:
Copyright (c) Microsoft Corporation
Licensed under the Apache License, Version 2.0 (the "License");you may not use this file except in compliance with the License.You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License.
Example: Custom License
emit: - "@azure-tools/typespec-python" - "@azure-tools/typespec-java"options: "@azure-tools/typespec-python": license: name: "Mozilla Public License 2.0" link: "https://www.mozilla.org/en-US/MPL/2.0/" header: "This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/." description: "This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/." "@azure-tools/typespec-java": license: name: "Mozilla Public License 2.0" link: "https://www.mozilla.org/en-US/MPL/2.0/" header: "This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/." description: "This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/."
Generated license comment in Java client code:
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
Generated LICENSE
file for Python client library:
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.