擷取規則清單

規則是使用規則集群組在一起。 規則可以不在任何規則集中,也可以在多個規則集中。 透過呼叫 API GET,使用 [Geographical URI]/api/rule 要求來取得所有可用規則的清單、規則集中的規則或是規則集。 有幾種不同的方法可以呼叫此 API,但是最常見的使用方式是擷取特定規則集的規則清單。

注意

此 API 確實需要令 OAuth 牌。

標頭

姓名 類型 預期值 是必要的嗎?
Accept-Language 字串 語言代碼 (例如 en-US)。 預設值為 en-US。 否

參數

姓名 類型 預期值 是必要的嗎?
規則集 字串 規則集的名稱或識別碼或是規則集識別碼識別碼的清單,或者以逗號或分號分隔的名稱 (例如「解決方案檢查工具」)。 否
includeMessageFormats bool 設定為 true 時,可能的訊息變化清單會包含在語言要求的結果中 (如果有的話)。 此清單對翻譯成多種語言很有幫助。 如果不需要,則不要提供此參數,或者提供 false 的值,因為此參數會增加回應的大小,並且可能加長處理時間。 否

預期回應

HTTP 狀態碼 案例 Result
200 已找到一個或多個結果 請參閱本文後面的範例。 可能會傳回一個或多個結果。
204 找不到結果 回應本文中沒有任何結果。
401 驗證失敗 回應本文中沒有任何結果。

預期回應本文

下表概述每個要求的回應結構 (僅限 HTTP 200 回應)。

屬性 類型 預期值 是必要的嗎?
字碼 字串 規則的識別碼,有時稱為規則 ID。 是
摘要 字串 規則的摘要。 是
description 字串 規則集更詳細的描述。 是
guidanceUrl URI 藉以尋找已發佈指引的 URL。 在某些情況下,沒有專屬的支援指引文章。 是
包括 boolean 向服務表示要在分析中包括規則。 對於此 API,該值為 true。 否
messageTemplates 陣列 只有在 includeMessageFormats 為 true 時,才會包含此屬性值。 否
messageTemplates.ruleId 字串 傳回與 code 屬性相同的識別碼值。 是
messageTemplates.messageTemplateId 字串 靜態分析結果交換格式 (SARIF) 報表中使用的識別碼,表示規則的問題訊息變化。 是
messageTemplates.messageTemplate 字串 規則所回報問題案例的訊息變化文字。 此文字是格式字串,其中可能會包含 SARIF 報表所提供之引數可用於建構詳細訊息的代用文字。 是

範例:以其他語言擷取規則集的規則

此範例會以法文語言傳回解決方案檢查工具規則集中所有規則的資料。 如果想要的語言是英文,只需移除 Accept-Language 標頭即可。

請求

GET [Geographical URI]/api/rule?ruleset=083A2EF5-7E0E-4754-9D88-9455142DC08B&api-version=2.0
x-ms-correlation-id: aaaa0000-bb11-2222-33cc-444444dddddd
Accept: application/json
Content-Type: application/json; charset=utf-8
Accept-Language: fr

回應

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8

[
    {
        "description": "Ne pas implémenter d’activités de workflow Microsoft Dynamics CRM 4.0",
        "guidanceUrl": "https://go.microsoft.com/fwlink/?LinkID=398563&error=il-avoid-crm4-wf&client=PAChecker",
        "include": true,
        "code": "il-avoid-crm4-wf",
        "summary": "Ne pas implémenter d’activités de workflow Microsoft Dynamics CRM 4.0",
        "howToFix": {
            "summary": ""
        }
    },
    {
        "description": "Utiliser InvalidPluginExecutionException dans des plug-ins et activités de workflow",
        "guidanceUrl": "https://go.microsoft.com/fwlink/?LinkID=398563&error=il-use-standard-exception&client=PAChecker",
        "include": true,
        "code": "il-use-standard-exception",
        "summary": "Utiliser InvalidPluginExecutionException dans des plug-ins et activités de workflow",
        "howToFix": {
            "summary": ""
        }
    },
...
]

範例:全部擷取

此範例傳回所有想要可用規則的資料。

請求

GET [Geographical URI]/api/rule?api-version=2.0
Accept: application/json
Content-Type: application/json; charset=utf-8

回應

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8

[
    {
        "description": "Retrieve specific columns for an entity via query APIs",
        "guidanceUrl": "https://go.microsoft.com/fwlink/?LinkID=398563&error=il-specify-column&client=PAChecker",
        "include": true,
        "code": "il-specify-column",
        "summary": "Retrieve specific columns for an entity via query APIs",
        "howToFix": {
            "summary": ""
        }
    },
    {
        "description": "Do not duplicate plug-in step registration",
        "guidanceUrl": "https://go.microsoft.com/fwlink/?LinkID=398563&error=meta-remove-dup-reg&client=PAChecker",
        "include": true,
        "code": "meta-remove-dup-reg",
        "summary": "Do not duplicate plug-in step registration",
        "howToFix": {
            "summary": ""
        }
    },
...
]

範例:擷取包含訊息格式的規則集

此範例會以法文語言傳回解決方案檢查工具規則集中所有規則的資料。 如果想要的語言是英文,只需移除 Accept-Language 標頭即可。

請求

GET [Geographical URI]/api/rule?ruleset=083A2EF5-7E0E-4754-9D88-9455142DC08B&includeMessageFormats=true&api-version=2.0
Accept: application/json
Content-Type: application/json; charset=utf-8

回應

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8

[
    {
        "description": "Do not implement Microsoft Dynamics CRM 4.0 workflow activities",
        "guidanceUrl": "https://go.microsoft.com/fwlink/?LinkID=398563&error=il-avoid-crm4-wf&client=PAChecker",
        "include": true,
        "code": "il-avoid-crm4-wf",
        "summary": "Do not implement Microsoft Dynamics CRM 4.0 workflow activities",
        "howToFix": {
            "summary": ""
        },
        "messageTemplates": [
            {
                "ruleId": "il-avoid-crm4-wf",
                "messageTemplateId": "message1",
                "messageTemplate": "Update the {0} class to derive from System.Workflow.Activities.CodeActivity, refactor Execute method implementation, and remove Microsoft.Crm.Workflow.CrmWorkflowActivityAttribute from type"
            },
            {
                "ruleId": "il-avoid-crm4-wf",
                "messageTemplateId": "message2",
                "messageTemplate": "Change the {0} property's type from {1} to {2} Argument <T> type"
            },
            {
                "ruleId": "il-avoid-crm4-wf",
                "messageTemplateId": "message3",
                "messageTemplate": "Replace the Microsoft.Crm.Workflow.Crm{0}Attribute with Microsoft.Xrm.Sdk.Workflow.{0}Attribute"
            },
            {
                "ruleId": "il-avoid-crm4-wf",
                "messageTemplateId": "message4",
                "messageTemplate": "Remove the {0} System.Workflow.ComponentModel.DependencyProperty type field"
            }
        ]
    },
    {
        "description": "Use InvalidPluginExecutionException in plug-ins and workflow activities",
        "guidanceUrl": "https://go.microsoft.com/fwlink/?LinkID=398563&error=il-use-standard-exception&client=PAChecker",
        "include": true,
        "code": "il-use-standard-exception",
        "summary": "Use InvalidPluginExecutionException in plug-ins and workflow activities",
        "howToFix": {
            "summary": ""
        },
        "messageTemplates": [
            {
                "ruleId": "il-use-standard-exception",
                "messageTemplateId": "message1",
                "messageTemplate": "An unguarded throw of type {0} was detected. Refactor this code to either throw an exception of type InvalidPluginExecutionException or guard against thrown exceptions of other types."
            },
            {
                "ruleId": "il-use-standard-exception",
                "messageTemplateId": "message2",
                "messageTemplate": "An unguarded rethrow of type {0} was detected. Refactor this code to either throw an exception of type InvalidPluginExecutionException or guard against thrown exceptions of other types."
            }
        ]
    },
...
]

請參閱

使用 Power Apps 檢查器 Web API
擷取規則集清單
上傳檔案
叫用分析
檢查分析狀態