azure-mgmt-apicenter-dotnet について
Azure Resource Manager SDKを使ってAzure API CenterのAPI台帳とガバナンスを管理する.NETスキルです。APIの分類、バージョン、仕様、環境、デプロイ記録を扱います。
主な機能
- 01ワークスペースとAPIレコードの作成
- 02APIバージョンと定義の管理
- 03API仕様のエクスポート
- 04環境とデプロイの追跡
- 05メタデータスキーマの定義
- 06ワークスペース内のAPI一覧
活用シーン
- 01チームや製品ごとのAPI台帳作成
- 02API仕様のアップロードとエクスポート
- 03APIのライフサイクルとデプロイ情報の記録
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ sickn33/ agentic-awesome-skills --skill azure-mgmt-apicenter-dotnetインストール後、Claude Code で/azure-mgmt-apicenter-dotnetを入力して読み込まれたか確認します。
詳細
Azure.ResourceManager.ApiCenter (.NET)
組織全体の API を管理するための、一元化された API インベントリおよびガバナンス SDK です。
インストール
dotnet add package Azure.ResourceManager.ApiCenter
dotnet add package Azure.Identity
例は、過去の 1.0 API ファミリを対象としています。レビュー済みのパッケージを固定し、生成された型と API バージョンが公式リファレンスと一致することを確認してください。これは最新バージョンであることを示すものではありません。
環境変数
AZURE_SUBSCRIPTION_ID=<your-subscription-id>
AZURE_RESOURCE_GROUP=<your-resource-group>
AZURE_APICENTER_SERVICE_NAME=<your-apicenter-service>
認証
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.ApiCenter;
ArmClient client = new ArmClient(new DefaultAzureCredential());
リソース階層
Subscription
└── ResourceGroup
└── ApiCenterService # API inventory service
├── Workspace # Logical grouping of APIs
│ ├── Api # API definition
│ │ └── ApiVersion # Version of the API
│ │ └── ApiDefinition # OpenAPI/GraphQL/etc specification
│ ├── Environment # Deployment target (dev/staging/prod)
│ └── Deployment # API deployed to environment
└── MetadataSchema # Custom metadata definitions
これらは個別のスニペットであり、Azure/Azure.Core/Resources のインポートと、固定した SDK でのコンパイルが必要です。正確なサブスクリプション/リソース ID、権限、プロビジョニング前のコストを確認してください。API Center のレコードはデプロイを記録するものであり、デプロイレコードを作成しても、動作する API がデプロイされるわけではありません。仕様をアップロードする前に、埋め込まれた認証情報や内部データがないか確認してください。
主なワークフロー
1. API Center サービスを作成する
using Azure.ResourceManager.ApiCenter;
using Azure.ResourceManager.ApiCenter.Models;
// Resolve the explicitly selected subscription, avoiding sync-over-async/default-account ambiguity.
var subscription = client.GetSubscriptionResource(new ResourceIdentifier(
$"/subscriptions/{Environment.GetEnvironmentVariable("AZURE_SUBSCRIPTION_ID")}"));
ResourceGroupResource resourceGroup = (await subscription
.GetResourceGroupAsync("my-resource-group")).Value;
ApiCenterServiceCollection services = resourceGroup.GetApiCenterServices();
ApiCenterServiceData data = new ApiCenterServiceData(AzureLocation.EastUS)
{
Identity = new ManagedServiceIdentity(ManagedServiceIdentityType.SystemAssigned)
};
ArmOperation<ApiCenterServiceResource> operation = await services
.CreateOrUpdateAsync(WaitUntil.Completed, "my-api-center", data);
ApiCenterServiceResource service = operation.Value;
2. ワークスペースを作成する
ApiCenterWorkspaceCollection workspaces = service.GetApiCenterWorkspaces();
ApiCenterWorkspaceData workspaceData = new ApiCenterWorkspaceData
{
Title = "Engineering APIs",
Description = "APIs owned by the engineering team"
};
ArmOperation<ApiCenterWorkspaceResource> operation = await workspaces
.CreateOrUpdateAsync(WaitUntil.Completed, "engineering", workspaceData);
ApiCenterWorkspaceResource workspace = operation.Value;
3. API を作成する
ApiCenterApiCollection apis = workspace.GetApiCenterApis();
ApiCenterApiData apiData = new ApiCenterApiData
{
Title = "Orders API",
Description = "API for managing customer orders",
Kind = ApiKind.Rest,
LifecycleStage = ApiLifecycleStage.Production,
TermsOfService = new ApiTermsOfService
{
Uri = new Uri("https://example.com/terms")
},
ExternalDocumentation =
{
new ApiExternalDocumentation
{
Title = "Documentation",
Uri = new Uri("https://docs.example.com/orders")
}
},
Contacts =
{
new ApiContact
{
Name = "API Support",
Email = "[email protected]"
}
}
};
// Add custom metadata
apiData.CustomProperties = BinaryData.FromObjectAsJson(new
{
team = "orders-team",
costCenter = "CC-1234"
});
ArmOperation<ApiCenterApiResource> operation = await apis
.CreateOrUpdateAsync(WaitUntil.Completed, "orders-api", apiData);
ApiCenterApiResource api = operation.Value;
4. API バージョンを作成する
ApiCenterApiVersionCollection versions = api.GetApiCenterApiVersions();
ApiCenterApiVersionData versionData = new ApiCenterApiVersionData
{
Title = "v1.0.0",
LifecycleStage = ApiLifecycleStage.Production
};
ArmOperation<ApiCenterApiVersionResource> operation = await versions
.CreateOrUpdateAsync(WaitUntil.Completed, "v1-0-0", versionData);
ApiCenterApiVersionResource version = operation.Value;
5. API 定義を作成する(OpenAPI 仕様をアップロードする)
ApiCenterApiDefinitionCollection definitions = version.GetApiCenterApiDefinitions();
ApiCenterApiDefinitionData definitionData = new ApiCenterApiDefinitionData
{
Title = "OpenAPI Specification",
Description = "Orders API OpenAPI 3.0 definition"
};
ArmOperation<ApiCenterApiDefinitionResource> operation = await definitions
.CreateOrUpdateAsync(WaitUntil.Completed, "openapi", definitionData);
ApiCenterApiDefinitionResource definition = operation.Value;
// Import specification
string openApiSpec = await File.ReadAllTextAsync("orders-api.yaml");
ApiSpecImportContent importContent = new ApiSpecImportContent
{
Format = ApiSpecImportSourceFormat.Inline,
Value = openApiSpec,
Specification = new ApiSpecImportSpecification
{
Name = "openapi",
Version = "3.0.1"
}
};
await definition.ImportSpecificationAsync(WaitUntil.Completed, importContent);
6. API 仕様をエクスポートする
ApiCenterApiDefinitionResource definition = await client
.GetApiCenterApiDefinitionResource(definitionResourceId)
.GetAsync();
ArmOperation<ApiSpecExportResult> operation = await definition
.ExportSpecificationAsync(WaitUntil.Completed);
ApiSpecExportResult result = operation.Value;
// result.Format - e.g., "inline"
// result.Value - the specification content
7. 環境を作成する
ApiCenterEnvironmentCollection environments = workspace.GetApiCenterEnvironments();
ApiCenterEnvironmentData envData = new ApiCenterEnvironmentData
{
Title = "Production",
Description = "Production environment",
Kind = ApiCenterEnvironmentKind.Production,
Server = new ApiCenterEnvironmentServer
{
ManagementPortalUris = { new Uri("https://portal.azure.com") }
},
Onboarding = new EnvironmentOnboardingModel
{
Instructions = "Contact platform team for access",
DeveloperPortalUris = { new Uri("https://developer.example.com") }
}
};
ArmOperation<ApiCenterEnvironmentResource> operation = await environments
.CreateOrUpdateAsync(WaitUntil.Completed, "production", envData);
8. デプロイを作成する
ApiCenterDeploymentCollection deployments = workspace.GetApiCenterDeployments();
// Get environment resource ID
ResourceIdentifier envResourceId = ApiCenterEnvironmentResource.CreateResourceIdentifier(
subscriptionId, resourceGroupName, serviceName, workspaceName, "production");
// Get API definition resource ID
ResourceIdentifier definitionResourceId = ApiCenterApiDefinitionResource.CreateResourceIdentifier(
subscriptionId, resourceGroupName, serviceName, workspaceName,
"orders-api", "v1-0-0", "openapi");
ApiCenterDeploymentData deploymentData = new ApiCenterDeploymentData
{
Title = "Orders API - Production",
Description = "Production deployment of Orders API v1.0.0",
EnvironmentId = envResourceId,
DefinitionId = definitionResourceId,
State = ApiCenterDeploymentState.Active,
Server = new ApiCenterDeploymentServer
{
RuntimeUris = { new Uri("https://api.example.com/orders") }
}
};
ArmOperation<ApiCenterDeploymentResource> operation = await deployments
.CreateOrUpdateAsync(WaitUntil.Completed, "orders-api-prod", deploymentData);
9. メタデータスキーマを作成する
ApiCenterMetadataSchemaCollection schemas = service.GetApiCenterMetadataSchemas();
string jsonSchema = """
{
"type": "object",
"properties": {
"team": {
"type": "string",
"title": "Owning Team"
},
"costCenter": {
"type": "string",
"title": "Cost Center"
},
"dataClassification": {
"type": "string",
"enum": ["public", "internal", "confidential"],
"title": "Data Classification"
}
},
"required": ["team"]
}
""";
ApiCenterMetadataSchemaData schemaData = new ApiCenterMetadataSchemaData
{
Schema = jsonSchema,
AssignedTo =
{
new MetadataAssignment
{
Entity = MetadataAssignmentEntity.Api,
Required = true
}
}
};
ArmOperation<ApiCenterMetadataSchemaResource> operation = await schemas
.CreateOrUpdateAsync(WaitUntil.Completed, "api-metadata", schemaData);
10. API の一覧表示と検索
// List all APIs in a workspace
ApiCenterWorkspaceResource workspace = await client
.GetApiCenterWorkspaceResource(workspaceResourceId)
.GetAsync();
await foreach (ApiCenterApiResource api in workspace.GetApiCenterApis().GetAllAsync())
{
Console.WriteLine($"API: {api.Data.Title}");
Console.WriteLine($" Kind: {api.Data.Kind}");
Console.WriteLine($" Stage: {api.Data.LifecycleStage}");
// List versions
await foreach (ApiCenterApiVersionResource version in api.GetApiCenterApiVersions().GetAllAsync())
{
Console.WriteLine($" Version: {version.Data.Title}");
}
}
// List environments
await foreach (ApiCenterEnvironmentResource env in workspace.GetApiCenterEnvironments().GetAllAsync())
{
Console.WriteLine($"Environment: {env.Data.Title} ({env.Data.Kind})");
}
// List deployments
await foreach (ApiCenterDeploymentResource deployment in workspace.GetApiCenterDeployments().GetAllAsync())
{
Console.WriteLine($"Deployment: {deployment.Data.Title}");
Console.WriteLine($" State: {deployment.Data.State}");
}
主要な型のリファレンス
| 型 | 用途 |
|---|---|
ApiCenterServiceResource | API Center サービスインスタンス |
ApiCenterWorkspaceResource | API の論理的なグループ |
ApiCenterApiResource | 個別の API |
ApiCenterApiVersionResource | API のバージョン |
ApiCenterApiDefinitionResource | API 仕様(OpenAPI など) |
ApiCenterEnvironmentResource | デプロイ環境 |
ApiCenterDeploymentResource | 環境への API デプロイ |
ApiCenterMetadataSchemaResource | カスタムメタデータスキーマ |
ApiKind | rest、graphql、grpc、soap、webhook、websocket、mcp |
ApiLifecycleStage | design、development、testing、preview、production、deprecated、retired |
ApiCenterEnvironmentKind | development、testing、staging、production |
ApiCenterDeploymentState | active、inactive |
ベストプラクティス
- ワークスペースで整理する — チーム、ドメイン、または製品ごとに API をグループ化します
- メタデータスキーマを使用する — ガバナンスのためのカスタムプロパティを定義します
- ライフサイクル段階を追跡する — API の状態を最新に保ちます(design → production → deprecated)
- 環境を文書化する — オンボーディング手順とポータル URI を含めます
- 一貫したバージョン管理を行う — API バージョンにセマンティックバージョニングを使用します
- 仕様をインポートする — 検出できるように OpenAPI/GraphQL 仕様をアップロードします
- デプロイをリンクする — API を実行環境に接続します
- マネージド ID を使用する — セキュアな統合のために SystemAssigned ID を有効にします
エラー処理
using Azure;
try
{
ArmOperation<ApiCenterApiResource> operation = await apis
.CreateOrUpdateAsync(WaitUntil.Completed, "my-api", apiData);
}
catch (RequestFailedException ex) when (ex.Status == 409)
{
Console.WriteLine("API already exists with conflicting configuration");
}
catch (RequestFailedException ex) when (ex.Status == 400)
{
Console.WriteLine($"Invalid request: {ex.Message}");
}
catch (RequestFailedException ex)
{
Console.WriteLine($"Azure error: {ex.Status} - {ex.Message}");
}
関連 SDK
| SDK | 用途 | インストール |
|---|---|---|
Azure.ResourceManager.ApiCenter | API Center の管理(この SDK) | dotnet add package Azure.ResourceManager.ApiCenter |
Azure.ResourceManager.ApiManagement | API ゲートウェイとポリシー | dotnet add package Azure.ResourceManager.ApiManagement |
リファレンスリンク
使用する場合
このスキルは、概要で説明されているワークフローまたはアクションを実行する場合に適用できます。
制限事項
- このスキルは、タスクが上記の説明範囲に明確に該当する場合にのみ使用してください。
- 出力を、環境固有の検証、テスト、または専門家によるレビューの代わりとして扱わないでください。
- 必要な入力、権限、安全上の境界、または成功基準が不明な場合は、作業を中止して確認してください。
コメント
Markdown 対応