检索规则列表

规则使用规则集组合在一起。 规则可以不属于规则集,也可以属于多个规则集。 使用 GET 请求通过调用 API [Geographical URI]/api/rule 获取所有可用规则、规则集中的规则或规则集的列表。 有一些变体可用于调用此 API,但是,最常用的用法是检索特定规则集的规则的列表。

备注

此 API 确实需要令 OAuth 牌。

标题

客户 类型 预期值 是否需要?
Accept-Language 字符串 语言代码(例如 en-US)。 默认值为 en-US。 否

参数设置

客户 类型 预期值 是否需要?
ruleset 字符串 规则集的名称或 ID 或规则集 ID 列表,或者用逗号或分号分隔的名称(例如“解决方案检查器”)。 否
includeMessageFormats bool 如果设置为 true,则语言请求(如果有)的结果中包含可用消息变体的列表。 此列表对于翻译成多种语言非常有用。 如果不需要,则不要提供此参数或提供 false 作为值,因为此参数会增加响应的大小并增加处理时间。 否

预期响应

HTTP 状态代码 场景 结果
200 找到了一个或多个结果 请参阅本文后面的示例。 可以返回一项或多项结果。
204 未找到任何结果 响应正文中无结果。
401 身份验证失败 响应正文中无结果。

预期响应正文

下表概述每个请求的响应(仅限 HTTP 200 响应)的结构。

属性 类型 预期值 是否需要?
代码 字符串 规则的标识符,有时称为“规则 ID”。 是
摘要 字符串 规则摘要。 是
description 字符串 更详细的规则描述。 是
guidanceUrl URI 要在其中查找发布的指导的 URL。 可能在某些情况下没有专门的支持性指导文章。 是
包括 boolean 发给服务并说明分析中要包含规则的信号。 对于此 API,该值为 true。 否
messageTemplates 数组 仅当 includeMessageFormats 为 true 时,才包含此属性值。 否
messageTemplates.ruleId 字符串 与 code 属性返回相同的 ID 值。 是
messageTemplates.messageTemplateId 字符串 静态分析结果交换格式 (SARIF) 报表中用于发出规则的消息变体信号的标识符。 是
messageTemplates.messageTemplate 字符串 规则报告的问题方案的消息变体的文本。 该文本是一个格式字符串,其中可能包含一些标记,SARIF 报告中提供的参数可用于构建详细的消息。 是

示例:检索另一种语言的规则集的规则

此示例返回法语的解决方案检查器规则集中所有规则的数据。 如果所需语言为英语,则仅删除 Accept-Language 标头。

Request

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

Response

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": ""
        }
    },
...
]

示例:全部检索

此示例返回所有可用规则的数据。

Request

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

Response

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 标头。

Request

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

Response

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
检索规则集列表
上载文件
调用分析
检查分析状态