From 527b486885ac5c2897b4b435f78655124ee2ac20 Mon Sep 17 00:00:00 2001 From: jianyexi Date: Wed, 9 Nov 2022 17:33:36 +0800 Subject: [PATCH 1/5] update doc files --- docs/rules.md | 98 ++++++++++--------- ...ubscriptions-and-resource-group-casing.md} | 0 ...es.md => un-supported-patch-properties.md} | 0 3 files changed, 53 insertions(+), 45 deletions(-) rename docs/{subscriptions-and-resourcegroup-casing.md => subscriptions-and-resource-group-casing.md} (100%) rename docs/{unsupported-patch-properties.md => un-supported-patch-properties.md} (100%) diff --git a/docs/rules.md b/docs/rules.md index 7dd4ba390..e24376fa2 100644 --- a/docs/rules.md +++ b/docs/rules.md @@ -56,14 +56,13 @@ Please refer to [api-version-parameter-required.md](./api-version-parameter-requ ### APIVersionPattern -The API Version parameter MUST be in the Year-Month-Date format (i.e. 2016-07-04.) NOTE that this is the en-US ordering of month and date. +The API Version parameter MUST be in the Year-Month-Date format (i.e. 2016-07-04.) NOTE that this is the en-US ordering of month and date. The date MAY optionally be followed by one of: - -- -preview - Indicates the API version is in (public) preview -- -alpha -- -beta -- -rc (release candidate) -- -privatepreview +* -preview - Indicates the API version is in (public) preview +* -alpha +* -beta +* -rc (release candidate) +* -privatepreview Please refer to [api-version-pattern.md](./api-version-pattern.md) for details. @@ -173,6 +172,12 @@ The default error response schema SHOULD correspond to the schema documented at Please refer to [default-error-response-schema.md](./default-error-response-schema.md) for details. +### DefaultInEnum + +This rule applies when the default value specified by the property does not appear in the enum constraint for a schema. + +Please refer to [default-in-enum.md](./default-in-enum.md) for details. + ### DefaultMustBeInEnum The value assigned as a default for an enum property must be present in the enums' list. @@ -188,10 +193,10 @@ Please refer to [default-response.md](./default-response.md) for details. ### DefinitionsPropertiesNamesCamelCase Property names must use lowerCamelCase style. -If the property is a single word (ex: foo, bar, etc.) it will be all lowercase. -Two-letter acronyms (ex: ID, IO, IP, etc.) should be capitalized. -Three-letter acronyms (ex: API, URL, etc.) should only have the first letter capitalized (ex: Api, Url, etc.) -For more capitalization guidance, see: [https://msdn.microsoft.com/en-us/library/141e06ef(v=vs.71).aspx]() +If the property is a single word (ex: foo, bar, etc.) it will be all lowercase. +Two-letter acronyms (ex: ID, IO, IP, etc.) should be capitalized. +Three-letter acronyms (ex: API, URL, etc.) should only have the first letter capitalized (ex: Api, Url, etc.) +For more capitalization guidance, see: [https://msdn.microsoft.com/en-us/library/141e06ef(v=vs.71).aspx](https://msdn.microsoft.com/en-us/library/141e06ef(v=vs.71).aspx) Please refer to [definitions-properties-names-camel-case.md](./definitions-properties-names-camel-case.md) for details. @@ -344,7 +349,6 @@ Please refer to [header-disallowed.md](./header-disallowed.md) for details. ### HostParametersValidation This is to validate if parameters in the 'x-ms-parameterized-host' follow the following rules:: - 1. If a parameter matches belows, therefore it must be called 'endpoint' and be typed 'type:string, format:url'. - Client level (x-ms-parameter-location: client) - A path component (in: path) @@ -423,6 +427,13 @@ Please refer to [long-running-operations-with-long-running-extension.md](./long- For ARM spec, the allowed response status codes for a long DELETE operation are "200" & "204"; the allowed response status codes for a POST operation are "200", "201" ,"202", & "204"; the allowed response status codes for a PUT/PATCH operation are "200" & "201". For Data plane spec, the allowed response status codes for a long DELETE operation are "200","202", & "204"; the allowed response status codes for a POST operation are "200", "201" ,"202", & "204"; the allowed response status codes for a PUT/PATCH operation are "200","201", & "202". +Please refer to [long-running-response-status-code-data-plane.md](./long-running-response-status-code-data-plane.md) for details. + +### LongRunningResponseStatusCode + +For ARM spec, the allowed response status codes for a long DELETE operation are "200" & "204"; the allowed response status codes for a POST operation are "200", "201" ,"202", & "204"; the allowed response status codes for a PUT/PATCH operation are "200" & "201". +For Data plane spec, the allowed response status codes for a long DELETE operation are "200","202", & "204"; the allowed response status codes for a POST operation are "200", "201" ,"202", & "204"; the allowed response status codes for a PUT/PATCH operation are "200","201", & "202". + Please refer to [long-running-response-status-code.md](./long-running-response-status-code.md) for details. ### LroExtension @@ -681,7 +692,7 @@ Please refer to [patch-sku-property.md](./patch-sku-property.md) for details. ### PathCharacters Path should contain only recommended characters. -The recommended characters are 0-9, A-Z, a-z, -, ., \_, ~, and :. +The recommended characters are 0-9, A-Z, a-z, -, ., _, ~, and :. Please refer to [path-characters.md](./path-characters.md) for details. @@ -695,7 +706,6 @@ Please refer to [path-contains-resource-group.md](./path-contains-resource-group Per ARM RPC,Uri for resource CRUD methods MUST contain a resource type. Uri path starts with \/providers/\/\ format, where - - \ is one of: 1. Tenant/Global: '/' 2. Subscription: "/subscriptions/{subscriptionId}" @@ -771,7 +781,7 @@ Using post for a create operation is discouraged. Please refer to [post-201-response.md](./post-201-response.md) for details. -### PostLongRunningOperation202Only +### PostOperationAsyncResponseValidation An async POST operation response include status code 202 with 'Location' header. Must support status code 200 if operation can be completed synchronously. Operation must also add "x-ms-long-running-operation and x-ms-long-running-operation-options" to mark that it is a long running operation (in case of 202) and how it is tracked (Location header). @@ -792,7 +802,6 @@ Please refer to [preview-version-over-one-year.md](./preview-version-over-one-ye ### PrivateEndpointResourceSchemaValidation This rule is to check if the schemas used by private endpoint conform to the common [privateLink](https://github.com/Azure/azure-rest-api-specs/blob/main/specification/common-types/resource-management/v1/privatelinks.json). The rule will check the schemas of following models and their properties: - 1. PrivateEndpointConnection 2. PrivateEndpointConnectionProperties 3. PrivateEndpointConnectionListResult @@ -930,34 +939,34 @@ Every schema should specify a well-defined combination of `type` and `format`. and not allowed for any other types. The well-defined type/format combinations are: **type: integer** -| format | description | comments | +| format | description | comments | | -------- | --------------- | ------------------------- | -| int32 | signed 32 bits | from [oas2][oas2] | -| int64 | signed 64 bits | from [oas2][oas2] | +| int32 | signed 32 bits | from [oas2][oas2] | +| int64 | signed 64 bits | from [oas2][oas2] | | unixtime | Unix time stamp | from [autorest][autorest] | **type: number** -| format | description | comments | +| format | description | comments | | ------- | ---------------------- | ------------------------- | -| float | 32 bit floating point | from [oas2][oas2] | -| int64 | 64 bit floating point | from [oas2][oas2] | +| float | 32 bit floating point | from [oas2][oas2] | +| int64 | 64 bit floating point | from [oas2][oas2] | | decimal | 128 bit floating point | from [autorest][autorest] | **type: string** -| format | description | comments | +| format | description | comments | | ----------------- | ---------------------------- | ------------------------- | -| byte | base64 encoded characters | from [oas2][oas2] | -| binary | any sequence of octets | from [oas2][oas2] | -| date | [RFC3339][rfc3339] full-date | from [oas2][oas2] | -| date-time | [RFC3339][rfc3339] date-time | from [oas2][oas2] | -| password | sensitive value | from [oas2][oas2] | -| char | | from [autorest][autorest] | -| time | | from [autorest][autorest] | -| date-time-rfc1123 | | from [autorest][autorest] | -| duration | | from [autorest][autorest] | -| uuid | | from [autorest][autorest] | -| base64url | | from [autorest][autorest] | -| url | | from [autorest][autorest] | -| odata-query | | from [autorest][autorest] | -| certificate | | from [autorest][autorest] | +| byte | base64 encoded characters | from [oas2][oas2] | +| binary | any sequence of octets | from [oas2][oas2] | +| date | [RFC3339][rfc3339] full-date | from [oas2][oas2] | +| date-time | [RFC3339][rfc3339] date-time | from [oas2][oas2] | +| password | sensitive value | from [oas2][oas2] | +| char | | from [autorest][autorest] | +| time | | from [autorest][autorest] | +| date-time-rfc1123 | | from [autorest][autorest] | +| duration | | from [autorest][autorest] | +| uuid | | from [autorest][autorest] | +| base64url | | from [autorest][autorest] | +| url | | from [autorest][autorest] | +| odata-query | | from [autorest][autorest] | +| certificate | | from [autorest][autorest] | oas2: https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#data-types autorest: https://github.com/Azure/autorest/blob/main/packages/libs/openapi/src/v3/formats.ts rfc3339: https://xml2rfc.tools.ietf.org/public/rfc/ @@ -986,7 +995,7 @@ Please refer to [subscription-id-parameter-in-operations.md](./subscription-id-p The URLs should be checked for consistency. It is easy to type "resourcegroups" instead of "resourceGroups". The current rules allow that through, which causes an issue at the resource provider registration step. When that happens, the APIs get split into two sets in the swagger. The RPaaS registration is very strict and requires the same resource to have all APIs in one set. The pipeline needs to be aware of this kind of behavior and provider URL validation. -Please refer to [subscriptions-and-resourcegroup-casing.md](./subscriptions-and-resourcegroup-casing.md) for details. +Please refer to [subscriptions-and-resource-group-casing.md](./subscriptions-and-resource-group-casing.md) for details. ### SuccessResponseBody @@ -1059,6 +1068,12 @@ Tracked resources must have put operation. Please refer to [tracked-resources-must-have-put.md](./tracked-resources-must-have-put.md) for details. +### UnSupportedPatchProperties + +Patch may not change the name, location, or type of the resource. + +Please refer to [un-supported-patch-properties.md](./un-supported-patch-properties.md) for details. + ### UniqueClientParameterName This may cause a problem when different swagger files come together. If two APIs with different client name have the same client parameter subscriptionId, but with different reference name in swaggers, the generated model will also have two clients with two client parameters subscriptionId and subscriptionId1 (the latter one has been renamed to avoid collision). We should ensure that the client parameters are all unique in the same API version. @@ -1075,7 +1090,6 @@ Please refer to [unique-model-name.md](./unique-model-name.md) for details. This rule will check all the swagger files with the same api-version, and ensure there is no duplicate x-ms-enum name. The following cases are deemed as violation: - 1. if two enums have the same x-ms-enum name , but types are different. 2. if two enums have the same x-ms-enum name , but 'modelAsString' are different. 3. if two enums have the same x-ms-enum name , but include different values. @@ -1089,12 +1103,6 @@ x-ms-example name should be unique in the same API version. Please refer to [unique-xms-example.md](./unique-xms-example.md) for details. -### UnSupportedPatchProperties - -Patch may not change the name, location, or type of the resource. - -Please refer to [unsupported-patch-properties.md](./unsupported-patch-properties.md) for details. - ### ValidFormats Only valid types are allowed for properties. diff --git a/docs/subscriptions-and-resourcegroup-casing.md b/docs/subscriptions-and-resource-group-casing.md similarity index 100% rename from docs/subscriptions-and-resourcegroup-casing.md rename to docs/subscriptions-and-resource-group-casing.md diff --git a/docs/unsupported-patch-properties.md b/docs/un-supported-patch-properties.md similarity index 100% rename from docs/unsupported-patch-properties.md rename to docs/un-supported-patch-properties.md From 1d2510aa641af7329ba3c6adc77f84ed1c7ab9b5 Mon Sep 17 00:00:00 2001 From: jianyexi Date: Fri, 9 Dec 2022 15:02:57 +0800 Subject: [PATCH 2/5] add verbose message for passed rule --- .../autorest/src/index.ts | 15 ++++++++------- .../rulesets/generated/spectral/az-arm.js | 19 +++++++++++++++---- .../src/spectral/functions/camel-case.ts | 5 +++-- .../spectral/functions/path-segment-casing.ts | 4 +--- .../rulesets/src/spectral/functions/utils.ts | 15 +++++++++++++++ 5 files changed, 42 insertions(+), 16 deletions(-) diff --git a/packages/azure-openapi-validator/autorest/src/index.ts b/packages/azure-openapi-validator/autorest/src/index.ts index ff48ea27d..11e92463d 100644 --- a/packages/azure-openapi-validator/autorest/src/index.ts +++ b/packages/azure-openapi-validator/autorest/src/index.ts @@ -19,13 +19,14 @@ const cachedFiles = new Map() function convertLintMsgToAutoRestMsg(message:LintResultMessage):Message { // try to extract provider namespace and resource type - const path = message.jsonpath?.[1] === "paths" && message.jsonpath[2] - const pathComponents = typeof path === "string" && path.split("/") - const pathComponentsProviderIndex = pathComponents && pathComponents.indexOf("providers") - const pathComponentsTail = - pathComponentsProviderIndex && pathComponentsProviderIndex >= 0 && pathComponents.slice(pathComponentsProviderIndex + 1) - const pathComponentProviderNamespace = pathComponentsTail && pathComponentsTail[0] - const pathComponentResourceType = pathComponentsTail && pathComponentsTail[1] + const path = message.jsonpath?.[1] === "paths" ? message.jsonpath[2] : undefined + const pathComponents = typeof path === "string" ? path.split("/") : undefined + const pathComponentsProviderIndex = pathComponents ? pathComponents.lastIndexOf("providers") : -1 + const pathComponentsTail = pathComponents && pathComponentsProviderIndex >= 0 ? pathComponents.slice(pathComponentsProviderIndex + 1) : [] + const pathComponentProviderNamespace = pathComponentsTail[0] || "" + + // we can infer the resource type from the path pattern like: "{scope}/providers/MyNamepace/RT1/{rt1Name}/RT2/{rt2Name}" whose pathComponentsTail is ["MyNamespace","RT1","{rt1Name}","RT2","{rt2Name}"] + const pathComponentResourceType = pathComponentsTail && pathComponentsTail.length >= 3 && pathComponentsTail.length % 2 ? pathComponentsTail[pathComponentsTail.length -2] : "" const msg = { Channel: message.type, Text: message.message, diff --git a/packages/rulesets/generated/spectral/az-arm.js b/packages/rulesets/generated/spectral/az-arm.js index d2aeb4fa1..f73736912 100644 --- a/packages/rulesets/generated/spectral/az-arm.js +++ b/packages/rulesets/generated/spectral/az-arm.js @@ -329,6 +329,18 @@ function isSchemaEqual(a, b) { } return false; } +function createRuleFunctionWithPasses(fn) { + return (input, options, ctx) => { + const messsages = fn(input, options, ctx); + if (messsages.length === 0) { + messsages.push({ + message: `[Info]this is a message to indicate that this rule was passed for specific swagger schema successfully, please ignore it if you see this message output by spectral cli diectly.`, + path: ctx.path + }); + } + return messsages; + }; +} const nextLinkPropertyMustExist = (opt, _opts, ctx) => { var _a, _b, _c; @@ -1405,7 +1417,7 @@ const bodyParamRepeatedInfo = (pathItem, _opts, paths) => { return errors; }; -function camelCase(propertyName, options, { path }) { +const camelCase = createRuleFunctionWithPasses((propertyName, options, { path }) => { if (!propertyName) { return []; } @@ -1418,7 +1430,7 @@ function camelCase(propertyName, options, { path }) { }); } return errors; -} +}); const collectionObjectPropertiesNaming = (op, _opts, paths) => { var _a, _b; @@ -1734,7 +1746,7 @@ const pathBodyParameters = (parameters, _opts, paths) => { return errors; }; -const pathSegmentCasing = (apiPaths, _opts, paths) => { +const pathSegmentCasing = (apiPaths, _opts, { path }) => { if (apiPaths === null || typeof apiPaths !== 'object') { return []; } @@ -1742,7 +1754,6 @@ const pathSegmentCasing = (apiPaths, _opts, paths) => { return []; } const segments = _opts.segments; - const path = paths.path || []; const errors = []; for (const apiPath of Object.keys(apiPaths)) { segments.forEach((seg) => { diff --git a/packages/rulesets/src/spectral/functions/camel-case.ts b/packages/rulesets/src/spectral/functions/camel-case.ts index 0d6a1ac3d..2c4e7a64f 100644 --- a/packages/rulesets/src/spectral/functions/camel-case.ts +++ b/packages/rulesets/src/spectral/functions/camel-case.ts @@ -1,8 +1,9 @@ import type { IFunctionResult } from "@stoplight/spectral-core" import type { JsonPath } from "@stoplight/types" +import { createRuleFunctionWithPasses } from "./utils" // check if given propertyName is camel case -export function camelCase(propertyName: string, options: any, { path }: { path: JsonPath }): IFunctionResult[] { +export const camelCase = createRuleFunctionWithPasses((propertyName: string, options: any, { path }: { path: JsonPath }): IFunctionResult[] => { if (!propertyName) { return [] as IFunctionResult[] } @@ -17,6 +18,6 @@ export function camelCase(propertyName: string, options: any, { path }: { path: }) } return errors -} +}) export default camelCase \ No newline at end of file diff --git a/packages/rulesets/src/spectral/functions/path-segment-casing.ts b/packages/rulesets/src/spectral/functions/path-segment-casing.ts index 2d8d9dae0..4ce4969eb 100644 --- a/packages/rulesets/src/spectral/functions/path-segment-casing.ts +++ b/packages/rulesets/src/spectral/functions/path-segment-casing.ts @@ -1,5 +1,5 @@ // _opts has a property 'segments' as string[] to specify the segment names to check for -export const pathSegmentCasing = (apiPaths:any, _opts:any, paths: any) => { +export const pathSegmentCasing = (apiPaths:any, _opts:any, {path}: any) => { if (apiPaths === null || typeof apiPaths !== 'object') { return []; } @@ -8,8 +8,6 @@ export const pathSegmentCasing = (apiPaths:any, _opts:any, paths: any) => { return [] } const segments = _opts.segments - const path = paths.path || []; - const errors:any[] = []; for (const apiPath of Object.keys(apiPaths)) { segments.forEach((seg:string) => { diff --git a/packages/rulesets/src/spectral/functions/utils.ts b/packages/rulesets/src/spectral/functions/utils.ts index 8e4756da6..95d2a2ed3 100644 --- a/packages/rulesets/src/spectral/functions/utils.ts +++ b/packages/rulesets/src/spectral/functions/utils.ts @@ -1,3 +1,5 @@ +import { IFunctionResult, RulesetFunctionContext } from "@stoplight/spectral-core" + /** * get all properties as array */ @@ -174,3 +176,16 @@ export function isSchemaEqual(a: any, b: any): boolean { } return false; } + +export function createRuleFunctionWithPasses(fn:(input:I, options:O, ctx: RulesetFunctionContext)=> IFunctionResult[]) { + return (input:I, options:O, ctx: RulesetFunctionContext):IFunctionResult[] => { + const messsages = fn(input,options,ctx) + if (messsages.length === 0) { + messsages.push({ + message: `[Verbose]this is a verbose message to indicate that this rule was passed for specific swagger schema successfully and no fix is needed, please ignore it.`, + path: ctx.path + }) + } + return messsages + } +} \ No newline at end of file From a08ec7d4f0669ff19c3e1e51b57a6b04beab8c38 Mon Sep 17 00:00:00 2001 From: jianyexi Date: Fri, 9 Dec 2022 15:15:04 +0800 Subject: [PATCH 3/5] add verbose flag --- packages/azure-openapi-validator/autorest/src/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/azure-openapi-validator/autorest/src/index.ts b/packages/azure-openapi-validator/autorest/src/index.ts index 11e92463d..c226927bc 100644 --- a/packages/azure-openapi-validator/autorest/src/index.ts +++ b/packages/azure-openapi-validator/autorest/src/index.ts @@ -27,8 +27,9 @@ function convertLintMsgToAutoRestMsg(message:LintResultMessage):Message { // we can infer the resource type from the path pattern like: "{scope}/providers/MyNamepace/RT1/{rt1Name}/RT2/{rt2Name}" whose pathComponentsTail is ["MyNamespace","RT1","{rt1Name}","RT2","{rt2Name}"] const pathComponentResourceType = pathComponentsTail && pathComponentsTail.length >= 3 && pathComponentsTail.length % 2 ? pathComponentsTail[pathComponentsTail.length -2] : "" + const type = message.message.startsWith("[Verbose]this is a verbose message to indicate that this rule was passed for specific swagger schema successfully and no fix is needed]") ? "verbose" : message.type const msg = { - Channel: message.type, + Channel: type, Text: message.message, Key: [message.code], Source: [ From 48e1a6f240fb900cea8122d288efc1da6f9478f8 Mon Sep 17 00:00:00 2001 From: jianyexi Date: Fri, 9 Dec 2022 15:33:27 +0800 Subject: [PATCH 4/5] small fix --- packages/azure-openapi-validator/autorest/src/index.ts | 4 ++-- packages/rulesets/generated/spectral/az-arm.js | 6 +++--- packages/rulesets/src/spectral/az-arm.ts | 2 +- packages/rulesets/src/spectral/functions/camel-case.ts | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/azure-openapi-validator/autorest/src/index.ts b/packages/azure-openapi-validator/autorest/src/index.ts index c226927bc..b49b7894e 100644 --- a/packages/azure-openapi-validator/autorest/src/index.ts +++ b/packages/azure-openapi-validator/autorest/src/index.ts @@ -19,7 +19,7 @@ const cachedFiles = new Map() function convertLintMsgToAutoRestMsg(message:LintResultMessage):Message { // try to extract provider namespace and resource type - const path = message.jsonpath?.[1] === "paths" ? message.jsonpath[2] : undefined + const path = message.jsonpath?.[0] === "paths" ? message.jsonpath[1] : undefined const pathComponents = typeof path === "string" ? path.split("/") : undefined const pathComponentsProviderIndex = pathComponents ? pathComponents.lastIndexOf("providers") : -1 const pathComponentsTail = pathComponents && pathComponentsProviderIndex >= 0 ? pathComponents.slice(pathComponentsProviderIndex + 1) : [] @@ -27,7 +27,7 @@ function convertLintMsgToAutoRestMsg(message:LintResultMessage):Message { // we can infer the resource type from the path pattern like: "{scope}/providers/MyNamepace/RT1/{rt1Name}/RT2/{rt2Name}" whose pathComponentsTail is ["MyNamespace","RT1","{rt1Name}","RT2","{rt2Name}"] const pathComponentResourceType = pathComponentsTail && pathComponentsTail.length >= 3 && pathComponentsTail.length % 2 ? pathComponentsTail[pathComponentsTail.length -2] : "" - const type = message.message.startsWith("[Verbose]this is a verbose message to indicate that this rule was passed for specific swagger schema successfully and no fix is needed]") ? "verbose" : message.type + const type = message.message.startsWith("[Verbose]this is a verbose message to indicate that this rule was passed for specific swagger schema successfully and no fix is needed") ? "verbose" : message.type const msg = { Channel: type, Text: message.message, diff --git a/packages/rulesets/generated/spectral/az-arm.js b/packages/rulesets/generated/spectral/az-arm.js index f73736912..ced6b74a8 100644 --- a/packages/rulesets/generated/spectral/az-arm.js +++ b/packages/rulesets/generated/spectral/az-arm.js @@ -334,7 +334,7 @@ function createRuleFunctionWithPasses(fn) { const messsages = fn(input, options, ctx); if (messsages.length === 0) { messsages.push({ - message: `[Info]this is a message to indicate that this rule was passed for specific swagger schema successfully, please ignore it if you see this message output by spectral cli diectly.`, + message: `[Verbose]this is a verbose message to indicate that this rule was passed for specific swagger schema successfully and no fix is needed, please ignore it.`, path: ctx.path }); } @@ -1425,7 +1425,7 @@ const camelCase = createRuleFunctionWithPasses((propertyName, options, { path }) const camelCaseReg = /^[a-z0-9$-]+([A-Z]{1,3}[a-z0-9$-]+)+$|^[a-z0-9$-]+$|^[a-z0-9$-]+([A-Z]{1,3}[a-z0-9$-]+)*[A-Z]{1,3}$/; if (!camelCaseReg.test(propertyName)) { errors.push({ - message: "", + message: "Property name should be camel case.", path }); } @@ -2354,7 +2354,7 @@ const ruleset = { }, DefinitionsPropertiesNamesCamelCase: { description: "Property names should be camel case.", - message: "Property name should be camel case.", + message: "{{error}}", severity: "error", resolved: false, given: "$.definitions..[?(@property === 'type' && @ === 'object')]^.properties[?(@property.match(/^[^@].+$/))]~", diff --git a/packages/rulesets/src/spectral/az-arm.ts b/packages/rulesets/src/spectral/az-arm.ts index bb9e54fe5..2af1bf53b 100644 --- a/packages/rulesets/src/spectral/az-arm.ts +++ b/packages/rulesets/src/spectral/az-arm.ts @@ -409,7 +409,7 @@ const ruleset: any = { // this rule covers BodyPropertiesNamesCamelCase and DefinitionsPropertiesNamesCamelCase DefinitionsPropertiesNamesCamelCase: { description: "Property names should be camel case.", - message: "Property name should be camel case.", + message: "{{error}}", severity: "error", resolved: false, given: "$.definitions..[?(@property === 'type' && @ === 'object')]^.properties[?(@property.match(/^[^@].+$/))]~", diff --git a/packages/rulesets/src/spectral/functions/camel-case.ts b/packages/rulesets/src/spectral/functions/camel-case.ts index 2c4e7a64f..4b797cc3e 100644 --- a/packages/rulesets/src/spectral/functions/camel-case.ts +++ b/packages/rulesets/src/spectral/functions/camel-case.ts @@ -13,7 +13,7 @@ export const camelCase = createRuleFunctionWithPasses((propertyName: string, opt if (!camelCaseReg.test(propertyName)) { errors.push({ - message:"", + message: "Property name should be camel case.", path }) } From 9c258fff3e0d89398105f30b297a36312f858a3f Mon Sep 17 00:00:00 2001 From: jianyexi Date: Fri, 9 Dec 2022 15:57:00 +0800 Subject: [PATCH 5/5] fix lint error --- packages/rulesets/src/spectral/functions/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/rulesets/src/spectral/functions/utils.ts b/packages/rulesets/src/spectral/functions/utils.ts index 95d2a2ed3..b65603279 100644 --- a/packages/rulesets/src/spectral/functions/utils.ts +++ b/packages/rulesets/src/spectral/functions/utils.ts @@ -177,7 +177,7 @@ export function isSchemaEqual(a: any, b: any): boolean { return false; } -export function createRuleFunctionWithPasses(fn:(input:I, options:O, ctx: RulesetFunctionContext)=> IFunctionResult[]) { +export function createRuleFunctionWithPasses(fn:(input:I, options:O, ctx: RulesetFunctionContext)=> IFunctionResult[]) { return (input:I, options:O, ctx: RulesetFunctionContext):IFunctionResult[] => { const messsages = fn(input,options,ctx) if (messsages.length === 0) {