Skip to content

Commit

Permalink
Merge branch 'main' into tejaswis/updateCommonTypes
Browse files Browse the repository at this point in the history
  • Loading branch information
tejaswiMinnu committed Sep 6, 2024
2 parents d0470a3 + 5f8120d commit 9cb4900
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 7 deletions.
5 changes: 1 addition & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -390,10 +390,7 @@ Once your PR is merged:

- Schedule a [Prod build] from the `main` branch.
- **!!! IMPORTANT !!!**: If you are updating [packages/azure-openapi-validator/autorest], see [this section](#synchronize-with-changes-to-openapi-alps-repository).
- Once the build is complete, schedule a [Prod npm release] from that build.
You may need to get an approval for the release from the appropriate Azure SDK EngSys team members.
- Note that sometimes the npm release may report failure even when it succeeded. This is because sometimes it tries to
publish package twice and succeeds only on the first try.
- You may need to get an approval for the release from the appropriate [Azure SDK EngSys team members](https://teams.microsoft.com/l/channel/19%3A59dbfadafb5e41c4890e2cd3d74cc7ba%40thread.skype/Engineering%20System%20%F0%9F%9B%A0%EF%B8%8F?groupId=3e17dcb0-4257-4a30-b843-77f47f1d4121).
- Verify the release worked by new versions of the appropriate packages being released to npm.
See [README `packages` section]. You can also look at the release build log.

Expand Down
6 changes: 5 additions & 1 deletion packages/rulesets/generated/spectral/az-arm.js
Original file line number Diff line number Diff line change
Expand Up @@ -2612,7 +2612,7 @@ const resourceNameRestriction = (paths, _opts, ctx) => {
const param = (_a = v.match(/[^{}]+(?=})/)) === null || _a === void 0 ? void 0 : _a[0];
if ((param === null || param === void 0 ? void 0 : param.match(/^\w+Name+$/)) && !EXCEPTION_LIST.includes(param)) {
const paramDefinition = getPathParameter(paths[pathKey], param);
if (paramDefinition && !paramDefinition.pattern) {
if (paramDefinition && !paramDefinition.enum && !paramDefinition.pattern) {
errors.push({
message: `The resource name parameter '${param}' should be defined with a 'pattern' restriction.`,
path: [...path, pathKey],
Expand Down Expand Up @@ -3354,6 +3354,7 @@ const ruleset = {
rpcGuidelineCode: "RPC-Policy-V1-03",
description: "Properties with type:object that don't reference a model definition are not allowed. ARM doesn't allow generic type definitions as this leads to bad customer experience.",
severity: "error",
stagingOnly: true,
message: "{{error}}",
resolved: true,
formats: [oas2],
Expand Down Expand Up @@ -3458,6 +3459,7 @@ const ruleset = {
description: "PATCH request body must only contain properties present in the corresponding PUT request body, and must contain at least one property.",
message: "{{error}}",
severity: "error",
stagingOnly: true,
resolved: true,
formats: [oas2],
given: ["$[paths,'x-ms-paths'].*"],
Expand Down Expand Up @@ -3673,6 +3675,7 @@ const ruleset = {
description: "Every Put and Patch operation must have a request body",
message: "{{error}}",
severity: "error",
stagingOnly: true,
resolved: true,
formats: [oas2],
given: "$[paths,'x-ms-paths'].*[put,patch].parameters",
Expand All @@ -3685,6 +3688,7 @@ const ruleset = {
description: "A Put operation must return the same schema for 200 and 201 response codes",
message: "{{error}}",
severity: "error",
stagingOnly: true,
resolved: true,
formats: [oas2],
given: "$.paths.*",
Expand Down
2 changes: 1 addition & 1 deletion packages/rulesets/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@microsoft.azure/openapi-validator-rulesets",
"version": "2.1.0",
"version": "2.1.2",
"description": "Azure OpenAPI Validator",
"main": "dist/index.js",
"scripts": {
Expand Down
4 changes: 4 additions & 0 deletions packages/rulesets/src/spectral/az-arm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ const ruleset: any = {
description:
"Properties with type:object that don't reference a model definition are not allowed. ARM doesn't allow generic type definitions as this leads to bad customer experience.",
severity: "error",
stagingOnly: true,
message: "{{error}}",
resolved: true,
formats: [oas2],
Expand Down Expand Up @@ -459,6 +460,7 @@ const ruleset: any = {
"PATCH request body must only contain properties present in the corresponding PUT request body, and must contain at least one property.",
message: "{{error}}",
severity: "error",
stagingOnly: true,
resolved: true,
formats: [oas2],
given: ["$[paths,'x-ms-paths'].*"],
Expand Down Expand Up @@ -711,6 +713,7 @@ const ruleset: any = {
description: "Every Put and Patch operation must have a request body",
message: "{{error}}",
severity: "error",
stagingOnly: true,
resolved: true,
formats: [oas2],
given: "$[paths,'x-ms-paths'].*[put,patch].parameters",
Expand All @@ -725,6 +728,7 @@ const ruleset: any = {
description: "A Put operation must return the same schema for 200 and 201 response codes",
message: "{{error}}",
severity: "error",
stagingOnly: true,
resolved: true,
formats: [oas2],
given: "$.paths.*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export const resourceNameRestriction = (paths: any, _opts: any, ctx: any) => {
// Get the preceding path segment
if (param?.match(/^\w+Name+$/) && !EXCEPTION_LIST.includes(param)) {
const paramDefinition = getPathParameter(paths[pathKey], param)
if (paramDefinition && !paramDefinition.pattern) {
// resource name param with enum doesnt need to explicitly have pattern specified
if (paramDefinition && !paramDefinition.enum && !paramDefinition.pattern) {
errors.push({
message: `The resource name parameter '${param}' should be defined with a 'pattern' restriction.`,
path: [...path, pathKey],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,39 @@ test("ResourceNameRestriction should find no errors for system-defined variables
expect(results.length).toBe(0)
})
})

test("ResourceNameRestriction should find no errors for type enums", () => {
const oasDoc = {
swagger: "2.0",
paths: {
"/subscriptions/{subscriptionId}/providers/Microsoft.AzurePlaywrightService/locations/{location}/quotas/{quotaName}": {
get: {
operationId: "Quotas_Get",
tags: ["Quotas"],
description: "Get quota by name.",
parameters: [
{
name: "location",
in: "path",
description: "The location of quota in ARM Normalized format like eastus, southeastasia etc.",
required: true,
type: "string",
},
{
name: "quotaName",
in: "path",
description: "The quota name.",
required: true,
type: "string",
enum: ["ScalableExecution", "Reporting"],
},
],
responses: {},
},
},
},
}
return linter.run(oasDoc).then((results) => {
expect(results.length).toBe(0)
})
})

0 comments on commit 9cb4900

Please sign in to comment.