---
schema_version: "1"
id: a15f2c3b9c784227139be84c0d8149fdcb180b8ce09f314bdd1057d701a9d11f
title: ガバナンスルールセットに対する API 仕様の検証
collection: mulesoft
version: current
locale: ja-jp
portal_url: https://docs.salesforce.com/mulesoft/current/ja-jp/anypoint-code-builder/des-govern-api.md
canonical_url: https://docs.mulesoft.com/jp/anypoint-code-builder/des-govern-api
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 34238002a12a81dbc3f84717111cd8b013432eb287c59de4b73b14be00ce3c12
description: MuleSoft Documentation Site
latest: true
---
# ガバナンスルールセットに対する API 仕様の検証

**進行中のベータリリース**​: **クラウド IDE は進行中のベータリリースです**​。ベータ状態での Anypoint Code Builder の使用には、IDE で入手できる、該当するベータサービス契約条件が適用されます。

ガバナンスルールセットのルールに対して Anypoint Code Builder 設計プロジェクトの API 仕様をテストし、結果として生じた準拠の問題を修正します。

ルールセットとガバナンスについての詳細は、​[Anypoint API Governance の概念](https://docs.mulesoft.com/api-governance/#anypoint-api-governance-concepts)​を参照してください。

## [](#prereqs)始める前に

サポートされる仕様を含む API 設計プロジェクトが Anypoint Code Builder にある必要があります。

- [API 仕様の作成およびインポート](https://docs.mulesoft.com/jp/anypoint-code-builder/des-create-api-specs)
- [AsyncAPI 仕様の作成およびインポート](https://docs.mulesoft.com/jp/anypoint-code-builder/des-create-asyncapi-api-specs)

## [](#workflows-tasks)ワークフローとタスク

通常のワークフローは次の 1 つ以上のタスクで構成されます。

1. 1 つ以上のルールセットを API 設計プロジェクトに追加します。
    
    [プロジェクトへのルールセットの追加](#add-rulesets)
2. ルールセットのルールを実行して、API 仕様がルールに準拠するかどうかを確認します。
    
    [API 仕様に対するルールの実行](#run-rules)
3. 仕様内の準拠の問題を修正します。
    
    [準拠の問題の修正](#fix-issues)

## [](#add-rulesets)プロジェクトへのルールセットの追加

ガバナンスルールセットを連動関係として Anypoint Code Builder の API 設計プロジェクトに追加します。

ルールセットは Exchange でホストされています。MuleSoft は多くの公開ルールセットを提供しています。これらのルールセットは Anypoint Code Builder で見つけることができます。また、 [Exchange](https://anypoint.mulesoft.com/exchange/?type=ruleset&show=mulesoft&sort=last&view=grid)​ で直接確認することもできます。たとえば、ルールセット [Anypoint Best Practices (Anypoint ベストプラクティス)](https://anypoint.mulesoft.com/exchange/68ef9520-24e9-4cf2-b2f5-620025690913/anypoint-best-practices/minor/1.6/)​ では、ドキュメントと例が提供されています。チームは組織のルールセットを作成して Exchange にパブリッシュすることもできます ([Creating Custom Governance Rulesets](https://docs.mulesoft.com/api-governance/create-custom-rulesets)を参照)。

1. Anypoint Code Builder で API 設計プロジェクトを開きます。
2. **Explorer**​ からプロジェクトの ​**\[Governance Rulesets (ガバナンスルールセット)\]**​ パネルを開きます。
    
    このパネルが ​**Explorer**​ にない場合、​**Explorer**​ の ​**\[Views and More Actions…​ (ビューおよびその他のアクション…​)\]**​ (​**…​**​) メニューでパネルをアクティブ化します。
3. ルールセットを追加します。
    
    - パネルにルールセットが含まれない場合、​**\[Add Rulesets (ルールセットを追加)\]**​ をクリックします。 次に例を示します。
        
        !["\[Governance Rulesets (ガバナンスルールセット)](/mulesoft/current/ja-jp/anypoint-code-builder/_images/gov-rulesets-add-panel.png) パネル",width=600\]
    - パネルにルールセットが含まれる場合、パネルにマウスポインターを置いて ​![](/mulesoft/current/ja-jp/anypoint-code-builder/_images/icon-gov-ruleset-add.png)​ (​**\[Add Governance Rulesets (ガバナンスルールセットを追加)\]**​) をクリックすると、別のルールセットを追加できます。次に例を示します。
        
        !["\[Add ruleset (ルールセットを追加)](/mulesoft/current/ja-jp/anypoint-code-builder/_images/gov-rulesets-add-panel-not-empty.png) アイコン",width=600\]
4. Anypoint Platform にサインインするように促されたら、サインインします。
5. ルールセットを検索して ​**\[Add Rulesets (ルールセットを追加)\]**​ をクリックします。次に例を示します。
    
    !["\[All Available Rulesets (すべての使用可能なルールセット)](/mulesoft/current/ja-jp/anypoint-code-builder/_images/gov-rulesets-search-add.png)",width=600\]
    
    また、​**\[Any organization (任意の組織)\]**​ メニューから検索を特定の組織に絞り込んだり、複数のバージョンを使用できる場合はルールセットの別のバージョンを選択したりできます。
6. [API 仕様に対するルールの実行](#run-rules)​に進みます。

## [](#トピックとエージェントの中央管理ルールセット)トピックとエージェントの中央管理ルールセット

トピックとエージェントに対して API プロジェクトを有効にすると、​**\[SF API Topic and Action Enablement (SF API トピックとアクションの有効化)\]**​ 中央管理ルールセットがトピック対応 API プロジェクトに自動的に追加されます。

詳細は、​[「トピックとエージェントのガバナンスルールセット」](https://docs.mulesoft.com/jp/anypoint-code-builder/ai-enabling-api-project-topic-center#governance-rulesets)​を参照してください。

## [](#run-rules)API 仕様に対するルールの実行

API 仕様がガバナンスルールセットのルールに準拠するかどうかを確認します。

1. Anypoint Code Builder で API 設計プロジェクトを開きます。
2. **Explorer**​ から ​**\[Governance Rulesets (ガバナンスルールセット)\]**​ パネルを開き、プロジェクトにルールセットがあるかどうかを確認します。
    
    - ルールセットが存在し、他のルールセットを追加しない場合は、次のステップに進みます。
        
        !["\[Add ruleset (ルールセットを追加)](/mulesoft/current/ja-jp/anypoint-code-builder/_images/gov-rulesets-add-panel-not-empty.png) アイコン",width=500\]
    - ルールセットが存在しない場合、または他のルールセットを追加する場合は、​[プロジェクトへのルールセットの追加](#add-rulesets)​に進みます。
        
        !["\[Governance Rulesets (ガバナンスルールセット)](/mulesoft/current/ja-jp/anypoint-code-builder/_images/gov-rulesets-add-panel.png) パネル",width=500\]
3. **\[Governance Rulesets (ガバナンスルールセット)\]**​ パネルからルールを実行します。
    
    ルールセットは複数のレベルで実行できます。
    
    - すべてのルールセットのすべてのルール
        
        ![すべてのルールセットを実行するアイコンのクリック](/mulesoft/current/ja-jp/anypoint-code-builder/_images/gov-rulesets-run-all.png)
    - 1 つのルールセットのすべてのルール
        
        ![1 つのルールセットを実行するアイコンのクリック](/mulesoft/current/ja-jp/anypoint-code-builder/_images/gov-rulesets-run-ruleset.png)
    - 1 つのルールセットの 1 つのルール
        
        ![1 つのルールを実行するアイコンのクリック](/mulesoft/current/ja-jp/anypoint-code-builder/_images/gov-rulesets-run-rule.png)
        
        ルールが実行されているときにルールを監視できます。次に例を示します。
        
        ![パネルに表示されている実行中のルール](/mulesoft/current/ja-jp/anypoint-code-builder/_images/gov-rulesets-running.png)
4. いずれかのルールでエラー (​![](/mulesoft/current/ja-jp/anypoint-code-builder/_images/icon-gov-rule-error.png)​) または警告 (​![](/mulesoft/current/ja-jp/anypoint-code-builder/_images/icon-gov-rule-warning.png)​) が返された場合、​[準拠の問題の修正](#fix-issues)​に進みます。
    
    たとえば、次のルールセットでは、いくつかのルールで警告が返されています。
    
    ![API ガバナンスパネルに表示されている警告を含むルールセット](/mulesoft/current/ja-jp/anypoint-code-builder/_images/gov-rulesets-warning.png)
    
    ルールセットに表示されている実行時間 (19.25 秒など) は各ルールの実行に要した時間の合計を表します。ルールは複数コアのマシンで並列実行されるため、ルールセットに表示されている実行時間は、実行完了までの実際の時間よりも長くなっている可能性があります。
    
    **\[Governance Results (ガバナンス結果)\]**​ パネルでも警告またはエラーが特定されます。次に例を示します。
    
    !["\[Governance Results (ガバナンス結果)](/mulesoft/current/ja-jp/anypoint-code-builder/_images/gov-rulesets-warning-output.png) パネルに表示されている警告を含むルールセット",width=700\]

## [](#fix-issues)準拠の問題の修正

エラーや警告を返すルールに対処するには、ルールに準拠するように仕様を修正します。その後、ルールを再実行して修正が有効であることを確認します。

### [](#example)例

問題に対処するプロセスを説明するために、この手順の例は RAML 仕様の一部といくつかのルールセットから始まっています。

![HTTPs ルールの再実行](/mulesoft/current/ja-jp/anypoint-code-builder/_images/gov-example-prefix.png)

完全な例

- 仕様には次のマークアップが含まれます。
    
    ```yaml
    #%RAML 1.0
    title: my-des-with-governance
    protocols:
      - HTTP
    ```
- 仕様の設計プロジェクトでは次のルールセットが適用されます。
    
    - HTTPS 適用
    - Anypoint ベストプラクティス

### [](#fix-conformance-issues)準拠の問題の修正

エラー (​![](/mulesoft/current/ja-jp/anypoint-code-builder/_images/icon-gov-rule-error.png)​) および警告 (​![](/mulesoft/current/ja-jp/anypoint-code-builder/_images/icon-gov-rule-warning.png)​) を修正する手順は、次のとおりです。

1. プロジェクトでルールセットを実行します。
    
    案内については、​[API 仕様に対するルールの実行](#run-rules)​を参照してください。
2. 発生したエラーおよび警告を ​**\[Governance Results (ガバナンス結果)\]**​ パネルで確認します。次に例を示します。
    
    ![ガバナンスルールセット内のエラーおよび警告](/mulesoft/current/ja-jp/anypoint-code-builder/_images/gov-example-postrun-issues.png)
    
    **\[Governance Results (ガバナンス結果)\]**​ に、対応する問題がリストされています。次に例を示します。
    
    ![ガバナンス結果内のエラーおよび警告](/mulesoft/current/ja-jp/anypoint-code-builder/_images/gov-example-postrun-issues-output.png)
    
    - `Error: [HTTPS Enforcement] Only use https protocol scheme (エラー: [HTTPS 適用] HTTPS プロトコルスキームのみを使用してください)。`
    - `Warning: [Anypoint Best Practices] Provide the documentation for the API (警告: [Anypoint ベストプラクティス] API のドキュメントを指定してください)。`
    - `Warning: [Anypoint Best Practices] Provide the description for the API (警告: [Anypoint ベストプラクティス] API の説明を指定してください)。`
3. 仕様内のエラーに対処します。
    
    たとえば、​`HTTP`​ を ​`HTTPS`​ に変更することで​[仕様例](#example)​の ​**HTTPS 適用**​エラーを修正します。
    
    ```yaml
    #%RAML 1.0
    title: my-des-with-governance
    protocols:
      - HTTPS
    ```
4. 失敗したルールを再実行してエラーが修正されたことを確認します。
    
    たとえば、​[仕様例](#example)​の ​`protocols`​ エラーを修正したら、​**\[Governance Rulesets (ガバナンスルールセット)\]**​ パネルから ​**use-https-for-scheme-protocol**​ を実行します。次に例を示します。
    
    ![HTTPs ルールの再実行](/mulesoft/current/ja-jp/anypoint-code-builder/_images/gov-example-run-fixed-error-https.png)
    
    **\[Governance Rulesets (ガバナンスルールセット)\]**​ にエラーが表示されなくなったことを確認します。次に例を示します。
    
    ![修正された HTTPs ルール](/mulesoft/current/ja-jp/anypoint-code-builder/_images/gov-example-error-fixed-https.png)
    
    また、​**\[Governance Results (ガバナンス結果)\]**​ パネルに問題がリストされなくなります。
5. 必要に応じて、警告に対処します。
    
    次に例を示します。
    
    1. [仕様例](#example)​に ​`description`​ を追加することで、警告​`「Provide the description for the API (API の説明を指定してください)」`​に対処します。次に例を示します。
        
        ```yaml
        #%RAML 1.0
        title: my-des-with-governance
        description: my description
        protocols:
          - HTTPS
        ```
        
        description は ​`title`​ と ​`protocols`​ の間にあります。
    2. ルール ​**api-must-have-description**​ を再実行して、仕様がルールに準拠するようになったことを確認します。
        
        ![修正された説明](/mulesoft/current/ja-jp/anypoint-code-builder/_images/gov-example-warning-fixed-description.png)
        
        ルールセットの別のルールに警告があるため、ルールセットでは引き続き警告が特定されています。
6. 修正する必要がある残りの問題に対処します。
    
    たとえば、​[例](#example)​の警告​`「Provide the documentation for the API (API のドキュメントを指定してください)」`​の場合、​`documentation`​ マークアップを仕様に追加して保存します。
    
    ```yaml
    #%RAML 1.0
    title: my-des-with-governance
    description: my description
    documentation:
      - title:  My Title
        content: |
          Welcome to my API documentation.
      - title: Legal
        content: |
          This is my legal documentation.
    protocols:
      - HTTPS
    ```
7. **\[Governance Rulesets (ガバナンスルールセット)\]**​ パネルで対応するルールを再実行します。
    
    たとえば、​**api-must-have-documentation**​ を再実行して、仕様がルールに準拠するようになったことを確認します。
    
    ![修正されたドキュメント](/mulesoft/current/ja-jp/anypoint-code-builder/_images/gov-example-warning-fixed-all.png)

仕様のエラーまたは警告がなくなりました。次に例を示します。

![ルールセット検証を表示しているパネル](/mulesoft/current/ja-jp/anypoint-code-builder/_images/gov-example-error-fixed-all.png)

## [](#ruleset-remove)プロジェクトからのルールセットの削除

1. **\[Governance Ruleset (ガバナンスルールセット)\]**​ パネルでルールセットにマウスポインターを置くと、​**\[More actions (その他のアクション)\]**​ (​**…​**​) メニューが表示されます。
2. **\[More actions (その他のアクション)\]**​ メニューで ​**\[Remove Ruleset…​ (ルールセットを削除…​)\]**​ をクリックします。

また、この目的ではコマンドパレットからコマンド ​**MuleSoft: Remove Governance Ruleset…​**​ を使用することもできます。

## [](#ruleset-yaml)ルールセット YAML ファイルを開く

ルールセットの YAML ファイルの設定を調べる手順は、次のとおりです。

1. **\[Governance Ruleset (ガバナンスルールセット)\]**​ パネルでルールセットにマウスポインターを置くと、​**\[More actions (その他のアクション)\]**​ (​**…​**​) メニューが表示されます。
2. **\[Show in Files (ファイルで表示)\]**​ をクリックすると、YAML ファイルが IDE の ​**\[ruleset.yaml\]**​ タブで開きます。

次の例は、HTTPS 適用 YAML ファイルのバージョン 1.6.1 を示しています。

```YAML
#%Validation Profile 1.0
profile: HTTPS enforcement
description: This ruleset helps ensure the use of HTTPS across URLs in API
  definitions, both in the base server URL and in any callbacks optionally
  defined.
violation:
  - use-https-for-callbacks
  - use-https-for-scheme-protocol
  - use-https-for-urls
tags:
  - security
validations:
  use-https-for-callbacks:
    message: "{{apiContract.expression}} must use https as it is a callback url"
    targetClass: apiContract.Callback
    propertyConstraints:
      apiContract.expression:
        pattern: ^https://
    examples:
      valid: |
        openapi: "3.0.0"
        info:
          title: example API
          version: "1.0.0"
        paths:
          /subscribe:
            post:
              responses:
                '201':
                  description: Webhook created
              callbacks:
                myEvent:
                  'https://{$request.body#/callbackUrl}'
      invalid: |
        openapi: "3.0.0"
        info:
          title: example API
          version: "1.0.0"
        paths:
          /subscribe:
            post:
              responses:
                '201':
                  description: Webhook created
              callbacks:
                myEvent:
                  'http://{$request.body#/callbackUrl}'
  use-https-for-scheme-protocol:
    message: Only use https protocol scheme
    targetClass: apiContract.WebAPI
    not:
      propertyConstraints:
        apiContract.scheme:
          containsSome:
            - HTTP
            - http
    examples:
      valid: |
        #%RAML 1.0
        protocols:
          - HTTPS
      invalid: |
        #%RAML 1.0
        protocols:
          - HTTP
  use-https-for-urls:
    message: "{{core.urlTemplate}} should use https"
    targetClass: apiContract.Server
    propertyConstraints:
      core.urlTemplate:
        pattern: ^https://
    examples:
      valid: |
        openapi: "3.0.0"
        servers:
          - url: "https://mySecureEndpoint"
            description: "My endpoint that uses HTTPS"
      invalid: |
        openapi: "3.0.0"
        servers:
          - url: "http://myNotSoSecureEndpoint"
            description: "My endpoint that uses HTTP"
```

## [](#ruleset-exchange)Exchange でルールセットを開く

Exchange ではルールセットにすべてのルールがリストされます。また、例を含むドキュメントが提供されている場合があります。

Exchange でルールセットを開く手順は、次のとおりです。

1. **\[Governance Ruleset (ガバナンスルールセット)\]**​ パネルでルールセットにマウスポインターを置くと、​**\[More actions (その他のアクション)\]**​ (​**…​**​) メニューが表示されます。
2. **\[Open in Exchange (Exchange で開く)\]**​ をクリックします。

## [](#ruleset-version)ルールセットバージョンの変更

ルールセットの別のバージョンを選択する手順は、次のとおりです。

1. **\[Governance Ruleset (ガバナンスルールセット)\]**​ パネルでルールセットにマウスポインターを置くと、​**\[More actions (その他のアクション)\]**​ (​**…​**​) メニューが表示されます。
2. **\[Change Version…​ (バージョンを変更…​)\]**​ をクリックします。
3. 開いた ​**\[Change Version (バージョンを変更)\]**​ メニューから別のバージョンを選択します。