Nguon: Microsoft Learn · .NET 8.0

Tham chiếu lệnh và cài đặt công cụ .NET OpenAPI

Nguồn: OpenAPI tools

Microsoft.dotnet-openapi là một .NET Global Tool (công cụ toàn cục .NET) để quản lý các tham chiếu OpenAPI trong một project.

Cài đặt

Để cài đặt Microsoft.dotnet-openapi, chạy lệnh sau:

dotnetcli
dotnet tool install -g Microsoft.dotnet-openapi

Lưu ý: Theo mặc định, kiến trúc của các binary .NET được cài đặt đại diện cho kiến trúc hệ điều hành đang chạy. Để chỉ định kiến trúc khác, xem cách sử dụng lệnh dotnet tool install với tùy chọn '--arch'.

Add (Thêm)

Thêm tham chiếu OpenAPI bằng bất kỳ lệnh nào trên trang này sẽ thêm phần tử <OpenApiReference /> tương tự như sau vào file .csproj:

xml
<OpenApiReference Include="openapi.json" />

Tham chiếu trên là cần thiết để ứng dụng gọi code client được tạo ra.

Add File (Thêm file)

Tùy chọn

Tùy chọn ngắnTùy chọn dàiMô tảVí dụ
-p--updateProjectProject để thực hiện thao tác.dotnet openapi add file --updateProject .\Ref.csproj .\OpenAPI.json
-c--code-generatorCode generator (bộ tạo code) để áp dụng cho tham chiếu. Các tùy chọn là NSwagCSharpNSwagTypeScript. Nếu không chỉ định --code-generator, mặc định là NSwagCSharp.dotnet openapi add file .\OpenApi.json --code-generator
-h--helpHiển thị thông tin trợ giúpdotnet openapi add file --help

Arguments (Tham số)

ArgumentMô tảVí dụ
source-fileNguồn để tạo tham chiếu. Phải là file OpenAPI.dotnet openapi add file .\OpenAPI.json

Add URL (Thêm URL)

Tùy chọn

Tùy chọn ngắnTùy chọn dàiMô tảVí dụ
-p--updateProjectProject để thực hiện thao tác.dotnet openapi add url --updateProject .\Ref.csproj https://contoso.com/openapi.json
-o--output-fileNơi đặt bản sao cục bộ của file OpenAPI.dotnet openapi add url https://contoso.com/openapi.json --output-file myclient.json
-c--code-generatorCode generator để áp dụng cho tham chiếu. Các tùy chọn là NSwagCSharpNSwagTypeScript.dotnet openapi add url https://contoso.com/openapi.json --code-generator
-h--helpHiển thị thông tin trợ giúpdotnet openapi add url --help

Arguments

ArgumentMô tảVí dụ
source-URLNguồn để tạo tham chiếu. Phải là URL.dotnet openapi add url https://contoso.com/openapi.json

Remove (Xóa)

Xóa tham chiếu OpenAPI khớp với tên file đã cho khỏi file .csproj. Khi tham chiếu OpenAPI bị xóa, client sẽ không được tạo ra. Các file .json.yaml cục bộ sẽ bị xóa.

Tùy chọn

Tùy chọn ngắnTùy chọn dàiMô tảVí dụ
-p--updateProjectProject để thực hiện thao tác.dotnet openapi remove --updateProject .\Ref.csproj .\OpenAPI.json
-h--helpHiển thị thông tin trợ giúpdotnet openapi remove --help

Arguments

ArgumentMô tảVí dụ
source-fileNguồn để xóa tham chiếu đến.dotnet openapi remove .\OpenAPI.json

Refresh (Làm mới)

Làm mới phiên bản cục bộ của một file đã được tải xuống bằng nội dung mới nhất từ URL tải xuống.

Tùy chọn

Tùy chọn ngắnTùy chọn dàiMô tảVí dụ
-p--updateProjectProject để thực hiện thao tác.dotnet openapi refresh --updateProject .\Ref.csproj https://contoso.com/openapi.json
-h--helpHiển thị thông tin trợ giúpdotnet openapi refresh --help

Arguments

ArgumentMô tảVí dụ
source-URLURL để làm mới tham chiếu từ đó.dotnet openapi refresh https://contoso.com/openapi.json