Obtaining Rules
Function
This API is used to query the rules based on conditions such as language and issue severity.
Calling Method
For details, see Calling APIs.
URI
GET /v2/rules
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
rule_languages |
No |
String |
Definition Rule language. Constraints Must be a language supported by the current environment. Range Only one language can be passed. Supported languages include: ArkTS, C#, C++, CSS, Go, HTML, Java, JavaScript, Kotlin, Lua, PHP, Python, Rust, Scala, Shell, SQL, and TypeScript. Default Value N/A |
rule_severity |
No |
String |
Definition Issue severity. Constraints N/A Range
Default Value 0,1,2,3. By default, issues of all severity levels are queried. |
offset |
No |
Integer |
Definition Offset for pagination. Constraints N/A Range 0–999 Default Value 0 |
limit |
No |
Integer |
Definition Number of records displayed on each page. Constraints N/A Range 0–200 Default Value 100 |
Request Parameters
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
X-Auth-Token |
Yes |
String |
Definition User token. Obtain a token by calling the IAM API forobtaining a user token. The value of X-Subject-Token in the response header is the user token. Constraints N/A Range 1–100,000 characters Default Value N/A |
Response Parameters
Status code: 200
Parameter |
Type |
Description |
---|---|---|
info |
Array of RuleListItem objects |
Definition Rule information. Range N/A |
total |
Integer |
Definition Total number. Range N/A |
Parameter |
Type |
Description |
---|---|---|
rule_set |
String |
Definition Rule standard type. Range The options include: common, common_standard_recommend, common_standard_rule, design_smells, security, security_standard_recommend, and security_standard_rule. |
rule_id |
String |
Definition Rule ID. Range 32-character UUID. |
rule_language |
String |
Definition Rule language. Range Supported languages include: ArkTS, C#, C++, CSS, Go, HTML, Java, JavaScript, Kotlin, Lua, PHP, Python, Rust, Scala, Shell, SQL, and TypeScript. |
rule_name |
String |
Definition Rule name. Range N/A |
rule_severity |
String |
Definition Issue severity. Range
|
rule_tages |
String |
Definition Rule tag. Range The options include huawei, iso5055, cert, cwe, top10, top25, misra, GJB, autosar, and PCI DSS. |
right_example |
String |
Definition Compliant example. Range Code block or text example. |
error_example |
String |
Definition Noncompliant example. Range Code block or text example. |
revise_opinion |
String |
Definition Fix suggestion. Range Code block or text example. |
rule_desc |
String |
Definition Rule description. Range N/A |
Status code: 400
Parameter |
Type |
Description |
---|---|---|
error_code |
String |
Error code. |
error_msg |
String |
Error message. |
Status code: 401
Parameter |
Type |
Description |
---|---|---|
error_code |
String |
Error code. |
error_msg |
String |
Error message. |
Example Requests
GET https://{endpoint}/v2/rules
Example Responses
Status code: 200
Request succeeded!
{ "info" : [ { "rule_id" : "2561", "rule_language" : "Java", "rule_name" : "\"=+\" cannot be replaced by \"+=\".", "rule_severity" : "1", "rule_tages" : "bug", "rule_desc" : "<p>Use strict equality operator (<code>===</code>) to compare different types. The result is always <code>false</code>. </p>", "right_example" : "<pre>\nvar a = 8;\nvar b = \"8\";\n\nif (a == b) {\n // ...\n}\n</pre>\n<p>or</p>\n<pre>\nvar a = 8;\nvar b = \"8\";\n\nif (a === Number(b)) {\n // ...\n}\n</pre>", "error_example" : "<pre>\nvar a = 8;\nvar b = \"8\";\n\nif (a === b) { //Noncompliant, always false\n // ...\n}\n</pre>", "revise_opinion" : "None", "rule_set" : "common" }, { "rule_id" : "8048", "rule_language" : "Java", "rule_name" : "\"Arrays.stream\" should be used for primitive arrays", "rule_severity" : "1", "rule_tages" : "performance", "rule_desc" : "<p>Use strict equality operator (<code>===</code>) to compare different types. The result is always <code>false</code>. </p>", "right_example" : "<pre>\nvar a = 8;\nvar b = \"8\";\n\nif (a == b) {\n // ...\n}\n</pre>\n<p>or</p>\n<pre>\nvar a = 8;\nvar b = \"8\";\n\nif (a === Number(b)) {\n // ...\n}\n</pre>", "error_example" : "<pre>\nvar a = 8;\nvar b = \"8\";\n\nif (a === b) { //Noncompliant, always false\n // ...\n}\n</pre>", "revise_opinion" : "None", "rule_set" : "common" } ], "total" : 2 }
Status code: 400
Bad Request
{ "error_code" : "CC.00000000", "error_msg" : "Network busy. Try again later." }
Status code: 401
Unauthorized
{ "error_code" : "CC.00000003", "error_msg" : "Authentication information expired." }
Status Codes
Status Code |
Description |
---|---|
200 |
Request succeeded! |
400 |
Bad Request |
401 |
Unauthorized |
Error Codes
See Error Codes.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot