检索规则列表

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

备注

此 API 不需要 OAuth 令牌。

标题

客户 类型​​ 预期值 是否为必填?
Accept-Language string 语言代码(例如 en-US)。 默认值为 en-US。

参数设置

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

预期响应

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

预期响应正文

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

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

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

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

请求

GET [Geographical URI]/api/rule?ruleset=083A2EF5-7E0E-4754-9D88-9455142DC08B&api-version=2.0
x-ms-correlation-id: 9E378E56-6F35-41E9-BF8B-C0CC88E2B832
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": ""
        }
    },
...
]

示例:全部检索

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

请求

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

请求

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